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

@mountaingapsolutions/objectutil

v1.1.3

Published

A handy collection of methods related to manipulating objects.

Readme

objectutil

A handy collection of methods related to manipulating objects.

clone

Performs a deep copy of the provided input. Supported data types at the moment are: Object, Array, Date, string, number, boolean, and function.

const {clone} = require('@mountaingapsolutions/objectutil');

// Cloneable data types: Object, Array, string, number, boolean, and
// function.
clone([
    {name: 'John'},
    ['nested array'],
    'foobar',
    42,
    true,
    () => console.log('hello world')
]);

filter

Similar to Array.filter, but for objects. The filter function will iterate through every key in the object.

const {filter} = require('@mountaingapsolutions/objectutil');

filter({key1: 'foo', key2: 'bar', key3: 'baz'}, (key) => key !== 'key2');
// => {key1: 'foo', key3: 'baz'}

toArray

Converts an object to an array. The optional 2rd argument is a custom mapper function to return just a specific subset of each element.

const {toArray} = require('@mountaingapsolutions/objectutil');

const input = {
    'MA': {name: 'Massachusetts'},
    'ME': {name: 'Maine'},
    'NH': {name: 'New Hampshire'}
};

toArray(input)
// => [{name: 'Massachusetts'}, {name: 'Maine'}, {name: 'New Hampshire'}]

toArray(input, (state) => state.name)
// => ['Massachusetts', 'Maine', 'New Hampshire']

toObject

Converts an array to an object. The 2nd argument is the key name to use. Defaults to a string index if not provided. Optional 3rd argument is a custom mapper function to return just a specific subset of the object.

const {toObject} = require('@mountaingapsolutions/objectutil');

const input = [
    {code: 'MA', name: 'Massachusetts'},
    {code: 'ME', name: 'Maine'},
    {code: 'NH', name: 'New Hampshire'}
];

toObject(input)
/**
{
    '0': {code: 'MA', name: 'Massachusetts'},
    '1': {code: 'ME', name: 'Maine'},
    '2': {code: 'NH', name: 'New Hampshire'}
}
**/

toObject(input, 'code')
/**
{
    MA: {code: 'MA', name: 'Massachusetts'},
    ME: {code: 'ME', name: 'Maine'},
    NH: {code: 'NH', name: 'New Hampshire'}
}
**/

toObject(input, 'code', (state) => state.name))
/**
{
    MA: 'Massachusetts',
    ME: 'Maine',
    NH: 'New Hampshire'
}
**/

safeWrap / unwrap

Wraps an object to safely return any object property, ignoring any undefined errors. This is analogous to using the existential operator in TypeScript.

const {safeWrap, unwrap} = require('@mountaingapsolutions/objectutil');

const input = {a: {b: {c: {d: 'value'}}}};
const wrappedInput = safeWrap(input);
unwrap(wrappedInput.a.b.c.d.e.f.g.h)
// => undefined
unwrap(wrappedInput.a.b.c.d)
// => 'value'

updateIn

Clones the provided array of objects and attempts to update the old object with the updated object by the specified key. If key is not provided, defaults to 'id'.

const {updateIn} = require('@mountaingapsolutions/objectutil');

const original = [{
    uuid: 0,
    label: 'foo'
    }, {
    uuid: 1,
    label: 'quz',
    value: true,
    date: ''
}];
const item = {
    uuid: 1,
    label: 'bar',
    value: false,
    attribute: ''
};
updateIn(original, item, 'uuid');
/** =>
{
    uuid: 1,
    label: 'bar',
    value: false,
    date: '',
    attribute: ''
});
*/

updateOrAppend

Same as updateIn, but if the object to update is not in the array, it will be appended to the cloned array.