Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/blu-j/ts-lens
https://github.com/blu-j/ts-lens
Last synced: 18 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/blu-j/ts-lens
- Owner: Blu-J
- Created: 2017-09-29T14:40:21.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-11-01T12:22:11.000Z (2 months ago)
- Last Synced: 2024-11-08T17:05:04.116Z (about 2 months ago)
- Language: TypeScript
- Size: 1.46 MB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# Lens
![Node.js CI](https://github.com/Blu-J/ts-lens/workflows/Node.js%20CI/badge.svg)A lens is a getter/ setter for traversing a structure.
A lens is also composable with other lenses, allowing traversing via a object or using projections.
[functional-lenses](https://medium.com/@dtipson/functional-lenses-d1aba9e52254)Realize that the only dependency is the Object.assign from es6
### Using
```ts
import { idLens } from 'ts-lens';type MyShape = {
a?:{
b: {
c: string
}
}
}const withShape = idLens();
withShape.withAttrOr('a', { b: { c: ''}}).get({}) // ? { b: { c: ''}}
withShape.withAttrOr('a', { b: { c: ''}}).withAttr('b').withAttr('b').get({a:{
b: {
c: 'test
}
}}) // 'b'
```