GithubHelp home page GithubHelp logo

libnested's Introduction

libnested

basic functions (map, each, get, set, keys) for nested objects.

api

each (object, iter(value, path), includeArrays?) => boolean

iterate over an object (depth first) and call iter with each value. path is an array with one or more items, which is the path to value. value will be any item which is not a {} object. Arrays are treated as values.

if iter returns false then each will stop traversing the object and return false also.

if includeArrays is true (defaults to false) then arrays encounted will be treated like objects. If includeArrays is not true, arrays will be treated like values.

map (object, iter(value, path) => nextValue, output, includeArrays?) => output

map over a nested object (depth first). A new object is returned (unless output is given), containing values returned by iter.

if includeArrays is true, the contents of arrays will be mapped, otherwise only the arrays themselves will be.

paths (object) => [path...]

return an array of paths into an object.

get(object, path, default) => value

get the value at path within object. if path does not exist in the object, return default.

path may be an array of strings or numbers, or a single string or number.

set(object, path, value)

set value at location path within object. If path is deeper than object goes, intermediate {}'s are added.

path may be an array of strings or numbers, or a single string or number.

object will be mutated.

clone (object)

return a new object with the same structure and primitive values as object

cyclic objects are not supported - will produce a RangeError (stackoverflow)

License

MIT

libnested's People

Contributors

dominictarr avatar ahdinosaur avatar jamieslome avatar arjunshibu avatar

Watchers

James Cloos avatar  avatar

Forkers

arjunshibu

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.