Gathering detailed insights and metrics for optics-ts
Gathering detailed insights and metrics for optics-ts
Gathering detailed insights and metrics for optics-ts
Gathering detailed insights and metrics for optics-ts
monocle-ts
A porting of scala monocle library to TypeScript
@optics-xyz/ts-interface
Optics contract typechain gens
ts-optics
Tired of updating nested JS objects? Not convinced that optional chaining isn't a filthy hack? This one's for you.
spectacles-ts
Practical Optics • Unfancy monocle-ts 🧐
npm install optics-ts
Typescript
Module System
TypeScript (99.38%)
JavaScript (0.55%)
Shell (0.07%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
874 Stars
486 Commits
13 Forks
11 Watchers
8 Branches
7 Contributors
Updated on Jul 14, 2025
Latest Version
2.4.1
Package Id
optics-ts@2.4.1
Unpacked Size
133.86 kB
Size
22.72 kB
File Count
121
Published on
Jul 10, 2023
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
optics-ts
provides type-safe, ergonomic, polymorphic optics for TypeScript:
any
,
ever.➡ Documentation ⬅
optics-ts
supports lenses, prisms, traversals, removing items from containers,
and much more!
Since optics-ts v2.2.0, there are two syntaxes for defining optics: method chaining (the default) and standalone optics (experimental). See the docs for more info!
Installation:
npm install optics-ts
or
yarn add optics-ts
Here's a simple example demonstrating how lenses can be used to drill into a nested data structure:
1import * as O from 'optics-ts' 2 3type Book = { 4 title: string 5 isbn: string 6 author: { 7 name: string 8 } 9} 10 11// Create a lens that focuses on author.name 12const optic = O.optic_<Book>().prop('author').prop('name') 13 14// This is the input data 15const input: Book = { 16 title: "The Hitchhiker's Guide to the Galaxy", 17 isbn: '978-0345391803', 18 author: { 19 name: 'Douglas Adams', 20 }, 21} 22 23// Read through the optic 24O.get(optic)(input) 25// "Douglas Adams" 26 27// Write through the optic 28O.set(optic)('Arthur Dent')(input) 29// { 30// title: "The Hitchhiker’s Guide to the Galaxy" 31// isbn: "978-0345391803", 32// author: { 33// name: "Arthur Dent" 34// } 35// } 36 37// Update the existing value through the optic, while also changing the data type 38O.modify(optic)((str) => str.length + 29)(input) 39// { 40// title: "The Hitchhiker’s Guide to the Galaxy" 41// isbn: "978-0345391803", 42// author: { 43// name: 42 44// } 45// }
Another example that converts all words longer than 5 characters to upper case:
1import * as O from 'optics-ts/standalone' 2 3const optic = O.optic<string>().words().when(s => s.length >= 5) 4 5const input = 'This is a string with some shorter and some longer words' 6O.modify(optic)((s) => s.toUpperCase()(input) 7// "This is a STRING with some SHORTER and some LONGER WORDS"
See the documentation for a tutorial and a detailed reference of all supported optics.
Run yarn
to install dependencies.
Run yarn test
.
For compiling and running the tests when files change, run these commands in separate terminals:
yarn build:test --watch
yarn jest dist-test/ --watchAll
You need Python 3 to build the docs.
python3 -m venv venv
./venv/bin/pip install mkdocs-material
Run a live reloading server for the documentation:
./venv/bin/mkdocs serve
Open http://localhost:8000/ in the browser.
$ yarn version --new-version <major|minor|patch>
$ yarn publish
$ git push origin main --tags
Open https://github.com/akheron/optics-ts/releases, edit the draft release, select the newest version tag, adjust the description as needed.
No vulnerabilities found.
Reason
all changesets reviewed
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
2 existing vulnerabilities detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 2
Details
Reason
1 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More