npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

insides

v0.0.2

Published

Small JavaScript utility library for working with nested objects.

Downloads

9

Readme

Insides

Small JavaScript utility library for working with nested objects.

Installation

npm install insides --save

Quick Examples

  var buildObject = require("insides").buildObject;
  var reduceKV    = require("insides").reduceKV;
  var getIn       = require("insides").getIn;
  var setIn       = require("insides").setIn;

  var object = buildObject([
    [ [ "a", "b", "c" ], 1 ],
    [ [ "a", "b", "d" ], 2 ],
    [ [ "e" ], 3 ]
  ]);

  console.log(JSON.stringify(object, null, 2));
  // {
  //   "a": {
  //     "b": {
  //       "c": 1,
  //       "d": 2
  //     }
  //   },
  //   "e": 3
  // }

  var depth = 3;
  var sum = reduceKV(object, depth, function(memo, key, value) {
    return memo + value;
  }, 0);

  console.log("sum: " + sum);
  // sum: 3

  var abcValue = getIn(object, [ "a", "b", "c" ]);

  console.log("abc value: " + abcValue);
  // abc value: 1

  var abgValue = getIn(object, [ "a", "b", "g" ], "not found");

  console.log("abg value: " + abgValue);
  // abg value: not found

  var newObject = setIn(object, [ "a", "b", "g" ], 10);
  var newAbgValue = getIn(newObject, [ "a", "b", "g" ], "not found");

  console.log("new abg value: " + newAbgValue);
  // new abg value: 10

Functions

buildObject(objectMap)

Creates object from nestedArray:

var object = buildObject([ [ "a", 2 ] ]); // => { a: 2 }

var object = buildObject([ [ [ "a", "b" ], 2 ] ]); // => { a: { b: 2 } }

var object = buildObject([
  [ [ "a", "b" ], 2 ],
  [ [ "a", "c" ], 3 ]
]); // => { a: { b: 2, c: 3 } }

Argument is array of two-element arrays, first element is key map for the value, and second argument is the value;

getIn(object, keys, [notFound])

Returns value from nested object.

Arguments

  • object - object from which to return value
  • keys - keys array, could be a string or a array of keys: "a", [ "a", "b" ] or "a.b"
  • notFound - optional not found value, defaults to undefined

Differences from object.a.b.c:

If object.a does not exists this will thor a TypeError, getIn(object, [ "a", "b", "c" ]) returns undefined.

setIn(object, keys, value/callback);

Sets value in object for provided keys array. Overwrites everything that was in this key and returns new object (initial one is left unchanged).

Arguments

  • object - object to update value
  • keys - keys array, could be a string or a array of keys: "a", [ "a", "b" ] or "a.b"
  • value/callback - value or a callback to update the object:
    • value - overwrites object at given keys to provided value
    • callback - calls callback(key, value) and replaces object at given key path to return value of the callback

updateIn(object, keys, value/callback);

The same as setIn but updates the values instead of replacing them:

var object = { "a": { "b": 3, "c": 2 } };

var setObject = setIn(object, [ "a" ], { b: 5 });
// => { "a": { "b": 5 } }

var updateObject = setIn(object, [ "a" ], { b: 5 });
// => { "a": { "b": 5, "c": 2 } }

eachKV(object, [depth], callback)

Iterates over object calling callback on each matching value.

Arguments

  • object - object to iterate on
  • [depth] - optional depth argument, positive integer, defaults to 0
  • callback - callback to be run on every matching node: callback(key, value, object)

mapKV(object, [depth], callback)

Same as eachKV but returns new object instead of updating existing one, returns new object (initial one is left unchanged).

reduceKV(object, [depth], callback, [initialValue])

Reduces nested object using provided callback.

Arguments

  • object - object to reduce
  • [depth] - optional depth argument, positive integer, defaults to 0
  • callback - callback to be run on every matching node: callback(memo, key, value, object)
  • [initialValue] - optional initial value for first memo in callback