{"id":13822980,"url":"https://github.com/akheron/optics-ts","last_synced_at":"2025-05-14T02:00:30.169Z","repository":{"id":37076172,"uuid":"232888504","full_name":"akheron/optics-ts","owner":"akheron","description":"Type-safe, ergonomic, polymorphic optics for TypeScript","archived":false,"fork":false,"pushed_at":"2025-04-30T15:36:11.000Z","size":2306,"stargazers_count":848,"open_issues_count":20,"forks_count":13,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-04-30T16:37:53.858Z","etag":null,"topics":["functional-programming","immutable","isomorphism","lens","optics","prism","traversal","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/akheron.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.old.md","contributing":null,"funding":null,"license":"LICENSE","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-01-09T19:30:35.000Z","updated_at":"2025-04-30T15:43:56.000Z","dependencies_parsed_at":"2022-06-24T19:29:48.563Z","dependency_job_id":"dee00ad9-efbf-4501-bf98-0692ba848fc9","html_url":"https://github.com/akheron/optics-ts","commit_stats":{"total_commits":483,"total_committers":7,"mean_commits":69.0,"dds":"0.33747412008281574","last_synced_commit":"583270548e003fab52b8f70c19f8023d303faceb"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akheron%2Foptics-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akheron%2Foptics-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akheron%2Foptics-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akheron%2Foptics-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akheron","download_url":"https://codeload.github.com/akheron/optics-ts/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254052658,"owners_count":22006716,"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","immutable","isomorphism","lens","optics","prism","traversal","typescript"],"created_at":"2024-08-04T08:02:27.563Z","updated_at":"2025-05-14T02:00:29.995Z","avatar_url":"https://github.com/akheron.png","language":"TypeScript","funding_links":[],"categories":["TypeScript","📦 Legacy \u0026 Inactive Projects"],"sub_categories":[],"readme":"# optics-ts\n\n[![Build](https://github.com/akheron/optics-ts/workflows/tests/badge.svg)](https://github.com/akheron/optics-ts/actions/workflows/tests.yml)\n\n`optics-ts` provides type-safe, ergonomic, polymorphic optics for TypeScript:\n\n- **Optics** allow you to read or modify values from deeply nested data\n  structures, while keeping all data immutable.\n- **Ergonomic**: Optics are composed with method chaining, making it easy and\n  fun!\n- **Polymorphic**: When writing through the optics, you can change the data\n  types in the nested structure.\n- **Type-safe**: The compiler will type check all operations you do. No `any`,\n  ever.\n\n➡ [Documentation](https://akheron.github.io/optics-ts) ⬅\n\n## Features\n\n`optics-ts` supports lenses, prisms, traversals, removing items from containers,\nand much more!\n\nSince optics-ts v2.2.0, there are two syntaxes for defining optics: method\nchaining (the default) and standalone optics (experimental). See\n[the docs](https://akheron.github.io/optics-ts) for more info!\n\n## Getting started\n\nInstallation:\n\n```\nnpm install optics-ts\n```\n\nor\n\n```\nyarn add optics-ts\n```\n\nHere's a simple example demonstrating how lenses can be used to drill into a\nnested data structure:\n\n```typescript\nimport * as O from 'optics-ts'\n\ntype Book = {\n  title: string\n  isbn: string\n  author: {\n    name: string\n  }\n}\n\n// Create a lens that focuses on author.name\nconst optic = O.optic_\u003cBook\u003e().prop('author').prop('name')\n\n// This is the input data\nconst input: Book = {\n  title: \"The Hitchhiker's Guide to the Galaxy\",\n  isbn: '978-0345391803',\n  author: {\n    name: 'Douglas Adams',\n  },\n}\n\n// Read through the optic\nO.get(optic)(input)\n// \"Douglas Adams\"\n\n// Write through the optic\nO.set(optic)('Arthur Dent')(input)\n// {\n//   title: \"The Hitchhiker’s Guide to the Galaxy\"\n//   isbn: \"978-0345391803\",\n//   author: {\n//     name: \"Arthur Dent\"\n//   }\n// }\n\n// Update the existing value through the optic, while also changing the data type\nO.modify(optic)((str) =\u003e str.length + 29)(input)\n// {\n//   title: \"The Hitchhiker’s Guide to the Galaxy\"\n//   isbn: \"978-0345391803\",\n//   author: {\n//     name: 42\n//   }\n// }\n```\n\nAnother example that converts all words longer than 5 characters to upper case:\n\n```typescript\nimport * as O from 'optics-ts/standalone'\n\nconst optic = O.optic\u003cstring\u003e().words().when(s =\u003e s.length \u003e= 5)\n\nconst input = 'This is a string with some shorter and some longer words'\nO.modify(optic)((s) =\u003e s.toUpperCase()(input))\n// \"This is a STRING with some SHORTER and some LONGER WORDS\"\n```\n\nSee the [documentation](https://akheron.github.io/optics-ts) for a tutorial and\na detailed reference of all supported optics.\n\n## Development\n\nRun `yarn` to install dependencies.\n\n### Running the test suite\n\nRun `yarn test`.\n\nFor compiling and running the tests when files change, run these commands in\nseparate terminals:\n\n```\nyarn build:test --watch\nyarn jest dist-test/ --watchAll\n```\n\n### Documentation\n\nYou need Python 3 to build the docs.\n\n```\npython3 -m venv venv\n./venv/bin/pip install mkdocs-material\n```\n\nRun a live reloading server for the documentation:\n\n```\n./venv/bin/mkdocs serve\n```\n\nOpen http://localhost:8000/ in the browser.\n\n### Releasing\n\n```\n$ yarn version --new-version \u003cmajor|minor|patch\u003e\n$ yarn publish\n$ git push origin main --tags\n```\n\nOpen https://github.com/akheron/optics-ts/releases, edit the draft release,\nselect the newest version tag, adjust the description as needed.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakheron%2Foptics-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakheron%2Foptics-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakheron%2Foptics-ts/lists"}