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 2.0.0 to 2.1.0

7

CHANGELOG.md

@@ -0,1 +1,8 @@

## v2.1.0 (2017-05-18)
* Add helper methods
- `tokenize()`
- `containWildcardToken()`
## v2.0.0 (2017-04-25)

@@ -2,0 +9,0 @@

@@ -0,1 +1,5 @@

/**
* Tokenize path string
*/
export declare const tokenize: (str: string) => string[];
export declare const get: (data: any, path: string | number, value?: any) => any;

@@ -36,1 +40,5 @@ /**

export declare const escapePath: (path: string) => string;
/**
* Check contains of wildcard syntax
*/
export declare const containWildcardToken: (path: string) => boolean;

25

lib/index.js

@@ -90,3 +90,6 @@ "use strict";

var hasToken = function (path) { return (path.indexOf('.') > -1 || path.indexOf('[') > -1); };
var tokenize = function (str) {
/**
* Tokenize path string
*/
exports.tokenize = function (str) {
var results = [];

@@ -109,3 +112,3 @@ splitTokens(str).forEach(function (token) {

var key = '__get_item__';
var tokens = tokenize(path);
var tokens = exports.tokenize(path);
var length = tokens.length;

@@ -170,3 +173,3 @@ var state = {

}
var tokens = tokenize(path);
var tokens = exports.tokenize(path);
if (tokens.indexOf('*') < 0) {

@@ -219,3 +222,3 @@ var res = _data;

}
var tokens = tokenize(path);
var tokens = exports.tokenize(path);
if (tokens.indexOf('*') < 0) {

@@ -270,3 +273,3 @@ var res = _data;

var key = '__has__item';
var tokens = tokenize(path);
var tokens = exports.tokenize(path);
var context = (_a = {}, _a[key] = [data], _a);

@@ -331,3 +334,3 @@ var result = true;

each(data, function (value, flat) {
var keys = tokenize(flat).reverse();
var keys = exports.tokenize(flat).reverse();
var key = keys.shift();

@@ -387,4 +390,4 @@ var child = isArrayKey(key) ? [] : {};

return true;
var a = tokenize(pathA);
var b = tokenize(pathB);
var a = exports.tokenize(pathA);
var b = exports.tokenize(pathB);
return a.length !== b.length ? false : a.every(function (t, i) {

@@ -397,4 +400,8 @@ return matchToken(t, b[i]) || matchToken(b[i], t);

*/
exports.escapePath = function (path) { return (!isString(path) ? '' : tokenize(path).map(function (p) {
exports.escapePath = function (path) { return (!isString(path) ? '' : exports.tokenize(path).map(function (p) {
return p.split('.').join('\\.');
}).join('\\.')); };
/**
* Check contains of wildcard syntax
*/
exports.containWildcardToken = function (path) { return (!isString(path) ? false : exports.tokenize(path).some(function (p) { return p === '*'; })); };
{
"name": "dot-wild",
"version": "2.0.0",
"version": "2.1.0",
"description": "Use powerful dot notation (dot path + wildcard) to manipulate properties of JSON",

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

@@ -26,3 +26,7 @@ dot-wild

```bash
$ npm install dot-wild
$ npm install dot-wild --save
# or
$ yarn add dot-wild
```

@@ -178,2 +182,12 @@

/**
* String to Tokens
*/
dot.tokenize('foo.bar.baz');
// => ['foo', 'bar', 'baz']
dot.tokenize('foo[1].2.*.bar\\.*.baz');
// => [ 'foo', '1', '2', '*', 'bar.*', 'baz' ]
/**
* Match path (helper method)

@@ -194,2 +208,14 @@ */

// => 'foo\\.bar\\.baz'
/**
* Check contains wildcard token
*/
dot.containWildcardToken('foo.*.bar');
dot.containWildcardToken('*.foo.1');
// => true
dot.containWildcardToken('path.string');
dot.containWildcardToken('foo*bar');
// => false
```

@@ -196,0 +222,0 @@

@@ -32,2 +32,18 @@ import * as assert from 'power-assert';

describe('dot-wild', () => {
it('tokenize()', () => {
assert.deepStrictEqual(dot.tokenize(''), []);
assert.deepStrictEqual(dot.tokenize('foo'), ['foo']);
assert.deepStrictEqual(dot.tokenize('foo.bar'), ['foo', 'bar']);
assert.deepStrictEqual(dot.tokenize('foo.bar.baz'), ['foo', 'bar', 'baz']);
assert.deepStrictEqual(dot.tokenize('foo\\.bar.baz'), ['foo.bar', 'baz']);
assert.deepStrictEqual(dot.tokenize('foo\\.bar\\.baz'), ['foo.bar.baz']);
assert.deepStrictEqual(dot.tokenize('foo.*.*.bar'), ['foo', '*', '*', 'bar']);
assert.deepStrictEqual(dot.tokenize('foo*.*.bar'), ['foo*', '*', 'bar']);
assert.deepStrictEqual(dot.tokenize('foo**bar'), ['foo**bar']);
assert.deepStrictEqual(dot.tokenize('hoge.1.fuga'), ['hoge', '1', 'fuga']);
assert.deepStrictEqual(dot.tokenize('hoge[1].fuga'), ['hoge', '1', 'fuga']);
assert.deepStrictEqual(dot.tokenize('hoge[1].*.fuga'), ['hoge', '1', '*', 'fuga']);
});
it('get()', () => {

@@ -508,2 +524,13 @@ const t1 = { foo: { bar: 'baz' } };

});
it('containWildcardToken()', () => {
assert(dot.containWildcardToken('foo.*.bar'));
assert(dot.containWildcardToken('*.foo'));
assert(dot.containWildcardToken('0.1.foo.bar.*'));
assert(dot.containWildcardToken('foo') === false);
assert(dot.containWildcardToken('foo*bar') === false);
assert(dot.containWildcardToken('foo.*bar') === false);
assert(dot.containWildcardToken('dot\\.path\\.*') === 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