JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 453
  • Score
    100M100P100Q92992F
  • License MIT

Get/set a value in an Object/Array using a dot-delimited String or Array of keys.

Package Exports

  • jaunt

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (jaunt) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Jaunt.js npm Version Build Status Coverage Status

Get/set a value in an Object/Array using a dot-delimited String or Array of keys.

Usage

Get:

var obj = {
  foo: {
    bar: ['Hello', 'World']
  }
};

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

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

Set:

var obj = {
  foo: {
    bar: ['Hello', 'World']
  }
};

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

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

Note the syntax for referencing Array elements; it is foo.bar.0 rather than foo.bar[0].

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.

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 path to.

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/jaunt.min.js"></script>
  <script>
    // jaunt available here
  </script>
</body>

Changelog

  • 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