{"id":18573920,"url":"https://github.com/basedwon/registry","last_synced_at":"2025-05-15T23:34:13.370Z","repository":{"id":205953522,"uuid":"715479236","full_name":"basedwon/registry","owner":"basedwon","description":"A simple yet powerful utility to manage and create class instances in JavaScript applications.","archived":false,"fork":false,"pushed_at":"2023-11-07T11:23:31.000Z","size":20,"stargazers_count":1,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-17T14:48:21.644Z","etag":null,"topics":["class-instance","class-register","javascript"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/basedwon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"docs/contributing.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-07T08:22:13.000Z","updated_at":"2023-11-09T00:43:46.000Z","dependencies_parsed_at":"2024-11-06T23:13:25.563Z","dependency_job_id":"51b85bb2-5042-4f81-8ed8-96385f2579ee","html_url":"https://github.com/basedwon/registry","commit_stats":null,"previous_names":["basedwon/registry"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basedwon%2Fregistry","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basedwon%2Fregistry/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basedwon%2Fregistry/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basedwon%2Fregistry/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/basedwon","download_url":"https://codeload.github.com/basedwon/registry/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254442346,"owners_count":22071863,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["class-instance","class-register","javascript"],"created_at":"2024-11-06T23:13:23.191Z","updated_at":"2025-05-15T23:34:13.294Z","avatar_url":"https://github.com/basedwon.png","language":"JavaScript","readme":"# Registry\n\n[![npm](https://img.shields.io/npm/v/@basd/registry?style=flat\u0026logo=npm)](https://www.npmjs.com/package/@basd/registry)\n[![pipeline](https://gitlab.com/frenware/utils/registry/badges/master/pipeline.svg)](https://gitlab.com/frenware/utils/registry/-/pipelines)\n[![license](https://img.shields.io/npm/l/@basd/registry)](https://gitlab.com/frenware/utils/registry/-/blob/master/LICENSE)\n[![downloads](https://img.shields.io/npm/dw/@basd/registry)](https://www.npmjs.com/package/@basd/registry) \n\n[![Gitlab](https://img.shields.io/badge/Gitlab%20-%20?logo=gitlab\u0026color=%23383a40)](https://gitlab.com/frenware/utils/registry)\n[![Github](https://img.shields.io/badge/Github%20-%20?logo=github\u0026color=%23383a40)](https://github.com/basedwon/registry)\n[![Twitter](https://img.shields.io/badge/@basdwon%20-%20?logo=twitter\u0026color=%23383a40)](https://twitter.com/basdwon)\n[![Discord](https://img.shields.io/badge/Basedwon%20-%20?logo=discord\u0026color=%23383a40)](https://discordapp.com/users/basedwon)\n\nA simple yet powerful utility to manage and create class instances in JavaScript applications. This registry allows you to define, override, and retrieve classes with ease. It also comes with built-in validation checks to ensure the integrity of the classes you're working with.\n\n## Features\n\n- Define classes once and access them globally.\n- Create instances of classes with runtime validation checks.\n- Support for deep-nesting of classes.\n- Override existing class definitions.\n\n## Installation\n\nInstall the package with:\n\n```bash\nnpm install @basd/registry\n```\n\n## Usage\n\nFirst, import the `Registry` library.\n\n```js\nimport Registry from '@basd/registry'\n```\nor\n```js\nconst Registry = require('@basd/registry')\n```\n\nThen use the registry to set, validate and instantiate some class:\n\n```js\nconst Registry = require('@basd/registry')\nconst MyClass = require('./MyClass')\n\nconst registry = new Registry()\n\n// Add MyClass to the registry\nregistry.set('MyClass', MyClass)\n\n// Create a new instance\nconst instance = registry.createInstance('MyClass')\n\n// Validate class and instance\nif (registry.isValidClass(MyClass) \u0026\u0026 registry.isValidInstance(instance)) {\n  console.log('Valid')\n}\n```\n\n## Documentation\n\n- [API Reference](/docs/api.md)\n\n## API\n\n### `constructor(config)`\n\nInitialize the `Registry` class with an optional configuration.\n\n```js\nconst Registry = require('@basd/registry')\nconst registry = new Registry({\n  classes: {\n    'MyClass': MyClassDefinition\n  }\n})\n```\n\n### `createInstance(name, args, baseClass)`\n\nCreate an instance of a class with a given `name`. Optionally, specify a `baseClass` to validate against.\n\n```js\nconst instance = registry.createInstance('MyClass', [arg1, arg2], MyBaseClass)\n```\n\n### `isValidClass(targetClass, baseClass)`\n\nValidate whether `targetClass` is a valid class optionally against a `baseClass`.\n\n### `isValidInstance(instance, baseClass)`\n\nCheck if `instance` is a valid object and optionally belongs to a class derived from `baseClass`.\n\n### `ingest(source)`\n\nIngest classes from another `source`.\n\n```js\nregistry.ingest(anotherRegistry)\n```\n\n### `setWith(name, targetClass, baseClass, override = false)`\n\nSet a class with additional validation checks. Optionally, specify a `baseClass` and if the class can be overridden.\n\n```js\nregistry.setWith('MyClass', MyClass, MyBaseClass, true)\n```\n\n### `set(name, targetClass, override = true)`\n\nSet a class in the registry. Optionally, allow it to be overridden.\n\n```js\nregistry.set('MyClass', MyClass)\n```\n\n### `setMany(classes, override = false)`\n\nSet multiple classes at once.\n\n```js\nregistry.setMany({\n  'MyClass1': MyClass1,\n  'MyClass2': MyClass2\n})\n```\n\n### `get(name, defaultValue = null)`\n\nGet a class from the registry by its `name`. If not found, return `defaultValue`.\n\n```js\nconst MyClass = registry.get('MyClass')\n```\n\n### `has(name)`\n\nCheck if the registry contains a class with the specified `name`.\n\n```js\nconst exists = registry.has('MyClass')\n```\n\n### `static get(config)`\n\nA static method to get an existing registry instance or create a new one.\n\n```js\nconst registry = Registry.get(existingConfig)\n```\n\n## Tests\n\nIn order to run the test suite, simply clone the repository and install its dependencies:\n\n```bash\ngit clone https://gitlab.com/frenware/utils/registry.git\ncd registry\nnpm install\n```\n\nTo run the tests:\n\n```bash\nnpm test\n```\n\n## Contributing\n\nThank you! Please see our [contributing guidelines](/docs/contributing.md) for details.\n\n## Donations\n\nIf you find this project useful and want to help support further development, please send us some coin. We greatly appreciate any and all contributions. Thank you!\n\n**Bitcoin (BTC):**\n```\n1JUb1yNFH6wjGekRUW6Dfgyg4J4h6wKKdF\n```\n\n**Monero (XMR):**\n```\n46uV2fMZT3EWkBrGUgszJCcbqFqEvqrB4bZBJwsbx7yA8e2WBakXzJSUK8aqT4GoqERzbg4oKT2SiPeCgjzVH6VpSQ5y7KQ\n```\n\n## License\n\n@basd/registry is [MIT licensed](https://gitlab.com/frenware/utils/registry/-/blob/master/LICENSE).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbasedwon%2Fregistry","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbasedwon%2Fregistry","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbasedwon%2Fregistry/lists"}