delvec

0.0.8 • Public • Published

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

Dependents (2)

Package Sidebar

Install

npm i delvec

Weekly Downloads

1

Version

0.0.8

License

ISC

Last publish

Collaborators

  • luk3thomas