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

javascript-easy-object

v1.0.8

Published

A module for handling all the action related to object in one step with multi pattern traversal.

Downloads

8

Readme

Javascript Easy Object (JEO)

A module for handling all the action related to object in one step with multi pattern traversal.

Traversal Patterns

  • Direct method : This is direct access to value through the path string separated by the delimitor during the JEO object initialization. Eg. For accessing the value e in the object { a: 'b', c: { d: 'e' } }, you can use path as a\\.c\\.d In above the delimitor is \\. which is the default value. You can change it by passing delimitor that you want during JEO object initialization.

  • Filter method : This method allows you to pick certain key or pattern in the object. Eg.

object :

{
  a: {
    v: 'a',
    b: {
      z: 'z1'
    },
    c: {
      z: 'z2'
    },
    d: {
      z: 'z3
    }
  }
}

path : a.[b,d].z

output: ['z1', 'z3']
  • One level skip method : This method allows you to skip a level and search for the pattern that you want. Eg.
object :

{
  a: {
    v: 'a',
    b: {
      z: 'z1'
    },
    c: {
      z: 'z2'
    },
    d: {
      z: 'z3
    }
  }
}

path : a.?.z

output : ['z1', 'z2', 'z3']
  • Any level skip method : This method allows you to pick the value for pattern without even knowing the path. Eg.
object :

{
  a: {
    v: 'a',
    b: {
      z: 'z1'
    },
    c: {
      z: 'z2'
    },
    d: {
      z: 'z3
    }
  }
}

path : *.z

output: ['z1', 'z2', 'z3', 'z4']

Usage

Above patterns can be composed with each other or can be used separately as per your need. With the above patterns you can do following actions :

     1. Get
     2. Put
     3. Delete
     4. Rename
     5. Get path

Get, put, delete method are well known actions. Rename action allows you to rename the key that is present in the object. Get-path allows you to specify any path traversal and it will return the path from root to the found element. Its return type is array of string(if more than one value found on traversal it will return all paths for those values).

Get has isSafe option which lets to return value or null safely instead of getting error on unknown path. Its default value is false. It is the third option in get function.

snippet :

import JEO from 'javascript-easy-object'

const jeo = new JEO('.') //delimitor value is optional. Default value is '\\.'
const values = jeo.get(object, path, true) // 3rd param is for isSafe mode
const modifiedObject = jeo.put(object, path, value)
const propertyDeletedObject = jeo.delete(object, path)
const renamedObject = jeo.rename(object, path, newName)
const paths = jeo.getPath(object, path)

Conclusion

More options in JEO and patterns for traversal will be released in future. If you're interested to contribute, please feel free to fork and send in a Pull Request.