@local901/validator 0.1.0 → 0.2.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.
@@ -1,8 +1,9 @@
1
1
  import type { ErrorValue } from "./ErrorType";
2
- type ArrayError<T extends ReadonlyArray<unknown>> = T extends [infer ITEM, ...infer ARR] ? [ValidationError<ITEM> | null, ...ARR extends never[] ? [] : ArrayError<ARR>] : T extends ReadonlyArray<infer ARR> ? Array<ValidationError<ARR> | null> : never;
3
- export type ErrorFields<T> = ((T extends object ? T extends readonly unknown[] ? ArrayError<T> : {
2
+ type TupleError<T extends ReadonlyArray<unknown>> = T extends [infer ITEM, ...infer ARR] ? [ValidationError<ITEM> | null, ...ARR extends never[] ? [] : TupleError<ARR>] : never;
3
+ type ArrayError<T extends ReadonlyArray<unknown>> = T extends [infer _ITEM, ...infer _ARR] ? TupleError<T> : T extends ReadonlyArray<infer ARR> ? Record<number, ValidationError<ARR> | null> : never;
4
+ export type ErrorFields<T> = (T extends object ? T extends readonly unknown[] ? ArrayError<T> : {
4
5
  [K in keyof T]: ValidationError<T[K]> | undefined;
5
- } : never) | Record<number, ValidationError<T>>);
6
+ } : never) | Record<number, ValidationError<T>>;
6
7
  export declare class ValidationError<T extends unknown = unknown> extends Error {
7
8
  readonly type: string;
8
9
  readonly error: ErrorValue;
@@ -1 +1 @@
1
- {"version":3,"file":"ValidationError.js","sourceRoot":"","sources":["../../src/errors/ValidationError.ts"],"names":[],"mappings":";;;AAYA,MAAa,eAEX,SAAQ,KAAK;IACK,IAAI,CAAS;IACb,KAAK,CAAa;IAClB,MAAM,CAAiB;IAEvC,YAAmB,IAAY,EAAE,KAAiB,EAAE,OAAe,EAAE,MAAuB;QACxF,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;CACJ;AAbD,0CAaC"}
1
+ {"version":3,"file":"ValidationError.js","sourceRoot":"","sources":["../../src/errors/ValidationError.ts"],"names":[],"mappings":";;;AAkBA,MAAa,eAEX,SAAQ,KAAK;IACK,IAAI,CAAS;IACb,KAAK,CAAa;IAClB,MAAM,CAAiB;IAEvC,YAAmB,IAAY,EAAE,KAAiB,EAAE,OAAe,EAAE,MAAuB;QACxF,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;CACJ;AAbD,0CAaC"}
package/index.d.ts CHANGED
@@ -10,6 +10,7 @@ import { OrValidator, type OrValidators } from "./types/util/OrValidator";
10
10
  import { ArrayValidator, type ArrayValidatorOptions } from "./types/object/ArrayValidator";
11
11
  import { EnumValidator, type EnumLike } from "./types/object/EnumValidator";
12
12
  import { TupleValidator, type TupleValidators } from "./types/object/TupleValidator";
13
+ import { InstanceofValidator, type ConstructorType, type InstanceofValidationOptions } from "./types/util/InstanceofValidator";
13
14
  export { Validator } from "./Validator";
14
15
  export { ErrorType, type ErrorValue } from "./errors/ErrorType";
15
16
  export { ValidationError, type ErrorFields } from "./errors/ValidationError";
@@ -23,6 +24,7 @@ export declare class v {
23
24
  static tuple: <T extends [...unknown[]]>(validators: TupleValidators<T>) => TupleValidator<T>;
24
25
  static string: <T extends string = string>(options?: StringValidationOptions) => stringValidator<T>;
25
26
  static any: <T>() => AnyValidator<T>;
27
+ static instanceof: <T>(instance: ConstructorType<T>, options: InstanceofValidationOptions<T>) => InstanceofValidator<T>;
26
28
  static optional: <T>(val: Validator<Exclude<T, undefined | null>>) => OptionalValidator<T>;
27
29
  static or: <T>(validators: OrValidators<T>) => OrValidator<T>;
28
30
  }
package/index.js CHANGED
@@ -12,6 +12,7 @@ const OrValidator_1 = require("./types/util/OrValidator");
12
12
  const ArrayValidator_1 = require("./types/object/ArrayValidator");
13
13
  const EnumValidator_1 = require("./types/object/EnumValidator");
14
14
  const TupleValidator_1 = require("./types/object/TupleValidator");
15
+ const InstanceofValidator_1 = require("./types/util/InstanceofValidator");
15
16
  var Validator_1 = require("./Validator");
16
17
  Object.defineProperty(exports, "Validator", { enumerable: true, get: function () { return Validator_1.Validator; } });
17
18
  var ErrorType_1 = require("./errors/ErrorType");
@@ -28,6 +29,7 @@ class v {
28
29
  static tuple = (validators) => new TupleValidator_1.TupleValidator(validators);
29
30
  static string = (options) => new StringValidator_1.stringValidator(options);
30
31
  static any = () => new AnyValidator_1.AnyValidator();
32
+ static instanceof = (instance, options) => new InstanceofValidator_1.InstanceofValidator(instance, options);
31
33
  static optional = (val) => new OptionalValidator_1.OptionalValidator(val);
32
34
  static or = (validators) => new OrValidator_1.OrValidator(validators);
33
35
  }
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,oEAAiE;AACjE,8DAAsF;AACtF,oEAA+F;AAC/F,oEAAuF;AACvF,sEAAmE;AACnE,oEAA+F;AAE/F,4DAAyD;AACzD,0DAA0E;AAC1E,kEAA2F;AAC3F,gEAA4E;AAC5E,kEAAqF;AAErF,yCAAwC;AAA/B,sGAAA,SAAS,OAAA;AAClB,gDAAgE;AAAvD,sGAAA,SAAS,OAAA;AAClB,4DAA6E;AAApE,kHAAA,eAAe,OAAA;AAExB,MAAa,CAAC;IACH,MAAM,CAAC,OAAO,GAAG,GAAG,EAAE,CAAC,IAAI,mCAAgB,EAAE,CAAC;IAE9C,MAAM,CAAC,GAAG,GAAG,CAAC,OAA8B,EAAE,EAAE,CAAC,IAAI,2BAAY,CAAC,OAAO,CAAC,CAAC;IAC3E,MAAM,CAAC,MAAM,GAAG,CAAC,OAAiC,EAAE,EAAE,CAAC,IAAI,iCAAe,CAAC,OAAO,CAAC,CAAC;IAEpF,MA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": "@local901/validator",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Type validator for javascript and typescript",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -18,11 +18,11 @@ class IntValidator extends Validator_1.Validator {
18
18
  }
19
19
  // Minimum value check
20
20
  if (this.options.min !== undefined && input < this.options.min) {
21
- return this.createError(ErrorType_1.ErrorType.VALUE_BELOW, `Has to be a minimum value of ${this.options.min}`);
21
+ return this.createError(ErrorType_1.ErrorType.VALUE_BELOW, `Has to be a minimum value of ${this.options.min}.`);
22
22
  }
23
23
  // Maximum value check
24
24
  if (this.options.max !== undefined && this.options.max < input) {
25
- return this.createError(ErrorType_1.ErrorType.VALUE_ABOVE, `Has to be a maximum value of ${this.options.max}`);
25
+ return this.createError(ErrorType_1.ErrorType.VALUE_ABOVE, `Has to be a maximum value of ${this.options.max}.`);
26
26
  }
27
27
  return null;
28
28
  }
