Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dot-finder

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dot-finder

dot-finder is using powerful dot notation to get values in JSON object

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

dot-finder

Build Status npm version

dot-finder is using powerful dot notation to get values in JSON object

Table of Contents

Install

$ npm install dot-finder

Usage

const dot = require("dot-finder");


/**
 * Object
 */

dot({ foo: { bar: "baz" } }, "foo.bar");
// or
dot({ foo: { bar: "baz" } }, "foo['bar']");
// => "baz"

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

dot({}, "notfound", "defaultValue");
// => "defaultValue"


/**
 * Array
 */

dot([[{ fruits: "apple" }, { fruits: "pineapple" }]], "[0][1].fruits");
// or
dot([[{ fruits: "apple" }, { fruits: "pineapple" }]], "0.1.fruits");
// => "pineapple"


/**
 * Advanced
 */

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

dot(data1, "authors.*.username");
// => ["tsuyoshiwada", "sampleuser", "foobarbaz"]

dot(data1, "authors.*.profile.age");
// => [24, 30, 33]


const data2 = [
  {
    posts: {
      tags: [
        { id: 1, slug: "news" },
        { id: 2, slug: "sports" },
        { id: 3, slug: "entertaiment" }
      ]
    }
  },
  {
    posts: {
      tags: [
        { id: 4, slug: "music" },
        { id: 5, slug: "it" },
        { id: 6, slug: "programming" }
      ]
    }
  }
];

dot(data2, "*.posts.tags.*.slug");
// => ["news", "sports", "entertaiment", "music", "it", "programming"]

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

License

MIT © tsuyoshiwada

Keywords

FAQs

Package last updated on 20 Jan 2017

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc