Socket
Socket
Sign inDemoInstall

get-prop

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

get-prop - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

2

bower.json
{
"name": "getprop",
"main": "getprop.js",
"version": "0.0.3",
"version": "0.0.4",
"homepage": "https://github.com/miguelmota/getprop",

@@ -6,0 +6,0 @@ "authors": [

(function(root) {
function getProp(o, s) {
function getProp(o, s, d) {
if (!o || !s) return;
if (!(typeof o === 'object' || o instanceof Object)) return;
if (!(typeof s === 'string' || s instanceof String)) return;
var props = s.match(/(\[(.*?)\]|[0-9a-zA-Z_]+)/gi).map(function(m) { return m.replace(/[\[\]]/gi,''); });
var props = s.match(/(\[(.*?)\]|[0-9a-zA-Z_$]+)/gi).map(function(m) { return m.replace(/[\[\]]/gi,''); });

@@ -14,3 +14,3 @@ var last = props[props.length - 1],

for (i = 0; i < props.length; i += 1) {
if (!head[props[i]]) return;
if (!head[props[i]]) d;
head = head[props[i]];

@@ -23,2 +23,3 @@ if (typeof head !== 'undefined') {

}
return d;
}

@@ -25,0 +26,0 @@

{
"name": "get-prop",
"version": "0.0.3",
"version": "0.0.4",
"description": "Get a property from object",

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

@@ -24,8 +24,9 @@ # getprop

}],
}
},
'key.with.dots': 'hello',
'"key.with.quotes"': {
greet: 'hi'
},
$el: 'element'
},
'key.with.dots': 'hello',
'"key.with.quotes"': {
greet: 'hi'
}
};

@@ -35,8 +36,11 @@

getProp(obj, 'deedee') // undefined
getProp(obj, 'deedee', "I'm default value") // "I'm default value"
getProp(obj, 'qux.zee.boop') // 'yo'
getProp(obj, 'qux.zee.peep.0') // 55
getProp(obj, 'qux.zee.peep.1') // 'zonk'
getProp(obj, 'qux.zee.peep[1]') // 'zonk'
getProp(obj, 'qux[key.with.dots]') // 'hello'
getProp(obj, 'qux["key.with.quotes"].greet') // 'hi'
getProp(obj, 'qux.zee.peep.2.__data') // 'pow'
getProp(obj, 'qux.$el') // 'element'
```

@@ -43,0 +47,0 @@

@@ -5,3 +5,3 @@ var test = require('tape');

test('getProp', function (t) {
t.plan(11);
t.plan(14);

@@ -20,3 +20,4 @@ var obj = {

greet: 'hi'
}
},
$el: 'element'
},

@@ -27,8 +28,11 @@ };

t.equal(getProp(obj, 'deedee'), undefined);
t.equal(getProp(obj, 'deedee', "I'm default value"), "I'm default value");
t.equal(getProp(obj, 'qux.zee.boop'), 'yo');
t.equal(getProp(obj, 'qux.zee.peep.0'), 55);
t.equal(getProp(obj, 'qux.zee.peep.1'), 'zonk');
t.equal(getProp(obj, 'qux.zee.peep[1]'), 'zonk');
t.equal(getProp(obj, 'qux[key.with.dots]'), 'hello');
t.equal(getProp(obj, 'qux["key.with.quotes"].greet'), 'hi');
t.equal(getProp(obj, 'qux.zee.peep.2.__data'), 'pow');
t.equal(getProp(obj, 'qux.$el'), 'element');
t.equal(getProp(obj, ''), undefined);

@@ -35,0 +39,0 @@ t.equal(getProp(obj, {}), undefined);

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