New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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 - npm Package Compare versions

Comparing version 0.0.2 to 1.0.0

8

index.js

@@ -1,2 +0,2 @@

module.exports = function(path) {
module.exports = function createPeek(path) {
if (typeof path !== 'string') {

@@ -6,5 +6,5 @@ throw new TypeError('path must be a string')

var parts = path.split('.')
return function(obj) {
return parts.reduce(function(obj, segment) {
if(obj === null || typeof obj !== 'object') {
return function peek(obj) {
return parts.reduce(function peekSegment(obj, segment) {
if (obj === null || obj === undefined) {
return undefined

@@ -11,0 +11,0 @@ }

{
"name": "peek",
"version": "0.0.2",
"version": "1.0.0",
"description": "Retrieve nested object properties easily.",

@@ -5,0 +5,0 @@ "main": "index.js",

var peek = require('./index')
, test = require('tape')
test('Test basic fetches', function(assert) {
test('basic fetches', function(assert) {
assert.strictEqual(peek('a')({a: 5}), 5)
assert.strictEqual(peek('1')([3, 7]), 7)
assert.strictEqual(peek('')({'': 6}), 6)

@@ -11,3 +12,3 @@

test('Test advanced fetches', function(assert) {
test('advanced fetches', function(assert) {
var find = peek('part.key.attribute')

@@ -29,3 +30,3 @@ , found = find({part: {key: {attribute: 'woop woop'}}})

test('Test example from README', function(assert) {
test('example from README', function(assert) {
var booty = peek("lower deck.captain's quarters.secret panel.treasure")

@@ -46,3 +47,3 @@ var pirate_ship = {

test('Test exception cases', function(assert) {
test('bad input cases', function(assert) {
[{}, true, undefined, null, 5, Infinity].forEach(function(bad_type) {

@@ -54,1 +55,31 @@ assert.throws(function() { peek(bad_type) }, TypeError)

})
test('accessing properties of primitives', function(assert) {
var primitives = [
"grilled cheese sandwiches"
, true
, false
, 15
]
var toString = peek('toString')
primitives.forEach(function testPrimitive(value) {
assert.doesNotThrow(function () { toString(value) })
assert.equal(toString(value).call(value), value.toString(), value + '.toString')
})
assert.end()
})
test('accessing properties of functions', function(assert) {
function f() {}
f.prototype.lettuce = 'optional'
var prototype = peek('prototype')
var lettuce = peek('prototype.lettuce')
assert.doesNotThrow(function () { prototype(f) })
assert.doesNotThrow(function () { lettuce(f) })
assert.strictEqual(prototype(f), f.prototype, 'prototype')
assert.strictEqual(lettuce(f), f.prototype.lettuce, 'prototype property')
assert.end()
})
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