Skip to content

A small curried library for fetching properties from objects

Notifications You must be signed in to change notification settings

luk3thomas/delvec

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

delvec

A small curried library for fetching properties from objects.

Get properties from JSON.

json = {
  "name": "Foo"
};

var fromJson = delvec(json);

fromJson('name');    // 'Foo'
fromJson('a.b.c');   // undefined

It also works in reverse order.

json = [
  { "name": "Foo" },
  { "name": "Bar" },
  { "name": "Baz" }
];

var name = delvec('name');

name(json[0]);    // 'Foo'
name(json[1]);    // 'Bar'
name(json[2]);    // 'Baz'

Set defaults if delvec is empty handed.

json = [
  { "name": "Foo", order: 1 },
  { "name": "Bar", order: 2 },
  { "name": "Baz" }
];

var order = delvec.or(0, 'order');

order(json[0]);    // 1
order(json[1]);    // 2
order(json[2]);    // 0

About

A small curried library for fetching properties from objects

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published