@genesislcap/foundation-utils 14.65.2 → 14.66.0
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/dist/dts/error/errorMap.d.ts +97 -0
- package/dist/dts/error/errorMap.d.ts.map +1 -0
- package/dist/dts/error/index.d.ts +2 -0
- package/dist/dts/error/index.d.ts.map +1 -0
- package/dist/dts/index.d.ts +1 -0
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/serializers/json/index.d.ts +2 -0
- package/dist/dts/serializers/json/index.d.ts.map +1 -1
- package/dist/dts/serializers/json/jsonReplacer.d.ts +9 -0
- package/dist/dts/serializers/json/jsonReplacer.d.ts.map +1 -0
- package/dist/dts/serializers/json/jsonReviver.d.ts +9 -0
- package/dist/dts/serializers/json/jsonReviver.d.ts.map +1 -0
- package/dist/dts/serializers/json/types.d.ts +26 -0
- package/dist/dts/serializers/json/types.d.ts.map +1 -0
- package/dist/dts/tsdoc-metadata.json +11 -0
- package/dist/esm/error/errorMap.js +101 -0
- package/dist/esm/error/index.js +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/serializers/json/index.js +2 -0
- package/dist/esm/serializers/json/jsonReplacer.js +26 -0
- package/dist/esm/serializers/json/jsonReviver.js +32 -0
- package/dist/esm/serializers/json/types.js +40 -0
- package/dist/foundation-utils.api.json +11993 -0
- package/dist/foundation-utils.d.ts +1599 -0
- package/docs/.gitattributes +2 -0
- package/docs/api/foundation-utils.createerrormap.md +13 -0
- package/docs/api/foundation-utils.defaulterrormap._constructor_.md +20 -0
- package/docs/api/foundation-utils.defaulterrormap.clear.md +17 -0
- package/docs/api/foundation-utils.defaulterrormap.delete.md +26 -0
- package/docs/api/foundation-utils.defaulterrormap.get.md +26 -0
- package/docs/api/foundation-utils.defaulterrormap.has.md +26 -0
- package/docs/api/foundation-utils.defaulterrormap.lasterror.md +13 -0
- package/docs/api/foundation-utils.defaulterrormap.md +38 -0
- package/docs/api/foundation-utils.defaulterrormap.messages.md +13 -0
- package/docs/api/foundation-utils.defaulterrormap.set.md +25 -0
- package/docs/api/foundation-utils.defaulterrormap.size.md +13 -0
- package/docs/api/foundation-utils.errordetailmap.md +12 -0
- package/docs/api/foundation-utils.errormap.lasterror.md +13 -0
- package/docs/api/foundation-utils.errormap.md +27 -0
- package/docs/api/foundation-utils.errormap.messages.md +13 -0
- package/docs/api/foundation-utils.errormap.set.md +25 -0
- package/docs/api/foundation-utils.errormaplogger.md +12 -0
- package/docs/api/foundation-utils.jsonreplacer.md +27 -0
- package/docs/api/foundation-utils.jsonreviver.md +27 -0
- package/docs/api/foundation-utils.md +7 -0
- package/docs/api-report.md +35 -0
- package/package.json +7 -3
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @public
|
|
3
|
+
*/
|
|
4
|
+
export type ErrorDetailMap = Record<string, unknown>;
|
|
5
|
+
/**
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export type ErrorMapLogger = (...args: any[]) => void;
|
|
9
|
+
/**
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export interface ErrorMap<TErrorDetailMap extends ErrorDetailMap> extends Pick<Map<keyof TErrorDetailMap, Error>, 'get' | 'has' | 'delete' | 'clear' | 'size'> {
|
|
13
|
+
/**
|
|
14
|
+
* Error map as messages.
|
|
15
|
+
* @returns string
|
|
16
|
+
*
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
readonly messages: string;
|
|
20
|
+
/**
|
|
21
|
+
* Set an error by key.
|
|
22
|
+
* @param key - The key.
|
|
23
|
+
* @param error - The error.
|
|
24
|
+
*
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
set(key: keyof TErrorDetailMap, error: Error): void;
|
|
28
|
+
/**
|
|
29
|
+
* The last set error if any.
|
|
30
|
+
* @returns Error
|
|
31
|
+
*
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
readonly lastError: Error;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* @public
|
|
38
|
+
*/
|
|
39
|
+
export declare class DefaultErrorMap<TErrorDetailMap extends ErrorDetailMap> implements ErrorMap<TErrorDetailMap> {
|
|
40
|
+
private logger;
|
|
41
|
+
private map;
|
|
42
|
+
/** {@inheritDoc ErrorMap.lastError} */
|
|
43
|
+
lastError: Error;
|
|
44
|
+
/**
|
|
45
|
+
* @param logger - A logger error method reference.
|
|
46
|
+
*/
|
|
47
|
+
constructor(logger: ErrorMapLogger);
|
|
48
|
+
/** {@inheritDoc ErrorMap.set} */
|
|
49
|
+
set(key: keyof TErrorDetailMap, error: Error): void;
|
|
50
|
+
/**
|
|
51
|
+
* Get an error by key.
|
|
52
|
+
* @param key - The key.
|
|
53
|
+
* @returns The error if it exists, otherwise undefined.
|
|
54
|
+
*
|
|
55
|
+
* @public
|
|
56
|
+
*/
|
|
57
|
+
get(key: keyof TErrorDetailMap): Error | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* Has an error for key.
|
|
60
|
+
* @param key - The key.
|
|
61
|
+
* @returns True if it exists, otherwise false.
|
|
62
|
+
*
|
|
63
|
+
* @public
|
|
64
|
+
*/
|
|
65
|
+
has(key: keyof TErrorDetailMap): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Delete an error.
|
|
68
|
+
* @param key - The key.
|
|
69
|
+
* @returns True if successful, otherwise false.
|
|
70
|
+
*
|
|
71
|
+
* @public
|
|
72
|
+
*/
|
|
73
|
+
delete(key: keyof TErrorDetailMap): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Clear errors.
|
|
76
|
+
* @public
|
|
77
|
+
*/
|
|
78
|
+
clear(): void;
|
|
79
|
+
/**
|
|
80
|
+
* The size of the error map.
|
|
81
|
+
* @returns number
|
|
82
|
+
*
|
|
83
|
+
* @public
|
|
84
|
+
*/
|
|
85
|
+
get size(): number;
|
|
86
|
+
/** {@inheritDoc ErrorMap.messages} */
|
|
87
|
+
get messages(): string;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* A factory to create the error map.
|
|
91
|
+
* @param logger - A logger error method reference.
|
|
92
|
+
* @returns A ErrorMap instance.
|
|
93
|
+
*
|
|
94
|
+
* @public
|
|
95
|
+
*/
|
|
96
|
+
export declare const createErrorMap: <TErrorDetailMap extends ErrorDetailMap>(logger: ErrorMapLogger) => ErrorMap<TErrorDetailMap>;
|
|
97
|
+
//# sourceMappingURL=errorMap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errorMap.d.ts","sourceRoot":"","sources":["../../../src/error/errorMap.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAErD;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;AAEtD;;GAEG;AACH,MAAM,WAAW,QAAQ,CAAC,eAAe,SAAS,cAAc,CAC9D,SAAQ,IAAI,CAAC,GAAG,CAAC,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,KAAK,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,GAAG,MAAM,CAAC;IAC5F;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAE1B;;;;;;OAMG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,eAAe,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAEpD;;;;;OAKG;IACH,QAAQ,CAAC,SAAS,EAAE,KAAK,CAAC;CAC3B;AAED;;GAEG;AACH,qBAAa,eAAe,CAAC,eAAe,SAAS,cAAc,CACjE,YAAW,QAAQ,CAAC,eAAe,CAAC;IAUxB,OAAO,CAAC,MAAM;IARd,OAAO,CAAC,GAAG,CAA2C;IAElE,uCAAuC;IAC3B,SAAS,EAAE,KAAK,CAAC;IAE7B;;OAEG;gBACiB,MAAM,EAAE,cAAc;IAE1C,iCAAiC;IACjC,GAAG,CAAC,GAAG,EAAE,MAAM,eAAe,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI;IAMnD;;;;;;OAMG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,eAAe,GAAG,KAAK,GAAG,SAAS;IAIlD;;;;;;OAMG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,eAAe,GAAG,OAAO;IAIxC;;;;;;OAMG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,eAAe,GAAG,OAAO;IAa3C;;;OAGG;IACH,KAAK;IAKL;;;;;OAKG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,sCAAsC;IACtC,IAAI,QAAQ,IAAI,MAAM,CAUrB;CACF;AAED;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,mDACjB,cAAc,8BACoD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/error/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC"}
|
package/dist/dts/index.d.ts
CHANGED
package/dist/dts/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,OAAO,CAAC;AACtB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/serializers/json/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/serializers/json/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON replacer function.
|
|
3
|
+
* @param key - The object key.
|
|
4
|
+
* @param value - The key value.
|
|
5
|
+
* @returns The resulting value.
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export declare function JSONReplacer(key: string, value: any): any;
|
|
9
|
+
//# sourceMappingURL=jsonReplacer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonReplacer.d.ts","sourceRoot":"","sources":["../../../../src/serializers/json/jsonReplacer.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,GAAG,CAoBzD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonReviver.d.ts","sourceRoot":"","sources":["../../../../src/serializers/json/jsonReviver.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,GAAG,CAyBxD"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Constructable } from '@microsoft/fast-element';
|
|
2
|
+
/**
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
export declare const ISO8601: RegExp;
|
|
6
|
+
/**
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export declare const NaNSymbol = "$NaN";
|
|
10
|
+
/**
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
type Deserializable = Constructable | {
|
|
14
|
+
prototype: any;
|
|
15
|
+
fromJSON(options: any): any;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export declare const getType: (typeId: string) => Deserializable;
|
|
21
|
+
/**
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export declare const getTypeId: (object: any) => string | undefined;
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/serializers/json/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD;;GAEG;AACH,eAAO,MAAM,OAAO,QACwI,CAAC;AAE7J;;GAEG;AACH,eAAO,MAAM,SAAS,SAAS,CAAC;AAEhC;;GAEG;AACH,KAAK,cAAc,GACf,aAAa,GACb;IACE,SAAS,EAAE,GAAG,CAAC;IACf,QAAQ,CAAC,OAAO,EAAE,GAAG,GAAG,GAAG,CAAC;CAC7B,CAAC;AAON;;GAEG;AACH,eAAO,MAAM,OAAO,WAAY,MAAM,mBAAiC,CAAC;AAExE;;GAEG;AACH,eAAO,MAAM,SAAS,WAAY,GAAG,KAAG,MAAM,GAAG,SAwBhD,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
|
2
|
+
// It should be published with your NPM package. It should not be tracked by Git.
|
|
3
|
+
{
|
|
4
|
+
"tsdocVersion": "0.12",
|
|
5
|
+
"toolPackages": [
|
|
6
|
+
{
|
|
7
|
+
"packageName": "@microsoft/api-extractor",
|
|
8
|
+
"packageVersion": "7.34.9"
|
|
9
|
+
}
|
|
10
|
+
]
|
|
11
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { observable } from '@microsoft/fast-element';
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export class DefaultErrorMap {
|
|
7
|
+
/**
|
|
8
|
+
* @param logger - A logger error method reference.
|
|
9
|
+
*/
|
|
10
|
+
constructor(logger) {
|
|
11
|
+
this.logger = logger;
|
|
12
|
+
this.map = new Map();
|
|
13
|
+
}
|
|
14
|
+
/** {@inheritDoc ErrorMap.set} */
|
|
15
|
+
set(key, error) {
|
|
16
|
+
this.logger(key, error);
|
|
17
|
+
this.lastError = error;
|
|
18
|
+
this.map = new Map(this.map.set(key, error));
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Get an error by key.
|
|
22
|
+
* @param key - The key.
|
|
23
|
+
* @returns The error if it exists, otherwise undefined.
|
|
24
|
+
*
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
get(key) {
|
|
28
|
+
return this.map.get(key);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Has an error for key.
|
|
32
|
+
* @param key - The key.
|
|
33
|
+
* @returns True if it exists, otherwise false.
|
|
34
|
+
*
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
has(key) {
|
|
38
|
+
return this.map.has(key);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Delete an error.
|
|
42
|
+
* @param key - The key.
|
|
43
|
+
* @returns True if successful, otherwise false.
|
|
44
|
+
*
|
|
45
|
+
* @public
|
|
46
|
+
*/
|
|
47
|
+
delete(key) {
|
|
48
|
+
const isDeletingLast = this.map.get(key) === this.lastError;
|
|
49
|
+
const result = this.map.delete(key);
|
|
50
|
+
if (result) {
|
|
51
|
+
this.map = new Map(this.map);
|
|
52
|
+
if (isDeletingLast) {
|
|
53
|
+
this.lastError = undefined;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Clear errors.
|
|
60
|
+
* @public
|
|
61
|
+
*/
|
|
62
|
+
clear() {
|
|
63
|
+
this.lastError = undefined;
|
|
64
|
+
this.map = new Map();
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The size of the error map.
|
|
68
|
+
* @returns number
|
|
69
|
+
*
|
|
70
|
+
* @public
|
|
71
|
+
*/
|
|
72
|
+
get size() {
|
|
73
|
+
return this.map.size;
|
|
74
|
+
}
|
|
75
|
+
/** {@inheritDoc ErrorMap.messages} */
|
|
76
|
+
get messages() {
|
|
77
|
+
const count = this.size;
|
|
78
|
+
if (!count) {
|
|
79
|
+
return '';
|
|
80
|
+
}
|
|
81
|
+
const errorMessages = [];
|
|
82
|
+
for (const { message } of this.map.values()) {
|
|
83
|
+
errorMessages.push(message);
|
|
84
|
+
}
|
|
85
|
+
return `${count} Error${count > 1 ? 's' : ''} Occurred:\n${errorMessages.join('\n')}`;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
__decorate([
|
|
89
|
+
observable
|
|
90
|
+
], DefaultErrorMap.prototype, "map", void 0);
|
|
91
|
+
__decorate([
|
|
92
|
+
observable
|
|
93
|
+
], DefaultErrorMap.prototype, "lastError", void 0);
|
|
94
|
+
/**
|
|
95
|
+
* A factory to create the error map.
|
|
96
|
+
* @param logger - A logger error method reference.
|
|
97
|
+
* @returns A ErrorMap instance.
|
|
98
|
+
*
|
|
99
|
+
* @public
|
|
100
|
+
*/
|
|
101
|
+
export const createErrorMap = (logger) => new DefaultErrorMap(logger);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './errorMap';
|
package/dist/esm/index.js
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { getTypeId, NaNSymbol } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* JSON replacer function.
|
|
4
|
+
* @param key - The object key.
|
|
5
|
+
* @param value - The key value.
|
|
6
|
+
* @returns The resulting value.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export function JSONReplacer(key, value) {
|
|
10
|
+
if (key) {
|
|
11
|
+
const first = key[0];
|
|
12
|
+
if (first === '_' || first === '$') {
|
|
13
|
+
return void 0;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (value !== void 0 && value !== null) {
|
|
17
|
+
const type = getTypeId(value);
|
|
18
|
+
if (type) {
|
|
19
|
+
value.type = type;
|
|
20
|
+
}
|
|
21
|
+
else if (Number.isNaN(value)) {
|
|
22
|
+
return NaNSymbol;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { getType, ISO8601, NaNSymbol } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* JSON reviver function.
|
|
4
|
+
* @param key - The object key.
|
|
5
|
+
* @param value - The key value.
|
|
6
|
+
* @returns The resulting value.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export function JSONReviver(key, value) {
|
|
10
|
+
if (typeof value === 'string') {
|
|
11
|
+
const isDate = ISO8601.exec(value);
|
|
12
|
+
if (isDate) {
|
|
13
|
+
return new Date(value);
|
|
14
|
+
}
|
|
15
|
+
else if (value === NaNSymbol) {
|
|
16
|
+
return Number.NaN;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
const typeId = value && value.type;
|
|
21
|
+
if (typeId) {
|
|
22
|
+
const ctor = getType(typeId);
|
|
23
|
+
if (ctor) {
|
|
24
|
+
if ('fromJSON' in ctor) {
|
|
25
|
+
return ctor.fromJSON(value);
|
|
26
|
+
}
|
|
27
|
+
return new ctor(value);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @internal
|
|
3
|
+
*/
|
|
4
|
+
export const ISO8601 = /^\d{4}-(0[1-9]|1[0-2])-([12]\d|0[1-9]|3[01])([T\s](([01]\d|2[0-3])\:[0-5]\d|24\:00)(\:[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3])\:?([0-5]\d)?)?)?$/;
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export const NaNSymbol = '$NaN';
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
const keyToConstructor = new Map();
|
|
13
|
+
/**
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export const getType = (typeId) => keyToConstructor.get(typeId);
|
|
17
|
+
/**
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export const getTypeId = (object) => {
|
|
21
|
+
if (object) {
|
|
22
|
+
if (object.type) {
|
|
23
|
+
return object.type;
|
|
24
|
+
}
|
|
25
|
+
const proto = Object.getPrototypeOf(object);
|
|
26
|
+
if (!proto) {
|
|
27
|
+
return void 0;
|
|
28
|
+
}
|
|
29
|
+
const ctor = proto.constructor;
|
|
30
|
+
if (!ctor) {
|
|
31
|
+
return void 0;
|
|
32
|
+
}
|
|
33
|
+
for (const [key, value] of keyToConstructor) {
|
|
34
|
+
if (ctor === value) {
|
|
35
|
+
return key;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return void 0;
|
|
39
|
+
}
|
|
40
|
+
};
|