{"id":18062949,"url":"https://github.com/stagas/define-accessors","last_synced_at":"2025-04-05T13:23:53.099Z","repository":{"id":57211812,"uuid":"434621619","full_name":"stagas/define-accessors","owner":"stagas","description":"define accessors for an object on another object","archived":false,"fork":false,"pushed_at":"2022-03-13T10:35:53.000Z","size":213,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-11T12:52:05.249Z","etag":null,"topics":["accessors","getters","setters"],"latest_commit_sha":null,"homepage":"","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/stagas.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":"2021-12-03T14:18:36.000Z","updated_at":"2022-03-13T10:35:54.000Z","dependencies_parsed_at":"2022-08-30T15:31:10.875Z","dependency_job_id":null,"html_url":"https://github.com/stagas/define-accessors","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":"stagas/ts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stagas%2Fdefine-accessors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stagas%2Fdefine-accessors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stagas%2Fdefine-accessors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stagas%2Fdefine-accessors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stagas","download_url":"https://codeload.github.com/stagas/define-accessors/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247340496,"owners_count":20923273,"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":["accessors","getters","setters"],"created_at":"2024-10-31T05:08:57.658Z","updated_at":"2025-04-05T13:23:53.082Z","avatar_url":"https://github.com/stagas.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003edefine-accessors\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\ndefine accessors for an object on another object\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n   \u003ca href=\"#install\"\u003e        🔧 \u003cstrong\u003eInstall\u003c/strong\u003e\u003c/a\u003e\n · \u003ca href=\"#example\"\u003e        🧩 \u003cstrong\u003eExample\u003c/strong\u003e\u003c/a\u003e\n · \u003ca href=\"#api\"\u003e            📜 \u003cstrong\u003eAPI docs\u003c/strong\u003e\u003c/a\u003e\n · \u003ca href=\"https://github.com/stagas/define-accessors/releases\"\u003e 🔥 \u003cstrong\u003eReleases\u003c/strong\u003e\u003c/a\u003e\n · \u003ca href=\"#contribute\"\u003e     💪🏼 \u003cstrong\u003eContribute\u003c/strong\u003e\u003c/a\u003e\n · \u003ca href=\"https://github.com/stagas/define-accessors/issues\"\u003e   🖐️ \u003cstrong\u003eHelp\u003c/strong\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n***\n\n## Install\n\n```sh\n$ npm i define-accessors\n```\n\n## API\n\n\u003c!-- Generated by documentation.js. Update this documentation by updating the source code. --\u003e\n\n#### Table of Contents\n\n*   [defineAccessors](#defineaccessors)\n    *   [Parameters](#parameters)\n\n### defineAccessors\n\n[src/index.ts:59-72](https://github.com/stagas/define-accessors/blob/95f6e9401b67076377588e17927a3a3c968be44f/src/index.ts#L59-L72 \"Source code on GitHub\")\n\nDefines accessors for a source object on a target object.\n\nExample; all values reflected on source:\n\n```ts\nconst target = {}\nconst source = {\n  foo: 'a prop',\n  bar: 'another',\n  zoo: 10,\n}\nconst typed = defineAccessors(target, source)\nexpect(typed).toBe(target)\nexpect(typed.foo).toBe(source.foo)\nexpect(typed.bar).toBe(source.bar)\nexpect(typed.zoo).toBe(source.zoo)\n\ntyped.foo = 'something else'\nexpect(typed.foo).toEqual('something else')\nexpect(source.foo).toEqual('something else')\n```\n\nExample; all values reflected on `other` using a custom property descriptor factory:\n\n```ts\nconst target = {}\nconst source = {\n  foo: 'a prop',\n}\nconst other: Record\u003cstring, unknown\u003e = {\n  foo: 'something else',\n}\nconst typed = defineAccessors(target, source, (key: string) =\u003e ({\n  enumerable: true,\n  get() {\n    return other[key]\n  },\n  set(value: never) {\n    other[key] = value\n  },\n}))\nexpect(typed).toBe(target)\nexpect(typed.foo).toBe(other.foo)\n```\n\n#### Parameters\n\n*   `target` **T** The target object to define accessors on\n*   `source` **S** The source object where the actual values are\n*   `propertyDescriptorFactory` **function (key: any, source: S): PropertyDescriptor** A function that returns a custom property descriptor for the given key (optional, default `createPropertyDescriptor`)\n\nReturns **any** The target object but with its type intersected with the source's type\n\n## Contribute\n\n[Fork](https://github.com/stagas/define-accessors/fork) or\n[edit](https://github.dev/stagas/define-accessors) and submit a PR.\n\nAll contributions are welcome!\n\n## License\n\nMIT © 2021\n[stagas](https://github.com/stagas)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstagas%2Fdefine-accessors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstagas%2Fdefine-accessors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstagas%2Fdefine-accessors/lists"}