valgen 5.19.4 → 5.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/constants.js CHANGED
@@ -1,4 +1,4 @@
1
- export const version = '5.19.4';
1
+ export const version = '5.20.0';
2
2
  export const postValidation = Symbol('postValidation');
3
3
  export const preValidation = Symbol('preValidation');
4
4
  export const VALIDATE_METADATA = Symbol('VALIDATE_METADATA');
package/index.d.ts CHANGED
@@ -56,6 +56,9 @@ declare const isUUID2: import("./core/validator.js").Validator<string, string, E
56
56
  declare const isUUID3: import("./core/validator.js").Validator<string, string, ExecutionOptions>;
57
57
  declare const isUUID4: import("./core/validator.js").Validator<string, string, ExecutionOptions>;
58
58
  declare const isUUID5: import("./core/validator.js").Validator<string, string, ExecutionOptions>;
59
+ declare const isUUID6: import("./core/validator.js").Validator<string, string, ExecutionOptions>;
60
+ declare const isUUID7: import("./core/validator.js").Validator<string, string, ExecutionOptions>;
61
+ declare const isUUID8: import("./core/validator.js").Validator<string, string, ExecutionOptions>;
59
62
  declare const toArray: import("./core/validator.js").Validator<any[], any, ExecutionOptions>;
60
63
  declare const toBigint: import("./core/validator.js").Validator<bigint, unknown, ExecutionOptions>;
61
64
  declare const toBoolean: import("./core/validator.js").Validator<boolean | undefined, unknown, ExecutionOptions>;
@@ -67,4 +70,4 @@ declare const toInteger: import("./core/validator.js").Validator<number, unknown
67
70
  declare const toNumber: import("./core/validator.js").Validator<number, unknown, ExecutionOptions>;
68
71
  declare const toString: import("./core/validator.js").Validator<string, unknown, ExecutionOptions>;
69
72
  declare const toTime: import("./core/validator.js").Validator<string, string | Date, ExecutionOptions>;
70
- export { isAlpha, isAlphanumeric, isAny, isArray, isAscii, isBase64, isBigint, isBoolean, isBtcAddress, isCreditCard, isDate, isDateString, isDecimal, isDefined, isEAN, isEmail, isEmpty, isETHAddress, isFQDN, isHex, isHexColor, isIBAN, isInteger, isIP, isIPRange, isISSN, isJWT, isLowercase, isMACAddress, isMobilePhone, isNotEmpty, isNotNull, isNotNullish, isNull, isNullish, isNumber, isObject, isObjectId, isPort, isString, isSWIFT, isTime, isUndefined, isUppercase, isURL, isUUID, isUUID1, isUUID2, isUUID3, isUUID4, isUUID5, toArray, toBigint, toBoolean, toDate, toDateString, toInteger, toNumber, toString, toTime, vg, };
73
+ export { isAlpha, isAlphanumeric, isAny, isArray, isAscii, isBase64, isBigint, isBoolean, isBtcAddress, isCreditCard, isDate, isDateString, isDecimal, isDefined, isEAN, isEmail, isEmpty, isETHAddress, isFQDN, isHex, isHexColor, isIBAN, isInteger, isIP, isIPRange, isISSN, isJWT, isLowercase, isMACAddress, isMobilePhone, isNotEmpty, isNotNull, isNotNullish, isNull, isNullish, isNumber, isObject, isObjectId, isPort, isString, isSWIFT, isTime, isUndefined, isUppercase, isURL, isUUID, isUUID1, isUUID2, isUUID3, isUUID4, isUUID5, isUUID6, isUUID7, isUUID8, toArray, toBigint, toBoolean, toDate, toDateString, toInteger, toNumber, toString, toTime, vg, };
package/index.js CHANGED
@@ -52,6 +52,9 @@ const isUUID2 = vg.isUUID(2);
52
52
  const isUUID3 = vg.isUUID(3);
53
53
  const isUUID4 = vg.isUUID(4);
54
54
  const isUUID5 = vg.isUUID(5);
55
+ const isUUID6 = vg.isUUID(6);
56
+ const isUUID7 = vg.isUUID(7);
57
+ const isUUID8 = vg.isUUID(8);
55
58
  const toArray = vg.isArray(isAny, { coerce: true });
56
59
  const toBigint = vg.isBigint({ coerce: true });
57
60
  const toBoolean = vg.isBoolean({ coerce: true });
@@ -74,4 +77,4 @@ const toInteger = vg.isInteger({ coerce: true });
74
77
  const toNumber = vg.isNumber({ coerce: true });
75
78
  const toString = vg.isString({ coerce: true });
76
79
  const toTime = vg.isTime({ coerce: true });
