@idlebox/common 1.4.2 → 1.4.3
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/lib/cjs/array/arrayUnique.cjs +2 -4
- package/lib/cjs/array/arrayUnique.cjs.map +1 -1
- package/lib/cjs/array/normalizeArray.cjs +2 -4
- package/lib/cjs/array/normalizeArray.cjs.map +1 -1
- package/lib/cjs/array/sortAlpha.cjs +2 -4
- package/lib/cjs/array/sortAlpha.cjs.map +1 -1
- package/lib/cjs/date/isInvalid.cjs +1 -1
- package/lib/cjs/date/isInvalid.cjs.map +1 -1
- package/lib/cjs/date/timeString.cjs +8 -10
- package/lib/cjs/date/timeString.cjs.map +1 -1
- package/lib/cjs/debugging/serializable.cjs +2 -2
- package/lib/cjs/debugging/serializable.cjs.map +1 -1
- package/lib/cjs/debugging/tryInspect.cjs +7 -9
- package/lib/cjs/debugging/tryInspect.cjs.map +1 -1
- package/lib/cjs/error/convertUnknown.cjs +2 -4
- package/lib/cjs/error/convertUnknown.cjs.map +1 -1
- package/lib/cjs/error/getFrame.cjs +2 -2
- package/lib/cjs/error/getFrame.cjs.map +1 -1
- package/lib/cjs/error/known.cjs.map +1 -1
- package/lib/cjs/error/pretty.cjs +22 -30
- package/lib/cjs/error/pretty.cjs.map +1 -1
- package/lib/cjs/function/asyncCallbackList.cjs.map +1 -1
- package/lib/cjs/function/callbackList.cjs.map +1 -1
- package/lib/cjs/function/delayCallbackList.cjs +3 -3
- package/lib/cjs/function/delayCallbackList.cjs.map +1 -1
- package/lib/cjs/lifecycle/dispose/disposableEvent.cjs +1 -3
- package/lib/cjs/lifecycle/dispose/disposableEvent.cjs.map +1 -1
- package/lib/cjs/lifecycle/dispose/lifecycle.async.cjs.map +1 -1
- package/lib/cjs/lifecycle/dispose/lifecycle.global.cjs +4 -8
- package/lib/cjs/lifecycle/dispose/lifecycle.global.cjs.map +1 -1
- package/lib/cjs/lifecycle/dispose/lifecycle.sync.cjs +1 -1
- package/lib/cjs/lifecycle/dispose/lifecycle.sync.cjs.map +1 -1
- package/lib/cjs/lifecycle/event/event.cjs.map +1 -1
- package/lib/cjs/lifecycle/event/memorized.cjs +1 -1
- package/lib/cjs/lifecycle/event/memorized.cjs.map +1 -1
- package/lib/cjs/lifecycle/promise/cancellationToken/driver.common.cjs.map +1 -1
- package/lib/cjs/lifecycle/promise/deferredPromise.cjs +2 -2
- package/lib/cjs/lifecycle/promise/deferredPromise.cjs.map +1 -1
- package/lib/cjs/lifecycle/timeout/timeout.cjs +1 -3
- package/lib/cjs/lifecycle/timeout/timeout.cjs.map +1 -1
- package/lib/cjs/lifecycle/timeout/timeoutError.cjs.map +1 -1
- package/lib/cjs/log/logger.cjs +4 -6
- package/lib/cjs/log/logger.cjs.map +1 -1
- package/lib/cjs/mapSet/customSet.cjs +3 -7
- package/lib/cjs/mapSet/customSet.cjs.map +1 -1
- package/lib/cjs/mapSet/extendMap.cjs +5 -9
- package/lib/cjs/mapSet/extendMap.cjs.map +1 -1
- package/lib/cjs/misc/assertNotNull.cjs +1 -3
- package/lib/cjs/misc/assertNotNull.cjs.map +1 -1
- package/lib/cjs/misc/package.json.cjs +1 -1
- package/lib/cjs/misc/package.json.cjs.map +1 -1
- package/lib/cjs/object/initOnRead.cjs.map +1 -1
- package/lib/cjs/object/objectSame.cjs +2 -1
- package/lib/cjs/object/objectSame.cjs.map +1 -1
- package/lib/cjs/path/normalizePath.cjs +7 -9
- package/lib/cjs/path/normalizePath.cjs.map +1 -1
- package/lib/cjs/path/pathArray.cjs +1 -1
- package/lib/cjs/path/pathArray.cjs.map +1 -1
- package/lib/cjs/platform/globalSingleton.cjs +1 -1
- package/lib/cjs/platform/globalSymbol.cjs +6 -8
- package/lib/cjs/platform/globalSymbol.cjs.map +1 -1
- package/lib/cjs/promise/promiseCollection.cjs +3 -3
- package/lib/cjs/promise/promiseCollection.cjs.map +1 -1
- package/lib/cjs/reflection/classes/singleton.cjs +1 -3
- package/lib/cjs/reflection/classes/singleton.cjs.map +1 -1
- package/lib/cjs/reflection/methods/bind.cjs +1 -3
- package/lib/cjs/reflection/methods/bind.cjs.map +1 -1
- package/lib/cjs/reflection/methods/initOnRead.cjs +2 -2
- package/lib/cjs/reflection/methods/initOnRead.cjs.map +1 -1
- package/lib/cjs/string/castCase.cjs +5 -5
- package/lib/cjs/string/castCase.cjs.map +1 -1
- package/lib/cjs/string/pad2.cjs +2 -4
- package/lib/cjs/string/pad2.cjs.map +1 -1
- package/lib/cjs/string/sizeString.cjs +23 -27
- package/lib/cjs/string/sizeString.cjs.map +1 -1
- package/lib/esm/array/arrayUnique.d.ts +1 -3
- package/lib/esm/array/arrayUnique.d.ts.map +1 -1
- package/lib/esm/array/arrayUnique.js +2 -4
- package/lib/esm/array/arrayUnique.js.map +1 -1
- package/lib/esm/array/normalizeArray.js +2 -4
- package/lib/esm/array/normalizeArray.js.map +1 -1
- package/lib/esm/array/sortAlpha.js +2 -4
- package/lib/esm/array/sortAlpha.js.map +1 -1
- package/lib/esm/date/isInvalid.js +1 -1
- package/lib/esm/date/isInvalid.js.map +1 -1
- package/lib/esm/date/timeString.d.ts +1 -3
- package/lib/esm/date/timeString.d.ts.map +1 -1
- package/lib/esm/date/timeString.js +8 -10
- package/lib/esm/date/timeString.js.map +1 -1
- package/lib/esm/debugging/serializable.d.ts +1 -1
- package/lib/esm/debugging/serializable.d.ts.map +1 -1
- package/lib/esm/debugging/serializable.js +2 -2
- package/lib/esm/debugging/serializable.js.map +1 -1
- package/lib/esm/debugging/tryInspect.d.ts.map +1 -1
- package/lib/esm/debugging/tryInspect.js +7 -9
- package/lib/esm/debugging/tryInspect.js.map +1 -1
- package/lib/esm/error/convertUnknown.d.ts.map +1 -1
- package/lib/esm/error/convertUnknown.js +2 -4
- package/lib/esm/error/convertUnknown.js.map +1 -1
- package/lib/esm/error/getFrame.js +2 -2
- package/lib/esm/error/getFrame.js.map +1 -1
- package/lib/esm/error/known.d.ts.map +1 -1
- package/lib/esm/error/known.js.map +1 -1
- package/lib/esm/error/pretty.d.ts.map +1 -1
- package/lib/esm/error/pretty.js +22 -30
- package/lib/esm/error/pretty.js.map +1 -1
- package/lib/esm/function/asyncCallbackList.d.ts +1 -1
- package/lib/esm/function/asyncCallbackList.d.ts.map +1 -1
- package/lib/esm/function/asyncCallbackList.js.map +1 -1
- package/lib/esm/function/callbackList.d.ts.map +1 -1
- package/lib/esm/function/callbackList.js.map +1 -1
- package/lib/esm/function/delayCallbackList.d.ts.map +1 -1
- package/lib/esm/function/delayCallbackList.js +3 -3
- package/lib/esm/function/delayCallbackList.js.map +1 -1
- package/lib/esm/lifecycle/dispose/disposableEvent.d.ts +1 -1
- package/lib/esm/lifecycle/dispose/disposableEvent.d.ts.map +1 -1
- package/lib/esm/lifecycle/dispose/disposableEvent.js +1 -3
- package/lib/esm/lifecycle/dispose/disposableEvent.js.map +1 -1
- package/lib/esm/lifecycle/dispose/lifecycle.async.d.ts +2 -2
- package/lib/esm/lifecycle/dispose/lifecycle.async.d.ts.map +1 -1
- package/lib/esm/lifecycle/dispose/lifecycle.async.js.map +1 -1
- package/lib/esm/lifecycle/dispose/lifecycle.d.ts +1 -1
- package/lib/esm/lifecycle/dispose/lifecycle.d.ts.map +1 -1
- package/lib/esm/lifecycle/dispose/lifecycle.global.d.ts +1 -1
- package/lib/esm/lifecycle/dispose/lifecycle.global.d.ts.map +1 -1
- package/lib/esm/lifecycle/dispose/lifecycle.global.js +4 -8
- package/lib/esm/lifecycle/dispose/lifecycle.global.js.map +1 -1
- package/lib/esm/lifecycle/dispose/lifecycle.sync.d.ts +2 -2
- package/lib/esm/lifecycle/dispose/lifecycle.sync.d.ts.map +1 -1
- package/lib/esm/lifecycle/dispose/lifecycle.sync.js +1 -1
- package/lib/esm/lifecycle/dispose/lifecycle.sync.js.map +1 -1
- package/lib/esm/lifecycle/event/event.d.ts +3 -7
- package/lib/esm/lifecycle/event/event.d.ts.map +1 -1
- package/lib/esm/lifecycle/event/event.js.map +1 -1
- package/lib/esm/lifecycle/event/memorized.d.ts +2 -2
- package/lib/esm/lifecycle/event/memorized.d.ts.map +1 -1
- package/lib/esm/lifecycle/event/memorized.js +1 -1
- package/lib/esm/lifecycle/event/memorized.js.map +1 -1
- package/lib/esm/lifecycle/promise/cancellationToken/driver.common.js.map +1 -1
- package/lib/esm/lifecycle/promise/cancellationToken/source.d.ts +2 -2
- package/lib/esm/lifecycle/promise/cancellationToken/source.d.ts.map +1 -1
- package/lib/esm/lifecycle/promise/deferredPromise.js +2 -2
- package/lib/esm/lifecycle/promise/deferredPromise.js.map +1 -1
- package/lib/esm/lifecycle/timeout/timeout.js +1 -3
- package/lib/esm/lifecycle/timeout/timeout.js.map +1 -1
- package/lib/esm/lifecycle/timeout/timeoutError.d.ts.map +1 -1
- package/lib/esm/lifecycle/timeout/timeoutError.js.map +1 -1
- package/lib/esm/log/logger.d.ts.map +1 -1
- package/lib/esm/log/logger.js +4 -6
- package/lib/esm/log/logger.js.map +1 -1
- package/lib/esm/mapSet/customSet.d.ts +1 -3
- package/lib/esm/mapSet/customSet.d.ts.map +1 -1
- package/lib/esm/mapSet/customSet.js +3 -7
- package/lib/esm/mapSet/customSet.js.map +1 -1
- package/lib/esm/mapSet/extendMap.d.ts.map +1 -1
- package/lib/esm/mapSet/extendMap.js +5 -9
- package/lib/esm/mapSet/extendMap.js.map +1 -1
- package/lib/esm/misc/assertNotNull.d.ts.map +1 -1
- package/lib/esm/misc/assertNotNull.js +1 -3
- package/lib/esm/misc/assertNotNull.js.map +1 -1
- package/lib/esm/misc/package.json.js +1 -1
- package/lib/esm/misc/package.json.js.map +1 -1
- package/lib/esm/object/initOnRead.d.ts +1 -3
- package/lib/esm/object/initOnRead.d.ts.map +1 -1
- package/lib/esm/object/initOnRead.js.map +1 -1
- package/lib/esm/object/objectSame.js +2 -1
- package/lib/esm/object/objectSame.js.map +1 -1
- package/lib/esm/path/normalizePath.d.ts.map +1 -1
- package/lib/esm/path/normalizePath.js +7 -9
- package/lib/esm/path/normalizePath.js.map +1 -1
- package/lib/esm/path/pathArray.js +1 -1
- package/lib/esm/path/pathArray.js.map +1 -1
- package/lib/esm/platform/globalSingleton.js +1 -1
- package/lib/esm/platform/globalSymbol.d.ts.map +1 -1
- package/lib/esm/platform/globalSymbol.js +6 -8
- package/lib/esm/platform/globalSymbol.js.map +1 -1
- package/lib/esm/promise/promiseCollection.js +3 -3
- package/lib/esm/promise/promiseCollection.js.map +1 -1
- package/lib/esm/reflection/classes/hookClass.d.ts +1 -1
- package/lib/esm/reflection/classes/hookClass.d.ts.map +1 -1
- package/lib/esm/reflection/classes/singleton.d.ts.map +1 -1
- package/lib/esm/reflection/classes/singleton.js +1 -3
- package/lib/esm/reflection/classes/singleton.js.map +1 -1
- package/lib/esm/reflection/methods/bind.d.ts.map +1 -1
- package/lib/esm/reflection/methods/bind.js +1 -3
- package/lib/esm/reflection/methods/bind.js.map +1 -1
- package/lib/esm/reflection/methods/initOnRead.d.ts +1 -1
- package/lib/esm/reflection/methods/initOnRead.d.ts.map +1 -1
- package/lib/esm/reflection/methods/initOnRead.js +2 -2
- package/lib/esm/reflection/methods/initOnRead.js.map +1 -1
- package/lib/esm/string/castCase.js +5 -5
- package/lib/esm/string/castCase.js.map +1 -1
- package/lib/esm/string/pad2.d.ts.map +1 -1
- package/lib/esm/string/pad2.js +2 -4
- package/lib/esm/string/pad2.js.map +1 -1
- package/lib/esm/string/sizeString.d.ts.map +1 -1
- package/lib/esm/string/sizeString.js +23 -27
- package/lib/esm/string/sizeString.js.map +1 -1
- package/lib/esm/typingHelper/deep.partial.d.ts +1 -1
- package/lib/esm/typingHelper/deep.partial.d.ts.map +1 -1
- package/lib/esm/typingHelper/deep.readonly.d.ts +1 -1
- package/lib/esm/typingHelper/deep.readonly.d.ts.map +1 -1
- package/lib/esm/typingHelper/deep.required.d.ts +1 -1
- package/lib/esm/typingHelper/deep.required.d.ts.map +1 -1
- package/lib/esm/typingHelper/deep.writable.d.ts +1 -1
- package/lib/esm/typingHelper/deep.writable.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/array/arrayUnique.ts +3 -6
- package/src/array/normalizeArray.ts +3 -3
- package/src/array/sortAlpha.ts +3 -3
- package/src/date/isInvalid.ts +1 -1
- package/src/date/timeString.ts +9 -15
- package/src/debugging/serializable.ts +8 -8
- package/src/debugging/tryInspect.ts +12 -8
- package/src/error/convertUnknown.ts +2 -3
- package/src/error/getFrame.ts +2 -2
- package/src/error/known.ts +2 -2
- package/src/error/pretty.ts +29 -34
- package/src/function/asyncCallbackList.ts +3 -3
- package/src/function/callbackList.ts +2 -2
- package/src/function/delayCallbackList.ts +4 -4
- package/src/lifecycle/dispose/disposableEvent.ts +2 -3
- package/src/lifecycle/dispose/disposedError.ts +1 -1
- package/src/lifecycle/dispose/lifecycle.async.ts +2 -2
- package/src/lifecycle/dispose/lifecycle.global.ts +6 -7
- package/src/lifecycle/dispose/lifecycle.sync.ts +3 -3
- package/src/lifecycle/dispose/lifecycle.ts +1 -1
- package/src/lifecycle/event/event.ts +4 -8
- package/src/lifecycle/event/memorized.ts +4 -4
- package/src/lifecycle/promise/cancellationToken/driver.browser.ts +1 -1
- package/src/lifecycle/promise/cancellationToken/driver.common.ts +2 -2
- package/src/lifecycle/promise/cancellationToken/source.ts +2 -2
- package/src/lifecycle/promise/deferredPromise.ts +2 -2
- package/src/lifecycle/timeout/timeout.ts +1 -2
- package/src/lifecycle/timeout/timeoutError.ts +1 -1
- package/src/log/logger.ts +8 -9
- package/src/mapSet/customSet.ts +4 -8
- package/src/mapSet/extendMap.ts +6 -7
- package/src/misc/assertNotNull.ts +1 -2
- package/src/misc/package.json.ts +1 -1
- package/src/object/initOnRead.ts +1 -3
- package/src/object/objectSame.ts +2 -2
- package/src/path/normalizePath.ts +14 -17
- package/src/path/pathArray.ts +2 -2
- package/src/platform/globalSingleton.ts +1 -1
- package/src/platform/globalSymbol.ts +8 -9
- package/src/promise/promiseCollection.ts +3 -3
- package/src/reflection/classes/hookClass.ts +1 -1
- package/src/reflection/classes/singleton.ts +3 -4
- package/src/reflection/methods/bind.ts +1 -2
- package/src/reflection/methods/initOnRead.ts +3 -3
- package/src/string/castCase.ts +5 -5
- package/src/string/pad2.ts +2 -3
- package/src/string/sizeString.ts +33 -25
- package/src/tsconfig.json +1 -1
- package/src/typingHelper/deep.partial.ts +7 -7
- package/src/typingHelper/deep.readonly.ts +7 -7
- package/src/typingHelper/deep.required.ts +7 -7
- package/src/typingHelper/deep.writable.ts +7 -7
|
@@ -10,12 +10,12 @@ const winLetter = /^[a-z]:[\/\\]/i;
|
|
|
10
10
|
const doubleSlash = /^[\/\\]{2}[^\/\\]/i;
|
|
11
11
|
|
|
12
12
|
export enum PathKind {
|
|
13
|
-
url,
|
|
14
|
-
unc,
|
|
15
|
-
win,
|
|
16
|
-
cifs,
|
|
17
|
-
unix,
|
|
18
|
-
relative,
|
|
13
|
+
url = 0,
|
|
14
|
+
unc = 1,
|
|
15
|
+
win = 2,
|
|
16
|
+
cifs = 3,
|
|
17
|
+
unix = 4,
|
|
18
|
+
relative = 5,
|
|
19
19
|
}
|
|
20
20
|
export interface IPathInfo {
|
|
21
21
|
kind: PathKind;
|
|
@@ -31,18 +31,18 @@ export function analyzePath(p: string) {
|
|
|
31
31
|
const u = new URL(p);
|
|
32
32
|
r = {
|
|
33
33
|
kind: PathKind.url,
|
|
34
|
-
prefix: u.protocol
|
|
34
|
+
prefix: `${u.protocol}//${u.host}`,
|
|
35
35
|
path: u.pathname.slice(1),
|
|
36
36
|
url: u,
|
|
37
37
|
};
|
|
38
38
|
} else if (unc.test(p)) {
|
|
39
39
|
p = p.replace(unc, '').replace(/^[\/\\]+/, '');
|
|
40
40
|
const i = /[\///]/.exec(p)?.index ?? -1;
|
|
41
|
-
if (i <= 0) throw new Error(
|
|
41
|
+
if (i <= 0) throw new Error(`invalid unc path: ${inp}`);
|
|
42
42
|
|
|
43
43
|
r = {
|
|
44
44
|
kind: PathKind.unc,
|
|
45
|
-
prefix:
|
|
45
|
+
prefix: `//?/UNC/${p.slice(0, i)}`,
|
|
46
46
|
path: p.slice(i + 1),
|
|
47
47
|
};
|
|
48
48
|
} else if (winSp.test(p) || winLetter.test(p)) {
|
|
@@ -56,11 +56,11 @@ export function analyzePath(p: string) {
|
|
|
56
56
|
} else if (doubleSlash.test(p)) {
|
|
57
57
|
p = p.replace(/^[\/\\]+/, '');
|
|
58
58
|
const i = /[\///]/.exec(p)?.index ?? -1;
|
|
59
|
-
if (i <= 0) throw new Error(
|
|
59
|
+
if (i <= 0) throw new Error(`invalid cifs url: ${inp}`);
|
|
60
60
|
|
|
61
61
|
r = {
|
|
62
62
|
kind: PathKind.cifs,
|
|
63
|
-
prefix:
|
|
63
|
+
prefix: `//${p.slice(0, i)}`,
|
|
64
64
|
path: p.slice(i + 1),
|
|
65
65
|
};
|
|
66
66
|
} else if (p.startsWith('/')) {
|
|
@@ -103,9 +103,8 @@ export function normalizePath(p: string) {
|
|
|
103
103
|
|
|
104
104
|
if (r.prefix === undefined) {
|
|
105
105
|
return r.path;
|
|
106
|
-
} else {
|
|
107
|
-
return `${r.prefix}/${r.path}`;
|
|
108
106
|
}
|
|
107
|
+
return `${r.prefix}/${r.path}`;
|
|
109
108
|
}
|
|
110
109
|
|
|
111
110
|
export function relativePath(from: string, to: string) {
|
|
@@ -113,9 +112,7 @@ export function relativePath(from: string, to: string) {
|
|
|
113
112
|
const r2 = analyzePath(to);
|
|
114
113
|
if (r1.kind !== r2.kind)
|
|
115
114
|
throw new Error(
|
|
116
|
-
`cannot relative path between different kind: "${PathKind[r1.kind]}::${from}" * "${
|
|
117
|
-
PathKind[r2.kind]
|
|
118
|
-
}::${to}"`,
|
|
115
|
+
`cannot relative path between different kind: "${PathKind[r1.kind]}::${from}" * "${PathKind[r2.kind]}::${to}"`
|
|
119
116
|
);
|
|
120
117
|
|
|
121
118
|
if (r1.prefix !== r2.prefix) return to;
|
|
@@ -132,7 +129,7 @@ export function relativePath(from: string, to: string) {
|
|
|
132
129
|
p2arr.splice(0, i);
|
|
133
130
|
|
|
134
131
|
// add ..
|
|
135
|
-
const p1 = p1arr.length > 0 ? p1arr.map(() => '..').join('/')
|
|
132
|
+
const p1 = p1arr.length > 0 ? `${p1arr.map(() => '..').join('/')}/` : '';
|
|
136
133
|
const p2 = p2arr.join('/');
|
|
137
134
|
|
|
138
135
|
return p1 + p2;
|
package/src/path/pathArray.ts
CHANGED
|
@@ -10,7 +10,7 @@ const isAbsolute = /^[a-z]:[/\\]/i;
|
|
|
10
10
|
abstract class PathArrayAbstract extends Set<string> {
|
|
11
11
|
constructor(
|
|
12
12
|
init: string,
|
|
13
|
-
private readonly sep: ':' | ';' = isWindows ? ';' : ':'
|
|
13
|
+
private readonly sep: ':' | ';' = isWindows ? ';' : ':'
|
|
14
14
|
) {
|
|
15
15
|
super();
|
|
16
16
|
if (init) this.add(init);
|
|
@@ -44,7 +44,7 @@ abstract class PathArrayAbstract extends Set<string> {
|
|
|
44
44
|
* @returns an array with `part` append to every element
|
|
45
45
|
*/
|
|
46
46
|
join(part: string) {
|
|
47
|
-
return [...this.values()].map((p) => normalizePath(p
|
|
47
|
+
return [...this.values()].map((p) => normalizePath(`${p}/${part}`));
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { functionName } from '../function/functionName.js';
|
|
2
2
|
import { ensureGlobalObject } from './globalObject.js';
|
|
3
3
|
|
|
4
|
-
const singletonRegistry = ensureGlobalObject(
|
|
4
|
+
const singletonRegistry = ensureGlobalObject('@@idlebox/global-singleton', () => {
|
|
5
5
|
return new Map<string | symbol, any>();
|
|
6
6
|
});
|
|
7
7
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ensureGlobalObject } from './globalObject.js';
|
|
2
2
|
|
|
3
|
-
const symbolRegistry = ensureGlobalObject(
|
|
3
|
+
const symbolRegistry = ensureGlobalObject('@@idlebox/global-symbol', () => {
|
|
4
4
|
return {} as Record<string, Record<string, symbol>>;
|
|
5
5
|
});
|
|
6
6
|
|
|
@@ -12,15 +12,14 @@ const symbolRegistry = ensureGlobalObject(`@@idlebox/global-symbol`, () => {
|
|
|
12
12
|
*/
|
|
13
13
|
export function createSymbol(category: string, name: string): symbol {
|
|
14
14
|
if (symbolRegistry[category]?.[name]) {
|
|
15
|
-
return symbolRegistry[category]
|
|
16
|
-
} else {
|
|
17
|
-
if (!symbolRegistry[category]) {
|
|
18
|
-
symbolRegistry[category] = {};
|
|
19
|
-
}
|
|
20
|
-
const c = symbolRegistry[category]!;
|
|
21
|
-
|
|
22
|
-
return (c[name] = Symbol(name));
|
|
15
|
+
return symbolRegistry[category]?.[name]!;
|
|
23
16
|
}
|
|
17
|
+
if (!symbolRegistry[category]) {
|
|
18
|
+
symbolRegistry[category] = {};
|
|
19
|
+
}
|
|
20
|
+
const c = symbolRegistry[category]!;
|
|
21
|
+
|
|
22
|
+
return (c[name] = Symbol(name));
|
|
24
23
|
}
|
|
25
24
|
|
|
26
25
|
/**
|
|
@@ -10,7 +10,7 @@ export class PromiseCollection {
|
|
|
10
10
|
|
|
11
11
|
create(id: string) {
|
|
12
12
|
if (this.promiseList[id]) {
|
|
13
|
-
throw new Error(
|
|
13
|
+
throw new Error(`duplicate promise with id ${id}`);
|
|
14
14
|
}
|
|
15
15
|
const dfd = new DeferredPromise<any>();
|
|
16
16
|
this.promiseList[id] = dfd;
|
|
@@ -22,12 +22,12 @@ export class PromiseCollection {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
done(id: string, data: any) {
|
|
25
|
-
this.promiseList[id]
|
|
25
|
+
this.promiseList[id]?.complete(data);
|
|
26
26
|
delete this.promiseList[id];
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
error(id: string, e: Error) {
|
|
30
|
-
this.promiseList[id]
|
|
30
|
+
this.promiseList[id]?.error(e);
|
|
31
31
|
delete this.promiseList[id];
|
|
32
32
|
}
|
|
33
33
|
|
|
@@ -6,7 +6,7 @@ interface IConstructorOf<T> extends Object {
|
|
|
6
6
|
|
|
7
7
|
interface IHooks<T, TC> {
|
|
8
8
|
afterConstruct?: ((obj: T) => void)[];
|
|
9
|
-
beforeConstruct?: ((obj: TC) => T |
|
|
9
|
+
beforeConstruct?: ((obj: TC) => T | undefined)[];
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export function hookClass<TC extends IConstructorOf<T>, T>(target: TC): IHooks<T, TC> {
|
|
@@ -3,8 +3,8 @@ import { hookClass } from './hookClass.js';
|
|
|
3
3
|
export const singletonSymbol = Symbol('@gongt/singleton');
|
|
4
4
|
|
|
5
5
|
export enum SingletonType {
|
|
6
|
-
Throw,
|
|
7
|
-
Return,
|
|
6
|
+
Throw = 0,
|
|
7
|
+
Return = 1,
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export function singleton(type: SingletonType = SingletonType.Return): ClassDecorator {
|
|
@@ -21,9 +21,8 @@ export function singleton(type: SingletonType = SingletonType.Return): ClassDeco
|
|
|
21
21
|
if (cls[singletonSymbol]) {
|
|
22
22
|
if (type === SingletonType.Return) {
|
|
23
23
|
return cls[singletonSymbol];
|
|
24
|
-
} else {
|
|
25
|
-
throw new Error(`Duplicate new singleton class [${target.name}]`);
|
|
26
24
|
}
|
|
25
|
+
throw new Error(`Duplicate new singleton class [${target.name}]`);
|
|
27
26
|
}
|
|
28
27
|
});
|
|
29
28
|
hook.afterConstruct.push((obj) => {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { InitFunc, initOnRead } from '../../object/initOnRead.js';
|
|
1
|
+
import { type InitFunc, initOnRead } from '../../object/initOnRead.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Decorater version of `initOnRead`
|
|
5
5
|
* @see initOnRead
|
|
6
6
|
*/
|
|
7
7
|
export function init<O, T extends keyof O>(init: InitFunc<O, O[T]>): PropertyDecorator {
|
|
8
|
-
return
|
|
8
|
+
return ((target: O, propertyKey: T) => {
|
|
9
9
|
initOnRead<O, T>(target, propertyKey, init);
|
|
10
|
-
} as any;
|
|
10
|
+
}) as any;
|
|
11
11
|
}
|
package/src/string/castCase.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export function camelCase(str: string) {
|
|
3
3
|
return str
|
|
4
4
|
.replace(/[-.\/_]+[a-z]/g, (s) => {
|
|
5
|
-
return s[1]
|
|
5
|
+
return s[1]?.toUpperCase();
|
|
6
6
|
})
|
|
7
7
|
.replace(/[-.\/_]+/g, '');
|
|
8
8
|
}
|
|
@@ -12,7 +12,7 @@ export function camelCase(str: string) {
|
|
|
12
12
|
* @public
|
|
13
13
|
*/
|
|
14
14
|
export function ucfirst<T extends string>(str: T): Capitalize<T> {
|
|
15
|
-
return <any>(str[0]
|
|
15
|
+
return <any>(str[0]?.toUpperCase() + str.slice(1));
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/**
|
|
@@ -20,7 +20,7 @@ export function ucfirst<T extends string>(str: T): Capitalize<T> {
|
|
|
20
20
|
* @public
|
|
21
21
|
*/
|
|
22
22
|
export function lcfirst<T extends string>(str: T): Uncapitalize<T> {
|
|
23
|
-
return <any>(str[0]
|
|
23
|
+
return <any>(str[0]?.toLowerCase() + str.slice(1));
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
/** @public */
|
|
@@ -30,7 +30,7 @@ export function linux_case(str: string) {
|
|
|
30
30
|
return s.toLowerCase();
|
|
31
31
|
})
|
|
32
32
|
.replace(/[A-Z]+/g, (s) => {
|
|
33
|
-
return
|
|
33
|
+
return `_${s.toLowerCase()}`;
|
|
34
34
|
})
|
|
35
35
|
.replace(/[-.\/_]+/g, '_');
|
|
36
36
|
}
|
|
@@ -42,7 +42,7 @@ export function linux_case_hyphen(str: string) {
|
|
|
42
42
|
return s.toLowerCase();
|
|
43
43
|
})
|
|
44
44
|
.replace(/[A-Z]+/g, (s) => {
|
|
45
|
-
return
|
|
45
|
+
return `-${s.toLowerCase()}`;
|
|
46
46
|
})
|
|
47
47
|
.replace(/[-.\/_]+/g, '-');
|
|
48
48
|
}
|
package/src/string/pad2.ts
CHANGED
package/src/string/sizeString.ts
CHANGED
|
@@ -5,19 +5,23 @@
|
|
|
5
5
|
export function humanSizeSI(bytes: number, fixed = 2) {
|
|
6
6
|
if (bytes < 0) {
|
|
7
7
|
return '<0B';
|
|
8
|
-
} else if (bytes < 1000) {
|
|
9
|
-
return bytes + 'B';
|
|
10
|
-
} else if (bytes < 1000000) {
|
|
11
|
-
return (bytes / 1000).toFixed(fixed) + 'KiB';
|
|
12
|
-
} else if (bytes < 1000000000) {
|
|
13
|
-
return (bytes / 1000000).toFixed(fixed) + 'MiB';
|
|
14
|
-
} else if (bytes < 1000000000000) {
|
|
15
|
-
return (bytes / 1000000000).toFixed(fixed) + 'GiB';
|
|
16
|
-
} else if (bytes < 1000000000000000) {
|
|
17
|
-
return (bytes / 1000000000000).toFixed(fixed) + 'TiB';
|
|
18
|
-
} else {
|
|
19
|
-
return (bytes / 1000000000000000).toFixed(fixed) + 'PiB';
|
|
20
8
|
}
|
|
9
|
+
if (bytes < 1000) {
|
|
10
|
+
return `${bytes}B`;
|
|
11
|
+
}
|
|
12
|
+
if (bytes < 1000000) {
|
|
13
|
+
return `${(bytes / 1000).toFixed(fixed)}KiB`;
|
|
14
|
+
}
|
|
15
|
+
if (bytes < 1000000000) {
|
|
16
|
+
return `${(bytes / 1000000).toFixed(fixed)}MiB`;
|
|
17
|
+
}
|
|
18
|
+
if (bytes < 1000000000000) {
|
|
19
|
+
return `${(bytes / 1000000000).toFixed(fixed)}GiB`;
|
|
20
|
+
}
|
|
21
|
+
if (bytes < 1000000000000000) {
|
|
22
|
+
return `${(bytes / 1000000000000).toFixed(fixed)}TiB`;
|
|
23
|
+
}
|
|
24
|
+
return `${(bytes / 1000000000000000).toFixed(fixed)}PiB`;
|
|
21
25
|
}
|
|
22
26
|
|
|
23
27
|
/**
|
|
@@ -27,26 +31,30 @@ export function humanSizeSI(bytes: number, fixed = 2) {
|
|
|
27
31
|
export function humanSize(bytes: number, fixed = 2) {
|
|
28
32
|
if (bytes < 0) {
|
|
29
33
|
return '<0B';
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
34
|
+
}
|
|
35
|
+
if (bytes < 1024) {
|
|
36
|
+
return `${bytes}B`;
|
|
37
|
+
}
|
|
38
|
+
if (bytes < 1048576) {
|
|
33
39
|
// 1024 * 1024
|
|
34
|
-
return (bytes / 1024).toFixed(fixed)
|
|
35
|
-
}
|
|
40
|
+
return `${(bytes / 1024).toFixed(fixed)}KiB`;
|
|
41
|
+
}
|
|
42
|
+
if (bytes < 1073741824) {
|
|
36
43
|
// 1024 * 1024 * 1024
|
|
37
|
-
return (bytes / 1048576).toFixed(fixed)
|
|
38
|
-
}
|
|
44
|
+
return `${(bytes / 1048576).toFixed(fixed)}MiB`;
|
|
45
|
+
}
|
|
46
|
+
if (bytes < 1099511627776) {
|
|
39
47
|
// 1024 * 1024 * 1024 * 1024
|
|
40
|
-
return (bytes / 1073741824).toFixed(fixed)
|
|
41
|
-
}
|
|
48
|
+
return `${(bytes / 1073741824).toFixed(fixed)}GiB`;
|
|
49
|
+
}
|
|
50
|
+
if (bytes < 1125899906842624) {
|
|
42
51
|
// 1024 * 1024 * 1024 * 1024 * 1024
|
|
43
|
-
return (bytes / 1099511627776).toFixed(fixed)
|
|
44
|
-
} else {
|
|
45
|
-
return (bytes / 1125899906842624).toFixed(fixed) + 'PiB';
|
|
52
|
+
return `${(bytes / 1099511627776).toFixed(fixed)}TiB`;
|
|
46
53
|
}
|
|
54
|
+
return `${(bytes / 1125899906842624).toFixed(fixed)}PiB`;
|
|
47
55
|
}
|
|
48
56
|
|
|
49
57
|
/** @deprecated */
|
|
50
58
|
export function humanSpeed(bps: number) {
|
|
51
|
-
return humanSize(bps)
|
|
59
|
+
return `${humanSize(bps)}/s`;
|
|
52
60
|
}
|
package/src/tsconfig.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { Primitive } from './literal.js';
|
|
1
|
+
import type { Primitive } from './literal.js';
|
|
2
2
|
|
|
3
3
|
export type DeepPartial<T> = T extends Primitive
|
|
4
4
|
? T
|
|
5
5
|
: T extends ReadonlyArray<infer U>
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
? DeepPartialArray<U>
|
|
7
|
+
: T extends ReadonlyMap<infer K, infer V>
|
|
8
|
+
? DeepPartialMap<K, V>
|
|
9
|
+
: T extends ReadonlySet<infer M>
|
|
10
|
+
? DeepPartialSet<M>
|
|
11
|
+
: DeepPartialObject<T>;
|
|
12
12
|
|
|
13
13
|
type DeepPartialArray<T> = Array<DeepPartial<T>>;
|
|
14
14
|
type DeepPartialMap<K, V> = Map<DeepPartial<K>, DeepPartial<V>>;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { Primitive } from './literal.js';
|
|
1
|
+
import type { Primitive } from './literal.js';
|
|
2
2
|
|
|
3
3
|
export type DeepReadonly<T> = T extends Primitive
|
|
4
4
|
? T
|
|
5
5
|
: T extends Array<infer U>
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
? DeepReadonlyArray<U>
|
|
7
|
+
: T extends Map<infer K, infer V>
|
|
8
|
+
? DeepReadonlyMap<K, V>
|
|
9
|
+
: T extends Set<infer M>
|
|
10
|
+
? DeepReadonlySet<M>
|
|
11
|
+
: DeepReadonlyObject<T>;
|
|
12
12
|
|
|
13
13
|
type DeepReadonlyArray<T> = ReadonlyArray<DeepReadonly<T>>;
|
|
14
14
|
type DeepReadonlyMap<K, V> = ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>>;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { Primitive } from './literal.js';
|
|
1
|
+
import type { Primitive } from './literal.js';
|
|
2
2
|
|
|
3
3
|
export type DeepNonNullable<T> = T extends Primitive
|
|
4
4
|
? T
|
|
5
5
|
: T extends ReadonlyArray<infer U> | Array<infer U>
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
? DeepNonNullableArray<U>
|
|
7
|
+
: T extends ReadonlyMap<infer K, infer V> | Map<infer K, infer V>
|
|
8
|
+
? DeepNonNullableMap<K, V>
|
|
9
|
+
: T extends ReadonlySet<infer M>
|
|
10
|
+
? DeepNonNullableSet<M>
|
|
11
|
+
: DeepNonNullableObject<T>;
|
|
12
12
|
|
|
13
13
|
type DeepNonNullableArray<T> = Array<DeepNonNullable<T>>;
|
|
14
14
|
type DeepNonNullableMap<K, V> = Map<DeepNonNullable<K>, DeepNonNullable<V>>;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { Primitive } from './literal.js';
|
|
1
|
+
import type { Primitive } from './literal.js';
|
|
2
2
|
|
|
3
3
|
export type DeepWriteable<T> = T extends Primitive
|
|
4
4
|
? T
|
|
5
5
|
: T extends ReadonlyArray<infer U>
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
? DeepWriteableArray<U>
|
|
7
|
+
: T extends ReadonlyMap<infer K, infer V>
|
|
8
|
+
? DeepWriteableMap<K, V>
|
|
9
|
+
: T extends ReadonlySet<infer M>
|
|
10
|
+
? DeepWriteableSet<M>
|
|
11
|
+
: DeepWriteableObject<T>;
|
|
12
12
|
|
|
13
13
|
type DeepWriteableArray<T> = Array<DeepWriteable<T>>;
|
|
14
14
|
type DeepWriteableMap<K, V> = Map<DeepWriteable<K>, DeepWriteable<V>>;
|