Comparing version 0.0.1 to 0.0.2
{ | ||
"name": "getprop", | ||
"main": "getprop.js", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"homepage": "https://github.com/miguelmota/getprop", | ||
@@ -6,0 +6,0 @@ "authors": [ |
@@ -7,4 +7,5 @@ (function(root) { | ||
if (!(typeof s === 'string' || s instanceof String)) return; | ||
var props = s.split('.'), | ||
last = props[props.length - 1], | ||
var props = s.match(/(\[(.*?)\]|[0-9a-zA-Z]+)/gi).map(function(m) { return m.replace(/[\[\]]/gi,''); }); | ||
var last = props[props.length - 1], | ||
i = 0, | ||
@@ -11,0 +12,0 @@ head = o; |
{ | ||
"name": "get-prop", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Get a property from object", | ||
@@ -5,0 +5,0 @@ "main": "getprop.js", |
@@ -23,3 +23,5 @@ # getprop | ||
} | ||
} | ||
}, | ||
'key.with.dots': 'hello', | ||
'"key.with.quotes"': 'hi' | ||
}; | ||
@@ -32,2 +34,4 @@ | ||
getProp(obj, 'qux.zee.peep.1') // 'zonk' | ||
getProp(obj, 'qux[key.with.dots]') // 'hello' | ||
getProp(obj, 'qux["key.with.quotes"]') // 'hi' | ||
``` | ||
@@ -34,0 +38,0 @@ |
@@ -5,3 +5,3 @@ var test = require('tape'); | ||
test('getProp', function (t) { | ||
t.plan(8); | ||
t.plan(10); | ||
@@ -14,4 +14,6 @@ var obj = { | ||
peep: [55,'zonk'] | ||
} | ||
} | ||
}, | ||
'key.with.dots': 'hello', | ||
'"key.with.quotes"': 'hi' | ||
}, | ||
}; | ||
@@ -24,2 +26,4 @@ | ||
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"]'), 'hi'); | ||
t.equal(getProp(obj, ''), undefined); | ||
@@ -26,0 +30,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
6268
80
40