{"id":19041979,"url":"https://github.com/writetome51/get-class-modification-decorator","last_synced_at":"2025-07-09T12:07:42.645Z","repository":{"id":122062393,"uuid":"221354744","full_name":"writetome51/get-class-modification-decorator","owner":"writetome51","description":"Returns a TypeScript ClassDecorator factory.","archived":false,"fork":false,"pushed_at":"2020-08-09T01:51:29.000Z","size":34,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-30T20:19:29.435Z","etag":null,"topics":["class","decorator","factory","function","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/writetome51.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"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":"2019-11-13T02:24:47.000Z","updated_at":"2020-08-13T20:41:49.000Z","dependencies_parsed_at":null,"dependency_job_id":"2d184881-7a7b-4e59-8239-f3b308b8d1c3","html_url":"https://github.com/writetome51/get-class-modification-decorator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/writetome51/get-class-modification-decorator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/writetome51%2Fget-class-modification-decorator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/writetome51%2Fget-class-modification-decorator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/writetome51%2Fget-class-modification-decorator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/writetome51%2Fget-class-modification-decorator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/writetome51","download_url":"https://codeload.github.com/writetome51/get-class-modification-decorator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/writetome51%2Fget-class-modification-decorator/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264455967,"owners_count":23611059,"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","decorator","factory","function","typescript"],"created_at":"2024-11-08T22:33:39.638Z","updated_at":"2025-07-09T12:07:42.628Z","avatar_url":"https://github.com/writetome51.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# getClassModificationDecorator(\u003cbr\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;modifyInstance: (\u003cbr\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;instance, decoratorArgs: any[]\u003cbr\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;) =\u003e void\u003cbr\u003e): (...decoratorArgs) =\u003e ClassDecorator\n\nReturns a TypeScript ClassDecorator factory. You set the decorator behavior with the  \ncallback `modifyInstance()`. The decorator creates a new constructor for the class  \nbeing decorated. The new constructor first calls the original, then the class instance  \nis passed into `modifyInstance()`, where you manipulate it however you want. (The  \nprototype chain is kept intact, and the `instanceof` operator will still work.)\n\n\n## Examples\n\n```ts\n// Here we make a decorator that adds properties:\n\nexport const add_properties = getClassModificationDecorator(\n    (instance, decoratorArgs: [object]) =\u003e {\n        let newProperties = decoratorArgs[0];\n        Object.assign(instance, newProperties);\n    }\n);\n\n// Now use it:\n\n@add_properties({hair: 'amazing', age: 50, income: 200000, wife: 'hot'})\nexport class Boss {\n}\n\n@add_properties({address: '100 fleet street', income: 600000})\nexport class CEO extends Boss {\n}\n\nlet ceo = new CEO();\n\nconsole.log(ceo);\n/*************\nCEO {\n  age: 50,\n  address: '100 fleet street',\n  hair: 'amazing',\n  income: 600000,\n  wife: 'hot' \n}\n**************/\n```\n\n## Installation\n```bash\nnpm i  @writetome51/get-class-modification-decorator\n```\n\n## Loading\n```js\nimport {getClassModificationDecorator} \n    from '@writetome51/get-class-modification-decorator';\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwritetome51%2Fget-class-modification-decorator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwritetome51%2Fget-class-modification-decorator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwritetome51%2Fget-class-modification-decorator/lists"}