UNPKG

big-json-viewer

Version:

JavaScript Library to view big JSON structures.

11 lines 14.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /* tslint:disable */ function initWorker() { var blob = new Blob(["parcelRequire=function(e,r,t,n){var i,o=\"function\"==typeof parcelRequire&&parcelRequire,u=\"function\"==typeof require&&require;function f(t,n){if(!r[t]){if(!e[t]){var i=\"function\"==typeof parcelRequire&&parcelRequire;if(!n&&i)return i(t,!0);if(o)return o(t,!0);if(u&&\"string\"==typeof t)return u(t);var c=new Error(\"Cannot find module '\"+t+\"'\");throw c.code=\"MODULE_NOT_FOUND\",c}p.resolve=function(r){return e[t][1][r]||r},p.cache={};var l=r[t]=new f.Module(t);e[t][0].call(l.exports,p,l,l.exports,this)}return r[t].exports;function p(e){return f(p.resolve(e))}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.exports={}},f.modules=e,f.cache=r,f.parent=o,f.register=function(r,t){e[r]=[function(e,r){r.exports=t},{}]};for(var c=0;c<t.length;c++)try{f(t[c])}catch(e){i||(i=e)}if(t.length){var l=f(t[t.length-1]);\"object\"==typeof exports&&\"undefined\"!=typeof module?module.exports=l:\"function\"==typeof define&&define.amd?define(function(){return l}):n&&(this[n]=l)}if(parcelRequire=f,i)throw i;return f}({\"../helpers/worker-provider.ts\":[function(require,module,exports) {\n\"use strict\";function e(e,s){void 0===s&&(s=self),s.onmessage=function(t){var r=t.data;if(r._init)s.postMessage({_init:!0});else if(r.handler&&e[r.handler])try{var a=e[r.handler].apply(e,r.args);r.resultId&&s.postMessage({resultId:r.resultId,result:a})}catch(i){r.resultId&&s.postMessage({resultId:r.resultId,error:i.toString()})}}}Object.defineProperty(exports,\"__esModule\",{value:!0}),exports.initProvider=e;\n},{}],\"../parser/json-node-search.ts\":[function(require,module,exports) {\n\"use strict\";function e(a,r,l){void 0===l&&(l=\"all\"),r=n(r);var o=[];return!a.path.length||\"all\"!==l&&\"keys\"!==l||t(r,a.path[a.path.length-1],function(e,t){o.push({path:a.path,key:e,length:t})}),\"object\"===a.type?a.getObjectNodes().forEach(function(t){o.push.apply(o,e(t,r,l))}):\"array\"===a.type?a.getArrayNodes().forEach(function(t){o.push.apply(o,e(t,r,l))}):\"all\"!==l&&\"values\"!==l||t(r,String(a.getValue()),function(e,t){o.push({path:a.path,value:e,length:t})}),o}function t(e,t,a){(e=n(e)).lastIndex=0;for(var r=null;null!==(r=e.exec(t));)a(r.index,r[0].length);e.lastIndex=0}function n(e){if(!e.global){var t=\"g\"+(e.ignoreCase?\"i\":\"\")+(e.multiline?\"m\":\"\");return new RegExp(e.source,t)}return e}Object.defineProperty(exports,\"__esModule\",{value:!0}),exports.searchJsonNodes=e,exports.forEachMatchFromString=t;\n},{}],\"../helpers/utils.ts\":[function(require,module,exports) {\n\"use strict\";function r(r,t){if(isNaN(r)||r<0)throw new Error(\"Invalid start \"+r);if(t&&t<0)throw new Error(\"Invalid limit \"+t)}Object.defineProperty(exports,\"__esModule\",{value:!0}),exports.assertStartLimit=r;\n},{}],\"../parser/buffer-json-parser.ts\":[function(require,module,exports) {\n\"use strict\";Object.defineProperty(exports,\"__esModule\",{value:!0});var t=require(\"../helpers/utils\"),e=\"{\".charCodeAt(0),r=\"}\".charCodeAt(0),a=\"[\".charCodeAt(0),o=\"]\".charCodeAt(0),n=\":\".charCodeAt(0),i=\",\".charCodeAt(0),s='\"'.charCodeAt(0),h=\"'\".charCodeAt(0),d=\" \".charCodeAt(0),p=\"\\t\".charCodeAt(0),c=\"\\n\".charCodeAt(0),u=\"\\b\".charCodeAt(0),f=\"\\r\".charCodeAt(0),y=\"\\f\".charCodeAt(0),l=\"\\\\\".charCodeAt(0),b=\"/\".charCodeAt(0),g=\"-\".charCodeAt(0),v=\"+\".charCodeAt(0),j=\".\".charCodeAt(0),I=\"e\".charCodeAt(0),A=\"E\".charCodeAt(0),w=\"0\".charCodeAt(0),C=\"9\".charCodeAt(0),N=[d,p,c,f],m=\"null\".split(\"\").map(function(t){return t.charCodeAt(0)}),x=\"true\".split(\"\").map(function(t){return t.charCodeAt(0)}),k=\"false\".split(\"\").map(function(t){return t.charCodeAt(0)}),E=function(){function e(t,e,r){this.path=[],this.parser=t,this.index=e,this.path=r}return e.prototype.getObjectKeys=function(e,r){if(void 0===e&&(e=0),\"object\"!==this.type)throw new Error(\"Unsupported method on non-object \"+this.type);t.assertStartLimit(e,r);var a={path:this.path,objectKeys:[],start:e,limit:r};return this.parser.parseObject(this.index,a),a.objectKeys},e.prototype.getByIndex=function(t){var e;if(\"object\"===this.type&&(e=this.getObjectNodes(t,1)).length)return e[0];if(\"array\"===this.type&&(e=this.getArrayNodes(t,1)).length)return e[0]},e.prototype.getByKey=function(t){if(\"object\"===this.type){var e={path:this.path,objectKey:t};return this.parser.parseObject(this.index,e),e.objectNodes?e.objectNodes[0]:void 0}if(\"array\"===this.type)return this.getByIndex(parseInt(t))},e.prototype.getByPath=function(t){if(t){if(!t.length)return this;for(var e,r=t.slice(),a=this;void 0!==(e=r.shift())&&a;)a=a.getByKey(e);return a}},e.prototype.getObjectNodes=function(e,r){if(void 0===e&&(e=0),\"object\"!==this.type)throw new Error(\"Unsupported method on non-object \"+this.type);t.assertStartLimit(e,r);var a={path:this.path,objectNodes:[],start:e,limit:r};return this.parser.parseObject(this.index,a),a.objectNodes},e.prototype.getArrayNodes=function(e,r){if(void 0===e&&(e=0),\"array\"!==this.type)throw new Error(\"Unsupported method on non-array \"+this.type);t.assertStartLimit(e,r);var a={path:this.path,arrayNodes:[],start:e,limit:r};return this.parser.parseArray(this.index,a),a.arrayNodes},e.prototype.getValue=function(){return this.parser.parseNative(this.index,this.index+this.chars)},e}();exports.BufferJsonNodeInfo=E;var O=function(){function t(t){if(t instanceof ArrayBuffer)this.data=new Uint16Array(t);else if(\"string\"==typeof t&&\"undefined\"!=typeof TextEncoder)this.data=(new TextEncoder).encode(t);else if(\"string\"==typeof t){this.data=new Uint16Array(new ArrayBuffer(2*t.length));for(var e=0;e<t.length;e++)this.data[e]=t.charCodeAt(e)}}return t.prototype.getRootNodeInfo=function(){var t=this.skipIgnored(0),e={path:[],nodeInfo:new E(this,t,[])};return t===this.parseValue(t,e,!1)?null:e.nodeInfo},t.prototype.parseValue=function(t,r,o){void 0===o&&(o=!0);var n=this.data[t];if(function(t){return t===s||t===h}(n))return this.parseString(t,r);if(function(t){return t===g||t>=w&&t<=C}(n))return this.parseNumber(t,r);if(n===e)return this.parseObject(t,r);if(n===a)return this.parseArray(t,r);if(n===x[0])return this.parseToken(t,x,r);if(n===k[0])return this.parseToken(t,k,r);if(n===m[0])return this.parseToken(t,m,r);if(o)throw new Error(\"parse value unknown token \"+K(n)+\" at \"+t)},t.prototype.parseObject=function(t,e){for(var a=t+1,o=0,s=[],h=[];a<=this.data.length;){if(a===this.data.length)throw new Error(\"parse object incomplete at end\");if(a=this.skipIgnored(a),this.data[a]===r){a++;break}var d=c(o);if(a=this.parseString(a,d),d&&e&&e.objectKeys&&s.push(d.value),a=this.skipIgnored(a),this.data[a]!==n)throw new Error(\"parse object unexpected token \"+K(this.data[a])+\" at \"+a+\". Expected :\");a++,a=this.skipIgnored(a);var p=null;if(d&&e&&(e.objectNodes||d.value===e.objectKey)&&(p={path:e.path,nodeInfo:new E(this,a,e.path.concat([d.value]))}),a=this.parseValue(a,p),a=this.skipIgnored(a),p&&e.objectNodes)h.push(p.nodeInfo);else if(p&&void 0!==e.objectKey)return void(e.objectNodes=[p.nodeInfo]);if(o++,this.data[a]===i)a++;else if(this.data[a]!==r)throw new Error(\"parse object unexpected token \"+K(this.data[a])+\" at \"+a+\". Expected , or }\")}function c(t){return!e||e.start&&t<e.start||e.limit&&t>=e.start+e.limit?null:e&&(e.objectKeys||e.objectNodes||void 0!==e.objectKey)?{path:e.path,value:null}:null}return e&&e.nodeInfo&&(e.nodeInfo.type=\"object\",e.nodeInfo.length=o,e.nodeInfo.chars=a-t),e&&e.objectKeys&&(e.objectKeys=s),e&&e.objectNodes&&(e.objectNodes=h),a},t.prototype.parseArray=function(t,e){for(var r,a=t+1,n=0;a<=this.data.length;){if(a===this.data.length)throw new Error(\"parse array incomplete at end\");if(a=this.skipIgnored(a),this.data[a]===o){a++;break}var s=null;if(r=n,!e||e.start&&r<e.start||e.limit&&r>=e.start+e.limit||!e.arrayNodes||(s={path:e.path,nodeInfo:new E(this,a,e.path.concat([n.toString()]))}),a=this.parseValue(a,s),s&&e.arrayNodes.push(s.nodeInfo),a=this.skipIgnored(a),n++,this.data[a]===i)a++;else if(this.data[a]!==o)throw new Error(\"parse array unexpected token \"+K(this.data[a])+\" at \"+a+\". Expected , or ]\")}return e&&e.nodeInfo&&(e.nodeInfo.type=\"array\",e.nodeInfo.length=n,e.nodeInfo.chars=a-t),a},t.prototype.parseString=function(t,e){var r=t,a=this.data[r]===s?s:h,o=!1,n=0;for(r++;r<=this.data.length;r++){if(r===this.data.length)throw new Error(\"parse string incomplete at end\");if(!o&&this.data[r]===a){r++;break}(o=this.data[r]===l&&!o)||n++}return e&&e.nodeInfo&&(e.nodeInfo.type=\"string\",e.nodeInfo.length=n,e.nodeInfo.chars=r-t),e&&void 0!==e.value&&(e.value=JSON.parse(K(this.data.subarray(t,r)))),r},t.prototype.parseNumber=function(t,e){var r=t;return this.data[r]===g&&r++,r=this.parseDigits(r),this.data[r]===j&&(r++,r=this.parseDigits(r)),this.data[r]!==A&&this.data[r]!==I||(r++,this.data[r]!==v&&this.data[r]!==g||r++,r=this.parseDigits(r)),e&&e.nodeInfo&&(e.nodeInfo.type=\"number\",e.nodeInfo.chars=r-t),e&&void 0!==e.value&&(e.value=JSON.parse(K(this.data.subarray(t,r)))),r},t.prototype.parseDigits=function(t){for(;this.data[t]>=w&&this.data[t]<=C;)t++;return t},t.prototype.parseToken=function(t,e,r){for(var a=t,o=0;o<e.length;o++){if(this.data[a]!==e[o])throw new Error(\"Unexpected token \"+K(this.data[a])+\" at \"+a+\". Expected \"+K(e));a++}var n=K(this.data.subarray(t,a));return r&&r.nodeInfo&&(r.nodeInfo.type=\"null\"===n?\"null\":\"boolean\",r.nodeInfo.chars=a-t),r&&void 0!==r.value&&(r.value=JSON.parse(n)),a},t.prototype.parseNative=function(t,e){return JSON.parse(K(this.data.subarray(t,e)))},t.prototype.skipIgnored=function(t){for(var e=t;e<this.data.length;e++)if(-1===N.indexOf(this.data[e]))return e},t}();function K(t){return\"number\"==typeof t&&(t=[t]),String.fromCharCode.apply(null,t)}exports.BufferJsonParser=O;\n},{\"../helpers/utils\":\"../helpers/utils.ts\"}],\"../parser/js-parser.ts\":[function(require,module,exports) {\n\"use strict\";function t(e){return(t=\"function\"==typeof Symbol&&\"symbol\"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&\"function\"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?\"symbol\":typeof t})(e)}Object.defineProperty(exports,\"__esModule\",{value:!0});var e=require(\"../helpers/utils\"),r=function(){function r(e,r){this.path=[],this.ref=e,this.path=r;var o=t(e);\"undefined\"===o&&(this.type=\"undefined\"),\"symbol\"===o&&(this.type=\"symbol\"),\"function\"===o&&(this.type=\"function\"),\"object\"===o&&null===e?this.type=\"null\":\"object\"===o&&Array.isArray(e)?this.type=\"array\":this.type=o,\"object\"===this.type&&(this.length=Object.keys(e).length),\"array\"!==this.type&&\"string\"!==this.type||(this.length=e.length)}return r.prototype.getObjectKeys=function(t,r){if(void 0===t&&(t=0),\"object\"!==this.type)throw new Error(\"Unsupported method on non-object \"+this.type);e.assertStartLimit(t,r);var o=Object.keys(this.ref);return r?o.slice(t,t+r):o.slice(t)},r.prototype.getByIndex=function(t){var e;if(\"object\"===this.type&&(e=this.getObjectNodes(t,1)).length)return e[0];if(\"array\"===this.type&&(e=this.getArrayNodes(t,1)).length)return e[0]},r.prototype.getByKey=function(t){return\"object\"===this.type&&this.ref.hasOwnProperty(t)?new r(this.ref[t],this.path.concat([t])):\"array\"===this.type?this.getByIndex(parseInt(t)):void 0},r.prototype.getByPath=function(t){if(t){if(!t.length)return this;for(var e,r=t.slice(),o=this;void 0!==(e=r.shift())&&o;)o=o.getByKey(e);return o}},r.prototype.getObjectNodes=function(t,o){var n=this;if(void 0===t&&(t=0),\"object\"!==this.type)throw new Error(\"Unsupported method on non-object \"+this.type);return e.assertStartLimit(t,o),this.getObjectKeys(t,o).map(function(t){return new r(n.ref[t],n.path.concat([t]))})},r.prototype.getArrayNodes=function(t,o){var n=this;if(void 0===t&&(t=0),\"array\"!==this.type)throw new Error(\"Unsupported method on non-array \"+this.type);return e.assertStartLimit(t,o),(o?this.ref.slice(t,t+o):this.ref.slice(t)).map(function(e,o){return new r(e,n.path.concat([String(t+o)]))})},r.prototype.getValue=function(){return this.ref},r}();exports.JsJsonNodeInfo=r;var o=function(){function t(t){this.data=t}return t.prototype.getRootNodeInfo=function(){return void 0===this.data?null:new r(this.data,[])},t}();exports.JsParser=o;\n},{\"../helpers/utils\":\"../helpers/utils.ts\"}],\"../big-json-viewer-service.ts\":[function(require,module,exports) {\n\"use strict\";Object.defineProperty(exports,\"__esModule\",{value:!0});var e=require(\"./parser/json-node-search\"),t=require(\"./parser/buffer-json-parser\"),r=require(\"./parser/js-parser\"),o=function(){function o(){}return o.prototype.initWithData=function(e){return this.rootNode=new t.BufferJsonParser(e).getRootNodeInfo(),this.getRenderInfo(this.rootNode)},o.prototype.initWithJs=function(e){return this.rootNode=new r.JsParser(e).getRootNodeInfo(),this.getRenderInfo(this.rootNode)},o.prototype.getNodes=function(e,t,r){var o=this,n=this.rootNode.getByPath(e);return n&&\"object\"===n.type?n.getObjectNodes(t,r).map(function(e){return o.getRenderInfo(e)}):n&&\"array\"===n.type?n.getArrayNodes(t,r).map(function(e){return o.getRenderInfo(e)}):null},o.prototype.getKeyIndex=function(e,t){var r=this.rootNode.getByPath(e);return r?r.getObjectKeys().indexOf(t):-1},o.prototype.search=function(t,r){return e.searchJsonNodes(this.rootNode,t,r)},o.prototype.getRenderInfo=function(e){var t={type:e.type,length:e.length,path:e.path,openable:this.isOpenableNode(e)};return t.openable||(t.value=e.getValue()),t},o.prototype.isOpenableNode=function(e){return(\"array\"===e.type||\"object\"===e.type)&&!!e.length},o}();exports.BigJsonViewerService=o;\n},{\"./parser/json-node-search\":\"../parser/json-node-search.ts\",\"./parser/buffer-json-parser\":\"../parser/buffer-json-parser.ts\",\"./parser/js-parser\":\"../parser/js-parser.ts\"}],\"big-json-viewer.worker.ts\":[function(require,module,exports) {\n\"use strict\";Object.defineProperty(exports,\"__esModule\",{value:!0});var e=require(\"../helpers/worker-provider\"),r=require(\"../big-json-viewer-service\");e.initProvider(new r.BigJsonViewerService);\n},{\"../helpers/worker-provider\":\"../helpers/worker-provider.ts\",\"../big-json-viewer-service\":\"../big-json-viewer-service.ts\"}]},{},[\"big-json-viewer.worker.ts\"], null)"], { type: 'text/javascript' }); var workerUrl = URL.createObjectURL(blob); return new Worker(workerUrl); } exports.initWorker = initWorker; ; //# sourceMappingURL=big-json-viewer.worker.inline.js.map