77
- export { isAlpha, isAlphanumeric, isAny, isArray, isAscii, isBase64, isBigint, isBoolean, isBtcAddress, isCreditCard, isDate, isDateString, isDecimal, isDefined, isEAN, isEmail, isEmpty, isETHAddress, isFQDN, isHex, isHexColor, isIBAN, isInteger, isIP, isIPRange, isISSN, isJWT, isLowercase, isMACAddress, isMobilePhone, isNotEmpty, isNotNull, isNotNullish, isNull, isNullish, isNumber, isObject, isObjectId, isPort, isString, isSWIFT, isTime, isUndefined, isUppercase, isURL, isUUID, isUUID1, isUUID2, isUUID3, isUUID4, isUUID5, toArray, toBigint, toBoolean, toDate, toDateString, toInteger, toNumber, toString, toTime, vg, };
80
+ export { isAlpha, isAlphanumeric, isAny, isArray, isAscii, isBase64, isBigint, isBoolean, isBtcAddress, isCreditCard, isDate, isDateString, isDecimal, isDefined, isEAN, isEmail, isEmpty, isETHAddress, isFQDN, isHex, isHexColor, isIBAN, isInteger, isIP, isIPRange, isISSN, isJWT, isLowercase, isMACAddress, isMobilePhone, isNotEmpty, isNotNull, isNotNullish, isNull, isNullish, isNumber, isObject, isObjectId, isPort, isString, isSWIFT, isTime, isUndefined, isUppercase, isURL, isUUID, isUUID1, isUUID2, isUUID3, isUUID4, isUUID5, isUUID6, isUUID7, isUUID8, toArray, toBigint, toBoolean, toDate, toDateString, toInteger, toNumber, toString, toTime, vg, };
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "valgen",
3
3
  "description": "Fast runtime type validator, converter and io (encoding/decoding) library",
4
- "version": "5.19.4",
4
+ "version": "5.20.0",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
7
7
  "dependencies": {
8
- "@browsery/validator": "^13.15.15",
8
+ "@browsery/validator": "^13.15.35",
9
9
  "date-fns": "^4.1.0",
10
10
  "reflect-metadata": "^0.2.2",
11
- "ts-gems": "^3.11.3",
11
+ "ts-gems": "^3.11.6",
12
12
  "tslib": "^2.8.1"
13
13
  },
14
14
  "type": "module",
@@ -1,6 +1,6 @@
1
- import validatorJS from '@browsery/validator';
1
+ import { type IsBase64Options as _IsBase64Options } from '@browsery/validator';
2
2
  import { type ValidationOptions } from '../../core/index.js';
3
- export interface Base64ValidatorOptions extends ValidationOptions, validatorJS.IsBase64Options {
3
+ export interface Base64ValidatorOptions extends ValidationOptions, _IsBase64Options {
4
4
  }
5
5
  /**
6
6
  * Validates if value is a "Base64" string.
@@ -1,6 +1,6 @@
1
- import validatorJS from '@browsery/validator';
1
+ import { type IsCreditCardOptions as _IsCreditCardOptions } from '@browsery/validator';
2
2
  import { type ValidationOptions } from '../../core/index.js';
3
- export interface CreditCardValidatorOptions extends ValidationOptions, validatorJS.IsCreditCardOptions {
3
+ export interface CreditCardValidatorOptions extends ValidationOptions, _IsCreditCardOptions {
4
4
  }
5
5
  /**
6
6
  * Validates if value is a credit card number
@@ -1,6 +1,6 @@
1
- import validatorJS from '@browsery/validator';
1
+ import { type HashAlgorithm as _HashAlgorithm } from '@browsery/validator';
2
2
  import { type ValidationOptions } from '../../core/index.js';
3
- export type HashAlgorithm = validatorJS.HashAlgorithm;
3
+ export type HashAlgorithm = _HashAlgorithm;
4
4
  /**
5
5
  * Validates if value a hash of type algorithm
6
6
  * @validator isHash
@@ -1,4 +1,4 @@
1
- import validatorJS from '@browsery/validator';
1
+ import { type MobilePhoneLocale as _MobilePhoneLocale } from '@browsery/validator';
2
2
  import { type ValidationOptions } from '../../core/index.js';
3
3
  export interface IsMobilePhoneOptions extends ValidationOptions {
4
4
  /**
@@ -11,7 +11,7 @@ export interface IsMobilePhoneOptions extends ValidationOptions {
11
11
  * Locale or locales of the mobile phone
12
12
  * @default 'any'
13
13
  */
14
- locale?: 'any' | validatorJS.MobilePhoneLocale | validatorJS.MobilePhoneLocale[];
14
+ locale?: 'any' | _MobilePhoneLocale | _MobilePhoneLocale[];
15
15
  }
16
16
  /**
17
17
  * Validates if value is a valid Email
@@ -1,6 +1,6 @@
1
- import validatorJS from '@browsery/validator';
1
+ import { type IsURLOptions as _IsURLOptions } from '@browsery/validator';
2
2
  import { type ValidationOptions } from '../../core/index.js';
3
- export interface IsURLOptions extends ValidationOptions, validatorJS.IsURLOptions {
3
+ export interface IsURLOptions extends ValidationOptions, _IsURLOptions {
4
4
  }
5
5
  /**
6
6
  * Validates if value is an URL
@@ -1,6 +1,8 @@
1
+ import { type UUIDVersion as _UUIDVersion } from '@browsery/validator';
1
2
  import { type ValidationOptions } from '../../core/index.js';
3
+ export type UUIDVersion = _UUIDVersion;
2
4
  /**
3
- * Validates if value is an "UUID".
5
+ * Validates if value is a "UUID".
4
6
  * @validator isUUID
5
7
  */
