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

pathly

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pathly

Get value of an object using an array.

  • 1.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

pathly v 1.0.6

A simple method to safely access nested values in an object.

Installation

Using NPM

npm install pathly

Using Yarn

yarn install pathly

Import Module ES6

import getVal from 'pathly'; 

Import Module CommonJS

const getVal = require('pathly'); 

Usage

Once installed, it can be used in js as

  const get = getVal;
  const result = {
    books: {
      chapters: [
        { title: 'Hello World!', authors: [ 'Jason fried', 'Paul Kinlan' ] },
        { title: 'JS For Beginners', authors: [ 'Yehuda Katz' ] },
        { title: 'Node For Beginners', authors: [] },
        { title: 'Software Development', authors: [ 'Martin Fowler', 'Donald Knuth', 'Linus Torvalds'] },
      ]
    }
  }

  const getPosts = get(['books', 'chapters'])
  console.log('=====correct======', get(['books', 'chapters', 0, 'authors'], result));
  console.log('=====wrong key======', get(['books', 'chapter', 0, 'authors'], result));
  console.log('=====chaining======', pathly(['books', 'chapters'], result).map(pathly(['authors'])));
  console.log('=====curryd======', getPosts(result));
  console.log('=====path undefined======', get(undefined, result));
  console.log('=====path empty======', get([], result));
  console.log('=====path String======', get('', result));
  console.log('=====path object======', get({}, result));

Keywords

FAQs

Package last updated on 02 Apr 2018

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