{"id":21304930,"url":"https://github.com/maximilianmairinger/attachtoprototype","last_synced_at":"2025-03-15T19:26:29.185Z","repository":{"id":57186477,"uuid":"238062922","full_name":"maximilianMairinger/attachToPrototype","owner":"maximilianMairinger","description":"Attatch functions as non enumerable properties to the prototype of any object.","archived":false,"fork":false,"pushed_at":"2023-07-22T10:57:39.000Z","size":36,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-24T05:16:19.057Z","etag":null,"topics":["attach","enumerable","prototype"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/attatch-to-prototype","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/maximilianMairinger.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-02-03T21:10:47.000Z","updated_at":"2023-07-22T10:57:44.000Z","dependencies_parsed_at":"2025-01-22T08:41:58.450Z","dependency_job_id":"48f48d05-6893-4d87-9315-0664b3dbb8d2","html_url":"https://github.com/maximilianMairinger/attachToPrototype","commit_stats":null,"previous_names":["maximilianmairinger/attatchtoprototype"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maximilianMairinger%2FattachToPrototype","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maximilianMairinger%2FattachToPrototype/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maximilianMairinger%2FattachToPrototype/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maximilianMairinger%2FattachToPrototype/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maximilianMairinger","download_url":"https://codeload.github.com/maximilianMairinger/attachToPrototype/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243779610,"owners_count":20346743,"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":["attach","enumerable","prototype"],"created_at":"2024-11-21T16:16:24.354Z","updated_at":"2025-03-15T19:26:29.158Z","avatar_url":"https://github.com/maximilianMairinger.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Attach to prototype\r\n\r\nAttach functions as non enumerable properties to the prototype of any object.\r\n\r\n\u003e Please not that Attach to prototype is currently under development and not yet suited for production\r\n\r\n## Example\r\n\r\n### Generic\r\n\r\n```ts\r\nimport { constructAttachToPrototype } from \"attatch-to-prototype\"\r\n\r\nconst attachToArray = constructAttachToPrototype(Array.prototype/*, options*/)\r\nattachToArray(\"removeByValue\", function(value) {\r\n  const index = this.indexOf(value)\r\n  if (index === -1) return\r\n  this.splice(index, 1)\r\n})\r\n\r\nconst ar = [\"a\", \"b\", \"c\"]\r\n\r\nar.removeByValue(\"b\")\r\n\r\nconsole.log(ar) // [\"a\", \"c\"]\r\n\r\n```\r\n### Getter / Setter\r\n\r\n#### Attach\r\n\r\n```ts\r\nattachToArray(\"last\", {\r\n  get() {\r\n    return this[this.length-1]\r\n  }\r\n  set(to) {\r\n    return this[this.length-1] = to\r\n  }\r\n})\r\n\r\n\r\nlet ar = [1, 2, 3]\r\n\r\nar.last      // return 3\r\nar.last = 0  // return 0\r\n\r\nconsole.log(ar) // [1, 2, 0]\r\n```\r\n\r\n\r\n#### Apply\r\n\r\nJust a different syntax to access getter / setter. Use Attach / apply depending on your coding conventions.\r\n\r\n```ts\r\nimport { constructApplyToPrototype } from \"attatch-to-prototype\"\r\n\r\nconst attachToArray = constructApplyToPrototype(Array.prototype/*, options*/)\r\nattachToArray(\"last\", {\r\n  get() {\r\n    return this[this.length-1]\r\n  }\r\n  set(to) {\r\n    return this[this.length-1] = to\r\n  }\r\n})\r\n\r\n\r\nlet ar = [1, 2, 3]\r\n\r\nar.last()   // return 3\r\nar.last(0)  // return 0\r\n\r\nconsole.log(ar) // [1, 2, 0]\r\n```\r\n\r\nThe [generic](#Generic) functionality is also available on apply\r\n\r\n## Contribute\r\n\r\nAll feedback is appreciated. Create a pull request or write an issue.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaximilianmairinger%2Fattachtoprototype","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaximilianmairinger%2Fattachtoprototype","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaximilianmairinger%2Fattachtoprototype/lists"}