{"id":24278637,"url":"https://github.com/iagobelo/ts-loupe","last_synced_at":"2025-07-30T08:08:50.955Z","repository":{"id":42672483,"uuid":"281451243","full_name":"iagobelo/ts-loupe","owner":"iagobelo","description":"Composable getters and setters.","archived":false,"fork":false,"pushed_at":"2023-01-07T22:51:50.000Z","size":1416,"stargazers_count":12,"open_issues_count":9,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-19T18:53:43.059Z","etag":null,"topics":["functional-programming","lens","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/iagobelo.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":"2020-07-21T16:38:32.000Z","updated_at":"2022-12-08T18:13:22.000Z","dependencies_parsed_at":"2023-02-08T03:00:25.192Z","dependency_job_id":null,"html_url":"https://github.com/iagobelo/ts-loupe","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":"VitorLuizC/typescript-library-boilerplate","purl":"pkg:github/iagobelo/ts-loupe","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iagobelo%2Fts-loupe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iagobelo%2Fts-loupe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iagobelo%2Fts-loupe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iagobelo%2Fts-loupe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iagobelo","download_url":"https://codeload.github.com/iagobelo/ts-loupe/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iagobelo%2Fts-loupe/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266135685,"owners_count":23881803,"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":["functional-programming","lens","typescript"],"created_at":"2025-01-16T00:56:16.315Z","updated_at":"2025-07-30T08:08:50.929Z","avatar_url":"https://github.com/iagobelo.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TS Loupe\n\n[![Build Status](https://travis-ci.org/iagobelo/ts-loupe.svg?branch=master)](https://travis-ci.org/iagobelo/ts-loupe)\n[![License](https://badgen.net/github/license/iagobelo/ts-loupe)](./LICENSE)\n[![Library minified size](https://badgen.net/bundlephobia/min/ts-loupe)](https://bundlephobia.com/result?p=ts-loupe)\n[![Library minified + gzipped size](https://badgen.net/bundlephobia/minzip/ts-loupe)](https://bundlephobia.com/result?p=ts-loupe)\n\n## About\n\nLenses is a pattern used to read and update properties within an object.\n\n## Installation\n\nThis library is published in the NPM registry and can be installed using any compatible package manager.\n\n```sh\nnpm install ts-loupe --save\n\n# For Yarn, use the command below.\nyarn add ts-loupe\n```\n\n### Installation from CDN\n\nThis module has an UMD bundle available through JSDelivr and Unpkg CDNs.\n\n```html\n\u003c!-- For UNPKG use the code below. --\u003e\n\u003cscript src=\"https://unpkg.com/ts-loupe\"\u003e\u003c/script\u003e\n\n\u003c!-- For JSDelivr use the code below. --\u003e\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/ts-loupe\"\u003e\u003c/script\u003e\n```\n\n## API\n\n- [Lens](#lens)\n- [View](#view)\n- [Set](#set)\n- [Over](#over)\n- [Prop](#prop)\n- [Compose](#compose)\n\n### Lens\n\nIs a pair of two functions that abstracts the way of we access the requested field. In other words is a focus into some data structure.\n\nSignature:\n\n```typescript\ntype Getter\u003cA, B\u003e = (data: A) =\u003e B;\n\ntype Setter\u003cA, B\u003e = (value: B) =\u003e (data: A) =\u003e A;\n\ninterface Lens\u003cA, B\u003e {\n  get: Getter\u003cA, B\u003e;\n  set: Setter\u003cA, B\u003e;\n}\n```\n\nExample:\n\n```typescript\ntype User = { name: string; age: number };\n\nconst user: User = { name: 'Jerry Lee', age: 18 };\n\nconst getName = (user: User) =\u003e user.name;\nconst setName = (name: User['name']) =\u003e (data: User) =\u003e ({ ...data, name });\n\nconst nameLens = lens(getName, setName);\n\nnameLens.get(user); // returns: \"Jerry Lee\".\nnameLens.set('Leon Lan')(user); // returns: A new user with Leon Lan as the name.\n```\n\n### View\n\nReturns the data structure pointed to by the lens getter function.\n\nSignature:\n\n```typescript\ntype LensView = \u003cO, V\u003e(lens: Pick\u003cLens\u003cO, V\u003e, 'get'\u003e) =\u003e (data: O) =\u003e V;\n```\n\nExample:\n\n```typescript\ntype User = { name: string };\n\nconst user: User = { name: 'Len Lon' };\n\nconst getName = (user: User) =\u003e user.name;\nconst setName = (name: User['name']) =\u003e (data: User) =\u003e ({ ...data, name });\n\nconst nameLens = lens(getName, setName);\n\nview(nameLens)(user); //returns: \"Len Lon\".\n```\n\n### Set\n\nSet is used to 'set' a value into the data structure pointed to by the lens setter function.\n\nSignature:\n\n```typescript\ntype LensSet = \u003cO, V\u003e(\n  lens: Pick\u003cLens\u003cO, V\u003e, 'set'\u003e\n) =\u003e (value: V) =\u003e (data: O) =\u003e O;\n```\n\nExample:\n\n```typescript\ntype User = { name: string };\n\nconst user: User = { name: 'Jackie Chan' };\n\nconst getName = (user: User) =\u003e user.name;\nconst setName = (name: User['name']) =\u003e (data: User) =\u003e ({ ...data, name });\nconst nameLens = lens(getName, setName);\n\nlensSet(nameLens)('John Wick')(user); // returns: A new user with \"John Wick\" as the name.\n```\n\n### Over\n\nApplies the function to the given lens property and returns the result.\n\nSignature:\n\n```typescript\ntype LensOver = \u003cO, V\u003e(\n  lens: Lens\u003cO, V\u003e\n) =\u003e (fn: (value: V) =\u003e V) =\u003e (data: O) =\u003e O;\n```\n\nExample:\n\n```typescript\ntype User = { name: string };\n\nconst user: User = { name: 'Santino' };\nconst nameLens = prop\u003cUser\u003e('name');\n\nover(nameLens)(name =\u003e `${name} D'Antonio`)(user); // returns: A new user with \"Santino D'Antonio\" as the name.\n```\n\n### Prop\n\nCreates a lens focused on a given property.\n\nSignature:\n\n```typescript\ntype LensProp = \u003cO, K extends keyof O = keyof O\u003e(key: K) =\u003e Lens\u003cO, O[K]\u003e;\n```\n\nExample:\n\n```typescript\ntype User = { age: string; name: string };\nlensProp\u003cUser\u003e('age'); // returns: A lens instance focused on the age propertie.\n```\n\n### Compose\n\nCompose two lenses `Lens\u003cA, B\u003e` and `Lens\u003cB, C\u003e`, to produce a new lens `Lens\u003cA, C\u003e`.\n\nSignature:\n\n```typescript\ninterface LensCompose {\n  \u003cA, B, C\u003e(...lenses: [Lens\u003cA, B\u003e, Lens\u003cB, C\u003e]): Lens\u003cA, C\u003e;\n}\n```\n\nExample:\n\n```typescript\ntype User = {\n  pocket: {\n    money: number;\n  };\n};\n\nconst user: User = {\n  pocket: {\n    money: 3213\n  }\n};\n\nconst pocketLens = lensProp\u003cUser\u003e('pocket');\nconst moneyLens = lensProp\u003cUser['pocket']\u003e('money');\n\ncompose(\n  pocketLens,\n  moneyLens\n); // returns: A new lens focused on money propertie.\n```\n\n## License\n\nReleased under [MIT License](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiagobelo%2Fts-loupe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiagobelo%2Fts-loupe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiagobelo%2Fts-loupe/lists"}