@nuware/lenses
v0.1.15
Published
Functional Lenses
Downloads
7
Readme
Lenses
Install
npm install @nuware/lenses --save
or
<script defer src="https://unpkg.com/@nuware/lenses@latest/dist/lenses.umd.js"></script>
or
<script defer src="https://unpkg.com/@nuware/lenses@latest/dist/lenses.min.js"></script>
Usage
Browser
const { Prop, Get, Set, Over, Focus } = window.nuware.L
Node
const { Prop, Get, Set, Over, Focus } = require('@nuware/lenses')
or
import { Prop, Get, Set, Over, Focus } from '@nuware/lenses'
Example
const NameLens = Prop('name')
const NestedLens = Focus(['a', 'b', 'c'])
const a = Set(NameLens)('Value')({}) // {name: 'Value'}
const b = Get(NameLens)(a) // 'Value'
const c = Over(NameLens)((val) => val.toLowerCase()))(a) // {name: 'value'}
const d = Set(NestedLens)(true)(c) // {name: 'value', a: {b: {c: true}}}
const e = Over(NestedLens)((val) => !val))(d) // {name: 'value', a: {b: {c: false}}}
API
Comming soon...
Authors
- Dmitry Dudin [email protected]