@@ -1 +1 @@
1
- {"version":3,"file":"IntValidator.js","sourceRoot":"","sources":["../../../src/types/number/IntValidator.ts"],"names":[],"mappings":";;;AAAA,sDAAmD;AAEnD,+CAA4C;AAS5C,MAAa,YAAa,SAAQ,qBAAiB;IAGX;IAFpB,IAAI,GAAG,KAAK,CAAC;IAE7B,YAAoC,UAAgC,EAAE;QAClE,KAAK,EAAE,CAAC;QADwB,YAAO,GAAP,OAAO,CAA2B;IAEtE,CAAC;IAED,kBAAkB;IACF,cAAc,CAAC,KAAc;QACzC,cAAc;QACd,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,KAAK,EAAE,CAAC;YAC3D,OAAO,IAAI,CAAC,WAAW,CAAC,qBAAS,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAC;QAC1E,CAAC;QAED,sBAAsB;QACtB,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,KAAK,SAAS,IAAI,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;YA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AED,sBAAsB;QACtB,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,KAAK,SAAS,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,GAAG,KAAK,EAAE,CAAC;YAC7D,OAAO,IAAI,CAAC,WAAW,CAAC,qBAAS,CAAC,WAAW,EAAE,gCAAgC,IAAI,CAAC,OAAO,CAAC,GAAG,GAAG,CAAC,CAAA;QACvG,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AAzBD,oCAyBC"}
@@ -18,11 +18,11 @@ class NumberValidator extends Validator_1.Validator {
18
18
  }
