Socket
Socket
Sign inDemoInstall

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.1.2 to 1.2.0

2

dist/json-ptr.min.js

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

!function(e,n){"function"==typeof define&&define.amd?define([],n):"object"==typeof module&&module.exports?module.exports=n():e.returnExports=n()}("undefined"!=typeof self?self:this,function(){var e=this,n=this.JsonPointer;function a(e,n,r){for(var t=e.toString(),i="",o=t,u=0,f=-1;-1<(f=o.indexOf(n));)i+=t.substring(u,u+f)+r,o=o.substring(f+n.length,o.length),u+=f+n.length;return 0<o.length&&(i+=t.substring(t.length-o.length,t.length)),i}function t(e){if("string"!=typeof e)throw new TypeError("Invalid type: JSON Pointers are represented as strings.");if(0===e.length)return[];if("/"!==e[0])throw new ReferenceError("Invalid JSON Pointer syntax. Non-empty pointer must begin with a solidus `/`.");return function(e){for(var n=-1,r=e.length,t=new Array(r);++n<r;)t[n]=a(a(e[n],"~1","/"),"~0","~");return t}(e.substring(1).split("/"))}function y(e){if(e&&!Array.isArray(e))throw new TypeError("Invalid type: path must be an array of segments.");return 0===e.length?"":"/".concat(function(e){for(var n=-1,r=e.length,t=new Array(r);++n<r;)"string"==typeof e[n]?t[n]=a(a(e[n],"~","~0"),"/","~1"):t[n]=e[n];return t}(e).join("/"))}function r(e){if("string"!=typeof e)throw new TypeError("Invalid type: JSON Pointers are represented as strings.");if(0===e.length||"#"!==e[0])throw new ReferenceError("Invalid JSON Pointer syntax; URI fragment idetifiers must begin with a hash.");if(1===e.length)return[];if("/"!==e[1])throw new ReferenceError("Invalid JSON Pointer syntax.");return function(e){for(var n=-1,r=e.length,t=new Array(r);++n<r;)t[n]=a(a(decodeURIComponent(""+e[n]),"~1","/"),"~0","~");return t}(e.substring(2).split("/"))}function d(e){if(e&&!Array.isArray(e))throw new TypeError("Invalid type: path must be an array of segments.");return 0===e.length?"#":"#/".concat(function(e){for(var n=-1,r=e.length,t=new Array(r);++n<r;)"string"==typeof e[n]?t[n]=encodeURIComponent(a(a(e[n],"~","~0"),"/","~1")):t[n]=e[n];return t}(e).join("/"))}function g(e,n){var r=n.length,t=0;if(1===r&&"-"===n[0])return Array.isArray(e)?e.length:0;if(0===r||1<r&&"0"===n[0]||!isFinite(n))return-1;for(;++t<r;)if(n[t]<"0"||"9"<n[t])return-1;return parseInt(n,10)}function s(e,n,r,t){var i,o,u,f,a,s,c,l;if(0===r.length)throw new Error("Cannot set the root object; assign it directly.");if(void 0===e)throw new TypeError("Cannot set values on undefined");if(i=e,o=r.length,u=r.length-1,f=-1,o)for(;++f<o;)if(a=r[f],Array.isArray(i)){if(s=g(i,a),i.length>s){if(f===u)return c=i[s],i[s]=n,c;i=i[s]}else if(i.length===s){if(f===u)return i.push(n),l;t&&(i=i[s]={})}}else{if(void 0===i[a]){if(t){if(f===u)return i[a]=n,l;if(-1!==g(i[a],r[f+1])){i=i[a]=[];continue}i=i[a]={};continue}return l}if(f===u)return c=i[a],i[a]=n,c;i=i[a]}return i}function c(e){return(n=e)&&n.length&&"#"===n[0]?r:t;var n}function p(e){var n,r,t,i,o=Array.isArray(e)?e.slice(0):e=c(e)(e),u=Array.isArray(e)?y(o):e,f=(i="if (typeof(obj) !== 'undefined'",0===(t=o).length?function(e){return e}:(i=t.reduce(function(e,n,r){return e+" && \n\ttypeof((obj = obj['"+a(t[r],"\\","\\\\")+"'])) !== 'undefined'"},"if (typeof(obj) !== 'undefined'"),i+=") {\n\treturn obj;\n }",new Function(["obj"],i)));Object.defineProperties(this,{get:{enumerable:!0,value:f},set:{enumerable:!0,value:function(e,n,r){return s(e,n,o,r)}},has:{enumerable:!0,value:function(e){return void 0!==f(e)}},path:{enumerable:!0,get:function(){return o.slice(0)}},pointer:{enumerable:!0,get:function(){return n||(n=y(o)),n}},uriFragmentIdentifier:{enumerable:!0,get:function(){return r||(r=d(o)),r}},toString:{enumerable:!0,configurable:!0,writable:!0,value:function(){return u}}})}function b(e){var n="string"==typeof e||Array.isArray(e)?new p(e):e;Object.defineProperties(this,{$ref:{enumerable:!0,value:n.uriFragmentIdentifier},resolve:{enumerable:!0,value:function(e){return n.get(e)}},toString:{enumerable:!0,writable:!0,configurable:!0,value:function(){return n.uriFragmentIdentifier}}})}function i(e,n,r){var t,i,o,u,f,a,s,c,l,g=[],h=0;for(g.push({obj:e,path:[]}),r&&(l=Object.create(null)),n(y([]),e);h<g.length;)if("object"===typeof(c=g[h++]).obj&&null!==c.obj)if(Array.isArray(c.obj))for(u=-1,f=c.obj.length;++u<f;){if(a=c.obj[u],s=c.path.concat(u),"object"==typeof a&&null!==a){if(r&&l[a]){n(y(s),new b(l[a]));continue}g.push({obj:a,path:s}),r&&(l[a]=new p(d(s)))}n(y(s),a)}else for(o=(t=Object.keys(c.obj)).length,i=-1;++i<o;){if(a=c.obj[t[i]],s=c.path.concat(t[i]),"object"==typeof a&&null!==a){if(r&&l[a]){n(y(s),new b(l[a]));continue}g.push({obj:a,path:s}),r&&(l[a]=new p(d(s)))}n(y(s),a)}}return b.isReference=function(e){return e&&e instanceof b||"string"==typeof e.$ref&&"function"==typeof e.resolve},p.create=function(e){return new p(e)},p.has=function(e,n){return function(e,n){var r,t,i,o,u;if(void 0===e)return!1;if(r=e,i=-1,t=n.length)for(;++i<t&&r;)if(o=n[i],Array.isArray(r)){if(isNaN(o)||!isFinite(o)){r=r[o];continue}if(u=g(r,o),!(r.length>u))break;r=r[u]}else r=r[o];return i===t&&void 0!==r}(e,c(n)(n))},p.get=function(e,n){return function(e,n){var r,t,i,o,u;if(void 0!==e){if(r=e,i=-1,t=n.length)for(;++i<t&&r;)if(o=n[i],Array.isArray(r)){if(isNaN(o)||!isFinite(o)){r=r[o];continue}if(u=g(r,o),!(r.length>u))return;r=r[u]}else r=r[o];return r}}(e,c(n)(n))},p.set=function(e,n,r,t){return s(e,r,c(n)(n),t)},p.list=function(e,n){var r=[];return i(e,n?function(e,n){r.push({fragmentId:d(t(e)),value:n})}:function(e,n){r.push({pointer:e,value:n})}),r},p.flatten=function(e,n){var r={};return i(e,n?function(e,n){r[d(t(e))]=n}:function(e,n){r[e]=n}),r},p.map=function(e,n){var r=[];return i(e,n?function(e,n){r.push({key:d(t(e)),value:n})}:r.set.bind(r)),r},p.visit=i,p.decode=function(e){return c(e)(e)},p.decodePointer=t,p.encodePointer=y,p.decodeUriFragmentIdentifier=r,p.encodeUriFragmentIdentifier=d,(p.JsonPointer=p).JsonReference=b,p.isReference=b.isReference,p.noConflict=function(){return e.JsonPointer=n,p},e.JsonPointer=p});
!function(e,n){"function"==typeof define&&define.amd?define([],n):"object"==typeof module&&module.exports?module.exports=n():e.returnExports=n()}("undefined"!=typeof self?self:this,function(){var e=this,n=this.JsonPointer;function o(e,n,r){for(var t=e.toString(),i="",o=t,u=0,f=-1;-1<(f=o.indexOf(n));)i+=t.substring(u,u+f)+r,o=o.substring(f+n.length,o.length),u+=f+n.length;return 0<o.length&&(i+=t.substring(t.length-o.length,t.length)),i}function t(e){if("string"!=typeof e)throw new TypeError("Invalid type: JSON Pointers are represented as strings.");if(0===e.length)return[];if("/"!==e[0])throw new ReferenceError("Invalid JSON Pointer syntax. Non-empty pointer must begin with a solidus `/`.");return function(e){for(var n=-1,r=e.length,t=new Array(r);++n<r;)t[n]=o(o(e[n],"~1","/"),"~0","~");return t}(e.substring(1).split("/"))}function p(e){if(e&&!Array.isArray(e))throw new TypeError("Invalid type: path must be an array of segments.");return 0===e.length?"":"/".concat(function(e){for(var n=-1,r=e.length,t=new Array(r);++n<r;)"string"==typeof e[n]?t[n]=o(o(e[n],"~","~0"),"/","~1"):t[n]=e[n];return t}(e).join("/"))}function r(e){if("string"!=typeof e)throw new TypeError("Invalid type: JSON Pointers are represented as strings.");if(0===e.length||"#"!==e[0])throw new ReferenceError("Invalid JSON Pointer syntax; URI fragment idetifiers must begin with a hash.");if(1===e.length)return[];if("/"!==e[1])throw new ReferenceError("Invalid JSON Pointer syntax.");return function(e){for(var n=-1,r=e.length,t=new Array(r);++n<r;)t[n]=o(o(decodeURIComponent(""+e[n]),"~1","/"),"~0","~");return t}(e.substring(2).split("/"))}function d(e){if(e&&!Array.isArray(e))throw new TypeError("Invalid type: path must be an array of segments.");return 0===e.length?"#":"#/".concat(function(e){for(var n=-1,r=e.length,t=new Array(r);++n<r;)"string"==typeof e[n]?t[n]=encodeURIComponent(o(o(e[n],"~","~0"),"/","~1")):t[n]=e[n];return t}(e).join("/"))}function h(e,n){var r=n.length,t=0;if(1===r&&"-"===n[0])return Array.isArray(e)?e.length:0;if(0===r||1<r&&"0"===n[0]||!isFinite(n))return-1;for(;++t<r;)if(n[t]<"0"||"9"<n[t])return-1;return parseInt(n,10)}function u(e,n,r,t){var i,o,u,f,a,s,c,l;if(0===r.length)throw new Error("Cannot set the root object; assign it directly.");if(void 0===e)throw new TypeError("Cannot set values on undefined");if(i=e,o=r.length,u=r.length-1,f=-1,o)for(;++f<o;)if(a=r[f],Array.isArray(i)){if(s=h(i,a),i.length>s){if(f===u)return c=i[s],i[s]=n,c;i=i[s]}else if(i.length===s){if(f===u)return i.push(n),l;t&&(i=i[s]={})}}else{if(void 0===i[a]){if(t){if(f===u)return i[a]=n,l;if(-1!==h(i[a],r[f+1])){i=i[a]=[];continue}i=i[a]={};continue}return l}if(f===u)return c=i[a],i[a]=n,c;i=i[a]}return i}function i(e){return function(e){return e&&e.length&&"#"===e[0]}(e)?r:t}function f(e){return Array.isArray(e)?e.slice(0):i(e)(e)}function y(e){var n,r,t=f(e),i=function(t){var e="if (typeof(obj) !== 'undefined'";return 0===t.length?function(e){return e}:(e=t.reduce(function(e,n,r){return e+" && \n\ttypeof((obj = obj['"+o(t[r],"\\","\\\\")+"'])) !== 'undefined'"},"if (typeof(obj) !== 'undefined'"),e+=") {\n\treturn obj;\n }",new Function(["obj"],e))}(t);Object.defineProperties(this,{get:{enumerable:!0,value:i},set:{enumerable:!0,value:function(e,n,r){return u(e,n,t,r)}},has:{enumerable:!0,value:function(e){return void 0!==i(e)}},concat:{enumerable:!0,value:function(e){return new y(t.concat(e instanceof y?e.path:f(e)))}},path:{enumerable:!0,get:function(){return t.slice(0)}},pointer:{enumerable:!0,get:function(){return n=n||p(t)}},uriFragmentIdentifier:{enumerable:!0,get:function(){return r=r||d(t)}},toString:{enumerable:!0,configurable:!0,writable:!0,value:function(){return this.pointer}}})}function b(e){var n="string"==typeof e||Array.isArray(e)?new y(e):e;Object.defineProperties(this,{$ref:{enumerable:!0,value:n.uriFragmentIdentifier},resolve:{enumerable:!0,value:function(e){return n.get(e)}},toString:{enumerable:!0,writable:!0,configurable:!0,value:function(){return n.uriFragmentIdentifier}}})}function a(e,n,r){var t,i,o,u,f,a,s,c,l,h=[],g=0;for(h.push({obj:e,path:[]}),r&&(l=Object.create(null)),n(p([]),e);g<h.length;)if("object"==typeof(c=h[g++]).obj&&null!==c.obj)if(Array.isArray(c.obj))for(u=-1,f=c.obj.length;++u<f;){if(a=c.obj[u],s=c.path.concat(u),"object"==typeof a&&null!==a){if(r&&l[a]){n(p(s),new b(l[a]));continue}h.push({obj:a,path:s}),r&&(l[a]=new y(d(s)))}n(p(s),a)}else for(o=(t=Object.keys(c.obj)).length,i=-1;++i<o;){if(a=c.obj[t[i]],s=c.path.concat(t[i]),"object"==typeof a&&null!==a){if(r&&l[a]){n(p(s),new b(l[a]));continue}h.push({obj:a,path:s}),r&&(l[a]=new y(d(s)))}n(p(s),a)}}return b.isReference=function(e){return e&&e instanceof b||"string"==typeof e.$ref&&"function"==typeof e.resolve},y.create=function(e){return new y(e)},y.has=function(e,n){return function(e,n){var r,t,i,o,u;if(void 0===e)return!1;if(r=e,i=-1,t=n.length)for(;++i<t&&r;)if(o=n[i],Array.isArray(r)){if(isNaN(o)||!isFinite(o)){r=r[o];continue}if(u=h(r,o),!(r.length>u))break;r=r[u]}else r=r[o];return i===t&&void 0!==r}(e,i(n)(n))},y.get=function(e,n){return function(e,n){var r,t,i,o,u;if(void 0!==e){if(r=e,i=-1,t=n.length)for(;++i<t&&r;)if(o=n[i],Array.isArray(r)){if(isNaN(o)||!isFinite(o)){r=r[o];continue}if(u=h(r,o),!(r.length>u))return;r=r[u]}else r=r[o];return r}}(e,i(n)(n))},y.set=function(e,n,r,t){return u(e,r,i(n)(n),t)},y.list=function(e,n){var r=[];return a(e,n?function(e,n){r.push({fragmentId:d(t(e)),value:n})}:function(e,n){r.push({pointer:e,value:n})}),r},y.flatten=function(e,n){var r={};return a(e,n?function(e,n){r[d(t(e))]=n}:function(e,n){r[e]=n}),r},y.map=function(e,n){var r=[];return a(e,n?function(e,n){r.push({key:d(t(e)),value:n})}:r.set.bind(r)),r},y.visit=a,y.decode=function(e){return i(e)(e)},y.decodePointer=t,y.encodePointer=p,y.decodeUriFragmentIdentifier=r,y.encodeUriFragmentIdentifier=d,(y.JsonPointer=y).JsonReference=b,y.isReference=b.isReference,y.noConflict=function(){return e.JsonPointer=n,y},e.JsonPointer=y});

