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.1.0 to 0.2.0

32

lib/index.js

@@ -5,2 +5,4 @@ "use strict";

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
/**

@@ -85,13 +87,12 @@ * Utilities

var results = [];
var prev = null;
var store = [];
tokens.forEach(function (token) {
if (/^.*\\$/.test(token)) {
prev = token;
store.push(token.slice(0, token.length - 1));
} else if (store.length > 0) {
results = [].concat(_toConsumableArray(results), [store.join(".") + "." + token]);
store = [];
} else {
if (prev == null) {
return results.push(token);
}
results.push(prev.slice(0, prev.length - 1) + "." + token);
prev = null;
results.push(token);
}

@@ -417,3 +418,3 @@ });

* @param {string} pathB
* @return {Object|Array}
* @return {string}
*/

@@ -433,2 +434,14 @@ var _matchPath = function _matchPath(pathA, pathB) {

/**
* Escape path string
*
* @param {string} path
* @return {string}
*/
var _escapePath = function _escapePath(path) {
return !isString(path) ? "" : tokenize(path).map(function (p) {
return p.split(".").join("\\.");
}).join("\\.");
};
/**
* Exports

@@ -443,3 +456,4 @@ */

expand: _expand,
matchPath: _matchPath
matchPath: _matchPath,
escapePath: _escapePath
};
{
"name": "dot-wild",
"version": "0.1.0",
"version": "0.2.0",
"description": "Use powerful dot notation (dot path + wildcard) to manipulate properties of JSON",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -15,2 +15,4 @@ dot-wild

- [Usage](#usage)
- [Basic](#basic)
- [Advanced](#advanced)
- [API](#api)

@@ -164,2 +166,12 @@ - [Contribute](#contribute)

// => true
/**
* Escape path string
*/
dot.escapePath("foo.bar");
// => "foo\\.bar"
dot.escapePath("foo\\.bar.baz");
// => "foo\\.bar\\.baz"
```

@@ -179,2 +191,3 @@

* `matchPath(pathA, pathB): boolean`
* `escapePath(path): string`

@@ -181,0 +194,0 @@

@@ -57,6 +57,8 @@ const assert = require("assert");

assert(dot.get({ "foo.bar.baz": "hoge" }, "foo\\.bar\\.baz") === "hoge");
const t2 = { "foo.bar": { baz: { fuga: "fuge" } } };
assert.deepStrictEqual(dot.get(t2, "foo\\.bar"), { baz: { fuga: "fuge" } });
assert.deepStrictEqual(dot.get(t2, "foo\\.bar.baz"), { fuga: "fuge" });
assert.deepStrictEqual(dot.get(t2, "foo\\.bar.baz.fuga"), "fuge");
assert(dot.get(t2, "foo\\.bar.baz.fuga") === "fuge");
assert(dot.get(t2, "foo\\.bar.baz.fuga.fuge") == null);

@@ -206,5 +208,5 @@

}), [
{ id: 1, profile: { name: "hoge" } },
{ id: 2, profile: { name: "fuga" } },
{ id: 3, profile: { name: "foo" } }
{ id: 1, profile: { name: "hoge" } },
{ id: 2, profile: { name: "fuga" } },
{ id: 3, profile: { name: "foo" } }
]);

@@ -216,5 +218,5 @@ assertT2();

}), [
{ id: 1, profile: { name: "hoge" } },
{ id: 2, profile: { name: "fuga" } },
{ profile: { name: "test", age: 50 } }
{ id: 1, profile: { name: "hoge" } },
{ id: 2, profile: { name: "fuga" } },
{ profile: { name: "test", age: 50 } }
]);

@@ -410,2 +412,16 @@ assertT2();

});
it("escapePath()", () => {
assert(dot.escapePath(null) === "");
assert(dot.escapePath(undefined) === "");
assert(dot.escapePath("") === "");
assert(dot.escapePath("path") === "path");
assert(dot.escapePath("foo.bar") === "foo\\.bar");
assert(dot.escapePath("this.is.my.path") === "this\\.is\\.my\\.path");
assert(dot.escapePath("foo\\.bar") === "foo\\.bar");
assert(dot.escapePath("foo\\.bar.baz") === "foo\\.bar\\.baz");
assert(dot.escapePath("foo\\.bar\\.baz") === "foo\\.bar\\.baz");
assert(dot.escapePath("foo\\.*.*.bar\\.baz") === "foo\\.*\\.*\\.bar\\.baz");
});
});
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