Socket
Socket
Sign inDemoInstall

diggs

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    diggs

Safely extract deeply nested properties – because safety is number one priority


Version published
Weekly downloads
2
Maintainers
1
Install size
6.27 kB
Created
Weekly downloads
 

Changelog

Source

1.0.0

  • First release

Readme

Source

diggs

A lightweight utility to safely dig into nested properties – because safety is number one priority.

Installation

To install diggs:

npm install --save diggs

That's it!

Why diggs?

diggs allows you to access deeply nested properties without having to worry about undefined properties, null, or TypeErrors.

// Uncaught TypeError: Cannot read property 'foo' of null
// Uncaught TypeError: Cannot read property 'foo' of undefined

Examples

import { get } from 'diggs';

let data = {
  a: {
    b: {
      c: ['foo', { d: 'bar' }],
    }
  },
  z: null,
}

// retrieve deeply nested properties
get(data, 'a.b.c')      // => ['foo', { d: 'bar' }]

// even array items
get(data, 'a.b.c[1].d') // => 'bar'

// returns undefined instead of throwing TypeErrors
get(data, 'z.a')        // => undefined

// returns a default value
get(data, 'z.a', false) // => false

API

get(object, path, defaultValue)

Returns the value at the specified path of object. If the value is not found (undefined), defaultValue will be returned instead.

Arguments
  • object (Object): The object to query
  • path (String): The path of the property to get
  • [defaultValue] (Any): The value returned for undefined values

Contributing

  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
  6. ...
  7. Profit

License

MIT

Keywords

FAQs

Last updated on 07 Feb 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