lib0 0.2.68 → 0.2.70
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/bin/0serve.js +1 -1
- package/broadcastchannel.d.ts.map +1 -1
- package/broadcastchannel.js +9 -1
- package/coverage/tmp/coverage-29565-1679338304477-0.json +1 -0
- package/decoding.js +2 -2
- package/deno.json +4 -1
- package/diff.d.ts.map +1 -1
- package/diff.js +12 -0
- package/diff.test.d.ts.map +1 -1
- package/dist/{broadcastchannel-4e5909e2.cjs → broadcastchannel-1097a8e1.cjs} +11 -3
- package/dist/broadcastchannel-1097a8e1.cjs.map +1 -0
- package/dist/broadcastchannel.cjs +3 -3
- package/dist/broadcastchannel.d.ts.map +1 -1
- package/dist/{buffer-9b566988.cjs → buffer-0021c8c3.cjs} +6 -6
- package/dist/buffer-0021c8c3.cjs.map +1 -0
- package/dist/buffer.cjs +2 -2
- package/dist/component.cjs +1 -1
- package/dist/decoding.cjs +2 -2
- package/dist/{diff-55061848.cjs → diff-6b03292e.cjs} +13 -1
- package/dist/diff-6b03292e.cjs.map +1 -0
- package/dist/diff.cjs +1 -1
- package/dist/diff.d.ts.map +1 -1
- package/dist/diff.test.d.ts.map +1 -1
- package/dist/encoding.cjs +2 -2
- package/dist/{environment-01c0e75b.cjs → environment-7991e0f6.cjs} +1 -1
- package/dist/{environment-01c0e75b.cjs.map → environment-7991e0f6.cjs.map} +1 -1
- package/dist/environment.cjs +1 -1
- package/dist/index.cjs +27 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/{logging-641c32f4.cjs → logging.browser.cjs} +38 -193
- package/dist/logging.browser.cjs.map +1 -0
- package/dist/{logging.d.ts → logging.browser.d.ts} +2 -10
- package/dist/logging.browser.d.ts.map +1 -0
- package/dist/logging.common.cjs +99 -0
- package/dist/logging.common.cjs.map +1 -0
- package/dist/logging.common.d.ts +12 -0
- package/dist/logging.common.d.ts.map +1 -0
- package/dist/logging.node.cjs +196 -0
- package/dist/logging.node.cjs.map +1 -0
- package/dist/logging.node.d.ts +14 -0
- package/dist/logging.node.d.ts.map +1 -0
- package/dist/performance.browser.cjs +14 -0
- package/dist/performance.browser.cjs.map +1 -0
- package/dist/performance.browser.d.ts +4 -0
- package/dist/performance.browser.d.ts.map +1 -0
- package/dist/performance.node.cjs +35 -0
- package/dist/performance.node.cjs.map +1 -0
- package/dist/performance.node.d.ts +15 -0
- package/dist/performance.node.d.ts.map +1 -0
- package/dist/{prng-cd2451c9.cjs → prng-98750e19.cjs} +2 -2
- package/dist/{prng-cd2451c9.cjs.map → prng-98750e19.cjs.map} +1 -1
- package/dist/prng.cjs +3 -3
- package/dist/random.cjs +3 -3
- package/dist/random.cjs.map +1 -1
- package/dist/random.d.ts.map +1 -1
- package/dist/storage.cjs +11 -1
- package/dist/storage.cjs.map +1 -1
- package/dist/storage.d.ts +5 -0
- package/dist/storage.d.ts.map +1 -1
- package/dist/testing.cjs +66 -48
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.d.ts.map +1 -1
- package/encoding.js +2 -2
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/isomorphic.js +2 -0
- package/{logging.d.ts → logging.browser.d.ts} +2 -10
- package/logging.browser.d.ts.map +1 -0
- package/{logging.js → logging.browser.js} +16 -152
- package/logging.common.d.ts +12 -0
- package/logging.common.d.ts.map +1 -0
- package/logging.common.js +76 -0
- package/logging.node.d.ts +14 -0
- package/logging.node.d.ts.map +1 -0
- package/logging.node.js +159 -0
- package/package.json +29 -7
- package/performance.browser.d.ts +4 -0
- package/performance.browser.d.ts.map +1 -0
- package/performance.browser.js +5 -0
- package/performance.node.d.ts +15 -0
- package/performance.node.d.ts.map +1 -0
- package/performance.node.js +21 -0
- package/random.d.ts.map +1 -1
- package/random.js +3 -3
- package/storage.d.ts +5 -0
- package/storage.d.ts.map +1 -1
- package/storage.js +10 -1
- package/test.html +2 -3
- package/test.js +1 -1
- package/testing.d.ts +1 -1
- package/testing.d.ts.map +1 -1
- package/testing.js +2 -3
- package/coverage/tmp/coverage-53209-1678990177518-0.json +0 -1
- package/dist/broadcastchannel-4e5909e2.cjs.map +0 -1
- package/dist/buffer-9b566988.cjs.map +0 -1
- package/dist/diff-55061848.cjs.map +0 -1
- package/dist/logging-641c32f4.cjs.map +0 -1
- package/dist/logging.cjs +0 -49
- package/dist/logging.cjs.map +0 -1
- package/dist/logging.d.ts.map +0 -1
- package/logging.d.ts.map +0 -1
|
@@ -6,51 +6,29 @@
|
|
|
6
6
|
|
|
7
7
|
import * as env from './environment.js'
|
|
8
8
|
import * as set from './set.js'
|
|
9
|
-
import * as symbol from './symbol.js'
|
|
10
9
|
import * as pair from './pair.js'
|
|
11
10
|
import * as dom from './dom.js'
|
|
12
11
|
import * as json from './json.js'
|
|
13
12
|
import * as map from './map.js'
|
|
14
13
|
import * as eventloop from './eventloop.js'
|
|
15
14
|
import * as math from './math.js'
|
|
16
|
-
import * as
|
|
17
|
-
import * as func from './function.js'
|
|
15
|
+
import * as common from './logging.common.js'
|
|
18
16
|
|
|
19
|
-
export
|
|
20
|
-
export const UNBOLD = symbol.create()
|
|
21
|
-
export const BLUE = symbol.create()
|
|
22
|
-
export const GREY = symbol.create()
|
|
23
|
-
export const GREEN = symbol.create()
|
|
24
|
-
export const RED = symbol.create()
|
|
25
|
-
export const PURPLE = symbol.create()
|
|
26
|
-
export const ORANGE = symbol.create()
|
|
27
|
-
export const UNCOLOR = symbol.create()
|
|
17
|
+
export { BOLD, UNBOLD, BLUE, GREY, GREEN, RED, PURPLE, ORANGE, UNCOLOR } from './logging.common.js'
|
|
28
18
|
|
|
29
19
|
/**
|
|
30
20
|
* @type {Object<Symbol,pair.Pair<string,string>>}
|
|
31
21
|
*/
|
|
32
22
|
const _browserStyleMap = {
|
|
33
|
-
[BOLD]: pair.create('font-weight', 'bold'),
|
|
34
|
-
[UNBOLD]: pair.create('font-weight', 'normal'),
|
|
35
|
-
[BLUE]: pair.create('color', 'blue'),
|
|
36
|
-
[GREEN]: pair.create('color', 'green'),
|
|
37
|
-
[GREY]: pair.create('color', 'grey'),
|
|
38
|
-
[RED]: pair.create('color', 'red'),
|
|
39
|
-
[PURPLE]: pair.create('color', 'purple'),
|
|
40
|
-
[ORANGE]: pair.create('color', 'orange'), // not well supported in chrome when debugging node with inspector - TODO: deprecate
|
|
41
|
-
[UNCOLOR]: pair.create('color', 'black')
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const _nodeStyleMap = {
|
|
45
|
-
[BOLD]: '\u001b[1m',
|
|
46
|
-
[UNBOLD]: '\u001b[2m',
|
|
47
|
-
[BLUE]: '\x1b[34m',
|
|
48
|
-
[GREEN]: '\x1b[32m',
|
|
49
|
-
[GREY]: '\u001b[37m',
|
|
50
|
-
[RED]: '\x1b[31m',
|
|
51
|
-
[PURPLE]: '\x1b[35m',
|
|
52
|
-
[ORANGE]: '\x1b[38;5;208m',
|
|
53
|
-
[UNCOLOR]: '\x1b[0m'
|
|
23
|
+
[common.BOLD]: pair.create('font-weight', 'bold'),
|
|
24
|
+
[common.UNBOLD]: pair.create('font-weight', 'normal'),
|
|
25
|
+
[common.BLUE]: pair.create('color', 'blue'),
|
|
26
|
+
[common.GREEN]: pair.create('color', 'green'),
|
|
27
|
+
[common.GREY]: pair.create('color', 'grey'),
|
|
28
|
+
[common.RED]: pair.create('color', 'red'),
|
|
29
|
+
[common.PURPLE]: pair.create('color', 'purple'),
|
|
30
|
+
[common.ORANGE]: pair.create('color', 'orange'), // not well supported in chrome when debugging node with inspector - TODO: deprecate
|
|
31
|
+
[common.UNCOLOR]: pair.create('color', 'black')
|
|
54
32
|
}
|
|
55
33
|
|
|
56
34
|
/**
|
|
@@ -104,90 +82,10 @@ const computeBrowserLoggingArgs = (args) => {
|
|
|
104
82
|
}
|
|
105
83
|
/* c8 ignore stop */
|
|
106
84
|
|
|
107
|
-
/* c8 ignore start */
|
|
108
|
-
/**
|
|
109
|
-
* @param {Array<string|Symbol|Object|number>} args
|
|
110
|
-
* @return {Array<string|object|number>}
|
|
111
|
-
*/
|
|
112
|
-
const computeNoColorLoggingArgs = args => {
|
|
113
|
-
const strBuilder = []
|
|
114
|
-
const logArgs = []
|
|
115
|
-
// try with formatting until we find something unsupported
|
|
116
|
-
let i = 0
|
|
117
|
-
for (; i < args.length; i++) {
|
|
118
|
-
const arg = args[i]
|
|
119
|
-
// @ts-ignore
|
|
120
|
-
const style = _nodeStyleMap[arg]
|
|
121
|
-
if (style === undefined) {
|
|
122
|
-
if (arg.constructor === String || arg.constructor === Number) {
|
|
123
|
-
strBuilder.push(arg)
|
|
124
|
-
} else {
|
|
125
|
-
break
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
if (i > 0) {
|
|
130
|
-
logArgs.push(strBuilder.join(''))
|
|
131
|
-
}
|
|
132
|
-
// append the rest
|
|
133
|
-
for (; i < args.length; i++) {
|
|
134
|
-
const arg = args[i]
|
|
135
|
-
if (!(arg instanceof Symbol)) {
|
|
136
|
-
if (arg.constructor === Object) {
|
|
137
|
-
logArgs.push(JSON.stringify(arg))
|
|
138
|
-
} else {
|
|
139
|
-
logArgs.push(arg)
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
return logArgs
|
|
144
|
-
}
|
|
145
|
-
/* c8 ignore stop */
|
|
146
|
-
|
|
147
|
-
/* c8 ignore start */
|
|
148
|
-
/**
|
|
149
|
-
* @param {Array<string|Symbol|Object|number>} args
|
|
150
|
-
* @return {Array<string|object|number>}
|
|
151
|
-
*/
|
|
152
|
-
const computeNodeLoggingArgs = (args) => {
|
|
153
|
-
const strBuilder = []
|
|
154
|
-
const logArgs = []
|
|
155
|
-
// try with formatting until we find something unsupported
|
|
156
|
-
let i = 0
|
|
157
|
-
for (; i < args.length; i++) {
|
|
158
|
-
const arg = args[i]
|
|
159
|
-
// @ts-ignore
|
|
160
|
-
const style = _nodeStyleMap[arg]
|
|
161
|
-
if (style !== undefined) {
|
|
162
|
-
strBuilder.push(style)
|
|
163
|
-
} else {
|
|
164
|
-
if (arg.constructor === String || arg.constructor === Number) {
|
|
165
|
-
strBuilder.push(arg)
|
|
166
|
-
} else {
|
|
167
|
-
break
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
if (i > 0) {
|
|
172
|
-
// create logArgs with what we have so far
|
|
173
|
-
strBuilder.push('\x1b[0m')
|
|
174
|
-
logArgs.push(strBuilder.join(''))
|
|
175
|
-
}
|
|
176
|
-
// append the rest
|
|
177
|
-
for (; i < args.length; i++) {
|
|
178
|
-
const arg = args[i]
|
|
179
|
-
if (!(arg instanceof Symbol)) {
|
|
180
|
-
logArgs.push(arg)
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
return logArgs
|
|
184
|
-
}
|
|
185
|
-
/* c8 ignore stop */
|
|
186
|
-
|
|
187
85
|
/* c8 ignore start */
|
|
188
86
|
const computeLoggingArgs = env.supportsColor
|
|
189
|
-
?
|
|
190
|
-
: computeNoColorLoggingArgs
|
|
87
|
+
? computeBrowserLoggingArgs
|
|
88
|
+
: common.computeNoColorLoggingArgs
|
|
191
89
|
/* c8 ignore stop */
|
|
192
90
|
|
|
193
91
|
/**
|
|
@@ -205,7 +103,7 @@ export const print = (...args) => {
|
|
|
205
103
|
*/
|
|
206
104
|
export const warn = (...args) => {
|
|
207
105
|
console.warn(...computeLoggingArgs(args))
|
|
208
|
-
args.unshift(ORANGE)
|
|
106
|
+
args.unshift(common.ORANGE)
|
|
209
107
|
vconsoles.forEach((vc) => vc.print(args))
|
|
210
108
|
}
|
|
211
109
|
/* c8 ignore stop */
|
|
@@ -428,7 +326,7 @@ export class VConsole {
|
|
|
428
326
|
* @param {Error} err
|
|
429
327
|
*/
|
|
430
328
|
printError (err) {
|
|
431
|
-
this.print([RED, BOLD, err.toString()])
|
|
329
|
+
this.print([common.RED, common.BOLD, err.toString()])
|
|
432
330
|
}
|
|
433
331
|
|
|
434
332
|
/**
|
|
@@ -469,42 +367,8 @@ export class VConsole {
|
|
|
469
367
|
/* c8 ignore next */
|
|
470
368
|
export const createVConsole = (dom) => new VConsole(dom)
|
|
471
369
|
|
|
472
|
-
const loggingColors = [GREEN, PURPLE, ORANGE, BLUE]
|
|
473
|
-
let nextColor = 0
|
|
474
|
-
let lastLoggingTime = time.getUnixTime()
|
|
475
|
-
|
|
476
|
-
/* c8 ignore start */
|
|
477
370
|
/**
|
|
478
371
|
* @param {string} moduleName
|
|
479
372
|
* @return {function(...any):void}
|
|
480
373
|
*/
|
|
481
|
-
export const createModuleLogger = (moduleName) =>
|
|
482
|
-
const color = loggingColors[nextColor]
|
|
483
|
-
const debugRegexVar = env.getVariable('log')
|
|
484
|
-
const doLogging = debugRegexVar !== null &&
|
|
485
|
-
(debugRegexVar === '*' || debugRegexVar === 'true' ||
|
|
486
|
-
new RegExp(debugRegexVar, 'gi').test(moduleName))
|
|
487
|
-
nextColor = (nextColor + 1) % loggingColors.length
|
|
488
|
-
moduleName += ': '
|
|
489
|
-
|
|
490
|
-
return !doLogging
|
|
491
|
-
? func.nop
|
|
492
|
-
: (...args) => {
|
|
493
|
-
const timeNow = time.getUnixTime()
|
|
494
|
-
const timeDiff = timeNow - lastLoggingTime
|
|
495
|
-
lastLoggingTime = timeNow
|
|
496
|
-
print(
|
|
497
|
-
color,
|
|
498
|
-
moduleName,
|
|
499
|
-
UNCOLOR,
|
|
500
|
-
...args.map((arg) =>
|
|
501
|
-
(typeof arg === 'string' || typeof arg === 'symbol')
|
|
502
|
-
? arg
|
|
503
|
-
: JSON.stringify(arg)
|
|
504
|
-
),
|
|
505
|
-
color,
|
|
506
|
-
' +' + timeDiff + 'ms'
|
|
507
|
-
)
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
/* c8 ignore stop */
|
|
374
|
+
export const createModuleLogger = (moduleName) => common.createModuleLogger(print, moduleName)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const BOLD: symbol;
|
|
2
|
+
export const UNBOLD: symbol;
|
|
3
|
+
export const BLUE: symbol;
|
|
4
|
+
export const GREY: symbol;
|
|
5
|
+
export const GREEN: symbol;
|
|
6
|
+
export const RED: symbol;
|
|
7
|
+
export const PURPLE: symbol;
|
|
8
|
+
export const ORANGE: symbol;
|
|
9
|
+
export const UNCOLOR: symbol;
|
|
10
|
+
export function computeNoColorLoggingArgs(args: Array<string | Symbol | Object | number>): Array<string | object | number>;
|
|
11
|
+
export function createModuleLogger(_print: (...args: any[]) => void, moduleName: string): (...args: any[]) => void;
|
|
12
|
+
//# sourceMappingURL=logging.common.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logging.common.d.ts","sourceRoot":"","sources":["logging.common.js"],"names":[],"mappings":"AAKA,0BAAmC;AACnC,4BAAqC;AACrC,0BAAmC;AACnC,0BAAmC;AACnC,2BAAoC;AACpC,yBAAkC;AAClC,4BAAqC;AACrC,4BAAqC;AACrC,6BAAsC;AAO/B,gDAHI,MAAM,MAAM,GAAC,MAAM,GAAC,MAAM,GAAC,MAAM,CAAC,GACjC,MAAM,MAAM,GAAC,MAAM,GAAC,MAAM,CAAC,CAgBtC;AAaM,qDAJgB,GAAG,OAAE,IAAI,cACrB,MAAM,aACO,GAAG,OAAE,IAAI,CA6BhC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import * as symbol from './symbol.js'
|
|
2
|
+
import * as time from './time.js'
|
|
3
|
+
import * as env from './environment.js'
|
|
4
|
+
import * as func from './function.js'
|
|
5
|
+
|
|
6
|
+
export const BOLD = symbol.create()
|
|
7
|
+
export const UNBOLD = symbol.create()
|
|
8
|
+
export const BLUE = symbol.create()
|
|
9
|
+
export const GREY = symbol.create()
|
|
10
|
+
export const GREEN = symbol.create()
|
|
11
|
+
export const RED = symbol.create()
|
|
12
|
+
export const PURPLE = symbol.create()
|
|
13
|
+
export const ORANGE = symbol.create()
|
|
14
|
+
export const UNCOLOR = symbol.create()
|
|
15
|
+
|
|
16
|
+
/* c8 ignore start */
|
|
17
|
+
/**
|
|
18
|
+
* @param {Array<string|Symbol|Object|number>} args
|
|
19
|
+
* @return {Array<string|object|number>}
|
|
20
|
+
*/
|
|
21
|
+
export const computeNoColorLoggingArgs = args => {
|
|
22
|
+
const strBuilder = []
|
|
23
|
+
const logArgs = []
|
|
24
|
+
// try with formatting until we find something unsupported
|
|
25
|
+
let i = 0
|
|
26
|
+
for (; i < args.length; i++) {
|
|
27
|
+
const arg = args[i]
|
|
28
|
+
if (arg.constructor === String || arg.constructor === Number) {
|
|
29
|
+
strBuilder.push(arg)
|
|
30
|
+
} else if (arg.constructor === Object) {
|
|
31
|
+
logArgs.push(JSON.stringify(arg))
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return logArgs
|
|
35
|
+
}
|
|
36
|
+
/* c8 ignore stop */
|
|
37
|
+
|
|
38
|
+
const loggingColors = [GREEN, PURPLE, ORANGE, BLUE]
|
|
39
|
+
let nextColor = 0
|
|
40
|
+
let lastLoggingTime = time.getUnixTime()
|
|
41
|
+
|
|
42
|
+
/* c8 ignore start */
|
|
43
|
+
/**
|
|
44
|
+
* @param {function(...any):void} _print
|
|
45
|
+
* @param {string} moduleName
|
|
46
|
+
* @return {function(...any):void}
|
|
47
|
+
*/
|
|
48
|
+
export const createModuleLogger = (_print, moduleName) => {
|
|
49
|
+
const color = loggingColors[nextColor]
|
|
50
|
+
const debugRegexVar = env.getVariable('log')
|
|
51
|
+
const doLogging = debugRegexVar !== null &&
|
|
52
|
+
(debugRegexVar === '*' || debugRegexVar === 'true' ||
|
|
53
|
+
new RegExp(debugRegexVar, 'gi').test(moduleName))
|
|
54
|
+
nextColor = (nextColor + 1) % loggingColors.length
|
|
55
|
+
moduleName += ': '
|
|
56
|
+
return !doLogging
|
|
57
|
+
? func.nop
|
|
58
|
+
: (...args) => {
|
|
59
|
+
const timeNow = time.getUnixTime()
|
|
60
|
+
const timeDiff = timeNow - lastLoggingTime
|
|
61
|
+
lastLoggingTime = timeNow
|
|
62
|
+
_print(
|
|
63
|
+
color,
|
|
64
|
+
moduleName,
|
|
65
|
+
UNCOLOR,
|
|
66
|
+
...args.map((arg) =>
|
|
67
|
+
(typeof arg === 'string' || typeof arg === 'symbol')
|
|
68
|
+
? arg
|
|
69
|
+
: JSON.stringify(arg)
|
|
70
|
+
),
|
|
71
|
+
color,
|
|
72
|
+
' +' + timeDiff + 'ms'
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/* c8 ignore stop */
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function print(...args: Array<string | Symbol | Object | number>): void;
|
|
2
|
+
export function warn(...args: Array<string | Symbol | Object | number>): void;
|
|
3
|
+
export function printError(err: Error): void;
|
|
4
|
+
export function printImg(_url: string, _height: number): void;
|
|
5
|
+
export function printImgBase64(base64: string, height: number): void;
|
|
6
|
+
export function group(...args: Array<string | Symbol | Object | number>): void;
|
|
7
|
+
export function groupCollapsed(...args: Array<string | Symbol | Object | number>): void;
|
|
8
|
+
export function groupEnd(): void;
|
|
9
|
+
export function printDom(_createNode: () => Node): void;
|
|
10
|
+
export function printCanvas(canvas: HTMLCanvasElement, height: number): void;
|
|
11
|
+
export function createVConsole(_dom: Element): void;
|
|
12
|
+
export function createModuleLogger(moduleName: string): (...args: any[]) => void;
|
|
13
|
+
export { BOLD, UNBOLD, BLUE, GREY, GREEN, RED, PURPLE, ORANGE, UNCOLOR } from "./logging.common.js";
|
|
14
|
+
//# sourceMappingURL=logging.node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logging.node.d.ts","sourceRoot":"","sources":["logging.node.js"],"names":[],"mappings":"AAwEO,+BAFI,MAAM,MAAM,GAAC,MAAM,GAAC,MAAM,GAAC,MAAM,CAAC,QAI5C;AAMM,8BAFI,MAAM,MAAM,GAAC,MAAM,GAAC,MAAM,GAAC,MAAM,CAAC,QAI5C;AAOM,gCAHI,KAAK,QAKf;AAQM,+BAJI,MAAM,WACN,MAAM,QAKhB;AAQM,uCAJI,MAAM,UACN,MAAM,QAIoC;AAM9C,+BAHI,MAAM,MAAM,GAAC,MAAM,GAAC,MAAM,GAAC,MAAM,CAAC,QAK5C;AAMM,wCAHI,MAAM,MAAM,GAAC,MAAM,GAAC,MAAM,GAAC,MAAM,CAAC,QAK5C;AAGM,iCAEN;AAMM,4CAHe,IAAI,QAGiB;AAOpC,oCAJI,iBAAiB,UACjB,MAAM,QAIqB;AAM/B,qCAHI,OAAO,QAGwB;AAOnC,+CAJI,MAAM,aACO,GAAG,OAAE,IAAI,CAG6D"}
|
package/logging.node.js
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Isomorphic logging module with support for colors!
|
|
3
|
+
*
|
|
4
|
+
* @module logging
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import * as env from './environment.js'
|
|
8
|
+
import * as common from './logging.common.js'
|
|
9
|
+
|
|
10
|
+
export { BOLD, UNBOLD, BLUE, GREY, GREEN, RED, PURPLE, ORANGE, UNCOLOR } from './logging.common.js'
|
|
11
|
+
|
|
12
|
+
const _nodeStyleMap = {
|
|
13
|
+
[common.BOLD]: '\u001b[1m',
|
|
14
|
+
[common.UNBOLD]: '\u001b[2m',
|
|
15
|
+
[common.BLUE]: '\x1b[34m',
|
|
16
|
+
[common.GREEN]: '\x1b[32m',
|
|
17
|
+
[common.GREY]: '\u001b[37m',
|
|
18
|
+
[common.RED]: '\x1b[31m',
|
|
19
|
+
[common.PURPLE]: '\x1b[35m',
|
|
20
|
+
[common.ORANGE]: '\x1b[38;5;208m',
|
|
21
|
+
[common.UNCOLOR]: '\x1b[0m'
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/* c8 ignore start */
|
|
25
|
+
/**
|
|
26
|
+
* @param {Array<string|Symbol|Object|number>} args
|
|
27
|
+
* @return {Array<string|object|number>}
|
|
28
|
+
*/
|
|
29
|
+
const computeNodeLoggingArgs = (args) => {
|
|
30
|
+
const strBuilder = []
|
|
31
|
+
const logArgs = []
|
|
32
|
+
// try with formatting until we find something unsupported
|
|
33
|
+
let i = 0
|
|
34
|
+
for (; i < args.length; i++) {
|
|
35
|
+
const arg = args[i]
|
|
36
|
+
// @ts-ignore
|
|
37
|
+
const style = _nodeStyleMap[arg]
|
|
38
|
+
if (style !== undefined) {
|
|
39
|
+
strBuilder.push(style)
|
|
40
|
+
} else {
|
|
41
|
+
if (arg.constructor === String || arg.constructor === Number) {
|
|
42
|
+
strBuilder.push(arg)
|
|
43
|
+
} else {
|
|
44
|
+
break
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (i > 0) {
|
|
49
|
+
// create logArgs with what we have so far
|
|
50
|
+
strBuilder.push('\x1b[0m')
|
|
51
|
+
logArgs.push(strBuilder.join(''))
|
|
52
|
+
}
|
|
53
|
+
// append the rest
|
|
54
|
+
for (; i < args.length; i++) {
|
|
55
|
+
const arg = args[i]
|
|
56
|
+
if (!(arg instanceof Symbol)) {
|
|
57
|
+
logArgs.push(arg)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return logArgs
|
|
61
|
+
}
|
|
62
|
+
/* c8 ignore stop */
|
|
63
|
+
|
|
64
|
+
/* c8 ignore start */
|
|
65
|
+
const computeLoggingArgs = env.supportsColor
|
|
66
|
+
? computeNodeLoggingArgs
|
|
67
|
+
: common.computeNoColorLoggingArgs
|
|
68
|
+
/* c8 ignore stop */
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @param {Array<string|Symbol|Object|number>} args
|
|
72
|
+
*/
|
|
73
|
+
export const print = (...args) => {
|
|
74
|
+
console.log(...computeLoggingArgs(args))
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/* c8 ignore start */
|
|
78
|
+
/**
|
|
79
|
+
* @param {Array<string|Symbol|Object|number>} args
|
|
80
|
+
*/
|
|
81
|
+
export const warn = (...args) => {
|
|
82
|
+
console.warn(...computeLoggingArgs(args))
|
|
83
|
+
}
|
|
84
|
+
/* c8 ignore stop */
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @param {Error} err
|
|
88
|
+
*/
|
|
89
|
+
/* c8 ignore start */
|
|
90
|
+
export const printError = (err) => {
|
|
91
|
+
console.error(err)
|
|
92
|
+
}
|
|
93
|
+
/* c8 ignore stop */
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* @param {string} _url image location
|
|
97
|
+
* @param {number} _height height of the image in pixel
|
|
98
|
+
*/
|
|
99
|
+
/* c8 ignore start */
|
|
100
|
+
export const printImg = (_url, _height) => {
|
|
101
|
+
// console.log('%c ', `font-size: ${height}x; background: url(${url}) no-repeat;`)
|
|
102
|
+
}
|
|
103
|
+
/* c8 ignore stop */
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* @param {string} base64
|
|
107
|
+
* @param {number} height
|
|
108
|
+
*/
|
|
109
|
+
/* c8 ignore next 2 */
|
|
110
|
+
export const printImgBase64 = (base64, height) =>
|
|
111
|
+
printImg(`data:image/gif;base64,${base64}`, height)
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* @param {Array<string|Symbol|Object|number>} args
|
|
115
|
+
*/
|
|
116
|
+
/* c8 ignore next 3 */
|
|
117
|
+
export const group = (...args) => {
|
|
118
|
+
console.group(...computeLoggingArgs(args))
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* @param {Array<string|Symbol|Object|number>} args
|
|
123
|
+
*/
|
|
124
|
+
/* c8 ignore next 3 */
|
|
125
|
+
export const groupCollapsed = (...args) => {
|
|
126
|
+
console.groupCollapsed(...computeLoggingArgs(args))
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/* c8 ignore next 3 */
|
|
130
|
+
export const groupEnd = () => {
|
|
131
|
+
console.groupEnd()
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* @param {function():Node} _createNode
|
|
136
|
+
*/
|
|
137
|
+
/* c8 ignore next 2 */
|
|
138
|
+
export const printDom = (_createNode) => {}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* @param {HTMLCanvasElement} canvas
|
|
142
|
+
* @param {number} height
|
|
143
|
+
*/
|
|
144
|
+
/* c8 ignore next 2 */
|
|
145
|
+
export const printCanvas = (canvas, height) =>
|
|
146
|
+
printImg(canvas.toDataURL(), height)
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* @param {Element} _dom
|
|
150
|
+
*/
|
|
151
|
+
/* c8 ignore next */
|
|
152
|
+
export const createVConsole = (_dom) => {}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* @param {string} moduleName
|
|
156
|
+
* @return {function(...any):void}
|
|
157
|
+
*/
|
|
158
|
+
/* c8 ignore next */
|
|
159
|
+
export const createModuleLogger = (moduleName) => common.createModuleLogger(print, moduleName)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lib0",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.70",
|
|
4
4
|
"description": "",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
@@ -201,13 +201,20 @@
|
|
|
201
201
|
"import": "./list.js",
|
|
202
202
|
"require": "./dist/list.cjs"
|
|
203
203
|
},
|
|
204
|
-
"./logging.js": "./logging.js",
|
|
205
|
-
"./dist/logging.cjs": "./dist/logging.cjs",
|
|
206
204
|
"./logging": {
|
|
207
|
-
"types": "./logging.d.ts",
|
|
208
|
-
"
|
|
209
|
-
"
|
|
210
|
-
"
|
|
205
|
+
"types": "./logging.node.d.ts",
|
|
206
|
+
"deno": "./logging.node.js",
|
|
207
|
+
"bun": "./logging.browser.js",
|
|
208
|
+
"node": {
|
|
209
|
+
"require": "./dist/logging.node.cjs",
|
|
210
|
+
"module": "./logging.node.js",
|
|
211
|
+
"default": "./logging.node.js"
|
|
212
|
+
},
|
|
213
|
+
"browser": {
|
|
214
|
+
"require": "./dist/logging.browser.cjs",
|
|
215
|
+
"module": "./logging.browser.js",
|
|
216
|
+
"default": "./logging.browser.js"
|
|
217
|
+
}
|
|
211
218
|
},
|
|
212
219
|
"./map.js": "./map.js",
|
|
213
220
|
"./dist/map.cjs": "./dist/map.cjs",
|
|
@@ -407,6 +414,21 @@
|
|
|
407
414
|
"require": "./dist/webcrypto.browser.cjs"
|
|
408
415
|
},
|
|
409
416
|
"module": "./webcrypto.browser.js"
|
|
417
|
+
},
|
|
418
|
+
"./performance": {
|
|
419
|
+
"types": "./performance.browser.d.ts",
|
|
420
|
+
"deno": "./performance.node.js",
|
|
421
|
+
"bun": "./performance.node.js",
|
|
422
|
+
"node": {
|
|
423
|
+
"require": "./dist/performance.node.cjs",
|
|
424
|
+
"module": "./performance.node.js",
|
|
425
|
+
"default": "./performance.node.js"
|
|
426
|
+
},
|
|
427
|
+
"browser": {
|
|
428
|
+
"require": "./dist/performance.browser.cjs",
|
|
429
|
+
"module": "./performance.browser.js",
|
|
430
|
+
"default": "./performance.browser.js"
|
|
431
|
+
}
|
|
410
432
|
}
|
|
411
433
|
},
|
|
412
434
|
"dependencies": {
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export const measure: (measureName: string, startOrMeasureOptions?: string | PerformanceMeasureOptions | undefined, endMark?: string | undefined) => PerformanceMeasure;
|
|
2
|
+
export const now: () => number;
|
|
3
|
+
export const mark: (markName: string, markOptions?: PerformanceMarkOptions | undefined) => PerformanceMark;
|
|
4
|
+
//# sourceMappingURL=performance.browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"performance.browser.d.ts","sourceRoot":"","sources":["performance.browser.js"],"names":[],"mappings":"AAEA,wKAA4D;AAC5D,+BAAoD;AACpD,2GAAsD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/**
|
|
3
|
+
* @type {typeof performance.measure}
|
|
4
|
+
*/
|
|
5
|
+
export const measure: typeof performance.measure;
|
|
6
|
+
/**
|
|
7
|
+
* @type {typeof performance.now}
|
|
8
|
+
*/
|
|
9
|
+
export const now: typeof performance.now;
|
|
10
|
+
/**
|
|
11
|
+
* @type {typeof performance.mark}
|
|
12
|
+
*/
|
|
13
|
+
export const mark: typeof performance.mark;
|
|
14
|
+
import { performance } from "perf_hooks";
|
|
15
|
+
//# sourceMappingURL=performance.node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"performance.node.d.ts","sourceRoot":"","sources":["performance.node.js"],"names":[],"mappings":";AAIA;;GAEG;AAEH,sBAHU,OAAO,mBAAmB,CAGyE;AAE7G;;GAEG;AAEH,kBAHU,OAAO,eAAe,CAGyD;AAEzF;;GAEG;AAEH,mBAHU,OAAO,gBAAgB,CAGmE"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { performance } from 'node:perf_hooks'
|
|
2
|
+
import { nop } from './function.js'
|
|
3
|
+
import * as time from './time.js'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @type {typeof performance.measure}
|
|
7
|
+
*/
|
|
8
|
+
/* c8 ignore next */
|
|
9
|
+
export const measure = performance.measure ? performance.measure.bind(performance) : /** @type {any} */ (nop)
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @type {typeof performance.now}
|
|
13
|
+
*/
|
|
14
|
+
/* c8 ignore next */
|
|
15
|
+
export const now = performance.now ? performance.now.bind(performance) : time.getUnixTime
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @type {typeof performance.mark}
|
|
19
|
+
*/
|
|
20
|
+
/* c8 ignore next */
|
|
21
|
+
export const mark = performance.mark ? performance.mark.bind(performance) : /** @type {any} */ (nop)
|
package/random.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"random.d.ts","sourceRoot":"","sources":["random.js"],"names":[],"mappings":"AAaA,gCAA+B;AAExB,
|
|
1
|
+
{"version":3,"file":"random.d.ts","sourceRoot":"","sources":["random.js"],"names":[],"mappings":"AAaA,gCAA+B;AAExB,iCAA2D;AAE3D,iCAGN;AAOM,sCAAyD;AAIzD,8BAEN"}
|
package/random.js
CHANGED
|
@@ -9,14 +9,14 @@
|
|
|
9
9
|
|
|
10
10
|
import * as math from './math.js'
|
|
11
11
|
import * as binary from './binary.js'
|
|
12
|
-
import {
|
|
12
|
+
import { getRandomValues } from 'lib0/webcrypto'
|
|
13
13
|
|
|
14
14
|
export const rand = Math.random
|
|
15
15
|
|
|
16
|
-
export const uint32 = () => new Uint32Array(
|
|
16
|
+
export const uint32 = () => getRandomValues(new Uint32Array(1))[0]
|
|
17
17
|
|
|
18
18
|
export const uint53 = () => {
|
|
19
|
-
const arr = new Uint32Array(
|
|
19
|
+
const arr = getRandomValues(new Uint32Array(8))
|
|
20
20
|
return (arr[0] & binary.BITS21) * (binary.BITS32 + 1) + (arr[1] >>> 0)
|
|
21
21
|
}
|
|
22
22
|
|
package/storage.d.ts
CHANGED
|
@@ -7,4 +7,9 @@ export function onChange(eventHandler: (arg0: {
|
|
|
7
7
|
newValue: string;
|
|
8
8
|
oldValue: string;
|
|
9
9
|
}) => void): true | void;
|
|
10
|
+
export function offChange(eventHandler: (arg0: {
|
|
11
|
+
key: string;
|
|
12
|
+
newValue: string;
|
|
13
|
+
oldValue: string;
|
|
14
|
+
}) => void): true | void;
|
|
10
15
|
//# sourceMappingURL=storage.d.ts.map
|
package/storage.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["storage.js"],"names":[],"mappings":"AAiDA;;GAEG;AAEH,6BAAuC;AAShC,8CAJa;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,KAAG,IAAI,eAIuC"}
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["storage.js"],"names":[],"mappings":"AAiDA;;GAEG;AAEH,6BAAuC;AAShC,8CAJa;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,KAAG,IAAI,eAIuC;AAS9G,+CAJa;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,KAAG,IAAI,eAI2C"}
|
package/storage.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*
|
|
1
|
+
/* eslint-env browser */
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Isomorphic variable storage.
|
|
@@ -61,3 +61,12 @@ export const varStorage = _localStorage
|
|
|
61
61
|
*/
|
|
62
62
|
/* c8 ignore next */
|
|
63
63
|
export const onChange = eventHandler => usePolyfill || addEventListener('storage', /** @type {any} */ (eventHandler))
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* A polyfill for `removeEventListener('storage', event => {..})` that does nothing if the polyfill is being used.
|
|
67
|
+
*
|
|
68
|
+
* @param {function({ key: string, newValue: string, oldValue: string }): void} eventHandler
|
|
69
|
+
* @function
|
|
70
|
+
*/
|
|
71
|
+
/* c8 ignore next */
|
|
72
|
+
export const offChange = eventHandler => usePolyfill || removeEventListener('storage', /** @type {any} */ (eventHandler))
|