Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dot-wild

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dot-wild - npm Package Compare versions

Comparing version 0.0.1 to 0.1.0

22

lib/index.js

@@ -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
};

2

package.json
{
"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);
});
});
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