@tstdl/base 0.90.57 → 0.90.59
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/.eslintrc.json +136 -116
- package/json-path/json-path.d.ts +11 -9
- package/json-path/json-path.js +9 -6
- package/jsx/render-to-string.d.ts +2 -0
- package/jsx/render-to-string.js +9 -3
- package/package.json +9 -9
- package/queue/mongo/queue.provider.d.ts +2 -4
- package/random/series.d.ts +1 -1
- package/schema/constraints/maximum.d.ts +1 -1
- package/schema/constraints/minimum-date.d.ts +1 -1
- package/schema/constraints/minimum.d.ts +1 -1
- package/schema/constraints/pattern.d.ts +1 -1
- package/schema/types/types.d.ts +2 -2
- package/search-index/elastic/query-builder/boolean-query-builder.d.ts +1 -4
- package/search-index/elastic/query-builder/boolean-query-builder.js +23 -23
- package/templates/renderers/jsx.template-renderer.d.ts +1 -1
- package/templates/renderers/jsx.template-renderer.js +3 -3
- package/theme/theme-service.d.ts +1 -1
- package/theme/theme-service.js +3 -2
- package/types.d.ts +26 -12
- package/utils/async-iterable-helpers/to-async-iterator.js +2 -2
- package/utils/async-iterator-iterable-iterator.js +3 -3
- package/utils/base64.js +1 -1
- package/utils/cryptography.d.ts +13 -13
- package/utils/cryptography.js +12 -12
- package/utils/date-time.js +1 -1
- package/utils/encoding.d.ts +6 -6
- package/utils/encoding.js +6 -6
- package/utils/enum.js +9 -15
- package/utils/equals.js +3 -2
- package/utils/format-error.d.ts +5 -5
- package/utils/format.js +7 -6
- package/utils/helpers.d.ts +9 -9
- package/utils/helpers.js +3 -3
- package/utils/object/decycle.d.ts +2 -2
- package/utils/object/decycle.js +8 -8
- package/utils/object/dereference.d.ts +4 -4
- package/utils/object/dereference.js +4 -4
- package/utils/object/forward-ref.js +2 -2
- package/utils/object/lazy-property.d.ts +9 -9
- package/utils/object/lazy-property.js +4 -3
- package/utils/object/merge.d.ts +1 -1
- package/utils/object/merge.js +3 -3
- package/utils/object/object.d.ts +2 -2
- package/utils/object/object.js +2 -2
- package/utils/object/property-name.d.ts +15 -15
- package/utils/object/property-name.js +12 -12
- package/utils/patch-worker.d.ts +3 -3
- package/utils/patterns.d.ts +2 -2
- package/utils/patterns.js +3 -3
- package/utils/periodic-reporter.d.ts +1 -1
- package/utils/periodic-sampler.d.ts +1 -1
- package/utils/periodic-sampler.js +7 -5
- package/utils/random.d.ts +2 -2
- package/utils/random.js +2 -2
- package/utils/reactive-value-to-signal.d.ts +1 -1
- package/utils/reactive-value-to-signal.js +1 -1
- package/utils/repl.js +1 -0
- package/utils/singleton.d.ts +5 -4
- package/utils/singleton.js +3 -3
- package/utils/stream/finalize-stream.d.ts +5 -5
- package/utils/stream/readable-stream-adapter.d.ts +1 -1
- package/utils/stream/readable-stream-adapter.js +2 -2
- package/utils/stream/readable-stream-from-promise.d.ts +1 -1
- package/utils/stream/slice.js +1 -1
- package/utils/stream/to-bytes-stream.js +4 -4
- package/utils/timing.d.ts +5 -5
- package/utils/timing.js +4 -4
- package/utils/type-guards.js +1 -1
- package/utils/type-of.d.ts +3 -2
- package/utils/type-of.js +1 -1
- package/utils/units.js +3 -2
- package/utils/url-builder.js +3 -3
- package/utils/value-or-provider.js +1 -1
- package/utils/z-base32.js +1 -3
- package/web-types.d.ts +1 -1
package/utils/format.js
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
|
+
import { kibibyte, kilobyte, microsecondsPerMillisecond, millisecondsPerSecond, nanosecondsPerMillisecond } from './units.js';
|
|
1
2
|
const siByteSizes = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
2
3
|
const iecByteSizes = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
|
|
3
4
|
export function formatDuration(milliseconds, precision) {
|
|
4
5
|
let value;
|
|
5
6
|
let suffix;
|
|
6
|
-
if (milliseconds >=
|
|
7
|
-
value = milliseconds /
|
|
7
|
+
if (milliseconds >= millisecondsPerSecond) {
|
|
8
|
+
value = milliseconds / millisecondsPerSecond;
|
|
8
9
|
suffix = 's';
|
|
9
10
|
}
|
|
10
11
|
else if (milliseconds >= 1) {
|
|
11
12
|
value = milliseconds;
|
|
12
13
|
suffix = 'ms';
|
|
13
14
|
}
|
|
14
|
-
else if (milliseconds >= 1 /
|
|
15
|
-
value = milliseconds *
|
|
15
|
+
else if (milliseconds >= 1 / microsecondsPerMillisecond) {
|
|
16
|
+
value = milliseconds * microsecondsPerMillisecond;
|
|
16
17
|
suffix = 'us';
|
|
17
18
|
}
|
|
18
19
|
else {
|
|
19
|
-
value = milliseconds *
|
|
20
|
+
value = milliseconds * nanosecondsPerMillisecond;
|
|
20
21
|
suffix = 'ns';
|
|
21
22
|
}
|
|
22
23
|
const trimmed = parseFloat(value.toFixed(precision));
|
|
@@ -25,7 +26,7 @@ export function formatDuration(milliseconds, precision) {
|
|
|
25
26
|
}
|
|
26
27
|
export function formatBytes(bytes, { decimals = 2, unit = 'IEC' } = {}) {
|
|
27
28
|
const iec = unit == 'IEC';
|
|
28
|
-
const base = iec ?
|
|
29
|
+
const base = iec ? kibibyte : kilobyte;
|
|
29
30
|
const exponent = Math.floor(Math.log(bytes) / Math.log(base));
|
|
30
31
|
const prefix = (iec ? iecByteSizes : siByteSizes)[exponent];
|
|
31
32
|
const result = (bytes / (base ** exponent));
|
package/utils/helpers.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { DeepArray, Record } from '../types.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Create an structured clone of an value using Notification if available, otherwise history state (may alters history)
|
|
4
4
|
*
|
|
5
5
|
* may not work in every environment!
|
|
6
6
|
* @param value value to clone
|
|
@@ -8,7 +8,7 @@ import type { DeepArray, Record } from '../types.js';
|
|
|
8
8
|
*/
|
|
9
9
|
export declare function structuredClone<T>(value: T): T;
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Create an structured clone of an value using a MessageChannel
|
|
12
12
|
*
|
|
13
13
|
* should work in all environments
|
|
14
14
|
* @param value value to clone
|
|
@@ -27,39 +27,39 @@ export declare function parseFirstAndFamilyName(name: string): {
|
|
|
27
27
|
};
|
|
28
28
|
export type NormalizeTextOptions = {
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
30
|
+
* Remove leading and trailing whitespace
|
|
31
31
|
*/
|
|
32
32
|
trim?: boolean;
|
|
33
33
|
/**
|
|
34
|
-
*
|
|
34
|
+
* Lowercase all characters
|
|
35
35
|
*/
|
|
36
36
|
lowercase?: boolean;
|
|
37
37
|
/**
|
|
38
|
-
*
|
|
38
|
+
* Remove multiple consecutive whitespace characters
|
|
39
39
|
*/
|
|
40
40
|
multipleWhitespace?: boolean;
|
|
41
41
|
/**
|
|
42
|
-
*
|
|
42
|
+
* Remove diacritics (è -> e)
|
|
43
43
|
*
|
|
44
44
|
* applies unicode NFD normalization and removes diacritics
|
|
45
45
|
* @see unicode option
|
|
46
46
|
*/
|
|
47
47
|
diacritics?: boolean;
|
|
48
48
|
/**
|
|
49
|
-
*
|
|
49
|
+
* Replace ligatures with their consecutive characters (æ -> ae)
|
|
50
50
|
*
|
|
51
51
|
* applies unicode NFKC normalization
|
|
52
52
|
* @see unicode option
|
|
53
53
|
*/
|
|
54
54
|
ligatures?: boolean;
|
|
55
55
|
/**
|
|
56
|
-
*
|
|
56
|
+
* Unicode normalization
|
|
57
57
|
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize
|
|
58
58
|
*/
|
|
59
59
|
unicode?: 'NFC' | 'NFD' | 'NFKC' | 'NFKD';
|
|
60
60
|
};
|
|
61
61
|
/**
|
|
62
|
-
*
|
|
62
|
+
* Trims, lowercases, replaces multi-character whitespace with a single space and unicode normalization
|
|
63
63
|
* @param text text to normalize
|
|
64
64
|
* @param options specify what to normalize. Defaults to all except unicode
|
|
65
65
|
* @returns normalized text
|
package/utils/helpers.js
CHANGED
|
@@ -4,7 +4,7 @@ import { DetailsError } from '../errors/details.error.js';
|
|
|
4
4
|
import { decycle } from './object/decycle.js';
|
|
5
5
|
import { isDefined } from './type-guards.js';
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Create an structured clone of an value using Notification if available, otherwise history state (may alters history)
|
|
8
8
|
*
|
|
9
9
|
* may not work in every environment!
|
|
10
10
|
* @param value value to clone
|
|
@@ -21,7 +21,7 @@ export function structuredClone(value) {
|
|
|
21
21
|
return copy;
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
24
|
+
* Create an structured clone of an value using a MessageChannel
|
|
25
25
|
*
|
|
26
26
|
* should work in all environments
|
|
27
27
|
* @param value value to clone
|
|
@@ -70,7 +70,7 @@ export function parseFirstAndFamilyName(name) {
|
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
72
|
/**
|
|
73
|
-
*
|
|
73
|
+
* Trims, lowercases, replaces multi-character whitespace with a single space and unicode normalization
|
|
74
74
|
* @param text text to normalize
|
|
75
75
|
* @param options specify what to normalize. Defaults to all except unicode
|
|
76
76
|
* @returns normalized text
|
|
@@ -3,13 +3,13 @@ export type Decycled<T> = {
|
|
|
3
3
|
__type: T;
|
|
4
4
|
} & Record<string>;
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Replaces cycles (circular references) in objects with JSONPath
|
|
7
7
|
* @param value object to decycle
|
|
8
8
|
* @param replacer replace values. Like JSON.stringify(value, *replacer*)
|
|
9
9
|
*/
|
|
10
10
|
export declare function decycle<T>(value: T, replacer?: (value: any) => any): Decycled<T>;
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Replaces JSONPath in objects with their reference
|
|
13
13
|
* @param value object to recycle
|
|
14
14
|
*/
|
|
15
15
|
export declare function recycle<T = any>(value: Decycled<T>, clone?: boolean): T;
|
package/utils/object/decycle.js
CHANGED
|
@@ -6,7 +6,7 @@ import { hasOwnProperty, mapObjectValues, objectKeys } from './object.js';
|
|
|
6
6
|
export function decycle(_value, replacer) {
|
|
7
7
|
const mapping = new Map();
|
|
8
8
|
const replacerFn = isDefined(replacer) ? replacer : (value) => value;
|
|
9
|
-
function
|
|
9
|
+
function decycleInternal(__value, path) {
|
|
10
10
|
const value = replacerFn(__value);
|
|
11
11
|
if (isPrimitive(value) || isRegExp(value) || isDate(value) || isFunction(value)) {
|
|
12
12
|
return value;
|
|
@@ -17,11 +17,11 @@ export function decycle(_value, replacer) {
|
|
|
17
17
|
}
|
|
18
18
|
mapping.set(value, path);
|
|
19
19
|
if (isArray(value)) {
|
|
20
|
-
return value.map((item, index) =>
|
|
20
|
+
return value.map((item, index) => decycleInternal(item, path.add(index)));
|
|
21
21
|
}
|
|
22
|
-
return mapObjectValues(value, (item, key) =>
|
|
22
|
+
return mapObjectValues(value, (item, key) => decycleInternal(item, path.add(key)));
|
|
23
23
|
}
|
|
24
|
-
return
|
|
24
|
+
return decycleInternal(_value, JsonPath.ROOT);
|
|
25
25
|
}
|
|
26
26
|
export function recycle(_value, _clone = true) {
|
|
27
27
|
const value = _clone ? clone(_value, true) : _value;
|
|
@@ -35,7 +35,7 @@ export function recycle(_value, _clone = true) {
|
|
|
35
35
|
}
|
|
36
36
|
return undefined;
|
|
37
37
|
}
|
|
38
|
-
function
|
|
38
|
+
function recycleInternal(node) {
|
|
39
39
|
if (isWritableArray(node)) {
|
|
40
40
|
for (let i = 0; i < node.length; i++) {
|
|
41
41
|
const ref = getRef(node[i]);
|
|
@@ -43,7 +43,7 @@ export function recycle(_value, _clone = true) {
|
|
|
43
43
|
node[i] = deref(value, ref);
|
|
44
44
|
}
|
|
45
45
|
else {
|
|
46
|
-
|
|
46
|
+
recycleInternal(node[i]);
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
}
|
|
@@ -54,11 +54,11 @@ export function recycle(_value, _clone = true) {
|
|
|
54
54
|
node[key] = deref(value, ref);
|
|
55
55
|
}
|
|
56
56
|
else {
|
|
57
|
-
|
|
57
|
+
recycleInternal(node[key]);
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
|
-
|
|
62
|
+
recycleInternal(value);
|
|
63
63
|
return value;
|
|
64
64
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type JsonPathInput } from '../../json-path/index.js';
|
|
2
2
|
export type CompiledDereferencer = (object: object) => unknown;
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Compiles a dereferencer for a specific reference
|
|
5
5
|
* @param object object to dereference
|
|
6
6
|
* @param reference path to property in dot notation or {@link JsonPath}
|
|
7
7
|
* @returns referenced value
|
|
8
8
|
*/
|
|
9
9
|
export declare function compileDereferencer(reference: JsonPathInput): (object: object) => unknown;
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Dereference a reference
|
|
12
12
|
*
|
|
13
13
|
* @description useful if you dereference a reference a few times at most
|
|
14
14
|
*
|
|
@@ -19,7 +19,7 @@ export declare function compileDereferencer(reference: JsonPathInput): (object:
|
|
|
19
19
|
*/
|
|
20
20
|
export declare function dereference(object: object, reference: JsonPathInput): unknown;
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* Cached version of {@link dereference}. It caches the internally used dereferencer, but it does *not* cache the referenced value
|
|
23
23
|
*
|
|
24
24
|
* @description
|
|
25
25
|
* useful if you dereference multiple references, each multiple times
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { JsonPath } from '../../json-path/index.js';
|
|
2
2
|
import { memoizeSingle } from '../function/memoize.js';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Compiles a dereferencer for a specific reference
|
|
5
5
|
* @param object object to dereference
|
|
6
6
|
* @param reference path to property in dot notation or {@link JsonPath}
|
|
7
7
|
* @returns referenced value
|
|
8
8
|
*/
|
|
9
9
|
export function compileDereferencer(reference) {
|
|
10
|
-
const nodes =
|
|
10
|
+
const nodes = JsonPath.from(reference).nodes;
|
|
11
11
|
function dereferencer(object) {
|
|
12
12
|
let target = object;
|
|
13
13
|
for (let i = 0; i < nodes.length; i++) { // eslint-disable-line @typescript-eslint/prefer-for-of
|
|
@@ -18,7 +18,7 @@ export function compileDereferencer(reference) {
|
|
|
18
18
|
return dereferencer;
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
21
|
+
* Dereference a reference
|
|
22
22
|
*
|
|
23
23
|
* @description useful if you dereference a reference a few times at most
|
|
24
24
|
*
|
|
@@ -31,7 +31,7 @@ export function dereference(object, reference) {
|
|
|
31
31
|
return compileDereferencer(reference)(object);
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
|
-
*
|
|
34
|
+
* Cached version of {@link dereference}. It caches the internally used dereferencer, but it does *not* cache the referenced value
|
|
35
35
|
*
|
|
36
36
|
* @description
|
|
37
37
|
* useful if you dereference multiple references, each multiple times
|
|
@@ -54,9 +54,9 @@ function getForwardRefProxy(context) {
|
|
|
54
54
|
}
|
|
55
55
|
function getContext(options) {
|
|
56
56
|
const reference = isDefined(options?.reference)
|
|
57
|
-
? { value: options
|
|
57
|
+
? { value: options.reference }
|
|
58
58
|
: isDefined(options?.initializer)
|
|
59
|
-
? { initializer: options
|
|
59
|
+
? { initializer: options.initializer }
|
|
60
60
|
: { value: undefined };
|
|
61
61
|
return lazyObject({
|
|
62
62
|
reference
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import type { IfUnknown } from '../../types.js';
|
|
1
|
+
import type { AnyFunction, IfUnknown } from '../../types.js';
|
|
2
2
|
declare const lazyObjectValueSymbol: unique symbol;
|
|
3
3
|
export type LazyPropertyInitializer<T, K extends keyof T> = (this: T, key: K) => T[K];
|
|
4
4
|
export type LazyPropertyObjectDefinition<T extends object, P extends keyof T> = LazyPropertyDescriptor & {
|
|
5
|
-
/**
|
|
5
|
+
/** Define property with existing value */
|
|
6
6
|
value?: T[P];
|
|
7
|
-
/**
|
|
7
|
+
/** Define property with getter */
|
|
8
8
|
get?: (this: T) => T[P];
|
|
9
|
-
/**
|
|
9
|
+
/** Define property with setter */
|
|
10
10
|
set?: (this: T, value: T[P]) => void;
|
|
11
|
-
/**
|
|
11
|
+
/** Lazily define property with initializer */
|
|
12
12
|
initializer?: LazyPropertyInitializer<T, P>;
|
|
13
13
|
};
|
|
14
14
|
export type LazyObjectValue<T> = {
|
|
15
15
|
[lazyObjectValueSymbol]: typeof lazyObjectValueSymbol;
|
|
16
16
|
value: T;
|
|
17
17
|
};
|
|
18
|
-
export type LazyInitializerItem<T extends object, P extends keyof T> = Exclude<IfUnknown<T[P], never, T[P]>,
|
|
18
|
+
export type LazyInitializerItem<T extends object, P extends keyof T> = Exclude<IfUnknown<T[P], never, T[P]>, AnyFunction | object> | LazyPropertyInitializer<T, P> | LazyPropertyObjectDefinition<T, P> | LazyObjectValue<T[P]>;
|
|
19
19
|
export type LazyPropertyDescriptor = {
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
21
|
+
* True if the type of this property descriptor may be changed and if the property may be deleted from the corresponding object
|
|
22
22
|
* @default true
|
|
23
23
|
*/
|
|
24
24
|
configurable?: boolean;
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
26
|
+
* True if and only if this property shows up during enumeration of the properties on the corresponding object
|
|
27
27
|
* @default true
|
|
28
28
|
*/
|
|
29
29
|
enumerable?: boolean;
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
31
|
+
* True if the value associated with the property may be changed with an assignment operator
|
|
32
32
|
* @default true
|
|
33
33
|
*/
|
|
34
34
|
writable?: boolean;
|
|
@@ -23,14 +23,15 @@ export function lazyProperty(object, propertyKey, initializer, descriptor = {})
|
|
|
23
23
|
}
|
|
24
24
|
return _value;
|
|
25
25
|
},
|
|
26
|
-
set:
|
|
27
|
-
|
|
26
|
+
set: writable
|
|
27
|
+
? function set(value) {
|
|
28
28
|
if (configurable) {
|
|
29
29
|
Object.defineProperty(object, propertyKey, { configurable, enumerable, writable, value });
|
|
30
30
|
}
|
|
31
31
|
_value = value;
|
|
32
32
|
initialized = true;
|
|
33
|
-
}
|
|
33
|
+
}
|
|
34
|
+
: undefined,
|
|
34
35
|
enumerable,
|
|
35
36
|
configurable
|
|
36
37
|
});
|
package/utils/object/merge.d.ts
CHANGED
package/utils/object/merge.js
CHANGED
|
@@ -3,9 +3,9 @@ import { arrayEquals } from '../equals.js';
|
|
|
3
3
|
import { isArray, isPrimitive, isUndefined } from '../type-guards.js';
|
|
4
4
|
import { hasOwnProperty, objectEntries } from './object.js';
|
|
5
5
|
export function mergeObjects(objects, options = {}) {
|
|
6
|
-
return objects.reduce((merged, object) =>
|
|
6
|
+
return objects.reduce((merged, object) => mergeObjectsInternal(merged, object, options), {});
|
|
7
7
|
}
|
|
8
|
-
function
|
|
8
|
+
function mergeObjectsInternal(a, b, options, path = '$') {
|
|
9
9
|
const merged = { ...a };
|
|
10
10
|
const bEntries = objectEntries(b);
|
|
11
11
|
for (const [key, valueB] of bEntries) {
|
|
@@ -36,7 +36,7 @@ function mergeValues(a, b, options, path) {
|
|
|
36
36
|
}
|
|
37
37
|
return mergeArray(a, b, options, path); // eslint-disable-line @typescript-eslint/no-unsafe-return
|
|
38
38
|
}
|
|
39
|
-
return
|
|
39
|
+
return mergeObjectsInternal(a, b, options, path);
|
|
40
40
|
}
|
|
41
41
|
function mergeArray(a, b, options, path) {
|
|
42
42
|
if (options.array == 'merge' || isUndefined(options.array)) {
|
package/utils/object/object.d.ts
CHANGED
|
@@ -2,11 +2,11 @@ import type { FromEntries, ObjectLiteral, PickBy, Record, SimplifyObject } from
|
|
|
2
2
|
import type { IsEqual } from 'type-fest';
|
|
3
3
|
export declare function hasOwnProperty<T extends Record>(obj: T, key: keyof T): boolean;
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Returns object entries including those with symbols keys (which Object.entries does not)
|
|
6
6
|
*/
|
|
7
7
|
export declare function objectEntries<T extends ObjectLiteral>(object: T): [keyof T, T[keyof T]][];
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* Returns object keys including symbols (which Object.keys does not)
|
|
10
10
|
*/
|
|
11
11
|
export declare function objectKeys<T extends ObjectLiteral>(object: T): (keyof T)[];
|
|
12
12
|
export declare function objectValues<T extends ObjectLiteral>(object: T): (T[keyof T])[];
|
package/utils/object/object.js
CHANGED
|
@@ -6,14 +6,14 @@ export function hasOwnProperty(obj, key) {
|
|
|
6
6
|
return Object.hasOwn(obj, key);
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* Returns object entries including those with symbols keys (which Object.entries does not)
|
|
10
10
|
*/
|
|
11
11
|
export function objectEntries(object) {
|
|
12
12
|
const keys = objectKeys(object);
|
|
13
13
|
return keys.map((key) => [key, object[key]]);
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
16
|
+
* Returns object keys including symbols (which Object.keys does not)
|
|
17
17
|
*/
|
|
18
18
|
export function objectKeys(object) {
|
|
19
19
|
return Reflect.ownKeys(object).filter((key) => key != '__proto__');
|
|
@@ -8,26 +8,26 @@ export type PropertyNameProxy<T extends Record> = {
|
|
|
8
8
|
[P in keyof DeepNonNullable<T>]: PropertyNameProxyChild<T[P]>;
|
|
9
9
|
};
|
|
10
10
|
export type PropertyNameProxyChild<T> = (T extends Record ? (PropertyNameProxy<T> & PropertyName) : (PropertyName)) & {
|
|
11
|
-
[cast]
|
|
11
|
+
[cast]<U extends T>(): PropertyNameProxyChild<U>;
|
|
12
12
|
};
|
|
13
13
|
export type PropertyNameOfExpressionObject<T> = {
|
|
14
14
|
[P in keyof T]: PropertyNameOfExpressionObject<DeepNonNullable<T>[P]> & {
|
|
15
|
-
[cast]
|
|
15
|
+
[cast]<U extends T[P]>(): PropertyNameOfExpressionObject<DeepNonNullable<U>>;
|
|
16
16
|
};
|
|
17
17
|
};
|
|
18
18
|
export type FlatPropertyNameOfExpressionObject<T> = {
|
|
19
19
|
[P in keyof DeepFlatten<T>]: FlatPropertyNameOfExpressionObject<DeepFlatten<DeepNonNullable<T>>[P]> & {
|
|
20
|
-
[cast]
|
|
20
|
+
[cast]<U extends DeepFlatten<T>[P]>(): FlatPropertyNameOfExpressionObject<DeepNonNullable<U>>;
|
|
21
21
|
};
|
|
22
22
|
};
|
|
23
23
|
export declare function getPropertyName(name: string): PropertyName;
|
|
24
24
|
export declare function isPropertyName(value: any): value is PropertyName;
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
26
|
+
* Get the path to a property
|
|
27
27
|
*
|
|
28
|
-
* @param options.deep
|
|
29
|
-
* @param options.flat
|
|
30
|
-
* @param options.prefix
|
|
28
|
+
* @param options.deep Whether to return the whole path to the property or just the last property
|
|
29
|
+
* @param options.flat Ignore array accesses (properties consiting only of numbers)
|
|
30
|
+
* @param options.prefix Name prefix
|
|
31
31
|
*
|
|
32
32
|
* @example
|
|
33
33
|
* import { getPropertyNameProxy, propertyName } from '@tstdl/base/utils/object.js';
|
|
@@ -42,19 +42,19 @@ export declare function getPropertyNameProxy<T extends Record = Record>(options?
|
|
|
42
42
|
prefix?: string;
|
|
43
43
|
}): PropertyNameProxy<T>;
|
|
44
44
|
/**
|
|
45
|
-
*
|
|
46
|
-
* @param expression
|
|
47
|
-
* @param options.deep
|
|
48
|
-
* @returns
|
|
45
|
+
* Get the path to a property
|
|
46
|
+
* @param expression Property selection expression
|
|
47
|
+
* @param options.deep Whether to return the whole path to the property or just the last property
|
|
48
|
+
* @returns Property name
|
|
49
49
|
*/
|
|
50
50
|
export declare function propertyNameOf<T extends Record = Record>(expression: (instance: PropertyNameOfExpressionObject<T>) => any, options?: {
|
|
51
51
|
deep?: boolean;
|
|
52
52
|
}): string;
|
|
53
53
|
/**
|
|
54
|
-
*
|
|
55
|
-
* @param expression
|
|
56
|
-
* @param options.deep
|
|
57
|
-
* @returns
|
|
54
|
+
* Get the flat path to a property (flat = ignore array accesses (properties only consisting of numbers))
|
|
55
|
+
* @param expression Property selection expression
|
|
56
|
+
* @param options.deep Whether to return the whole path to the property or just the last property
|
|
57
|
+
* @returns Property name
|
|
58
58
|
*/
|
|
59
59
|
export declare function flatPropertyNameOf<T extends Record = Record>(expression: (instance: FlatPropertyNameOfExpressionObject<T>) => any, options?: {
|
|
60
60
|
deep?: boolean;
|
|
@@ -9,11 +9,11 @@ export function isPropertyName(value) {
|
|
|
9
9
|
}
|
|
10
10
|
const propertyNameProxy = Symbol('PropertyNameProxy');
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Get the path to a property
|
|
13
13
|
*
|
|
14
|
-
* @param options.deep
|
|
15
|
-
* @param options.flat
|
|
16
|
-
* @param options.prefix
|
|
14
|
+
* @param options.deep Whether to return the whole path to the property or just the last property
|
|
15
|
+
* @param options.flat Ignore array accesses (properties consiting only of numbers)
|
|
16
|
+
* @param options.prefix Name prefix
|
|
17
17
|
*
|
|
18
18
|
* @example
|
|
19
19
|
* import { getPropertyNameProxy, propertyName } from '@tstdl/base/utils/object.js';
|
|
@@ -53,20 +53,20 @@ export function getPropertyNameProxy(options = {}) {
|
|
|
53
53
|
return proxy;
|
|
54
54
|
}
|
|
55
55
|
/**
|
|
56
|
-
*
|
|
57
|
-
* @param expression
|
|
58
|
-
* @param options.deep
|
|
59
|
-
* @returns
|
|
56
|
+
* Get the path to a property
|
|
57
|
+
* @param expression Property selection expression
|
|
58
|
+
* @param options.deep Whether to return the whole path to the property or just the last property
|
|
59
|
+
* @returns Property name
|
|
60
60
|
*/
|
|
61
61
|
export function propertyNameOf(expression, options = {}) {
|
|
62
62
|
const name = expression(getPropertyNameProxy({ deep: options.deep, flat: false }))?.[propertyName];
|
|
63
63
|
return assertStringPass(name, 'invalid expression');
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
|
-
*
|
|
67
|
-
* @param expression
|
|
68
|
-
* @param options.deep
|
|
69
|
-
* @returns
|
|
66
|
+
* Get the flat path to a property (flat = ignore array accesses (properties only consisting of numbers))
|
|
67
|
+
* @param expression Property selection expression
|
|
68
|
+
* @param options.deep Whether to return the whole path to the property or just the last property
|
|
69
|
+
* @returns Property name
|
|
70
70
|
*/
|
|
71
71
|
export function flatPropertyNameOf(expression, options = {}) {
|
|
72
72
|
const name = expression(getPropertyNameProxy({ deep: options.deep, flat: true }))?.[propertyName];
|
package/utils/patch-worker.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Observable } from 'rxjs';
|
|
2
2
|
import type { Record, StringMap } from '../types.js';
|
|
3
3
|
export type PatchWorkerOptions<T extends StringMap> = {
|
|
4
4
|
debounceTime?: number;
|
|
5
5
|
retryDelay?: number;
|
|
6
6
|
handleOn?: Observable<any>;
|
|
7
7
|
completeOn?: Observable<any>;
|
|
8
|
-
handler
|
|
9
|
-
errorHandler
|
|
8
|
+
handler(patch: Partial<T>): void | Promise<void>;
|
|
9
|
+
errorHandler?(error: Error): void | Promise<void>;
|
|
10
10
|
};
|
|
11
11
|
export declare class PatchWorker<T extends Record> {
|
|
12
12
|
private readonly patchAddedSubject;
|
package/utils/patterns.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** Pattern matching valid JavaScript number literals including binary, octal and hexadecimal format but *not* Infinity and NaN */
|
|
2
2
|
export declare const numberPattern: RegExp;
|
|
3
|
-
/**
|
|
3
|
+
/** Pattern matching valid email addresses */
|
|
4
4
|
export declare const mailPattern: RegExp;
|
|
5
5
|
export declare function isEmail(value: string): boolean;
|
package/utils/patterns.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** Pattern matching valid JavaScript number literals including binary, octal and hexadecimal format but *not* Infinity and NaN */
|
|
2
2
|
export const numberPattern = /^[+-]?(?:\d*\.?\d+|\d+\.?\d*|0[bB][01]+|0[xX][\da-fA-F]+|0[oO][0-7]+)$/u;
|
|
3
|
-
/**
|
|
4
|
-
// eslint-disable-next-line no-control-regex
|
|
3
|
+
/** Pattern matching valid email addresses */
|
|
4
|
+
// eslint-disable-next-line no-control-regex, prefer-named-capture-group
|
|
5
5
|
export const mailPattern = /^(?:[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-zA-Z0-9-]*[a-zA-Z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/u;
|
|
6
6
|
export function isEmail(value) {
|
|
7
7
|
return mailPattern.test(value);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Subject } from 'rxjs';
|
|
2
|
-
import { bufferCount, filter, map } from 'rxjs';
|
|
1
|
+
import { Subject, bufferCount, filter, map } from 'rxjs';
|
|
3
2
|
import { compareByValue } from './comparison.js';
|
|
4
3
|
import { average } from './math.js';
|
|
5
4
|
import { timeout } from './timing.js';
|
|
@@ -55,18 +54,21 @@ function aggregate(aggregation, values) {
|
|
|
55
54
|
return Math.max(...values);
|
|
56
55
|
case AggregationMode.Mean:
|
|
57
56
|
return average(values);
|
|
58
|
-
case AggregationMode.Median:
|
|
57
|
+
case AggregationMode.Median: {
|
|
59
58
|
values.sort(compareByValue);
|
|
60
59
|
const median = Math.floor(values.length / 2);
|
|
61
60
|
return values[median];
|
|
62
|
-
|
|
61
|
+
}
|
|
62
|
+
case AggregationMode.FirstQuartile: {
|
|
63
63
|
values.sort(compareByValue);
|
|
64
64
|
const firstQuartile = Math.floor(values.length / 4 * 1);
|
|
65
65
|
return values[firstQuartile];
|
|
66
|
-
|
|
66
|
+
}
|
|
67
|
+
case AggregationMode.ThirdQuartile: {
|
|
67
68
|
values.sort(compareByValue);
|
|
68
69
|
const thirdQuartile = Math.floor(values.length / 4 * 3);
|
|
69
70
|
return values[thirdQuartile];
|
|
71
|
+
}
|
|
70
72
|
default:
|
|
71
73
|
throw new Error(`aggregation mode ${aggregation} not implemented`);
|
|
72
74
|
}
|
package/utils/random.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Generate cryptographically secure random bytes
|
|
3
3
|
*
|
|
4
4
|
* if allowUnsafe is true a view on the underlying pool is returned. This can be dangerous as the underlying
|
|
5
5
|
* pool can be read and modified by other callers of {@link getRandomBytes} but improves performance as
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
export declare function getRandomBytes(count: number, allowUnsafe?: boolean): Uint8Array;
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Generate a cryptographically secure random string (in terms of source of randomness).
|
|
13
13
|
* @param length length of string
|
|
14
14
|
* @param alphabet alphabet to choose characters from. Defaults to {@link Alphabet.LowerUpperCaseNumbers}
|
|
15
15
|
*/
|
package/utils/random.js
CHANGED
|
@@ -4,7 +4,7 @@ const bufferBypassThreshold = (bufferSize / 2) + 1;
|
|
|
4
4
|
let randomBytesBuffer = new Uint8Array();
|
|
5
5
|
let randomBytesBufferIndex = 0;
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Generate cryptographically secure random bytes
|
|
8
8
|
*
|
|
9
9
|
* if allowUnsafe is true a view on the underlying pool is returned. This can be dangerous as the underlying
|
|
10
10
|
* pool can be read and modified by other callers of {@link getRandomBytes} but improves performance as
|
|
@@ -26,7 +26,7 @@ export function getRandomBytes(count, allowUnsafe = false) {
|
|
|
26
26
|
return bytes;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
|
-
*
|
|
29
|
+
* Generate a cryptographically secure random string (in terms of source of randomness).
|
|
30
30
|
* @param length length of string
|
|
31
31
|
* @param alphabet alphabet to choose characters from. Defaults to {@link Alphabet.LowerUpperCaseNumbers}
|
|
32
32
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Signal, type ToSignalOptions } from '../signals/api.js';
|
|
2
2
|
import type { ReactiveValue } from '../types.js';
|
|
3
3
|
export type ReactiveValueToSignalOptions = ToSignalOptions;
|
|
4
4
|
export declare function reactiveValueToSignal<T>(source: ReactiveValue<T>): Signal<T | undefined>;
|