@jeffchi/logger 4.2.0-rc.0 → 4.2.2-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -5
- package/lib/index.cjs +1 -0
- package/lib/index.d.ts +107 -0
- package/lib/index.mjs +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<a href="https://github.com/poechiang/jeffchi-logger#readme" target="_blank">@JeffChi/Logger</a>
|
|
3
3
|
</h1>
|
|
4
4
|
|
|
5
|
-
<div
|
|
5
|
+
<div >
|
|
6
6
|
|
|
7
7
|
A log print output javascript tool library that can be used at the front and back ends
|
|
8
8
|
|
|
@@ -12,16 +12,14 @@ A log print output javascript tool library that can be used at the front and bac
|
|
|
12
12
|
[](https://github.com/prettier/prettier)
|
|
13
13
|
[](https://github.com/poechiang/jeffchi-logger/actions/workflows/jest-report.yml)
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
15
|
## 支持环境
|
|
18
16
|
|
|
19
17
|
- 现代浏览器。
|
|
20
18
|
- 支持服务端使用, 在服务端使用时默认写入 %root%/logs/yyyy-mm-dd.log 日志文件。
|
|
21
19
|
|
|
22
20
|
| [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/edge/edge_48x48.png" alt="IE / Edge" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)IE / Edge | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png" alt="Firefox" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)Firefox | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png" alt="Chrome" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)Chrome | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/safari/safari_48x48.png" alt="Safari" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)Safari | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/opera/opera_48x48.png" alt="Opera" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)Opera |
|
|
23
|
-
|
|
|
24
|
-
| Edge
|
|
21
|
+
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
22
|
+
| Edge | last 2 versions | last 2 versions | last 2 versions | last 2 versions |
|
|
25
23
|
|
|
26
24
|
## 安装
|
|
27
25
|
|
|
@@ -35,6 +33,10 @@ npm install @jeffchi/logger --save
|
|
|
35
33
|
yarn add @jeffchi/logger
|
|
36
34
|
```
|
|
37
35
|
|
|
36
|
+
```bash
|
|
37
|
+
pnpm add @jeffchi/logger --save
|
|
38
|
+
```
|
|
39
|
+
|
|
38
40
|
如果你的网络环境不佳,推荐使用 [cnpm](https://github.com/cnpm/cnpm)。
|
|
39
41
|
|
|
40
42
|
## 用法
|
package/lib/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";function t(t,e,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(t):r?r.value:e.get(t)}function e(t,e,n,r,a){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!a)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!a:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?a.call(t,n):a?a.value=n:e.set(t,n),n}const n=()=>"undefined"!=typeof window;function r(t){return r="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},r(t)}function a(t){return a="function"==typeof Symbol&&"symbol"==r(Symbol.iterator)?function(t){return void 0===t?"undefined":r(t)}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":void 0===t?"undefined":r(t)},a(t)}function o(t){if(null===t||!0===t||!1===t)return NaN;var e=Number(t);return isNaN(e)?e:e<0?Math.ceil(e):Math.floor(e)}function i(t,e){if(e.length<t)throw new TypeError(t+" argument"+(t>1?"s":"")+" required, but only "+e.length+" present")}function u(t){i(1,arguments);var e=Object.prototype.toString.call(t);return t instanceof Date||"object"===a(t)&&"[object Date]"===e?new Date(t.getTime()):"number"==typeof t||"[object Number]"===e?new Date(t):("string"!=typeof t&&"[object String]"!==e||"undefined"==typeof console||(console.warn("Starting with v2.0.0-beta.1 date-fns doesn't accept strings as date arguments. Please use `parseISO` to parse strings. See: https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#string-arguments"),console.warn((new Error).stack)),new Date(NaN))}function s(t,e){i(2,arguments);var n=u(t).getTime(),r=o(e);return new Date(n+r)}var l={};function d(){return l}function c(t){var e=new Date(Date.UTC(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds()));return e.setUTCFullYear(t.getFullYear()),t.getTime()-e.getTime()}function f(t){return i(1,arguments),t instanceof Date||"object"===a(t)&&"[object Date]"===Object.prototype.toString.call(t)}function h(t){if(i(1,arguments),!f(t)&&"number"!=typeof t)return!1;var e=u(t);return!isNaN(Number(e))}function m(t,e){i(2,arguments);var n=o(e);return s(t,-n)}var g=864e5;function v(t){i(1,arguments);var e=1,n=u(t),r=n.getUTCDay(),a=(r<e?7:0)+r-e;return n.setUTCDate(n.getUTCDate()-a),n.setUTCHours(0,0,0,0),n}function w(t){i(1,arguments);var e=u(t),n=e.getUTCFullYear(),r=new Date(0);r.setUTCFullYear(n+1,0,4),r.setUTCHours(0,0,0,0);var a=v(r),o=new Date(0);o.setUTCFullYear(n,0,4),o.setUTCHours(0,0,0,0);var s=v(o);return e.getTime()>=a.getTime()?n+1:e.getTime()>=s.getTime()?n:n-1}function b(t){i(1,arguments);var e=w(t),n=new Date(0);n.setUTCFullYear(e,0,4),n.setUTCHours(0,0,0,0);var r=v(n);return r}var y=6048e5;function p(t,e){var n,r,a,s,l,c,f,h;i(1,arguments);var m=d(),g=o(null!==(n=null!==(r=null!==(a=null!==(s=null==e?void 0:e.weekStartsOn)&&void 0!==s?s:null==e||null===(l=e.locale)||void 0===l||null===(c=l.options)||void 0===c?void 0:c.weekStartsOn)&&void 0!==a?a:m.weekStartsOn)&&void 0!==r?r:null===(f=m.locale)||void 0===f||null===(h=f.options)||void 0===h?void 0:h.weekStartsOn)&&void 0!==n?n:0);if(!(g>=0&&g<=6))throw new RangeError("weekStartsOn must be between 0 and 6 inclusively");var v=u(t),w=v.getUTCDay(),b=(w<g?7:0)+w-g;return v.setUTCDate(v.getUTCDate()-b),v.setUTCHours(0,0,0,0),v}function S(t,e){var n,r,a,s,l,c,f,h;i(1,arguments);var m=u(t),g=m.getUTCFullYear(),v=d(),w=o(null!==(n=null!==(r=null!==(a=null!==(s=null==e?void 0:e.firstWeekContainsDate)&&void 0!==s?s:null==e||null===(l=e.locale)||void 0===l||null===(c=l.options)||void 0===c?void 0:c.firstWeekContainsDate)&&void 0!==a?a:v.firstWeekContainsDate)&&void 0!==r?r:null===(f=v.locale)||void 0===f||null===(h=f.options)||void 0===h?void 0:h.firstWeekContainsDate)&&void 0!==n?n:1);if(!(w>=1&&w<=7))throw new RangeError("firstWeekContainsDate must be between 1 and 7 inclusively");var b=new Date(0);b.setUTCFullYear(g+1,0,w),b.setUTCHours(0,0,0,0);var y=p(b,e),S=new Date(0);S.setUTCFullYear(g,0,w),S.setUTCHours(0,0,0,0);var T=p(S,e);return m.getTime()>=y.getTime()?g+1:m.getTime()>=T.getTime()?g:g-1}function T(t,e){var n,r,a,u,s,l,c,f;i(1,arguments);var h=d(),m=o(null!==(n=null!==(r=null!==(a=null!==(u=null==e?void 0:e.firstWeekContainsDate)&&void 0!==u?u:null==e||null===(s=e.locale)||void 0===s||null===(l=s.options)||void 0===l?void 0:l.firstWeekContainsDate)&&void 0!==a?a:h.firstWeekContainsDate)&&void 0!==r?r:null===(c=h.locale)||void 0===c||null===(f=c.options)||void 0===f?void 0:f.firstWeekContainsDate)&&void 0!==n?n:1),g=S(t,e),v=new Date(0);v.setUTCFullYear(g,0,m),v.setUTCHours(0,0,0,0);var w=p(v,e);return w}var C=6048e5;function M(t,e){for(var n=t<0?"-":"",r=Math.abs(t).toString();r.length<e;)r="0"+r;return n+r}var D=function(t,e){var n=t.getUTCFullYear(),r=n>0?n:1-n;return M("yy"===e?r%100:r,e.length)},E=function(t,e){var n=t.getUTCMonth();return"M"===e?String(n+1):M(n+1,2)},k=function(t,e){return M(t.getUTCDate(),e.length)},U=function(t,e){return M(t.getUTCHours()%12||12,e.length)},x=function(t,e){return M(t.getUTCHours(),e.length)},O=function(t,e){return M(t.getUTCMinutes(),e.length)},P=function(t,e){return M(t.getUTCSeconds(),e.length)},W=function(t,e){var n=e.length,r=t.getUTCMilliseconds();return M(Math.floor(r*Math.pow(10,n-3)),e.length)},N="midnight",R="noon",L="morning",Y="afternoon",A="evening",F="night",j={G:function(t,e,n){var r=t.getUTCFullYear()>0?1:0;switch(e){case"G":case"GG":case"GGG":return n.era(r,{width:"abbreviated"});case"GGGGG":return n.era(r,{width:"narrow"});default:return n.era(r,{width:"wide"})}},y:function(t,e,n){if("yo"===e){var r=t.getUTCFullYear(),a=r>0?r:1-r;return n.ordinalNumber(a,{unit:"year"})}return D(t,e)},Y:function(t,e,n,r){var a=S(t,r),o=a>0?a:1-a;return"YY"===e?M(o%100,2):"Yo"===e?n.ordinalNumber(o,{unit:"year"}):M(o,e.length)},R:function(t,e){return M(w(t),e.length)},u:function(t,e){return M(t.getUTCFullYear(),e.length)},Q:function(t,e,n){var r=Math.ceil((t.getUTCMonth()+1)/3);switch(e){case"Q":return String(r);case"QQ":return M(r,2);case"Qo":return n.ordinalNumber(r,{unit:"quarter"});case"QQQ":return n.quarter(r,{width:"abbreviated",context:"formatting"});case"QQQQQ":return n.quarter(r,{width:"narrow",context:"formatting"});default:return n.quarter(r,{width:"wide",context:"formatting"})}},q:function(t,e,n){var r=Math.ceil((t.getUTCMonth()+1)/3);switch(e){case"q":return String(r);case"qq":return M(r,2);case"qo":return n.ordinalNumber(r,{unit:"quarter"});case"qqq":return n.quarter(r,{width:"abbreviated",context:"standalone"});case"qqqqq":return n.quarter(r,{width:"narrow",context:"standalone"});default:return n.quarter(r,{width:"wide",context:"standalone"})}},M:function(t,e,n){var r=t.getUTCMonth();switch(e){case"M":case"MM":return E(t,e);case"Mo":return n.ordinalNumber(r+1,{unit:"month"});case"MMM":return n.month(r,{width:"abbreviated",context:"formatting"});case"MMMMM":return n.month(r,{width:"narrow",context:"formatting"});default:return n.month(r,{width:"wide",context:"formatting"})}},L:function(t,e,n){var r=t.getUTCMonth();switch(e){case"L":return String(r+1);case"LL":return M(r+1,2);case"Lo":return n.ordinalNumber(r+1,{unit:"month"});case"LLL":return n.month(r,{width:"abbreviated",context:"standalone"});case"LLLLL":return n.month(r,{width:"narrow",context:"standalone"});default:return n.month(r,{width:"wide",context:"standalone"})}},w:function(t,e,n,r){var a=function(t,e){i(1,arguments);var n=u(t),r=p(n,e).getTime()-T(n,e).getTime();return Math.round(r/C)+1}(t,r);return"wo"===e?n.ordinalNumber(a,{unit:"week"}):M(a,e.length)},I:function(t,e,n){var r=function(t){i(1,arguments);var e=u(t),n=v(e).getTime()-b(e).getTime();return Math.round(n/y)+1}(t);return"Io"===e?n.ordinalNumber(r,{unit:"week"}):M(r,e.length)},d:function(t,e,n){return"do"===e?n.ordinalNumber(t.getUTCDate(),{unit:"date"}):k(t,e)},D:function(t,e,n){var r=function(t){i(1,arguments);var e=u(t),n=e.getTime();e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0);var r=e.getTime(),a=n-r;return Math.floor(a/g)+1}(t);return"Do"===e?n.ordinalNumber(r,{unit:"dayOfYear"}):M(r,e.length)},E:function(t,e,n){var r=t.getUTCDay();switch(e){case"E":case"EE":case"EEE":return n.day(r,{width:"abbreviated",context:"formatting"});case"EEEEE":return n.day(r,{width:"narrow",context:"formatting"});case"EEEEEE":return n.day(r,{width:"short",context:"formatting"});default:return n.day(r,{width:"wide",context:"formatting"})}},e:function(t,e,n,r){var a=t.getUTCDay(),o=(a-r.weekStartsOn+8)%7||7;switch(e){case"e":return String(o);case"ee":return M(o,2);case"eo":return n.ordinalNumber(o,{unit:"day"});case"eee":return n.day(a,{width:"abbreviated",context:"formatting"});case"eeeee":return n.day(a,{width:"narrow",context:"formatting"});case"eeeeee":return n.day(a,{width:"short",context:"formatting"});default:return n.day(a,{width:"wide",context:"formatting"})}},c:function(t,e,n,r){var a=t.getUTCDay(),o=(a-r.weekStartsOn+8)%7||7;switch(e){case"c":return String(o);case"cc":return M(o,e.length);case"co":return n.ordinalNumber(o,{unit:"day"});case"ccc":return n.day(a,{width:"abbreviated",context:"standalone"});case"ccccc":return n.day(a,{width:"narrow",context:"standalone"});case"cccccc":return n.day(a,{width:"short",context:"standalone"});default:return n.day(a,{width:"wide",context:"standalone"})}},i:function(t,e,n){var r=t.getUTCDay(),a=0===r?7:r;switch(e){case"i":return String(a);case"ii":return M(a,e.length);case"io":return n.ordinalNumber(a,{unit:"day"});case"iii":return n.day(r,{width:"abbreviated",context:"formatting"});case"iiiii":return n.day(r,{width:"narrow",context:"formatting"});case"iiiiii":return n.day(r,{width:"short",context:"formatting"});default:return n.day(r,{width:"wide",context:"formatting"})}},a:function(t,e,n){var r=t.getUTCHours()/12>=1?"pm":"am";switch(e){case"a":case"aa":return n.dayPeriod(r,{width:"abbreviated",context:"formatting"});case"aaa":return n.dayPeriod(r,{width:"abbreviated",context:"formatting"}).toLowerCase();case"aaaaa":return n.dayPeriod(r,{width:"narrow",context:"formatting"});default:return n.dayPeriod(r,{width:"wide",context:"formatting"})}},b:function(t,e,n){var r,a=t.getUTCHours();switch(r=12===a?R:0===a?N:a/12>=1?"pm":"am",e){case"b":case"bb":return n.dayPeriod(r,{width:"abbreviated",context:"formatting"});case"bbb":return n.dayPeriod(r,{width:"abbreviated",context:"formatting"}).toLowerCase();case"bbbbb":return n.dayPeriod(r,{width:"narrow",context:"formatting"});default:return n.dayPeriod(r,{width:"wide",context:"formatting"})}},B:function(t,e,n){var r,a=t.getUTCHours();switch(r=a>=17?A:a>=12?Y:a>=4?L:F,e){case"B":case"BB":case"BBB":return n.dayPeriod(r,{width:"abbreviated",context:"formatting"});case"BBBBB":return n.dayPeriod(r,{width:"narrow",context:"formatting"});default:return n.dayPeriod(r,{width:"wide",context:"formatting"})}},h:function(t,e,n){if("ho"===e){var r=t.getUTCHours()%12;return 0===r&&(r=12),n.ordinalNumber(r,{unit:"hour"})}return U(t,e)},H:function(t,e,n){return"Ho"===e?n.ordinalNumber(t.getUTCHours(),{unit:"hour"}):x(t,e)},K:function(t,e,n){var r=t.getUTCHours()%12;return"Ko"===e?n.ordinalNumber(r,{unit:"hour"}):M(r,e.length)},k:function(t,e,n){var r=t.getUTCHours();return 0===r&&(r=24),"ko"===e?n.ordinalNumber(r,{unit:"hour"}):M(r,e.length)},m:function(t,e,n){return"mo"===e?n.ordinalNumber(t.getUTCMinutes(),{unit:"minute"}):O(t,e)},s:function(t,e,n){return"so"===e?n.ordinalNumber(t.getUTCSeconds(),{unit:"second"}):P(t,e)},S:function(t,e){return W(t,e)},X:function(t,e,n,r){var a=(r._originalDate||t).getTimezoneOffset();if(0===a)return"Z";switch(e){case"X":return q(a);case"XXXX":case"XX":return G(a);default:return G(a,":")}},x:function(t,e,n,r){var a=(r._originalDate||t).getTimezoneOffset();switch(e){case"x":return q(a);case"xxxx":case"xx":return G(a);default:return G(a,":")}},O:function(t,e,n,r){var a=(r._originalDate||t).getTimezoneOffset();switch(e){case"O":case"OO":case"OOO":return"GMT"+$(a,":");default:return"GMT"+G(a,":")}},z:function(t,e,n,r){var a=(r._originalDate||t).getTimezoneOffset();switch(e){case"z":case"zz":case"zzz":return"GMT"+$(a,":");default:return"GMT"+G(a,":")}},t:function(t,e,n,r){var a=r._originalDate||t;return M(Math.floor(a.getTime()/1e3),e.length)},T:function(t,e,n,r){return M((r._originalDate||t).getTime(),e.length)}};function $(t,e){var n=t>0?"-":"+",r=Math.abs(t),a=Math.floor(r/60),o=r%60;if(0===o)return n+String(a);var i=e||"";return n+String(a)+i+M(o,2)}function q(t,e){return t%60==0?(t>0?"-":"+")+M(Math.abs(t)/60,2):G(t,e)}function G(t,e){var n=e||"",r=t>0?"-":"+",a=Math.abs(t);return r+M(Math.floor(a/60),2)+n+M(a%60,2)}var z=j,H=function(t,e){switch(t){case"P":return e.date({width:"short"});case"PP":return e.date({width:"medium"});case"PPP":return e.date({width:"long"});default:return e.date({width:"full"})}},B=function(t,e){switch(t){case"p":return e.time({width:"short"});case"pp":return e.time({width:"medium"});case"ppp":return e.time({width:"long"});default:return e.time({width:"full"})}},_={p:B,P:function(t,e){var n,r=t.match(/(P+)(p+)?/)||[],a=r[1],o=r[2];if(!o)return H(t,e);switch(a){case"P":n=e.dateTime({width:"short"});break;case"PP":n=e.dateTime({width:"medium"});break;case"PPP":n=e.dateTime({width:"long"});break;default:n=e.dateTime({width:"full"})}return n.replace("{{date}}",H(a,e)).replace("{{time}}",B(o,e))}},Q=_,I=["D","DD"],X=["YY","YYYY"];function J(t){return-1!==I.indexOf(t)}function V(t){return-1!==X.indexOf(t)}function K(t,e,n){if("YYYY"===t)throw new RangeError("Use `yyyy` instead of `YYYY` (in `".concat(e,"`) for formatting years to the input `").concat(n,"`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md"));if("YY"===t)throw new RangeError("Use `yy` instead of `YY` (in `".concat(e,"`) for formatting years to the input `").concat(n,"`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md"));if("D"===t)throw new RangeError("Use `d` instead of `D` (in `".concat(e,"`) for formatting days of the month to the input `").concat(n,"`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md"));if("DD"===t)throw new RangeError("Use `dd` instead of `DD` (in `".concat(e,"`) for formatting days of the month to the input `").concat(n,"`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md"))}var Z={lessThanXSeconds:{one:"less than a second",other:"less than {{count}} seconds"},xSeconds:{one:"1 second",other:"{{count}} seconds"},halfAMinute:"half a minute",lessThanXMinutes:{one:"less than a minute",other:"less than {{count}} minutes"},xMinutes:{one:"1 minute",other:"{{count}} minutes"},aboutXHours:{one:"about 1 hour",other:"about {{count}} hours"},xHours:{one:"1 hour",other:"{{count}} hours"},xDays:{one:"1 day",other:"{{count}} days"},aboutXWeeks:{one:"about 1 week",other:"about {{count}} weeks"},xWeeks:{one:"1 week",other:"{{count}} weeks"},aboutXMonths:{one:"about 1 month",other:"about {{count}} months"},xMonths:{one:"1 month",other:"{{count}} months"},aboutXYears:{one:"about 1 year",other:"about {{count}} years"},xYears:{one:"1 year",other:"{{count}} years"},overXYears:{one:"over 1 year",other:"over {{count}} years"},almostXYears:{one:"almost 1 year",other:"almost {{count}} years"}};function tt(t){return function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=e.width?String(e.width):t.defaultWidth,r=t.formats[n]||t.formats[t.defaultWidth];return r}}var et={date:tt({formats:{full:"EEEE, MMMM do, y",long:"MMMM do, y",medium:"MMM d, y",short:"MM/dd/yyyy"},defaultWidth:"full"}),time:tt({formats:{full:"h:mm:ss a zzzz",long:"h:mm:ss a z",medium:"h:mm:ss a",short:"h:mm a"},defaultWidth:"full"}),dateTime:tt({formats:{full:"{{date}} 'at' {{time}}",long:"{{date}} 'at' {{time}}",medium:"{{date}}, {{time}}",short:"{{date}}, {{time}}"},defaultWidth:"full"})},nt={lastWeek:"'last' eeee 'at' p",yesterday:"'yesterday at' p",today:"'today at' p",tomorrow:"'tomorrow at' p",nextWeek:"eeee 'at' p",other:"P"};function rt(t){return function(e,n){var r;if("formatting"===(null!=n&&n.context?String(n.context):"standalone")&&t.formattingValues){var a=t.defaultFormattingWidth||t.defaultWidth,o=null!=n&&n.width?String(n.width):a;r=t.formattingValues[o]||t.formattingValues[a]}else{var i=t.defaultWidth,u=null!=n&&n.width?String(n.width):t.defaultWidth;r=t.values[u]||t.values[i]}return r[t.argumentCallback?t.argumentCallback(e):e]}}function at(t){return function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=n.width,a=r&&t.matchPatterns[r]||t.matchPatterns[t.defaultMatchWidth],o=e.match(a);if(!o)return null;var i,u=o[0],s=r&&t.parsePatterns[r]||t.parsePatterns[t.defaultParseWidth],l=Array.isArray(s)?it(s,(function(t){return t.test(u)})):ot(s,(function(t){return t.test(u)}));i=t.valueCallback?t.valueCallback(l):l,i=n.valueCallback?n.valueCallback(i):i;var d=e.slice(u.length);return{value:i,rest:d}}}function ot(t,e){for(var n in t)if(t.hasOwnProperty(n)&&e(t[n]))return n}function it(t,e){for(var n=0;n<t.length;n++)if(e(t[n]))return n}var ut,st={code:"en-US",formatDistance:function(t,e,n){var r,a=Z[t];return r="string"==typeof a?a:1===e?a.one:a.other.replace("{{count}}",e.toString()),null!=n&&n.addSuffix?n.comparison&&n.comparison>0?"in "+r:r+" ago":r},formatLong:et,formatRelative:function(t,e,n,r){return nt[t]},localize:{ordinalNumber:function(t,e){var n=Number(t),r=n%100;if(r>20||r<10)switch(r%10){case 1:return n+"st";case 2:return n+"nd";case 3:return n+"rd"}return n+"th"},era:rt({values:{narrow:["B","A"],abbreviated:["BC","AD"],wide:["Before Christ","Anno Domini"]},defaultWidth:"wide"}),quarter:rt({values:{narrow:["1","2","3","4"],abbreviated:["Q1","Q2","Q3","Q4"],wide:["1st quarter","2nd quarter","3rd quarter","4th quarter"]},defaultWidth:"wide",argumentCallback:function(t){return t-1}}),month:rt({values:{narrow:["J","F","M","A","M","J","J","A","S","O","N","D"],abbreviated:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],wide:["January","February","March","April","May","June","July","August","September","October","November","December"]},defaultWidth:"wide"}),day:rt({values:{narrow:["S","M","T","W","T","F","S"],short:["Su","Mo","Tu","We","Th","Fr","Sa"],abbreviated:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],wide:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]},defaultWidth:"wide"}),dayPeriod:rt({values:{narrow:{am:"a",pm:"p",midnight:"mi",noon:"n",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},abbreviated:{am:"AM",pm:"PM",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},wide:{am:"a.m.",pm:"p.m.",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"}},defaultWidth:"wide",formattingValues:{narrow:{am:"a",pm:"p",midnight:"mi",noon:"n",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"},abbreviated:{am:"AM",pm:"PM",midnight:"midnight",noon:"noon",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"},wide:{am:"a.m.",pm:"p.m.",midnight:"midnight",noon:"noon",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"}},defaultFormattingWidth:"wide"})},match:{ordinalNumber:(ut={matchPattern:/^(\d+)(th|st|nd|rd)?/i,parsePattern:/\d+/i,valueCallback:function(t){return parseInt(t,10)}},function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.match(ut.matchPattern);if(!n)return null;var r=n[0],a=t.match(ut.parsePattern);if(!a)return null;var o=ut.valueCallback?ut.valueCallback(a[0]):a[0];o=e.valueCallback?e.valueCallback(o):o;var i=t.slice(r.length);return{value:o,rest:i}}),era:at({matchPatterns:{narrow:/^(b|a)/i,abbreviated:/^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,wide:/^(before christ|before common era|anno domini|common era)/i},defaultMatchWidth:"wide",parsePatterns:{any:[/^b/i,/^(a|c)/i]},defaultParseWidth:"any"}),quarter:at({matchPatterns:{narrow:/^[1234]/i,abbreviated:/^q[1234]/i,wide:/^[1234](th|st|nd|rd)? quarter/i},defaultMatchWidth:"wide",parsePatterns:{any:[/1/i,/2/i,/3/i,/4/i]},defaultParseWidth:"any",valueCallback:function(t){return t+1}}),month:at({matchPatterns:{narrow:/^[jfmasond]/i,abbreviated:/^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,wide:/^(january|february|march|april|may|june|july|august|september|october|november|december)/i},defaultMatchWidth:"wide",parsePatterns:{narrow:[/^j/i,/^f/i,/^m/i,/^a/i,/^m/i,/^j/i,/^j/i,/^a/i,/^s/i,/^o/i,/^n/i,/^d/i],any:[/^ja/i,/^f/i,/^mar/i,/^ap/i,/^may/i,/^jun/i,/^jul/i,/^au/i,/^s/i,/^o/i,/^n/i,/^d/i]},defaultParseWidth:"any"}),day:at({matchPatterns:{narrow:/^[smtwf]/i,short:/^(su|mo|tu|we|th|fr|sa)/i,abbreviated:/^(sun|mon|tue|wed|thu|fri|sat)/i,wide:/^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i},defaultMatchWidth:"wide",parsePatterns:{narrow:[/^s/i,/^m/i,/^t/i,/^w/i,/^t/i,/^f/i,/^s/i],any:[/^su/i,/^m/i,/^tu/i,/^w/i,/^th/i,/^f/i,/^sa/i]},defaultParseWidth:"any"}),dayPeriod:at({matchPatterns:{narrow:/^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,any:/^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i},defaultMatchWidth:"any",parsePatterns:{any:{am:/^a/i,pm:/^p/i,midnight:/^mi/i,noon:/^no/i,morning:/morning/i,afternoon:/afternoon/i,evening:/evening/i,night:/night/i}},defaultParseWidth:"any"})},options:{weekStartsOn:0,firstWeekContainsDate:1}},lt=/[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g,dt=/P+p+|P+|p+|''|'(''|[^'])+('|$)|./g,ct=/^'([^]*?)'?$/,ft=/''/g,ht=/[a-zA-Z]/;function mt(t,e,n){var r,a,s,l,f,g,v,w,b,y,p,S,T,C,M,D,E,k;i(2,arguments);var U=String(e),x=d(),O=null!==(r=null!==(a=null==n?void 0:n.locale)&&void 0!==a?a:x.locale)&&void 0!==r?r:st,P=o(null!==(s=null!==(l=null!==(f=null!==(g=null==n?void 0:n.firstWeekContainsDate)&&void 0!==g?g:null==n||null===(v=n.locale)||void 0===v||null===(w=v.options)||void 0===w?void 0:w.firstWeekContainsDate)&&void 0!==f?f:x.firstWeekContainsDate)&&void 0!==l?l:null===(b=x.locale)||void 0===b||null===(y=b.options)||void 0===y?void 0:y.firstWeekContainsDate)&&void 0!==s?s:1);if(!(P>=1&&P<=7))throw new RangeError("firstWeekContainsDate must be between 1 and 7 inclusively");var W=o(null!==(p=null!==(S=null!==(T=null!==(C=null==n?void 0:n.weekStartsOn)&&void 0!==C?C:null==n||null===(M=n.locale)||void 0===M||null===(D=M.options)||void 0===D?void 0:D.weekStartsOn)&&void 0!==T?T:x.weekStartsOn)&&void 0!==S?S:null===(E=x.locale)||void 0===E||null===(k=E.options)||void 0===k?void 0:k.weekStartsOn)&&void 0!==p?p:0);if(!(W>=0&&W<=6))throw new RangeError("weekStartsOn must be between 0 and 6 inclusively");if(!O.localize)throw new RangeError("locale must contain localize property");if(!O.formatLong)throw new RangeError("locale must contain formatLong property");var N=u(t);if(!h(N))throw new RangeError("Invalid time value");var R=c(N),L=m(N,R),Y={firstWeekContainsDate:P,weekStartsOn:W,locale:O,_originalDate:N},A=U.match(dt).map((function(t){var e=t[0];return"p"===e||"P"===e?(0,Q[e])(t,O.formatLong):t})).join("").match(lt).map((function(r){if("''"===r)return"'";var a=r[0];if("'"===a)return gt(r);var o=z[a];if(o)return null!=n&&n.useAdditionalWeekYearTokens||!V(r)||K(r,e,String(t)),null!=n&&n.useAdditionalDayOfYearTokens||!J(r)||K(r,e,String(t)),o(L,r,O.localize,Y);if(a.match(ht))throw new RangeError("Format string contains an unescaped latin alphabet character `"+a+"`");return r})).join("");return A}function gt(t){var e=t.match(ct);return e?e[1].replace(ft,"'"):t}const vt=t=>"string"==typeof t||"[object String]"===(t=>Object.prototype.toString.call(t))(t),wt=Array.isArray,bt=Number.isInteger,yt=(t,e)=>{let n=null;bt(e)&&(e={wait:e});const{immediate:r,wait:a=100}=e||{};return(...e)=>{n&&clearTimeout(n),r&&!n&&t(...e),n=setTimeout((()=>{t(...e)}),a)}};var pt,St,Tt,Ct,Mt,Dt,Et,kt,Ut,xt,Ot,Pt=()=>{};class Wt{static get cache(){return t(Wt,St,"f",Tt)}get defaultLogFile(){return`logs/${mt(Date.now(),"yyyy-MM-dd")}.log`}constructor(){pt.add(this),this.lastWrite=Date.now(),Ct.set(this,void 0),Mt.set(this,void 0),e(this,Ct,new Map,"f"),(n()?Promise.resolve(null):Promise.all([import("fs"),import("path")]).then((([t,e])=>{if(!t)return null;const{existsSync:n,mkdirSync:r,writeFile:a}=t,{sep:o,resolve:i,join:u,dirname:s}=e;return{existsSync:n,mkdirSync:r,writeFile:a,join:u,sep:o,resolve:i,dirname:s}})).catch((()=>null))).then((t=>{e(this,Mt,t,"f")}))}push(e,n){var r;let a=(null==n?void 0:n.file)||this.defaultLogFile;if(null==n?void 0:n.groupByLevel){const t=e.prefix||[],n=(null===(r=e.level)||void 0===r?void 0:r.toLowerCase())||"unknown";a=a.replace(/\.log$/,`.${n}.log`),e.prefix=t}let o=t(this,Ct,"f").get(a);o||(o={Set:new Set,writer:yt((t=>this.flush(t)),1e3)},t(this,Ct,"f").set(a,o));const i=Date.now();o.Set.add(e).size>1e3||i-this.lastWrite>3e4?this.flush(a):o.writer(a)}flush(e){t(this,Mt,"f")&&t(this,Ct,"f").forEach(((n,r)=>{if(n&&(null===e&&r===this.defaultLogFile||!e||r===e)){const e=Array.from(n.Set);n.Set.clear(),t(this,pt,"m",Et).call(this,r,e),this.lastWrite=Date.now()}}))}}St=Wt,Ct=new WeakMap,Mt=new WeakMap,pt=new WeakSet,Dt=function(e){var n,r;const a=(null===(r=null===(n=t(this,Mt,"f"))||void 0===n?void 0:n.dirname)||void 0===r?void 0:r.call(n,e||this.defaultLogFile))||"",{existsSync:o,mkdirSync:i}=t(this,Mt,"f")||{};(null==o?void 0:o(a))||null==i||i(a)},Et=function(e,n){if(wt(n)||(n=[n]),!e)throw new Error("output log file is missed");t(this,pt,"m",Dt).call(this,e);const{writeFile:r}=t(this,Mt,"f")||{};if(e&&r){const t=n.reduce(((t,{prefix:e=[],data:n})=>[...t,[...e,...n.map((t=>"string"==typeof t?t:JSON.stringify(t)))].join(" "),"\n"]),[]);null==r||r(e,t.join(""),{flag:"a"},Pt)}},Tt={value:new Wt},(Ut=kt||(kt={})).ALL="all",Ut.PRODUCTION="production",Ut.DEVELOPMENET="development",(Ot=xt||(xt={})).ASSERT="ASSERT",Ot.LOG="LOG",Ot.WARN="WARN",Ot.INFO="INFO",Ot.ERROR="ERROR",Ot.DEBUG="DEBUG",Ot.SUCCESS="SUCCESS";const Nt={date:!0,env:kt.ALL},Rt=t=>("all"===t||process.env.NODE_ENV===t)&&void 0!==console;var Lt=Object.freeze({__proto__:null,$boolean:"#9c27b0",$date:"#0063ff",$empty:"#656565",$function:"#795548",$number:"#0063ff",$object:"#795548",ASSERT:"#00bcd4",DEBUG:"#607d8b",ERROR:"#f44336",INFO:"#2196f3",LOG:"#757575",SUCCESS:"#4caf50",WARN:"#ff9800",timestamp:"#9e9e9e"});var Yt=Object.freeze({__proto__:null,$boolean:"[35m",$date:"[90m",$empty:"[90m",$function:"[90m",$number:"[94m",$object:"[90m",ASSERT:"[34m",DEBUG:"[36m",ERROR:"[91m",INFO:"[94m",LOG:"[0m",SUCCESS:"[32m",WARN:"[33m",timestamp:"[90m"});var At=Object.freeze({__proto__:null,ASSERT:"A",DEBUG:"D",ERROR:"E",INFO:"I",LOG:"L",SUCCESS:"O",WARN:"W"});const Ft={},jt=t=>{if(null==t)return"%s";const e=t.constructor.name.toLocaleLowerCase();return"number"===e?"%f":"function"===e||"object"===e||null==t?"%o":"%s"},$t=(t,e,r)=>{var a,o,i;return n()?(null==r?void 0:r.backColor)?[`%c${null!==(a=null==r?void 0:r.fmtTag)&&void 0!==a?a:"%s"}%c `,`color:${t};background-color:${t}3f;padding-inline:4px;border-radius:2px;`,e,""]:[`%c${null!==(o=null==r?void 0:r.fmtTag)&&void 0!==o?o:"%s"}%c `,`color:${t}`,e,""]:[`%s${null!==(i=null==r?void 0:r.fmtTag)&&void 0!==i?i:"%s"}%s `,t,e,"[0m"]},qt=(t,e,r)=>{var a;const o=n()?Lt:Yt,i=null===(a=null==r?void 0:r.date)||void 0===a||a,u=[];if(!1!==i){const t=new Date;u.push($t(o.timestamp,vt(i)?mt(t,i):t.toISOString()))}const s=o[t];u.push($t(s,`[${At[t]}]`));const{tags:l,args:d}=e||{},c=(wt(l)?l:l.split(",")).reduce(((t,e)=>{const r=Ft[e]||(Ft[e]=(()=>{if(n())return`#${Math.floor(128*Math.random()).toString(16).padStart(2,"0")}${Math.floor(128*Math.random()).toString(16).padStart(2,"0")}${Math.floor(128*Math.random()).toString(16).padStart(2,"0")}`;{const t=[40,100,41,101,42,102,43,103,44,104,45,105,46,106,47,107],e=Math.floor(Math.random()*t.length),n=t[e];return`[${t[t.length-e-1]-10}m[${n}m`}})());return[...t,$t(r,e.toUpperCase(),{backColor:!0})]}),[]),f=d.reduce(((t,e)=>{var r;const a=null!==(r=(t=>{const e=n()?Lt:Yt;return null==t?e.$empty:e[`$${t.constructor.name.toLocaleLowerCase()}`]})(e))&&void 0!==r?r:s;return[...t,$t(a,e,{fmtTag:jt(e)})]}),[]);return[...u,...c,...f]},Gt=(t,e,n)=>{const{output:r,levels:a=[]}=n,o=vt(r)?{file:r}:r;(null==a?void 0:a.length)&&!a.includes(xt.SUCCESS)||Wt.cache.push({level:t,data:[...e.reduce(((t,e)=>[...t,e[1]]),[])]},o)},zt=(t,e,n,r)=>{const{env:a=kt.ALL,color:o=!0}=r;Rt(null!=a?a:kt.ALL)&&(!1!==o?t(e,...n.reduce(((t,e)=>[...t,...e]),[])):t(...n.reduce(((t,e)=>[...t,e[1]]),[])))};exports.withTags=(t,e)=>{const r={...Nt,...e};return{assert:(a,...o)=>{var i;const u=qt(xt.ASSERT,{tags:t,args:o},e),s=u.reduce(((t,[e])=>t+e),""),l=u.reduce(((t,[e,...n])=>[...t,n]),[]);Rt(null!==(i=r.env)&&void 0!==i?i:kt.ALL)&&(n()?!1===r.color?console.assert(a,...l.reduce(((t,e)=>[...t,e[1]]),[])):console.assert(a,s,...l.reduce(((t,e)=>[...t,...e]),[])):console.assert(a,l.reduce(((t,e)=>[...t,...!1===r.color?[e[1]]:e]),[]).join(" "))),a||Gt(xt.ASSERT,l,r)},debug:(...n)=>{const a=qt(xt.DEBUG,{tags:t,args:n},e),o=a.reduce(((t,[e])=>t+e),""),i=a.reduce(((t,[e,...n])=>[...t,n]),[]);zt(console.debug,o,i,r),Gt(xt.DEBUG,i,r)},info:(...n)=>{const a=qt(xt.INFO,{tags:t,args:n},e),o=a.reduce(((t,[e])=>t+e),""),i=a.reduce(((t,[e,...n])=>[...t,n]),[]);zt(console.info,o,i,r),Gt(xt.INFO,i,r)},log:(...n)=>{const a=qt(xt.LOG,{tags:t,args:n},e),o=a.reduce(((t,[e])=>t+e),""),i=a.reduce(((t,[e,...n])=>[...t,n]),[]);zt(console.log,o,i,r),Gt(xt.LOG,i,r)},warn:(...n)=>{const a=qt(xt.WARN,{tags:t,args:n},e),o=a.reduce(((t,[e])=>t+e),""),i=a.reduce(((t,[e,...n])=>[...t,n]),[]),{disableError:u}=r,s=u?console.log:console.warn;zt(s,o,i,r),Gt(xt.WARN,i,r)},error:(n,a)=>{const o=qt(xt.ERROR,{tags:t,args:[n,a]},e),i=o.reduce(((t,[e])=>t+e),""),u=o.reduce(((t,[e,...n])=>[...t,n]),[]),{disableThrow:s,disableError:l}=r,d=l?console.log:console.error;if(zt(d,i,u,r),Gt(xt.ERROR,u,r),!1===s)throw new Error(n)},success:(...n)=>{const a=qt(xt.SUCCESS,{tags:t,args:n},e),o=a.reduce(((t,[e])=>t+e),""),i=a.reduce(((t,[e,...n])=>[...t,n]),[]);zt(console.log,o,i,r),Gt(xt.SUCCESS,i,r)}}};
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 日志输出打印的模式
|
|
3
|
+
* @default LogMode.ALL
|
|
4
|
+
*/
|
|
5
|
+
declare enum LogMode {
|
|
6
|
+
/**
|
|
7
|
+
* 默认,所有模式下都会打印输出
|
|
8
|
+
*/
|
|
9
|
+
ALL = "all",
|
|
10
|
+
/**
|
|
11
|
+
* 仅生产模式启用日志打印输出
|
|
12
|
+
*/
|
|
13
|
+
PRODUCTION = "production",
|
|
14
|
+
/**
|
|
15
|
+
* 仅开发模式下启用日志打印输出
|
|
16
|
+
*/
|
|
17
|
+
DEVELOPMENET = "development"
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 日志级别
|
|
21
|
+
*/
|
|
22
|
+
declare enum LogLevel {
|
|
23
|
+
ASSERT = "ASSERT",
|
|
24
|
+
LOG = "LOG",
|
|
25
|
+
WARN = "WARN",
|
|
26
|
+
INFO = "INFO",
|
|
27
|
+
ERROR = "ERROR",
|
|
28
|
+
DEBUG = "DEBUG",
|
|
29
|
+
SUCCESS = "SUCCESS"
|
|
30
|
+
}
|
|
31
|
+
/** 日志标签 */
|
|
32
|
+
type LogTags = string | string[];
|
|
33
|
+
type LogOutputOptions = {
|
|
34
|
+
/**
|
|
35
|
+
* 基于当前工程根目录下的日志输出文件
|
|
36
|
+
*/
|
|
37
|
+
file: string;
|
|
38
|
+
/**
|
|
39
|
+
* 日志文件是否按日志级别分组,如果设置分组,则在日志文件中不在输出表示级别的tag:[LOG][INFO][WARN][ERROR]等,日志文件名称对应添加*.(log|info|warn|error).log
|
|
40
|
+
*/
|
|
41
|
+
groupByLevel?: boolean;
|
|
42
|
+
};
|
|
43
|
+
/** 日志配置选项 */
|
|
44
|
+
interface ILogOptions {
|
|
45
|
+
/** 日志级别
|
|
46
|
+
* @default LogLevel.LOG
|
|
47
|
+
*/
|
|
48
|
+
levels?: LogLevel[];
|
|
49
|
+
/**
|
|
50
|
+
* 是否支持输出时间戳及时间戳格式
|
|
51
|
+
*
|
|
52
|
+
* 字符串格式参见: https://github.com/date-fns/date-fns/blob/main/src/format/index.ts
|
|
53
|
+
* @default true 开启后默认IOS格式 'yyyy-MM-ddTHH:mm:ss.SSSZ'
|
|
54
|
+
*/
|
|
55
|
+
date?: boolean | string;
|
|
56
|
+
/**
|
|
57
|
+
* 日志输出条件,默认全部输出
|
|
58
|
+
* @default LogMode.All
|
|
59
|
+
*/
|
|
60
|
+
env?: LogMode;
|
|
61
|
+
/** 禁用warn输出,避免在测试场景下影响测试结果
|
|
62
|
+
* @default false
|
|
63
|
+
*/
|
|
64
|
+
disableWarn?: boolean;
|
|
65
|
+
/** 禁用error输出,避免在测试场景下打断正常测试流程
|
|
66
|
+
* @default false
|
|
67
|
+
*/
|
|
68
|
+
disableError?: boolean;
|
|
69
|
+
/** 调用error输出错误信息后,禁止继续抛出异常错误
|
|
70
|
+
* @description
|
|
71
|
+
* 调用error输出错误信息后,默认继续抛出异常错误,在测试环境下可以临地禁用,避免影响正常的测试流程
|
|
72
|
+
*/
|
|
73
|
+
disableThrow?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* 基于当前工程根目录下的日志输出文件
|
|
76
|
+
*
|
|
77
|
+
* @description
|
|
78
|
+
* 浏览器环境:自动忽略该选项;
|
|
79
|
+
*
|
|
80
|
+
* node环境下默认 logs/xxx.log
|
|
81
|
+
*/
|
|
82
|
+
output?: string | LogOutputOptions;
|
|
83
|
+
/**
|
|
84
|
+
* 终端日志输出配色
|
|
85
|
+
* @version ^4.0+
|
|
86
|
+
*/
|
|
87
|
+
color?: boolean;
|
|
88
|
+
}
|
|
89
|
+
interface ILogger {
|
|
90
|
+
assert: (...args: any[]) => void;
|
|
91
|
+
debug: (...args: any[]) => void;
|
|
92
|
+
info: (...args: any[]) => void;
|
|
93
|
+
log: (...args: any[]) => void;
|
|
94
|
+
warn: (...args: any[]) => void;
|
|
95
|
+
error: (...args: any[]) => void;
|
|
96
|
+
success: (...args: any[]) => void;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* 出口方法,
|
|
101
|
+
* @param tags 标签或标签列表,统一转换为大写输出
|
|
102
|
+
* @param options ILogOptions
|
|
103
|
+
* @returns
|
|
104
|
+
*/
|
|
105
|
+
declare const withTags: (tags: LogTags, options?: ILogOptions) => ILogger;
|
|
106
|
+
|
|
107
|
+
export { withTags };
|
package/lib/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function t(t,e,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(t):r?r.value:e.get(t)}function e(t,e,n,r,a){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!a)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!a:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?a.call(t,n):a?a.value=n:e.set(t,n),n}const n=()=>"undefined"!=typeof window;function r(t){return r="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},r(t)}function a(t){return a="function"==typeof Symbol&&"symbol"==r(Symbol.iterator)?function(t){return void 0===t?"undefined":r(t)}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":void 0===t?"undefined":r(t)},a(t)}function o(t){if(null===t||!0===t||!1===t)return NaN;var e=Number(t);return isNaN(e)?e:e<0?Math.ceil(e):Math.floor(e)}function i(t,e){if(e.length<t)throw new TypeError(t+" argument"+(t>1?"s":"")+" required, but only "+e.length+" present")}function u(t){i(1,arguments);var e=Object.prototype.toString.call(t);return t instanceof Date||"object"===a(t)&&"[object Date]"===e?new Date(t.getTime()):"number"==typeof t||"[object Number]"===e?new Date(t):("string"!=typeof t&&"[object String]"!==e||"undefined"==typeof console||(console.warn("Starting with v2.0.0-beta.1 date-fns doesn't accept strings as date arguments. Please use `parseISO` to parse strings. See: https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#string-arguments"),console.warn((new Error).stack)),new Date(NaN))}function s(t,e){i(2,arguments);var n=u(t).getTime(),r=o(e);return new Date(n+r)}var l={};function d(){return l}function c(t){var e=new Date(Date.UTC(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds()));return e.setUTCFullYear(t.getFullYear()),t.getTime()-e.getTime()}function f(t){return i(1,arguments),t instanceof Date||"object"===a(t)&&"[object Date]"===Object.prototype.toString.call(t)}function h(t){if(i(1,arguments),!f(t)&&"number"!=typeof t)return!1;var e=u(t);return!isNaN(Number(e))}function m(t,e){i(2,arguments);var n=o(e);return s(t,-n)}var g=864e5;function v(t){i(1,arguments);var e=1,n=u(t),r=n.getUTCDay(),a=(r<e?7:0)+r-e;return n.setUTCDate(n.getUTCDate()-a),n.setUTCHours(0,0,0,0),n}function w(t){i(1,arguments);var e=u(t),n=e.getUTCFullYear(),r=new Date(0);r.setUTCFullYear(n+1,0,4),r.setUTCHours(0,0,0,0);var a=v(r),o=new Date(0);o.setUTCFullYear(n,0,4),o.setUTCHours(0,0,0,0);var s=v(o);return e.getTime()>=a.getTime()?n+1:e.getTime()>=s.getTime()?n:n-1}function b(t){i(1,arguments);var e=w(t),n=new Date(0);n.setUTCFullYear(e,0,4),n.setUTCHours(0,0,0,0);var r=v(n);return r}var y=6048e5;function p(t,e){var n,r,a,s,l,c,f,h;i(1,arguments);var m=d(),g=o(null!==(n=null!==(r=null!==(a=null!==(s=null==e?void 0:e.weekStartsOn)&&void 0!==s?s:null==e||null===(l=e.locale)||void 0===l||null===(c=l.options)||void 0===c?void 0:c.weekStartsOn)&&void 0!==a?a:m.weekStartsOn)&&void 0!==r?r:null===(f=m.locale)||void 0===f||null===(h=f.options)||void 0===h?void 0:h.weekStartsOn)&&void 0!==n?n:0);if(!(g>=0&&g<=6))throw new RangeError("weekStartsOn must be between 0 and 6 inclusively");var v=u(t),w=v.getUTCDay(),b=(w<g?7:0)+w-g;return v.setUTCDate(v.getUTCDate()-b),v.setUTCHours(0,0,0,0),v}function S(t,e){var n,r,a,s,l,c,f,h;i(1,arguments);var m=u(t),g=m.getUTCFullYear(),v=d(),w=o(null!==(n=null!==(r=null!==(a=null!==(s=null==e?void 0:e.firstWeekContainsDate)&&void 0!==s?s:null==e||null===(l=e.locale)||void 0===l||null===(c=l.options)||void 0===c?void 0:c.firstWeekContainsDate)&&void 0!==a?a:v.firstWeekContainsDate)&&void 0!==r?r:null===(f=v.locale)||void 0===f||null===(h=f.options)||void 0===h?void 0:h.firstWeekContainsDate)&&void 0!==n?n:1);if(!(w>=1&&w<=7))throw new RangeError("firstWeekContainsDate must be between 1 and 7 inclusively");var b=new Date(0);b.setUTCFullYear(g+1,0,w),b.setUTCHours(0,0,0,0);var y=p(b,e),S=new Date(0);S.setUTCFullYear(g,0,w),S.setUTCHours(0,0,0,0);var T=p(S,e);return m.getTime()>=y.getTime()?g+1:m.getTime()>=T.getTime()?g:g-1}function T(t,e){var n,r,a,u,s,l,c,f;i(1,arguments);var h=d(),m=o(null!==(n=null!==(r=null!==(a=null!==(u=null==e?void 0:e.firstWeekContainsDate)&&void 0!==u?u:null==e||null===(s=e.locale)||void 0===s||null===(l=s.options)||void 0===l?void 0:l.firstWeekContainsDate)&&void 0!==a?a:h.firstWeekContainsDate)&&void 0!==r?r:null===(c=h.locale)||void 0===c||null===(f=c.options)||void 0===f?void 0:f.firstWeekContainsDate)&&void 0!==n?n:1),g=S(t,e),v=new Date(0);v.setUTCFullYear(g,0,m),v.setUTCHours(0,0,0,0);var w=p(v,e);return w}var C=6048e5;function M(t,e){for(var n=t<0?"-":"",r=Math.abs(t).toString();r.length<e;)r="0"+r;return n+r}var D=function(t,e){var n=t.getUTCFullYear(),r=n>0?n:1-n;return M("yy"===e?r%100:r,e.length)},E=function(t,e){var n=t.getUTCMonth();return"M"===e?String(n+1):M(n+1,2)},k=function(t,e){return M(t.getUTCDate(),e.length)},U=function(t,e){return M(t.getUTCHours()%12||12,e.length)},x=function(t,e){return M(t.getUTCHours(),e.length)},O=function(t,e){return M(t.getUTCMinutes(),e.length)},P=function(t,e){return M(t.getUTCSeconds(),e.length)},W=function(t,e){var n=e.length,r=t.getUTCMilliseconds();return M(Math.floor(r*Math.pow(10,n-3)),e.length)},N="midnight",R="noon",L="morning",Y="afternoon",A="evening",F="night",j={G:function(t,e,n){var r=t.getUTCFullYear()>0?1:0;switch(e){case"G":case"GG":case"GGG":return n.era(r,{width:"abbreviated"});case"GGGGG":return n.era(r,{width:"narrow"});default:return n.era(r,{width:"wide"})}},y:function(t,e,n){if("yo"===e){var r=t.getUTCFullYear(),a=r>0?r:1-r;return n.ordinalNumber(a,{unit:"year"})}return D(t,e)},Y:function(t,e,n,r){var a=S(t,r),o=a>0?a:1-a;return"YY"===e?M(o%100,2):"Yo"===e?n.ordinalNumber(o,{unit:"year"}):M(o,e.length)},R:function(t,e){return M(w(t),e.length)},u:function(t,e){return M(t.getUTCFullYear(),e.length)},Q:function(t,e,n){var r=Math.ceil((t.getUTCMonth()+1)/3);switch(e){case"Q":return String(r);case"QQ":return M(r,2);case"Qo":return n.ordinalNumber(r,{unit:"quarter"});case"QQQ":return n.quarter(r,{width:"abbreviated",context:"formatting"});case"QQQQQ":return n.quarter(r,{width:"narrow",context:"formatting"});default:return n.quarter(r,{width:"wide",context:"formatting"})}},q:function(t,e,n){var r=Math.ceil((t.getUTCMonth()+1)/3);switch(e){case"q":return String(r);case"qq":return M(r,2);case"qo":return n.ordinalNumber(r,{unit:"quarter"});case"qqq":return n.quarter(r,{width:"abbreviated",context:"standalone"});case"qqqqq":return n.quarter(r,{width:"narrow",context:"standalone"});default:return n.quarter(r,{width:"wide",context:"standalone"})}},M:function(t,e,n){var r=t.getUTCMonth();switch(e){case"M":case"MM":return E(t,e);case"Mo":return n.ordinalNumber(r+1,{unit:"month"});case"MMM":return n.month(r,{width:"abbreviated",context:"formatting"});case"MMMMM":return n.month(r,{width:"narrow",context:"formatting"});default:return n.month(r,{width:"wide",context:"formatting"})}},L:function(t,e,n){var r=t.getUTCMonth();switch(e){case"L":return String(r+1);case"LL":return M(r+1,2);case"Lo":return n.ordinalNumber(r+1,{unit:"month"});case"LLL":return n.month(r,{width:"abbreviated",context:"standalone"});case"LLLLL":return n.month(r,{width:"narrow",context:"standalone"});default:return n.month(r,{width:"wide",context:"standalone"})}},w:function(t,e,n,r){var a=function(t,e){i(1,arguments);var n=u(t),r=p(n,e).getTime()-T(n,e).getTime();return Math.round(r/C)+1}(t,r);return"wo"===e?n.ordinalNumber(a,{unit:"week"}):M(a,e.length)},I:function(t,e,n){var r=function(t){i(1,arguments);var e=u(t),n=v(e).getTime()-b(e).getTime();return Math.round(n/y)+1}(t);return"Io"===e?n.ordinalNumber(r,{unit:"week"}):M(r,e.length)},d:function(t,e,n){return"do"===e?n.ordinalNumber(t.getUTCDate(),{unit:"date"}):k(t,e)},D:function(t,e,n){var r=function(t){i(1,arguments);var e=u(t),n=e.getTime();e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0);var r=e.getTime(),a=n-r;return Math.floor(a/g)+1}(t);return"Do"===e?n.ordinalNumber(r,{unit:"dayOfYear"}):M(r,e.length)},E:function(t,e,n){var r=t.getUTCDay();switch(e){case"E":case"EE":case"EEE":return n.day(r,{width:"abbreviated",context:"formatting"});case"EEEEE":return n.day(r,{width:"narrow",context:"formatting"});case"EEEEEE":return n.day(r,{width:"short",context:"formatting"});default:return n.day(r,{width:"wide",context:"formatting"})}},e:function(t,e,n,r){var a=t.getUTCDay(),o=(a-r.weekStartsOn+8)%7||7;switch(e){case"e":return String(o);case"ee":return M(o,2);case"eo":return n.ordinalNumber(o,{unit:"day"});case"eee":return n.day(a,{width:"abbreviated",context:"formatting"});case"eeeee":return n.day(a,{width:"narrow",context:"formatting"});case"eeeeee":return n.day(a,{width:"short",context:"formatting"});default:return n.day(a,{width:"wide",context:"formatting"})}},c:function(t,e,n,r){var a=t.getUTCDay(),o=(a-r.weekStartsOn+8)%7||7;switch(e){case"c":return String(o);case"cc":return M(o,e.length);case"co":return n.ordinalNumber(o,{unit:"day"});case"ccc":return n.day(a,{width:"abbreviated",context:"standalone"});case"ccccc":return n.day(a,{width:"narrow",context:"standalone"});case"cccccc":return n.day(a,{width:"short",context:"standalone"});default:return n.day(a,{width:"wide",context:"standalone"})}},i:function(t,e,n){var r=t.getUTCDay(),a=0===r?7:r;switch(e){case"i":return String(a);case"ii":return M(a,e.length);case"io":return n.ordinalNumber(a,{unit:"day"});case"iii":return n.day(r,{width:"abbreviated",context:"formatting"});case"iiiii":return n.day(r,{width:"narrow",context:"formatting"});case"iiiiii":return n.day(r,{width:"short",context:"formatting"});default:return n.day(r,{width:"wide",context:"formatting"})}},a:function(t,e,n){var r=t.getUTCHours()/12>=1?"pm":"am";switch(e){case"a":case"aa":return n.dayPeriod(r,{width:"abbreviated",context:"formatting"});case"aaa":return n.dayPeriod(r,{width:"abbreviated",context:"formatting"}).toLowerCase();case"aaaaa":return n.dayPeriod(r,{width:"narrow",context:"formatting"});default:return n.dayPeriod(r,{width:"wide",context:"formatting"})}},b:function(t,e,n){var r,a=t.getUTCHours();switch(r=12===a?R:0===a?N:a/12>=1?"pm":"am",e){case"b":case"bb":return n.dayPeriod(r,{width:"abbreviated",context:"formatting"});case"bbb":return n.dayPeriod(r,{width:"abbreviated",context:"formatting"}).toLowerCase();case"bbbbb":return n.dayPeriod(r,{width:"narrow",context:"formatting"});default:return n.dayPeriod(r,{width:"wide",context:"formatting"})}},B:function(t,e,n){var r,a=t.getUTCHours();switch(r=a>=17?A:a>=12?Y:a>=4?L:F,e){case"B":case"BB":case"BBB":return n.dayPeriod(r,{width:"abbreviated",context:"formatting"});case"BBBBB":return n.dayPeriod(r,{width:"narrow",context:"formatting"});default:return n.dayPeriod(r,{width:"wide",context:"formatting"})}},h:function(t,e,n){if("ho"===e){var r=t.getUTCHours()%12;return 0===r&&(r=12),n.ordinalNumber(r,{unit:"hour"})}return U(t,e)},H:function(t,e,n){return"Ho"===e?n.ordinalNumber(t.getUTCHours(),{unit:"hour"}):x(t,e)},K:function(t,e,n){var r=t.getUTCHours()%12;return"Ko"===e?n.ordinalNumber(r,{unit:"hour"}):M(r,e.length)},k:function(t,e,n){var r=t.getUTCHours();return 0===r&&(r=24),"ko"===e?n.ordinalNumber(r,{unit:"hour"}):M(r,e.length)},m:function(t,e,n){return"mo"===e?n.ordinalNumber(t.getUTCMinutes(),{unit:"minute"}):O(t,e)},s:function(t,e,n){return"so"===e?n.ordinalNumber(t.getUTCSeconds(),{unit:"second"}):P(t,e)},S:function(t,e){return W(t,e)},X:function(t,e,n,r){var a=(r._originalDate||t).getTimezoneOffset();if(0===a)return"Z";switch(e){case"X":return q(a);case"XXXX":case"XX":return G(a);default:return G(a,":")}},x:function(t,e,n,r){var a=(r._originalDate||t).getTimezoneOffset();switch(e){case"x":return q(a);case"xxxx":case"xx":return G(a);default:return G(a,":")}},O:function(t,e,n,r){var a=(r._originalDate||t).getTimezoneOffset();switch(e){case"O":case"OO":case"OOO":return"GMT"+$(a,":");default:return"GMT"+G(a,":")}},z:function(t,e,n,r){var a=(r._originalDate||t).getTimezoneOffset();switch(e){case"z":case"zz":case"zzz":return"GMT"+$(a,":");default:return"GMT"+G(a,":")}},t:function(t,e,n,r){var a=r._originalDate||t;return M(Math.floor(a.getTime()/1e3),e.length)},T:function(t,e,n,r){return M((r._originalDate||t).getTime(),e.length)}};function $(t,e){var n=t>0?"-":"+",r=Math.abs(t),a=Math.floor(r/60),o=r%60;if(0===o)return n+String(a);var i=e||"";return n+String(a)+i+M(o,2)}function q(t,e){return t%60==0?(t>0?"-":"+")+M(Math.abs(t)/60,2):G(t,e)}function G(t,e){var n=e||"",r=t>0?"-":"+",a=Math.abs(t);return r+M(Math.floor(a/60),2)+n+M(a%60,2)}var z=j,H=function(t,e){switch(t){case"P":return e.date({width:"short"});case"PP":return e.date({width:"medium"});case"PPP":return e.date({width:"long"});default:return e.date({width:"full"})}},B=function(t,e){switch(t){case"p":return e.time({width:"short"});case"pp":return e.time({width:"medium"});case"ppp":return e.time({width:"long"});default:return e.time({width:"full"})}},_={p:B,P:function(t,e){var n,r=t.match(/(P+)(p+)?/)||[],a=r[1],o=r[2];if(!o)return H(t,e);switch(a){case"P":n=e.dateTime({width:"short"});break;case"PP":n=e.dateTime({width:"medium"});break;case"PPP":n=e.dateTime({width:"long"});break;default:n=e.dateTime({width:"full"})}return n.replace("{{date}}",H(a,e)).replace("{{time}}",B(o,e))}},Q=_,I=["D","DD"],X=["YY","YYYY"];function J(t){return-1!==I.indexOf(t)}function V(t){return-1!==X.indexOf(t)}function K(t,e,n){if("YYYY"===t)throw new RangeError("Use `yyyy` instead of `YYYY` (in `".concat(e,"`) for formatting years to the input `").concat(n,"`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md"));if("YY"===t)throw new RangeError("Use `yy` instead of `YY` (in `".concat(e,"`) for formatting years to the input `").concat(n,"`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md"));if("D"===t)throw new RangeError("Use `d` instead of `D` (in `".concat(e,"`) for formatting days of the month to the input `").concat(n,"`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md"));if("DD"===t)throw new RangeError("Use `dd` instead of `DD` (in `".concat(e,"`) for formatting days of the month to the input `").concat(n,"`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md"))}var Z={lessThanXSeconds:{one:"less than a second",other:"less than {{count}} seconds"},xSeconds:{one:"1 second",other:"{{count}} seconds"},halfAMinute:"half a minute",lessThanXMinutes:{one:"less than a minute",other:"less than {{count}} minutes"},xMinutes:{one:"1 minute",other:"{{count}} minutes"},aboutXHours:{one:"about 1 hour",other:"about {{count}} hours"},xHours:{one:"1 hour",other:"{{count}} hours"},xDays:{one:"1 day",other:"{{count}} days"},aboutXWeeks:{one:"about 1 week",other:"about {{count}} weeks"},xWeeks:{one:"1 week",other:"{{count}} weeks"},aboutXMonths:{one:"about 1 month",other:"about {{count}} months"},xMonths:{one:"1 month",other:"{{count}} months"},aboutXYears:{one:"about 1 year",other:"about {{count}} years"},xYears:{one:"1 year",other:"{{count}} years"},overXYears:{one:"over 1 year",other:"over {{count}} years"},almostXYears:{one:"almost 1 year",other:"almost {{count}} years"}};function tt(t){return function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=e.width?String(e.width):t.defaultWidth,r=t.formats[n]||t.formats[t.defaultWidth];return r}}var et={date:tt({formats:{full:"EEEE, MMMM do, y",long:"MMMM do, y",medium:"MMM d, y",short:"MM/dd/yyyy"},defaultWidth:"full"}),time:tt({formats:{full:"h:mm:ss a zzzz",long:"h:mm:ss a z",medium:"h:mm:ss a",short:"h:mm a"},defaultWidth:"full"}),dateTime:tt({formats:{full:"{{date}} 'at' {{time}}",long:"{{date}} 'at' {{time}}",medium:"{{date}}, {{time}}",short:"{{date}}, {{time}}"},defaultWidth:"full"})},nt={lastWeek:"'last' eeee 'at' p",yesterday:"'yesterday at' p",today:"'today at' p",tomorrow:"'tomorrow at' p",nextWeek:"eeee 'at' p",other:"P"};function rt(t){return function(e,n){var r;if("formatting"===(null!=n&&n.context?String(n.context):"standalone")&&t.formattingValues){var a=t.defaultFormattingWidth||t.defaultWidth,o=null!=n&&n.width?String(n.width):a;r=t.formattingValues[o]||t.formattingValues[a]}else{var i=t.defaultWidth,u=null!=n&&n.width?String(n.width):t.defaultWidth;r=t.values[u]||t.values[i]}return r[t.argumentCallback?t.argumentCallback(e):e]}}function at(t){return function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=n.width,a=r&&t.matchPatterns[r]||t.matchPatterns[t.defaultMatchWidth],o=e.match(a);if(!o)return null;var i,u=o[0],s=r&&t.parsePatterns[r]||t.parsePatterns[t.defaultParseWidth],l=Array.isArray(s)?it(s,(function(t){return t.test(u)})):ot(s,(function(t){return t.test(u)}));i=t.valueCallback?t.valueCallback(l):l,i=n.valueCallback?n.valueCallback(i):i;var d=e.slice(u.length);return{value:i,rest:d}}}function ot(t,e){for(var n in t)if(t.hasOwnProperty(n)&&e(t[n]))return n}function it(t,e){for(var n=0;n<t.length;n++)if(e(t[n]))return n}var ut,st={code:"en-US",formatDistance:function(t,e,n){var r,a=Z[t];return r="string"==typeof a?a:1===e?a.one:a.other.replace("{{count}}",e.toString()),null!=n&&n.addSuffix?n.comparison&&n.comparison>0?"in "+r:r+" ago":r},formatLong:et,formatRelative:function(t,e,n,r){return nt[t]},localize:{ordinalNumber:function(t,e){var n=Number(t),r=n%100;if(r>20||r<10)switch(r%10){case 1:return n+"st";case 2:return n+"nd";case 3:return n+"rd"}return n+"th"},era:rt({values:{narrow:["B","A"],abbreviated:["BC","AD"],wide:["Before Christ","Anno Domini"]},defaultWidth:"wide"}),quarter:rt({values:{narrow:["1","2","3","4"],abbreviated:["Q1","Q2","Q3","Q4"],wide:["1st quarter","2nd quarter","3rd quarter","4th quarter"]},defaultWidth:"wide",argumentCallback:function(t){return t-1}}),month:rt({values:{narrow:["J","F","M","A","M","J","J","A","S","O","N","D"],abbreviated:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],wide:["January","February","March","April","May","June","July","August","September","October","November","December"]},defaultWidth:"wide"}),day:rt({values:{narrow:["S","M","T","W","T","F","S"],short:["Su","Mo","Tu","We","Th","Fr","Sa"],abbreviated:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],wide:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]},defaultWidth:"wide"}),dayPeriod:rt({values:{narrow:{am:"a",pm:"p",midnight:"mi",noon:"n",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},abbreviated:{am:"AM",pm:"PM",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},wide:{am:"a.m.",pm:"p.m.",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"}},defaultWidth:"wide",formattingValues:{narrow:{am:"a",pm:"p",midnight:"mi",noon:"n",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"},abbreviated:{am:"AM",pm:"PM",midnight:"midnight",noon:"noon",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"},wide:{am:"a.m.",pm:"p.m.",midnight:"midnight",noon:"noon",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"}},defaultFormattingWidth:"wide"})},match:{ordinalNumber:(ut={matchPattern:/^(\d+)(th|st|nd|rd)?/i,parsePattern:/\d+/i,valueCallback:function(t){return parseInt(t,10)}},function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.match(ut.matchPattern);if(!n)return null;var r=n[0],a=t.match(ut.parsePattern);if(!a)return null;var o=ut.valueCallback?ut.valueCallback(a[0]):a[0];o=e.valueCallback?e.valueCallback(o):o;var i=t.slice(r.length);return{value:o,rest:i}}),era:at({matchPatterns:{narrow:/^(b|a)/i,abbreviated:/^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,wide:/^(before christ|before common era|anno domini|common era)/i},defaultMatchWidth:"wide",parsePatterns:{any:[/^b/i,/^(a|c)/i]},defaultParseWidth:"any"}),quarter:at({matchPatterns:{narrow:/^[1234]/i,abbreviated:/^q[1234]/i,wide:/^[1234](th|st|nd|rd)? quarter/i},defaultMatchWidth:"wide",parsePatterns:{any:[/1/i,/2/i,/3/i,/4/i]},defaultParseWidth:"any",valueCallback:function(t){return t+1}}),month:at({matchPatterns:{narrow:/^[jfmasond]/i,abbreviated:/^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,wide:/^(january|february|march|april|may|june|july|august|september|october|november|december)/i},defaultMatchWidth:"wide",parsePatterns:{narrow:[/^j/i,/^f/i,/^m/i,/^a/i,/^m/i,/^j/i,/^j/i,/^a/i,/^s/i,/^o/i,/^n/i,/^d/i],any:[/^ja/i,/^f/i,/^mar/i,/^ap/i,/^may/i,/^jun/i,/^jul/i,/^au/i,/^s/i,/^o/i,/^n/i,/^d/i]},defaultParseWidth:"any"}),day:at({matchPatterns:{narrow:/^[smtwf]/i,short:/^(su|mo|tu|we|th|fr|sa)/i,abbreviated:/^(sun|mon|tue|wed|thu|fri|sat)/i,wide:/^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i},defaultMatchWidth:"wide",parsePatterns:{narrow:[/^s/i,/^m/i,/^t/i,/^w/i,/^t/i,/^f/i,/^s/i],any:[/^su/i,/^m/i,/^tu/i,/^w/i,/^th/i,/^f/i,/^sa/i]},defaultParseWidth:"any"}),dayPeriod:at({matchPatterns:{narrow:/^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,any:/^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i},defaultMatchWidth:"any",parsePatterns:{any:{am:/^a/i,pm:/^p/i,midnight:/^mi/i,noon:/^no/i,morning:/morning/i,afternoon:/afternoon/i,evening:/evening/i,night:/night/i}},defaultParseWidth:"any"})},options:{weekStartsOn:0,firstWeekContainsDate:1}},lt=/[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g,dt=/P+p+|P+|p+|''|'(''|[^'])+('|$)|./g,ct=/^'([^]*?)'?$/,ft=/''/g,ht=/[a-zA-Z]/;function mt(t,e,n){var r,a,s,l,f,g,v,w,b,y,p,S,T,C,M,D,E,k;i(2,arguments);var U=String(e),x=d(),O=null!==(r=null!==(a=null==n?void 0:n.locale)&&void 0!==a?a:x.locale)&&void 0!==r?r:st,P=o(null!==(s=null!==(l=null!==(f=null!==(g=null==n?void 0:n.firstWeekContainsDate)&&void 0!==g?g:null==n||null===(v=n.locale)||void 0===v||null===(w=v.options)||void 0===w?void 0:w.firstWeekContainsDate)&&void 0!==f?f:x.firstWeekContainsDate)&&void 0!==l?l:null===(b=x.locale)||void 0===b||null===(y=b.options)||void 0===y?void 0:y.firstWeekContainsDate)&&void 0!==s?s:1);if(!(P>=1&&P<=7))throw new RangeError("firstWeekContainsDate must be between 1 and 7 inclusively");var W=o(null!==(p=null!==(S=null!==(T=null!==(C=null==n?void 0:n.weekStartsOn)&&void 0!==C?C:null==n||null===(M=n.locale)||void 0===M||null===(D=M.options)||void 0===D?void 0:D.weekStartsOn)&&void 0!==T?T:x.weekStartsOn)&&void 0!==S?S:null===(E=x.locale)||void 0===E||null===(k=E.options)||void 0===k?void 0:k.weekStartsOn)&&void 0!==p?p:0);if(!(W>=0&&W<=6))throw new RangeError("weekStartsOn must be between 0 and 6 inclusively");if(!O.localize)throw new RangeError("locale must contain localize property");if(!O.formatLong)throw new RangeError("locale must contain formatLong property");var N=u(t);if(!h(N))throw new RangeError("Invalid time value");var R=c(N),L=m(N,R),Y={firstWeekContainsDate:P,weekStartsOn:W,locale:O,_originalDate:N},A=U.match(dt).map((function(t){var e=t[0];return"p"===e||"P"===e?(0,Q[e])(t,O.formatLong):t})).join("").match(lt).map((function(r){if("''"===r)return"'";var a=r[0];if("'"===a)return gt(r);var o=z[a];if(o)return null!=n&&n.useAdditionalWeekYearTokens||!V(r)||K(r,e,String(t)),null!=n&&n.useAdditionalDayOfYearTokens||!J(r)||K(r,e,String(t)),o(L,r,O.localize,Y);if(a.match(ht))throw new RangeError("Format string contains an unescaped latin alphabet character `"+a+"`");return r})).join("");return A}function gt(t){var e=t.match(ct);return e?e[1].replace(ft,"'"):t}const vt=t=>"string"==typeof t||"[object String]"===(t=>Object.prototype.toString.call(t))(t),wt=Array.isArray,bt=Number.isInteger,yt=(t,e)=>{let n=null;bt(e)&&(e={wait:e});const{immediate:r,wait:a=100}=e||{};return(...e)=>{n&&clearTimeout(n),r&&!n&&t(...e),n=setTimeout((()=>{t(...e)}),a)}};var pt,St,Tt,Ct,Mt,Dt,Et,kt,Ut,xt,Ot,Pt=()=>{};class Wt{static get cache(){return t(Wt,St,"f",Tt)}get defaultLogFile(){return`logs/${mt(Date.now(),"yyyy-MM-dd")}.log`}constructor(){pt.add(this),this.lastWrite=Date.now(),Ct.set(this,void 0),Mt.set(this,void 0),e(this,Ct,new Map,"f"),(n()?Promise.resolve(null):Promise.all([import("fs"),import("path")]).then((([t,e])=>{if(!t)return null;const{existsSync:n,mkdirSync:r,writeFile:a}=t,{sep:o,resolve:i,join:u,dirname:s}=e;return{existsSync:n,mkdirSync:r,writeFile:a,join:u,sep:o,resolve:i,dirname:s}})).catch((()=>null))).then((t=>{e(this,Mt,t,"f")}))}push(e,n){var r;let a=(null==n?void 0:n.file)||this.defaultLogFile;if(null==n?void 0:n.groupByLevel){const t=e.prefix||[],n=(null===(r=e.level)||void 0===r?void 0:r.toLowerCase())||"unknown";a=a.replace(/\.log$/,`.${n}.log`),e.prefix=t}let o=t(this,Ct,"f").get(a);o||(o={Set:new Set,writer:yt((t=>this.flush(t)),1e3)},t(this,Ct,"f").set(a,o));const i=Date.now();o.Set.add(e).size>1e3||i-this.lastWrite>3e4?this.flush(a):o.writer(a)}flush(e){t(this,Mt,"f")&&t(this,Ct,"f").forEach(((n,r)=>{if(n&&(null===e&&r===this.defaultLogFile||!e||r===e)){const e=Array.from(n.Set);n.Set.clear(),t(this,pt,"m",Et).call(this,r,e),this.lastWrite=Date.now()}}))}}St=Wt,Ct=new WeakMap,Mt=new WeakMap,pt=new WeakSet,Dt=function(e){var n,r;const a=(null===(r=null===(n=t(this,Mt,"f"))||void 0===n?void 0:n.dirname)||void 0===r?void 0:r.call(n,e||this.defaultLogFile))||"",{existsSync:o,mkdirSync:i}=t(this,Mt,"f")||{};(null==o?void 0:o(a))||null==i||i(a)},Et=function(e,n){if(wt(n)||(n=[n]),!e)throw new Error("output log file is missed");t(this,pt,"m",Dt).call(this,e);const{writeFile:r}=t(this,Mt,"f")||{};if(e&&r){const t=n.reduce(((t,{prefix:e=[],data:n})=>[...t,[...e,...n.map((t=>"string"==typeof t?t:JSON.stringify(t)))].join(" "),"\n"]),[]);null==r||r(e,t.join(""),{flag:"a"},Pt)}},Tt={value:new Wt},(Ut=kt||(kt={})).ALL="all",Ut.PRODUCTION="production",Ut.DEVELOPMENET="development",(Ot=xt||(xt={})).ASSERT="ASSERT",Ot.LOG="LOG",Ot.WARN="WARN",Ot.INFO="INFO",Ot.ERROR="ERROR",Ot.DEBUG="DEBUG",Ot.SUCCESS="SUCCESS";const Nt={date:!0,env:kt.ALL},Rt=t=>("all"===t||process.env.NODE_ENV===t)&&void 0!==console;var Lt=Object.freeze({__proto__:null,$boolean:"#9c27b0",$date:"#0063ff",$empty:"#656565",$function:"#795548",$number:"#0063ff",$object:"#795548",ASSERT:"#00bcd4",DEBUG:"#607d8b",ERROR:"#f44336",INFO:"#2196f3",LOG:"#757575",SUCCESS:"#4caf50",WARN:"#ff9800",timestamp:"#9e9e9e"});var Yt=Object.freeze({__proto__:null,$boolean:"[35m",$date:"[90m",$empty:"[90m",$function:"[90m",$number:"[94m",$object:"[90m",ASSERT:"[34m",DEBUG:"[36m",ERROR:"[91m",INFO:"[94m",LOG:"[0m",SUCCESS:"[32m",WARN:"[33m",timestamp:"[90m"});var At=Object.freeze({__proto__:null,ASSERT:"A",DEBUG:"D",ERROR:"E",INFO:"I",LOG:"L",SUCCESS:"O",WARN:"W"});const Ft={},jt=t=>{if(null==t)return"%s";const e=t.constructor.name.toLocaleLowerCase();return"number"===e?"%f":"function"===e||"object"===e||null==t?"%o":"%s"},$t=(t,e,r)=>{var a,o,i;return n()?(null==r?void 0:r.backColor)?[`%c${null!==(a=null==r?void 0:r.fmtTag)&&void 0!==a?a:"%s"}%c `,`color:${t};background-color:${t}3f;padding-inline:4px;border-radius:2px;`,e,""]:[`%c${null!==(o=null==r?void 0:r.fmtTag)&&void 0!==o?o:"%s"}%c `,`color:${t}`,e,""]:[`%s${null!==(i=null==r?void 0:r.fmtTag)&&void 0!==i?i:"%s"}%s `,t,e,"[0m"]},qt=(t,e,r)=>{var a;const o=n()?Lt:Yt,i=null===(a=null==r?void 0:r.date)||void 0===a||a,u=[];if(!1!==i){const t=new Date;u.push($t(o.timestamp,vt(i)?mt(t,i):t.toISOString()))}const s=o[t];u.push($t(s,`[${At[t]}]`));const{tags:l,args:d}=e||{},c=(wt(l)?l:l.split(",")).reduce(((t,e)=>{const r=Ft[e]||(Ft[e]=(()=>{if(n())return`#${Math.floor(128*Math.random()).toString(16).padStart(2,"0")}${Math.floor(128*Math.random()).toString(16).padStart(2,"0")}${Math.floor(128*Math.random()).toString(16).padStart(2,"0")}`;{const t=[40,100,41,101,42,102,43,103,44,104,45,105,46,106,47,107],e=Math.floor(Math.random()*t.length),n=t[e];return`[${t[t.length-e-1]-10}m[${n}m`}})());return[...t,$t(r,e.toUpperCase(),{backColor:!0})]}),[]),f=d.reduce(((t,e)=>{var r;const a=null!==(r=(t=>{const e=n()?Lt:Yt;return null==t?e.$empty:e[`$${t.constructor.name.toLocaleLowerCase()}`]})(e))&&void 0!==r?r:s;return[...t,$t(a,e,{fmtTag:jt(e)})]}),[]);return[...u,...c,...f]},Gt=(t,e,n)=>{const{output:r,levels:a=[]}=n,o=vt(r)?{file:r}:r;(null==a?void 0:a.length)&&!a.includes(xt.SUCCESS)||Wt.cache.push({level:t,data:[...e.reduce(((t,e)=>[...t,e[1]]),[])]},o)},zt=(t,e,n,r)=>{const{env:a=kt.ALL,color:o=!0}=r;Rt(null!=a?a:kt.ALL)&&(!1!==o?t(e,...n.reduce(((t,e)=>[...t,...e]),[])):t(...n.reduce(((t,e)=>[...t,e[1]]),[])))},Ht=(t,e)=>{const r={...Nt,...e};return{assert:(a,...o)=>{var i;const u=qt(xt.ASSERT,{tags:t,args:o},e),s=u.reduce(((t,[e])=>t+e),""),l=u.reduce(((t,[e,...n])=>[...t,n]),[]);Rt(null!==(i=r.env)&&void 0!==i?i:kt.ALL)&&(n()?!1===r.color?console.assert(a,...l.reduce(((t,e)=>[...t,e[1]]),[])):console.assert(a,s,...l.reduce(((t,e)=>[...t,...e]),[])):console.assert(a,l.reduce(((t,e)=>[...t,...!1===r.color?[e[1]]:e]),[]).join(" "))),a||Gt(xt.ASSERT,l,r)},debug:(...n)=>{const a=qt(xt.DEBUG,{tags:t,args:n},e),o=a.reduce(((t,[e])=>t+e),""),i=a.reduce(((t,[e,...n])=>[...t,n]),[]);zt(console.debug,o,i,r),Gt(xt.DEBUG,i,r)},info:(...n)=>{const a=qt(xt.INFO,{tags:t,args:n},e),o=a.reduce(((t,[e])=>t+e),""),i=a.reduce(((t,[e,...n])=>[...t,n]),[]);zt(console.info,o,i,r),Gt(xt.INFO,i,r)},log:(...n)=>{const a=qt(xt.LOG,{tags:t,args:n},e),o=a.reduce(((t,[e])=>t+e),""),i=a.reduce(((t,[e,...n])=>[...t,n]),[]);zt(console.log,o,i,r),Gt(xt.LOG,i,r)},warn:(...n)=>{const a=qt(xt.WARN,{tags:t,args:n},e),o=a.reduce(((t,[e])=>t+e),""),i=a.reduce(((t,[e,...n])=>[...t,n]),[]),{disableError:u}=r,s=u?console.log:console.warn;zt(s,o,i,r),Gt(xt.WARN,i,r)},error:(n,a)=>{const o=qt(xt.ERROR,{tags:t,args:[n,a]},e),i=o.reduce(((t,[e])=>t+e),""),u=o.reduce(((t,[e,...n])=>[...t,n]),[]),{disableThrow:s,disableError:l}=r,d=l?console.log:console.error;if(zt(d,i,u,r),Gt(xt.ERROR,u,r),!1===s)throw new Error(n)},success:(...n)=>{const a=qt(xt.SUCCESS,{tags:t,args:n},e),o=a.reduce(((t,[e])=>t+e),""),i=a.reduce(((t,[e,...n])=>[...t,n]),[]);zt(console.log,o,i,r),Gt(xt.SUCCESS,i,r)}}};export{Ht as withTags};
|