19
19
  // Minimum value check.
20
20
  if (this.options.min !== undefined && (this.options.minExclusive ? input <= this.options.min : input < this.options.min)) {
21
- return this.createError(this.options.minExclusive ? ErrorType_1.ErrorType.VALUE_BELOW_EXCLUSIVE : ErrorType_1.ErrorType.VALUE_BELOW, `Has to be a minimum value of ${this.options.min}${this.options.minExclusive ? " (exclusive)" : ""}`);
21
+ return this.createError(this.options.minExclusive ? ErrorType_1.ErrorType.VALUE_BELOW_EXCLUSIVE : ErrorType_1.ErrorType.VALUE_BELOW, `Has to be a minimum value of ${this.options.min}${this.options.minExclusive ? " (exclusive)" : ""}.`);
22
22
  }
23
23
  // Maximum value check.
24
24
  if (this.options.max !== undefined && (this.options.maxExclusive ? this.options.max <= input : this.options.max < input)) {
25
- return this.createError(this.options.maxExclusive ? ErrorType_1.ErrorType.VALUE_ABOVE_EXCLUSIVE : ErrorType_1.ErrorType.VALUE_ABOVE, `Has to be a maximum value of ${this.options.max}${this.options.minExclusive ? " (exclusive)" : ""}`);
25
+ return this.createError(this.options.maxExclusive ? ErrorType_1.ErrorType.VALUE_ABOVE_EXCLUSIVE : ErrorType_1.ErrorType.VALUE_ABOVE, `Has to be a maximum value of ${this.options.max}${this.options.minExclusive ? " (exclusive)" : ""}.`);
26
26
  }
27
27
  return null;
28
28
  }
@@ -1 +1 @@
1
- {"version":3,"file":"NumberValidator.js","sourceRoot":"","sources":["../../../src/types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IAAI,CAAC,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,GAAG,CACxG,CAAC;QACN,CAAC;QAED,uBAAuB;QACvB,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,KAAK,SAAS,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,GAAG,KAAK,CAAC,EAAE,CAAC;YACvH,OAAO,IAAI,CAAC,WAAW,CACnB,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,qBAAS,CAAC,qBAAqB,CAAC,CAAC,CAAC,qBAAS,CAAC,WAAW,EACnF,gCAAgC,IAAI,CAAC,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,GAAG,CACxG,CAAC;QACN,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AA/BD,0CA+BC"}
@@ -20,21 +20,21 @@ class ArrayValidator extends Validator_1.Validator {
20
20
  }
21
21
  // Check minimum length
22
22
  if (this.options.min !== undefined && input.length < this.options.min) {
23
- return this.createError(ErrorType_1.ErrorType.VALUE_SHORT, `Has to have a minimum length of ${this.options.min}`);
23
+ return this.createError(ErrorType_1.ErrorType.VALUE_SHORT, `Has to have a minimum length of ${this.options.min}.`);
24
24
  }
25
25
  // Check maximum length
26
26
  if (this.options.max !== undefined && input.length > this.options.max) {
27
- return this.createError(ErrorType_1.ErrorType.VALUE_SHORT, `Has to have a maximum length of ${this.options.max}`);
27
+ return this.createError(ErrorType_1.ErrorType.VALUE_SHORT, `Has to have a maximum length of ${this.options.max}.`);
28
28
  }
29
29
  // Check item type
30
30
  let hasError = false;
31
- const fields = input.map((item) => {
31
+ const fields = Object.fromEntries(input.map((item, index) => {
32
32
  const result = this.item.validateReturn(item);
33
33
  if (result !== null) {
34
34
  hasError = true;
35
35
  }
36
- return result;
37
- });
36
+ return [index, result];
37
+ }).filter((entry) => !!entry[1]));
38
38
  if (hasError) {
39
39
  return this.createError(ErrorType_1.ErrorType.INCORRECT_TYPE, "One or more items are incorrect.", fields);
40
40
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ArrayValidator.js","sourceRoot":"","sources":["../../../src/types/object/ArrayValidator.ts"],"names":[],"mappings":";;;AAAA,sDAAmD;AAEnD,+CAA4C;AAS5C,MAAa,cAAkB,SAAQ,qBAAc;IAI7B;IACE;IAJN,IAAI,GAAG,OAAO,CAAC;IAE/B,YACoB,IAAkB,EAChB,UAAiC,EAAE;QAErD,KAAK,EAAE,CAAC;QAHQ,SAAI,GAAJ,IAAI,CAAc;QAChB,YAAO,GAAP,OAAO,CAA4B;IAGzD,CAAC;IAED,kBAAkB;IACF,cAAc,CAAC,KAAc;QACzC,aAAa;QACb,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACvE,OAAO,IAAI,CAAC,WAAW,CAAC,qBAAS,CAAC,cAAc,EAAE,qBAAqB,CAAC,CAAC;QAC7E,CAAC;QAED,uBAAuB;QACvB,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,KAAK,SAAS,IAAI,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;YACpE,OAAO,IAAI,CAAC,WAAW,CAAC,qBAAS,CAAC,WAAW,EAAE,mCAAmC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAA;QACzG,CAAC;QAED,uBAAuB;QACvB,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,KAAK,SAAS,IAAI,KAAK,CAAC,MAAM,GAAG,IAAI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AC;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AA1CD,wCA0CC"}
@@ -31,7 +31,7 @@ class ObjectValidator extends Validator_1.Validator {
31
31
  }));
32
32
  if (hasError || extraKeys.length) {
33
33
  if (extraKeys.length) {
34
- return this.createError(ErrorType_1.ErrorType.UNKNOWN_FIELD, `No extra keys allowed. Found [${extraKeys.join(", ")}]`, hasError ? fields : undefined);
34
+ return this.createError(ErrorType_1.ErrorType.UNKNOWN_FIELD, `No extra keys allowed. Found [${extraKeys.join(", ")}].`, hasError ? fields : undefined);
35
35
  }
36
36
  return this.createError(ErrorType_1.ErrorType.INCORRECT_TYPE, "One or more fields are incorrect.", fields);
37
37
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ObjectValidator.js","sourceRoot":"","sources":["../../../src/types/object/ObjectValidator.ts"],"names":[],"mappings":";;;AAAA,sDAAmD;AAEnD,+CAA4C;AAM5C,MAAa,eAAkC,SAAQ,qBAAY;IAG5B;IAFnB,IAAI,GAAG,QAAQ,CAAC;IAEhC,YAAmC,MAA0B;QACzD,KAAK,EAAE,CAAC;QADuB,WAAM,GAAN,MAAM,CAAoB;IAE7D,CAAC;IAED,kBAAkB;IACF,cAAc,CAAC,KAAc;QACzC,aAAa;QACb,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YAC9C,OAAO,IAAI,CAAC,WAAW,CAAC,qBAAS,CAAC,cAAc,EAAE,sBAAsB,CAAC,CAAC;QAC9E,CAAC;QAED,yBAAyB;QACzB,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC3C,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACrC,MAAM,SAAS,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CA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C,CAAC,CAAC,SAAS,CAChC,CAAC;YACN,CAAC;YACD,OAAO,IAAI,CAAC,WAAW,CAAC,qBAAS,CAAC,cAAc,EAAE,mCAAmC,EAAE,MAAM,CAAC,CAAC;QACnG,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;CAEJ;AA1CD,0CA0CC"}
@@ -19,7 +19,7 @@ class TupleValidator extends Validator_1.Validator {
19
19
  if (input.length !== this.validators.length) {
20
20
  return this.createError(input.length < this.validators.length
21
21
  ? ErrorType_1.ErrorType.VALUE_SHORT
22
- : ErrorType_1.ErrorType.VALUE_LONG, `Has to have length of ${this.validators.length}`);
22
+ : ErrorType_1.ErrorType.VALUE_LONG, `Has to have length of ${this.validators.length}.`);
23
23
  }
24
24
  // Check items
25
25
  let hasError = false;
@@ -1 +1 @@
1
- {"version":3,"file":"TupleValidator.js","sourceRoot":"","sources":["../../../src/types/object/TupleValidator.ts"],"names":[],"mappings":";;;AAAA,sDAAmD;AAEnD,+CAA4C;AAM5C,MAAa,cAAyC,SAAQ,qBAAY;IAGnC;IAFnB,IAAI,GAAG,OAAO,CAAC;IAE/B,YAAmC,UAA8B;QAC7D,KAAK,EAAE,CAAC;QADuB,eAAU,GAAV,UAAU,CAAoB;IAEjE,CAAC;IAEe,cAAc,CAAC,KAAc;QACzC,aAAa;QACb,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAC/D,OAAO,IAAI,CAAC,WAAW,CAAC,qBAAS,CAAC,cAAc,EAAE,oBAAoB,CAAC,CAAC;QAC5E,CAAC;QAED,eAAe;QACf,IAAI,KAAK,CAAC,MAAM,KAAK,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC;YAC1C,OAAO,IAAI,CAAC,WAAW,CACnB,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM;gBACjC,CAAC,CAAC,qBAAS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M,KAAK,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC;YAC1C,OAAO,IAAI,CAAC,WAAW,CACnB,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM;gBACjC,CAAC,CAAC,qBAAS,CAAC,WAAW;gBACvB,CAAC,CAAC,qBAAS,CAAC,UAAU,EAC1B,yBAAyB,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,CACrD,CAAC;QACN,CAAC;QAED,cAAc;QACd,IAAI,QAAQ,GAAG,KAAK,CAAC;QACrB,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE;YACpD,MAAM,MAAM,GAAG,SAAS,CAAC,cAAc,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;YACtD,IAAI,MAAM,EAAE,CAAC;gBACT,QAAQ,GAAG,IAAI,CAAC;YACpB,CAAC;YACD,OAAO,MAAM,CAAC;QAClB,CAAC,CAAmB,CAAC;QACrB,IAAI,QAAQ,EAAE,CAAC;YACX,OAAO,IAAI,CAAC,WAAW,CAAC,qBAAS,CAAC,cAAc,EAAE,kCAAkC,EAAE,MAAM,CAAC,CAAC;QAClG,CAAC;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AAtCD,wCAsCC"}
@@ -21,19 +21,19 @@ class stringValidator extends Validator_1.Validator {
21
21
  if (!this.options.enum.includes(input)) {
22
22
  return null;
23
23
  }
24
- return this.createError(ErrorType_1.ErrorType.NO_MATCH, `Has to match one of the known values [${this.options.enum.join(", ")}]`);
24
+ return this.createError(ErrorType_1.ErrorType.NO_MATCH, `Has to match one of the known values [${this.options.enum.join(", ")}].`);
25
25
  }
26
26
  // Minimum length check.
27
27
  if (this.options.min !== undefined && input.length < this.options.min) {
28
- return this.createError(ErrorType_1.ErrorType.VALUE_SHORT, `Has to have a minimum length of ${this.options.min}`);
28
+ return this.createError(ErrorType_1.ErrorType.VALUE_SHORT, `Has to have a minimum length of ${this.options.min}.`);
29
29
  }
30
30
  // Maximum length check.
31
31
  if (this.options.max !== undefined && this.options.max < input.length) {
32
- return this.createError(ErrorType_1.ErrorType.VALUE_LONG, `Has to have a maximum length of ${this.options.max}`);
32
+ return this.createError(ErrorType_1.ErrorType.VALUE_LONG, `Has to have a maximum length of ${this.options.max}.`);
33
33
  }
34
34
  // Regex format check.
35
35
  if (this.options.regex && !this.options.regex.test(input)) {
36
- return this.createError(ErrorType_1.ErrorType.INCORRECT_FORMAT, `Has to match format '${this.options.regex.source}'`);
36
+ return this.createError(ErrorType_1.ErrorType.INCORRECT_FORMAT, `Has to match format '${this.options.regex.source}'.`);
37
37
  }
38
38
  return null;
39
39
  }
@@ -1 +1 @@
1
- {"version":3,"file":"StringValidator.js","sourceRoot":"","sources":["../../../src/types/string/StringValidator.ts"],"names":[],"mappings":";;;AAAA,sDAAmD;AAEnD,+CAA4C;AAa5C,MAAa,eAA2C,SAAQ,qBAAY;IAGpC;IAFpB,IAAI,GAAG,QAAQ,CAAC;IAEhC,YAAoC,UAAmC,EAAE;QACrE,KAAK,EAAE,CAAC;QADwB,YAAO,GAAP,OAAO,CAA8B;IAEzE,CAAC;IAED,kBAAkB;IACF,cAAc,CAAC,KAAc;QACzC,cAAc;QACd,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC5B,OAAO,IAAI,CAAC,WAAW,CAAC,qBAAS,CAAC,cAAc,EAAE,qBAAqB,CAAC,CAAC;QAC7E,CAAC;QAED,cAAc;QACd,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YACpB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;gBACrC,OAAO,IAAI,CAAC;YAChB,CAAC;YACD,OAAO,IAAI,CAAC,WAAW,CACnB,qBAAS,CAAC,QAAQ,EAClB,yCAAyC,IAAI,CAAC,OAAO,CAAC,IA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AO,IAAI,CAAC,WAAW,CAAC,qBAAS,CAAC,gBAAgB,EAAE,wBAAwB,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,IAAI,CAAC,CAAC;QAC/G,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AAzCD,0CAyCC"}
@@ -0,0 +1,24 @@
1
+ import { ValidationError } from "../../errors/ValidationError";
2
+ import { Validator } from "../../Validator";
3
+ export type ConstructorType<T> = {
4
+ new (...args: unknown[]): T;
5
+ name: string;
6
+ };
7
+ export interface InstanceofValidationOptions<T> {
8
+ /**
9
+ *
10
+ * @param value Value to be checked.
11
+ * @returns
12
+ * - `true`: When the value is correct.
13
+ * - `string`: Message when the value is incorrect.
14
+ */
15
+ check?: (value: T) => true | string;
16
+ }
17
+ export declare class InstanceofValidator<T> extends Validator<T> {
18
+ readonly instance: ConstructorType<T>;
19
+ private readonly options;
20
+ type: string;
21
+ constructor(instance: ConstructorType<T>, options?: InstanceofValidationOptions<T>);
22
+ /** @inheritdoc */
23
+ validateReturn(input: unknown): ValidationError<T> | null;
24
+ }
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InstanceofValidator = void 0;
4
+ const ErrorType_1 = require("../../errors/ErrorType");
5
+ const ValidationError_1 = require("../../errors/ValidationError");
6
+ const Validator_1 = require("../../Validator");
7
+ class InstanceofValidator extends Validator_1.Validator {
8
+ instance;
9
+ options;
10
+ type = "instanceof";
11
+ constructor(instance, options = {}) {
12
+ super();
13
+ this.instance = instance;
14
+ this.options = options;
15
+ }
16
+ /** @inheritdoc */
17
+ validateReturn(input) {
18
+ // Type check.
19
+ if (!(input instanceof this.instance)) {
20
+ return this.createError(ErrorType_1.ErrorType.INCORRECT_TYPE, `Has to be instance of ${this.instance.name}.`);
21
+ }
22
+ // Check with custom test.
23
+ if (this.options.check) {
24
+ try {
25
+ const result = this.options.check(input);
26
+ if (result !== true) {
27
+ return this.createError(ErrorType_1.ErrorType.INCORRECT_FORMAT, result);
28
+ }
29
+ }
30
+ catch (e) {
31
+ if (e instanceof ValidationError_1.ValidationError) {
32
+ return e;
33
+ }
34
+ else if (e instanceof Error) {
35
+ return this.createError(ErrorType_1.ErrorType.INCORRECT_FORMAT, e.message);
36
+ }
37
+ return this, this.createError(ErrorType_1.ErrorType.INCORRECT_FORMAT, "Unknown.");
38
+ }
39
+ }
40
+ return null;
41
+ }
42
+ }
43
+ exports.InstanceofValidator = InstanceofValidator;
44
+ //# sourceMappingURL=InstanceofValidator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InstanceofValidator.js","sourceRoot":"","sources":["../../../src/types/util/InstanceofValidator.ts"],"names":[],"mappings":";;;AAAA,sDAAmD;AACnD,kEAA+D;AAC/D,+CAA4C;AAkB5C,MAAa,mBAAuB,SAAQ,qBAAY;IAIhC;IACC;IAJL,IAAI,GAAG,YAAY,CAAC;IAEpC,YACoB,QAA4B,EAC3B,UAA0C,EAAE;QAE7D,KAAK,EAAE,CAAC;QAHQ,aAAQ,GAAR,QAAQ,CAAoB;QAC3B,YAAO,GAAP,OAAO,CAAqC;IAGjE,CAAC;IAED,kBAAkB;IACF,cAAc,CAAC,KAAc;QACzC,cAAc;QACd,IAAI,CAAC,CAAC,KAAK,YAAY,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;YACpC,OAAO,IAAI,CAAC,WAAW,CAAC,qBAAS,CAAC,cAAc,EAAE,yBAAyB,IAAI,CAAC,QAAQ,CAAC,IAAI,GAAG,CAAC,CAAC;QACtG,CAAC;QAED,0BAA0B;QAC1B,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;YACrB,IAAI,CAAC;gBACD,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;gBACzC,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;oBAClB,OAAO,IAAI,CAAC,WAAW,CAAC,qBAAS,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC;gBAChE,CAAC;YACL,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACT,IAAI,CAAC,YAAY,iCAAe,EAAE,CAAC;oBAC/B,OAAO,CAAC,CAAC;gBACb,CAAC;qBAAM,IAAI,CAAC,YAAY,KAAK,EAAE,CAAC;oBAC5B,OAAO,IAAI,CAAC,WAAW,CAAC,qBAAS,CAAC,gBAAgB,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;gBACnE,CAAC;gBACD,OAAO,IAAI,EAAC,IAAI,CAAC,WAAW,CAAC,qBAAS,CAAC,gBAAgB,EAAE,UAAU,CAAC,CAAC;YACzE,CAAC;QACL,CAAC;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AApCD,kDAoCC"}
@@ -1,9 +1,13 @@
1
1
  import type { ValidationError } from "../../errors/ValidationError";
2
2
  import { Validator } from "../../Validator";
3
+ export interface OptionalValidatorOptions {
4
+ only?: "undefined" | "null";
5
+ }
3
6
  export declare class OptionalValidator<T> extends Validator<T> {
4
7
  readonly child: Validator<Exclude<T, undefined | null>>;
8
+ private readonly options;
5
9
  type: string;
6
- constructor(child: Validator<Exclude<T, undefined | null>>);
10
+ constructor(child: Validator<Exclude<T, undefined | null>>, options?: OptionalValidatorOptions);
7
11
  /** @inheritdoc */
8
12
  validateReturn(input: unknown): ValidationError<T> | null;
9
13
  }
@@ -1,18 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OptionalValidator = void 0;
4
+ const ErrorType_1 = require("../../errors/ErrorType");
4
5
  const Validator_1 = require("../../Validator");
5
6
  class OptionalValidator extends Validator_1.Validator {
6
7
  child;
8
+ options;
7
9
  type = "optional";
8
- constructor(child) {
10
+ constructor(child, options = {}) {
9
11
  super();
10
12
  this.child = child;
13
+ this.options = options;
11
14
  }
12
15
  /** @inheritdoc */
13
16
  validateReturn(input) {
14
17
  if (input === undefined || input === null) {
15
- return null;
18
+ if (!this.options.only || input === (this.options.only === "null" ? null : undefined)) {
19
+ return null;
20
+ }
21
+ return this.createError(ErrorType_1.ErrorType.INCORRECT_FORMAT, `Optional value has to be ${this.options.only}`);
16
22
  }
17
23
  return this.child.validateReturn(input);
18
24
  }
@@ -1 +1 @@
1
- {"version":3,"file":"OptionalValidator.js","sourceRoot":"","sources":["../../../src/types/util/OptionalValidator.ts"],"names":[],"mappings":";;;AACA,+CAA4C;AAE5C,MAAa,iBAAqB,SAAQ,qBAAY;IAGf;IAFnB,IAAI,GAAG,UAAU,CAAC;IAElC,YAAmC,KAA8C;QAC7E,KAAK,EAAE,CAAA;QADwB,UAAK,GAAL,KAAK,CAAyC;IAEjF,CAAC;IAED,kBAAkB;IACF,cAAc,CAAC,KAAc;QACzC,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YACxC,OAAO,IAAI,CAAC;QAChB,CAAC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC5C,CAAC;CAEJ;AAfD,8CAeC"}
1
+ {"version":3,"file":"OptionalValidator.js","sourceRoot":"","sources":["../../../src/types/util/OptionalValidator.ts"],"names":[],"mappings":";;;AAAA,sDAAmD;AAEnD,+CAA4C;AAM5C,MAAa,iBAAqB,SAAQ,qBAAY;IAI9B;IACC;IAJL,IAAI,GAAG,UAAU,CAAC;IAElC,YACoB,KAA8C,EAC7C,UAAoC,EAAE;QAEvD,KAAK,EAAE,CAAA;QAHS,UAAK,GAAL,KAAK,CAAyC;QAC7C,YAAO,GAAP,OAAO,CAA+B;IAG3D,CAAC;IAED,kBAAkB;IACF,cAAc,CAAC,KAAc;QACzC,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YACxC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,KAAK,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,KA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