@@ -312,8 +312,11 @@ (function (root, factory) {

function decodePtrInit(ptr) {
return (Array.isArray(ptr)) ?
ptr.slice(0) :
pickDecoder(ptr)(ptr);
}
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 localPath = decodePtrInit(ptr);
var $pointer;

@@ -339,2 +342,8 @@ var $fragmentId;

},
concat: {
enumerable: true,
value: function (target) {
return new JsonPointer(localPath.concat(target instanceof JsonPointer ? target.path : decodePtrInit(target)));
}
},
path: {

@@ -369,3 +378,3 @@ enumerable: true,

value: function () {
return $original;
return this.pointer;
}

@@ -372,0 +381,0 @@ }

{
"name": "json-ptr",
"version": "1.1.2",
"version": "1.2.0",
"author": "Phillip Clark <phillip@flitbit.com>",

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

"pretest": "npm run lint",
"test": "mocha test/**/*.js",
"test": "mocha test/**/*.js --reporter tap",
"test:watch": "nodemon --ext js,json --ignore dist/ --exec 'npm test'",

@@ -33,13 +33,13 @@ "preci": "npm run lint",

"devDependencies": {
"bluebird": "^3.5.3",
"eslint": "^5.15.1",
"eslint-plugin-mocha": "^5.3.0",
"bluebird": "^3.5.5",
"eslint": "^6.4.0",
"eslint-plugin-mocha": "^6.1.1",
"expect.js": "^0.3.1",
"json": "^9.0.6",
"mocha": "^6.0.2",
"mocha-junit-reporter": "^1.18.0",
"nodemon": "^1.18.10",
"rimraf": "^2.6.3",
"uglify-js": "^3.4.9"
"mocha": "^6.2.0",
"mocha-junit-reporter": "^1.23.1",
"nodemon": "^1.19.2",
"rimraf": "^3.0.0",
"uglify-js": "^3.6.0"
}
}

@@ -5,4 +5,2 @@ # json-ptr

[![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.

@@ -484,2 +482,10 @@

#### .concat(target)
Creates new pointer appending target to the current pointer's path
_arguments:_
* `target` : _JsonPointer, array or string, required_ &ndash; the path to be appended to the current path
## Performance

@@ -486,0 +492,0 @@

@@ -1008,2 +1008,24 @@ (function (root, factory) {

describe('concat pointers', function () {
var ptr1 = ptr.create('/a/b');
var ptr2 = ptr.create('/c/d');
var result = '/a/b/c/d';
it('#concat JsonPointer("/a/b") with array ["a", "b"] should produce ' + result, function () {
expect(ptr1.concat(Array.from(ptr2.path)).pointer).to.be(result);
});
it('#concat JsonPointer("/a/b") with JsonPointer("/b/c") should produce ' + result, function () {
expect(ptr1.concat(ptr2).pointer).to.be(result);
});
it('#concat JsonPointer("/a/b") with string "/b/c" should produce ' + result, function () {
expect(ptr1.concat(ptr2.pointer).pointer).to.be(result);
});
it('#concat JsonPointer("/a/b") with string "#/b/c" should produce ' + result, function () {
expect(ptr1.concat(ptr2.uriFragmentIdentifier).toString()).to.be(result);
});
});
}));

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