Comparing version 0.0.1 to 0.1.0
@@ -411,2 +411,21 @@ "use strict"; | ||
/** | ||
* Match key | ||
* | ||
* @param {string} pathA | ||
* @param {string} pathB | ||
* @return {Object|Array} | ||
*/ | ||
var _matchPath = function _matchPath(pathA, pathB) { | ||
if (!isString(pathA) || !isString(pathB)) return false; | ||
if (pathA === pathB) return true; | ||
var a = tokenize(pathA); | ||
var b = tokenize(pathB); | ||
return a.length !== b.length ? false : a.every(function (t, i) { | ||
return matchToken(t, b[i]) || matchToken(b[i], t); | ||
}); | ||
}; | ||
/** | ||
* Exports | ||
@@ -420,3 +439,4 @@ */ | ||
flatten: _flatten, | ||
expand: _expand | ||
expand: _expand, | ||
matchPath: _matchPath | ||
}; |
{ | ||
"name": "dot-wild", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Use powerful dot notation (dot path + wildcard) to manipulate properties of JSON", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -131,2 +131,6 @@ dot-wild | ||
/** | ||
* Flatten values | ||
*/ | ||
dot.flatten(data); | ||
@@ -146,4 +150,16 @@ // => { | ||
/** | ||
* Expand values | ||
*/ | ||
dot.expand({ "foo.bar": "baz" }); | ||
// => { foo: { bar: "baz" } } | ||
/** | ||
* Match path (helper method) | ||
*/ | ||
dot.matchPath("foo.bar", "foo.bar"); | ||
dot.matchPath("foo.*.bar.*.baz", "foo.5.bar.1.baz"); | ||
// => true | ||
``` | ||
@@ -162,2 +178,3 @@ | ||
* `expand(data): Object | Array` | ||
* `matchPath(pathA, pathB): boolean` | ||
@@ -164,0 +181,0 @@ |
@@ -385,2 +385,24 @@ const assert = require("assert"); | ||
}); | ||
it("matchPath()", () => { | ||
assert(dot.matchPath("", "") === true); | ||
assert(dot.matchPath("hoge", "hoge") === true); | ||
assert(dot.matchPath("foo.bar", "foo.bar") === true); | ||
assert(dot.matchPath("foo\\.bar", "foo\\.bar") === true); | ||
assert(dot.matchPath("foo.*.nested", "foo.*.nested") === true); | ||
assert(dot.matchPath("foo.*.nested", "foo.7.nested") === true); | ||
assert(dot.matchPath("foo.7.nested", "foo.*.nested") === true); | ||
assert(dot.matchPath("foo.7.nested.0.deep", "foo.*.nested.*.deep") === true); | ||
assert(dot.matchPath("foo\\.bar.*.baz", "foo\\.bar.2.baz") === true); | ||
assert(dot.matchPath(false, false) === false); | ||
assert(dot.matchPath(true, true) === false); | ||
assert(dot.matchPath(null, null) === false); | ||
assert(dot.matchPath("fuga", "fugahoge") === false); | ||
assert(dot.matchPath("foo.2", "foo.1") === false); | ||
assert(dot.matchPath("foo.*.bar", "foo.bar") === false); | ||
assert(dot.matchPath("foo.*.bar", "foo.*.bar.baz") === false); | ||
assert(dot.matchPath("foo.*.bar", "foo\\.1.bar") === false); | ||
}); | ||
}); |
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
29064
713
218