{"id":21762604,"url":"https://github.com/dawee/modella-collector","last_synced_at":"2025-03-21T04:42:45.120Z","repository":{"id":16426513,"uuid":"19177815","full_name":"dawee/modella-collector","owner":"dawee","description":"modella plugin to enable collection attributes","archived":false,"fork":false,"pushed_at":"2014-06-17T14:26:32.000Z","size":196,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-15T08:18:41.530Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dawee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-04-26T13:20:11.000Z","updated_at":"2014-06-17T14:26:32.000Z","dependencies_parsed_at":"2022-09-17T00:11:13.061Z","dependency_job_id":null,"html_url":"https://github.com/dawee/modella-collector","commit_stats":null,"previous_names":["dawicorti/modella-collector"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dawee%2Fmodella-collector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dawee%2Fmodella-collector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dawee%2Fmodella-collector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dawee%2Fmodella-collector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dawee","download_url":"https://codeload.github.com/dawee/modella-collector/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244739938,"owners_count":20501990,"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":[],"created_at":"2024-11-26T12:12:36.579Z","updated_at":"2025-03-21T04:42:45.097Z","avatar_url":"https://github.com/dawee.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# modella-collector\n\n[modella](http://github.com/modella/modella) plugin to enable collection attributes.\n\n## Declaration\n\n```js\nvar modella = require('modella');\nvar Child = modella('Child').attr('name');\nvar Mom = modella('Mom').attr('children', {type: [Child]}).use(collector);\n\nvar mom = new Mom({children: [\n  {name: 'Pete'}, // Collection models can be initialized with data\n  new Child({name: 'jack'}) // or with instance\n]});\n```\n\n_This plugin is inspired by [this discussion](https://github.com/modella/modella/issues/24)_\n\n## Playing with Collections\n\n\n### Collection#get(index)\n\nReturns a model at a given index.\n\n```js\nmom.get('children').get(0).name(); // Pete\n```\n\n### Collection#first()\n\nReturns the first model.\n\n```js\nmom.get('children').first().name(); // Pete\n```\n\n### Collection#last()\n\nReturns the last model.\n\n```js\nmom.get('children').last().name(); // Jack\n```\n\n### Collection#add(model)\n\nAdds a model\n\n```js\nmom.get('children').add({name: 'Mickael'}); // With data\nmom.get('children').add(new Child({name: 'John'})); // With instance\n```\n\n### Collection#each(fn)\n\nIterates over the collection with the given function.\n\n```js\nmom.get('children').each(function (child) {\n  console.log(child.name());\n});\n```\n\n### Collection#every(fn)\n\nIterates over the collection.\nReturns true if every predicates called returns true.\n\n```js\nmom.get('children').every(function (child) {\n  return child.name().length \u003e 3;\n});\n```\n### Collection#some(fn)\n\nIterates over the collection.\nReturns true if at least one predicate called returns true.\n\n```js\nmom.get('children').some(function (child) {\n  return child.name() === 'John';\n});\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdawee%2Fmodella-collector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdawee%2Fmodella-collector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdawee%2Fmodella-collector/lists"}