{"id":15698989,"url":"https://github.com/pgilad/derived-property","last_synced_at":"2025-03-30T14:25:26.450Z","repository":{"id":57226576,"uuid":"38989014","full_name":"pgilad/derived-property","owner":"pgilad","description":"Create a derived property for an object","archived":false,"fork":false,"pushed_at":"2015-07-13T19:45:46.000Z","size":132,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-16T18:19:09.044Z","etag":null,"topics":[],"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/pgilad.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":"2015-07-13T03:18:38.000Z","updated_at":"2015-07-13T07:00:47.000Z","dependencies_parsed_at":"2022-08-22T12:20:37.241Z","dependency_job_id":null,"html_url":"https://github.com/pgilad/derived-property","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgilad%2Fderived-property","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgilad%2Fderived-property/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgilad%2Fderived-property/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgilad%2Fderived-property/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pgilad","download_url":"https://codeload.github.com/pgilad/derived-property/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246329583,"owners_count":20759927,"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-10-03T19:37:15.571Z","updated_at":"2025-03-30T14:25:26.423Z","avatar_url":"https://github.com/pgilad.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# derived-property\n\n[![Build Status](https://travis-ci.org/pgilad/derived-property.svg?branch=master)](https://travis-ci.org/pgilad/derived-property)\n[![Coverage Status](https://coveralls.io/repos/pgilad/derived-property/badge.svg?branch=master\u0026service=github)](https://coveralls.io/github/pgilad/derived-property?branch=master)\n\n\u003e Create a derived property for an object\n\n* [Install](#install)\n* [Usage](#usage)\n* [API](#api)\n* [Contributing](#contributing)\n* [Run tests](#run-tests)\n* [Related](#related)\n* [License](#license)\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/)\n\n```sh\n$ npm install derived-property --save\n```\n\n## Usage\n\n```js\nvar derivedProperty = require('derived-property');\n\nvar obj = {\n  first: 'Gilad',\n  last: 'Peleg'\n}\n\nvar displayName = derivedProperty({\n  dependencies: ['first', 'last'],\n  getter: function (first, last) {\n    return first + ' ' + last;\n  }\n});\n\n// apply the derived property\nObject.defineProperty(obj, 'displayName', displayName);\n\nconsole.log(obj.displayName);\n// =\u003e 'Gilad Peleg'\n\n// later on..\nobj.first = 'John';\nconsole.log(obj.displayName);\n// =\u003e 'John Peleg'\n```\n\n## API\n\n### [derivedProperty](index.js#L44)\n\n`derivedProperty(options)`\n\nCreate a derived property. Returns a `response` that should be applied using `Object.defineProperty(obj, 'property', response)`\n\n**options**\n\n* `getter` **{Function}**: Getter function to do the calculation. Gets the values of dependencies as arguments.\n* `dependencies` **{Array}**: Optional list of properties to depend on.\n* `cache` **{Boolean}**: Whether to use the cached result if dependencies haven't changed. Defaults to `true`. Set off for non-pure derived properties (i.e - relies on `Date.now()`).\n* `getMethod` **{Function}**: Optional getter method to access the dependencies on the object. Defaults to `lodash.result`.\n* `compareMethod` **{Function}**: Optional compare method to check if the dependency has changed. Defaults to `===`.\n\n## Contributing\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/pgilad/derived-property/issues)\n\n## Run tests\n\n```sh\n$ npm test\n```\n\n## Related\n\n- [computed-property](https://github.com/doowb/computed-property)\n\n## License\n\nMIT ©[Gilad Peleg](http://giladpeleg.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpgilad%2Fderived-property","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpgilad%2Fderived-property","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpgilad%2Fderived-property/lists"}