paqmind.data-lens
v0.6.0
Published
Data lens
Downloads
11
Readme
JavaScript data lens
Port of Laiff/data.lens great library. Immutable lenses over native JS data.
Differences:
- ES6 syntax
- Returns
undefined
for missed object keys following JS behavior - Can create nested structure at once
- Tests!
Usage
import Lens from "paqmind.data-lens";
let lens = Lens("username");
console.log(lens.get({})); // undefined
console.log(lens.get({username: "john"})); // "john"
console.log(lens.set({username: "john"}, "jack")); // {username: "jack"}
Rules
Reads
- Returns undefined for 1 missed key
- Throws for 2+ missed keys
Writes
- Throws for operations that can't be performed (setting keys to
Number
andString
types) - Creates desired structure in other cases