Socket
Socket
Sign inDemoInstall

dot-wild-tiny

Package Overview
Dependencies
2
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    dot-wild-tiny

Use powerful dot notation (dot path + wildcard) to access properties of JSON


Version published
Weekly downloads
11
increased by57.14%
Maintainers
1
Created
Weekly downloads
 

Changelog

Source

v1.0.0

2017-12-17

Breaking changes

  • Add get, forEach, map methods.
  • The export format has been changed.

Readme

Source

dot-wild-tiny

Build Status npm version

Use powerful dot notation (dot path + wildcard) to access properties of JSON.
If you need to do set or delete, use dot-wild which has all functions.

Table of Contents

Install

$ npm install dot-wild-tiny --save

# or

$ yarn add dot-wild-tiny

Usage

import * as dot from 'dot-wild-tiny';


/**
 * Getter
 */
dot.get({ foo: { bar: 'baz' } }, 'foo.bar');
// => 'baz'

dot.get({ 'foo.bar': 'baz' }, 'foo\\.bar');
// => 'baz'

dot.get({ 'foo.bar': 'baz' }, 'notfound', 'default');
// => 'default'

const authorData = {
  authors: [
    { username: 'tsuyoshiwada', profile: { age: 24 } },
    { username: 'sampleuser', profile: { age: 30 } },
    { username: 'foobarbaz', profile: { age: 33 } }
  ]
};

dot.get(authorData, 'authors.*.username');
// => ['tsuyoshiwada', 'sampleuser', 'foobarbaz']

dot.get(authorData, 'authors.*.profile.age');
// => [24, 30, 33]


/**
 * Collection helpers (forEach, map)
 */
dot.forEach(postData, 'data.posts.*.id', (value, key, context, path, data) => {
  // value   => 1, 2
  // key     => 'id', 'id'
  // context => { id: 1, title: 'post 1' }, { id: 2, title: 'post 2' }
  // path    => 'data.posts.0.id', 'data.posts.1.id'
  // data    => postData...
});

dot.map(postData, 'data.tags.*.name', (value, key, context, path, data) => {
  return `${dot.get(data, path)} === ${value} (${key})`;
});
// => ['tag 1 === tag 1 (name)', 'tag 2 === tag 2 (name)']

Contribute

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Bugs, feature requests and comments are more than welcome in the issues.

License

MIT © tsuyoshiwada

Keywords

FAQs

Last updated on 17 Dec 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc