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

easy-object-selector

v1.3.0

Published

Utility to manage an object property using simple 'a.b.c' paths.

Readme

easy-object-selector Easy Object Selector Build Status

easy-object-selector

Utility to manage an object property using simple 'a.b.c' paths (with dot–notation).

Install

npm install easy-object-selector

Paths

| Path | Description | | :-------------- | :---------------------- | | a.b.c | The value of 'c' | | ["a", "b", "c"] | The value of 'c' | | a.d.1.e | The second value of 'e' | | a.d.*.e | All values of 'e' | | a.d.first().e | The first value of 'e' | | a.d.last().e | The last value of 'e' |

Examples

const selector = require("easy-object-selector");
const obj = {
     a: {
         b: {
             c: "val1"
         },
         d: [
                 {
                     e: "val2"
                 },
                 {
                     e: "val3"
                 }
         ]
     }
};
const select = selector.select;
select(obj, "a.b.c"); // => "val1"
select(obj, ["a", "b", "c"]); // => "val1"
select(obj, "a.b.x", "defValue"); // => "defValue"
select(obj, "a.d.0.e"); // => "val2"
select(obj, "a.d.*.e"); // => ["val2", "val3"]
select(obj, "a.d.first().e"); // => "val2"
select(obj, "a.d.last().e"); // => "val3"

const has = selector.has;
has(obj, "a.b.c"); // => true

const keys = selector.keys;
keys(obj, "a"); // => ["b", "d"]

const put = selector.put;
const o = {};
put(o, "a.b.c", "val1") // => {a:{b:{c:"val1"}}}

const wrapper = selector.wrap(obj);
wrapper.get("a.b.c"); // => "val1"
wrapper.has("a.b.c"); // => true
wrapper.keys("a"); // => ["b", "d"]

const o2 = {};
const wrapper2 = selector.wrap(o2);
wrapper2.put("a.b.c", "val1"); // => {a:{b:{c:"val1"}}}

API

Table of Contents

select

Get the value of the selected property if it exists.

Parameters

Examples

const selector = require("easy-object-selector");
const select = selector.select;
const obj = {
     a: {
         b: {
             c: "val1"
         },
         d: [
                 {
                     e: "val2"
                 },
                 {
                     e: "val3"
                 }
         ]
     }
};
select(obj, "a.b.c"); // => "val1"
select(obj, ["a", "b", "c"]); // => "val1"
select(obj, "a.b.x"); // => undefined
select(obj, "a.b.x", "defValue"); // => "defValue"
select(obj, "a.d.0.e"); // => "val2"
select(obj, "a.d.1.e"); // => "val3"
select(obj, "a.d.*.e"); // => ["val2", "val3"]
select(obj, "a.d.first().e"); // => "val2"
select(obj, "a.d.last().e"); // => "val3"

Returns (Object | Array | String | Number | Boolean | undefined)

has

Check if the selected property exists.

Parameters

Examples

const selector = require("easy-object-selector");
const has = selector.has;
const obj = {
     a : {
         b : {
             c: "val1"
         }
     }
};
has(obj, "a.b.c"); // => true
has(obj, ["a", "b", "c"]); // => true
has(obj, "a.b.x"); // => false

Returns Boolean

keys

Returns an array of keys.

Parameters

Examples

const selector = require("easy-object-selector");
const keys = selector.keys;
const obj = {
     a : {
         b : {
             c: "val1",
             d: "val2",
             e: "val3",
         }
     }
};
keys(obj, "a.b"); // => ["c", "d", "e"]
keys(obj, ["a", "b"]); // => ["c", "d", "e"]
keys(obj, "a.b.x"); // => []
keys(obj, "a.b.x", ["a", "b"]); // => ["a", "b"]

Returns Array

put

Put the value in the object property.

Parameters

Examples

const selector = require("easy-object-selector");
const put = selector.put;
const o = {};
put(o, "a.b.c", "val1") // => {a:{b:{c:"val1"}}}
const o2 = {};
put(o2, ["a", "b", "c"], "val1") // => {a:{b:{c:"val1"}}}

Returns Object

wrap

Creates a new ObjectWrapper

Parameters

Examples

const selector = require("easy-object-selector");
const obj = {
     a: {
         b: {
             c: "val1"
         }
     }
};
const wrapper = selector.wrap(obj);
wrapper.get("a.b.c"); // => "val1"
wrapper.get(["a", "b", "c"]); // => "val1"

Returns ObjectWrapper wrapper

ObjectWrapper

Object wrapper

Parameters

get

Get the value of the selected property if it exists.

Parameters

Examples

const selector = require("easy-object-selector");
const obj = {
     a: {
         b: {
             c: "val1"
         },
         d: [
                 {
                     e: "val2"
                 },
                 {
                     e: "val3"
                 }
         ]
     }
};
const wrapper = selector.wrap(obj);
wrapper.get("a.b.c"); // => "val1"
wrapper.get(["a", "b", "c"]); // => "val1"
wrapper.get("a.b.x"); // => undefined
wrapper.get("a.b.x", "defValue"); // => "defValue"
wrapper.get("a.d.0.e"); // => "val2"
wrapper.get("a.d.1.e"); // => "val3"
wrapper.get("a.d.*.e"); // => ["val2", "val3"]
wrapper.get("a.d.first().e"); // => "val2"
wrapper.get("a.d.last().e"); // => "val3"

Returns (Object | Array | String | Number | Boolean | undefined)

has

Check if the selected property exists.

Parameters

Examples

const selector = require("easy-object-selector");
const obj = {
     a : {
         b : {
             c: "val1"
         }
     }
};
const wrapper = selector.wrap(obj);
wrapper.has("a.b.c"); // => true
wrapper.has(["a", "b", "c"]); // => true
wrapper.has("a.b.x"); // => false

Returns Boolean

keys

Returns an array of keys.

Parameters

Examples

const selector = require("easy-object-selector");
const obj = {
     a : {
         b : {
             c: "val1",
             d: "val2",
             e: "val3",
         }
     }
};
const wrapper = selector.wrap(obj);
wrapper.keys("a.b"); // => ["c", "d", "e"]
wrapper.keys(["a", "b"]); // => ["c", "d", "e"]
wrapper.keys("a.b.x"); // => []
wrapper.keys("a.b.x", ["a", "b"]); // => ["a", "b"]

Returns Array

put

Put the value in the object property.

Parameters

Examples

const selector = require("easy-object-selector");
const o = {};
const wrapper = selector.wrap(o);
wrapper.put("a.b.c", "val1") // => {a:{b:{c:"val1"}}}

Returns Object