json-pointer
Advanced tools
Comparing version 0.5.0 to 0.6.0
13
index.js
@@ -107,3 +107,14 @@ 'use strict'; | ||
} | ||
delete api.get(obj, refTokens.slice(0, -1))[finalToken]; | ||
var parent = api.get(obj, refTokens.slice(0, -1)); | ||
if (Array.isArray(parent)) { | ||
var index = +finalToken; | ||
if (finalToken === '' && isNaN(index)) { | ||
throw new Error('Invalid array index: "' + finalToken + '"'); | ||
} | ||
Array.prototype.splice.call(parent, index, 1); | ||
} else { | ||
delete parent[finalToken]; | ||
} | ||
}; | ||
@@ -110,0 +121,0 @@ |
{ | ||
"name": "json-pointer", | ||
"description": "Some utilities for JSON pointers described by RFC 6901", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"author": "Manuel Stofer <manuel@takimata.ch>", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
@@ -18,9 +18,3 @@ # json-pointer | ||
[component](https://github.com/component/component) | ||
```bash | ||
$ component install manuelstofer/json-pointer | ||
``` | ||
## API | ||
@@ -27,0 +21,0 @@ |
@@ -180,20 +180,45 @@ /*global describe, it, beforeEach*/ | ||
each(Object.keys(rfcValues), function (p) { | ||
if (p !== '') { | ||
it('should work for "' + p + '"', function () { | ||
pointer.remove(rfcExample, p); | ||
expect(pointer.get.bind(pointer, rfcExample, p)).to.throw(Error); | ||
}); | ||
} | ||
if (p === '' || p === '/foo/0') return; | ||
it('should work for "' + p + '"', function () { | ||
pointer.remove(rfcExample, p); | ||
expect(pointer.get.bind(pointer, rfcExample, p)).to.throw(Error); | ||
}); | ||
}); | ||
it('should work for "/foo/0"', function () { | ||
var p = '/foo/0'; | ||
pointer.remove(rfcExample, p); | ||
expect(pointer.get(rfcExample, p)).to.equal('baz'); | ||
}); | ||
it('should work for "/foo/1"', function () { | ||
var p = '/foo/1'; | ||
pointer.remove(rfcExample, p); | ||
expect(pointer.get.bind(pointer, rfcExample, p)).to.throw(Error); | ||
}); | ||
each(Object.keys(rfcParsed), function (p) { | ||
if (p !== '') { | ||
it('should work for ' + JSON.stringify(rfcParsed[p].tokens), function () { | ||
pointer.remove(rfcExample, immutable(rfcParsed[p].tokens)); | ||
expect(function() { | ||
pointer.get(pointer, rfcExample, immutable(rfcParsed[p].tokens)); | ||
}).to.throw(Error); | ||
}); | ||
} | ||
if (p === '' || p === '/foo/0') return; | ||
it('should work for ' + JSON.stringify(rfcParsed[p].tokens), function () { | ||
pointer.remove(rfcExample, immutable(rfcParsed[p].tokens)); | ||
expect(function() { | ||
pointer.get(rfcExample, immutable(rfcParsed[p].tokens)); | ||
}).to.throw(Error); | ||
}); | ||
}); | ||
it('should work for ["foo","0"]', function () { | ||
var p = immutable(['foo', '0']); | ||
pointer.remove(rfcExample, p); | ||
expect(pointer.get(rfcExample, p)).to.equal('baz'); | ||
}); | ||
it('should work for ["foo","1"]', function () { | ||
var p = immutable(['foo', '1']); | ||
pointer.remove(rfcExample, p); | ||
expect(pointer.get.bind(pointer, rfcExample, p)).to.throw(Error); | ||
}); | ||
}); | ||
@@ -200,0 +225,0 @@ |
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
25584
565
9
160