@fgv/ts-utils 2.1.1-alpha.0 → 2.1.1-alpha.2

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.
@@ -490,6 +490,16 @@ declare interface ConverterTraits {
490
490
  readonly brand?: string;
491
491
  }
492
492
 
493
+ /**
494
+ * A {@link Hash.HashingNormalizer | hashing normalizer} which computes object
495
+ * hash using the CRC32 algorithm.
496
+ * @public
497
+ */
498
+ declare class Crc32Normalizer extends HashingNormalizer {
499
+ constructor();
500
+ static crc32Hash(parts: string[]): string;
501
+ }
502
+
493
503
  /**
494
504
  * Default {@link Validation.ValidatorTraitValues | validation traits}.
495
505
  * @public
@@ -966,6 +976,38 @@ export declare function getTypeOfProperty<T extends object>(key: string | number
966
976
  */
967
977
  export declare function getValueOfPropertyOrDefault<T extends object>(key: string | number | symbol, item: T, defaultValue?: unknown): unknown | undefined;
968
978
 
979
+ declare namespace Hash {
980
+ export {
981
+ Crc32Normalizer,
982
+ HashFunction,
983
+ HashingNormalizer
984
+ }
985
+ }
986
+ export { Hash }
987
+
988
+ /**
989
+ * Function to compute a hash from a pre-normalized array of strings.
990
+ * @public
991
+ */
992
+ declare type HashFunction = (parts: string[]) => string;
993
+
994
+ /**
995
+ * Normalizes an arbitrary JSON object
996
+ * @public
997
+ */
998
+ declare class HashingNormalizer extends Normalizer {
999
+ private _hash;
1000
+ constructor(hash: HashFunction);
1001
+ computeHash(from: unknown): Result<string>;
1002
+ /**
1003
+ * Constructs a normalized string representation of some literal value.
1004
+ * @param from - The literal value to be normalized.
1005
+ * @returns A normalized string representation of the literal.
1006
+ * @internal
1007
+ */
1008
+ protected _normalizeLiteralToString(from: string | number | bigint | boolean | symbol | undefined | Date | RegExp | null): Result<string>;
1009
+ }
1010
+
969
1011
  /**
970
1012
  * Infers the type that will be returned by an instantiated converter. Works
971
1013
  * for complex as well as simple types.
@@ -1397,17 +1439,15 @@ declare type LogLevel = 'detail' | 'info' | 'warning' | 'error' | 'silent';
1397
1439
  * Converts property names (entry key) to string and then sorts as string.
1398
1440
  * @param entries - The entries to be normalized.
1399
1441
  * @returns A normalized sorted array of entries.
1400
- * @internal
1401
1442
  */
1402
- protected _normalizeEntries<T = unknown>(entries: Iterable<Entry<T>>): Entry<T>[];
1443
+ normalizeEntries<T = unknown>(entries: Iterable<Entry<T>>): Entry<T>[];
1403
1444
  protected _normalizeArray(from: unknown[]): Result<unknown[]>;
1404
1445
  /**
1405
1446
  * Normalizes the supplied literal value
1406
1447
  * @param from - The literal value to be normalized.
1407
1448
  * @returns A normalized value for the literal.
1408
- * @internal
1409
1449
  */
1410
- protected _normalizeLiteral<T>(from: T): Result<T>;
1450
+ normalizeLiteral<T>(from: T): Result<T>;
1411
1451
  }
1412
1452
 
1413
1453
  /**
@@ -1526,7 +1566,7 @@ declare type LogLevel = 'detail' | 'info' | 'warning' | 'error' | 'silent';
1526
1566
  * for other conversion options.
1527
1567
  * @public
1528
1568
  */
