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 🙏

© 2024 – Pkg Stats / Ryan Hefner

deep-property-access

v1.0.1

Published

Deep property access by dot separated string or key array

Downloads

7

Readme

Deep Property Access

Deep property access function. Access properties by path. For arrays just include the index in the path (see example, property 4).

Usage

Use the library like this:

npm install --save deep-property-access
var DeepPropertyAccess = require('deep-property-access');

Retrieve a value from an arbitrary depth property:

var value = DeepPropertyAccess('path.to.my.key');

or

var value = DeepPropertyAccess( ['path', 'to', 'my', 'key' ] );

If the path cannot be resolved to a valid key the return value is undefined.

Example

Running the included example file

var util = require('util');
var deep = require('../');

var testObject = {
  key1: {
    subkey1: "Some string",
    subkey2: true
  },
  key2: {
    subkey3: {
      subsubkey1: 42
    }
  },
  key3: [ 24, -10, true ]
}

console.log("Object:\n" + util.inspect(testObject, { depth: 8, colors: true }) + "\n");

var property1 = "key1.subkey2";
var property2 = [ "key2", "subkey3", "subsubkey1" ];
var property3 = "key2";
var property4 = "key3.1";

console.log("Property '" + property1 + "': " + deep(testObject, property1));
console.log("Property '[ '" + property2.join("', '") + "' ]': " + deep(testObject, property2));
console.log("Property '" + property3 + "': " + util.inspect(deep(testObject, property3), { depth: 8, colors: true }));
console.log("Property '" + property4 + "': " + deep(testObject, property4));

will result in this:

Object:
{ key1: { subkey1: 'Some string', subkey2: true },
  key2: { subkey3: { subsubkey1: 42 } },
  key3: [ 24, -10, true ] }

Property 'key1.subkey2': true
Property '[ 'key2', 'subkey3', 'subsubkey1' ]': 42
Property 'key2': { subkey3: { subsubkey1: 42 } }
Property 'key3.1': -10

License

This project is licensed as LGPLv3, the license file is included in the project directory.

Find this project on: GitHub or npm

Copyright 2015 Stefan Hamminga - prjct.net