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

json-ptr

Package Overview
Dependencies
Maintainers
1
Versions
91
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-ptr - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

.circleci/config.yml

5

bower.json
{
"name": "json-ptr",
"main": "index.js",
"version": "0.3.1",
"version": "1.0.1",
"homepage": "https://github.com/flitbit/json-ptr",

@@ -23,4 +23,5 @@ "authors": [

"test",
"tests"
"tests",
"releases"
]
}

3

examples/readme/module.map.js

@@ -1,2 +0,1 @@

'use strict';

@@ -9,4 +8,4 @@ var ptr = require('../../'); // json-ptr

for (let it of map) {
for (var it of map) {
console.log(JSON.stringify(it, null, ' '));
}

@@ -1,2 +0,1 @@

'use strict';

@@ -19,3 +18,3 @@ var ptr = require('..'),

if (data && Array.isArray(data)) {
let images = data.reduce((acc, it) => {
var images = data.reduce((acc, it) => {
// Using the prepared pointers to select parts...

@@ -22,0 +21,0 @@ acc.push({

@@ -103,3 +103,3 @@ var assert = require('assert'),

let complexKeys = {
var complexKeys = {
'a/b': {

@@ -123,3 +123,3 @@ c: 1

// draft-ietf-appsawg-json-pointer-08 has special array rules
let ary = ['zero', 'one', 'two'];
var ary = ['zero', 'one', 'two'];
assert.equal(ptr.get(ary, '/01'), null);

@@ -134,3 +134,3 @@

// Examples from the draft:
let example = {
var example = {
'foo': ['bar', 'baz'],

@@ -143,3 +143,3 @@ '': 0,

'i\\j': 5,
'k\"l': 6,
'k"l': 6,
' ': 7,

@@ -150,3 +150,3 @@ 'm~n': 8

assert.equal(ptr.get(example, ''), example);
let ans = ptr.get(example, '/foo');
var ans = ptr.get(example, '/foo');
assert.equal(ans.length, 2);

@@ -162,3 +162,3 @@ assert.equal(ans[0], 'bar');

assert.equal(ptr.get(example, '/i\\j'), 5);
assert.equal(ptr.get(example, '/k\"l'), 6);
assert.equal(ptr.get(example, '/k"l'), 6);
assert.equal(ptr.get(example, '/ '), 7);

@@ -165,0 +165,0 @@ assert.equal(ptr.get(example, '/m~0n'), 8);

@@ -1,7 +0,14 @@

'use strict';
(function (root, factory) {
if (typeof define === 'function' && define.amd) { // eslint-disable-line no-undef
define([], factory);// eslint-disable-line no-undef
} else if (typeof module === 'object' && module.exports) {
module.exports = factory();
} else {
root.returnExports = factory();
}
// eslint-disable-next-line no-undef
}(typeof self !== 'undefined' ? self : this, function () {
var root = this;
var $savedJsonPointer = this.JsonPointer;
(function() {
var root = this; // either the module or the window (in a browser)
var savedJsonPointer = root.JsonPointer;
function replace(str, find, repl) {

@@ -125,8 +132,11 @@ // modified from http://jsperf.com/javascript-replace-all/10

var cursor = 0;
if (len === 0 || len > 1 && idx[0] === '0') {
return -1;
}
if (len === 1 && idx[0] === '-') {
if (!Array.isArray(arr)) {
return 0;
}
return arr.length;
}
if (len === 0 || len > 1 && idx[0] === '0' || !isFinite(idx)) {
return -1;
}

@@ -180,3 +190,3 @@ while (++cursor < len) {

var p;
var nonexistent = undefined;
var nonexistent;
if (typeof target !== 'undefined') {

@@ -210,16 +220,16 @@ it = target;

function compilePointerDereference(path) {
let body = `if (typeof(obj) !== 'undefined'`;
var body = 'if (typeof(obj) !== \'undefined\'';
if (path.length === 0) {
return function(root) {
return root;
return function (it) {
return it;
};
}
body = path.reduce((body, p, i) => {
return `${body} &&
typeof((obj = obj['${replace(path[i], '\\', '\\\\')}'])) !== 'undefined'`;
}, `if (typeof(obj) !== 'undefined'`);
body = `${body}) {
return obj;
}`;
return new Function(['obj'], body); // eslint-disable-line no-new-func
// eslint-disable-next-line
body = path.reduce(function (body, p, i) {
return body + ' && \n\ttypeof((obj = obj[\'' +
replace(path[i], '\\', '\\\\') + '\'])) !== \'undefined\'';
}, 'if (typeof(obj) !== \'undefined\'');
body = body + ') {\n\treturn obj;\n }';
// eslint-disable-next-line no-new-func
return new Function(['obj'], body);
}

@@ -235,3 +245,3 @@

var rem;
var nonexistent = undefined;
var nonexistent;
if (path.length === 0) {

@@ -241,3 +251,3 @@ throw new Error('Cannot set the root object; assign it directly.');

if (typeof target === 'undefined') {
throw TypeError('Cannot set values on undefined');
throw new TypeError('Cannot set values on undefined');
}

@@ -261,4 +271,8 @@ it = target;

} else if (it.length === p) {
it.push(val);
return nonexistent;
if (cursor === end) {
it.push(val);
return nonexistent;
} else if (force) {
it = it[p] = {};
}
}

@@ -272,2 +286,7 @@ } else {

}
// if the next step is an array index, this step should be an array.
if (toArrayIndexReference(it[step], path[cursor + 1]) !== -1) {
it = it[step] = [];
continue;
}
it = it[step] = {};

@@ -298,63 +317,91 @@ continue;

let $path = Symbol();
let $orig = Symbol();
let $pointer = Symbol();
let $fragmentId = Symbol();
class JsonPointer {
constructor(ptr) {
this[$orig] = ptr;
this[$path] = (Array.isArray(ptr)) ? ptr : pickDecoder(ptr)(ptr);
Object.defineProperty(this, 'get', {
function JsonPointer(ptr) {
// decode if necessary, make immutable.
var localPath = (Array.isArray(ptr)) ?
ptr.slice(0) :
ptr = pickDecoder(ptr)(ptr);
var $original = (Array.isArray(ptr)) ? encodePointer(localPath) : ptr;
var $pointer;
var $fragmentId;
var $compiledGetter = compilePointerDereference(localPath);
Object.defineProperties(this, {
get: {
enumerable: true,
value: compilePointerDereference(this.path)
});
}
get path() {
return this[$path];
}
get pointer() {
if (!this[$pointer]) {
this[$pointer] = encodePointer(this.path);
value: $compiledGetter
},
set: {
enumerable: true,
value: function (target, value, force) {
return setValueAtPath(target, value, localPath, force);
}
},
has: {
enumerable: true,
value: function (target) {
return typeof ($compiledGetter(target)) !== 'undefined';
}
},
path: {
enumerable: true,
get: function () {
return localPath.slice(0);
}
},
pointer: {
enumerable: true,
get: function () {
if (!$pointer) {
$pointer = encodePointer(localPath);
}
return $pointer;
}
},
uriFragmentIdentifier: {
enumerable: true,
get: function () {
if (!$fragmentId) {
$fragmentId = encodeUriFragmentIdentifier(localPath);
}
return $fragmentId;
}
},
toString: {
enumerable: true,
configurable: true,
writable: true,
value: function () {
return $original;
}
}
return this[$pointer];
}
get uriFragmentIdentifier() {
if (!this[$fragmentId]) {
this[$fragmentId] = encodeUriFragmentIdentifier(this.path);
}
return this[$fragmentId];
}
has(target) {
return typeof(this.get(target)) != 'undefined';
}
});
}
class JsonReference {
function JsonReference(pointer) {
var localPtr = (typeof (pointer) === 'string' || Array.isArray(pointer)) ?
new JsonPointer(pointer) :
pointer;
constructor(pointer) {
this[$pointer] = pointer;
}
get $ref() {
return this[$pointer].uriFragmentIdentifier;
}
resolve(target) {
return this[$pointer].get(target);
}
toString() {
return this.$ref;
}
Object.defineProperties(this, {
$ref: {
enumerable: true,
value: localPtr.uriFragmentIdentifier
},
resolve: {
enumerable: true,
value: function (target) {
return localPtr.get(target);
}
},
toString: {
enumerable: true,
writable: true,
configurable: true,
value: function () {
return localPtr.uriFragmentIdentifier;
}
}
});
}
JsonReference.isReference = function(obj) {
JsonReference.isReference = function (obj) {
return obj && obj instanceof JsonReference ||

@@ -368,3 +415,3 @@ (typeof obj.$ref === 'string' &&

var distinctObjects;
var q = new Array();
var q = [];
var qcursor = 0;

@@ -376,3 +423,3 @@ q.push({

if (cycle) {
distinctObjects = new Map();
distinctObjects = Object.create(null);
}

@@ -391,4 +438,4 @@ visitor(encodePointer([]), target);

if (typeof it === 'object' && it !== null) {
if (cycle && distinctObjects.has(it)) {
visitor(encodePointer(path), new JsonReference(distinctObjects.get(it)));
if (cycle && distinctObjects[it]) {
visitor(encodePointer(path), new JsonReference(distinctObjects[it]));
continue;

@@ -401,3 +448,3 @@ }

if (cycle) {
distinctObjects.set(it, new JsonPointer(encodeUriFragmentIdentifier(path)));
distinctObjects[it] = new JsonPointer(encodeUriFragmentIdentifier(path));
}

@@ -415,4 +462,4 @@ }

if (typeof it === 'object' && it !== null) {
if (cycle && distinctObjects.has(it)) {
visitor(encodePointer(path), new JsonReference(distinctObjects.get(it)));
if (cycle && distinctObjects[it]) {
visitor(encodePointer(path), new JsonReference(distinctObjects[it]));
continue;

@@ -425,3 +472,3 @@ }

if (cycle) {
distinctObjects.set(it, new JsonPointer(encodeUriFragmentIdentifier(path)));
distinctObjects[it] = new JsonPointer(encodeUriFragmentIdentifier(path));
}

@@ -436,30 +483,22 @@ }

JsonPointer.prototype.set = function(target, value, force) {
return setValueAtPath(target, value, this.path, force);
};
JsonPointer.prototype.toString = function() {
return this.original;
};
JsonPointer.create = function(ptr) {
JsonPointer.create = function (ptr) {
return new JsonPointer(ptr);
};
JsonPointer.has = function(target, ptr) {
JsonPointer.has = function (target, ptr) {
return hasValueAtPath(target, pickDecoder(ptr)(ptr));
};
JsonPointer.get = function(target, ptr) {
JsonPointer.get = function (target, ptr) {
return getValueAtPath(target, pickDecoder(ptr)(ptr));
};
JsonPointer.set = function(target, ptr, val, force) {
JsonPointer.set = function (target, ptr, val, force) {
return setValueAtPath(target, val, pickDecoder(ptr)(ptr), force);
};
JsonPointer.list = function(target, fragmentId) {
JsonPointer.list = function (target, fragmentId) {
var res = [];
var visitor = (fragmentId) ?
function(ptr, val) {
function (ptr, val) {
res.push({

@@ -470,3 +509,3 @@ fragmentId: encodeUriFragmentIdentifier(decodePointer(ptr)),

} :
function(ptr, val) {
function (ptr, val) {
res.push({

@@ -481,9 +520,9 @@ pointer: ptr,

JsonPointer.flatten = function(target, fragmentId) {
JsonPointer.flatten = function (target, fragmentId) {
var res = {};
var visitor = (fragmentId) ?
function(ptr, val) {
function (ptr, val) {
res[encodeUriFragmentIdentifier(decodePointer(ptr))] = val;
} :
function(ptr, val) {
function (ptr, val) {
res[ptr] = val;

@@ -495,7 +534,7 @@ };

JsonPointer.map = function(target, fragmentId) {
var res = new Map();
JsonPointer.map = function (target, fragmentId) {
var res = [];
var visitor = (fragmentId) ?
function(ptr, val) {
res.set(encodeUriFragmentIdentifier(decodePointer(ptr)), val);
function (ptr, val) {
res.push({ key: encodeUriFragmentIdentifier(decodePointer(ptr)), value: val });
} : res.set.bind(res);

@@ -508,3 +547,3 @@ visit(target, visitor);

JsonPointer.decode = function(ptr) {
JsonPointer.decode = function (ptr) {
return pickDecoder(ptr)(ptr);

@@ -518,18 +557,14 @@ };

// support ES6 style destructuring...
JsonPointer.JsonPointer = JsonPointer;
JsonPointer.JsonReference = JsonReference;
JsonPointer.isReference = JsonReference.isReference;
JsonPointer.noConflict = function() {
root.JsonPointer = savedJsonPointer;
JsonPointer.noConflict = function () {
root.JsonPointer = $savedJsonPointer;
return JsonPointer;
};
if (typeof exports !== 'undefined') {
if (typeof module !== 'undefined' && module.exports) {
exports = module.exports = JsonPointer;
}
exports.JsonPointer = JsonPointer;
} else {
root.JsonPointer = JsonPointer;
}
}).call(Function('return this')()); // eslint-disable-line no-new-func
root.JsonPointer = JsonPointer;
return JsonPointer;
}));
{
"name": "json-ptr",
"version": "1.0.1",
"version": "1.1.0",
"author": "Phillip Clark <phillip@flitbit.com>",

@@ -13,20 +13,2 @@ "description": "A complete implementation of JSON Pointer (RFC 6901) for nodejs and modern browsers.",

"main": "index.js",
"directories": {
"example": "examples",
"test": "test"
},
"scripts": {
"release": "babel --presets es2015 --minified --no-comments index.js --out-file releases/json-ptr-$npm_package_version.min.js",
"cover": "istanbul cover ./node_modules/mocha/bin/_mocha --report html -- -R spec",
"pretest": "eslint .",
"test": "mocha -R spec"
},
"devDependencies": {
"babel-cli": "^6.3.17",
"babel-preset-es2015": "^6.6.0",
"blanket": "^1.2.1",
"eslint": "^1.10.3",
"expect.js": "~0.3.1",
"mocha": "~2.3.4"
},
"license": "MIT",

@@ -37,22 +19,27 @@ "repository": {

},
"engines": {
"node": ">=4.0"
"scripts": {
"prerelease": "npm run clean && npm run test",
"release": "uglifyjs -c -m -o dist/json-ptr.min.js -r '$,require,exports,self,module,define' index.js",
"clean": "rimraf dist && mkdir dist",
"preversion": "npm run release",
"postversion": "git push && git push --tags",
"pretest": "npm run lint",
"test": "mocha test/**/*.js",
"test:watch": "nodemon --ext js,json --ignore dist/ --exec 'npm test'",
"preci": "npm run lint",
"ci": "mocha --reporter mocha-junit-reporter test/**/*.js",
"lint": "eslint src test"
},
"config": {
"blanket": {
"pattern": [
"index.js"
],
"data-cover-never": [
"node_modules",
"tests"
]
}
},
"jspm": {
"directories": {
"lib": "releases"
},
"main": "json-ptr-1.0.1.min.js"
"devDependencies": {
"bluebird": "^3.5.1",
"eslint": "^4.18.1",
"eslint-plugin-mocha": "^4.11.0",
"expect.js": "^0.3.1",
"json": "^9.0.6",
"mocha": "^5.0.1",
"mocha-junit-reporter": "^1.17.0",
"nodemon": "^1.15.1",
"rimraf": "^2.6.2",
"uglify-js": "^3.3.12"
}
}

@@ -1,7 +0,9 @@

# json-ptr [![Build Status](https://travis-ci.org/flitbit/json-ptr.png)](http://travis-ci.org/flitbit/json-ptr)&nbsp;[![bitHound Overall Score](https://www.bithound.io/github/flitbit/json-ptr/badges/score.svg)](https://www.bithound.io/github/flitbit/json-ptr)
# json-ptr
[![CircleCI](https://circleci.com/gh/flitbit/json-ptr/tree/master.svg?style=svg)](https://circleci.com/gh/flitbit/json-ptr/tree/master)
[![bitHound Overall Score](https://www.bithound.io/github/flitbit/json-ptr/badges/score.svg)](https://www.bithound.io/github/flitbit/json-ptr)
A complete implementation of JSON Pointer ([RFC 6901](https://tools.ietf.org/html/rfc6901)) for nodejs and modern browsers.
> As pointed out by @twindagger __`v0.3+` breaks backward compatability for the `list` function__. The interface was previously `.list(obj)` and returned _fragmentId pairs_; in v0.3+ the interface is `.list(obj, fragmentId)` and returns _pointer pairs_ when `fragmentId` is not specified (truthy). It essentially is the opposite of what you would expect if you were using the module prior to v0.3.x... my appologies.
## Background

@@ -21,10 +23,13 @@

[nodejs](https://nodejs.org/en/)
### [nodejs](https://nodejs.org/en/)
```javascript
// npm install json-ptr
var ptr = require('json-ptr')
```
**browser**
### browser
```html
<script src="json-ptr-0.3.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/flitbit/json-ptr@1/dist/json-ptr.min.js"></script>
<!-- exports an object named JsonPointer -->

@@ -34,10 +39,5 @@ <script>var ptr = JsonPointer.noConflict()</script>

[duo](https://github.com/duojs/duo)
```javascript
var ptr = require('flitbit/json-ptr')
```
### Module API
**Classes:**
#### Classes

@@ -47,3 +47,3 @@ * [`JsonPointer`](#user-content-jsonpointer-class) : _class_ &ndash; a convenience class for working with JSON pointers.

**Functions:**
#### Functions

@@ -59,2 +59,3 @@ * [`.create(pointer)`](#user-content-createpointer)

All example code assumes data has this structure:
```javascript

@@ -87,8 +88,11 @@ var data = {

_arguments:_
* `pointer` : _string, required_ &ndash; a JSON pointer in [JSON string representation](https://tools.ietf.org/html/rfc6901#section-5) or [URI fragment identifier representation](https://tools.ietf.org/html/rfc6901#section-6)
_returns:_
* a new [`JsonPointer` instance](#user-content-jsonpointer-class)
_example:_
```javascript

@@ -104,2 +108,3 @@ var pointer = ptr.create('/legumes/0');

_arguments:_
* `target` : _object, required_ &ndash; the target object

@@ -109,2 +114,3 @@ * `pointer` : _string, required_ &ndash; a JSON pointer in [JSON string representation](https://tools.ietf.org/html/rfc6901#section-5) or [URI fragment identifier representation](https://tools.ietf.org/html/rfc6901#section-6)

_returns:_
* the dereferenced value or _undefined_ if nonexistent

@@ -117,2 +123,3 @@

_arguments:_
* `target` : _object, required_ &ndash; the target object

@@ -122,5 +129,7 @@ * `pointer` : _string, required_ &ndash; a JSON pointer in [JSON string representation](https://tools.ietf.org/html/rfc6901#section-5) or [URI fragment identifier representation](https://tools.ietf.org/html/rfc6901#section-6)

_returns:_
* the dereferenced value or _undefined_ if nonexistent
_example:_
```javascript

@@ -136,2 +145,3 @@ var value = ptr.get(data, '/legumes/1');

_arguments:_
* `target` : _object, required_ &ndash; the target object

@@ -143,6 +153,7 @@ * `pointer` : _string, required_ &ndash; a JSON pointer in [JSON string representation](https://tools.ietf.org/html/rfc6901#section-5) or [URI fragment identifier representation](https://tools.ietf.org/html/rfc6901#section-6)

_returns:_
* The prior value at the pointer's path &mdash; therefore, _undefined_ means the pointer's path was nonexistent.
_example:_
_example:_
```javascript

@@ -153,2 +164,3 @@ var prior = ptr.set(data, '#/legumes/1/instock', 50);

example force:
```javascript

@@ -163,2 +175,3 @@ var data = {};

```
```json

@@ -181,2 +194,3 @@ {

_arguments:_
* `target` : _object, required_ &ndash; the target object

@@ -186,8 +200,11 @@ * `fragmentId` : _boolean, optional_ &ndash; indicates whether fragment identifiers should be listed instead of pointers

_returns:_
* an array of `pointer-value` pairs
_example:_
```javascript
var list = ptr.list(data);
```
```json

@@ -219,5 +236,7 @@ [ ...

_`fragmentId` example:_
```javascript
var list = ptr.list(data, true);
```
```json

@@ -253,2 +272,3 @@ [ ...

_arguments:_
* `target` : _object, required_ &ndash; the target object

@@ -258,8 +278,11 @@ * `fragmentId` : _boolean, optional_ &ndash; indicates whether fragment identifiers should be listed instead of pointers

_returns:_
* a flattened object of `property-value` pairs as properties.
_example:_
```javascript
var obj = ptr.flatten(data, true);
```
```json

@@ -284,2 +307,3 @@ { ...

_arguments:_
* `target` : _object, required_ &ndash; the target object

@@ -289,5 +313,7 @@ * `fragmentId` : _boolean, optional_ &ndash; indicates whether fragment identifiers should be listed instead of pointers

_returns:_
* a Map object containing key-value pairs where keys are pointers.
_example:_
```javascript

@@ -300,2 +326,3 @@ var map = ptr.map(data, true);

```
```json

@@ -322,11 +349,15 @@ ...

_arguments:_
* `pointer` : _string, required_ &ndash; a JSON pointer in [JSON string representation](https://tools.ietf.org/html/rfc6901#section-5) or [URI fragment identifier representation](https://tools.ietf.org/html/rfc6901#section-6).
_returns:_
* An array of path segments used as indexers to descend from a root/`target` object to a referenced value.
_example:_
```javascript
var path = ptr.decode('#/legumes/1/instock');
```
```json

@@ -341,11 +372,15 @@ [ "legumes", "1", "instock" ]

_arguments:_
* `pointer` : _string, required_ &ndash; a JSON pointer in [JSON string representation](https://tools.ietf.org/html/rfc6901#section-5).
_returns:_
* An array of path segments used as indexers to descend from a root/`target` object to a referenced value.
_example:_
```javascript
var path = ptr.decodePointer('/people/wilbur dongleworth/age');
```
```json

@@ -360,11 +395,15 @@ [ "people", "wilbur dongleworth", "age" ]

_arguments:_
* `path` : _Array, required_ &ndash; an array of path segments
_returns:_
* A JSON pointer in [JSON string representation](https://tools.ietf.org/html/rfc6901#section-5).
_example:_
```javascript
var path = ptr.encodePointer(['people', 'wilbur dongleworth', 'age']);
```
```json

@@ -379,11 +418,15 @@ "/people/wilbur dongleworth/age"

_arguments:_
* `pointer` : _string, required_ &ndash; a JSON pointer in [URI fragment identifier representation](https://tools.ietf.org/html/rfc6901#section-6).
_returns:_
* An array of path segments used as indexers to descend from a root/`target` object to a referenced value.
_example:_
```javascript
var path = ptr.decodePointer('#/people/wilbur%20dongleworth/age');
```
```json

@@ -398,11 +441,15 @@ [ "people", "wilbur dongleworth", "age" ]

_arguments:_
* `path` : _Array, required_ - an array of path segments
_returns:_
* A JSON pointer in [URI fragment identifier representation](https://tools.ietf.org/html/rfc6901#section-6).
_example:_
```javascript
var path = ptr.encodePointer(['people', 'wilbur dongleworth', 'age']);
```
```json

@@ -417,10 +464,11 @@ "#/people/wilbur%20dongleworth/age"

_example:_
```html
<!-- ur codez -->
<script src="/json-ptr-0.3.0.min.js"></script>
<script>
// At this point, JsonPointer is the json-ptr module
var ptr = JsonPointer.noConflict();
// and now it is restored to whatever it was before the json-ptr import.
</script>
<!-- ur codez -->
<script src="/json-ptr-0.3.0.min.js"></script>
<script>
// At this point, JsonPointer is the json-ptr module
var ptr = JsonPointer.noConflict();
// and now it is restored to whatever it was before the json-ptr import.
</script>
```

@@ -433,2 +481,3 @@

_properties:_
* `.path` : _array_ &ndash; contains the pointer's path segements.

@@ -439,12 +488,17 @@ * `.pointer` : _string_ &ndash; the pointer's [JSON string representation](https://tools.ietf.org/html/rfc6901#section-5)

_methods:_
#### .has(target)
Determins whether the specified `target` has a value at the pointer's path.
#### .get(target)
Looks up the specified `target`'s value at the pointer's path if such exists; otherwise _undefined_.
#### .set(target, value, force)
Sets the specified `target`'s value at the pointer's path, if such exists.If `force` is specified (_truthy_), missing path segments are created and the value is always set at the pointer's path.
_arguments:_
* `target` : _object, required_ &ndash; the target object

@@ -455,2 +509,3 @@ * `value` : _any_ &ndash; the value to be set at the specified `pointer`'s path

_result:_
* The prior value at the pointer's path &mdash; therefore, _undefined_ means the pointer's path was nonexistent.

@@ -463,2 +518,3 @@

**All timings are expressed as nanoseconds:**
```text

@@ -513,2 +569,3 @@ .flatten(obj)

_Consider this example code that queries the flickr API and prints results to the console:_
```javascript

@@ -561,2 +618,3 @@ 'use strict';

```
> \[[example/real-world.js](https://github.com/flitbit/json-ptr/blob/master/examples/real-world.js)]

@@ -566,3 +624,3 @@

Tests are written using [mocha](http://visionmedia.github.io/mocha/) and [expect.js](https://github.com/Automattic/expect.js).
Tests are written using [mocha](https://mochajs.org/) and [expect.js](https://github.com/Automattic/expect.js).

@@ -569,0 +627,0 @@ ```bash

@@ -1,950 +0,1008 @@

(function() {
var root = this; // either the module or the window (in a browser)
if (typeof require === 'function') {
root.expect = root.expect || require('expect.js');
root.JsonPointer = root.JsonPointer || require('..');
(function (root, factory) {
if (typeof define === 'function' && define.amd) { // eslint-disable-line no-undef
define(['json-ptr', 'expect.js'], factory);// eslint-disable-line no-undef
} else if (typeof module === 'object' && module.exports) {
module.exports = factory(require('../'), require('expect.js'));
} else {
root.returnExports = factory(root.JsonPointer, root.expect);
}
// eslint-disable-next-line no-undef
}(typeof self !== 'undefined' ? self : this, function (ptr, expect) {
(function(ptr, expect) {
describe('JsonPointer', function () {
describe('JsonPointer', function() {
'use strict';
describe('when working with the example data from the rfc', function () {
var data = {
'foo': ['bar', 'baz'],
'': 0,
'a/b': 1,
'c%d': 2,
'e^f': 3,
'g|h': 4,
'i\\j': 5,
'k"l': 6,
' ': 7,
'm~n': 8
};
describe('when working with the example data from the rfc', function() {
var data = {
'foo': ['bar', 'baz'],
'': 0,
'a/b': 1,
'c%d': 2,
'e^f': 3,
'g|h': 4,
'i\\j': 5,
'k"l': 6,
' ': 7,
'm~n': 8
};
describe('with a JSON pointer to the root ``', function () {
var p = ptr.create('');
describe('with a JSON pointer to the root ``', function() {
var p = ptr.create('');
it('#get should resolve to the object itself', function () {
expect(p.get(data)).to.eql(data);
});
it('#get should resolve to the object itself', function() {
expect(p.get(data)).to.eql(data);
});
it('#set should throw', function () {
expect(function () {
p.set(data, {
this: 'should cause an exception'
});
}).to.throwError();
});
it('#set should throw', function() {
expect(function() {
p.set(data, {
this: 'should cause an exception'
});
}).to.throwError();
});
it('should have an empty path', function () {
expect(p.path).to.have.length(0);
});
it('should have an empty path', function() {
expect(p.path).to.have.length(0);
});
it('should have a pointer that is empty', function () {
expect(p.pointer).to.eql('');
});
it('should have a pointer that is empty', function() {
expect(p.pointer).to.eql('');
});
it('should have a URI fragment identfier that is empty', function () {
expect(p.uriFragmentIdentifier).to.eql('#');
});
});
it('should have a URI fragment identfier that is empty', function() {
expect(p.uriFragmentIdentifier).to.eql('#');
});
describe('a URI fragment identfier to the root #', function () {
var p = ptr.create('#');
it('#get should resolve to the object itself', function () {
expect(p.get(data)).to.equal(data);
});
describe('a URI fragment identfier to the root #', function() {
var p = ptr.create('#');
it('#set should throw', function () {
expect(function () {
p.set(data, {
this: 'should cause an exception'
});
}).to.throwError();
});
it('#get should resolve to the object itself', function() {
expect(p.get(data)).to.equal(data);
});
it('should have an empty path', function () {
expect(p.path).to.have.length(0);
});
it('#set should throw', function() {
expect(function() {
p.set(data, {
this: 'should cause an exception'
});
}).to.throwError();
});
it('should have a pointer that is empty', function () {
expect(p.pointer).to.eql('');
});
it('should have an empty path', function() {
expect(p.path).to.have.length(0);
});
it('should have a URI fragment identfier that is empty', function () {
expect(p.uriFragmentIdentifier).to.eql('#');
});
});
it('should have a pointer that is empty', function() {
expect(p.pointer).to.eql('');
});
describe('with a JSON pointer of `/foo`', function () {
var p = ptr.create('/foo');
it('should have a URI fragment identfier that is empty', function() {
expect(p.uriFragmentIdentifier).to.eql('#');
});
it('#get should resolve to data["foo"]', function () {
expect(p.get(data)).to.equal(data.foo);
});
describe('with a JSON pointer of `/foo`', function() {
var p = ptr.create('/foo');
it('#set should succeed changing the referenced value', function () {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('#get should resolve to data["foo"]', function() {
expect(p.get(data)).to.equal(data['foo']);
});
it('should have a path of [ "foo" ]', function () {
expect(p.path).to.eql(['foo']);
});
it('#set should succeed changing the referenced value', function() {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('should have the pointer `/foo`', function () {
expect(p.pointer).to.eql('/foo');
});
it('should have a path of [ "foo" ]', function() {
expect(p.path).to.eql(['foo']);
});
it('should have the URI fragment identfier `#/foo`', function () {
expect(p.uriFragmentIdentifier).to.eql('#/foo');
});
});
it('should have the pointer `/foo`', function() {
expect(p.pointer).to.eql('/foo');
});
describe('a URI fragment identifier of `#/foo`', function () {
var p = ptr.create('#/foo');
it('should have the URI fragment identfier `#/foo`', function() {
expect(p.uriFragmentIdentifier).to.eql('#/foo');
});
it('#get should resolve to data["foo"]', function () {
expect(p.get(data)).to.equal(data.foo);
});
describe('a URI fragment identifier of `#/foo`', function() {
var p = ptr.create('#/foo');
it('#set should succeed changing the referenced value', function () {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('#get should resolve to data["foo"]', function() {
expect(p.get(data)).to.equal(data['foo']);
});
it('should have a path of [ "foo" ]', function () {
expect(p.path).to.eql(['foo']);
});
it('#set should succeed changing the referenced value', function() {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('should have the pointer `/foo`', function () {
expect(p.pointer).to.eql('/foo');
});
it('should have a path of [ "foo" ]', function() {
expect(p.path).to.eql(['foo']);
});
it('should have the URI fragment identfier `#/foo`', function () {
expect(p.uriFragmentIdentifier).to.eql('#/foo');
});
});
it('should have the pointer `/foo`', function() {
expect(p.pointer).to.eql('/foo');
});
describe('with a JSON pointer of `/foo/0`', function () {
var p = ptr.create('/foo/0');
it('should have the URI fragment identfier `#/foo`', function() {
expect(p.uriFragmentIdentifier).to.eql('#/foo');
});
it('#get should resolve to data.foo[0]', function () {
expect(p.get(data)).to.equal(data.foo[0]);
});
describe('with a JSON pointer of `/foo/0`', function() {
var p = ptr.create('/foo/0');
it('#set should succeed changing the referenced value', function () {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('#get should resolve to data.foo[0]', function() {
expect(p.get(data)).to.equal(data.foo[0]);
});
it('should have a path of [ "foo", "0" ]', function () {
expect(p.path).to.eql(['foo', '0']);
});
it('#set should succeed changing the referenced value', function() {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('should have the pointer `/foo/0`', function () {
expect(p.pointer).to.eql('/foo/0');
});
it('should have a path of [ "foo", "0" ]', function() {
expect(p.path).to.eql(['foo', '0']);
});
it('should have the URI fragment identfier `#/foo/0`', function () {
expect(p.uriFragmentIdentifier).to.eql('#/foo/0');
});
});
it('should have the pointer `/foo/0`', function() {
expect(p.pointer).to.eql('/foo/0');
});
describe('a URI fragment identifier of `#/foo/0`', function () {
var p = ptr.create('#/foo/0');
it('should have the URI fragment identfier `#/foo/0`', function() {
expect(p.uriFragmentIdentifier).to.eql('#/foo/0');
});
it('#get should resolve to data.foo[0]', function () {
expect(p.get(data)).to.equal(data.foo[0]);
});
describe('a URI fragment identifier of `#/foo/0`', function() {
var p = ptr.create('#/foo/0');
it('#set should succeed changing the referenced value', function () {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('#get should resolve to data.foo[0]', function() {
expect(p.get(data)).to.equal(data.foo[0]);
});
it('should have a path of [ "foo", "0" ]', function () {
expect(p.path).to.eql(['foo', '0']);
});
it('#set should succeed changing the referenced value', function() {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('should have the pointer `/foo/0`', function () {
expect(p.pointer).to.eql('/foo/0');
});
it('should have a path of [ "foo", "0" ]', function() {
expect(p.path).to.eql(['foo', '0']);
});
it('should have the URI fragment identfier `#/foo/0`', function () {
expect(p.uriFragmentIdentifier).to.eql('#/foo/0');
});
});
it('should have the pointer `/foo/0`', function() {
expect(p.pointer).to.eql('/foo/0');
});
describe('a URI fragment identifier of `#/newArray/0`', function () {
var p = ptr.create('#/newArray/0');
it('should have the URI fragment identfier `#/foo/0`', function() {
expect(p.uriFragmentIdentifier).to.eql('#/foo/0');
});
it('#get should resolve to undefined', function () {
expect(p.get(data)).to.equal(undefined);
});
describe('with a JSON pointer of `/`', function() {
var p = ptr.create('/');
it('#set with force should succeed creating an array and setting the referenced value', function () {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated, true);
expect(data.newArray).to.be.an('array');
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('#get should resolve to data[""]', function() {
expect(p.get(data)).to.equal(data['']);
});
it('should have a path of [ "newArray", "0" ]', function () {
expect(p.path).to.eql(['newArray', '0']);
});
it('#set should succeed changing the referenced value', function() {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('should have the pointer `/newArray/0`', function () {
expect(p.pointer).to.eql('/newArray/0');
});
it('should have a path of [ "" ]', function() {
expect(p.path).to.eql(['']);
});
it('should have the URI fragment identfier `#/newArray/0`', function () {
expect(p.uriFragmentIdentifier).to.eql('#/newArray/0');
});
});
it('should have the pointer `/`', function() {
expect(p.pointer).to.eql('/');
});
describe('with a JSON pointer of `/`', function () {
var p = ptr.create('/');
it('should have the URI fragment identfier `#/`', function() {
expect(p.uriFragmentIdentifier).to.eql('#/');
});
it('#get should resolve to data[""]', function () {
expect(p.get(data)).to.equal(data['']);
});
describe('a URI fragment identifier of `#/`', function() {
var p = ptr.create('#/');
it('#set should succeed changing the referenced value', function () {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('#get should resolve to data[""]', function() {
expect(p.get(data)).to.equal(data['']);
});
it('should have a path of [ "" ]', function () {
expect(p.path).to.eql(['']);
});
it('#set should succeed changing the referenced value', function() {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('should have the pointer `/`', function () {
expect(p.pointer).to.eql('/');
});
it('should have a path of [ "" ]', function() {
expect(p.path).to.eql(['']);
});
it('should have the URI fragment identfier `#/`', function () {
expect(p.uriFragmentIdentifier).to.eql('#/');
});
});
it('should have the pointer `/`', function() {
expect(p.pointer).to.eql('/');
});
describe('a URI fragment identifier of `#/`', function () {
var p = ptr.create('#/');
it('should have the URI fragment identfier `#/`', function() {
expect(p.uriFragmentIdentifier).to.eql('#/');
});
it('#get should resolve to data[""]', function () {
expect(p.get(data)).to.equal(data['']);
});
describe('with a JSON pointer of `/a~1b`', function() {
var p = ptr.create('/a~1b');
it('#set should succeed changing the referenced value', function () {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('#get should resolve to data["a/b"]', function() {
expect(p.get(data)).to.equal(data['a/b']);
});
it('should have a path of [ "" ]', function () {
expect(p.path).to.eql(['']);
});
it('#set should succeed changing the referenced value', function() {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('should have the pointer `/`', function () {
expect(p.pointer).to.eql('/');
});
it('should have a path of [ "a/b" ]', function() {
expect(p.path).to.eql(['a/b']);
});
it('should have the URI fragment identfier `#/`', function () {
expect(p.uriFragmentIdentifier).to.eql('#/');
});
});
it('should have the pointer `/a~1b`', function() {
expect(p.pointer).to.eql('/a~1b');
});
describe('with a JSON pointer of `/a~1b`', function () {
var p = ptr.create('/a~1b');
it('should have the URI fragment identfier `#/a~1b`', function() {
expect(p.uriFragmentIdentifier).to.eql('#/a~1b');
});
it('#get should resolve to data["a/b"]', function () {
expect(p.get(data)).to.equal(data['a/b']);
});
describe('a URI fragment identifier of `#/a~1b`', function() {
var p = ptr.create('#/a~1b');
it('#set should succeed changing the referenced value', function () {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('#get should resolve to data["a/b"]', function() {
expect(p.get(data)).to.equal(data['a/b']);
});
it('should have a path of [ "a/b" ]', function () {
expect(p.path).to.eql(['a/b']);
});
it('#set should succeed changing the referenced value', function() {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('should have the pointer `/a~1b`', function () {
expect(p.pointer).to.eql('/a~1b');
});
it('should have a path of [ "a/b" ]', function() {
expect(p.path).to.eql(['a/b']);
});
it('should have the URI fragment identfier `#/a~1b`', function () {
expect(p.uriFragmentIdentifier).to.eql('#/a~1b');
});
});
it('should have the pointer `/a~1b`', function() {
expect(p.pointer).to.eql('/a~1b');
});
describe('a URI fragment identifier of `#/a~1b`', function () {
var p = ptr.create('#/a~1b');
it('should have the URI fragment identfier `#/a~1b`', function() {
expect(p.uriFragmentIdentifier).to.eql('#/a~1b');
});
it('#get should resolve to data["a/b"]', function () {
expect(p.get(data)).to.equal(data['a/b']);
});
describe('with a JSON pointer of `/c%d`', function() {
var p = ptr.create('/c%d');
it('#set should succeed changing the referenced value', function () {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('#get should resolve to data["c%d"]', function() {
expect(p.get(data)).to.equal(data['c%d']);
});
it('should have a path of [ "a/b" ]', function () {
expect(p.path).to.eql(['a/b']);
});
it('#set should succeed changing the referenced value', function() {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('should have the pointer `/a~1b`', function () {
expect(p.pointer).to.eql('/a~1b');
});
it('should have a path of [ "c%d" ]', function() {
expect(p.path).to.eql(['c%d']);
});
it('should have the URI fragment identfier `#/a~1b`', function () {
expect(p.uriFragmentIdentifier).to.eql('#/a~1b');
});
});
it('should have the pointer `/c%d`', function() {
expect(p.pointer).to.eql('/c%d');
});
describe('with a JSON pointer of `/c%d`', function () {
var p = ptr.create('/c%d');
it('should have the URI fragment identfier `#/c%25d`', function() {
expect(p.uriFragmentIdentifier).to.eql('#/c%25d');
});
it('#get should resolve to data["c%d"]', function () {
expect(p.get(data)).to.equal(data['c%d']);
});
describe('a URI fragment identifier of `#/c%25d`', function() {
var p = ptr.create('#/c%25d');
it('#set should succeed changing the referenced value', function () {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('#get should resolve to data["c%d"]', function() {
expect(p.get(data)).to.equal(data['c%d']);
});
it('should have a path of [ "c%d" ]', function () {
expect(p.path).to.eql(['c%d']);
});
it('#set should succeed changing the referenced value', function() {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('should have the pointer `/c%d`', function () {
expect(p.pointer).to.eql('/c%d');
});
it('should have a path of [ "c%d" ]', function() {
expect(p.path).to.eql(['c%d']);
});
it('should have the URI fragment identfier `#/c%25d`', function () {
expect(p.uriFragmentIdentifier).to.eql('#/c%25d');
});
});
it('should have the pointer `/c%d`', function() {
expect(p.pointer).to.eql('/c%d');
});
describe('a URI fragment identifier of `#/c%25d`', function () {
var p = ptr.create('#/c%25d');
it('should have the URI fragment identfier `#/c%25d`', function() {
expect(p.uriFragmentIdentifier).to.eql('#/c%25d');
});
it('#get should resolve to data["c%d"]', function () {
expect(p.get(data)).to.equal(data['c%d']);
});
describe('with a JSON pointer of `/e^f`', function() {
var p = ptr.create('/e^f');
it('#set should succeed changing the referenced value', function () {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('#get should resolve to data["e^f"]', function() {
expect(p.get(data)).to.equal(data['e^f']);
});
it('should have a path of [ "c%d" ]', function () {
expect(p.path).to.eql(['c%d']);
});
it('#set should succeed changing the referenced value', function() {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('should have the pointer `/c%d`', function () {
expect(p.pointer).to.eql('/c%d');
});
it('should have a path of [ "e^f" ]', function() {
expect(p.path).to.eql(['e^f']);
});
it('should have the URI fragment identfier `#/c%25d`', function () {
expect(p.uriFragmentIdentifier).to.eql('#/c%25d');
});
});
it('should have the pointer `/e^f`', function() {
expect(p.pointer).to.eql('/e^f');
});
describe('with a JSON pointer of `/e^f`', function () {
var p = ptr.create('/e^f');
it('should have the URI fragment identfier `#/e%5Ef`', function() {
expect(p.uriFragmentIdentifier).to.eql('#/e%5Ef');
});
it('#get should resolve to data["e^f"]', function () {
expect(p.get(data)).to.equal(data['e^f']);
});
describe('a URI fragment identifier of `#/e%5Ef`', function() {
var p = ptr.create('#/e%5Ef');
it('#set should succeed changing the referenced value', function () {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('#get should resolve to data["e^f"]', function() {
expect(p.get(data)).to.equal(data['e^f']);
});
it('should have a path of [ "e^f" ]', function () {
expect(p.path).to.eql(['e^f']);
});
it('#set should succeed changing the referenced value', function() {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('should have the pointer `/e^f`', function () {
expect(p.pointer).to.eql('/e^f');
});
it('should have a path of [ "e^f" ]', function() {
expect(p.path).to.eql(['e^f']);
});
it('should have the URI fragment identfier `#/e%5Ef`', function () {
expect(p.uriFragmentIdentifier).to.eql('#/e%5Ef');
});
});
it('should have the pointer `/e^f`', function() {
expect(p.pointer).to.eql('/e^f');
});
describe('a URI fragment identifier of `#/e%5Ef`', function () {
var p = ptr.create('#/e%5Ef');
it('should have the URI fragment identfier `#/e%5Ef`', function() {
expect(p.uriFragmentIdentifier).to.eql('#/e%5Ef');
});
it('#get should resolve to data["e^f"]', function () {
expect(p.get(data)).to.equal(data['e^f']);
});
describe('with a JSON pointer of `/g|h`', function() {
var p = ptr.create('/g|h');
it('#set should succeed changing the referenced value', function () {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('#get should resolve to data["g|h"]', function() {
expect(p.get(data)).to.equal(data['g|h']);
});
it('should have a path of [ "e^f" ]', function () {
expect(p.path).to.eql(['e^f']);
});
it('#set should succeed changing the referenced value', function() {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('should have the pointer `/e^f`', function () {
expect(p.pointer).to.eql('/e^f');
});
it('should have a path of [ "g|h" ]', function() {
expect(p.path).to.eql(['g|h']);
});
it('should have the URI fragment identfier `#/e%5Ef`', function () {
expect(p.uriFragmentIdentifier).to.eql('#/e%5Ef');
});
});
it('should have the pointer `/g|h`', function() {
expect(p.pointer).to.eql('/g|h');
});
describe('with a JSON pointer of `/g|h`', function () {
var p = ptr.create('/g|h');
it('should have the URI fragment identfier `#/g%7Ch`', function() {
expect(p.uriFragmentIdentifier).to.eql('#/g%7Ch');
});
it('#get should resolve to data["g|h"]', function () {
expect(p.get(data)).to.equal(data['g|h']);
});
describe('a URI fragment identifier of `#/g%7Ch`', function() {
var p = ptr.create('#/g%7Ch');
it('#set should succeed changing the referenced value', function () {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('#get should resolve to data["g|h"]', function() {
expect(p.get(data)).to.equal(data['g|h']);
});
it('should have a path of [ "g|h" ]', function () {
expect(p.path).to.eql(['g|h']);
});
it('#set should succeed changing the referenced value', function() {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('should have the pointer `/g|h`', function () {
expect(p.pointer).to.eql('/g|h');
});
it('should have a path of [ "g|h" ]', function() {
expect(p.path).to.eql(['g|h']);
});
it('should have the URI fragment identfier `#/g%7Ch`', function () {
expect(p.uriFragmentIdentifier).to.eql('#/g%7Ch');
});
});
it('should have the pointer `/g|h`', function() {
expect(p.pointer).to.eql('/g|h');
});
describe('a URI fragment identifier of `#/g%7Ch`', function () {
var p = ptr.create('#/g%7Ch');
it('should have the URI fragment identfier `#/g%7Ch`', function() {
expect(p.uriFragmentIdentifier).to.eql('#/g%7Ch');
});
it('#get should resolve to data["g|h"]', function () {
expect(p.get(data)).to.equal(data['g|h']);
});
describe('with a JSON pointer of "/i\\j"', function() {
var p = ptr.create('/i\\j');
it('#set should succeed changing the referenced value', function () {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('#get should resolve to data["i\j"]', function() {
expect(p.get(data)).to.equal(data['i\\j']);
});
it('should have a path of [ "g|h" ]', function () {
expect(p.path).to.eql(['g|h']);
});
it('#set should succeed changing the referenced value', function() {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('should have the pointer `/g|h`', function () {
expect(p.pointer).to.eql('/g|h');
});
it('should have a path of [ "i\\j" ]', function() {
expect(p.path).to.eql(['i\\j']);
});
it('should have the URI fragment identfier `#/g%7Ch`', function () {
expect(p.uriFragmentIdentifier).to.eql('#/g%7Ch');
});
});
it('should have the pointer `/i\\j`', function() {
expect(p.pointer).to.eql('/i\\j');
});
describe('with a JSON pointer of "/i\\j"', function () {
var p = ptr.create('/i\\j');
it('should have the URI fragment identfier `#/i%5Cj`', function() {
expect(p.uriFragmentIdentifier).to.eql('#/i%5Cj');
});
it('#get should resolve to data["i\\j"]', function () {
expect(p.get(data)).to.equal(data['i\\j']);
});
describe('a URI fragment identifier of `#/i%5Cj`', function() {
var p = ptr.create('#/i%5Cj');
it('#set should succeed changing the referenced value', function () {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('#get should resolve to data["i\\j"]', function() {
expect(p.get(data)).to.equal(data['i\\j']);
});
it('should have a path of [ "i\\j" ]', function () {
expect(p.path).to.eql(['i\\j']);
});
it('#set should succeed changing the referenced value', function() {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('should have the pointer `/i\\j`', function () {
expect(p.pointer).to.eql('/i\\j');
});
it('should have a path of [ "i\\j" ]', function() {
expect(p.path).to.eql(['i\\j']);
});
it('should have the URI fragment identfier `#/i%5Cj`', function () {
expect(p.uriFragmentIdentifier).to.eql('#/i%5Cj');
});
});
it('should have the pointer `/i\\j`', function() {
expect(p.pointer).to.eql('/i\\j');
});
describe('a URI fragment identifier of `#/i%5Cj`', function () {
var p = ptr.create('#/i%5Cj');
it('should have the URI fragment identfier `#/i%5Cj`', function() {
expect(p.uriFragmentIdentifier).to.eql('#/i%5Cj');
});
it('#get should resolve to data["i\\j"]', function () {
expect(p.get(data)).to.equal(data['i\\j']);
});
describe('with a JSON pointer of `/k\"l`', function() {
var p = ptr.create('/k\"l');
it('#set should succeed changing the referenced value', function () {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('#get should resolve to data["k\"l"]', function() {
expect(p.get(data)).to.equal(data['k\"l']);
});
it('should have a path of [ "i\\j" ]', function () {
expect(p.path).to.eql(['i\\j']);
});
it('#set should succeed changing the referenced value', function() {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('should have the pointer `/i\\j`', function () {
expect(p.pointer).to.eql('/i\\j');
});
it('should have a path of [ "k\"l" ]', function() {
expect(p.path).to.eql(['k\"l']);
});
it('should have the URI fragment identfier `#/i%5Cj`', function () {
expect(p.uriFragmentIdentifier).to.eql('#/i%5Cj');
});
});
it('should have the pointer `/k\"l`', function() {
expect(p.pointer).to.eql('/k\"l');
});
describe('with a JSON pointer of \'/k\\"l\'', function () {
// eslint-disable-next-line no-useless-escape
var p = ptr.create('/k\"l');
it('should have the URI fragment identfier `#/k%22l`', function() {
expect(p.uriFragmentIdentifier).to.eql('#/k%22l');
});
// eslint-disable-next-line no-useless-escape
it('#get should resolve to data["k\"l"]', function () {
// eslint-disable-next-line no-useless-escape
expect(p.get(data)).to.equal(data['k\"l']);
});
describe('a URI fragment identifier of `#/k%22l`', function() {
var p = ptr.create('#/k%22l');
it('#set should succeed changing the referenced value', function () {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('#get should resolve to data["k\"l"]', function() {
expect(p.get(data)).to.equal(data['k\"l']);
});
// eslint-disable-next-line no-useless-escape
it('should have a path of [ "k\"l" ]', function () {
// eslint-disable-next-line no-useless-escape
expect(p.path).to.eql(['k\"l']);
});
it('#set should succeed changing the referenced value', function() {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
// eslint-disable-next-line no-useless-escape
it('should have the pointer `/k\"l`', function () {
// eslint-disable-next-line no-useless-escape
expect(p.pointer).to.eql('/k\"l');
});
it('should have a path of [ "k\"l" ]', function() {
expect(p.path).to.eql(['k\"l']);
});
it('should have the URI fragment identfier `#/k%22l`', function () {
expect(p.uriFragmentIdentifier).to.eql('#/k%22l');
});
});
it('should have the pointer `/k\"l`', function() {
expect(p.pointer).to.eql('/k\"l');
});
describe('a URI fragment identifier of `#/k%22l`', function () {
var p = ptr.create('#/k%22l');
it('should have the URI fragment identfier `#/k%22l`', function() {
expect(p.uriFragmentIdentifier).to.eql('#/k%22l');
});
// eslint-disable-next-line no-useless-escape
it('#get should resolve to data["k\"l"]', function () {
// eslint-disable-next-line no-useless-escape
expect(p.get(data)).to.equal(data['k\"l']);
});
describe('with a JSON pointer of `/ `', function() {
var p = ptr.create('/ ');
it('#set should succeed changing the referenced value', function () {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('#get should resolve to data[" "]', function() {
expect(p.get(data)).to.equal(data[' ']);
});
// eslint-disable-next-line no-useless-escape
it('should have a path of [ "k\"l" ]', function () {
// eslint-disable-next-line no-useless-escape
expect(p.path).to.eql(['k\"l']);
});
it('#set should succeed changing the referenced value', function() {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
// eslint-disable-next-line no-useless-escape
it('should have the pointer `/k\"l`', function () {
// eslint-disable-next-line no-useless-escape
expect(p.pointer).to.eql('/k\"l');
});
it('should have a path of [ " " ]', function() {
expect(p.path).to.eql([' ']);
});
it('should have the URI fragment identfier `#/k%22l`', function () {
expect(p.uriFragmentIdentifier).to.eql('#/k%22l');
});
});
it('should have the pointer `/ `', function() {
expect(p.pointer).to.eql('/ ');
});
describe('with a JSON pointer of `/ `', function () {
var p = ptr.create('/ ');
it('should have the URI fragment identfier `#/%20`', function() {
expect(p.uriFragmentIdentifier).to.eql('#/%20');
});
it('#get should resolve to data[" "]', function () {
expect(p.get(data)).to.equal(data[' ']);
});
describe('a URI fragment identifier of `#/%20`', function() {
var p = ptr.create('#/%20');
it('#set should succeed changing the referenced value', function () {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('#get should resolve to data[" "]', function() {
expect(p.get(data)).to.equal(data[' ']);
});
it('should have a path of [ " " ]', function () {
expect(p.path).to.eql([' ']);
});
it('#set should succeed changing the referenced value', function() {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('should have the pointer `/ `', function () {
expect(p.pointer).to.eql('/ ');
});
it('should have a path of [ " " ]', function() {
expect(p.path).to.eql([' ']);
});
it('should have the URI fragment identfier `#/%20`', function () {
expect(p.uriFragmentIdentifier).to.eql('#/%20');
});
});
it('should have the pointer `/ `', function() {
expect(p.pointer).to.eql('/ ');
});
describe('a URI fragment identifier of `#/%20`', function () {
var p = ptr.create('#/%20');
it('should have the URI fragment identfier `#/%20`', function() {
expect(p.uriFragmentIdentifier).to.eql('#/%20');
});
it('#get should resolve to data[" "]', function () {
expect(p.get(data)).to.equal(data[' ']);
});
describe('with a JSON pointer of `/m~0n`', function() {
var p = ptr.create('/m~0n');
it('#set should succeed changing the referenced value', function () {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('#get should resolve to data["m~n"]', function() {
expect(p.get(data)).to.equal(data['m~n']);
});
it('should have a path of [ " " ]', function () {
expect(p.path).to.eql([' ']);
});
it('#set should succeed changing the referenced value', function() {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('should have the pointer `/ `', function () {
expect(p.pointer).to.eql('/ ');
});
it('should have a path of [ "m~n" ]', function() {
expect(p.path).to.eql(['m~n']);
});
it('should have the URI fragment identfier `#/%20`', function () {
expect(p.uriFragmentIdentifier).to.eql('#/%20');
});
});
it('should have the pointer `/m~0n`', function() {
expect(p.pointer).to.eql('/m~0n');
});
describe('with a JSON pointer of `/m~0n`', function () {
var p = ptr.create('/m~0n');
it('should have the URI fragment identfier `#/m~0n`', function() {
expect(p.uriFragmentIdentifier).to.eql('#/m~0n');
});
it('#get should resolve to data["m~n"]', function () {
expect(p.get(data)).to.equal(data['m~n']);
});
describe('a URI fragment identifier of `#/m~0n`', function() {
var p = ptr.create('#/m~0n');
it('#set should succeed changing the referenced value', function () {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('#get should resolve to data["m~n"]', function() {
expect(p.get(data)).to.equal(data['m~n']);
});
it('should have a path of [ "m~n" ]', function () {
expect(p.path).to.eql(['m~n']);
});
it('#set should succeed changing the referenced value', function() {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('should have the pointer `/m~0n`', function () {
expect(p.pointer).to.eql('/m~0n');
});
it('should have a path of [ "m~n" ]', function() {
expect(p.path).to.eql(['m~n']);
});
it('should have the URI fragment identfier `#/m~0n`', function () {
expect(p.uriFragmentIdentifier).to.eql('#/m~0n');
});
});
it('should have the pointer `/m~0n`', function() {
expect(p.pointer).to.eql('/m~0n');
});
describe('a URI fragment identifier of `#/m~0n`', function () {
var p = ptr.create('#/m~0n');
it('should have the URI fragment identfier `#/m~0n`', function() {
expect(p.uriFragmentIdentifier).to.eql('#/m~0n');
});
it('#get should resolve to data["m~n"]', function () {
expect(p.get(data)).to.equal(data['m~n']);
});
describe('a special array pointer from draft-ietf-appsawg-json-pointer-08 `/foo/-`', function() {
var p = ptr.create('/foo/-');
it('#set should succeed changing the referenced value', function () {
var capture = p.get(data);
var updated = {
this: 'should succeed'
};
p.set(data, updated);
expect(p.get(data)).to.eql(updated);
p.set(data, capture);
});
it('should not resolve via #get', function() {
expect(p.get(data)).to.not.be.ok();
});
it('should have a path of [ "m~n" ]', function () {
expect(p.path).to.eql(['m~n']);
});
it('should set the next element of the array, repeatedly...', function() {
p.set(data, 'qux');
expect(data.foo[2]).to.eql('qux');
});
it('should have the pointer `/m~0n`', function () {
expect(p.pointer).to.eql('/m~0n');
});
it('...', function() {
p.set(data, 'quux');
expect(data.foo[3]).to.eql('quux');
});
it('should have the URI fragment identfier `#/m~0n`', function () {
expect(p.uriFragmentIdentifier).to.eql('#/m~0n');
});
});
it('...', function() {
p.set(data, 'corge');
expect(data.foo[4]).to.eql('corge');
});
describe('a special array pointer from draft-ietf-appsawg-json-pointer-08 `/foo/-`', function () {
var p = ptr.create('/foo/-');
it('...', function() {
p.set(data, 'grault');
expect(data.foo[5]).to.eql('grault');
});
it('should not resolve via #get', function () {
expect(p.get(data)).to.not.be.ok();
});
describe('an invalid pointer', function() {
it('should set the next element of the array, repeatedly...', function () {
p.set(data, 'qux');
expect(data.foo[2]).to.eql('qux');
});
it('should fail to parse', function() {
expect(function() {
ptr.create('a/');
}).to.throwError();
});
it('...3', function () {
p.set(data, 'quux');
expect(data.foo[3]).to.eql('quux');
});
describe('an invalid URI fragment identifier', function() {
it('...4', function () {
p.set(data, 'corge');
expect(data.foo[4]).to.eql('corge');
});
it('should fail to parse', function() {
expect(function() {
ptr.create('#a');
}).to.throwError();
});
it('...5', function () {
p.set(data, 'grault');
expect(data.foo[5]).to.eql('grault');
});
});
describe('an invalid pointer', function () {
it('should fail to parse', function () {
expect(function () {
ptr.create('a/');
}).to.throwError();
});
});
describe('can revert namespace using noConflict', function() {
ptr = ptr.noConflict();
describe('an invalid URI fragment identifier', function () {
it('conflict is restored (when applicable)', function() {
// In node there is no global conflict.
if (typeof globalConflict !== 'undefined') {
expect(JsonPointer).to.be(globalConflict); // eslint-disable-line no-undef
}
it('should fail to parse', function () {
expect(function () {
ptr.create('#a');
}).to.throwError();
});
it('JsonPointer functionality available through result of noConflict()', function() {
expect(ptr).to.have.property('get');
});
});
});
describe('when working with complex data', function() {
var data = {
a: 1,
b: {
c: 2
},
d: {
e: [{
a: 3
}, {
b: 4
}, {
c: 5
}]
},
f: null,
'http://schema.org/name': 'Phillip'
};
describe('can revert namespace using noConflict', function () {
ptr = ptr.noConflict();
it('conflict is restored (when applicable)', function () {
// In node there is no global conflict.
if (typeof globalConflict !== 'undefined') {
expect(JsonPointer).to.be(globalConflict); // eslint-disable-line no-undef
}
});
it('#get should return `undefined` when the requested element is undefined (#/g/h)',
function() {
var unk = ptr.get(data, '#/g/h');
expect(unk).to.be.an('undefined');
});
it('JsonPointer functionality available through result of noConflict()', function () {
expect(ptr).to.have.property('get');
});
});
describe('when working with complex data', function () {
var data = {
a: 1,
b: {
c: 2
},
d: {
e: [{
a: 3
}, {
b: 4
}, {
c: 5
}]
},
f: null,
'http://schema.org/name': 'Phillip'
};
it('#get should return null when the requested element has a null value (#/f)',
function() {
var unk = ptr.get(data, '#/f');
expect(unk).to.be(null);
});
it('#get should return the value of a prop named with multiple slahes (#/http:~1~1schema.org~1name)',
function() {
var unk = ptr.get(data, '#/http:~1~1schema.org~1name');
expect(unk).to.be('Phillip');
});
it('#get should return `undefined` when the requested element is undefined (#/g/h)',
function () {
var unk = ptr.get(data, '#/g/h');
expect(unk).to.be.an('undefined');
});
it('#get should return the value of a prop named with multiple slahes (/http:~1~1schema.org~1name)',
function() {
var unk = ptr.get(data, '/http:~1~1schema.org~1name');
expect(unk).to.be('Phillip');
});
it('#set should set the value of a prop named with multiple slahes (#/http:~1~1schema.org~1name)',
function() {
ptr.set(data, '#/http:~1~1schema.org~1name', 'Phil');
let unk = ptr.get(data, '/http:~1~1schema.org~1name');
expect(unk).to.be('Phil');
});
it('#get should return null when the requested element has a null value (#/f)',
function () {
var unk = ptr.get(data, '#/f');
expect(unk).to.be(null);
});
it('#set should set the value of a prop named with multiple slahes (/http:~1~1schema.org~1name)',
function() {
ptr.set(data, '/http:~1~1schema.org~1name', 'Phil');
let unk = ptr.get(data, '/http:~1~1schema.org~1name');
expect(unk).to.be('Phil');
});
it('#get should return the value of a prop named with multiple slahes (#/http:~1~1schema.org~1name)',
function () {
var unk = ptr.get(data, '#/http:~1~1schema.org~1name');
expect(unk).to.be('Phillip');
});
});
it('#get should return the value of a prop named with multiple slahes (/http:~1~1schema.org~1name)',
function () {
var unk = ptr.get(data, '/http:~1~1schema.org~1name');
expect(unk).to.be('Phillip');
});
describe('given an sequence of property names ["d", "e~f", "2"]', function() {
var path = ['d', 'e~f', '2'];
it('#encodePointer should produce a pointer (/d/e~0f/2)', function() {
expect(ptr.encodePointer(path)).to.be('/d/e~0f/2');
it('#set should set the value of a prop named with multiple slahes (#/http:~1~1schema.org~1name)',
function () {
ptr.set(data, '#/http:~1~1schema.org~1name', 'Phil');
var unk = ptr.get(data, '/http:~1~1schema.org~1name');
expect(unk).to.be('Phil');
});
it('#encodeUriFragmentIdentifier should produce a pointer (#/d/e~0f/2)', function() {
expect(ptr.encodeUriFragmentIdentifier(path)).to.be('#/d/e~0f/2');
it('#set should set the value of a prop named with multiple slahes (/http:~1~1schema.org~1name)',
function () {
ptr.set(data, '/http:~1~1schema.org~1name', 'Phil');
var unk = ptr.get(data, '/http:~1~1schema.org~1name');
expect(unk).to.be('Phil');
});
});
describe('given an sequence of property names ["d", "e~f", "2"]', function () {
var path = ['d', 'e~f', '2'];
it('#encodePointer should produce a pointer (/d/e~0f/2)', function () {
expect(ptr.encodePointer(path)).to.be('/d/e~0f/2');
});
describe('#list', function() {
var data = {
a: 1,
b: {
c: 2
},
d: {
e: [{
a: 3
}, {
b: 4
}, {
c: 5
}]
},
f: null
};
var tests = [
['#list(data)', [data, undefined], 'pointer', [
['', data],
['/a', data.a],
['/b', data.b],
['/d', data.d],
['/f', data.f],
['/b/c', data.b.c],
['/d/e', data.d.e],
['/d/e/0', data.d.e[0]],
['/d/e/1', data.d.e[1]],
['/d/e/2', data.d.e[2]],
['/d/e/0/a', data.d.e[0].a],
['/d/e/1/b', data.d.e[1].b],
['/d/e/2/c', data.d.e[2].c]
]],
['#list(data, true)', [data, true], 'fragmentId', [
['#', data],
['#/a', data.a],
['#/b', data.b],
['#/d', data.d],
['#/f', data.f],
['#/b/c', data.b.c],
['#/d/e', data.d.e],
['#/d/e/0', data.d.e[0]],
['#/d/e/1', data.d.e[1]],
['#/d/e/2', data.d.e[2]],
['#/d/e/0/a', data.d.e[0].a],
['#/d/e/1/b', data.d.e[1].b],
['#/d/e/2/c', data.d.e[2].c]
]]
];
tests.forEach(function(test) {
describe(test[0], function() {
var items;
before(function() {
items = ptr.list(test[1][0], test[1][1]);
it('#encodeUriFragmentIdentifier should produce a pointer (#/d/e~0f/2)', function () {
expect(ptr.encodeUriFragmentIdentifier(path)).to.be('#/d/e~0f/2');
});
});
describe('#list', function () {
var data = {
a: 1,
b: {
c: 2
},
d: {
e: [{
a: 3
}, {
b: 4
}, {
c: 5
}]
},
f: null
};
var tests = [
['#list(data)', [data, undefined], 'pointer', [
['', data],
['/a', data.a],
['/b', data.b],
['/d', data.d],
['/f', data.f],
['/b/c', data.b.c],
['/d/e', data.d.e],
['/d/e/0', data.d.e[0]],
['/d/e/1', data.d.e[1]],
['/d/e/2', data.d.e[2]],
['/d/e/0/a', data.d.e[0].a],
['/d/e/1/b', data.d.e[1].b],
['/d/e/2/c', data.d.e[2].c]
]],
['#list(data, true)', [data, true], 'fragmentId', [
['#', data],
['#/a', data.a],
['#/b', data.b],
['#/d', data.d],
['#/f', data.f],
['#/b/c', data.b.c],
['#/d/e', data.d.e],
['#/d/e/0', data.d.e[0]],
['#/d/e/1', data.d.e[1]],
['#/d/e/2', data.d.e[2]],
['#/d/e/0/a', data.d.e[0].a],
['#/d/e/1/b', data.d.e[1].b],
['#/d/e/2/c', data.d.e[2].c]
]]
];
tests.forEach(function (test) {
describe(test[0], function () {
var items;
before(function () {
items = ptr.list(test[1][0], test[1][1]);
});
test[3].forEach(function (tt, n) {
it('item ' + n + ' has ' + test[2] + ' \'' + tt[0] + '\'', function () {
expect(items[n][test[2]]).to.equal(tt[0]);
});
test[3].forEach(function(tt, n) {
it('item ' + n + ' has ' + test[2] + ' \'' + tt[0] + '\'', function() {
expect(items[n][test[2]]).to.equal(tt[0]);
});
it('item ' + n + ' has correct value', function() {
expect(items[n].value).to.equal(tt[1]);
});
it('item ' + n + ' has correct value', function () {
expect(items[n].value).to.equal(tt[1]);
});
});
});
});
});
});
describe('when data contains an array early in the path', function () {
var data = {
foo: []
};
it('#set(o, val, true) should create the path through the array #/foo/0/wilbur/idiocies',
function () {
var p = ptr.create('#/foo/0/wilbur/idiocies');
p.set(data, 5, true);
expect(p.get(data)).to.be(5);
});
});
});
}).call(root, root.JsonPointer, root.expect);
}).call(this);
}));

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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