@dereekb/util 7.9.0 → 7.11.1

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/CHANGELOG.md CHANGED
@@ -2,6 +2,29 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ ## [7.11.1](https://github.com/dereekb/dbx-components/compare/v7.11.0-dev...v7.11.1) (2022-06-13)
6
+
7
+
8
+
9
+ # [7.11.0](https://github.com/dereekb/dbx-components/compare/v7.10.0-dev...v7.11.0) (2022-06-13)
10
+
11
+
12
+ ### Features
13
+
14
+ * added arrayToObject() ([edc723f](https://github.com/dereekb/dbx-components/commit/edc723f94a39f56dd6d43827595ee267830bf897))
15
+
16
+
17
+
18
+ # [7.10.0](https://github.com/dereekb/dbx-components/compare/v7.9.0-dev...v7.10.0) (2022-06-11)
19
+
20
+
21
+ ### Features
22
+
23
+ * added firestoreIdBatchVerifierFactory() ([182f086](https://github.com/dereekb/dbx-components/commit/182f086f80671fa38ed1268a6c98854f114ba629))
24
+ * added idBatchFactory() ([b39510b](https://github.com/dereekb/dbx-components/commit/b39510b7b617e927da48efe03b3121f74fe192e8))
25
+
26
+
27
+
5
28
  # [7.9.0](https://github.com/dereekb/dbx-components/compare/v7.8.1-dev...v7.9.0) (2022-06-11)
6
29
 
7
30
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dereekb/util",
3
- "version": "7.9.0",
3
+ "version": "7.11.1",
4
4
  "type": "commonjs",
5
5
  "exports": {
6
6
  ".": {
@@ -10,7 +10,8 @@
10
10
  },
11
11
  "./test": {
12
12
  "main": "./test/index.js",
13
- "types": "./test/index.d.ts"
13
+ "types": "./test/index.d.ts",
14
+ "default": "./test/index.js"
14
15
  }
15
16
  },
16
17
  "main": "./src/index.js",
@@ -1,12 +1,21 @@
1
1
  import { Factory, FactoryWithIndex, FactoryWithRequiredInput } from '../getter/getter';
2
+ import { AsyncMapFunction } from '../value/map';
2
3
  /**
3
4
  * Factory that generates multiple values given a number of items to make.
4
5
  */
5
6
  export declare type ArrayFactory<T> = FactoryWithRequiredInput<T[], number>;
7
+ /**
8
+ * Async ArrayFactory
9
+ */
10
+ export declare type AsyncArrayFactory<T> = AsyncMapFunction<ArrayFactory<T>>;
6
11
  /**
7
12
  * Factory that generates a value for each input value.
8
13
  */
9
14
  export declare type ArrayInputFactory<I, O> = FactoryWithRequiredInput<O[], I[]>;
15
+ /**
16
+ * Async ArrayInputFactory
17
+ */
18
+ export declare type AsyncArrayInputFactory<I, O> = AsyncMapFunction<ArrayInputFactory<I, O>>;
10
19
  /**
11
20
  * Creates a new ArrayFactory.
12
21
  *
@@ -1 +1 @@
1
- {"version":3,"file":"array.factory.js","sourceRoot":"","sources":["../../../../../../packages/util/src/lib/array/array.factory.ts"],"names":[],"mappings":";;;AAAA,6CAA8H;AAY9H;;;;;GAKG;AACH,SAAgB,YAAY,CAAI,OAAyC;IACvE,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,wBAAe,EAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AACpD,CAAC;AAFD,oCAEC;AAED;;;;;GAKG;AACH,SAAgB,iBAAiB,CAAO,OAAuC;IAC7E,OAAO,CAAC,KAAU,EAAE,EAAE,CAAC,IAAA,6BAAoB,EAAO,OAAO,EAAE,KAAK,CAAC,CAAC;AACpE,CAAC;AAFD,8CAEC"}
1
+ {"version":3,"file":"array.factory.js","sourceRoot":"","sources":["../../../../../../packages/util/src/lib/array/array.factory.ts"],"names":[],"mappings":";;;AAAA,6CAA8H;AAuB9H;;;;;GAKG;AACH,SAAgB,YAAY,CAAI,OAAyC;IACvE,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,wBAAe,EAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AACpD,CAAC;AAFD,oCAEC;AAED;;;;;GAKG;AACH,SAAgB,iBAAiB,CAAO,OAAuC;IAC7E,OAAO,CAAC,KAAU,EAAE,EAAE,CAAC,IAAA,6BAAoB,EAAO,OAAO,EAAE,KAAK,CAAC,CAAC;AACpE,CAAC;AAFD,8CAEC"}
@@ -30,7 +30,3 @@ export declare type RandomArrayFactory<T> = FactoryWithInput<T[], number>;
30
30
  * @returns
31
31
  */
32
32
  export declare function randomArrayFactory<T>(config: RandomArrayFactoryConfig<T>): RandomArrayFactory<T>;
33
- /**
34
- * @deprecated Use randomArrayFactory instead.
35
- */
36
- export declare const makeRandomArrayFn: typeof randomArrayFactory;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeRandomArrayFn = exports.randomArrayFactory = exports.makeArray = void 0;
3
+ exports.randomArrayFactory = exports.makeArray = void 0;
4
4
  const getter_1 = require("../getter");
5
5
  const random_1 = require("../number/random");
6
6
  const array_factory_1 = require("./array.factory");
@@ -29,8 +29,4 @@ function randomArrayFactory(config) {
29
29
  return (count = nextRandomCount()) => factory(count);
30
30
  }
31
31
  exports.randomArrayFactory = randomArrayFactory;
32
- /**
33
- * @deprecated Use randomArrayFactory instead.
34
- */
35
- exports.makeRandomArrayFn = randomArrayFactory;
36
32
  //# sourceMappingURL=array.make.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"array.make.js","sourceRoot":"","sources":["../../../../../../packages/util/src/lib/array/array.make.ts"],"names":[],"mappings":";;;AAAA,sCAAuE;AACvE,6CAAsG;AACtG,mDAA+C;AAW/C;;;;;;;GAOG;AACH,SAAgB,SAAS,CAAI,EAAE,KAAK,EAAE,IAAI,EAAgB;IACxD,OAAO,IAAA,wBAAe,EAAC,IAAkB,EAAE,KAAK,CAAC,CAAC;AACpD,CAAC;AAFD,8BAEC;AAYD;;;;;GAKG;AACH,SAAgB,kBAAkB,CAAI,MAAmC;IACvE,MAAM,QAAQ,GAAG,OAAO,MAAM,CAAC,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,IAAA,4BAAmB,EAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC1G,MAAM,eAAe,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;IACnD,MAAM,OAAO,GAAG,IAAA,4BAAY,EAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC1C,OAAO,CAAC,KAAK,GAAG,eAAe,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AACvD,CAAC;AALD,gDAKC;AAED;;GAEG;AACU,QAAA,iBAAiB,GAAG,kBAAkB,CAAC"}
1
+ {"version":3,"file":"array.make.js","sourceRoot":"","sources":["../../../../../../packages/util/src/lib/array/array.make.ts"],"names":[],"mappings":";;;AAAA,sCAAuE;AACvE,6CAAsG;AACtG,mDAA+C;AAW/C;;;;;;;GAOG;AACH,SAAgB,SAAS,CAAI,EAAE,KAAK,EAAE,IAAI,EAAgB;IACxD,OAAO,IAAA,wBAAe,EAAC,IAAkB,EAAE,KAAK,CAAC,CAAC;AACpD,CAAC;AAFD,8BAEC;AAYD;;;;;GAKG;AACH,SAAgB,kBAAkB,CAAI,MAAmC;IACvE,MAAM,QAAQ,GAAG,OAAO,MAAM,CAAC,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,IAAA,4BAAmB,EAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC1G,MAAM,eAAe,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;IACnD,MAAM,OAAO,GAAG,IAAA,4BAAY,EAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC1C,OAAO,CAAC,KAAK,GAAG,eAAe,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AACvD,CAAC;AALD,gDAKC"}
@@ -6,6 +6,12 @@ import { Maybe } from '../value/maybe.type';
6
6
  export declare function arrayToMap<T, V, K extends PrimativeKey = PrimativeKey>(values: T[], keyFn: ReadKeyFunction<T, K>, valueFn: (t: T) => V): Map<Maybe<K>, V>;
7
7
  export declare function arrayToMap<T, K extends PrimativeKey = PrimativeKey>(values: T[], keyFn: ReadKeyFunction<T, K>, valueFn: (t: T) => T): Map<Maybe<K>, T>;
8
8
  export declare function arrayToMap<T, K extends PrimativeKey = PrimativeKey>(values: T[], keyFn: ReadKeyFunction<T, K>): Map<Maybe<K>, T>;
9
+ /**
10
+ * Maps the values of the input array to a Record object. Can additionally specify a value function to map out the input value to another value for the map.
11
+ */
12
+ export declare function arrayToObject<T, V, K extends PrimativeKey = PrimativeKey>(values: T[], keyFn: ReadKeyFunction<T, K>, valueFn: (t: T) => V): Record<K, T>;
13
+ export declare function arrayToObject<T, K extends PrimativeKey = PrimativeKey>(values: T[], keyFn: ReadKeyFunction<T, K>, valueFn: (t: T) => T): Record<K, T>;
14
+ export declare function arrayToObject<T, K extends PrimativeKey = PrimativeKey>(values: T[], keyFn: ReadKeyFunction<T, K>): Record<K, T>;
9
15
  /**
10
16
  * Generates a value for the input
11
17
  *
@@ -1,10 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateIfDoesNotExist = exports.arrayToMap = void 0;
3
+ exports.generateIfDoesNotExist = exports.arrayToObject = exports.arrayToMap = void 0;
4
4
  function arrayToMap(values, keyFn, valueFn = (t) => t) {
5
5
  return new Map(values.map((x) => [keyFn(x), valueFn(x)]));
6
6
  }
7
7
  exports.arrayToMap = arrayToMap;
8
+ function arrayToObject(values, keyFn, valueFn = (t) => t) {
9
+ const record = {};
10
+ values.map((x) => {
11
+ const key = keyFn(x);
12
+ const value = valueFn(x);
13
+ if (key != undefined) {
14
+ record[key] = value;
15
+ }
16
+ });
17
+ return record;
18
+ }
19
+ exports.arrayToObject = arrayToObject;
8
20
  /**
9
21
  * Generates a value for the input
10
22
  *
@@ -1 +1 @@
1
- {"version":3,"file":"array.map.js","sourceRoot":"","sources":["../../../../../../packages/util/src/lib/array/array.map.ts"],"names":[],"mappings":";;;AASA,SAAgB,UAAU,CAA8C,MAAW,EAAE,KAA4B,EAAE,UAAuB,CAAC,CAAC,EAAE,EAAE,CAAC,CAAiB;IAChK,OAAO,IAAI,GAAG,CAAc,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACzE,CAAC;AAFD,gCAEC;AAED;;;;;;;;GAQG;AACH,SAAgB,sBAAsB,CAA2C,IAAS,EAAE,QAAa,EAAE,OAA8B,EAAE,UAAyB;IAClK,MAAM,GAAG,GAAG,UAAU,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAE1C,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;;QACpB,MAAM,KAAK,GAAG,MAAA,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,mCAAI,UAAU,CAAC,CAAC,CAAC,CAAC;QAC1C,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;AACL,CAAC;AAPD,wDAOC"}
1
+ {"version":3,"file":"array.map.js","sourceRoot":"","sources":["../../../../../../packages/util/src/lib/array/array.map.ts"],"names":[],"mappings":";;;AASA,SAAgB,UAAU,CAA8C,MAAW,EAAE,KAA4B,EAAE,UAAuB,CAAC,CAAC,EAAE,EAAE,CAAC,CAAiB;IAChK,OAAO,IAAI,GAAG,CAAc,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACzE,CAAC;AAFD,gCAEC;AAQD,SAAgB,aAAa,CAA8C,MAAW,EAAE,KAA4B,EAAE,UAAuB,CAAC,CAAC,EAAE,EAAE,CAAC,CAAiB;IACnK,MAAM,MAAM,GAAiB,EAAkB,CAAC;IAEhD,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QACf,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACrB,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;QAEzB,IAAI,GAAG,IAAI,SAAS,EAAE;YACpB,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;SACrB;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC;AAbD,sCAaC;AAED;;;;;;;;GAQG;AACH,SAAgB,sBAAsB,CAA2C,IAAS,EAAE,QAAa,EAAE,OAA8B,EAAE,UAAyB;IAClK,MAAM,GAAG,GAAG,UAAU,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAE1C,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;;QACpB,MAAM,KAAK,GAAG,MAAA,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,mCAAI,UAAU,CAAC,CAAC,CAAC,CAAC;QAC1C,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;AACL,CAAC;AAPD,wDAOC"}
@@ -2,12 +2,14 @@ import { PrimativeKey, ReadKeyFunction } from '../key';
2
2
  import { Maybe } from '../value/maybe.type';
3
3
  export declare function concatArraysUnique<T extends PrimativeKey = PrimativeKey>(...arrays: Maybe<T[]>[]): T[];
4
4
  export declare function flattenArrayUnique<T extends PrimativeKey = PrimativeKey>(array: T[][]): T[];
5
- export declare function unique<T extends PrimativeKey = PrimativeKey>(values: T[]): T[];
5
+ export declare function unique<T extends PrimativeKey = PrimativeKey>(values: T[], exclude?: T[]): T[];
6
6
  export declare function findUnique<T, K extends PrimativeKey = PrimativeKey>(models: T[], readKey: ReadKeyFunction<T, K>, additionalKeys?: K[]): T[];
7
7
  /**
8
8
  * Finds unique values in the input.
9
+ *
10
+ * Can also specify additional keys to exclude.
9
11
  */
10
- export declare type FindUniqueFunction<T> = (input: T[]) => T[];
12
+ export declare type FindUniqueFunction<T> = (input: T[], exclude?: T[]) => T[];
11
13
  /**
12
14
  * Creates a FindUniqueFunction.
13
15
  *
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.makeFindUniqueFunction = exports.findUnique = exports.unique = exports.flattenArrayUnique = exports.concatArraysUnique = void 0;
4
4
  const array_1 = require("./array");
5
+ const array_value_1 = require("./array.value");
6
+ const set_1 = require("../set/set");
5
7
  function concatArraysUnique(...arrays) {
6
8
  return unique((0, array_1.concatArrays)(...arrays));
7
9
  }
@@ -10,8 +12,12 @@ function flattenArrayUnique(array) {
10
12
  return unique((0, array_1.flattenArray)(array));
11
13
  }
12
14
  exports.flattenArrayUnique = flattenArrayUnique;
13
- function unique(values) {
14
- return Array.from(new Set(values));
15
+ function unique(values, exclude) {
16
+ const unique = new Set(values);
17
+ if (exclude != null && exclude.length) {
18
+ (0, set_1.removeFromSet)(unique, exclude);
19
+ }
20
+ return Array.from(unique);
15
21
  }
16
22
  exports.unique = unique;
17
23
  function findUnique(models, readKey, additionalKeys = []) {
@@ -34,7 +40,7 @@ exports.findUnique = findUnique;
34
40
  * @returns
35
41
  */
36
42
  function makeFindUniqueFunction(readKey, additionalKeys = []) {
37
- return (input) => findUnique(input, readKey, additionalKeys);
43
+ return (input, exclude) => findUnique(input, readKey, exclude ? (0, array_1.mergeArrays)([(0, array_value_1.filterMaybeValues)(exclude.map(readKey)), additionalKeys]) : additionalKeys);
38
44
  }
39
45
  exports.makeFindUniqueFunction = makeFindUniqueFunction;
40
46
  //# sourceMappingURL=array.unique.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"array.unique.js","sourceRoot":"","sources":["../../../../../../packages/util/src/lib/array/array.unique.ts"],"names":[],"mappings":";;;AAAA,mCAAqD;AAIrD,SAAgB,kBAAkB,CAAwC,GAAG,MAAoB;IAC/F,OAAO,MAAM,CAAC,IAAA,oBAAY,EAAC,GAAG,MAAM,CAAC,CAAC,CAAC;AACzC,CAAC;AAFD,gDAEC;AAED,SAAgB,kBAAkB,CAAwC,KAAY;IACpF,OAAO,MAAM,CAAC,IAAA,oBAAY,EAAC,KAAK,CAAC,CAAC,CAAC;AACrC,CAAC;AAFD,gDAEC;AAED,SAAgB,MAAM,CAAwC,MAAW;IACvE,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;AACrC,CAAC;AAFD,wBAEC;AAED,SAAgB,UAAU,CAA2C,MAAW,EAAE,OAA8B,EAAE,iBAAsB,EAAE;IACxI,MAAM,IAAI,GAAG,IAAI,GAAG,CAAW,cAAc,CAAC,CAAC;IAE/C,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE;QACzB,MAAM,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;QAEvB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;YAClB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACd,OAAO,IAAI,CAAC;SACb;QAED,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;AACL,CAAC;AAbD,gCAaC;AAOD;;;;;;GAMG;AACH,SAAgB,sBAAsB,CAA2C,OAA8B,EAAE,iBAAsB,EAAE;IACvI,OAAO,CAAC,KAAU,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,OAAO,EAAE,cAAc,CAAC,CAAC;AACpE,CAAC;AAFD,wDAEC"}
1
+ {"version":3,"file":"array.unique.js","sourceRoot":"","sources":["../../../../../../packages/util/src/lib/array/array.unique.ts"],"names":[],"mappings":";;;AAAA,mCAAkE;AAGlE,+CAAkD;AAClD,oCAA2C;AAE3C,SAAgB,kBAAkB,CAAwC,GAAG,MAAoB;IAC/F,OAAO,MAAM,CAAC,IAAA,oBAAY,EAAC,GAAG,MAAM,CAAC,CAAC,CAAC;AACzC,CAAC;AAFD,gDAEC;AAED,SAAgB,kBAAkB,CAAwC,KAAY;IACpF,OAAO,MAAM,CAAC,IAAA,oBAAY,EAAC,KAAK,CAAC,CAAC,CAAC;AACrC,CAAC;AAFD,gDAEC;AAED,SAAgB,MAAM,CAAwC,MAAW,EAAE,OAAa;IACtF,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;IAE/B,IAAI,OAAO,IAAI,IAAI,IAAI,OAAO,CAAC,MAAM,EAAE;QACrC,IAAA,mBAAa,EAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAChC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC5B,CAAC;AARD,wBAQC;AAED,SAAgB,UAAU,CAA2C,MAAW,EAAE,OAA8B,EAAE,iBAAsB,EAAE;IACxI,MAAM,IAAI,GAAG,IAAI,GAAG,CAAW,cAAc,CAAC,CAAC;IAE/C,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE;QACzB,MAAM,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;QAEvB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;YAClB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACd,OAAO,IAAI,CAAC;SACb;QAED,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;AACL,CAAC;AAbD,gCAaC;AASD;;;;;;GAMG;AACH,SAAgB,sBAAsB,CAA2C,OAA8B,EAAE,iBAAsB,EAAE;IACvI,OAAO,CAAC,KAAU,EAAE,OAAa,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,IAAA,mBAAW,EAAC,CAAC,IAAA,+BAAiB,EAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC;AACtK,CAAC;AAFD,wDAEC"}
@@ -0,0 +1,12 @@
1
+ import { Factory } from './getter';
2
+ /**
3
+ * Returns a random value.
4
+ */
5
+ export declare type RandomFromArrayFactory<T> = Factory<T>;
6
+ /**
7
+ * Makes a RandomFromArrayFactory
8
+ *
9
+ * @param config
10
+ * @returns
11
+ */
12
+ export declare function randomFromArrayFactory<T>(values: T[]): RandomFromArrayFactory<T>;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.randomFromArrayFactory = void 0;
4
+ const random_1 = require("../number/random");
5
+ /**
6
+ * Makes a RandomFromArrayFactory
7
+ *
8
+ * @param config
9
+ * @returns
10
+ */
11
+ function randomFromArrayFactory(values) {
12
+ const random = (0, random_1.randomNumberFactory)({ min: 0, max: values.length - 1, round: 'floor' });
13
+ return () => values[random()];
14
+ }
15
+ exports.randomFromArrayFactory = randomFromArrayFactory;
16
+ //# sourceMappingURL=getter.util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getter.util.js","sourceRoot":"","sources":["../../../../../../packages/util/src/lib/getter/getter.util.ts"],"names":[],"mappings":";;;AAAA,6CAAuD;AAQvD;;;;;GAKG;AACH,SAAgB,sBAAsB,CAAI,MAAW;IACnD,MAAM,MAAM,GAAG,IAAA,4BAAmB,EAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;IACvF,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;AAChC,CAAC;AAHD,wDAGC"}
@@ -1,4 +1,5 @@
1
1
  export * from './type';
2
2
  export * from './getter';
3
+ export * from './getter.util';
3
4
  export * from './getter.cache';
4
5
  export * from './getter.map';
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./type"), exports);
5
5
  tslib_1.__exportStar(require("./getter"), exports);
6
+ tslib_1.__exportStar(require("./getter.util"), exports);
6
7
  tslib_1.__exportStar(require("./getter.cache"), exports);
7
8
  tslib_1.__exportStar(require("./getter.map"), exports);
8
9
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/util/src/lib/getter/index.ts"],"names":[],"mappings":";;;AAAA,iDAAuB;AACvB,mDAAyB;AACzB,yDAA+B;AAC/B,uDAA6B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/util/src/lib/getter/index.ts"],"names":[],"mappings":";;;AAAA,iDAAuB;AACvB,mDAAyB;AACzB,wDAA8B;AAC9B,yDAA+B;AAC/B,uDAA6B"}
@@ -0,0 +1,36 @@
1
+ import { ArrayFactory, AsyncArrayFactory } from '../array/array.factory';
2
+ import { FindUniqueFunction } from '../array/array.unique';
3
+ import { AsyncMapFunction, MapFunction } from '../value/map';
4
+ /**
5
+ * Used to verify each id valid and available for use.
6
+ */
7
+ export declare type IdBatchVerifierFunction<T> = AsyncMapFunction<MapFunction<T[], T[]>>;
8
+ /**
9
+ * Used by to verify tags have not already been taken.
10
+ */
11
+ export declare type IdBatchVerifier<T> = {
12
+ /**
13
+ * Optional function to ensure uniqueness.
14
+ */
15
+ findUnique?: FindUniqueFunction<T>;
16
+ verify: IdBatchVerifierFunction<T>;
17
+ /**
18
+ * Max number of tags that can be verified per batch.
19
+ */
20
+ maxBatchSize: number;
21
+ };
22
+ export interface IdBatchFactoryConfig<T> {
23
+ readonly factory: ArrayFactory<T>;
24
+ readonly verifier: IdBatchVerifier<T>;
25
+ }
26
+ /**
27
+ * Used to generate valid, unused identifiers.
28
+ */
29
+ export declare type IdBatchFactory<T> = AsyncArrayFactory<T>;
30
+ /**
31
+ * Creates an IdBatchFactory
32
+ *
33
+ * @param config
34
+ * @returns
35
+ */
36
+ export declare function idBatchFactory<T>(config: IdBatchFactoryConfig<T>): IdBatchFactory<T>;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.idBatchFactory = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const array_1 = require("../array");
6
+ const promise_loop_1 = require("../promise/promise.loop");
7
+ /**
8
+ * Creates an IdBatchFactory
9
+ *
10
+ * @param config
11
+ * @returns
12
+ */
13
+ function idBatchFactory(config) {
14
+ const { factory, verifier } = config;
15
+ const { maxBatchSize: tagsToGeneratePerBatch, findUnique = (x) => x, verify: verifyTags } = verifier;
16
+ const maxUniquenessFailures = 20; // arbitrary failure point, but generally shouldn't occur with proper input.
17
+ return (totalTagIdentifiersToGenerate) => tslib_1.__awaiter(this, void 0, void 0, function* () {
18
+ const uniquenessAccumulator = []; // used for uniqueness checks
19
+ function generateIdentifiersBatch(batchSize) {
20
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
21
+ let ids = [];
22
+ let uniquenessFailure = 0;
23
+ while (ids.length < batchSize) {
24
+ const countToGenerate = batchSize - ids.length;
25
+ let newIds = findUnique(factory(countToGenerate), uniquenessAccumulator);
26
+ if (newIds.length === 0) {
27
+ uniquenessFailure += 1;
28
+ if (uniquenessFailure === maxUniquenessFailures) {
29
+ throw new Error(`idBatchFactory failed generating unique values "${maxUniquenessFailures}" times. Factory may be insufficient for generating unique values.`);
30
+ }
31
+ continue;
32
+ }
33
+ else if (newIds.length > countToGenerate) {
34
+ newIds = newIds.slice(0, countToGenerate); // ignore any extra values the generator may return.
35
+ }
36
+ // add to the uniqueness acumulator to prevent further usage
37
+ (0, array_1.mergeIntoArray)(uniquenessAccumulator, newIds);
38
+ const verifiedIds = yield verifyTags(newIds);
39
+ // concat identifiers
40
+ ids = ids.concat(verifiedIds);
41
+ // restart loop if there are still items to be generated.
42
+ }
43
+ return ids;
44
+ });
45
+ }
46
+ const tagBatches = yield (0, promise_loop_1.performBatchLoop)({
47
+ totalItems: totalTagIdentifiersToGenerate,
48
+ itemsPerBatch: tagsToGeneratePerBatch,
49
+ make: (batchSize) => tslib_1.__awaiter(this, void 0, void 0, function* () {
50
+ const result = yield generateIdentifiersBatch(batchSize);
51
+ return result;
52
+ })
53
+ });
54
+ return tagBatches.flat();
55
+ });
56
+ }
57
+ exports.idBatchFactory = idBatchFactory;
58
+ //# sourceMappingURL=id.batch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"id.batch.js","sourceRoot":"","sources":["../../../../../../packages/util/src/lib/model/id.batch.ts"],"names":[],"mappings":";;;;AAAA,oCAA0C;AAG1C,0DAA2D;AAiC3D;;;;;GAKG;AACH,SAAgB,cAAc,CAAI,MAA+B;IAC/D,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC;IACrC,MAAM,EAAE,YAAY,EAAE,sBAAsB,EAAE,UAAU,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,QAAQ,CAAC;IACrG,MAAM,qBAAqB,GAAG,EAAE,CAAC,CAAC,4EAA4E;IAE9G,OAAO,CAAO,6BAAqC,EAAE,EAAE;QACrD,MAAM,qBAAqB,GAAQ,EAAE,CAAC,CAAC,6BAA6B;QAEpE,SAAe,wBAAwB,CAAC,SAAiB;;gBACvD,IAAI,GAAG,GAAQ,EAAE,CAAC;gBAElB,IAAI,iBAAiB,GAAG,CAAC,CAAC;gBAC1B,OAAO,GAAG,CAAC,MAAM,GAAG,SAAS,EAAE;oBAC7B,MAAM,eAAe,GAAG,SAAS,GAAG,GAAG,CAAC,MAAM,CAAC;oBAC/C,IAAI,MAAM,GAAG,UAAU,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,qBAAqB,CAAC,CAAC;oBAEzE,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;wBACvB,iBAAiB,IAAI,CAAC,CAAC;wBAEvB,IAAI,iBAAiB,KAAK,qBAAqB,EAAE;4BAC/C,MAAM,IAAI,KAAK,CAAC,mDAAmD,qBAAqB,oEAAoE,CAAC,CAAC;yBAC/J;wBACD,SAAS;qBACV;yBAAM,IAAI,MAAM,CAAC,MAAM,GAAG,eAAe,EAAE;wBAC1C,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,oDAAoD;qBAChG;oBAED,4DAA4D;oBAC5D,IAAA,sBAAc,EAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;oBAE9C,MAAM,WAAW,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,CAAC;oBAE7C,qBAAqB;oBACrB,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;oBAE9B,yDAAyD;iBAC1D;gBAED,OAAO,GAAG,CAAC;YACb,CAAC;SAAA;QAED,MAAM,UAAU,GAAU,MAAM,IAAA,+BAAgB,EAAI;YAClD,UAAU,EAAE,6BAA6B;YACzC,aAAa,EAAE,sBAAsB;YACrC,IAAI,EAAE,CAAO,SAAiB,EAAE,EAAE;gBAChC,MAAM,MAAM,GAAQ,MAAM,wBAAwB,CAAC,SAAS,CAAC,CAAC;gBAC9D,OAAO,MAAM,CAAC;YAChB,CAAC,CAAA;SACF,CAAC,CAAC;QAEH,OAAO,UAAU,CAAC,IAAI,EAAE,CAAC;IAC3B,CAAC,CAAA,CAAC;AACJ,CAAC;AApDD,wCAoDC"}
@@ -3,3 +3,4 @@ export * from './model.copy';
3
3
  export * from './model.conversion';
4
4
  export * from './model.conversion.field';
5
5
  export * from './model.modify';
6
+ export * from './id.batch';
@@ -6,4 +6,5 @@ tslib_1.__exportStar(require("./model.copy"), exports);
6
6
  tslib_1.__exportStar(require("./model.conversion"), exports);
7
7
  tslib_1.__exportStar(require("./model.conversion.field"), exports);
8
8
  tslib_1.__exportStar(require("./model.modify"), exports);
9
+ tslib_1.__exportStar(require("./id.batch"), exports);
9
10
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/util/src/lib/model/index.ts"],"names":[],"mappings":";;;AAAA,kDAAwB;AACxB,uDAA6B;AAC7B,6DAAmC;AACnC,mEAAyC;AACzC,yDAA+B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/util/src/lib/model/index.ts"],"names":[],"mappings":";;;AAAA,kDAAwB;AACxB,uDAA6B;AAC7B,6DAAmC;AACnC,mEAAyC;AACzC,yDAA+B;AAC/B,qDAA2B"}
@@ -1,6 +1,18 @@
1
+ import { MapFunction } from '../value/map';
1
2
  import { Factory } from './../getter/getter';
2
3
  export declare type RandomNumberFactory = Factory<number>;
4
+ export declare type NumberRounding = 'none' | 'floor' | 'ceil' | 'round';
5
+ export declare type RoundingFunction = MapFunction<number, number>;
6
+ export declare function roundingFunction(type: NumberRounding): RoundingFunction;
7
+ export declare type RoundingInput = NumberRounding | RoundingFunction;
8
+ /**
9
+ * randomNumberFactory configuration
10
+ */
3
11
  export interface RandomNumberFactoryConfig {
12
+ /**
13
+ * Rounding type. By default will round to
14
+ */
15
+ round?: RoundingInput;
4
16
  min?: number;
5
17
  max: number;
6
18
  }
@@ -11,7 +23,7 @@ export declare type RandomNumberFactoryInput = number | RandomNumberFactoryConfi
11
23
  * @param maxOrArgs
12
24
  * @returns
13
25
  */
14
- export declare function randomNumberFactory(maxOrArgs: RandomNumberFactoryInput): RandomNumberFactory;
26
+ export declare function randomNumberFactory(maxOrArgs: RandomNumberFactoryInput, roundingInput?: RoundingInput): RandomNumberFactory;
15
27
  /**
16
28
  * @deprecated use randomNumberFactory() instead.
17
29
  */
@@ -1,15 +1,36 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeRandomFunction = exports.randomNumberFactory = void 0;
3
+ exports.makeRandomFunction = exports.randomNumberFactory = exports.roundingFunction = void 0;
4
+ function roundingFunction(type) {
5
+ let fn;
6
+ switch (type) {
7
+ case 'floor':
8
+ fn = Math.floor;
9
+ break;
10
+ case 'ceil':
11
+ fn = Math.ceil;
12
+ break;
13
+ case 'none':
14
+ fn = (x) => x;
15
+ break;
16
+ case 'round':
17
+ default:
18
+ fn = Math.round;
19
+ break;
20
+ }
21
+ return fn;
22
+ }
23
+ exports.roundingFunction = roundingFunction;
4
24
  /**
5
25
  * Used to generate a RandomNumberFunction that returns a number between the input and the maximum.
6
26
  *
7
27
  * @param maxOrArgs
8
28
  * @returns
9
29
  */
10
- function randomNumberFactory(maxOrArgs) {
30
+ function randomNumberFactory(maxOrArgs, roundingInput) {
11
31
  const config = typeof maxOrArgs === 'number' ? { min: 0, max: maxOrArgs } : maxOrArgs;
12
- const { min, max } = config;
32
+ const { min, max, round: roundConfig } = config;
33
+ const round = roundingInput !== null && roundingInput !== void 0 ? roundingInput : roundConfig;
13
34
  let fn;
14
35
  if (min != null) {
15
36
  const range = max - min;
@@ -18,6 +39,11 @@ function randomNumberFactory(maxOrArgs) {
18
39
  else {
19
40
  fn = () => Math.random() * max;
20
41
  }
42
+ if (round && round !== 'none') {
43
+ const roundFn = typeof round === 'function' ? round : roundingFunction(round);
44
+ const randomFn = fn;
45
+ fn = () => roundFn(randomFn());
46
+ }
21
47
  return fn;
22
48
  }
23
49
  exports.randomNumberFactory = randomNumberFactory;
@@ -1 +1 @@
1
- {"version":3,"file":"random.js","sourceRoot":"","sources":["../../../../../../packages/util/src/lib/number/random.ts"],"names":[],"mappings":";;;AAWA;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,SAAmC;IACrE,MAAM,MAAM,GAA8B,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IACjH,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,MAAM,CAAC;IAC5B,IAAI,EAAuB,CAAC;IAE5B,IAAI,GAAG,IAAI,IAAI,EAAE;QACf,MAAM,KAAK,GAAG,GAAG,GAAG,GAAG,CAAC;QACxB,EAAE,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,KAAK,GAAG,GAAG,CAAC;KACxC;SAAM;QACL,EAAE,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC;KAChC;IAED,OAAO,EAAE,CAAC;AACZ,CAAC;AAbD,kDAaC;AAED;;GAEG;AACU,QAAA,kBAAkB,GAAG,mBAAmB,CAAC"}
1
+ {"version":3,"file":"random.js","sourceRoot":"","sources":["../../../../../../packages/util/src/lib/number/random.ts"],"names":[],"mappings":";;;AAQA,SAAgB,gBAAgB,CAAC,IAAoB;IACnD,IAAI,EAAoB,CAAC;IAEzB,QAAQ,IAAI,EAAE;QACZ,KAAK,OAAO;YACV,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;YAChB,MAAM;QACR,KAAK,MAAM;YACT,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC;YACf,MAAM;QACR,KAAK,MAAM;YACT,EAAE,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;YACd,MAAM;QACR,KAAK,OAAO,CAAC;QACb;YACE,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;YAChB,MAAM;KACT;IAED,OAAO,EAAE,CAAC;AACZ,CAAC;AApBD,4CAoBC;AAkBD;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,SAAmC,EAAE,aAA6B;IACpG,MAAM,MAAM,GAA8B,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IACjH,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,MAAM,CAAC;IAChD,MAAM,KAAK,GAAG,aAAa,aAAb,aAAa,cAAb,aAAa,GAAI,WAAW,CAAC;IAC3C,IAAI,EAAuB,CAAC;IAE5B,IAAI,GAAG,IAAI,IAAI,EAAE;QACf,MAAM,KAAK,GAAG,GAAG,GAAG,GAAG,CAAC;QACxB,EAAE,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,KAAK,GAAG,GAAG,CAAC;KACxC;SAAM;QACL,EAAE,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC;KAChC;IAED,IAAI,KAAK,IAAI,KAAK,KAAK,MAAM,EAAE;QAC7B,MAAM,OAAO,GAAG,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;QAC9E,MAAM,QAAQ,GAAG,EAAE,CAAC;QACpB,EAAE,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;KAChC;IAED,OAAO,EAAE,CAAC;AACZ,CAAC;AApBD,kDAoBC;AAED;;GAEG;AACU,QAAA,kBAAkB,GAAG,mBAAmB,CAAC"}
package/test/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ ## [7.11.1](https://github.com/dereekb/dbx-components/compare/v7.11.0-dev...v7.11.1) (2022-06-13)
6
+
7
+
8
+
9
+ # [7.11.0](https://github.com/dereekb/dbx-components/compare/v7.10.0-dev...v7.11.0) (2022-06-13)
10
+
11
+
12
+
13
+ # [7.10.0](https://github.com/dereekb/dbx-components/compare/v7.9.0-dev...v7.10.0) (2022-06-11)
14
+
15
+
16
+
5
17
  # [7.9.0](https://github.com/dereekb/dbx-components/compare/v7.8.1-dev...v7.9.0) (2022-06-11)
6
18
 
7
19
 
package/test/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@dereekb/util/test",
3
- "version": "7.9.0",
3
+ "version": "7.11.1",
4
4
  "main": "./src/index.js",
5
5
  "typings": "./src/index.d.ts",
6
6
  "dependencies": {},
7
7
  "peerDependencies": {
8
- "@dereekb/util": "7.9.0",
8
+ "@dereekb/util": "7.11.1",
9
9
  "make-error": "^1.3.0",
10
10
  "ts-essentials": "^9.1.2",
11
11
  "extra-set": "^2.2.11",