savejs

1.0.4 • Public • Published

Build Status npm version Dependency Status Dependency Status Sauce Test Status

SaveJS

A simple javascript util library.

APIs

get(object, path, defaultValue)#

Given an object and a path, return the path value of the object.

save.get({a: 'hello'}, 'a') => 'hello'
save.get({a: {b:'world'}}, 'a.b') => 'world'
save.get({a: {b:'world'}}, 'a.b.c') => undefined
save.get({a: {b:'world'}}, 'a.b.c', 'jack') => 'jack'

hasOwn

Given an object and a path, return if the object contains the path.

save.hasOwn({a: 'hello'}, 'a') => true
save.hasOwn({a: {b:'world'}}, 'a.b') => true
save.hasOwn({a: {b:'world'}}, 'a.b.c') => false
save.hasOwn({a: {b: false}}, 'a.b') => true
 

paths

Given an object/array, return all its paths and corresponding values.

save.paths({a:1, b: { c: 2, d: 3}, f: 7})
 
=>
 
[
    { path: ['a'], value: 1 },
    { path: ['b', 'c'], value: 2 },
    { path: ['b', 'd'], value: 3 },
    { path: ['f'], value: 7 }
]
 
 
// you may also want to concat the path with '.', 
// just put it as the second parameter
 
save.paths({a:1, b: { c: 2, d: 3}, f: 7}, '.')
 
=>
 
[
    { path: 'a', value: 1 },
    { path: 'b.c', value: 2 },
    { path: 'b.d', value: 3 },
    { path: 'f', value: 7 }
]
 

License

MIT

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.4
    0
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.4
    0
  • 1.0.3
    0
  • 1.0.1
    0
  • 1.0.0
    0

Package Sidebar

Install

npm i savejs

Weekly Downloads

0

Version

1.0.4

License

MIT

Last publish

Collaborators

  • ssnau