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

jaunt

v1.3.0

Published

Get or set a value in an object/array using a dot-delimited string or array of keys.

Downloads

4,009

Readme

Jaunt.js npm Version Build Status Coverage Status

Get or set a value in an object/array using a dot-delimited string or array of keys.

API

jaunt.get(obj, path)

Returns the value in obj corresponding to path. Returns undefined if path does not exist.

  • obj — An object or array.
  • path — A dot-delimited string of keys, or an array of keys.
var obj = {
  foo: {
    bar: ['Hello', 'World'],
    baz: 'Goodbye'
  }
};

jaunt.get(obj, 'foo.bar'); //=> ['Hello', 'World']
jaunt.get(obj, 'foo.baz'); //=> 'Goodbye'

jaunt.get(obj, 'foo.bar.0'); //=> 'Hello'
jaunt.get(obj, 'foo.baz.0'); //=> 'Goodbye'

jaunt.get(obj, ['foo', 'bar', 0]); //=> 'World'
jaunt.get(obj, ['foo', 'baz', 0]); //=> 'Goodbye'

jaunt.get(obj, 'invalid'); //=> undefined

There can be a trailing “0” in path if it corresponds to a leaf node. So, in the example above, the paths foo.baz and foo.baz.0 are equivalent.

jaunt.set(obj, path, val)

Sets the element corresponding to path in the obj to the specified val. Any “intermediate” elements in the path will be created if they do not exist. Returns the modified obj.

  • obj — An object or array.
  • path — A dot-delimited string of keys, or an array of keys.
  • val — The value to set the element corresponding to path.
var obj = {
  foo: {
    bar: ['Hello', 'World']
  }
};

jaunt.set(obj, 'foo.bar.0', 'Hola');
/* =>
 * {
 *   foo: {
 *     bar: ['Hola', 'World']
 *   }
 * }
 */

jaunt.set(obj, 'baz', 'Shiny!');
/* =>
 * {
 *   foo: {
 *     bar: ['Hola', 'World']
 *   },
 *   baz: 'Shiny!'
 * }
 */

Installation

Install via npm:

$ npm i --save jaunt

Install via bower:

$ bower i --save yuanqing/jaunt

To use Jaunt in the browser, include the minified script in your HTML:

<body>
  <!-- ... -->
  <script src="path/to/dist/jaunt.min.js"></script>
  <script>
    // jaunt available here
  </script>
</body>

Changelog

  • 1.3.0
    • Allow trailing “0” in path for the get method
  • 1.2.0
    • Migrate tests to tape
  • 1.1.3
    • Expose module for use in the browser
    • Add minified version of the module
    • Add bower.json
  • 1.0.0
    • Initial release

License

MIT license