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
npm install optics-ts
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
786 Stars
485 Commits
9 Forks
12 Watching
6 Branches
6 Contributors
Updated on 28 Nov 2024
TypeScript (99.38%)
JavaScript (0.55%)
Shell (0.07%)
Cumulative downloads
Total Downloads
Last day
-9.4%
23,858
Compared to previous day
Last week
1.6%
142,483
Compared to previous week
Last month
-19.4%
618,613
Compared to previous month
Last year
590.8%
4,746,548
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
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
SAST tool is run on all commits
Details
Reason
0 existing vulnerabilities detected
Reason
3 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 2
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 2024-11-25
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