@nu-art/ts-common 0.200.89 → 0.200.90

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nu-art/ts-common",
3
- "version": "0.200.89",
3
+ "version": "0.200.90",
4
4
  "description": "js and ts infra",
5
5
  "keywords": [
6
6
  "TacB0sS",
@@ -87,3 +87,4 @@ export declare function groupArrayBy<T extends object, K extends string | number
87
87
  values: T[];
88
88
  }[];
89
89
  export declare function toggleInArray<T extends any = string, K extends any = (T extends object ? keyof T : T)>(arr: T[], item: T, mapper?: (item: T) => K): void;
90
+ export declare function generateArray<T extends any = number>(length: number, mapper?: (index: number) => T): T[];
@@ -26,7 +26,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
26
26
  });
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.toggleInArray = exports.groupArrayBy = exports.flatArray = exports.batchActionParallel = exports.batchAction = exports.sortArray = exports.reduceToMap = exports.arrayToMap = exports.filterFalsy = exports.filterInstances = exports.filterDuplicates = exports.findDuplicates = exports.filterAsync = exports.toggleElementInArray = exports.addItemToArrayAtIndex = exports.addItemToArray = exports.removeFromArrayByIndex = exports.removeFromArray = exports.removeItemFromArray = exports.filterInOut = void 0;
29
+ exports.generateArray = exports.toggleInArray = exports.groupArrayBy = exports.flatArray = exports.batchActionParallel = exports.batchAction = exports.sortArray = exports.reduceToMap = exports.arrayToMap = exports.filterFalsy = exports.filterInstances = exports.filterDuplicates = exports.findDuplicates = exports.filterAsync = exports.toggleElementInArray = exports.addItemToArrayAtIndex = exports.addItemToArray = exports.removeFromArrayByIndex = exports.removeFromArray = exports.removeItemFromArray = exports.filterInOut = void 0;
30
30
  const tools_1 = require("./tools");
31
31
  const object_tools_1 = require("./object-tools");
32
32
  function filterInOut(input, filter) {
@@ -243,3 +243,7 @@ function toggleInArray(arr, item, mapper = item => item) {
243
243
  arr.push(item);
244
244
  }
245
245
  exports.toggleInArray = toggleInArray;
246
+ function generateArray(length, mapper = i => i) {
247
+ return Array.from({ length }).map((e, i) => mapper(i));
248
+ }
249
+ exports.generateArray = generateArray;
@@ -24,4 +24,7 @@ export declare const tsValidateNonMandatoryObject: <T>(validator: ValidatorTypeR
24
24
  export declare const tsValidator_valueByKey: <T extends unknown>(validatorObject: {
25
25
  [k: string]: Validator<any> | import("./validator-core").TypeValidator<any>;
26
26
  }) => ValidatorTypeResolver<T>;
27
+ export declare const tsValidator_ArrayOfObjectsByKey: <T extends Object>(key: keyof T, validatorMap: {
28
+ [k: string]: ValidatorTypeResolver<T>;
29
+ }) => Validator<T[]>;
27
30
  export {};
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.tsValidator_valueByKey = exports.tsValidateNonMandatoryObject = exports.tsValidateAudit = exports.tsValidateTimestamp = exports.tsValidateRegexp = exports.tsValidateRange = exports.tsValidateIsInRange = exports.tsValidateValue = exports.tsValidateBoolean = exports.tsValidateEnum = exports.tsValidateNumber = exports.tsValidateString = exports.tsValidateArray = exports.tsValidateUnionV3 = exports.tsValidateCustom = exports.tsValidateUnion = exports.tsValidateDynamicObject = void 0;
3
+ exports.tsValidator_ArrayOfObjectsByKey = exports.tsValidator_valueByKey = exports.tsValidateNonMandatoryObject = exports.tsValidateAudit = exports.tsValidateTimestamp = exports.tsValidateRegexp = exports.tsValidateRange = exports.tsValidateIsInRange = exports.tsValidateValue = exports.tsValidateBoolean = exports.tsValidateEnum = exports.tsValidateNumber = exports.tsValidateString = exports.tsValidateArray = exports.tsValidateUnionV3 = exports.tsValidateCustom = exports.tsValidateUnion = exports.tsValidateDynamicObject = void 0;
4
4
  const tools_1 = require("../utils/tools");
5
5
  const validator_core_1 = require("./validator-core");
6
6
  const date_time_tools_1 = require("../utils/date-time-tools");
7
7
  const array_tools_1 = require("../utils/array-tools");
8
8
  const object_tools_1 = require("../utils/object-tools");
9
+ const exceptions_1 = require("../core/exceptions");
9
10
  const tsValidateDynamicObject = (valuesValidator, keysValidator, mandatory = true) => {
10
11
  return [(0, validator_core_1.tsValidateExists)(mandatory),
11
12
  (input) => {
@@ -186,3 +187,13 @@ const tsValidator_valueByKey = (validatorObject) => {
186
187
  });
187
188
  };
188
189
  exports.tsValidator_valueByKey = tsValidator_valueByKey;
190
+ const tsValidator_ArrayOfObjectsByKey = (key, validatorMap) => {
191
+ return (0, exports.tsValidateArray)((0, exports.tsValidateCustom)((value) => {
192
+ const _value = value;
193
+ const validator = validatorMap[_value[key]];
194
+ if (!validator)
195
+ throw new exceptions_1.BadImplementationException(`No validator defined for key ${key} with value ${_value[key]}`);
196
+ return (0, validator_core_1.tsValidateResult)(_value, validator);
197
+ }));
198
+ };
199
+ exports.tsValidator_ArrayOfObjectsByKey = tsValidator_ArrayOfObjectsByKey;