oj
Version:
A unified templating language for the people. Thirsty people.
1 lines • 8.97 kB
JavaScript
function inspect(e,t){var n={seen:[],stylize:stylizeNoColor};return arguments.length>=3&&(n.depth=arguments[2]),arguments.length>=4&&(n.colors=arguments[3]),isBoolean(t)?n.showHidden=t:t&&exports._extend(n,t),isUndefined(n.showHidden)&&(n.showHidden=!1),isUndefined(n.depth)&&(n.depth=2),isUndefined(n.colors)&&(n.colors=!1),isUndefined(n.customInspect)&&(n.customInspect=!0),n.colors&&(n.stylize=stylizeWithColor),formatValue(n,e,n.depth)}function stylizeWithColor(e,t){var n=inspect.styles[t];return n?"["+inspect.colors[n][0]+"m"+e+"["+inspect.colors[n][1]+"m":e}function stylizeNoColor(e,t){return e}function arrayToHash(e){var t={};return e.forEach(function(e,n){t[e]=!0}),t}function formatValue(e,t,n){if(e.customInspect&&t&&isFunction(t.inspect)&&t.inspect!==exports.inspect&&(!t.constructor||t.constructor.prototype!==t)){var r=t.inspect(n,e);return isString(r)||(r=formatValue(e,r,n)),r}var i=formatPrimitive(e,t);if(i)return i;var s=Object.keys(t),o=arrayToHash(s);e.showHidden&&(s=Object.getOwnPropertyNames(t));if(s.length===0){if(isFunction(t)){var u=t.name?": "+t.name:"";return e.stylize("[Function"+u+"]","special")}if(isRegExp(t))return e.stylize(RegExp.prototype.toString.call(t),"regexp");if(isDate(t))return e.stylize(Date.prototype.toString.call(t),"date");if(isError(t))return formatError(t)}var a="",f=!1,l=["{","}"];isArray(t)&&(f=!0,l=["[","]"]);if(isFunction(t)){var c=t.name?": "+t.name:"";a=" [Function"+c+"]"}isRegExp(t)&&(a=" "+RegExp.prototype.toString.call(t)),isDate(t)&&(a=" "+Date.prototype.toUTCString.call(t)),isError(t)&&(a=" "+formatError(t));if(s.length!==0||!!f&&t.length!=0){if(n<0)return isRegExp(t)?e.stylize(RegExp.prototype.toString.call(t),"regexp"):e.stylize("[Object]","special");e.seen.push(t);var h;return f?h=formatArray(e,t,n,o,s):h=s.map(function(r){return formatProperty(e,t,n,o,r,f)}),e.seen.pop(),reduceToSingleString(h,a,l)}return l[0]+a+l[1]}function formatPrimitive(e,t){if(isUndefined(t))return e.stylize("undefined","undefined");if(isString(t)){var n="'"+JSON.stringify(t).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return e.stylize(n,"string")}if(isNumber(t))return e.stylize(""+t,"number");if(isBoolean(t))return e.stylize(""+t,"boolean");if(isNull(t))return e.stylize("null","null")}function formatError(e){return"["+Error.prototype.toString.call(e)+"]"}function formatArray(e,t,n,r,i){var s=[];for(var o=0,u=t.length;o<u;++o)hasOwnProperty(t,String(o))?s.push(formatProperty(e,t,n,r,String(o),!0)):s.push("");return i.forEach(function(i){i.match(/^\d+$/)||s.push(formatProperty(e,t,n,r,i,!0))}),s}function formatProperty(e,t,n,r,i,s){var o,u,a;a=Object.getOwnPropertyDescriptor(t,i)||{value:t[i]},a.get?a.set?u=e.stylize("[Getter/Setter]","special"):u=e.stylize("[Getter]","special"):a.set&&(u=e.stylize("[Setter]","special")),hasOwnProperty(r,i)||(o="["+i+"]"),u||(e.seen.indexOf(a.value)<0?(isNull(n)?u=formatValue(e,a.value,null):u=formatValue(e,a.value,n-1),u.indexOf("\n")>-1&&(s?u=u.split("\n").map(function(e){return" "+e}).join("\n").substr(2):u="\n"+u.split("\n").map(function(e){return" "+e}).join("\n"))):u=e.stylize("[Circular]","special"));if(isUndefined(o)){if(s&&i.match(/^\d+$/))return u;o=JSON.stringify(""+i),o.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(o=o.substr(1,o.length-2),o=e.stylize(o,"name")):(o=o.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),o=e.stylize(o,"string"))}return o+": "+u}function reduceToSingleString(e,t,n){var r=0,i=e.reduce(function(e,t){return r++,t.indexOf("\n")>=0&&r++,e+t.replace(/\u001b\[\d\d?m/g,"").length+1},0);return i>60?n[0]+(t===""?"":t+"\n ")+" "+e.join(",\n ")+" "+n[1]:n[0]+t+" "+e.join(", ")+" "+n[1]}function isArray(e){return Array.isArray(e)}function isBoolean(e){return typeof e=="boolean"}function isNull(e){return e===null}function isNullOrUndefined(e){return e==null}function isNumber(e){return typeof e=="number"}function isString(e){return typeof e=="string"}function isSymbol(e){return typeof e=="symbol"}function isUndefined(e){return e===void 0}function isRegExp(e){return isObject(e)&&objectToString(e)==="[object RegExp]"}function isObject(e){return typeof e=="object"&&e!==null}function isDate(e){return isObject(e)&&objectToString(e)==="[object Date]"}function isError(e){return isObject(e)&&objectToString(e)==="[object Error]"}function isFunction(e){return typeof e=="function"}function isPrimitive(e){return e===null||typeof e=="boolean"||typeof e=="number"||typeof e=="string"||typeof e=="symbol"||typeof e=="undefined"}function isBuffer(e){return e instanceof Buffer}function objectToString(e){return Object.prototype.toString.call(e)}function pad(e){return e<10?"0"+e.toString(10):e.toString(10)}function timestamp(){var e=new Date,t=[pad(e.getHours()),pad(e.getMinutes()),pad(e.getSeconds())].join(":");return[e.getDate(),months[e.getMonth()],t].join(" ")}function hasOwnProperty(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var formatRegExp=/%[sdj%]/g;exports.format=function(e){if(!isString(e)){var t=[];for(var n=0;n<arguments.length;n++)t.push(inspect(arguments[n]));return t.join(" ")}var n=1,r=arguments,i=r.length,s=String(e).replace(formatRegExp,function(e){if(e==="%%")return"%";if(n>=i)return e;switch(e){case"%s":return String(r[n++]);case"%d":return Number(r[n++]);case"%j":try{return JSON.stringify(r[n++])}catch(t){return"[Circular]"};default:return e}});for(var o=r[n];n<i;o=r[++n])isNull(o)||!isObject(o)?s+=" "+o:s+=" "+inspect(o);return s},exports.deprecate=function(e,t){function r(){if(!n){if(process.throwDeprecation)throw new Error(t);process.traceDeprecation?console.trace(t):console.error(t),n=!0}return e.apply(this,arguments)}if(isUndefined(global.process))return function(){return exports.deprecate(e,t).apply(this,arguments)};if(process.noDeprecation===!0)return e;var n=!1;return r};var debugs={},debugEnviron;exports.debuglog=function(e){isUndefined(debugEnviron)&&(debugEnviron=process.env.NODE_DEBUG||""),e=e.toUpperCase();if(!debugs[e])if((new RegExp("\\b"+e+"\\b","i")).test(debugEnviron)){var t=process.pid;debugs[e]=function(){var n=exports.format.apply(exports,arguments);console.error("%s %d: %s",e,t,n)}}else debugs[e]=function(){};return debugs[e]},exports.inspect=inspect,inspect.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},inspect.styles={special:"cyan",number:"yellow","boolean":"yellow","undefined":"grey","null":"bold",string:"green",date:"magenta",regexp:"red"},exports.isArray=isArray,exports.isBoolean=isBoolean,exports.isNull=isNull,exports.isNullOrUndefined=isNullOrUndefined,exports.isNumber=isNumber,exports.isString=isString,exports.isSymbol=isSymbol,exports.isUndefined=isUndefined,exports.isRegExp=isRegExp,exports.isObject=isObject,exports.isDate=isDate,exports.isError=isError,exports.isFunction=isFunction,exports.isPrimitive=isPrimitive,exports.isBuffer=isBuffer;var months=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];exports.log=function(){console.log("%s - %s",timestamp(),exports.format.apply(exports,arguments))},exports.inherits=function(e,t){e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})},exports._extend=function(e,t){if(!t||!isObject(t))return e;var n=Object.keys(t),r=n.length;while(r--)e[n[r]]=t[n[r]];return e},exports.p=exports.deprecate(function(){for(var e=0,t=arguments.length;e<t;++e)console.error(exports.inspect(arguments[e]))},"util.p: Use console.error() instead"),exports.exec=exports.deprecate(function(){return require("child_process").exec.apply(this,arguments)},"util.exec is now called `child_process.exec`."),exports.print=exports.deprecate(function(){for(var e=0,t=arguments.length;e<t;++e)process.stdout.write(String(arguments[e]))},"util.print: Use console.log instead"),exports.puts=exports.deprecate(function(){for(var e=0,t=arguments.length;e<t;++e)process.stdout.write(arguments[e]+"\n")},"util.puts: Use console.log instead"),exports.debug=exports.deprecate(function(e){process.stderr.write("DEBUG: "+e+"\n")},"util.debug: Use console.error instead"),exports.error=exports.deprecate(function(e){for(var t=0,n=arguments.length;t<n;++t)process.stderr.write(arguments[t]+"\n")},"util.error: Use console.error instead"),exports.pump=exports.deprecate(function(e,t,n){function i(e,t,i){n&&!r&&(n(e,t,i),r=!0)}var r=!1;e.addListener("data",function(n){t.write(n)===!1&&e.pause()}),t.addListener("drain",function(){e.resume()}),e.addListener("end",function(){t.end()}),e.addListener("close",function(){i()}),e.addListener("error",function(e){t.end(),i(e)}),t.addListener("error",function(t){e.destroy(),i(t)})},"util.pump(): Use readableStream.pipe() instead");var uv;exports._errnoException=function(e,t){isUndefined(uv)&&(uv=process.binding("uv"));var n=uv.errname(e),r=new Error(t+" "+n);return r.code=n,r.errno=n,r.syscall=t,r}