New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@mrtujiawei/utils

Package Overview
Dependencies
Maintainers
1
Versions
600
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mrtujiawei/utils - npm Package Compare versions

Comparing version 1.1.23 to 1.1.24

jest.config.js

2

dist/utils.js

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

!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.utils=e():t.utils=e()}(this,(function(){return(()=>{"use strict";var t={};class e{constructor(){this.stack=[]}get size(){return this.stack.length}isEmpty(){return 0==this.size}push(...t){t.forEach((t=>{this.stack.push(t)}))}pop(){if(this.isEmpty())throw new e.StackEmptyError;return this.stack.pop()}peak(){if(this.isEmpty())throw new e.StackEmptyError;return this.stack[this.stack.length-1]}}e.StackEmptyError=class extends Error{constructor(t="Stack is empty"){super(t)}};class s{constructor(){this.queue=[]}get size(){return this.queue.length}isEmpty(){return 0==this.size}enqueue(...t){t.forEach((t=>{this.queue.push(t)}))}dequeue(){if(this.isEmpty())throw new s.QueueEmptyError;return this.queue.shift()}}s.QueueEmptyError=class extends Error{constructor(t="Queue is empty"){super(t)}};const i=s;class r{constructor(t=1){this.queue=new i,this.size=0,this.maxSize=1,this.setSize(t)}setSize(t=1){if(t<=0)throw new r.InvalidSizeError;this.maxSize=t}async lock(){if(this.size++,!(this.size<=this.maxSize))return new Promise((t=>{this.queue.enqueue(t)}))}unLock(){if(this.size<=0)throw new r.InvalidSizeError;this.queue.isEmpty()?this.size--:this.queue.dequeue()()}}r.InvalidSizeError=class extends Error{constructor(t="Size is invalid"){super(t)}};const n=Object.prototype.toString,h=t=>n.call(t);class a{}function o(t,e=2){return String(t).padStart(e,"0")}function u(t){const e=h(t);return a.NULL!=e&&a.UNDEFINED!=e&&/^[0-9]+$/.test(t.toString())}a.UNDEFINED=h(void 0),a.NULL=h(null),a.STRING=h(""),a.NUMBER=h(0),a.BOOLEAN=h(!1),a.FUNCTION=h(Function.prototype),a.SYMBOL="[object Symbol]",a.OBJECT=h({}),a.ARRAY=h([]),a.DATE=h(new Date),a.ERROR=h(new Error);class l{constructor(t,e,s){this.value=t,this.prev=e,this.next=s}}const c=t=>t,p=t=>void 0!==t;class f extends Error{constructor(t="Index is invalid"){super(t)}}class d{constructor(){this.head=new l,this.tail=new l,this.length=0,this.clear()}checkIndex(t){if(t<0||t>=this.size())throw new d.InvalidIndexError}clear(){this.head.next=this.tail,this.tail.prev=this.head,this.length=0}concat(t){if(t){let e=t.head.next;this.tail.prev.next=e,e.prev=this.tail.prev,this.tail=t.tail,this.length+=t.size()}return this}contains(t){return-1!=this.indexOf(t)}filter(t){let e=new d;return this.forEach(((e,s,i)=>{t(e,s,i)&&i.push(e)})),e}find(t){for(let e=0,s=this.head.next;s!=this.tail;s=s.next,e++)if(t(s.value,e,this))return s.value}findIndex(t){for(let e=0,s=this.head.next;s!=this.tail;s=s.next,e++)if(t(s.value,e++,this))return e;return-1}forEach(t){for(let e=0,s=this.head.next;s!=this.tail;s=s.next,e++)t(s.value,e,this)}get(t){this.checkIndex(t);let e=this.head.next;for(let s=0;s<t;e=e.next,s++);return e.value}includes(t){return-1!=this.indexOf(t)}indexOf(t){return this.findIndex((e=>e==t))}isEmpty(){return 0==this.size()}join(t="",e=c){if("function"!=typeof e)throw new TypeError("transfer is not a function");let s=[];return this.forEach(((t,i)=>{s.push(e(t,i,this))})),s.join(t)}lastIndexOf(t){for(let e=this.tail.prev,s=this.size()-1;e!=this.head;e=e.prev,s--)if(t==e.value)return s;return-1}map(t){let e=new d;return this.forEach(((s,i)=>{e.push(t(s,i,this))})),e}pop(){if(!this.size())return;this.length--;let t=this.tail.prev;return t.prev.next=this.tail,this.tail.prev=t.prev,t.value}push(t){let e=new l(t);e.next=this.tail,e.prev=this.tail.prev,this.tail.prev.next=e,this.tail.prev=e,this.length++}reduce(t,e){if(!this.size()&&!p(e))throw new TypeError("Reduce of empty array with no initial value");return this.forEach(((s,i)=>{e=0!=i||p(e)?t(e,s,i):s})),e}reduceRight(t,e){let s=this.size()-1,i=this.tail.prev;if(!p(e)){if(!this.size())throw new TypeError("Reduce of empty array with no initial value");e=i.value,i=i.prev,s--}for(;i!=this.head;i=i.prev,s--)e=t(e,i.value,s);return e}remove(t){this.checkIndex(t);for(let e=0,s=this.head.next;s!=this.tail;s=s.next,e++)if(e==t)return s.prev.next=s.next,s.next.prev=s.prev,this.length--,s.value}reverse(){let t=this.head.next,e=this.tail;for(this.clear();t!=e;)this.unshift(t.value),t=t.next;return this}set(t,e){this.checkIndex(t);for(let s=0,i=this.head.next;i!=this.tail;i=i.next,s++)if(s==t){i.value=e;break}}shift(){if(this.size()){let t=this.head.next;return this.head.next=t.next,t.next.prev=this.head,this.length--,t.value}}size(){return this.length}slice(t=0,e){t=t||0,e=(e=p(e)?e:this.size())>-1?e:this.size()-e;let s=new d;return this.forEach(((i,r)=>{r>=t&&r<e&&s.push(i)})),s}some(t){return-1!=this.findIndex(t)}sort(t){for(let e=this.head.next;e!=this.tail;e=e.next){let s=e;for(let i=e.next;i!=this.tail;i=i.next)t(s.value,i.value)>0&&(s=i);[e.value,s.value]=[s.value,e.value]}return this}toString(){return this.join()}toArray(){return this.reduce(((t,e)=>(t.push(e),t)),[])}unshift(t){let e=new l(t);e.next=this.head.next,e.prev=this.head,this.head.next=e,this.length++}[Symbol.iterator](){let t=this.head.next,e=this.tail;return{next(){let s,i=t==e;return i||(s=t.value,t=t.next),{value:s,done:i}}}}}var m;d.InvalidIndexError=f,function(t){t[t.ALL=0]="ALL",t[t.TRACE=1]="TRACE",t[t.DEBUG=2]="DEBUG",t[t.INFO=3]="INFO",t[t.WARN=4]="WARN",t[t.ERROR=5]="ERROR",t[t.FATAL=6]="FATAL",t[t.OFF=7]="OFF"}(m||(m={}));class E{constructor(){this.level=m.OFF,this.listenHandle=[]}formatMessage(t,e){return`[${m[t]}] ${class{static timeFormat(t,e=":"){return[t.getHours(),t.getMinutes(),t.getSeconds()].map((t=>o(t))).join(e)}static dateFormat(t,e="-"){return[t.getFullYear(),t.getMonth()+1,t.getDate()].map((t=>o(t))).join(e)}static dateTimeFormat(t,e="-",s=":"){return`${this.dateFormat(t,e)} ${this.timeFormat(t,s)}`}static getNthDayBefore(t){const e=new Date,s=new Date;return s.setTime(s.getTime()-864e5*t),[s,e]}static getNthHourBefore(t){const e=new Date,s=new Date;return s.setTime(s.getTime()-36e5*t),[s,e]}static getNthMonthBefore(t=1){const e=new Date,s=new Date;return s.setMonth(s.getMonth()-t),[s,e]}static toDayBegin(t){t.setHours(0),t.setMinutes(0),t.setSeconds(0),t.setMilliseconds(0)}}.dateTimeFormat(new Date)} ${e}`}getParameters(t){return t.map((t=>{let e=h(t);if([a.FUNCTION,a.STRING,a.UNDEFINED,a.NULL].includes(e))return String(t);if("undefined"!=typeof Symbol&&a.SYMBOL==e)return t.toString();if(a.NUMBER==e)return t;if(a.ERROR==e)return`${t.message}: \n${t.stack}`;if(a.DATE==e)return`date: ${t.getTime()}`;if(a.ARRAY==e){let e=[];e.push("[");for(let s in t)u(s)?e.push(`${this.getParameters([t[s]])}, `):e.push(`${s}: ${this.getParameters([t[s]])}, `);return e.push(`length: ${t.length}`),e.push("]"),e.join("")}if(a.OBJECT==e){let e=[];e.push("{");for(let s in t)e.push(`${s} => ${this.getParameters([t[s]])}, `);return 1<e.length&&(e[e.length-1]=e[e.length-1].slice(0,-2)),e.push("}"),e.join("")}try{return JSON.stringify(t)}catch(e){return t.toString()}})).join(" ")}publish(t){this.listenHandle.forEach((e=>{try{e(t)}catch(t){console.log(t)}}))}static getLogger(){return this.instance}setLevel(t){this.level=t}subscribe(t){this.listenHandle.push(t)}unsubscribe(t){for(let e=0;e<this.listenHandle.length;e++)if(this.listenHandle[e]==t){this.listenHandle.splice(e,1);break}}trace(...t){const e=m.TRACE;e>=this.level&&this.publish(this.formatMessage(e,this.getParameters(t)))}info(...t){const e=m.INFO;e>=this.level&&this.publish(this.formatMessage(e,this.getParameters(t)))}debug(...t){const e=m.DEBUG;e>=this.level&&this.publish(this.formatMessage(e,this.getParameters(t)))}warn(...t){const e=m.WARN;e>=this.level&&this.publish(this.formatMessage(e,this.getParameters(t)))}error(...t){const e=m.ERROR;e>=this.level&&this.publish(this.formatMessage(e,this.getParameters(t)))}fatal(...t){const e=m.FATAL;e>=this.level&&this.publish(this.formatMessage(e,this.getParameters(t)))}}E.LOG_LEVEL=m,E.instance=new E;class v{constructor(t,e=[]){if(!(t instanceof Function))throw new v.CompareInvalidError;this.compare=t,this.heap=e,this.buildHeap()}buildHeap(){for(let t=(this.heap.length>>1)-1;t>=0;t--)this.shiftDown(t)}shiftDown(t){let e=this.heap,s=e.length,i=e[t],r=s>>1;for(;t<r;){let r=1+(t<<1),n=e[r],h=r+1;if(h<s&&0>this.compare(n,e[h])&&(n=e[h],r=h),0<=this.compare(i,n))break;e[t]=n,t=r}e[t]=i}shiftUp(t){let e=this.heap,s=e[t],i=t-1>>1;for(;0<=i&&0>=this.compare(e[i],s);)e[t]=e[i],i=(t=i)-1>>1;e[t]=s}get size(){return this.heap.length}isEmpty(){return 0==this.size}peak(){if(this.isEmpty())throw new v.HeapEmptyError;return this.heap[0]}insert(t){this.heap.push(t),this.shiftUp(this.size-1)}remove(){if(this.isEmpty())throw new v.HeapEmptyError;let t=this.heap[0],e=this.heap.pop();return this.isEmpty()||(this.heap[0]=e,this.shiftDown(0)),t}}return v.CompareInvalidError=class extends Error{constructor(t="Param Compare is not a function."){super(t)}},v.HeapEmptyError=class extends Error{constructor(t="Heap is empty"){super(t)}},t.default})()}));
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.utils=e():t.utils=e()}(this,(function(){return(()=>{"use strict";var t={d:(e,s)=>{for(var i in s)t.o(s,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:s[i]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{CountDown:()=>F,DateTimeTool:()=>I,Heap:()=>G,LinkList:()=>$,Lock:()=>h,Logger:()=>B,Pagination:()=>L,Queue:()=>n,ResponsibilityChain:()=>u,Stack:()=>i,TYPES:()=>p,TaskQueue:()=>o,addZero:()=>m,debounce:()=>b,hiddenMobile:()=>D,identify:()=>x,isInteger:()=>k,isPlainObject:()=>v,isPromise:()=>y,objectToUrlParams:()=>g,retry:()=>w,reverseRange:()=>z,sleep:()=>f,throttle:()=>T,toString:()=>c,trailing:()=>O,trim:()=>d,urlParamsToObject:()=>E});class s{constructor(){this.stack=[]}get size(){return this.stack.length}isEmpty(){return 0==this.size}push(...t){t.forEach((t=>{this.stack.push(t)}))}pop(){if(this.isEmpty())throw new s.StackEmptyError;return this.stack.pop()}peak(){if(this.isEmpty())throw new s.StackEmptyError;return this.stack[this.stack.length-1]}}s.StackEmptyError=class extends Error{constructor(t="Stack is empty"){super(t)}};const i=s;class r{constructor(){this.queue=[]}get size(){return this.queue.length}isEmpty(){return 0==this.size}enqueue(...t){t.forEach((t=>{this.queue.push(t)}))}dequeue(){if(this.isEmpty())throw new r.QueueEmptyError;return this.queue.shift()}}r.QueueEmptyError=class extends Error{constructor(t="Queue is empty"){super(t)}};const n=r;class a{constructor(t=1){this.queue=new n,this.size=0,this.maxSize=1,this.setSize(t)}setSize(t=1){if(t<=0)throw new a.InvalidSizeError;this.maxSize=t}async lock(){if(this.size++,!(this.size<=this.maxSize))return new Promise((t=>{this.queue.enqueue(t)}))}unLock(){if(this.size<=0)throw new a.InvalidSizeError;this.queue.isEmpty()?this.size--:this.queue.dequeue()()}}a.InvalidSizeError=class extends Error{constructor(t="Size is invalid"){super(t)}};const h=a,o=class{constructor(t){this.access=new h(1),this.timeout=6e4,this.handler=function(){},this.setOptions(t)}setOptions(t){t.timeout&&(this.timeout=t.timeout),t.handler&&(this.handler=t.handler)}async push(...t){try{return await this.getAccess(),await this.handler(...t)}finally{this.access.unLock()}}getAccess(){return new Promise((async(t,e)=>{this.timeout&&setTimeout((()=>{e("timeout")}),this.timeout),await this.access.lock(),t()}))}},u=class{constructor(){this.chain=[]}add(t){this.chain.push(t)}doAction(...t){let e;for(let s=0;s<this.chain.length&&(e=this.chain[s](...t),!e);s++);return e}},l=Object.prototype.toString,c=t=>l.call(t);class p{}async function f(t=0){return new Promise((e=>{setTimeout(e,1e3*t)}))}function d(t){if(typeof t==typeof{})for(let e in t)t[e]=d(t[e]);else"string"==typeof t&&(t=t.trim());return t}function m(t,e=2){return String(t).padStart(e,"0")}function g(t){return Object.entries(t).map((([t,e])=>`${t}=${e}`)).join("&")}function E(t){return t.substr(1).split("&").map((t=>t.split("="))).reduce(((t,[e,s])=>(t[decodeURIComponent(e)]=decodeURIComponent(s),t)),{})}function v(t){if("object"!=typeof t)return!1;for(const e in t)return!1;return!0}function b(t,e){let s;return function(...i){s&&clearTimeout(s),s=setTimeout((()=>{t(...i),s=null}),e)}}function y(t){return t&&p.FUNCTION==c(t.then)&&p.FUNCTION==c(t.catch)}function x(t){return t}function w(t,e=2){return function(...s){let i=0;function r(t,...s){if(i++<e)return n(...s);throw new Error(t.message)}function n(...e){try{let s=t(...e);return y(s)?s.then(x).catch((t=>r(t,...e))):s}catch(t){return r(t,...e)}}return n(...s)}}p.UNDEFINED=c(void 0),p.NULL=c(null),p.STRING=c(""),p.NUMBER=c(0),p.BOOLEAN=c(!1),p.FUNCTION=c(Function.prototype),p.SYMBOL="[object Symbol]",p.OBJECT=c({}),p.ARRAY=c([]),p.DATE=c(new Date),p.ERROR=c(new Error);const S={timeout:500,leading:!1};function T(t,e=S){return e.leading?function(t,e){let s,i=null,r=!1;function n(a){i?r=!0:(i=setTimeout((()=>{r?(r=!1,i=null,n(a)):(i&&clearTimeout(i),i=null)}),e),t.apply(a,s))}return function(...t){s=t,n(this)}}(t,e.timeout):O(t,e.timeout)}function O(t,e){let s,i=null;return function(...r){s=r,i||(i=setTimeout((()=>{i=null,t.apply(this,s)}),e))}}function k(t){const e=c(t);return p.NULL!=e&&p.UNDEFINED!=e&&/^[0-9]+$/.test(t.toString())}function D(t){return(t=t||"").replace(/\d{1,4}(?=(\d{4}$))/,(t=>"".padStart(t.length,"*")))}function z(t,e,s){let i=(s-e>>1)+e;for(let r=e;r<i;r++)R(t,r,s-r-1+e)}function R(t,e,s){let i=t[e];t[e]=t[s],t[s]=i}const I=class{static timeFormat(t,e=":"){return[t.getHours(),t.getMinutes(),t.getSeconds()].map((t=>m(t))).join(e)}static dateFormat(t,e="-"){return[t.getFullYear(),t.getMonth()+1,t.getDate()].map((t=>m(t))).join(e)}static dateTimeFormat(t,e="-",s=":"){return`${this.dateFormat(t,e)} ${this.timeFormat(t,s)}`}static getNthDayBefore(t){const e=new Date,s=new Date;return s.setTime(s.getTime()-864e5*t),[s,e]}static getNthHourBefore(t){const e=new Date,s=new Date;return s.setTime(s.getTime()-36e5*t),[s,e]}static getNthMonthBefore(t=1){const e=new Date,s=new Date;return s.setMonth(s.getMonth()-t),[s,e]}static toDayBegin(t){t.setHours(0),t.setMinutes(0),t.setSeconds(0),t.setMilliseconds(0)}},N={start:60,end:60,timeout:1},F=class{constructor(t){this.message="",this.callbacks=[],this.message=t}async start(t=N){for(let e=t.start;e>t.end;e--)this.publish(e,!1),await f(t.timeout);this.publish(this.message,!0)}publish(t,e){this.callbacks.forEach((s=>{s({message:t,done:e})}))}subscribe(t){return this.callbacks.push(t),t}unsubscribe(t){let e=this.callbacks.findIndex((e=>e==t));return-1!=e&&(this.callbacks.splice(e,1),!0)}clear(){this.callbacks=[]}},L=class{constructor(t){this.callbacks=[],this.tableData=t}setOrder(t="order"){this.tableData.list.forEach(((e,s)=>{e[t]=s+1}))}sort(t,e="desc"){"asc"==e?this.tableData.list.sort(((e,s)=>e[t]-s[t])):this.tableData.list.sort(((e,s)=>s[t]-e[t]))}to(t){t=t||this.tableData.pageNum,this.tableData.pageNum=t;let{pageSize:e}=this.tableData,s=(t-1)*e,i=s+e,r=this.tableData.list.slice(s,i);return this.publish({...this.tableData,list:r}),r}setPageSize(t){this.tableData.pageSize=t}publish(t){this.callbacks.forEach((e=>e(t)))}subscribe(t){this.callbacks.push(t)}};class A{constructor(t,e,s){this.value=t,this.prev=e,this.next=s}}const P=t=>t,j=t=>void 0!==t;class M extends Error{constructor(t="Index is invalid"){super(t)}}class U{constructor(){this.head=new A,this.tail=new A,this.length=0,this.clear()}checkIndex(t){if(t<0||t>=this.size())throw new U.InvalidIndexError}clear(){this.head.next=this.tail,this.tail.prev=this.head,this.length=0}concat(t){if(t){let e=t.head.next;this.tail.prev.next=e,e.prev=this.tail.prev,this.tail=t.tail,this.length+=t.size()}return this}contains(t){return-1!=this.indexOf(t)}filter(t){let e=new U;return this.forEach(((e,s,i)=>{t(e,s,i)&&i.push(e)})),e}find(t){for(let e=0,s=this.head.next;s!=this.tail;s=s.next,e++)if(t(s.value,e,this))return s.value}findIndex(t){for(let e=0,s=this.head.next;s!=this.tail;s=s.next,e++)if(t(s.value,e++,this))return e;return-1}forEach(t){for(let e=0,s=this.head.next;s!=this.tail;s=s.next,e++)t(s.value,e,this)}get(t){this.checkIndex(t);let e=this.head.next;for(let s=0;s<t;e=e.next,s++);return e.value}includes(t){return-1!=this.indexOf(t)}indexOf(t){return this.findIndex((e=>e==t))}isEmpty(){return 0==this.size()}join(t="",e=P){if("function"!=typeof e)throw new TypeError("transfer is not a function");let s=[];return this.forEach(((t,i)=>{s.push(e(t,i,this))})),s.join(t)}lastIndexOf(t){for(let e=this.tail.prev,s=this.size()-1;e!=this.head;e=e.prev,s--)if(t==e.value)return s;return-1}map(t){let e=new U;return this.forEach(((s,i)=>{e.push(t(s,i,this))})),e}pop(){if(!this.size())return;this.length--;let t=this.tail.prev;return t.prev.next=this.tail,this.tail.prev=t.prev,t.value}push(t){let e=new A(t);e.next=this.tail,e.prev=this.tail.prev,this.tail.prev.next=e,this.tail.prev=e,this.length++}reduce(t,e){if(!this.size()&&!j(e))throw new TypeError("Reduce of empty array with no initial value");return this.forEach(((s,i)=>{e=0!=i||j(e)?t(e,s,i):s})),e}reduceRight(t,e){let s=this.size()-1,i=this.tail.prev;if(!j(e)){if(!this.size())throw new TypeError("Reduce of empty array with no initial value");e=i.value,i=i.prev,s--}for(;i!=this.head;i=i.prev,s--)e=t(e,i.value,s);return e}remove(t){this.checkIndex(t);for(let e=0,s=this.head.next;s!=this.tail;s=s.next,e++)if(e==t)return s.prev.next=s.next,s.next.prev=s.prev,this.length--,s.value}reverse(){let t=this.head.next,e=this.tail;for(this.clear();t!=e;)this.unshift(t.value),t=t.next;return this}set(t,e){this.checkIndex(t);for(let s=0,i=this.head.next;i!=this.tail;i=i.next,s++)if(s==t){i.value=e;break}}shift(){if(this.size()){let t=this.head.next;return this.head.next=t.next,t.next.prev=this.head,this.length--,t.value}}size(){return this.length}slice(t=0,e){t=t||0,e=(e=j(e)?e:this.size())>-1?e:this.size()-e;let s=new U;return this.forEach(((i,r)=>{r>=t&&r<e&&s.push(i)})),s}some(t){return-1!=this.findIndex(t)}sort(t){for(let e=this.head.next;e!=this.tail;e=e.next){let s=e;for(let i=e.next;i!=this.tail;i=i.next)t(s.value,i.value)>0&&(s=i);[e.value,s.value]=[s.value,e.value]}return this}toString(){return this.join()}toArray(){return this.reduce(((t,e)=>(t.push(e),t)),[])}unshift(t){let e=new A(t);e.next=this.head.next,e.prev=this.head,this.head.next=e,this.length++}[Symbol.iterator](){let t=this.head.next,e=this.tail;return{next(){let s,i=t==e;return i||(s=t.value,t=t.next),{value:s,done:i}}}}}U.InvalidIndexError=M;const $=U;var C;!function(t){t[t.ALL=0]="ALL",t[t.TRACE=1]="TRACE",t[t.DEBUG=2]="DEBUG",t[t.INFO=3]="INFO",t[t.WARN=4]="WARN",t[t.ERROR=5]="ERROR",t[t.FATAL=6]="FATAL",t[t.OFF=7]="OFF"}(C||(C={}));class H{constructor(){this.level=C.OFF,this.listenHandle=[]}formatMessage(t,e){return`[${C[t]}] ${I.dateTimeFormat(new Date)} ${e}`}getParameters(t){return t.map((t=>{let e=c(t);if([p.FUNCTION,p.STRING,p.UNDEFINED,p.NULL].includes(e))return String(t);if("undefined"!=typeof Symbol&&p.SYMBOL==e)return t.toString();if(p.NUMBER==e)return t;if(p.ERROR==e)return`${t.message}: \n${t.stack}`;if(p.DATE==e)return`date: ${t.getTime()}`;if(p.ARRAY==e){let e=[];e.push("[");for(let s in t)k(s)?e.push(`${this.getParameters([t[s]])}, `):e.push(`${s}: ${this.getParameters([t[s]])}, `);return e.push(`length: ${t.length}`),e.push("]"),e.join("")}if(p.OBJECT==e){let e=[];e.push("{");for(let s in t)e.push(`${s} => ${this.getParameters([t[s]])}, `);return 1<e.length&&(e[e.length-1]=e[e.length-1].slice(0,-2)),e.push("}"),e.join("")}try{return JSON.stringify(t)}catch(e){return t.toString()}})).join(" ")}publish(t){this.listenHandle.forEach((e=>{try{e(t)}catch(t){console.log(t)}}))}static getLogger(){return this.instance}setLevel(t){this.level=t}subscribe(t){this.listenHandle.push(t)}unsubscribe(t){for(let e=0;e<this.listenHandle.length;e++)if(this.listenHandle[e]==t){this.listenHandle.splice(e,1);break}}trace(...t){const e=C.TRACE;e>=this.level&&this.publish(this.formatMessage(e,this.getParameters(t)))}info(...t){const e=C.INFO;e>=this.level&&this.publish(this.formatMessage(e,this.getParameters(t)))}debug(...t){const e=C.DEBUG;e>=this.level&&this.publish(this.formatMessage(e,this.getParameters(t)))}warn(...t){const e=C.WARN;e>=this.level&&this.publish(this.formatMessage(e,this.getParameters(t)))}error(...t){const e=C.ERROR;e>=this.level&&this.publish(this.formatMessage(e,this.getParameters(t)))}fatal(...t){const e=C.FATAL;e>=this.level&&this.publish(this.formatMessage(e,this.getParameters(t)))}}H.LOG_LEVEL=C,H.instance=new H;const B=H;class q{constructor(t,e=[]){if(!(t instanceof Function))throw new q.CompareInvalidError;this.compare=t,this.heap=e,this.buildHeap()}buildHeap(){for(let t=(this.heap.length>>1)-1;t>=0;t--)this.shiftDown(t)}shiftDown(t){let e=this.heap,s=e.length,i=e[t],r=s>>1;for(;t<r;){let r=1+(t<<1),n=e[r],a=r+1;if(a<s&&0>this.compare(n,e[a])&&(n=e[a],r=a),0<=this.compare(i,n))break;e[t]=n,t=r}e[t]=i}shiftUp(t){let e=this.heap,s=e[t],i=t-1>>1;for(;0<=i&&0>=this.compare(e[i],s);)e[t]=e[i],i=(t=i)-1>>1;e[t]=s}get size(){return this.heap.length}isEmpty(){return 0==this.size}peak(){if(this.isEmpty())throw new q.HeapEmptyError;return this.heap[0]}insert(t){this.heap.push(t),this.shiftUp(this.size-1)}remove(){if(this.isEmpty())throw new q.HeapEmptyError;let t=this.heap[0],e=this.heap.pop();return this.isEmpty()||(this.heap[0]=e,this.shiftDown(0)),t}}q.CompareInvalidError=class extends Error{constructor(t="Param Compare is not a function."){super(t)}},q.HeapEmptyError=class extends Error{constructor(t="Heap is empty"){super(t)}};const G=q;return e})()}));
//# sourceMappingURL=utils.js.map
{
"name": "@mrtujiawei/utils",
"version": "1.1.23",
"version": "1.1.24",
"description": "把自己写的工具函数打包发布到npm上",
"types": "types/index.d.ts",
"main": "dist/utils.js",
"files": [
"dist",
"types"
],
"scripts": {

@@ -12,0 +8,0 @@ "build": "webpack",

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