Comparing version 0.0.2 to 0.0.3
{ | ||
"name": "getprop", | ||
"main": "getprop.js", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"homepage": "https://github.com/miguelmota/getprop", | ||
@@ -6,0 +6,0 @@ "authors": [ |
@@ -7,3 +7,3 @@ (function(root) { | ||
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,''); }); | ||
@@ -10,0 +10,0 @@ var last = props[props.length - 1], |
{ | ||
"name": "get-prop", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Get a property from object", | ||
@@ -5,0 +5,0 @@ "main": "getprop.js", |
@@ -21,7 +21,11 @@ # getprop | ||
boop: 'yo', | ||
peep: [55,'zonk'] | ||
peep: [55,'zonk', { | ||
__data: 'pow' | ||
}], | ||
} | ||
}, | ||
'key.with.dots': 'hello', | ||
'"key.with.quotes"': 'hi' | ||
'"key.with.quotes"': { | ||
greet: 'hi' | ||
} | ||
}; | ||
@@ -35,3 +39,4 @@ | ||
getProp(obj, 'qux[key.with.dots]') // 'hello' | ||
getProp(obj, 'qux["key.with.quotes"]') // 'hi' | ||
getProp(obj, 'qux["key.with.quotes"].greet') // 'hi' | ||
getProp(obj, 'qux.zee.peep.2.__data') // 'pow' | ||
``` | ||
@@ -38,0 +43,0 @@ |
@@ -5,3 +5,3 @@ var test = require('tape'); | ||
test('getProp', function (t) { | ||
t.plan(10); | ||
t.plan(11); | ||
@@ -13,6 +13,10 @@ var obj = { | ||
boop: 'yo', | ||
peep: [55,'zonk'] | ||
peep: [55,'zonk', { | ||
__data: 'pow' | ||
}], | ||
}, | ||
'key.with.dots': 'hello', | ||
'"key.with.quotes"': 'hi' | ||
'"key.with.quotes"': { | ||
greet: 'hi' | ||
} | ||
}, | ||
@@ -27,3 +31,4 @@ }; | ||
t.equal(getProp(obj, 'qux[key.with.dots]'), 'hello'); | ||
t.equal(getProp(obj, 'qux["key.with.quotes"]'), 'hi'); | ||
t.equal(getProp(obj, 'qux["key.with.quotes"].greet'), 'hi'); | ||
t.equal(getProp(obj, 'qux.zee.peep.2.__data'), 'pow'); | ||
t.equal(getProp(obj, ''), undefined); | ||
@@ -30,0 +35,0 @@ t.equal(getProp(obj, {}), undefined); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6499
85
45