to-function
Convert property access strings into functions
Installation
$ component install component/to-function
Examples
var toFunction = ;var fn = ;var user = name: first: 'Tobi' ;;// => "Tobi"
Dot access
var _ = ; var users = name: first: 'Tobi' name: first: 'Loki' name: first: 'Jane' name: first: 'Manny' ; var short = users;console;// => [ 'Tobi', 'Loki', 'Jane', 'Manny' ]
Equality
var _ = ; var tobi = name: first: 'Tobi' age: 2 ;var loki = name: first: 'Loki' age: 2 ;var jane = name: first: 'Jane' age: 6 ; var users = tobi loki jane; var user = users;console;// => { name: { first: 'Loki' }, age: 2 }
Expressions
var _ = ; var users = name: first: 'Tobi' age: 2 name: first: 'Loki' age: 2 name: first: 'Jane' age: 6 ; var oldPets = users;console;// => [ { name: { first: 'Jane' }, age: 6 } ]
Regular expressions
var _ = ; var users = 'Tobi' 'Loki' 'Jane'; var t = users; console;// => [ 'Tobi' ]
Nesting
var _ = ; var users = name: first: 'Tobi' last: 'Ferret' age: 2 name: first: 'Loki' last: 'Ferret' age: 2 name: first: 'Luna' last: 'Cat' age: 2 name: first: 'Manny' last: 'Cat' age: 3 ; // single-key var query = ; console;// => [ { name: { first: 'Luna', last: 'Cat' }, age: 2 },// { name: { first: 'Manny', last: 'Cat' }, age: 3 } ] // multi-key var query = ; console;// => [ { name: { first: 'Luna', last: 'Cat' }, age: 2 } ] // multi-level var query = ; console;// => [ { name: { first: 'Manny', last: 'Cat' }, age: 3 } ]
License
MIT