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 🙏

© 2025 – Pkg Stats / Ryan Hefner

ts-obj

v1.0.6

Published

ts-object - Object Manipulation Module for TypeScript

Readme

tsObject

ts-object is a forked project from aobj and is an object manipulation module for TypeScript

Setup

Install in your project using npm

npm install ts-object

Require in your file as

import tsObject from 'ts-obj';

Methods

extract

extract(obj: Object, keys: Array<String>) :Object

Extract keys/value into a new Object

const person = {name: 'Donald', lastname: 'Trump', favorite_color: 'red'}

tsObject.extract(person, ['name', 'lastname'])
// {name: 'Donald', lastname: 'Trump'}

has

has(obj: Object, keys: Array<String>) :Boolean

Check if an Object has certain keys

const person = {name: 'Donald', lastname: 'Trump', favorite_color: 'red'}

tsObject.has(person, 'lastname') // true
tsObject.has(person, ['name', 'lastname']) // true
tsObject.has(person, ['name', 'lastname', 'age']) // false

clone

clone(obj: Object) :Object

Deep Clones an Object

Without Cloning

const person = {name: 'Donald', lastname: 'Trump', favorite_color: 'red'}

const samePerson = person;
samePerson.name = 'Mike';

samePerson.name; // 'Mike'
person.name; // 'Mike'

With Deep Cloning

const person = {name: 'Donald', lastname: 'Trump', favorite_color: 'red'}

const anotherPerson = tsObject.clone(person);
anotherPerson.name = 'Mike';

anotherPerson.name; // 'Mike'
person.name; // 'Donald'

isEmpty

isEmpty(obj: Object) :Boolean

Check if an Object is empty

const person = {name: 'Donald', lastname: 'Trump', favorite_color: 'red'}

tsObject.isEmpty({}) // true

tsObject.isEmpty(person) // false

isObject

isObject(obj: Object) :Boolean

Check if a variable is an Object

const person = {name: 'Donald', lastname: 'Trump', favorite_color: 'red'}

tsObject.isObject(person) // true
tsObject.isObject({}) // true

tsObject.isObject('') // false
tsObject.isObject(new Number(1)) // false
tsObject.isObject(undefined) // false
tsObject.isObject(null) // false

map

map(obj: Object, action: (key: String, value: any) => { key: String; value: any; })) :Object

Like Array.map for Objects (For deep objects use traverse)

const person = {
    name: 'Donald',
    age: 10
}

const newPerson = tsObject.map(person, (key, value) => {
    if(key == 'age'){
        key = 'birthyear';
        value = 2020 - age;
    }
    return { key, value };
});

console.log(newPerson);
/*
{
    name: 'Donald',
    birthyear: 2010
}
*/

mapKeys

mapKeys(obj: Object, action: (key: String) => key: String)) :Object

Like Array.map for Objects Keys (For deep objects use traverseKeys)

const person = {
    name: 'Donald',
    age: 10
}

const newPerson = tsObject.map(person, (key) => {
    if(key == 'name') key = 'fullname';
    return key;
});

console.log(newPerson);
/*
{
    fullname: 'Donald',
    birthyear: 2010
}
*/

mapValues

mapValues(obj: Object, action: (value: any) => value: any)) :Object

Like Array.map for Objects Values (For deep objects use traverse)

const person = {
    name: 'Donald',
    age: 10
}

const newPerson = tsObject.mapValues(person, (value) => {
    if(typeof value == 'number') value += 50;
    return value;
});

console.log(newPerson);
/*
{
    name: 'Donald',
    age: 60
}
*/

traverse

traverse(obj: Object, action: (key: String, value: any) => { key: String; value: any; })) :Object

Like map but for deeply nested objects

const house = {
    rooms: {
        dinner_room: {
            m2: 30,
            chairs: {
                oldChair: {
                    m2: 0.2,
                    age: 5
                }
            }
        },
        bedroom: {
            m2: 30,
            gamerChair: {
                m2: 0.23,
                age: 1
            }
        }
    }
}

const newPerson = tsObject.traverse(person, (key, value) => {
    if(key == 'age'){
        key = 'year';
        value = 2020 - age;
    }
    return { key, value };
});

console.log(newPerson);
/*
{
    rooms: {
        dinner_room: {
            m2: 30,
            chairs: {
                oldChair: {
                    m2: 0.2,
                    year: 2015
                }
            }
        },
        bedroom: {
            m2: 30,
            gamerChair: {
                m2: 0.23,
                year: 2019
            }
        }
    }
}
*/

traverseKeys

traverseKeys(obj: Object, action: (key: String) => key: String)) :Object

Like map but for deeply nested objects

const house = {
    rooms: {
        a: {
            m2: 120
        },
        b: {
            m2: 112
        },
        c: {
            m2: 117
        }
    }
}

const newPerson = tsObject.traverseKeys(person, (key) => {
    if(key == 'a') key = 'Biggest_room';
    if(key == 'b') key = 'Small_room';
    if(key == 'c') key = 'Medium_room';
    return key;
});

console.log(newPerson);
/*
{
    rooms: {
        Biggest_room: {
            m2: 120
        },
        Small_room: {
            m2: 112
        },
        Medium_room: {
            m2: 117
        }
    }
}
*/

traverseValues

traverseValues(obj: Object, action: (value: String) => value: String)) :Object

Like map but for deeply nested objects

const house = {
    rooms: {
        a: {
            m2: 120
        },
        b: {
            m2: 112
        },
        c: {
            m2: 117
        }
    }
}

const newPerson = tsObject.traverseValues(person, (value) => {
    return value + 100;
});

console.log(newPerson);
/*
{
    rooms: {
        a: {
            m2: 220
        },
        b: {
            m2: 212
        },
        c: {
            m2: 217
        }
    }
}
*/

TODO:

Tests for:

  • [ ] deepFilter
  • [ ] deepFilterKeys
  • [ ] deepFilterValues
  • [ ] filter
  • [ ] filterKeys
  • [ ] filterValues

Examples for:

  • [ ] deepFilter
  • [ ] deepFilterKeys
  • [ ] deepFilterValues
  • [ ] filter
  • [ ] filterKeys
  • [ ] filterValues
  • [ ] invert
  • [ ] extractDefault