Port of Laiff/data.lens great library. Immutable lenses over native JS data.
- ES6 syntax
- Returns
undefined
for missed keys instead of throwing - Can create nested structure at once
- Tests!
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"}
- Returns undefined for 1 missed key
- Throws for 2+ missed keys
- Throws for operations that can't be performed (setting keys to
Number
andString
types) - Creates desired structure in other cases (mkdirp)