json-pretty-html
Version:
Transforms a JSON object to a pretty piece of HTML Edit
16 lines (14 loc) • 10.8 kB
JavaScript
!function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.prettyPrint=n():t.prettyPrint=n()}("undefined"!=typeof self?self:this,function(){return function(t){var n={};function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}return e.m=t,e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:r})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,n){if(1&n&&(t=e(t)),8&n)return t;if(4&n&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(e.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&n&&"string"!=typeof t)for(var o in t)e.d(r,o,function(n){return t[n]}.bind(null,o));return r},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},e.p="",e(e.s=0)}([function(t,n,e){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=e(1),o=/["'&<>]/,i=function(t){var n=o.exec(t);if(null!==n){var e,r="",i=void 0,u=0;for(i=n.index;i<t.length;i++){switch(t.charCodeAt(i)){case 34:e=""";break;case 38:e="&";break;case 39:e="'";break;case 60:e="<";break;case 62:e=">";break;default:continue}u!==i&&(r+=t.substring(u,i)),u=i+1,r+=e}return u!==i?r+t.substring(u,i):r}return t},u=function(){function t(t){this.buffer=[],this.indentString=t,this.objects=[],this._printSelectionEndAtNewLine=!1}return t.prototype.checkCircular=function(t){for(var n=0,e=this.objects;n<e.length;n++){if(t===e[n])throw new Error("Cannot pretty print object with circular reference")}this.objects.push(t)},t.prototype.print=function(t){this.buffer.push(t)},t.prototype.newLine=function(){this._printSelectionEndAtNewLine?(this.printSelectionEnd(),this._printSelectionEndAtNewLine=!1):this.buffer.push("<br>")},t.prototype.space=function(){this.buffer.push(" ")},t.prototype.indent=function(t){if(t>0){for(var n="",e=0;e<t;e++)n+=this.indentString;this.buffer.push(n)}},t.prototype.printKey=function(t){this.buffer.push('"'),this.buffer.push('<span class="json-key">'+i(t)+"</span>"),this.buffer.push('"')},t.prototype.printString=function(t){this.buffer.push('"'),this.buffer.push('<span class="json-string">'+i(t)+"</span>"),this.buffer.push('"')},t.prototype.printBoolean=function(t){this.buffer.push('<span class="json-boolean">'+t+"</span>")},t.prototype.printNumber=function(t){this.buffer.push('<span class="json-number">'+t+"</span>")},t.prototype.printSelectionStart=function(){this.buffer.push("</div>"),this.buffer.push('<div class="json-pretty json-selected">')},t.prototype.printSelectionEnd=function(){this.buffer.push("</div>"),this.buffer.push('<div class="json-pretty">')},Object.defineProperty(t.prototype,"printSelectionEndAtNewLine",{set:function(t){this._printSelectionEndAtNewLine=t},enumerable:!0,configurable:!0}),t.prototype.toString=function(){return this.buffer.join("")},t}(),c=function(t,n,e,r,o){n.checkCircular(t),n.print("{"),n.newLine();for(var i=Object.keys(t),u=0;u<i.length;u++){var a=i[u],s=t[a];switch(r===s&&n.printSelectionStart(),n.indent(e+1),n.printKey(a),n.print(":"),n.space(),typeof s){case"number":n.printNumber(s);break;case"boolean":n.printBoolean(s);break;case"string":n.printString(s);break;case"object":null===s?n.print("null"):Array.isArray(s)?f(s,n,e+1,r,o):c(s,n,e+1,r,o);break;case"undefined":n.print("undefined");break;default:throw new Error("Don''t know what to do with "+typeof s)}u<i.length-1&&n.print(","),n.newLine()}n.indent(e),n.print("}"),r===t&&(n.printSelectionEndAtNewLine=!0)},f=function(t,n,e,r,o){n.checkCircular(t),n.print("["),n.newLine();for(var i=0;i<t.length;i++){var u=t[i];switch(r===u&&n.printSelectionStart(),n.indent(e+1),typeof u){case"number":n.printNumber(u);break;case"boolean":n.printBoolean(u);break;case"string":n.printString(u);break;case"object":null==u?n.print("null"):c(u,n,e+1,r,o);break;case"undefined":n.print("undefined");break;default:throw new Error("Don''t know what to do with "+typeof u)}i<t.length-1&&n.print(","),n.newLine()}n.indent(e),n.print("]"),r===t&&(n.printSelectionEndAtNewLine=!0)};n.default=function(t,n,e){if(void 0!==typeof t&&null!=t){var o=r.__assign({indent:" "},e),i=new u(o.indent);return t===n?i.print('<div class="json-pretty json-selected">'):i.print('<div class="json-pretty">'),Array.isArray(t)?f(t,i,0,n,o):c(t,i,0,n,o),i.print("</div>"),i.toString()}return""}},function(t,n,e){"use strict";e.r(n),e.d(n,"__extends",function(){return o}),e.d(n,"__assign",function(){return i}),e.d(n,"__rest",function(){return u}),e.d(n,"__decorate",function(){return c}),e.d(n,"__param",function(){return f}),e.d(n,"__metadata",function(){return a}),e.d(n,"__awaiter",function(){return s}),e.d(n,"__generator",function(){return p}),e.d(n,"__exportStar",function(){return l}),e.d(n,"__values",function(){return d}),e.d(n,"__read",function(){return y}),e.d(n,"__spread",function(){return b}),e.d(n,"__await",function(){return h}),e.d(n,"__asyncGenerator",function(){return v}),e.d(n,"__asyncDelegator",function(){return w}),e.d(n,"__asyncValues",function(){return _}),e.d(n,"__makeTemplateObject",function(){return j}),e.d(n,"__importStar",function(){return g}),e.d(n,"__importDefault",function(){return S});
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
var r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var e in n)n.hasOwnProperty(e)&&(t[e]=n[e])};function o(t,n){function e(){this.constructor=t}r(t,n),t.prototype=null===n?Object.create(n):(e.prototype=n.prototype,new e)}var i=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var o in n=arguments[e])Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o]);return t};function u(t,n){var e={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&n.indexOf(r)<0&&(e[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)n.indexOf(r[o])<0&&(e[r[o]]=t[r[o]])}return e}function c(t,n,e,r){var o,i=arguments.length,u=i<3?n:null===r?r=Object.getOwnPropertyDescriptor(n,e):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)u=Reflect.decorate(t,n,e,r);else for(var c=t.length-1;c>=0;c--)(o=t[c])&&(u=(i<3?o(u):i>3?o(n,e,u):o(n,e))||u);return i>3&&u&&Object.defineProperty(n,e,u),u}function f(t,n){return function(e,r){n(e,r,t)}}function a(t,n){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,n)}function s(t,n,e,r){return new(e||(e=Promise))(function(o,i){function u(t){try{f(r.next(t))}catch(t){i(t)}}function c(t){try{f(r.throw(t))}catch(t){i(t)}}function f(t){t.done?o(t.value):new e(function(n){n(t.value)}).then(u,c)}f((r=r.apply(t,n||[])).next())})}function p(t,n){var e,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(e)throw new TypeError("Generator is already executing.");for(;u;)try{if(e=1,r&&(o=r[2&i[0]?"return":i[0]?"throw":"next"])&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[0,o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,r=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=(o=u.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=n.call(t,u)}catch(t){i=[6,t],r=0}finally{e=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}function l(t,n){for(var e in t)n.hasOwnProperty(e)||(n[e]=t[e])}function d(t){var n="function"==typeof Symbol&&t[Symbol.iterator],e=0;return n?n.call(t):{next:function(){return t&&e>=t.length&&(t=void 0),{value:t&&t[e++],done:!t}}}}function y(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return u}function b(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(y(arguments[n]));return t}function h(t){return this instanceof h?(this.v=t,this):new h(t)}function v(t,n,e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r,o=e.apply(t,n||[]),i=[];return r={},u("next"),u("throw"),u("return"),r[Symbol.asyncIterator]=function(){return this},r;function u(t){o[t]&&(r[t]=function(n){return new Promise(function(e,r){i.push([t,n,e,r])>1||c(t,n)})})}function c(t,n){try{!function(t){t.value instanceof h?Promise.resolve(t.value.v).then(f,a):s(i[0][2],t)}(o[t](n))}catch(t){s(i[0][3],t)}}function f(t){c("next",t)}function a(t){c("throw",t)}function s(t,n){t(n),i.shift(),i.length&&c(i[0][0],i[0][1])}}function w(t){var n,e;return n={},r("next"),r("throw",function(t){throw t}),r("return"),n[Symbol.iterator]=function(){return this},n;function r(r,o){t[r]&&(n[r]=function(n){return(e=!e)?{value:h(t[r](n)),done:"return"===r}:o?o(n):n})}}function _(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=t[Symbol.asyncIterator];return n?n.call(t):d(t)}function j(t,n){return Object.defineProperty?Object.defineProperty(t,"raw",{value:n}):t.raw=n,t}function g(t){if(t&&t.__esModule)return t;var n={};if(null!=t)for(var e in t)Object.hasOwnProperty.call(t,e)&&(n[e]=t[e]);return n.default=t,n}function S(t){return t&&t.__esModule?t:{default:t}}}])});