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

peek

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

peek

Retrieve nested object properties easily.

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
209
decreased by-20.53%
Maintainers
1
Weekly downloads
 
Created
Source

peek

Access deeply nested object properties using a path string.

Advantages over literal access

  • The expression obj.foo.bar will throw a TypeError if obj.foo is not an object. peeking will yield undefined, instead.
  • Wacky property names: obj['the question is']["'doctor who?'"] is verbose compared to peeking with the question is.'doctor who?'.

Other uses for peek

  • Accessing variably-nested properties programmatically.
  • Accessing the same nested property of multiple objects.

Usage


  var peek = require('peek')

  var booty = peek("lower deck.captain's quarters.secret panel.treasure")
  var pirate_ship = {
    'lower deck': {
      "captain's quarters": {
        'secret panel': {
          treasure: '5000 gold'
        }
      }
    }
  }

  console.log(booty(pirate_ship)) // == "5000 gold"

Limitations

Property names may not contain dots, as all dots are interpreted as object key separators.

Running the tests

  $ git clone https://github.com/adamdicarlo/peek.git # clone or fork
  $ cd peek
  $ npm install
  $ npm test

License

MIT

Keywords

FAQs

Package last updated on 02 Dec 2013

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