llonebot-dist 7.0.1 → 7.1.1
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/llonebot.js +2336 -10459
- package/llonebot.js.map +1 -1
- package/node_modules/cosmokit/LICENSE +21 -0
- package/node_modules/cosmokit/README.md +24 -0
- package/node_modules/cosmokit/lib/index.cjs +463 -0
- package/node_modules/cosmokit/lib/index.cjs.map +6 -0
- package/node_modules/cosmokit/lib/index.d.ts +142 -0
- package/node_modules/cosmokit/lib/index.mjs +403 -0
- package/node_modules/cosmokit/lib/index.mjs.map +6 -0
- package/node_modules/cosmokit/package.json +56 -0
- package/node_modules/cosmokit/src/array.ts +35 -0
- package/node_modules/cosmokit/src/index.ts +5 -0
- package/node_modules/cosmokit/src/misc.ts +57 -0
- package/node_modules/cosmokit/src/string.ts +101 -0
- package/node_modules/cosmokit/src/time.ts +91 -0
- package/node_modules/cosmokit/src/types.ts +129 -0
- package/node_modules/has-flag/index.d.ts +39 -0
- package/node_modules/has-flag/index.js +8 -0
- package/node_modules/has-flag/license +9 -0
- package/node_modules/has-flag/package.json +46 -0
- package/node_modules/has-flag/readme.md +89 -0
- package/node_modules/object-inspect/CHANGELOG.md +424 -0
- package/node_modules/object-inspect/LICENSE +21 -0
- package/node_modules/object-inspect/example/all.js +23 -0
- package/node_modules/object-inspect/example/circular.js +6 -0
- package/node_modules/object-inspect/example/fn.js +5 -0
- package/node_modules/object-inspect/example/inspect.js +10 -0
- package/node_modules/object-inspect/index.js +544 -0
- package/node_modules/object-inspect/package-support.json +20 -0
- package/node_modules/object-inspect/package.json +105 -0
- package/node_modules/object-inspect/readme.markdown +84 -0
- package/node_modules/object-inspect/test/bigint.js +58 -0
- package/node_modules/object-inspect/test/browser/dom.js +15 -0
- package/node_modules/object-inspect/test/circular.js +16 -0
- package/node_modules/object-inspect/test/deep.js +12 -0
- package/node_modules/object-inspect/test/element.js +53 -0
- package/node_modules/object-inspect/test/err.js +48 -0
- package/node_modules/object-inspect/test/fakes.js +29 -0
- package/node_modules/object-inspect/test/fn.js +76 -0
- package/node_modules/object-inspect/test/global.js +17 -0
- package/node_modules/object-inspect/test/has.js +15 -0
- package/node_modules/object-inspect/test/holes.js +15 -0
- package/node_modules/object-inspect/test/indent-option.js +271 -0
- package/node_modules/object-inspect/test/inspect.js +139 -0
- package/node_modules/object-inspect/test/lowbyte.js +12 -0
- package/node_modules/object-inspect/test/number.js +58 -0
- package/node_modules/object-inspect/test/quoteStyle.js +26 -0
- package/node_modules/object-inspect/test/toStringTag.js +40 -0
- package/node_modules/object-inspect/test/undef.js +12 -0
- package/node_modules/object-inspect/test/values.js +261 -0
- package/node_modules/object-inspect/test-core-js.js +26 -0
- package/node_modules/object-inspect/util.inspect.js +1 -0
- package/node_modules/reggol/LICENSE +21 -0
- package/node_modules/reggol/README.md +8 -0
- package/node_modules/reggol/index.d.ts +79 -0
- package/node_modules/reggol/lib/browser.mjs +299 -0
- package/node_modules/reggol/lib/node.js +31 -0
- package/node_modules/reggol/lib/shared.js +258 -0
- package/node_modules/reggol/lib/shared.mjs +266 -0
- package/node_modules/reggol/node_modules/supports-color/browser.js +24 -0
- package/node_modules/reggol/node_modules/supports-color/index.js +152 -0
- package/node_modules/reggol/node_modules/supports-color/license +9 -0
- package/node_modules/reggol/node_modules/supports-color/package.json +58 -0
- package/node_modules/reggol/node_modules/supports-color/readme.md +77 -0
- package/node_modules/reggol/package.json +65 -0
- package/node_modules/reggol/src/browser.ts +8 -0
- package/node_modules/reggol/src/index.ts +3 -0
- package/node_modules/reggol/src/node.ts +8 -0
- package/node_modules/reggol/src/shared.ts +249 -0
- package/node_modules/supports-color/browser.d.ts +1 -0
- package/node_modules/supports-color/browser.js +35 -0
- package/node_modules/supports-color/index.d.ts +55 -0
- package/node_modules/supports-color/index.js +202 -0
- package/node_modules/supports-color/license +9 -0
- package/node_modules/supports-color/package.json +64 -0
- package/node_modules/supports-color/readme.md +75 -0
- package/package.json +1 -1
- package/webui/assets/index-CO7Tbtyt.css +1 -0
- package/webui/assets/index-D7SfQ8t3.js +308 -0
- package/webui/favicon.ico +0 -0
- package/webui/index.html +2 -2
- package//344/275/277/347/224/250/350/257/264/346/230/216.txt +2 -2
- package//346/233/264/346/226/260/346/227/245/345/277/227.txt +24 -0
- package/webui/assets/index-DH65Wt1j.css +0 -1
- package/webui/assets/index-fRyBxWld.js +0 -273
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const os = require('os');
|
|
3
|
+
const tty = require('tty');
|
|
4
|
+
const hasFlag = require('has-flag');
|
|
5
|
+
|
|
6
|
+
const {env} = process;
|
|
7
|
+
|
|
8
|
+
let flagForceColor;
|
|
9
|
+
if (hasFlag('no-color') ||
|
|
10
|
+
hasFlag('no-colors') ||
|
|
11
|
+
hasFlag('color=false') ||
|
|
12
|
+
hasFlag('color=never')) {
|
|
13
|
+
flagForceColor = 0;
|
|
14
|
+
} else if (hasFlag('color') ||
|
|
15
|
+
hasFlag('colors') ||
|
|
16
|
+
hasFlag('color=true') ||
|
|
17
|
+
hasFlag('color=always')) {
|
|
18
|
+
flagForceColor = 1;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function envForceColor() {
|
|
22
|
+
if ('FORCE_COLOR' in env) {
|
|
23
|
+
if (env.FORCE_COLOR === 'true') {
|
|
24
|
+
return 1;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (env.FORCE_COLOR === 'false') {
|
|
28
|
+
return 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function translateLevel(level) {
|
|
36
|
+
if (level === 0) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
level,
|
|
42
|
+
hasBasic: true,
|
|
43
|
+
has256: level >= 2,
|
|
44
|
+
has16m: level >= 3
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {
|
|
49
|
+
const noFlagForceColor = envForceColor();
|
|
50
|
+
if (noFlagForceColor !== undefined) {
|
|
51
|
+
flagForceColor = noFlagForceColor;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
|
|
55
|
+
|
|
56
|
+
if (forceColor === 0) {
|
|
57
|
+
return 0;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (sniffFlags) {
|
|
61
|
+
if (hasFlag('color=16m') ||
|
|
62
|
+
hasFlag('color=full') ||
|
|
63
|
+
hasFlag('color=truecolor')) {
|
|
64
|
+
return 3;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (hasFlag('color=256')) {
|
|
68
|
+
return 2;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (haveStream && !streamIsTTY && forceColor === undefined) {
|
|
73
|
+
return 0;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const min = forceColor || 0;
|
|
77
|
+
|
|
78
|
+
if (env.TERM === 'dumb') {
|
|
79
|
+
return min;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (process.platform === 'win32') {
|
|
83
|
+
// Windows 10 build 10586 is the first Windows release that supports 256 colors.
|
|
84
|
+
// Windows 10 build 14931 is the first release that supports 16m/TrueColor.
|
|
85
|
+
const osRelease = os.release().split('.');
|
|
86
|
+
if (
|
|
87
|
+
Number(osRelease[0]) >= 10 &&
|
|
88
|
+
Number(osRelease[2]) >= 10586
|
|
89
|
+
) {
|
|
90
|
+
return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return 1;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if ('CI' in env) {
|
|
97
|
+
if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI', 'GITHUB_ACTIONS', 'BUILDKITE', 'DRONE'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
|
|
98
|
+
return 1;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return min;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if ('TEAMCITY_VERSION' in env) {
|
|
105
|
+
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (env.COLORTERM === 'truecolor') {
|
|
109
|
+
return 3;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if ('TERM_PROGRAM' in env) {
|
|
113
|
+
const version = Number.parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
|
|
114
|
+
|
|
115
|
+
switch (env.TERM_PROGRAM) {
|
|
116
|
+
case 'iTerm.app':
|
|
117
|
+
return version >= 3 ? 3 : 2;
|
|
118
|
+
case 'Apple_Terminal':
|
|
119
|
+
return 2;
|
|
120
|
+
// No default
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (/-256(color)?$/i.test(env.TERM)) {
|
|
125
|
+
return 2;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
|
129
|
+
return 1;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if ('COLORTERM' in env) {
|
|
133
|
+
return 1;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return min;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function getSupportLevel(stream, options = {}) {
|
|
140
|
+
const level = supportsColor(stream, {
|
|
141
|
+
streamIsTTY: stream && stream.isTTY,
|
|
142
|
+
...options
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
return translateLevel(level);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
module.exports = {
|
|
149
|
+
supportsColor: getSupportLevel,
|
|
150
|
+
stdout: getSupportLevel({isTTY: tty.isatty(1)}),
|
|
151
|
+
stderr: getSupportLevel({isTTY: tty.isatty(2)})
|
|
152
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "supports-color",
|
|
3
|
+
"version": "8.1.1",
|
|
4
|
+
"description": "Detect whether a terminal supports color",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": "chalk/supports-color",
|
|
7
|
+
"funding": "https://github.com/chalk/supports-color?sponsor=1",
|
|
8
|
+
"author": {
|
|
9
|
+
"name": "Sindre Sorhus",
|
|
10
|
+
"email": "sindresorhus@gmail.com",
|
|
11
|
+
"url": "https://sindresorhus.com"
|
|
12
|
+
},
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=10"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"test": "xo && ava"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"index.js",
|
|
21
|
+
"browser.js"
|
|
22
|
+
],
|
|
23
|
+
"exports": {
|
|
24
|
+
"node": "./index.js",
|
|
25
|
+
"default": "./browser.js"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"color",
|
|
29
|
+
"colour",
|
|
30
|
+
"colors",
|
|
31
|
+
"terminal",
|
|
32
|
+
"console",
|
|
33
|
+
"cli",
|
|
34
|
+
"ansi",
|
|
35
|
+
"styles",
|
|
36
|
+
"tty",
|
|
37
|
+
"rgb",
|
|
38
|
+
"256",
|
|
39
|
+
"shell",
|
|
40
|
+
"xterm",
|
|
41
|
+
"command-line",
|
|
42
|
+
"support",
|
|
43
|
+
"supports",
|
|
44
|
+
"capability",
|
|
45
|
+
"detect",
|
|
46
|
+
"truecolor",
|
|
47
|
+
"16m"
|
|
48
|
+
],
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"has-flag": "^4.0.0"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"ava": "^2.4.0",
|
|
54
|
+
"import-fresh": "^3.2.2",
|
|
55
|
+
"xo": "^0.35.0"
|
|
56
|
+
},
|
|
57
|
+
"browser": "browser.js"
|
|
58
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# supports-color
|
|
2
|
+
|
|
3
|
+
> Detect whether a terminal supports color
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
$ npm install supports-color
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
const supportsColor = require('supports-color');
|
|
15
|
+
|
|
16
|
+
if (supportsColor.stdout) {
|
|
17
|
+
console.log('Terminal stdout supports color');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (supportsColor.stdout.has256) {
|
|
21
|
+
console.log('Terminal stdout supports 256 colors');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (supportsColor.stderr.has16m) {
|
|
25
|
+
console.log('Terminal stderr supports 16 million colors (truecolor)');
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## API
|
|
30
|
+
|
|
31
|
+
Returns an `Object` with a `stdout` and `stderr` property for testing either streams. Each property is an `Object`, or `false` if color is not supported.
|
|
32
|
+
|
|
33
|
+
The `stdout`/`stderr` objects specifies a level of support for color through a `.level` property and a corresponding flag:
|
|
34
|
+
|
|
35
|
+
- `.level = 1` and `.hasBasic = true`: Basic color support (16 colors)
|
|
36
|
+
- `.level = 2` and `.has256 = true`: 256 color support
|
|
37
|
+
- `.level = 3` and `.has16m = true`: Truecolor support (16 million colors)
|
|
38
|
+
|
|
39
|
+
### `require('supports-color').supportsColor(stream, options?)`
|
|
40
|
+
|
|
41
|
+
Additionally, `supports-color` exposes the `.supportsColor()` function that takes an arbitrary write stream (e.g. `process.stdout`) and an optional options object to (re-)evaluate color support for an arbitrary stream.
|
|
42
|
+
|
|
43
|
+
For example, `require('supports-color').stdout` is the equivalent of `require('supports-color').supportsColor(process.stdout)`.
|
|
44
|
+
|
|
45
|
+
The options object supports a single boolean property `sniffFlags`. By default it is `true`, which instructs `supportsColor()` to sniff `process.argv` for the multitude of `--color` flags (see _Info_ below). If `false`, then `process.argv` is not considered when determining color support.
|
|
46
|
+
|
|
47
|
+
## Info
|
|
48
|
+
|
|
49
|
+
It obeys the `--color` and `--no-color` CLI flags.
|
|
50
|
+
|
|
51
|
+
For situations where using `--color` is not possible, use the environment variable `FORCE_COLOR=1` (level 1), `FORCE_COLOR=2` (level 2), or `FORCE_COLOR=3` (level 3) to forcefully enable color, or `FORCE_COLOR=0` to forcefully disable. The use of `FORCE_COLOR` overrides all other color support checks.
|
|
52
|
+
|
|
53
|
+
Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=16m` flags, respectively.
|
|
54
|
+
|
|
55
|
+
## Related
|
|
56
|
+
|
|
57
|
+
- [supports-color-cli](https://github.com/chalk/supports-color-cli) - CLI for this module
|
|
58
|
+
- [chalk](https://github.com/chalk/chalk) - Terminal string styling done right
|
|
59
|
+
|
|
60
|
+
## Maintainers
|
|
61
|
+
|
|
62
|
+
- [Sindre Sorhus](https://github.com/sindresorhus)
|
|
63
|
+
- [Josh Junon](https://github.com/qix-)
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
<div align="center">
|
|
68
|
+
<b>
|
|
69
|
+
<a href="https://tidelift.com/subscription/pkg/npm-supports-color?utm_source=npm-supports-color&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
|
|
70
|
+
</b>
|
|
71
|
+
<br>
|
|
72
|
+
<sub>
|
|
73
|
+
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
|
74
|
+
</sub>
|
|
75
|
+
</div>
|
|
76
|
+
|
|
77
|
+
---
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "reggol",
|
|
3
|
+
"description": "Logger for professionals",
|
|
4
|
+
"version": "1.7.1",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"main": "lib/node.js",
|
|
7
|
+
"types": "index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"node": "./lib/node.js",
|
|
11
|
+
"browser": "./lib/browser.mjs",
|
|
12
|
+
"types": "./index.d.ts"
|
|
13
|
+
},
|
|
14
|
+
"./shared": {
|
|
15
|
+
"require": "./lib/shared.js",
|
|
16
|
+
"import": "./lib/shared.mjs"
|
|
17
|
+
},
|
|
18
|
+
"./package.json": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"lib",
|
|
22
|
+
"src",
|
|
23
|
+
"index.d.ts"
|
|
24
|
+
],
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/shigma/reggol.git"
|
|
28
|
+
},
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/shigma/reggol/issues"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://github.com/shigma/reggol",
|
|
33
|
+
"author": "Shigma <shigma10826@gmail.com>",
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build:node": "esbuild src/node.ts --outfile=lib/node.cjs --bundle --sourcemap --sources-content=false --platform=node --external:cosmokit --external:supports-color --target=es2022",
|
|
37
|
+
"build:browser": "esbuild src/browser.ts --outfile=lib/browser.mjs --bundle --sourcemap --sources-content=false --platform=browser --external:cosmokit --external:supports-color --target=es2022",
|
|
38
|
+
"build": "yarn build:node && yarn build:browser && yarn tsc -b",
|
|
39
|
+
"test": "mocha -r esbuild-register tests/*.spec.ts",
|
|
40
|
+
"test:text": "shx rm -rf coverage && c8 -r text yarn test",
|
|
41
|
+
"test:json": "shx rm -rf coverage && c8 -r json yarn test",
|
|
42
|
+
"test:html": "shx rm -rf coverage && c8 -r html yarn test"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@sinonjs/fake-timers": "^6.0.1",
|
|
46
|
+
"@types/chai": "^4.3.16",
|
|
47
|
+
"@types/mocha": "^9.1.1",
|
|
48
|
+
"@types/node": "^22.1.0",
|
|
49
|
+
"@types/object-inspect": "^1.8.4",
|
|
50
|
+
"@types/sinonjs__fake-timers": "^6.0.4",
|
|
51
|
+
"@types/supports-color": "^8.1.3",
|
|
52
|
+
"c8": "^7.14.0",
|
|
53
|
+
"chai": "^5.1.1",
|
|
54
|
+
"esbuild": "^0.23.1",
|
|
55
|
+
"esbuild-register": "^3.5.0",
|
|
56
|
+
"mocha": "^9.2.2",
|
|
57
|
+
"shx": "^0.3.4",
|
|
58
|
+
"typescript": "^5.5.3"
|
|
59
|
+
},
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"cosmokit": "^1.6.3",
|
|
62
|
+
"object-inspect": "^1.13.1",
|
|
63
|
+
"supports-color": "^8.1.1"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { stdout } from 'supports-color'
|
|
2
|
+
import { Time } from 'cosmokit'
|
|
3
|
+
|
|
4
|
+
const c16 = [6, 2, 3, 4, 5, 1]
|
|
5
|
+
const c256 = [
|
|
6
|
+
20, 21, 26, 27, 32, 33, 38, 39, 40, 41, 42, 43, 44, 45, 56, 57, 62,
|
|
7
|
+
63, 68, 69, 74, 75, 76, 77, 78, 79, 80, 81, 92, 93, 98, 99, 112, 113,
|
|
8
|
+
129, 134, 135, 148, 149, 160, 161, 162, 163, 164, 165, 166, 167, 168,
|
|
9
|
+
169, 170, 171, 172, 173, 178, 179, 184, 185, 196, 197, 198, 199, 200,
|
|
10
|
+
201, 202, 203, 204, 205, 206, 207, 208, 209, 214, 215, 220, 221,
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
function isAggregateError(error: any): error is Error & { errors: Error[] } {
|
|
14
|
+
return error instanceof Error && Array.isArray((error as any)['errors'])
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
namespace Logger {
|
|
18
|
+
export interface LevelConfig {
|
|
19
|
+
base: number
|
|
20
|
+
[K: string]: Level
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type Level = number | LevelConfig
|
|
24
|
+
export type Function = (format: any, ...param: any[]) => void
|
|
25
|
+
export type Type = 'success' | 'error' | 'info' | 'warn' | 'debug'
|
|
26
|
+
export type Formatter = (value: any, target: Target, logger: Logger) => any
|
|
27
|
+
|
|
28
|
+
export interface LabelStyle {
|
|
29
|
+
width?: number
|
|
30
|
+
margin?: number
|
|
31
|
+
align?: 'left' | 'right'
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface Record {
|
|
35
|
+
id: number
|
|
36
|
+
meta: any
|
|
37
|
+
name: string
|
|
38
|
+
type: Type
|
|
39
|
+
level: number
|
|
40
|
+
content: string
|
|
41
|
+
timestamp: number
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface Target {
|
|
45
|
+
/**
|
|
46
|
+
* - 0: no color support
|
|
47
|
+
* - 1: 16 color support
|
|
48
|
+
* - 2: 256 color support
|
|
49
|
+
* - 3: truecolor support
|
|
50
|
+
*/
|
|
51
|
+
colors?: false | number
|
|
52
|
+
showDiff?: boolean
|
|
53
|
+
showTime?: string
|
|
54
|
+
label?: LabelStyle
|
|
55
|
+
maxLength?: number
|
|
56
|
+
record?(record: Record): void
|
|
57
|
+
print?(text: string): void
|
|
58
|
+
levels?: LevelConfig
|
|
59
|
+
timestamp?: number
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
interface Logger extends Record<Logger.Type, Logger.Function> {}
|
|
64
|
+
|
|
65
|
+
class Logger {
|
|
66
|
+
// log levels
|
|
67
|
+
static readonly SILENT = 0
|
|
68
|
+
static readonly SUCCESS = 1
|
|
69
|
+
static readonly ERROR = 1
|
|
70
|
+
static readonly INFO = 2
|
|
71
|
+
static readonly WARN = 2
|
|
72
|
+
static readonly DEBUG = 3
|
|
73
|
+
|
|
74
|
+
// global config
|
|
75
|
+
static id = 0
|
|
76
|
+
static targets: Logger.Target[] = [{
|
|
77
|
+
colors: stdout && stdout.level,
|
|
78
|
+
print(text) {
|
|
79
|
+
console.log(text)
|
|
80
|
+
},
|
|
81
|
+
}]
|
|
82
|
+
|
|
83
|
+
// global registry
|
|
84
|
+
static formatters: Record<string, Logger.Formatter> = Object.create(null)
|
|
85
|
+
|
|
86
|
+
static format(name: string, formatter: Logger.Formatter) {
|
|
87
|
+
this.formatters[name] = formatter
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
static levels: Logger.LevelConfig = {
|
|
91
|
+
base: 2,
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
static color(target: Logger.Target, code: number, value: any, decoration = '') {
|
|
95
|
+
if (!target.colors) return '' + value
|
|
96
|
+
return `\u001b[3${code < 8 ? code : '8;5;' + code}${target.colors >= 2 ? decoration : ''}m${value}\u001b[0m`
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
static code(name: string, target: Logger.Target) {
|
|
100
|
+
let hash = 0
|
|
101
|
+
for (let i = 0; i < name.length; i++) {
|
|
102
|
+
hash = ((hash << 3) - hash) + name.charCodeAt(i) + 13
|
|
103
|
+
hash |= 0
|
|
104
|
+
}
|
|
105
|
+
const colors = !target.colors ? [] : target.colors >= 2 ? c256 : c16
|
|
106
|
+
return colors[Math.abs(hash) % colors.length]
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
static render(target: Logger.Target, record: Logger.Record) {
|
|
110
|
+
const prefix = `[${record.type[0].toUpperCase()}]`
|
|
111
|
+
const space = ' '.repeat(target.label?.margin ?? 1)
|
|
112
|
+
let indent = 3 + space.length, output = ''
|
|
113
|
+
if (target.showTime) {
|
|
114
|
+
indent += target.showTime.length + space.length
|
|
115
|
+
output += Logger.color(target, 8, Time.template(target.showTime)) + space
|
|
116
|
+
}
|
|
117
|
+
const code = Logger.code(record.name, target)
|
|
118
|
+
const label = Logger.color(target, code, record.name, ';1')
|
|
119
|
+
const padLength = (target.label?.width ?? 0) + label.length - record.name.length
|
|
120
|
+
if (target.label?.align === 'right') {
|
|
121
|
+
output += label.padStart(padLength) + space + prefix + space
|
|
122
|
+
indent += (target.label.width ?? 0) + space.length
|
|
123
|
+
} else {
|
|
124
|
+
output += prefix + space + label.padEnd(padLength) + space
|
|
125
|
+
}
|
|
126
|
+
output += record.content.replace(/\n/g, '\n' + ' '.repeat(indent))
|
|
127
|
+
if (target.showDiff && target.timestamp) {
|
|
128
|
+
const diff = record.timestamp - target.timestamp
|
|
129
|
+
output += Logger.color(target, code, ' +' + Time.format(diff))
|
|
130
|
+
}
|
|
131
|
+
return output
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
constructor(public name: string, public meta?: any) {
|
|
135
|
+
this.createMethod('success', Logger.SUCCESS)
|
|
136
|
+
this.createMethod('error', Logger.ERROR)
|
|
137
|
+
this.createMethod('info', Logger.INFO)
|
|
138
|
+
this.createMethod('warn', Logger.WARN)
|
|
139
|
+
this.createMethod('debug', Logger.DEBUG)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
extend = (namespace: string) => {
|
|
143
|
+
return new Logger(`${this.name}:${namespace}`, this.meta)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
warning = (format: any, ...args: any[]) => {
|
|
147
|
+
this.warn(format, ...args)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
createMethod(type: Logger.Type, level: number) {
|
|
151
|
+
this[type] = (...args) => {
|
|
152
|
+
if (args.length === 1 && args[0] instanceof Error) {
|
|
153
|
+
if (args[0].cause) {
|
|
154
|
+
this[type](args[0].cause)
|
|
155
|
+
} else if (isAggregateError(args[0])) {
|
|
156
|
+
args[0].errors.forEach(error => this[type](error))
|
|
157
|
+
return
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const id = ++Logger.id
|
|
162
|
+
const timestamp = Date.now()
|
|
163
|
+
for (const target of Logger.targets) {
|
|
164
|
+
if (this.getLevel(target) < level) continue
|
|
165
|
+
const content = this.format(target, ...args)
|
|
166
|
+
const record: Logger.Record = { id, type, level, name: this.name, meta: this.meta, content, timestamp }
|
|
167
|
+
if (target.record) {
|
|
168
|
+
target.record(record)
|
|
169
|
+
} else {
|
|
170
|
+
const { print = console.log } = target
|
|
171
|
+
print(Logger.render(target, record))
|
|
172
|
+
}
|
|
173
|
+
target.timestamp = timestamp
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
private format(target: Logger.Target, ...args: any[]) {
|
|
179
|
+
if (args[0] instanceof Error) {
|
|
180
|
+
args[0] = args[0].stack || args[0].message
|
|
181
|
+
args.unshift('%s')
|
|
182
|
+
} else if (typeof args[0] !== 'string') {
|
|
183
|
+
args.unshift('%o')
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
let format: string = args.shift()
|
|
187
|
+
format = format.replace(/%([a-zA-Z%])/g, (match, char) => {
|
|
188
|
+
if (match === '%%') return '%'
|
|
189
|
+
const formatter = Logger.formatters[char]
|
|
190
|
+
if (typeof formatter === 'function') {
|
|
191
|
+
const value = args.shift()
|
|
192
|
+
return formatter(value, target, this)
|
|
193
|
+
}
|
|
194
|
+
return match
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
for (let arg of args) {
|
|
198
|
+
if (typeof arg === 'object' && arg) {
|
|
199
|
+
arg = Logger.formatters['o'](arg, target, this)
|
|
200
|
+
}
|
|
201
|
+
format += ' ' + arg
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const { maxLength = 10240 } = target
|
|
205
|
+
return format.split(/\r?\n/g).map(line => {
|
|
206
|
+
return line.slice(0, maxLength) + (line.length > maxLength ? '...' : '')
|
|
207
|
+
}).join('\n')
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
getLevel(target?: Logger.Target) {
|
|
211
|
+
const paths = this.name.split(':')
|
|
212
|
+
let config: Logger.Level = target?.levels || Logger.levels
|
|
213
|
+
do {
|
|
214
|
+
config = config[paths.shift()!] ?? config['base']
|
|
215
|
+
} while (paths.length && typeof config === 'object')
|
|
216
|
+
return config as number
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
get level() {
|
|
220
|
+
return this.getLevel()
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
set level(value) {
|
|
224
|
+
const paths = this.name.split(':')
|
|
225
|
+
let config = Logger.levels
|
|
226
|
+
while (paths.length > 1) {
|
|
227
|
+
const name = paths.shift()!
|
|
228
|
+
const value = config[name]
|
|
229
|
+
if (typeof value === 'object') {
|
|
230
|
+
config = value
|
|
231
|
+
} else {
|
|
232
|
+
config = config[name] = { base: value ?? config.base }
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
config[paths[0]] = value
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
Logger.format('s', (value) => value)
|
|
240
|
+
Logger.format('d', (value) => +value)
|
|
241
|
+
Logger.format('j', (value) => JSON.stringify(value))
|
|
242
|
+
Logger.format('c', (value, target, logger) => {
|
|
243
|
+
return Logger.color(target, Logger.code(logger.name, target), value)
|
|
244
|
+
})
|
|
245
|
+
Logger.format('C', (value, target) => {
|
|
246
|
+
return Logger.color(target, 15, value, ';1')
|
|
247
|
+
})
|
|
248
|
+
|
|
249
|
+
export = Logger
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {default} from './index.js';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/* eslint-env browser */
|
|
2
|
+
/* eslint-disable n/no-unsupported-features/node-builtins */
|
|
3
|
+
|
|
4
|
+
const level = (() => {
|
|
5
|
+
if (!('navigator' in globalThis)) {
|
|
6
|
+
return 0;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
if (globalThis.navigator.userAgentData) {
|
|
10
|
+
const brand = navigator.userAgentData.brands.find(({brand}) => brand === 'Chromium');
|
|
11
|
+
if (brand?.version > 93) {
|
|
12
|
+
return 3;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (/\b(Chrome|Chromium)\//.test(globalThis.navigator.userAgent)) {
|
|
17
|
+
return 1;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return 0;
|
|
21
|
+
})();
|
|
22
|
+
|
|
23
|
+
const colorSupport = level !== 0 && {
|
|
24
|
+
level,
|
|
25
|
+
hasBasic: true,
|
|
26
|
+
has256: level >= 2,
|
|
27
|
+
has16m: level >= 3,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const supportsColor = {
|
|
31
|
+
stdout: colorSupport,
|
|
32
|
+
stderr: colorSupport,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export default supportsColor;
|