@jeffchi/logger 1.0.8 → 1.1.11-rc.2

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Archer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -19,8 +19,8 @@ A log print output javascript tool library that can be used at the front and bac
19
19
  - 支持服务端使用, 在服务端使用时默认写入 %root%/logs/yyyy-mm-dd.log 日志文件。
20
20
 
21
21
  | [<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/)</br>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/)</br>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/)</br>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/)</br>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/)</br>Opera |
22
- | --- | --- | --- | --- | --- |
23
- | Edge | last 2 versions | last 2 versions | last 2 versions | last 2 versions |
22
+ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
23
+ | Edge | last 2 versions | last 2 versions | last 2 versions | last 2 versions |
24
24
 
25
25
  ## 安装
26
26
 
@@ -36,23 +36,22 @@ $ yarn add @jeffchi/logger
36
36
 
37
37
  如果你的网络环境不佳,推荐使用 [cnpm](https://github.com/cnpm/cnpm)。
38
38
 
39
-
40
39
  ## 用法
41
40
 
42
41
  ```javascript
43
42
  import { loggerWithTags } from '@jeffchi/logger';
44
43
  import { LogLevel, LogMode } from '@jeffchi/logger/lib/interface';
45
- const { debug,error,info,log,warn } = loggerWithTags(
46
- 'api', // ['api','get'] 一个或多个tag
47
- {
48
- level: LogLevel.LOG, // 日志级别只有指定级别的日志才会输出至日志文件
49
- date: 'MMM dd, yyyy HH:mm:ss.sss', // 日志输出的时间戳格式,true表示使用默认utc IOS日期时间格式,false表示不输出时间戳
50
- env: LogMode.ALL, // 环境参数,开发版本或生产版本,如果指定开发环境,则生产环境不输出任何内容,也不会写入到日志文件
51
- disableWarn: false, // 禁用Warn输出,用debug代替,仅影响前端控制台和后端终端,不影响实际内容打印.在跑测试时应该启用,避免影响测试结果
52
- disableError: false, // 禁用Error输出,用debug代替,仅影响前端控制台和后端终端,不影响实际内容打印.在跑测试时应该启用,避免影响测试结果
53
- ignoreThrow: false, // 默认Error输出后,会抛出异常,从而打断后端执行流程,可指定true取消该行为,在跑测试时应该启用,避免影响测试测试流程
54
- outputFile: 'logs/<yyyy-MM-dd>.log', // 输出日志文件的位置,仅服务端使用时有效
55
- }
44
+ const { debug, error, info, log, warn } = loggerWithTags(
45
+ 'api', // ['api','get'] 一个或多个tag
46
+ {
47
+ level: LogLevel.LOG, // 日志级别只有指定级别的日志才会输出至日志文件
48
+ date: 'MMM dd, yyyy HH:mm:ss.sss', // 日志输出的时间戳格式,true表示使用默认utc IOS日期时间格式,false表示不输出时间戳
49
+ env: LogMode.ALL, // 环境参数,开发版本或生产版本,如果指定开发环境,则生产环境不输出任何内容,也不会写入到日志文件
50
+ disableWarn: false, // 禁用Warn输出,用debug代替,仅影响前端控制台和后端终端,不影响实际内容打印.在跑测试时应该启用,避免影响测试结果
51
+ disableError: false, // 禁用Error输出,用debug代替,仅影响前端控制台和后端终端,不影响实际内容打印.在跑测试时应该启用,避免影响测试结果
52
+ ignoreThrow: false, // 默认Error输出后,会抛出异常,从而打断后端执行流程,可指定true取消该行为,在跑测试时应该启用,避免影响测试测试流程
53
+ outputFile: 'logs/<yyyy-MM-dd>.log', // 输出日志文件的位置,仅服务端使用时有效
54
+ },
56
55
  );
57
56
  ```
58
57
 
@@ -70,8 +69,8 @@ export type LogTags = string | string[];
70
69
  ```
71
70
 
72
71
  ### options
73
- ```javascript
74
72
 
73
+ ```javascript
75
74
  /** 日志配置选项 */
76
75
  export interface ILogOptions {
77
76
  /** 日志级别
@@ -113,8 +112,27 @@ export interface ILogOptions {
113
112
  */
114
113
  outputFile?: string;
115
114
  }
116
-
117
115
  ```
118
116
 
119
- ## Lincence
117
+ ## 测试
118
+
119
+ `src/__test__` 目录下的 `*.spec.ts` 和 `*.test.ts` 是测试文件.
120
+
121
+ - `*.spec.ts` 特定于指定版本的测试文件,需要切换到指定版本分支才能保证测试通过
122
+ - `*.test.ts` 当前版本的测试文件
123
+
124
+ > 测试基于 `ts-jest`,终端窗口通过指定参数,来运行特定的测试文件
125
+ >
126
+ > ```bash
127
+ > npm run test 1.0.3 # 1.0.3的测试文件
128
+ > npm run test main # 当前测试文件
129
+ > npm run test # 所有测试文件
130
+ > ```
131
+
132
+ ## License
133
+
120
134
  MIT
135
+
136
+ ```
137
+
138
+ ```
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}function n(t){return n="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},n(t)}function r(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 a(t,e){if(e.length<t)throw new TypeError(t+" argument"+(t>1?"s":"")+" required, but only "+e.length+" present")}function i(t){return i="function"==typeof Symbol&&"symbol"===n(Symbol.iterator)?function(t){return void 0===t?"undefined":n(t)}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":void 0===t?"undefined":n(t)},i(t)}function o(t){a(1,arguments);var e=Object.prototype.toString.call(t);return t instanceof Date||"object"===i(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 u(t,e){a(2,arguments);var n=o(t).getTime(),i=r(e);return new Date(n+i)}var s={};function l(){return s}function d(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 c(t){return c="function"==typeof Symbol&&"symbol"===n(Symbol.iterator)?function(t){return void 0===t?"undefined":n(t)}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":void 0===t?"undefined":n(t)},c(t)}function h(t){return a(1,arguments),t instanceof Date||"object"===c(t)&&"[object Date]"===Object.prototype.toString.call(t)}function f(t){if(a(1,arguments),!h(t)&&"number"!=typeof t)return!1;var e=o(t);return!isNaN(Number(e))}function m(t,e){a(2,arguments);var n=r(e);return u(t,-n)}var g=864e5;function w(t){a(1,arguments);var e=1,n=o(t),r=n.getUTCDay(),i=(r<e?7:0)+r-e;return n.setUTCDate(n.getUTCDate()-i),n.setUTCHours(0,0,0,0),n}function v(t){a(1,arguments);var e=o(t),n=e.getUTCFullYear(),r=new Date(0);r.setUTCFullYear(n+1,0,4),r.setUTCHours(0,0,0,0);var i=w(r),u=new Date(0);u.setUTCFullYear(n,0,4),u.setUTCHours(0,0,0,0);var s=w(u);return e.getTime()>=i.getTime()?n+1:e.getTime()>=s.getTime()?n:n-1}function b(t){a(1,arguments);var e=v(t),n=new Date(0);n.setUTCFullYear(e,0,4),n.setUTCHours(0,0,0,0);var r=w(n);return r}var y=6048e5;function p(t,e){var n,i,u,s,d,c,h,f;a(1,arguments);var m=l(),g=r(null!==(n=null!==(i=null!==(u=null!==(s=null==e?void 0:e.weekStartsOn)&&void 0!==s?s:null==e||null===(d=e.locale)||void 0===d||null===(c=d.options)||void 0===c?void 0:c.weekStartsOn)&&void 0!==u?u:m.weekStartsOn)&&void 0!==i?i:null===(h=m.locale)||void 0===h||null===(f=h.options)||void 0===f?void 0:f.weekStartsOn)&&void 0!==n?n:0);if(!(g>=0&&g<=6))throw new RangeError("weekStartsOn must be between 0 and 6 inclusively");var w=o(t),v=w.getUTCDay(),b=(v<g?7:0)+v-g;return w.setUTCDate(w.getUTCDate()-b),w.setUTCHours(0,0,0,0),w}function T(t,e){var n,i,u,s,d,c,h,f;a(1,arguments);var m=o(t),g=m.getUTCFullYear(),w=l(),v=r(null!==(n=null!==(i=null!==(u=null!==(s=null==e?void 0:e.firstWeekContainsDate)&&void 0!==s?s:null==e||null===(d=e.locale)||void 0===d||null===(c=d.options)||void 0===c?void 0:c.firstWeekContainsDate)&&void 0!==u?u:w.firstWeekContainsDate)&&void 0!==i?i:null===(h=w.locale)||void 0===h||null===(f=h.options)||void 0===f?void 0:f.firstWeekContainsDate)&&void 0!==n?n:1);if(!(v>=1&&v<=7))throw new RangeError("firstWeekContainsDate must be between 1 and 7 inclusively");var b=new Date(0);b.setUTCFullYear(g+1,0,v),b.setUTCHours(0,0,0,0);var y=p(b,e),T=new Date(0);T.setUTCFullYear(g,0,v),T.setUTCHours(0,0,0,0);var C=p(T,e);return m.getTime()>=y.getTime()?g+1:m.getTime()>=C.getTime()?g:g-1}function C(t,e){var n,i,o,u,s,d,c,h;a(1,arguments);var f=l(),m=r(null!==(n=null!==(i=null!==(o=null!==(u=null==e?void 0:e.firstWeekContainsDate)&&void 0!==u?u:null==e||null===(s=e.locale)||void 0===s||null===(d=s.options)||void 0===d?void 0:d.firstWeekContainsDate)&&void 0!==o?o:f.firstWeekContainsDate)&&void 0!==i?i:null===(c=f.locale)||void 0===c||null===(h=c.options)||void 0===h?void 0:h.firstWeekContainsDate)&&void 0!==n?n:1),g=T(t,e),w=new Date(0);w.setUTCFullYear(g,0,m),w.setUTCHours(0,0,0,0);var v=p(w,e);return v}var M=6048e5;function D(t,e){for(var n=t<0?"-":"",r=Math.abs(t).toString();r.length<e;)r="0"+r;return n+r}var S=function(t,e){var n=t.getUTCFullYear(),r=n>0?n:1-n;return D("yy"===e?r%100:r,e.length)},k=function(t,e){var n=t.getUTCMonth();return"M"===e?String(n+1):D(n+1,2)},x=function(t,e){return D(t.getUTCDate(),e.length)},U=function(t,e){return D(t.getUTCHours()%12||12,e.length)},P=function(t,e){return D(t.getUTCHours(),e.length)},W=function(t,e){return D(t.getUTCMinutes(),e.length)},E=function(t,e){return D(t.getUTCSeconds(),e.length)},O=function(t,e){var n=e.length,r=t.getUTCMilliseconds();return D(Math.floor(r*Math.pow(10,n-3)),e.length)},N="midnight",Y="noon",L="morning",F="afternoon",j="evening",q="night",A={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 S(t,e)},Y:function(t,e,n,r){var a=T(t,r),i=a>0?a:1-a;return"YY"===e?D(i%100,2):"Yo"===e?n.ordinalNumber(i,{unit:"year"}):D(i,e.length)},R:function(t,e){return D(v(t),e.length)},u:function(t,e){return D(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 D(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 D(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 k(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 D(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 i=function(t,e){a(1,arguments);var n=o(t),r=p(n,e).getTime()-C(n,e).getTime();return Math.round(r/M)+1}(t,r);return"wo"===e?n.ordinalNumber(i,{unit:"week"}):D(i,e.length)},I:function(t,e,n){var r=function(t){a(1,arguments);var e=o(t),n=w(e).getTime()-b(e).getTime();return Math.round(n/y)+1}(t);return"Io"===e?n.ordinalNumber(r,{unit:"week"}):D(r,e.length)},d:function(t,e,n){return"do"===e?n.ordinalNumber(t.getUTCDate(),{unit:"date"}):x(t,e)},D:function(t,e,n){var r=function(t){a(1,arguments);var e=o(t),n=e.getTime();e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0);var r=e.getTime(),i=n-r;return Math.floor(i/g)+1}(t);return"Do"===e?n.ordinalNumber(r,{unit:"dayOfYear"}):D(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(),i=(a-r.weekStartsOn+8)%7||7;switch(e){case"e":return String(i);case"ee":return D(i,2);case"eo":return n.ordinalNumber(i,{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(),i=(a-r.weekStartsOn+8)%7||7;switch(e){case"c":return String(i);case"cc":return D(i,e.length);case"co":return n.ordinalNumber(i,{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 D(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?Y: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?j:a>=12?F:a>=4?L:q,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"}):P(t,e)},K:function(t,e,n){var r=t.getUTCHours()%12;return"Ko"===e?n.ordinalNumber(r,{unit:"hour"}):D(r,e.length)},k:function(t,e,n){var r=t.getUTCHours();return 0===r&&(r=24),"ko"===e?n.ordinalNumber(r,{unit:"hour"}):D(r,e.length)},m:function(t,e,n){return"mo"===e?n.ordinalNumber(t.getUTCMinutes(),{unit:"minute"}):W(t,e)},s:function(t,e,n){return"so"===e?n.ordinalNumber(t.getUTCSeconds(),{unit:"second"}):E(t,e)},S:function(t,e){return O(t,e)},X:function(t,e,n,r){var a=(r._originalDate||t).getTimezoneOffset();if(0===a)return"Z";switch(e){case"X":return G(a);case"XXXX":case"XX":return H(a);default:return H(a,":")}},x:function(t,e,n,r){var a=(r._originalDate||t).getTimezoneOffset();switch(e){case"x":return G(a);case"xxxx":case"xx":return H(a);default:return H(a,":")}},O:function(t,e,n,r){var a=(r._originalDate||t).getTimezoneOffset();switch(e){case"O":case"OO":case"OOO":return"GMT"+R(a,":");default:return"GMT"+H(a,":")}},z:function(t,e,n,r){var a=(r._originalDate||t).getTimezoneOffset();switch(e){case"z":case"zz":case"zzz":return"GMT"+R(a,":");default:return"GMT"+H(a,":")}},t:function(t,e,n,r){var a=r._originalDate||t;return D(Math.floor(a.getTime()/1e3),e.length)},T:function(t,e,n,r){return D((r._originalDate||t).getTime(),e.length)}};function R(t,e){var n=t>0?"-":"+",r=Math.abs(t),a=Math.floor(r/60),i=r%60;if(0===i)return n+String(a);var o=e||"";return n+String(a)+o+D(i,2)}function G(t,e){return t%60==0?(t>0?"-":"+")+D(Math.abs(t)/60,2):H(t,e)}function H(t,e){var n=e||"",r=t>0?"-":"+",a=Math.abs(t);return r+D(Math.floor(a/60),2)+n+D(a%60,2)}var z=A,B=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"})}},Q=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"})}},X={p:Q,P:function(t,e){var n,r=t.match(/(P+)(p+)?/)||[],a=r[1],i=r[2];if(!i)return B(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}}",B(a,e)).replace("{{time}}",Q(i,e))}},I=X,J=["D","DD"],$=["YY","YYYY"];function _(t){return-1!==J.indexOf(t)}function V(t){return-1!==$.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,i=null!=n&&n.width?String(n.width):a;r=t.formattingValues[i]||t.formattingValues[a]}else{var o=t.defaultWidth,u=null!=n&&n.width?String(n.width):t.defaultWidth;r=t.values[u]||t.values[o]}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],i=e.match(a);if(!i)return null;var o,u=i[0],s=r&&t.parsePatterns[r]||t.parsePatterns[t.defaultParseWidth],l=Array.isArray(s)?ot(s,(function(t){return t.test(u)})):it(s,(function(t){return t.test(u)}));o=t.valueCallback?t.valueCallback(l):l,o=n.valueCallback?n.valueCallback(o):o;var d=e.slice(u.length);return{value:o,rest:d}}}function it(t,e){for(var n in t)if(t.hasOwnProperty(n)&&e(t[n]))return n}function ot(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 i=ut.valueCallback?ut.valueCallback(a[0]):a[0];i=e.valueCallback?e.valueCallback(i):i;var o=t.slice(r.length);return{value:i,rest:o}}),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=/^'([^]*?)'?$/,ht=/''/g,ft=/[a-zA-Z]/;function mt(t,e,n){var i,u,s,c,h,g,w,v,b,y,p,T,C,M,D,S,k,x;a(2,arguments);var U=String(e),P=l(),W=null!==(i=null!==(u=null==n?void 0:n.locale)&&void 0!==u?u:P.locale)&&void 0!==i?i:st,E=r(null!==(s=null!==(c=null!==(h=null!==(g=null==n?void 0:n.firstWeekContainsDate)&&void 0!==g?g:null==n||null===(w=n.locale)||void 0===w||null===(v=w.options)||void 0===v?void 0:v.firstWeekContainsDate)&&void 0!==h?h:P.firstWeekContainsDate)&&void 0!==c?c:null===(b=P.locale)||void 0===b||null===(y=b.options)||void 0===y?void 0:y.firstWeekContainsDate)&&void 0!==s?s:1);if(!(E>=1&&E<=7))throw new RangeError("firstWeekContainsDate must be between 1 and 7 inclusively");var O=r(null!==(p=null!==(T=null!==(C=null!==(M=null==n?void 0:n.weekStartsOn)&&void 0!==M?M:null==n||null===(D=n.locale)||void 0===D||null===(S=D.options)||void 0===S?void 0:S.weekStartsOn)&&void 0!==C?C:P.weekStartsOn)&&void 0!==T?T:null===(k=P.locale)||void 0===k||null===(x=k.options)||void 0===x?void 0:x.weekStartsOn)&&void 0!==p?p:0);if(!(O>=0&&O<=6))throw new RangeError("weekStartsOn must be between 0 and 6 inclusively");if(!W.localize)throw new RangeError("locale must contain localize property");if(!W.formatLong)throw new RangeError("locale must contain formatLong property");var N=o(t);if(!f(N))throw new RangeError("Invalid time value");var Y=d(N),L=m(N,Y),F={firstWeekContainsDate:E,weekStartsOn:O,locale:W,_originalDate:N},j=U.match(dt).map((function(t){var e=t[0];return"p"===e||"P"===e?(0,I[e])(t,W.formatLong):t})).join("").match(lt).map((function(r){if("''"===r)return"'";var a=r[0];if("'"===a)return gt(r);var i=z[a];if(i)return null!=n&&n.useAdditionalWeekYearTokens||!V(r)||K(r,e,String(t)),null!=n&&n.useAdditionalDayOfYearTokens||!_(r)||K(r,e,String(t)),i(L,r,W.localize,F);if(a.match(ft))throw new RangeError("Format string contains an unescaped latin alphabet character `"+a+"`");return r})).join("");return j}function gt(t){var e=t.match(ct);return e?e[1].replace(ht,"'"):t}const wt=t=>"string"==typeof t||"[object String]"===(t=>Object.prototype.toString.call(t))(t),vt=Array.isArray,bt=Number.isInteger;var yt,pt,Tt,Ct,Mt,Dt,St,kt,xt,Ut,Pt,Wt=()=>{};class Et{static get cache(){return t(Et,pt,"f",Tt)}get defaultLogFile(){return`logs/${mt(Date.now(),"yyyy-MM-dd")}.log`}constructor(){yt.add(this),this.lastWrite=Date.now(),Ct.set(this,void 0),Mt.set(this,void 0),this.write=((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)}})((t=>this.flush(t)),1e3),e(this,Ct,new Map,"f"),Promise.all([import("fs"),import("path")]).then((([t,e])=>{if(!t)return null;const{existsSync:n,mkdirSync:r,writeFile:a}=t,{sep:i,resolve:o,join:u,dirname:s}=e;return{existsSync:n,mkdirSync:r,writeFile:a,join:u,sep:i,resolve:o,dirname:s}})).then((t=>{e(this,Mt,t,"f")}))}push(e,n){n=n||this.defaultLogFile;let r=t(this,Ct,"f").get(n);r||(r=new Set,t(this,Ct,"f").set(n,r));const a=Date.now();r.add(e).size>1e3||a-this.lastWrite>3e4?this.flush(n):this.write(n)}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);n.clear(),t(this,yt,"m",St).call(this,r,e),this.lastWrite=Date.now()}}))}}pt=Et,Ct=new WeakMap,Mt=new WeakMap,yt=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:i,mkdirSync:o}=t(this,Mt,"f")||{};(null==i?void 0:i(a))||null==o||o(a)},St=function(e,n){vt(n)||(n=[n]),e=e||this.defaultLogFile,t(this,yt,"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(JSON.stringify),"\n"].join(" ")]),[]);null==r||r(e,t.join(""),{flag:"a"},Wt)}},Tt={value:new Et},(xt=kt||(kt={})).ALL="all",xt.PRODUCTION="production",xt.DEVELOPMENET="development",xt.NONE="none",(Pt=Ut||(Ut={})).LOG="LOG",Pt.WARN="WARN",Pt.INFO="INFO",Pt.ERROR="ERROR",Pt.DEBUG="DEBUG";const Ot={date:!0,env:kt.ALL},Nt=(t,e)=>{const{date:n}=e,r=[];if(t.length&&r.unshift(t.map((t=>`[${t.toUpperCase()}]`)).join(" ")),n){const t=new Date;let e;e=wt(n)?mt(t,n):new Date(t).toISOString(),r.unshift(e)}return r},Yt=t=>("all"===t||process.env.NODE_ENV===t)&&void 0!==console;exports.loggerWithTags=(t,e)=>{vt(t)||(t=[t]);const{env:n,outputFile:r,levels:a=[],...i}={...Ot,...e||{}};return{debug:(...e)=>{const o=Nt(t,{...i});o.unshift(`[${Ut.DEBUG}]\t`),Yt(n||kt.ALL)&&console.debug(...o,...e),(null==a?void 0:a.length)&&!a.includes(Ut.DEBUG)||Et.cache.push({prefix:o,timestamp:Date.now(),data:[...e]},r)},info:(...e)=>{const o=Nt(t,{...i});o.unshift(`[${Ut.INFO}]\t`),Yt(n||kt.ALL)&&console.info(...o,...e),(null==a?void 0:a.length)&&!a.includes(Ut.INFO)||Et.cache.push({prefix:o,timestamp:Date.now(),data:[...e]},r)},log:(...e)=>{const o=Nt(t,i);o.unshift(`[${Ut.LOG}]\t`),Yt(n||kt.ALL)&&console.log(...o,...e),(null==a?void 0:a.length)&&!a.includes(Ut.LOG)||Et.cache.push({prefix:o,timestamp:Date.now(),data:[...e]},r)},warn:(...e)=>{const o=Nt(t,{...i});o.unshift(`[${Ut.WARN}]\t`);const{disableError:u}=i,s=u?console.debug:console.warn;Yt(n||kt.ALL)&&s(...o,...e),(null==a?void 0:a.length)&&!a.includes(Ut.WARN)||Et.cache.push({prefix:o,timestamp:Date.now(),data:[...e]},r)},error:(e,o)=>{const u=Nt(t,{...i});u.unshift(`[${Ut.ERROR}]\t`);const{disableThrow:s,ignoreThrow:l,disableError:d}=i,c=d?console.debug:console.error;if(Yt(n||kt.ALL)&&c(...u,e),(null==a?void 0:a.length)&&!a.includes(Ut.ERROR)||Et.cache.push({prefix:u,timestamp:Date.now(),data:[e]},r),!1===l||!1===s)throw new Error(e,{cause:o})}}};
package/lib/index.d.ts CHANGED
@@ -1,2 +1,80 @@
1
- import { ILogger, ILogOptions, LogTags } from './interface';
2
- export declare const loggerWithTags: (tags: LogTags, options?: ILogOptions) => ILogger;
1
+ /**
2
+ * 日志输出打印的模式
3
+ * @default LogMode.ALL
4
+ */
5
+ declare enum LogMode {
6
+ ALL = "all",
7
+ PRODUCTION = "production",
8
+ DEVELOPMENET = "development",
9
+ NONE = "none"
10
+ }
11
+ /**
12
+ * 日志级别
13
+ */
14
+ declare enum LogLevel {
15
+ LOG = "LOG",
16
+ WARN = "WARN",
17
+ INFO = "INFO",
18
+ ERROR = "ERROR",
19
+ DEBUG = "DEBUG"
20
+ }
21
+ /** 日志标签 */
22
+ type LogTags = string | string[];
23
+ /** 日志配置选项 */
24
+ interface ILogOptions {
25
+ /** 日志级别
26
+ * @default LogLevel.LOG
27
+ */
28
+ levels?: LogLevel[];
29
+ /**
30
+ * 是否支持输出时间戳及时间戳格式
31
+ *
32
+ * 字符串格式参见: https://github.com/date-fns/date-fns/blob/main/src/format/index.ts
33
+ * @default true 开启后默认IOS格式 'yyyy-MM-ddTHH:mm:ss.SSSZ'
34
+ */
35
+ date?: boolean | string;
36
+ /**
37
+ * 日志输出条件,默认全部输出
38
+ * @default LogMode.All
39
+ */
40
+ env?: LogMode;
41
+ /** 禁用warn输出,避免在测试场景下影响测试结果
42
+ * @default false
43
+ */
44
+ disableWarn?: boolean;
45
+ /** 禁用error输出,避免在测试场景下打断正常测试流程
46
+ * @default false
47
+ */
48
+ disableError?: boolean;
49
+ /** 调用error输出错误信息后,禁止继续抛出异常错误
50
+ * @description
51
+ * 调用error输出错误信息后,默认继续抛出异常错误,在测试环境下可以临地禁用,避免影响正常的测试流程
52
+ * @deprecated 由disabledThrow代替
53
+ */
54
+ ignoreThrow?: boolean;
55
+ /** 调用error输出错误信息后,禁止继续抛出异常错误
56
+ * @description
57
+ * 调用error输出错误信息后,默认继续抛出异常错误,在测试环境下可以临地禁用,避免影响正常的测试流程
58
+ */
59
+ disableThrow?: boolean;
60
+ /**
61
+ * 基于当前工程根目录下的日志输出文件
62
+ *
63
+ * @description
64
+ * 浏览器环境:自动忽略该选项;
65
+ *
66
+ * node环境下默认 logs/xxx.log
67
+ */
68
+ outputFile?: string;
69
+ }
70
+ interface ILogger {
71
+ debug: (...rest: any[]) => void;
72
+ info: (...rest: any[]) => void;
73
+ log: (...rest: any[]) => void;
74
+ warn: (...rest: any[]) => void;
75
+ error: (msg: string) => void;
76
+ }
77
+
78
+ declare const loggerWithTags: (tags: LogTags, options?: ILogOptions) => ILogger;
79
+
80
+ export { loggerWithTags };
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}function n(t){return n="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},n(t)}function r(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 a(t,e){if(e.length<t)throw new TypeError(t+" argument"+(t>1?"s":"")+" required, but only "+e.length+" present")}function i(t){return i="function"==typeof Symbol&&"symbol"===n(Symbol.iterator)?function(t){return void 0===t?"undefined":n(t)}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":void 0===t?"undefined":n(t)},i(t)}function o(t){a(1,arguments);var e=Object.prototype.toString.call(t);return t instanceof Date||"object"===i(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 u(t,e){a(2,arguments);var n=o(t).getTime(),i=r(e);return new Date(n+i)}var s={};function l(){return s}function d(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 c(t){return c="function"==typeof Symbol&&"symbol"===n(Symbol.iterator)?function(t){return void 0===t?"undefined":n(t)}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":void 0===t?"undefined":n(t)},c(t)}function h(t){return a(1,arguments),t instanceof Date||"object"===c(t)&&"[object Date]"===Object.prototype.toString.call(t)}function f(t){if(a(1,arguments),!h(t)&&"number"!=typeof t)return!1;var e=o(t);return!isNaN(Number(e))}function m(t,e){a(2,arguments);var n=r(e);return u(t,-n)}var g=864e5;function w(t){a(1,arguments);var e=1,n=o(t),r=n.getUTCDay(),i=(r<e?7:0)+r-e;return n.setUTCDate(n.getUTCDate()-i),n.setUTCHours(0,0,0,0),n}function v(t){a(1,arguments);var e=o(t),n=e.getUTCFullYear(),r=new Date(0);r.setUTCFullYear(n+1,0,4),r.setUTCHours(0,0,0,0);var i=w(r),u=new Date(0);u.setUTCFullYear(n,0,4),u.setUTCHours(0,0,0,0);var s=w(u);return e.getTime()>=i.getTime()?n+1:e.getTime()>=s.getTime()?n:n-1}function b(t){a(1,arguments);var e=v(t),n=new Date(0);n.setUTCFullYear(e,0,4),n.setUTCHours(0,0,0,0);var r=w(n);return r}var y=6048e5;function p(t,e){var n,i,u,s,d,c,h,f;a(1,arguments);var m=l(),g=r(null!==(n=null!==(i=null!==(u=null!==(s=null==e?void 0:e.weekStartsOn)&&void 0!==s?s:null==e||null===(d=e.locale)||void 0===d||null===(c=d.options)||void 0===c?void 0:c.weekStartsOn)&&void 0!==u?u:m.weekStartsOn)&&void 0!==i?i:null===(h=m.locale)||void 0===h||null===(f=h.options)||void 0===f?void 0:f.weekStartsOn)&&void 0!==n?n:0);if(!(g>=0&&g<=6))throw new RangeError("weekStartsOn must be between 0 and 6 inclusively");var w=o(t),v=w.getUTCDay(),b=(v<g?7:0)+v-g;return w.setUTCDate(w.getUTCDate()-b),w.setUTCHours(0,0,0,0),w}function T(t,e){var n,i,u,s,d,c,h,f;a(1,arguments);var m=o(t),g=m.getUTCFullYear(),w=l(),v=r(null!==(n=null!==(i=null!==(u=null!==(s=null==e?void 0:e.firstWeekContainsDate)&&void 0!==s?s:null==e||null===(d=e.locale)||void 0===d||null===(c=d.options)||void 0===c?void 0:c.firstWeekContainsDate)&&void 0!==u?u:w.firstWeekContainsDate)&&void 0!==i?i:null===(h=w.locale)||void 0===h||null===(f=h.options)||void 0===f?void 0:f.firstWeekContainsDate)&&void 0!==n?n:1);if(!(v>=1&&v<=7))throw new RangeError("firstWeekContainsDate must be between 1 and 7 inclusively");var b=new Date(0);b.setUTCFullYear(g+1,0,v),b.setUTCHours(0,0,0,0);var y=p(b,e),T=new Date(0);T.setUTCFullYear(g,0,v),T.setUTCHours(0,0,0,0);var C=p(T,e);return m.getTime()>=y.getTime()?g+1:m.getTime()>=C.getTime()?g:g-1}function C(t,e){var n,i,o,u,s,d,c,h;a(1,arguments);var f=l(),m=r(null!==(n=null!==(i=null!==(o=null!==(u=null==e?void 0:e.firstWeekContainsDate)&&void 0!==u?u:null==e||null===(s=e.locale)||void 0===s||null===(d=s.options)||void 0===d?void 0:d.firstWeekContainsDate)&&void 0!==o?o:f.firstWeekContainsDate)&&void 0!==i?i:null===(c=f.locale)||void 0===c||null===(h=c.options)||void 0===h?void 0:h.firstWeekContainsDate)&&void 0!==n?n:1),g=T(t,e),w=new Date(0);w.setUTCFullYear(g,0,m),w.setUTCHours(0,0,0,0);var v=p(w,e);return v}var M=6048e5;function D(t,e){for(var n=t<0?"-":"",r=Math.abs(t).toString();r.length<e;)r="0"+r;return n+r}var S=function(t,e){var n=t.getUTCFullYear(),r=n>0?n:1-n;return D("yy"===e?r%100:r,e.length)},k=function(t,e){var n=t.getUTCMonth();return"M"===e?String(n+1):D(n+1,2)},x=function(t,e){return D(t.getUTCDate(),e.length)},U=function(t,e){return D(t.getUTCHours()%12||12,e.length)},P=function(t,e){return D(t.getUTCHours(),e.length)},W=function(t,e){return D(t.getUTCMinutes(),e.length)},E=function(t,e){return D(t.getUTCSeconds(),e.length)},O=function(t,e){var n=e.length,r=t.getUTCMilliseconds();return D(Math.floor(r*Math.pow(10,n-3)),e.length)},N="midnight",Y="noon",L="morning",F="afternoon",j="evening",q="night",A={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 S(t,e)},Y:function(t,e,n,r){var a=T(t,r),i=a>0?a:1-a;return"YY"===e?D(i%100,2):"Yo"===e?n.ordinalNumber(i,{unit:"year"}):D(i,e.length)},R:function(t,e){return D(v(t),e.length)},u:function(t,e){return D(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 D(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 D(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 k(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 D(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 i=function(t,e){a(1,arguments);var n=o(t),r=p(n,e).getTime()-C(n,e).getTime();return Math.round(r/M)+1}(t,r);return"wo"===e?n.ordinalNumber(i,{unit:"week"}):D(i,e.length)},I:function(t,e,n){var r=function(t){a(1,arguments);var e=o(t),n=w(e).getTime()-b(e).getTime();return Math.round(n/y)+1}(t);return"Io"===e?n.ordinalNumber(r,{unit:"week"}):D(r,e.length)},d:function(t,e,n){return"do"===e?n.ordinalNumber(t.getUTCDate(),{unit:"date"}):x(t,e)},D:function(t,e,n){var r=function(t){a(1,arguments);var e=o(t),n=e.getTime();e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0);var r=e.getTime(),i=n-r;return Math.floor(i/g)+1}(t);return"Do"===e?n.ordinalNumber(r,{unit:"dayOfYear"}):D(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(),i=(a-r.weekStartsOn+8)%7||7;switch(e){case"e":return String(i);case"ee":return D(i,2);case"eo":return n.ordinalNumber(i,{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(),i=(a-r.weekStartsOn+8)%7||7;switch(e){case"c":return String(i);case"cc":return D(i,e.length);case"co":return n.ordinalNumber(i,{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 D(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?Y: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?j:a>=12?F:a>=4?L:q,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"}):P(t,e)},K:function(t,e,n){var r=t.getUTCHours()%12;return"Ko"===e?n.ordinalNumber(r,{unit:"hour"}):D(r,e.length)},k:function(t,e,n){var r=t.getUTCHours();return 0===r&&(r=24),"ko"===e?n.ordinalNumber(r,{unit:"hour"}):D(r,e.length)},m:function(t,e,n){return"mo"===e?n.ordinalNumber(t.getUTCMinutes(),{unit:"minute"}):W(t,e)},s:function(t,e,n){return"so"===e?n.ordinalNumber(t.getUTCSeconds(),{unit:"second"}):E(t,e)},S:function(t,e){return O(t,e)},X:function(t,e,n,r){var a=(r._originalDate||t).getTimezoneOffset();if(0===a)return"Z";switch(e){case"X":return G(a);case"XXXX":case"XX":return H(a);default:return H(a,":")}},x:function(t,e,n,r){var a=(r._originalDate||t).getTimezoneOffset();switch(e){case"x":return G(a);case"xxxx":case"xx":return H(a);default:return H(a,":")}},O:function(t,e,n,r){var a=(r._originalDate||t).getTimezoneOffset();switch(e){case"O":case"OO":case"OOO":return"GMT"+R(a,":");default:return"GMT"+H(a,":")}},z:function(t,e,n,r){var a=(r._originalDate||t).getTimezoneOffset();switch(e){case"z":case"zz":case"zzz":return"GMT"+R(a,":");default:return"GMT"+H(a,":")}},t:function(t,e,n,r){var a=r._originalDate||t;return D(Math.floor(a.getTime()/1e3),e.length)},T:function(t,e,n,r){return D((r._originalDate||t).getTime(),e.length)}};function R(t,e){var n=t>0?"-":"+",r=Math.abs(t),a=Math.floor(r/60),i=r%60;if(0===i)return n+String(a);var o=e||"";return n+String(a)+o+D(i,2)}function G(t,e){return t%60==0?(t>0?"-":"+")+D(Math.abs(t)/60,2):H(t,e)}function H(t,e){var n=e||"",r=t>0?"-":"+",a=Math.abs(t);return r+D(Math.floor(a/60),2)+n+D(a%60,2)}var z=A,B=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"})}},Q=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"})}},X={p:Q,P:function(t,e){var n,r=t.match(/(P+)(p+)?/)||[],a=r[1],i=r[2];if(!i)return B(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}}",B(a,e)).replace("{{time}}",Q(i,e))}},I=X,J=["D","DD"],$=["YY","YYYY"];function _(t){return-1!==J.indexOf(t)}function V(t){return-1!==$.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,i=null!=n&&n.width?String(n.width):a;r=t.formattingValues[i]||t.formattingValues[a]}else{var o=t.defaultWidth,u=null!=n&&n.width?String(n.width):t.defaultWidth;r=t.values[u]||t.values[o]}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],i=e.match(a);if(!i)return null;var o,u=i[0],s=r&&t.parsePatterns[r]||t.parsePatterns[t.defaultParseWidth],l=Array.isArray(s)?ot(s,(function(t){return t.test(u)})):it(s,(function(t){return t.test(u)}));o=t.valueCallback?t.valueCallback(l):l,o=n.valueCallback?n.valueCallback(o):o;var d=e.slice(u.length);return{value:o,rest:d}}}function it(t,e){for(var n in t)if(t.hasOwnProperty(n)&&e(t[n]))return n}function ot(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 i=ut.valueCallback?ut.valueCallback(a[0]):a[0];i=e.valueCallback?e.valueCallback(i):i;var o=t.slice(r.length);return{value:i,rest:o}}),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=/^'([^]*?)'?$/,ht=/''/g,ft=/[a-zA-Z]/;function mt(t,e,n){var i,u,s,c,h,g,w,v,b,y,p,T,C,M,D,S,k,x;a(2,arguments);var U=String(e),P=l(),W=null!==(i=null!==(u=null==n?void 0:n.locale)&&void 0!==u?u:P.locale)&&void 0!==i?i:st,E=r(null!==(s=null!==(c=null!==(h=null!==(g=null==n?void 0:n.firstWeekContainsDate)&&void 0!==g?g:null==n||null===(w=n.locale)||void 0===w||null===(v=w.options)||void 0===v?void 0:v.firstWeekContainsDate)&&void 0!==h?h:P.firstWeekContainsDate)&&void 0!==c?c:null===(b=P.locale)||void 0===b||null===(y=b.options)||void 0===y?void 0:y.firstWeekContainsDate)&&void 0!==s?s:1);if(!(E>=1&&E<=7))throw new RangeError("firstWeekContainsDate must be between 1 and 7 inclusively");var O=r(null!==(p=null!==(T=null!==(C=null!==(M=null==n?void 0:n.weekStartsOn)&&void 0!==M?M:null==n||null===(D=n.locale)||void 0===D||null===(S=D.options)||void 0===S?void 0:S.weekStartsOn)&&void 0!==C?C:P.weekStartsOn)&&void 0!==T?T:null===(k=P.locale)||void 0===k||null===(x=k.options)||void 0===x?void 0:x.weekStartsOn)&&void 0!==p?p:0);if(!(O>=0&&O<=6))throw new RangeError("weekStartsOn must be between 0 and 6 inclusively");if(!W.localize)throw new RangeError("locale must contain localize property");if(!W.formatLong)throw new RangeError("locale must contain formatLong property");var N=o(t);if(!f(N))throw new RangeError("Invalid time value");var Y=d(N),L=m(N,Y),F={firstWeekContainsDate:E,weekStartsOn:O,locale:W,_originalDate:N},j=U.match(dt).map((function(t){var e=t[0];return"p"===e||"P"===e?(0,I[e])(t,W.formatLong):t})).join("").match(lt).map((function(r){if("''"===r)return"'";var a=r[0];if("'"===a)return gt(r);var i=z[a];if(i)return null!=n&&n.useAdditionalWeekYearTokens||!V(r)||K(r,e,String(t)),null!=n&&n.useAdditionalDayOfYearTokens||!_(r)||K(r,e,String(t)),i(L,r,W.localize,F);if(a.match(ft))throw new RangeError("Format string contains an unescaped latin alphabet character `"+a+"`");return r})).join("");return j}function gt(t){var e=t.match(ct);return e?e[1].replace(ht,"'"):t}const wt=t=>"string"==typeof t||"[object String]"===(t=>Object.prototype.toString.call(t))(t),vt=Array.isArray,bt=Number.isInteger;var yt,pt,Tt,Ct,Mt,Dt,St,kt,xt,Ut,Pt,Wt=()=>{};class Et{static get cache(){return t(Et,pt,"f",Tt)}get defaultLogFile(){return`logs/${mt(Date.now(),"yyyy-MM-dd")}.log`}constructor(){yt.add(this),this.lastWrite=Date.now(),Ct.set(this,void 0),Mt.set(this,void 0),this.write=((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)}})((t=>this.flush(t)),1e3),e(this,Ct,new Map,"f"),Promise.all([import("fs"),import("path")]).then((([t,e])=>{if(!t)return null;const{existsSync:n,mkdirSync:r,writeFile:a}=t,{sep:i,resolve:o,join:u,dirname:s}=e;return{existsSync:n,mkdirSync:r,writeFile:a,join:u,sep:i,resolve:o,dirname:s}})).then((t=>{e(this,Mt,t,"f")}))}push(e,n){n=n||this.defaultLogFile;let r=t(this,Ct,"f").get(n);r||(r=new Set,t(this,Ct,"f").set(n,r));const a=Date.now();r.add(e).size>1e3||a-this.lastWrite>3e4?this.flush(n):this.write(n)}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);n.clear(),t(this,yt,"m",St).call(this,r,e),this.lastWrite=Date.now()}}))}}pt=Et,Ct=new WeakMap,Mt=new WeakMap,yt=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:i,mkdirSync:o}=t(this,Mt,"f")||{};(null==i?void 0:i(a))||null==o||o(a)},St=function(e,n){vt(n)||(n=[n]),e=e||this.defaultLogFile,t(this,yt,"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(JSON.stringify),"\n"].join(" ")]),[]);null==r||r(e,t.join(""),{flag:"a"},Wt)}},Tt={value:new Et},(xt=kt||(kt={})).ALL="all",xt.PRODUCTION="production",xt.DEVELOPMENET="development",xt.NONE="none",(Pt=Ut||(Ut={})).LOG="LOG",Pt.WARN="WARN",Pt.INFO="INFO",Pt.ERROR="ERROR",Pt.DEBUG="DEBUG";const Ot={date:!0,env:kt.ALL},Nt=(t,e)=>{const{date:n}=e,r=[];if(t.length&&r.unshift(t.map((t=>`[${t.toUpperCase()}]`)).join(" ")),n){const t=new Date;let e;e=wt(n)?mt(t,n):new Date(t).toISOString(),r.unshift(e)}return r},Yt=t=>("all"===t||process.env.NODE_ENV===t)&&void 0!==console,Lt=(t,e)=>{vt(t)||(t=[t]);const{env:n,outputFile:r,levels:a=[],...i}={...Ot,...e||{}};return{debug:(...e)=>{const o=Nt(t,{...i});o.unshift(`[${Ut.DEBUG}]\t`),Yt(n||kt.ALL)&&console.debug(...o,...e),(null==a?void 0:a.length)&&!a.includes(Ut.DEBUG)||Et.cache.push({prefix:o,timestamp:Date.now(),data:[...e]},r)},info:(...e)=>{const o=Nt(t,{...i});o.unshift(`[${Ut.INFO}]\t`),Yt(n||kt.ALL)&&console.info(...o,...e),(null==a?void 0:a.length)&&!a.includes(Ut.INFO)||Et.cache.push({prefix:o,timestamp:Date.now(),data:[...e]},r)},log:(...e)=>{const o=Nt(t,i);o.unshift(`[${Ut.LOG}]\t`),Yt(n||kt.ALL)&&console.log(...o,...e),(null==a?void 0:a.length)&&!a.includes(Ut.LOG)||Et.cache.push({prefix:o,timestamp:Date.now(),data:[...e]},r)},warn:(...e)=>{const o=Nt(t,{...i});o.unshift(`[${Ut.WARN}]\t`);const{disableError:u}=i,s=u?console.debug:console.warn;Yt(n||kt.ALL)&&s(...o,...e),(null==a?void 0:a.length)&&!a.includes(Ut.WARN)||Et.cache.push({prefix:o,timestamp:Date.now(),data:[...e]},r)},error:(e,o)=>{const u=Nt(t,{...i});u.unshift(`[${Ut.ERROR}]\t`);const{disableThrow:s,ignoreThrow:l,disableError:d}=i,c=d?console.debug:console.error;if(Yt(n||kt.ALL)&&c(...u,e),(null==a?void 0:a.length)&&!a.includes(Ut.ERROR)||Et.cache.push({prefix:u,timestamp:Date.now(),data:[e]},r),!1===l||!1===s)throw new Error(e,{cause:o})}}};export{Lt as loggerWithTags};
package/package.json CHANGED
@@ -1,8 +1,10 @@
1
1
  {
2
2
  "name": "@jeffchi/logger",
3
- "version": "1.0.8",
4
- "main": "lib/index.js",
3
+ "version": "1.1.11-rc.2",
4
+ "main": "lib/index.cjs",
5
+ "module": "lib/index.mjs",
5
6
  "types": "lib/index.d.ts",
7
+ "type": "module",
6
8
  "description": "A log print output javascript tool library that can be used at the front and back ends",
7
9
  "repository": {
8
10
  "type": "git",
@@ -23,37 +25,73 @@
23
25
  "debug"
24
26
  ],
25
27
  "scripts": {
26
- "build": "tsc",
28
+ "clear": "rm -rf lib/ docs/",
29
+ "doc": "typedoc --options typedoc.json",
30
+ "dev": "rollup -c --watch",
31
+ "build": "npm run clear && npm run doc && rollup -c",
27
32
  "prepare": "npm run build",
28
33
  "format": "prettier --write \"src/**/*.ts\"",
29
34
  "lint": "tslint -p tsconfig.json",
30
35
  "test": "jest --config jestconfig.json",
31
36
  "prepublishOnly": "npm run test && npm run lint",
32
37
  "preversion": "npm run lint",
33
- "version": "npm run format && git add -A src",
34
- "postversion": "git push && git push --tags"
38
+ "version": "npm run format && git add .",
39
+ "postversion": "git push && git push --tags",
40
+ "prerelease": "npm run lint && npm run format && npm run doc",
41
+ "release": "standard-version",
42
+ "postrelease": "git push --follow-tags && npm publish",
43
+ "prerelease:alpha": "npm run lint && npm run format && npm run doc",
44
+ "release:alpha": "standard-version --prerelease alpha",
45
+ "postrelease:alpha": "git push --follow-tags && npm publish --tag alpha",
46
+ "prerelease:rc": "npm run lint && npm run format && npm run doc",
47
+ "release:rc": "standard-version --prerelease rc",
48
+ "postrelease:rc": "git push --follow-tags && npm publish --tag rc",
49
+ "release:major": "npm run release -- --release-as major",
50
+ "release:minor": "npm run release -- --release-as minor",
51
+ "release:patch": "npm run release -- --release-as patch"
35
52
  },
36
53
  "author": "jeffery·chiang",
37
54
  "license": "MIT",
55
+ "exports": {
56
+ ".": {
57
+ "import": "./lib/index.mjs",
58
+ "require": "./lib/index.cjs",
59
+ "types": "./index.d.ts"
60
+ }
61
+ },
38
62
  "files": [
39
- "lib/**/*"
63
+ "lib",
64
+ "*.d.ts"
40
65
  ],
41
66
  "peerDependencies": {
42
- "date-fns": "^2.29.3",
43
- "@types/lodash": "^4.14.191",
44
- "@types/node": "^18.11.18",
45
- "lodash": "^4.17.21"
67
+ "date-fns": "^2.29.3"
46
68
  },
47
69
  "devDependencies": {
70
+ "@babel/core": "^7.20.12",
71
+ "@rollup/plugin-alias": "^4.0.2",
72
+ "@rollup/plugin-babel": "^6.0.3",
73
+ "@rollup/plugin-commonjs": "^24.0.0",
74
+ "@rollup/plugin-json": "^6.0.0",
75
+ "@rollup/plugin-node-resolve": "^15.0.1",
76
+ "@rollup/plugin-terser": "^0.3.0",
77
+ "@rollup/plugin-typescript": "^11.0.0",
48
78
  "@types/jest": "^29.2.5",
49
- "@types/lodash": "^4.14.191",
50
79
  "@types/node": "^18.11.18",
80
+ "babel-preset-env": "^1.7.0",
81
+ "esbuild": "^0.17.0",
51
82
  "jest": "^29.3.1",
52
- "lodash": "^4.17.21",
53
83
  "prettier": "^2.8.2",
84
+ "rollup": "^3.10.0",
85
+ "rollup-plugin-cleanup": "^3.2.1",
86
+ "rollup-plugin-dts": "^5.1.1",
87
+ "rollup-plugin-esbuild": "^5.0.0",
88
+ "rollup-plugin-typescript2": "^0.34.1",
89
+ "standard-version": "^9.5.0",
54
90
  "ts-jest": "^29.0.5",
91
+ "tslib": "^2.4.1",
55
92
  "tslint": "^6.1.3",
56
93
  "tslint-config-prettier": "^1.18.0",
94
+ "typedoc": "^0.23.24",
57
95
  "typescript": "^4.9.4"
58
96
  }
59
97
  }
package/lib/cache.d.ts DELETED
@@ -1,19 +0,0 @@
1
- /// <reference types="lodash" />
2
- export interface LogContent {
3
- prefix?: string[];
4
- data: any[];
5
- timestamp: number;
6
- }
7
- /** 单例模式的缓存对像 */
8
- export declare class LogCache {
9
- #private;
10
- lastWrite: number;
11
- static get cache(): LogCache;
12
- get defaultLogFile(): string;
13
- private constructor();
14
- push(data: LogContent, file?: string): void;
15
- /** 立即写入并清空缓存 */
16
- flush(file?: string): void;
17
- /** 延迟写入并清空缓存 */
18
- write: import("lodash").DebouncedFunc<(file: any) => void>;
19
- }
package/lib/cache.js DELETED
@@ -1,83 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.LogCache = void 0;
7
- const checkPlateform_1 = require("./utils/checkPlateform");
8
- const date_fns_1 = require("date-fns");
9
- const lodash_1 = require("lodash");
10
- const noop_1 = __importDefault(require("./utils/noop"));
11
- const type_1 = require("./utils/type");
12
- /** 单例模式的缓存对像 */
13
- class LogCache {
14
- static #cache = new LogCache();
15
- lastWrite = Date.now();
16
- #map;
17
- #fs;
18
- static get cache() {
19
- return LogCache.#cache;
20
- }
21
- get defaultLogFile() {
22
- return `logs/${(0, date_fns_1.format)(Date.now(), 'yyyy-MM-dd')}.log`;
23
- }
24
- constructor() {
25
- this.#map = new Map();
26
- (0, checkPlateform_1.checkPlatform)().then((fs) => {
27
- this.#fs = fs;
28
- });
29
- }
30
- push(data, file) {
31
- file = file || this.defaultLogFile;
32
- let set = this.#map.get(file);
33
- if (!set) {
34
- set = new Set();
35
- this.#map.set(file, set);
36
- }
37
- const now = Date.now();
38
- if (set.add(data).size > 1000 || now - this.lastWrite > 30000) {
39
- this.flush(file);
40
- }
41
- else {
42
- this.write(file);
43
- }
44
- }
45
- /** 立即写入并清空缓存 */
46
- flush(file) {
47
- if (!this.#fs)
48
- return;
49
- this.#map.forEach((set, key) => {
50
- if (!set)
51
- return;
52
- if ((file === null && key === this.defaultLogFile) || !file || key === file) {
53
- const list = Array.from(set);
54
- set.clear();
55
- this.#writeLogFile(key, list);
56
- this.lastWrite = Date.now();
57
- }
58
- });
59
- }
60
- /** 延迟写入并清空缓存 */
61
- write = (0, lodash_1.debounce)((file) => this.flush(file), 1000);
62
- /** 检查日志文件的路径,如果目录不存在,则创建,最好返回有效的日志文件,如果文件已存在,则追加日志数据 */
63
- #checkFolder(output) {
64
- const paths = this.#fs?.dirname?.(output || this.defaultLogFile) || '';
65
- const { existsSync, mkdirSync } = this.#fs || {};
66
- if (!existsSync?.(paths)) {
67
- mkdirSync?.(paths);
68
- }
69
- }
70
- #writeLogFile(outputFile, content) {
71
- if (!(0, type_1.isArray)(content)) {
72
- content = [content];
73
- }
74
- outputFile = outputFile || this.defaultLogFile;
75
- this.#checkFolder(outputFile);
76
- const { writeFile } = this.#fs || {};
77
- if (outputFile && writeFile) {
78
- const list = content.reduce((o, { prefix = [], data }) => [...o, [...prefix, ...data.map(JSON.stringify), '\n'].join(' ')], []);
79
- writeFile?.(outputFile, list.join(''), { flag: 'a' }, noop_1.default);
80
- }
81
- }
82
- }
83
- exports.LogCache = LogCache;
@@ -1,2 +0,0 @@
1
- import { ILogOptions } from '../interface';
2
- export declare const defOptions: ILogOptions;
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defOptions = void 0;
4
- const interface_1 = require("../interface");
5
- exports.defOptions = {
6
- date: true,
7
- env: interface_1.LogMode.ALL,
8
- };
package/lib/index.js DELETED
@@ -1,49 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.loggerWithTags = void 0;
4
- const cache_1 = require("./cache");
5
- const defOptions_1 = require("./consts/defOptions");
6
- const interface_1 = require("./interface");
7
- const buildLogPreffix_1 = require("./utils/buildLogPreffix");
8
- const checkLogMode_1 = require("./utils/checkLogMode");
9
- const type_1 = require("./utils/type");
10
- const loggerWithTags = (tags, options) => {
11
- if (!(0, type_1.isArray)(tags)) {
12
- tags = [tags];
13
- }
14
- const { env, outputFile, ...mergedOptions } = { ...defOptions_1.defOptions, ...(options || {}) };
15
- const debug = (...rest) => {
16
- const prefix = (0, buildLogPreffix_1.buildLogPreffix)(tags, { level: interface_1.LogLevel.DEBUG, ...mergedOptions });
17
- (0, checkLogMode_1.checkLogMode)(env || interface_1.LogMode.ALL) && console.debug(...prefix, ...rest);
18
- cache_1.LogCache.cache.push({ prefix, timestamp: Date.now(), data: [...rest] }, outputFile);
19
- };
20
- const info = (...rest) => {
21
- const prefix = (0, buildLogPreffix_1.buildLogPreffix)(tags, { level: interface_1.LogLevel.INFO, ...mergedOptions });
22
- (0, checkLogMode_1.checkLogMode)(env || interface_1.LogMode.ALL) && console.info(...prefix, ...rest);
23
- cache_1.LogCache.cache.push({ prefix, timestamp: Date.now(), data: [...rest] }, outputFile);
24
- };
25
- const log = (...rest) => {
26
- const prefix = (0, buildLogPreffix_1.buildLogPreffix)(tags, mergedOptions);
27
- (0, checkLogMode_1.checkLogMode)(env || interface_1.LogMode.ALL) && console.log(...prefix, ...rest);
28
- cache_1.LogCache.cache.push({ prefix, timestamp: Date.now(), data: [...rest] }, outputFile);
29
- };
30
- const warn = (...rest) => {
31
- const prefix = (0, buildLogPreffix_1.buildLogPreffix)(tags, { level: interface_1.LogLevel.WARN, ...mergedOptions });
32
- const { disableError } = mergedOptions;
33
- const out = disableError ? console.debug : console.warn;
34
- (0, checkLogMode_1.checkLogMode)(env || interface_1.LogMode.ALL) && out(...prefix, ...rest);
35
- cache_1.LogCache.cache.push({ prefix, timestamp: Date.now(), data: [...rest] }, outputFile);
36
- };
37
- const error = (msg, cause) => {
38
- const prefix = (0, buildLogPreffix_1.buildLogPreffix)(tags, { level: interface_1.LogLevel.ERROR, ...mergedOptions });
39
- const { ignoreThrow, disableError } = mergedOptions;
40
- const out = disableError ? console.debug : console.error;
41
- (0, checkLogMode_1.checkLogMode)(env || interface_1.LogMode.ALL) && out(...prefix, msg);
42
- cache_1.LogCache.cache.push({ prefix, timestamp: Date.now(), data: [msg] }, outputFile);
43
- if (!ignoreThrow) {
44
- throw new Error(msg, { cause });
45
- }
46
- };
47
- return { debug, info, log, warn, error };
48
- };
49
- exports.loggerWithTags = loggerWithTags;
@@ -1,84 +0,0 @@
1
- /// <reference types="node" />
2
- export type PathLike = string | Buffer | URL;
3
- /**
4
- * 日志输出打印的模式
5
- * @default LogMode.ALL
6
- */
7
- export declare enum LogMode {
8
- ALL = "all",
9
- PRODUCTION = "production",
10
- DEVELOPMENET = "development",
11
- NONE = "none"
12
- }
13
- /**
14
- * 日志级别
15
- */
16
- export declare enum LogLevel {
17
- LOG = "LOG",
18
- WARN = "WARN",
19
- INFO = "INFO",
20
- ERROR = "ERROR",
21
- DEBUG = "DEBUG"
22
- }
23
- /** 日志标签 */
24
- export type LogTags = string | string[];
25
- /** 日志配置选项 */
26
- export interface ILogOptions {
27
- /** 日志级别
28
- * @default LogLevel.LOG
29
- */
30
- level?: LogLevel;
31
- /**
32
- * 是否支持输出时间戳及时间戳格式
33
- *
34
- * 字符串格式参见: https://github.com/date-fns/date-fns/blob/main/src/format/index.ts
35
- * @default true 开启后默认IOS格式 'yyyy-MM-ddTHH:mm:ss.SSSZ'
36
- */
37
- date?: boolean | string;
38
- /**
39
- * 日志输出条件,默认全部输出
40
- * @default 'all'
41
- */
42
- env?: LogMode;
43
- /** 禁用warn输出,避免在测试场景下影响测试结果
44
- * @default false
45
- */
46
- disableWarn?: boolean;
47
- /** 禁用error输出,避免在测试场景下打断正常测试流程
48
- * @default false
49
- */
50
- disableError?: boolean;
51
- /** 调用error输出错误信息后,禁止继续抛出异常错误
52
- * @description
53
- * 调用error输出错误信息后,默认继续抛出异常错误,在测试环境下可以临地禁用,避免影响正常的测试流程
54
- */
55
- ignoreThrow?: boolean;
56
- /**
57
- * 基于当前工程根目录下的日志输出文件
58
- *
59
- * @description
60
- * 浏览器环境:自动忽略该选项;
61
- *
62
- * node环境下默认 logs/xxx.log
63
- */
64
- outputFile?: string;
65
- }
66
- export interface IFileHelper {
67
- existsSync?: (path: PathLike) => boolean;
68
- mkdirSync?: (path: PathLike, options?: {
69
- mode?: number | string | undefined;
70
- recursive: true;
71
- }) => string | undefined;
72
- writeFile?: CallableFunction;
73
- join?: (...paths: string[]) => string;
74
- sep?: '\\' | '/';
75
- resolve?: (...paths: string[]) => string;
76
- dirname?: (fn: string) => string;
77
- }
78
- export interface ILogger {
79
- debug: (...rest: any[]) => void;
80
- info: (...rest: any[]) => void;
81
- log: (...rest: any[]) => void;
82
- warn: (...rest: any[]) => void;
83
- error: (msg: string) => void;
84
- }
package/lib/interface.js DELETED
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LogLevel = exports.LogMode = void 0;
4
- /**
5
- * 日志输出打印的模式
6
- * @default LogMode.ALL
7
- */
8
- var LogMode;
9
- (function (LogMode) {
10
- LogMode["ALL"] = "all";
11
- LogMode["PRODUCTION"] = "production";
12
- LogMode["DEVELOPMENET"] = "development";
13
- LogMode["NONE"] = "none";
14
- })(LogMode = exports.LogMode || (exports.LogMode = {}));
15
- /**
16
- * 日志级别
17
- */
18
- var LogLevel;
19
- (function (LogLevel) {
20
- LogLevel["LOG"] = "LOG";
21
- LogLevel["WARN"] = "WARN";
22
- LogLevel["INFO"] = "INFO";
23
- LogLevel["ERROR"] = "ERROR";
24
- LogLevel["DEBUG"] = "DEBUG";
25
- })(LogLevel = exports.LogLevel || (exports.LogLevel = {}));
@@ -1,2 +0,0 @@
1
- import { ILogOptions } from '../interface';
2
- export declare const buildLogPreffix: (tags: string[], options: ILogOptions) => any[];
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildLogPreffix = void 0;
4
- const date_fns_1 = require("date-fns");
5
- const interface_1 = require("../interface");
6
- const type_1 = require("./type");
7
- const buildLogPreffix = (tags, options) => {
8
- const { level = interface_1.LogLevel.LOG, date } = options;
9
- const prefix = [];
10
- if (tags.length) {
11
- prefix.unshift(tags.map((t) => `[${t.toUpperCase()}]`).join(' '));
12
- }
13
- if (date) {
14
- const now = new Date();
15
- let dtStr;
16
- if ((0, type_1.isString)(date)) {
17
- dtStr = (0, date_fns_1.format)(now, date);
18
- }
19
- else {
20
- dtStr = new Date(now).toISOString();
21
- }
22
- prefix.unshift(dtStr);
23
- }
24
- prefix.unshift(`[${level}]\t`);
25
- return prefix;
26
- };
27
- exports.buildLogPreffix = buildLogPreffix;
@@ -1,2 +0,0 @@
1
- import { LogMode } from '../interface';
2
- export declare const checkLogMode: (env: LogMode) => boolean;
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkLogMode = void 0;
4
- const checkLogMode = (env) => (env === 'all' || process.env.NODE_ENV === env) && console !== undefined;
5
- exports.checkLogMode = checkLogMode;
@@ -1,6 +0,0 @@
1
- import { IFileHelper } from '../interface';
2
- /**
3
- * 检查当前运行环境,node环境下返回node的fs模块,浏览器环境返回null
4
- * @returns fs
5
- */
6
- export declare const checkPlatform: () => Promise<IFileHelper | null>;
@@ -1,47 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.checkPlatform = void 0;
27
- /**
28
- * 检查当前运行环境,node环境下返回node的fs模块,浏览器环境返回null
29
- * @returns fs
30
- */
31
- const checkPlatform = () => Promise.all([Promise.resolve().then(() => __importStar(require('fs'))), Promise.resolve().then(() => __importStar(require('path')))]).then(([fs, path]) => {
32
- // 如果fs为空则判定当前为浏览器环境
33
- if (!fs)
34
- return null;
35
- const { existsSync, mkdirSync, writeFile } = fs;
36
- const { sep, resolve, join, dirname } = path;
37
- return {
38
- existsSync,
39
- mkdirSync,
40
- writeFile,
41
- join,
42
- sep,
43
- resolve,
44
- dirname,
45
- };
46
- });
47
- exports.checkPlatform = checkPlatform;
@@ -1,2 +0,0 @@
1
- declare const _default: () => undefined;
2
- export default _default;
package/lib/utils/noop.js DELETED
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = () => void 0;
@@ -1,3 +0,0 @@
1
- export declare const isUndefined: (v: any) => boolean;
2
- export declare const isString: (v: any) => boolean;
3
- export declare const isArray: (arg: any) => arg is any[];
package/lib/utils/type.js DELETED
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isArray = exports.isString = exports.isUndefined = void 0;
4
- const toString = (v) => Object.prototype.toString.call(v);
5
- const isUndefined = (v) => v === undefined;
6
- exports.isUndefined = isUndefined;
7
- const isString = (v) => typeof v === 'string' || toString(v) === '[object String]';
8
- exports.isString = isString;
9
- exports.isArray = Array.isArray;
@@ -1,2 +0,0 @@
1
- import { LogContent } from '../interface';
2
- export declare const writeLogFile: (writer: any, data: LogContent) => void;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.writeLogFile = void 0;
7
- const date_fns_1 = require("date-fns");
8
- const noop_1 = __importDefault(require("./noop"));
9
- const writeLogFile = (writer, data) => writer?.(`logs/${(0, date_fns_1.format)(Date.now(), 'yyyy-MM-dd')}.log`, data.map(JSON.stringify).join(' ') + '\n', { flag: 'a' }, noop_1.default);
10
- exports.writeLogFile = writeLogFile;
package/lib/utils.d.ts DELETED
@@ -1,8 +0,0 @@
1
- /// <reference types="node" />
2
- import { ILogOptions, LogMode } from './interface';
3
- export declare const isUndefined: (v: any) => boolean;
4
- export declare const isString: (v: any) => boolean;
5
- export declare const buildOutputPreffix: (tags: string[], options: ILogOptions) => (string | Date)[];
6
- export declare const checkEnv: (env: LogMode) => boolean;
7
- export declare const checkPlatform: () => Promise<typeof import("fs").writeFile>;
8
- export declare const noop: () => undefined;
package/lib/utils.js DELETED
@@ -1,57 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.noop = exports.checkPlatform = exports.checkEnv = exports.buildOutputPreffix = exports.isString = exports.isUndefined = void 0;
27
- const date_fns_1 = require("date-fns");
28
- const toString = (v) => Object.prototype.toString.call(v);
29
- const isUndefined = (v) => v === undefined;
30
- exports.isUndefined = isUndefined;
31
- const isString = (v) => typeof v === 'string' || toString(v) === '[object String]';
32
- exports.isString = isString;
33
- const buildOutputPreffix = (tags, options) => {
34
- const prefix = [];
35
- const { date } = options;
36
- if (date) {
37
- let now = new Date();
38
- if ((0, exports.isString)(date)) {
39
- now = (0, date_fns_1.format)(now, date);
40
- }
41
- prefix.unshift(now);
42
- }
43
- if (tags.length) {
44
- prefix.unshift(tags.map((t) => `[${t.toUpperCase()}]`).join(' '));
45
- }
46
- return prefix;
47
- };
48
- exports.buildOutputPreffix = buildOutputPreffix;
49
- const checkEnv = (env) => (env === 'all' || process.env.NODE_ENV === env) && console !== undefined;
50
- exports.checkEnv = checkEnv;
51
- const checkPlatform = () => Promise.resolve().then(() => __importStar(require('fs'))).then((fs) => {
52
- // fs.opendir('logs')
53
- return fs?.writeFile;
54
- });
55
- exports.checkPlatform = checkPlatform;
56
- const noop = () => void 0;
57
- exports.noop = noop;