6
- export declare function isUUID(version?: 1 | 2 | 3 | 4 | 5, options?: ValidationOptions): import("../../core/validator.js").Validator<string, string, import("../../core/types.js").ExecutionOptions>;
8
+ export declare function isUUID(version?: UUIDVersion, options?: ValidationOptions): import("../../core/validator.js").Validator<string, string, import("../../core/types.js").ExecutionOptions>;
@@ -1,7 +1,7 @@
1
1
  import validatorJS from '@browsery/validator';
2
2
  import { validator, } from '../../core/index.js';
3
3
  /**
4
- * Validates if value is an "UUID".
4
+ * Validates if value is a "UUID".
5
5
  * @validator isUUID
6
6
  */
7
7
  export function isUUID(version, options) {
@@ -1,6 +1,8 @@
1
+ import { type VATCountryCode as _VATCountryCode } from '@browsery/validator';
1
2
  import { type ValidationOptions } from '../../core/index.js';
3
+ export type VATCountryCode = _VATCountryCode;
2
4
  /**
3
- * Validates if value is an VAT number
5
+ * Validates if value is a VAT number
4
6
  * @validator isVAT
5
7
  */
6
- export declare function isVATNumber(countryCode: string, options?: ValidationOptions): import("../../core/validator.js").Validator<string, string, import("../../core/types.js").ExecutionOptions>;
8
+ export declare function isVATNumber(countryCode: VATCountryCode, options?: ValidationOptions): import("../../core/validator.js").Validator<string, string, import("../../core/types.js").ExecutionOptions>;
@@ -1,7 +1,7 @@
1
1
  import validatorJS from '@browsery/validator';
2
2
  import { validator, } from '../../core/index.js';
3
3
  /**
4
- * Validates if value is an VAT number
4
+ * Validates if value is a VAT number
5
5
  * @validator isVAT
6
6
  */
7
7
  export function isVATNumber(countryCode, options) {
@@ -50,7 +50,7 @@ export function isDateString(options) {
50
50
  if (parsed.precision < precisionMinIdx) {
51
51
  context.fail(_this, `Minimum date precision should be ${precisionMin}`, input, options);
52
52
  }
53
- if (parsed.precision > precisionMaxIdx) {
53
+ if (parsed.precision > precisionMaxIdx && !(input instanceof Date)) {
54
54
  context.fail(_this, `Maximum date precision should be ${precisionMax}`, input, options);
55
55
  }
56
56
  return coerce ? parsed.value : input;
@@ -64,7 +64,7 @@ const DATE_PATTERN2 = /^(\d{4,14})(?:\.(\d{1,6}))?(?:(?:([+-])(0[0-9]|1[0-2])(\d
64
64
  function coerceDateString(input, trimPrecision) {
65
65
  const precisionIndex = (trimPrecision ? PRECISION_INDEX[trimPrecision] : 9) || 9;
66
66
  let dateParts;
67
- let detectedPrecision = 0;
67
+ let detectedPrecision;
68
68
  if (input instanceof Date || typeof input === 'number') {
69
69
  const d = typeof input === 'number' ? new Date(input) : input;
70
70
  dateParts = [
@@ -75,8 +75,11 @@ function coerceDateString(input, trimPrecision) {
75
75
  String(d.getMinutes()).padStart(2, '0'),
76
76
  String(d.getSeconds()).padStart(2, '0'),
77
77
  ];
78
- if (precisionIndex >= 7 && d.getMilliseconds() > 0)
79
- dateParts.push(String(d.getMilliseconds()).padStart(3, '0'));
78
+ if (precisionIndex >= 7)
79
+ if (d.getMilliseconds() > 0)
80
+ dateParts.push(String(d.getMilliseconds()).padStart(3, '0'));
81
+ else
82
+ dateParts.push('');
80
83
  if (precisionIndex >= 8) {
81
84
  const tzOffset = d.getTimezoneOffset();
82
85
  const tz = tzOffset > 0
@@ -13,7 +13,6 @@ export function isEnum(values, options) {
13
13
  if (values[k] != null)
14
14
  a.push(values[k]);
15
15
  return a;
16
- // v => !(typeof v === 'number' && !keys.includes(String(v))),
17
16
  }, []);
18
17
  }
19
18
  const valObj = (Array.isArray(values) ? values : [values]).reduce((a, v) => {
@@ -47,7 +47,7 @@ export function isObject(schema, options) {
47
47
  }
48
48
  const keys = Array.from(new Set([...Object.keys(output), ...schemaKeys]));
49
49
  const l = keys.length;
50
- let i = 0;
50
+ let i;
51
51
  let inputKey;
52
52
  let schemaKey;
53
53
  let v;