{"id":15992240,"url":"https://github.com/angrykoala/compositer","last_synced_at":"2025-04-14T11:11:15.714Z","repository":{"id":57204944,"uuid":"127410703","full_name":"angrykoala/compositer","owner":"angrykoala","description":"Utility to generate composite classes dynamically","archived":false,"fork":false,"pushed_at":"2019-10-14T12:27:34.000Z","size":66,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T00:22:54.550Z","etag":null,"topics":["class","composite","es6","javascript","node"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/angrykoala.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}},"created_at":"2018-03-30T09:40:13.000Z","updated_at":"2021-07-14T08:13:40.000Z","dependencies_parsed_at":"2022-09-18T00:22:52.411Z","dependency_job_id":null,"html_url":"https://github.com/angrykoala/compositer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/angrykoala%2Fcompositer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/angrykoala%2Fcompositer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/angrykoala%2Fcompositer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/angrykoala%2Fcompositer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/angrykoala","download_url":"https://codeload.github.com/angrykoala/compositer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248868766,"owners_count":21174758,"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","composite","es6","javascript","node"],"created_at":"2024-10-08T06:20:25.725Z","updated_at":"2025-04-14T11:11:15.680Z","avatar_url":"https://github.com/angrykoala.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Compositer\n==========\n_by @angrykoala_\n\n[![npm version](https://badge.fury.io/js/compositer.svg)](https://badge.fury.io/js/compositer)\n[![Build Status](https://travis-ci.org/angrykoala/compositer.svg?branch=master)](https://travis-ci.org/angrykoala/compositer)\n\nCompositer is an utility to generate [composed](https://en.wikipedia.org/wiki/Composition_over_inheritance) ES6 classes dynamically.\n\n`npm install --save compositer`\n\n```js\nconst compose=require('compositer');\n\nclass Child{\n    constructor(parent){\n        this._value=parent.value*10;\n    }\n\n    get value(){\n        return this._value;\n    }\n}\n\n\nclass Parent{\n    constructor(value){\n        this.value=value;\n    }\n}\n\n// Components define the composite names for the instances of the child classes\nconst components = {\n    \"myChild\": Child\n};\n\n// compose returns a new class containing the parent class and the composed sub classes\nconst ComposedParent = compose(Parent,components);\n// The constructor of the composed class will instance and attach the child classes to getters\nconst myComposite = new ComposedParent(100);\n\nmyComposite.value; // 100\nmyComposite.myChild.value; // 1000\n```\n\n\n## Api\n\nComposer exposes one function to generate composite classes:\n\n**compose(ParentClass, components, ...extraParams?)**    \n* ParentClass is the class that will have the child attached to.\n* components is an object with keys being the name to use for the instance and value the child class. Same child class can be used multiple times.\n    * If a plain function is used instead of a class, the function will be attached directly, the same arguments as the constructor will be used plus any argument passed to the function when called.\n* extraParams allow you to add params to the child classes constructors.\n* Returns a new class that will instance the child classes. The class will be named the same as the ParentClass with \"Composite\" at the end.\n* ParentClass will receive an extra parameter with a list of all its components names, allowing it to access dynamically\n\n## Development Instructions\nAfter cloning the repo:\n\n1. `npm install`\n2. `npm test`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fangrykoala%2Fcompositer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fangrykoala%2Fcompositer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fangrykoala%2Fcompositer/lists"}