1529
- declare class ObjectConverter<T, TC = unknown> extends BaseConverter<T, TC> {
1569
+ export declare class ObjectConverter<T, TC = unknown> extends BaseConverter<T, TC> {
1530
1570
  /**
1531
1571
  * Fields converted by this {@link Conversion.ObjectConverter | ObjectConverter}.
1532
1572
  */
package/lib/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import * as Conversion from './packlets/conversion';
2
+ import * as Hash from './packlets/hash';
2
3
  import * as Validation from './packlets/validation';
3
- import { Converter, Converters } from './packlets/conversion';
4
+ import { Converter, Converters, ObjectConverter } from './packlets/conversion';
4
5
  import { Validator, Validators } from './packlets/validation';
5
6
  export * from './packlets/base';
6
- export { Conversion, Converter, Converters, Validation, Validator, Validators };
7
+ export { Conversion, Converter, Converters, Hash, ObjectConverter, Validation, Validator, Validators };
7
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAC;AAEpD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAE9D,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AACxC,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAC;AAEpD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC/E,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAE9D,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,eAAe,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC"}
package/lib/index.js CHANGED
@@ -47,13 +47,16 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
47
47
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
48
48
  };
49
49
  Object.defineProperty(exports, "__esModule", { value: true });
50
- exports.Validators = exports.Validation = exports.Converters = exports.Conversion = void 0;
50
+ exports.Validators = exports.Validation = exports.ObjectConverter = exports.Hash = exports.Converters = exports.Conversion = void 0;
51
51
  const Conversion = __importStar(require("./packlets/conversion"));
52
52
  exports.Conversion = Conversion;
53
+ const Hash = __importStar(require("./packlets/hash"));
54
+ exports.Hash = Hash;
53
55
  const Validation = __importStar(require("./packlets/validation"));
54
56
  exports.Validation = Validation;
55
57
  const conversion_1 = require("./packlets/conversion");
56
58
  Object.defineProperty(exports, "Converters", { enumerable: true, get: function () { return conversion_1.Converters; } });
59
+ Object.defineProperty(exports, "ObjectConverter", { enumerable: true, get: function () { return conversion_1.ObjectConverter; } });
57
60
  const validation_1 = require("./packlets/validation");
58
61
  Object.defineProperty(exports, "Validators", { enumerable: true, get: function () { return validation_1.Validators; } });
59
62
  __exportStar(require("./packlets/base"), exports);
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,kEAAoD;AAO3C,gCAAU;AANnB,kEAAoD;AAMR,gCAAU;AAJtD,sDAA8D;AAI9B,2FAJZ,uBAAU,OAIY;AAH1C,sDAA8D;AAGK,2FAH/C,uBAAU,OAG+C;AAD7E,kDAAgC","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport * as Conversion from './packlets/conversion';\nimport * as Validation from './packlets/validation';\n\nimport { Converter, Converters } from './packlets/conversion';\nimport { Validator, Validators } from './packlets/validation';\n\nexport * from './packlets/base';\nexport { Conversion, Converter, Converters, Validation, Validator, Validators };\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,kEAAoD;AAQ3C,gCAAU;AAPnB,sDAAwC;AAOI,oBAAI;AANhD,kEAAoD;AAMe,gCAAU;AAJ7E,sDAA+E;AAI/C,2FAJZ,uBAAU,OAIY;AAAQ,gGAJlB,4BAAe,OAIkB;AAHjE,sDAA8D;AAG4B,2FAHtE,uBAAU,OAGsE;AADpG,kDAAgC","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport * as Conversion from './packlets/conversion';\nimport * as Hash from './packlets/hash';\nimport * as Validation from './packlets/validation';\n\nimport { Converter, Converters, ObjectConverter } from './packlets/conversion';\nimport { Validator, Validators } from './packlets/validation';\n\nexport * from './packlets/base';\nexport { Conversion, Converter, Converters, Hash, ObjectConverter, Validation, Validator, Validators };\n"]}
@@ -34,16 +34,14 @@ export declare class Normalizer {
34
34
  * Converts property names (entry key) to string and then sorts as string.
35
35
  * @param entries - The entries to be normalized.
36
36
  * @returns A normalized sorted array of entries.
37
- * @internal
38
37
  */
39
- protected _normalizeEntries<T = unknown>(entries: Iterable<Entry<T>>): Entry<T>[];
38
+ normalizeEntries<T = unknown>(entries: Iterable<Entry<T>>): Entry<T>[];
40
39
  protected _normalizeArray(from: unknown[]): Result<unknown[]>;
41
40
  /**
42
41
  * Normalizes the supplied literal value
43
42
  * @param from - The literal value to be normalized.
44
43
  * @returns A normalized value for the literal.
45
- * @internal
46
44
  */
47
- protected _normalizeLiteral<T>(from: T): Result<T>;
45
+ normalizeLiteral<T>(from: T): Result<T>;
48
46
  }
49
47
  //# sourceMappingURL=normalize.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../../src/packlets/base/normalize.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,MAAM,EAA6B,MAAM,UAAU,CAAC;AAE7D;;GAEG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC,CAAC;AAErD;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAEnE;;;GAGG;AACH,qBAAa,UAAU;IACrB;;;;;OAKG;IACI,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAA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CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE;IAQ7E,SAAS,CAAC,eAAe,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;IAI7D;;;;OAIG;IACI,gBAAgB,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;CAwB/C"}
@@ -42,22 +42,22 @@ class Normalizer {
42
42
  case 'number':
43
43
  case 'symbol':
44
44
  case 'undefined':
45
- return this._normalizeLiteral(from);
45
+ return this.normalizeLiteral(from);
46
46
  case 'object':
47
47
  if (from === null || from instanceof Date || from instanceof RegExp) {
48
- return this._normalizeLiteral(from);
48
+ return this.normalizeLiteral(from);
49
49
  }
50
50
  else if (Array.isArray(from)) {
51
51
  return this._normalizeArray(from);
52
52
  }
53
53
  else if (from instanceof Map) {
54
- return (0, result_1.succeed)(new Map(this._normalizeEntries(from.entries())));
54
+ return (0, result_1.succeed)(new Map(this.normalizeEntries(from.entries())));
55
55
  }
56
56
  else if (from instanceof Set) {
57
- return (0, result_1.succeed)(new Set(this._normalizeEntries(from.entries())));
57
+ return (0, result_1.succeed)(new Set(this.normalizeEntries(from.entries())));
58
58
  }
59
59
  const obj = {};
60
- for (const e of this._normalizeEntries(Object.entries(from))) {
60
+ for (const e of this.normalizeEntries(Object.entries(from))) {
61
61
  obj[e[0]] = e[1];
62
62
  }
63
63
  return (0, result_1.succeed)(obj);
@@ -90,9 +90,8 @@ class Normalizer {
90
90
  * Converts property names (entry key) to string and then sorts as string.
91
91
  * @param entries - The entries to be normalized.
92
92
  * @returns A normalized sorted array of entries.
93
- * @internal
94
93
  */
95
- _normalizeEntries(entries) {
94
+ normalizeEntries(entries) {
96
95
  return Array.from(entries)
97
96
  .sort((e1, e2) => this._compareKeys(e1[0], e2[0]))
98
97
  .map((e) => [e[0], this.normalize(e[1])])
@@ -106,9 +105,8 @@ class Normalizer {
106
105
  * Normalizes the supplied literal value
107
106
  * @param from - The literal value to be normalized.
108
107
  * @returns A normalized value for the literal.
109
- * @internal
110
108
  */
111
- _normalizeLiteral(from) {
109
+ normalizeLiteral(from) {
112
110
  // TODO: Apply configurable normalization rules
113
111
  switch (typeof from) {
114
112
  case 'string':
@@ -1 +1 @@
1
- {"version":3,"file":"normalize.js","sourceRoot":"","sources":["../../../src/packlets/base/normalize.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,qCAA6D;AAY7D;;;GAGG;AACH,MAAa,UAAU;IACrB;;;;;OAKG;IACI,SAAS,CAAI,IAAO;QACzB,QAAQ,OAAO,IAAI,EAAE,CAAC;YACpB,KAAK,QAAQ,CAAC;YACd,KAAK,QAAQ,CAAC;YACd,KAAK,SAAS,CAAC;YACf,KAAK,QAAQ,CAAC;YACd,KAAK,QAAQ,CAAC;YACd,KAAK,WAAW;gBACd,OAAO,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;YACtC,KAAK,QAAQ;gBACX,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,YAAY,IAAI,IAAI,IAAI,YAAY,MAAM,EAAE,CAAC;oBACpE,OAAO,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;gBACtC,CAAC;qBAAM,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;oBAC/B,OAAO,IAAI,CAAC,eAAe,CAAC,IAAI,CAAyB,CAAC;gBAC5D,CAAC;qBAAM,IAAI,IAAI,YAAY,GAAG,EAAE,CAAC;oBAC/B,OAAO,IAAA,gBAAO,EAAC,IAAI,GAAG,CAAC,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAiB,CAAC,CAAC;gBAClF,CAAC;qBAAM,IAAI,IAAI,YAAY,GAAG,EAAE,CAAC;oBAC/B,OAAO,IAAA,gBAAO,EAAC,IAAI,GAAG,CAAC,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,O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Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Result, fail, mapResults, succeed } from './result';\n\n/**\n * @internal\n */\nexport type Entry<T> = [string | number | symbol, T];\n\n/**\n * @internal\n */\nexport type ResultEntry<T> = [string | number | symbol, Result<T>];\n\n/**\n * Normalizes an arbitrary JSON object\n * @public\n */\nexport class Normalizer {\n /**\n * Normalizes the supplied value\n *\n * @param from - The value to be normalized\n * @returns A normalized version of the value\n */\n public normalize<T>(from: T): Result<T> {\n switch (typeof from) {\n case 'string':\n case 'bigint':\n case 'boolean':\n case 'number':\n case 'symbol':\n case 'undefined':\n return this._normalizeLiteral(from);\n case 'object':\n if (from === null || from instanceof Date || from instanceof RegExp) {\n return this._normalizeLiteral(from);\n } else if (Array.isArray(from)) {\n return this._normalizeArray(from) as unknown as Result<T>;\n } else if (from instanceof Map) {\n return succeed(new Map(this._normalizeEntries(from.entries())) as unknown as T);\n } else if (from instanceof Set) {\n return succeed(new Set(this._normalizeEntries(from.entries())) as unknown as T);\n }\n const obj: { [key in number | string | symbol]: unknown } = {};\n for (const e of this._normalizeEntries(Object.entries(from as unknown as object))) {\n obj[e[0]] = e[1];\n }\n return succeed(obj as T);\n }\n return fail(`normalize: Unexpected type - cannot normalize '${typeof from}'`);\n }\n\n /**\n * Compares two property names from some object being normalized.\n * @param k1 - First key to be compared.\n * @param k2 - Second key to be compared.\n * @returns `1` if `k1` is greater, `-1` if `k2` is greater and\n * `0` if they are equal.\n * @internal\n */\n protected _compareKeys(k1: unknown, k2: unknown): number {\n const cs1 = String(k1);\n const cs2 = String(k2);\n if (cs1 > cs2) {\n return 1;\n }\n if (cs2 > cs1) {\n return -1;\n }\n /* c8 ignore next 2 */\n return 0;\n }\n\n /**\n * Normalizes an array of object property entries (e.g. as returned by `Object.entries()`).\n * @remarks\n * Converts property names (entry key) to string and then sorts as string.\n * @param entries - The entries to be normalized.\n * @returns A normalized sorted array of entries.\n * @internal\n */\n protected _normalizeEntries<T = unknown>(entries: Iterable<Entry<T>>): Entry<T>[] {\n return Array.from(entries)\n .sort((e1, e2) => this._compareKeys(e1[0], e2[0]))\n .map((e) => [e[0], this.normalize(e[1])] as ResultEntry<T>)\n .filter((e) => e[1].isSuccess())\n .map((e) => [e[0], e[1].orThrow()]);\n }\n\n protected _normalizeArray(from: unknown[]): Result<unknown[]> {\n return mapResults(from.map((v) => this.normalize(v)));\n }\n\n /**\n * Normalizes the supplied literal value\n * @param from - The literal value to be normalized.\n * @returns A normalized value for the literal.\n * @internal\n */\n protected _normalizeLiteral<T>(from: T): Result<T> {\n // TODO: Apply configurable normalization rules\n switch (typeof from) {\n case 'string':\n return succeed(from);\n case 'bigint':\n case 'boolean':\n case 'number':\n case 'symbol':\n case 'undefined':\n return succeed(from);\n }\n if (from === null) {\n return succeed(from);\n }\n if (from instanceof Date) {\n return succeed(from);\n }\n if (from instanceof RegExp) {\n return succeed(from);\n }\n /* c8 ignore next 2 */\n return fail(`cannot normalize ${JSON.stringify(from)}`);\n }\n}\n"]}
1
+ {"version":3,"file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AAC,OAAO,EAAE,CAAC,CAAC,CAAC;IACxC,CAAC;IAES,eAAe,CAAC,IAAe;QACvC,OAAO,IAAA,mBAAU,EAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACxD,CAAC;IAED;;;;OAIG;IACI,gBAAgB,CAAI,IAAO;QAChC,+CAA+C;QAC/C,QAAQ,OAAO,IAAI,EAAE,CAAC;YACpB,KAAK,QAAQ;gBACX,OAAO,IAAA,gBAAO,EAAC,IAAI,CAAC,CAAC;YACvB,KAAK,QAAQ,CAAC;YACd,KAAK,SAAS,CAAC;YACf,KAAK,QAAQ,CAAC;YACd,KAAK,QAAQ,CAAC;YACd,KAAK,WAAW;gBACd,OAAO,IAAA,gBAAO,EAAC,IAAI,CAAC,CAAC;QACzB,CAAC;QACD,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YAClB,OAAO,IAAA,gBAAO,EAAC,IAAI,CAAC,CAAC;QACvB,CAAC;QACD,IAAI,IAAI,YAAY,IAAI,EAAE,CAAC;YACzB,OAAO,IAAA,gBAAO,EAAC,IAAI,CAAC,CAAC;QACvB,CAAC;QACD,IAAI,IAAI,YAAY,MAAM,EAAE,CAAC;YAC3B,OAAO,IAAA,gBAAO,EAAC,IAAI,CAAC,CAAC;QACvB,CAAC;QACD,sBAAsB;QACtB,OAAO,IAAA,aAAI,EAAC,oBAAoB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC1D,CAAC;CACF;AAxGD,gCAwGC","sourcesContent":["/*\n * Copyright (c) 2021 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Result, fail, mapResults, succeed } from './result';\n\n/**\n * @internal\n */\nexport type Entry<T> = [string | number | symbol, T];\n\n/**\n * @internal\n */\nexport type ResultEntry<T> = [string | number | symbol, Result<T>];\n\n/**\n * Normalizes an arbitrary JSON object\n * @public\n */\nexport class Normalizer {\n /**\n * Normalizes the supplied value\n *\n * @param from - The value to be normalized\n * @returns A normalized version of the value\n */\n public normalize<T>(from: T): Result<T> {\n switch (typeof from) {\n case 'string':\n case 'bigint':\n case 'boolean':\n case 'number':\n case 'symbol':\n case 'undefined':\n return this.normalizeLiteral(from);\n case 'object':\n if (from === null || from instanceof Date || from instanceof RegExp) {\n return this.normalizeLiteral(from);\n } else if (Array.isArray(from)) {\n return this._normalizeArray(from) as unknown as Result<T>;\n } else if (from instanceof Map) {\n return succeed(new Map(this.normalizeEntries(from.entries())) as unknown as T);\n } else if (from instanceof Set) {\n return succeed(new Set(this.normalizeEntries(from.entries())) as unknown as T);\n }\n const obj: { [key in number | string | symbol]: unknown } = {};\n for (const e of this.normalizeEntries(Object.entries(from as unknown as object))) {\n obj[e[0]] = e[1];\n }\n return succeed(obj as T);\n }\n return fail(`normalize: Unexpected type - cannot normalize '${typeof from}'`);\n }\n\n /**\n * Compares two property names from some object being normalized.\n * @param k1 - First key to be compared.\n * @param k2 - Second key to be compared.\n * @returns `1` if `k1` is greater, `-1` if `k2` is greater and\n * `0` if they are equal.\n * @internal\n */\n protected _compareKeys(k1: unknown, k2: unknown): number {\n const cs1 = String(k1);\n const cs2 = String(k2);\n if (cs1 > cs2) {\n return 1;\n }\n if (cs2 > cs1) {\n return -1;\n }\n /* c8 ignore next 2 */\n return 0;\n }\n\n /**\n * Normalizes an array of object property entries (e.g. as returned by `Object.entries()`).\n * @remarks\n * Converts property names (entry key) to string and then sorts as string.\n * @param entries - The entries to be normalized.\n * @returns A normalized sorted array of entries.\n */\n public normalizeEntries<T = unknown>(entries: Iterable<Entry<T>>): Entry<T>[] {\n return Array.from(entries)\n .sort((e1, e2) => this._compareKeys(e1[0], e2[0]))\n .map((e) => [e[0], this.normalize(e[1])] as ResultEntry<T>)\n .filter((e) => e[1].isSuccess())\n .map((e) => [e[0], e[1].orThrow()]);\n }\n\n protected _normalizeArray(from: unknown[]): Result<unknown[]> {\n return mapResults(from.map((v) => this.normalize(v)));\n }\n\n /**\n * Normalizes the supplied literal value\n * @param from - The literal value to be normalized.\n * @returns A normalized value for the literal.\n */\n public normalizeLiteral<T>(from: T): Result<T> {\n // TODO: Apply configurable normalization rules\n switch (typeof from) {\n case 'string':\n return succeed(from);\n case 'bigint':\n case 'boolean':\n case 'number':\n case 'symbol':\n case 'undefined':\n return succeed(from);\n }\n if (from === null) {\n return succeed(from);\n }\n if (from instanceof Date) {\n return succeed(from);\n }\n if (from instanceof RegExp) {\n return succeed(from);\n }\n /* c8 ignore next 2 */\n return fail(`cannot normalize ${JSON.stringify(from)}`);\n }\n}\n"]}
@@ -0,0 +1,11 @@
1
+ import { HashingNormalizer } from './hashingNormalizer';
2
+ /**
3
+ * A {@link Hash.HashingNormalizer | hashing normalizer} which computes object
4
+ * hash using the CRC32 algorithm.
5
+ * @public
6
+ */
7
+ export declare class Crc32Normalizer extends HashingNormalizer {
8
+ constructor();
9
+ static crc32Hash(parts: string[]): string;
10
+ }
11
+ //# sourceMappingURL=crcNormalizer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crcNormalizer.d.ts","sourceRoot":"","sources":["../../../src/packlets/hash/crcNormalizer.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD;;;;GAIG;AACH,qBAAa,eAAgB,SAAQ,iBAAiB;;WAKtC,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM;CAGjD"}
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2023 Erik Fortune
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in all
13
+ * copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
22
+ */
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.Crc32Normalizer = void 0;
25
+ const crc_1 = require("crc");
26
+ const hashingNormalizer_1 = require("./hashingNormalizer");
27
+ /**
28
+ * A {@link Hash.HashingNormalizer | hashing normalizer} which computes object
29
+ * hash using the CRC32 algorithm.
30
+ * @public
31
+ */
32
+ class Crc32Normalizer extends hashingNormalizer_1.HashingNormalizer {
33
+ constructor() {
34
+ super(Crc32Normalizer.crc32Hash);
35
+ }
36
+ static crc32Hash(parts) {
37
+ return String((0, crc_1.crc32)(parts.join('|')));
38
+ }
39
+ }
40
+ exports.Crc32Normalizer = Crc32Normalizer;
41
+ //# sourceMappingURL=crcNormalizer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crcNormalizer.js","sourceRoot":"","sources":["../../../src/packlets/hash/crcNormalizer.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,6BAA4B;AAC5B,2DAAwD;AAExD;;;;GAIG;AACH,MAAa,eAAgB,SAAQ,qCAAiB;IACpD;QACE,KAAK,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;IACnC,CAAC;IAEM,MAAM,CAAC,SAAS,CAAC,KAAe;QACrC,OAAO,MAAM,CAAC,IAAA,WAAK,EAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACxC,CAAC;CACF;AARD,0CAQC","sourcesContent":["/*\n * Copyright (c) 2023 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { crc32 } from 'crc';\nimport { HashingNormalizer } from './hashingNormalizer';\n\n/**\n * A {@link Hash.HashingNormalizer | hashing normalizer} which computes object\n * hash using the CRC32 algorithm.\n * @public\n */\nexport class Crc32Normalizer extends HashingNormalizer {\n public constructor() {\n super(Crc32Normalizer.crc32Hash);\n }\n\n public static crc32Hash(parts: string[]): string {\n return String(crc32(parts.join('|')));\n }\n}\n"]}
@@ -0,0 +1,23 @@
1
+ import { Normalizer, Result } from '../base';
2
+ /**
3
+ * Function to compute a hash from a pre-normalized array of strings.
4
+ * @public
5
+ */
6
+ export type HashFunction = (parts: string[]) => string;
7
+ /**
8
+ * Normalizes an arbitrary JSON object
9
+ * @public
10
+ */
11
+ export declare class HashingNormalizer extends Normalizer {
12
+ private _hash;
13
+ constructor(hash: HashFunction);
14
+ computeHash(from: unknown): Result<string>;
15
+ /**
16
+ * Constructs a normalized string representation of some literal value.
17
+ * @param from - The literal value to be normalized.
18
+ * @returns A normalized string representation of the literal.
19
+ * @internal
20
+ */
21
+ protected _normalizeLiteralToString(from: string | number | bigint | boolean | symbol | undefined | Date | RegExp | null): Result<string>;
22
+ }
23
+ //# sourceMappingURL=hashingNormalizer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hashingNormalizer.d.ts","sourceRoot":"","sources":["../../../src/packlets/hash/hashingNormalizer.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,UAAU,EAAE,MAAM,EAA4C,MAAM,SAAS,CAAC;AAEvF;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,MAAM,CAAC;AAEvD;;;GAGG;AACH,qBAAa,iBAAkB,SAAQ,UAAU;IAC/C,OAAO,CAAC,KAAK,CAAe;gBAET,IAAI,EAAE,YAAY;IAK9B,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC;IA4BjD;;;;;OAKG;IACH,SAAS,CAAC,yBAAyB,CACjC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,GACnF,MAAM,CAAC,MAAM,CAAC;CAuBlB"}
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2021 Erik Fortune
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in all
13
+ * copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
22
+ */
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.HashingNormalizer = void 0;
25
+ const base_1 = require("../base");
26
+ /**
27
+ * Normalizes an arbitrary JSON object
28
+ * @public
29
+ */
30
+ class HashingNormalizer extends base_1.Normalizer {
31
+ constructor(hash) {
32
+ super();
33
+ this._hash = hash;
34
+ }
35
+ computeHash(from) {
36
+ switch (typeof from) {
37
+ case 'string':
38
+ case 'bigint':
39
+ case 'boolean':
40
+ case 'number':
41
+ case 'symbol':
42
+ case 'undefined':
43
+ return this._normalizeLiteralToString(from).onSuccess((v) => {
44
+ return (0, base_1.captureResult)(() => this._hash([v]));
45
+ });
46
+ case 'object':
47
+ if (from === null || from instanceof Date || from instanceof RegExp) {
48
+ return this._normalizeLiteralToString(from).onSuccess((v) => {
49
+ return (0, base_1.captureResult)(() => this._hash([v]));
50
+ });
51
+ }
52
+ else if (Array.isArray(from)) {
53
+ return (0, base_1.mapResults)(from.map((e) => this.computeHash(e))).onSuccess((a) => {
54
+ return (0, base_1.captureResult)(() => this._hash(a));
55
+ });
56
+ }
57
+ else if (from instanceof Map || from instanceof Set) {
58
+ return this.computeHash(this.normalizeEntries(from.entries()));
59
+ }
60
+ return this.computeHash(this.normalizeEntries(Object.entries(from)));
61
+ }
62
+ return (0, base_1.fail)(`computeHash: Unexpected type - cannot hash '${typeof from}'`);
63
+ }
64
+ /**
65
+ * Constructs a normalized string representation of some literal value.
66
+ * @param from - The literal value to be normalized.
67
+ * @returns A normalized string representation of the literal.
68
+ * @internal
69
+ */
70
+ _normalizeLiteralToString(from) {
71
+ switch (typeof from) {
72
+ case 'string':
73
+ return (0, base_1.succeed)(from);
74
+ case 'bigint':
75
+ case 'boolean':
76
+ case 'number':
77
+ case 'symbol':
78
+ case 'undefined':
79
+ return (0, base_1.succeed)(`${typeof from}:[[[${String(from)}]]]`);
80
+ }
81
+ if (from === null) {
82
+ return (0, base_1.succeed)('object:[[[null]]');
83
+ }
84
+ if (from instanceof Date) {
85
+ return (0, base_1.succeed)(`Date:[[[${String(from.valueOf())}]]]`);
86
+ }
87
+ if (from instanceof RegExp) {
88
+ return (0, base_1.succeed)(`RegExp:[[[${from.toString()}]]]`);
89
+ }
90
+ /* c8 ignore next 2 */
91
+ return (0, base_1.fail)(`cannot normalize ${JSON.stringify(from)}`);
92
+ }
93
+ }
94
+ exports.HashingNormalizer = HashingNormalizer;
95
+ //# sourceMappingURL=hashingNormalizer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hashingNormalizer.js","sourceRoot":"","sources":["../../../src/packlets/hash/hashingNormalizer.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,kCAAuF;AAQvF;;;GAGG;AACH,MAAa,iBAAkB,SAAQ,iBAAU;IAG/C,YAAmB,IAAkB;QACnC,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAEM,WAAW,CAAC,IAAa;QAC9B,QAAQ,OAAO,IAAI,EAAE,CAAC;YACpB,KAAK,QAAQ,CAAC;YACd,KAAK,QAAQ,CAAC;YACd,KAAK,SAAS,CAAC;YACf,KAAK,QAAQ,CAAC;YACd,KAAK,QAAQ,CAAC;YACd,KAAK,WAAW;gBACd,OAAO,IAAI,CAAC,yBAAyB,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE;oBAC1D,OAAO,IAAA,oBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC9C,CAAC,CAAC,CAAC;YACL,KAAK,QAAQ;gBACX,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,YAAY,IAAI,IAAI,IAAI,YAAY,MAAM,EAAE,CAAC;oBACpE,OAAO,IAAI,CAAC,yBAAyB,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE;wBAC1D,OAAO,IAAA,oBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;oBAC9C,CAAC,CAAC,CAAC;gBACL,C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,CAAC;QACrC,CAAC;QACD,IAAI,IAAI,YAAY,IAAI,EAAE,CAAC;YACzB,OAAO,IAAA,cAAO,EAAC,WAAW,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;QACzD,CAAC;QACD,IAAI,IAAI,YAAY,MAAM,EAAE,CAAC;YAC3B,OAAO,IAAA,cAAO,EAAC,aAAa,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QACpD,CAAC;QACD,sBAAsB;QACtB,OAAO,IAAA,WAAI,EAAC,oBAAoB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC1D,CAAC;CACF;AAnED,8CAmEC","sourcesContent":["/*\n * Copyright (c) 2021 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Normalizer, Result, captureResult, fail, mapResults, succeed } from '../base';\n\n/**\n * Function to compute a hash from a pre-normalized array of strings.\n * @public\n */\nexport type HashFunction = (parts: string[]) => string;\n\n/**\n * Normalizes an arbitrary JSON object\n * @public\n */\nexport class HashingNormalizer extends Normalizer {\n private _hash: HashFunction;\n\n public constructor(hash: HashFunction) {\n super();\n this._hash = hash;\n }\n\n public computeHash(from: unknown): Result<string> {\n switch (typeof from) {\n case 'string':\n case 'bigint':\n case 'boolean':\n case 'number':\n case 'symbol':\n case 'undefined':\n return this._normalizeLiteralToString(from).onSuccess((v) => {\n return captureResult(() => this._hash([v]));\n });\n case 'object':\n if (from === null || from instanceof Date || from instanceof RegExp) {\n return this._normalizeLiteralToString(from).onSuccess((v) => {\n return captureResult(() => this._hash([v]));\n });\n } else if (Array.isArray(from)) {\n return mapResults(from.map((e) => this.computeHash(e))).onSuccess((a) => {\n return captureResult(() => this._hash(a));\n });\n } else if (from instanceof Map || from instanceof Set) {\n return this.computeHash(this.normalizeEntries(from.entries()));\n }\n return this.computeHash(this.normalizeEntries(Object.entries(from)));\n }\n return fail(`computeHash: Unexpected type - cannot hash '${typeof from}'`);\n }\n\n /**\n * Constructs a normalized string representation of some literal value.\n * @param from - The literal value to be normalized.\n * @returns A normalized string representation of the literal.\n * @internal\n */\n protected _normalizeLiteralToString(\n from: string | number | bigint | boolean | symbol | undefined | Date | RegExp | null\n ): Result<string> {\n switch (typeof from) {\n case 'string':\n return succeed(from);\n case 'bigint':\n case 'boolean':\n case 'number':\n case 'symbol':\n case 'undefined':\n return succeed(`${typeof from}:[[[${String(from)}]]]`);\n }\n if (from === null) {\n return succeed('object:[[[null]]');\n }\n if (from instanceof Date) {\n return succeed(`Date:[[[${String(from.valueOf())}]]]`);\n }\n if (from instanceof RegExp) {\n return succeed(`RegExp:[[[${from.toString()}]]]`);\n }\n /* c8 ignore next 2 */\n return fail(`cannot normalize ${JSON.stringify(from)}`);\n }\n}\n"]}
@@ -0,0 +1,3 @@
1
+ export * from './crcNormalizer';
2
+ export * from './hashingNormalizer';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/hash/index.ts"],"names":[],"mappings":"AAsBA,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2020 Erik Fortune
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in all
13
+ * copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
22
+ */
23
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
24
+ if (k2 === undefined) k2 = k;
25
+ var desc = Object.getOwnPropertyDescriptor(m, k);
26
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
27
+ desc = { enumerable: true, get: function() { return m[k]; } };
28
+ }
29
+ Object.defineProperty(o, k2, desc);
30
+ }) : (function(o, m, k, k2) {
31
+ if (k2 === undefined) k2 = k;
32
+ o[k2] = m[k];
33
+ }));
34
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
35
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ __exportStar(require("./crcNormalizer"), exports);
39
+ __exportStar(require("./hashingNormalizer"), exports);
40
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/hash/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;AAEH,kDAAgC;AAChC,sDAAoC","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nexport * from './crcNormalizer';\nexport * from './hashingNormalizer';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fgv/ts-utils",
3
- "version": "2.1.1-alpha.0",
3
+ "version": "2.1.1-alpha.2",
4
4
  "description": "Assorted Typescript Utilities",
5
5
  "main": "lib/index.js",
6
6
  "types": "dist/ts-utils.d.ts",
@@ -26,7 +26,7 @@
26
26
  "bugs": {
27
27
  "url": "https://github.com/ErikFortune/fgv/issues"
28
28
  },
29
- "homepage": "https://github.com/ErikFortune/fgv#readme",
29
+ "homepage": "https://github.com/ErikFortune/fgv/tree/main/libraries/ts-utils#readme",
30
30
  "devDependencies": {
31
31
  "@jest/expect-utils": "^29.7.0",
32
32
  "@microsoft/api-documenter": "^7.23.17",
@@ -60,6 +60,7 @@
60
60
  },
61
61
  "dependencies": {
62
62
  "luxon": "^3.4.4",
63
- "mustache": "^4.2.0"
63
+ "mustache": "^4.2.0",
64
+ "crc": "~4.3.2"
64
65
  }
65
66
  }