valgen 6.1.0 → 6.2.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.
Files changed (76) hide show
  1. package/constants.js +1 -1
  2. package/index.d.ts +1 -0
  3. package/index.js +1 -0
  4. package/package.json +3 -3
  5. package/rules/format-rules/is-alpha.js +1 -1
  6. package/rules/format-rules/is-alphanumeric.js +1 -1
  7. package/rules/format-rules/is-ascii.js +1 -1
  8. package/rules/format-rules/is-base64.js +1 -1
  9. package/rules/format-rules/is-btc-address.js +1 -1
  10. package/rules/format-rules/is-credit-card.js +1 -1
  11. package/rules/format-rules/is-decimal.js +1 -1
  12. package/rules/format-rules/is-ean.js +1 -1
  13. package/rules/format-rules/is-email.js +1 -1
  14. package/rules/format-rules/is-eth-address.js +1 -1
  15. package/rules/format-rules/is-fqdn.js +1 -1
  16. package/rules/format-rules/is-hash.js +1 -1
  17. package/rules/format-rules/is-hex-color.js +1 -1
  18. package/rules/format-rules/is-hex.js +1 -1
  19. package/rules/format-rules/is-iban.js +1 -1
  20. package/rules/format-rules/is-ip.js +2 -2
  21. package/rules/format-rules/is-issn.js +1 -1
  22. package/rules/format-rules/is-jwt.js +1 -1
  23. package/rules/format-rules/is-lowercase.js +1 -1
  24. package/rules/format-rules/is-mac-address.js +1 -1
  25. package/rules/format-rules/is-mobile-phone.js +1 -1
  26. package/rules/format-rules/is-object-id.js +1 -1
  27. package/rules/format-rules/is-passport-number.js +1 -1
  28. package/rules/format-rules/is-port.js +1 -1
  29. package/rules/format-rules/is-swift.js +1 -1
  30. package/rules/format-rules/is-time.js +1 -1
  31. package/rules/format-rules/is-uppercase.js +1 -1
  32. package/rules/format-rules/is-url.js +1 -1
  33. package/rules/format-rules/is-uuid.js +1 -1
  34. package/rules/format-rules/is-vat-number.js +1 -1
  35. package/rules/format-rules/matches.js +1 -1
  36. package/rules/index.d.ts +2 -0
  37. package/rules/index.js +2 -0
  38. package/rules/logical-rules/is-defined.js +1 -1
  39. package/rules/logical-rules/is-empty.js +1 -1
  40. package/rules/logical-rules/is-equal.js +2 -2
  41. package/rules/logical-rules/is-gt.js +1 -1
  42. package/rules/logical-rules/is-gte.d.ts +1 -1
  43. package/rules/logical-rules/is-gte.js +1 -1
  44. package/rules/logical-rules/is-lt.js +1 -1
  45. package/rules/logical-rules/is-lte.js +1 -1
  46. package/rules/logical-rules/range.js +1 -1
  47. package/rules/type-rules/is-any.js +1 -1
  48. package/rules/type-rules/is-array.js +1 -1
  49. package/rules/type-rules/is-bigint.js +1 -1
  50. package/rules/type-rules/is-boolean.js +1 -1
  51. package/rules/type-rules/is-date.d.ts +1 -1
  52. package/rules/type-rules/is-date.js +14 -9
  53. package/rules/type-rules/is-enum.js +1 -1
  54. package/rules/type-rules/is-instanceof.js +1 -1
  55. package/rules/type-rules/is-integer.js +1 -1
  56. package/rules/type-rules/is-null.js +4 -4
  57. package/rules/type-rules/is-number.js +1 -1
  58. package/rules/type-rules/is-object.js +1 -1
  59. package/rules/type-rules/is-record.js +1 -1
  60. package/rules/type-rules/is-string.js +1 -1
  61. package/rules/type-rules/is-tuple.js +1 -1
  62. package/rules/type-rules/is-undefined.js +1 -1
  63. package/rules/utility-rules/all-of.js +1 -1
  64. package/rules/utility-rules/exists.js +1 -1
  65. package/rules/utility-rules/fixed.d.ts +5 -0
  66. package/rules/utility-rules/fixed.js +10 -0
  67. package/rules/utility-rules/get-length.js +1 -1
  68. package/rules/utility-rules/nullable.d.ts +11 -0
  69. package/rules/utility-rules/nullable.js +12 -0
  70. package/rules/utility-rules/one-of.js +1 -1
  71. package/rules/utility-rules/optional.d.ts +2 -2
  72. package/rules/utility-rules/optional.js +2 -2
  73. package/rules/utility-rules/pipe.js +1 -1
  74. package/rules/utility-rules/required.js +1 -1
  75. package/rules/utility-rules/string-utils.d.ts +2 -2
  76. package/rules/utility-rules/string-utils.js +17 -15
package/constants.js CHANGED
@@ -1,4 +1,4 @@
1
- export const version = '6.1.0';
1
+ export const version = '6.2.1';
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
@@ -3,6 +3,7 @@ import { Context, type ExecutionOptions, type Validator } from './core/index.js'
3
3
  import * as vg from './rules/index.js';
4
4
  export * from './constants.js';
5
5
  export * from './core/index.js';
6
+ export * from './core/types.js';
6
7
  declare const isAlpha: Validator<string, string, ExecutionOptions>;
7
8
  declare const isAlphanumeric: Validator<string, string, ExecutionOptions>;
8
9
  declare const isAny: Validator<any, any, ExecutionOptions>;
package/index.js CHANGED
@@ -2,6 +2,7 @@ import { Context, } from './core/index.js';
2
2
  import * as vg from './rules/index.js';
3
3
  export * from './constants.js';
4
4
  export * from './core/index.js';
5
+ export * from './core/types.js';
5
6
  const isInstanceOfCache = new WeakMap();
6
7
  const isAlpha = vg.isAlpha();
7
8
  const isAlphanumeric = vg.isAlphanumeric();
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "valgen",
3
3
  "description": "Fast runtime type validator, converter and io (encoding/decoding) library",
4
- "version": "6.1.0",
4
+ "version": "6.2.1",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
7
7
  "dependencies": {
8
8
  "@browsery/validator": "^13.15.35",
9
- "@jsopen/objects": "^2.2.1",
10
- "date-fns": "^4.1.0",
9
+ "@jsopen/objects": "^2.2.2",
10
+ "date-fns": "^4.2.1",
11
11
  "reflect-metadata": "^0.2.2",
12
12
  "ts-gems": "^3.12.0",
13
13
  "tslib": "^2.8.1"
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
5
5
  * @validator isAlpha
6
6
  */
7
7
  export function isAlpha(options) {
8
- return validator('isAlpha', (input, context, _this) => {
8
+ return validator(isAlpha.name, (input, context, _this) => {
9
9
  if (typeof input === 'string' && validatorJS.isAlpha(input))
10
10
  return input;
11
11
  context.fail(_this, `"Value must be an alpha string`, input);
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
5
5
  * @validator isAlphanumeric
6
6
  */
7
7
  export function isAlphanumeric(options) {
8
- return validator('isAlphanumeric', (input, context, _this) => {
8
+ return validator(isAlphanumeric.name, (input, context, _this) => {
9
9
  if (typeof input === 'string' && validatorJS.isAlphanumeric(input)) {
10
10
  return input;
11
11
  }
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
5
5
  * @validator isAscii
6
6
  */
7
7
  export function isAscii(options) {
8
- return validator('isAscii', (input, context, _this) => {
8
+ return validator(isAscii.name, (input, context, _this) => {
9
9
  if (typeof input === 'string' && validatorJS.isAscii(input))
10
10
  return input;
11
11
  context.fail(_this, `Value must be an ascii string`, input);
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
5
5
  * @validator isBase64
6
6
  */
7
7
  export function isBase64(options) {
8
- return validator('isBase64', (input, context, _this) => {
8
+ return validator(isBase64.name, (input, context, _this) => {
9
9
  if (typeof input === 'string' && validatorJS.isBase64(input, options)) {
10
10
  return input;
11
11
  }
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
5
5
  * @validator isBtcAddress
6
6
  */
7
7
  export function isBtcAddress(options) {
8
- return validator('isBtcAddress', (input, context, _this) => {
8
+ return validator(isBtcAddress.name, (input, context, _this) => {
9
9
  if (typeof input === 'string' && validatorJS.isBtcAddress(input)) {
10
10
  return input;
11
11
  }
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
5
5
  * @validator isCreditCard
6
6
  */
7
7
  export function isCreditCard(options) {
8
- return validator('isCreditCard', (input, context, _this) => {
8
+ return validator(isCreditCard.name, (input, context, _this) => {
9
9
  if (typeof input === 'string' &&
10
10
  validatorJS.isCreditCard(input, options)) {
11
11
  return input;
@@ -6,7 +6,7 @@ import { validator, } from '../../core/index.js';
6
6
  * @validator isDecimal
7
7
  */
8
8
  export function isDecimal(options) {
9
- return validator('isDecimal', (input, context, _this) => {
9
+ return validator(isDecimal.name, (input, context, _this) => {
10
10
  if (typeof input === 'string' && validatorJS.isDecimal(input)) {
11
11
  return input;
12
12
  }
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
5
5
  * @validator isEAN
6
6
  */
7
7
  export function isEAN(options) {
8
- return validator('isEAN', (input, context, _this) => {
8
+ return validator(isEAN.name, (input, context, _this) => {
9
9
  if (typeof input === 'string' && validatorJS.isEAN(input))
10
10
  return input;
11
11
  context.fail(_this, `Value must be a valid EAN (European Article Number)`, input);
@@ -11,7 +11,7 @@ export function isEmail(options) {
11
11
  ignore_max_length: true,
12
12
  allow_ip_domain: options?.allowIpDomain,
13
13
  };
14
- return validator('isEmail', (input, context, _this) => {
14
+ return validator(isEmail.name, (input, context, _this) => {
15
15
  if (typeof input === 'string' &&
16
16
  validatorJS.isEmail(input, emailOptions)) {
17
17
  if (options?.requireDisplayName) {
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
5
5
  * @validator isETHAddress
6
6
  */
7
7
  export function isETHAddress(options) {
8
- return validator('isETHAddress', (input, context, _this) => {
8
+ return validator(isETHAddress.name, (input, context, _this) => {
9
9
  if (typeof input === 'string' && validatorJS.isEthereumAddress(input)) {
10
10
  return input;
11
11
  }
@@ -8,7 +8,7 @@ export function isFQDN(options) {
8
8
  const opts = {
9
9
  allow_wildcard: options?.allowWildcard,
10
10
  };
11
- return validator('isFQDN', (input, context, _this) => {
11
+ return validator(isFQDN.name, (input, context, _this) => {
12
12
  if (typeof input === 'string' && validatorJS.isFQDN(input, opts)) {
13
13
  return input;
14
14
  }
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
5
5
  * @validator isHash
6
6
  */
7
7
  export function isHash(algorithm, options) {
8
- return validator('isHash', (input, context, _this) => {
8
+ return validator(isHash.name, (input, context, _this) => {
9
9
  if (typeof input === 'string' && validatorJS.isHash(input, algorithm)) {
10
10
  return input;
11
11
  }
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
5
5
  * @validator isHexColor
6
6
  */
7
7
  export function isHexColor(options) {
8
- return validator('isHexColor', (input, context, _this) => {
8
+ return validator(isHexColor.name, (input, context, _this) => {
9
9
  if (typeof input === 'string' && validatorJS.isHexColor(input)) {
10
10
  return input;
11
11
  }
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
5
5
  * @validator isHex
6
6
  */
7
7
  export function isHex(options) {
8
- return validator('isHex', (input, context, _this) => {
8
+ return validator(isHex.name, (input, context, _this) => {
9
9
  if (typeof input === 'string' && validatorJS.isHexadecimal(input)) {
10
10
  return input;
11
11
  }
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
5
5
  * @validator isIBAN
6
6
  */
7
7
  export function isIBAN(options) {
8
- return validator('isIBAN', (input, context, _this) => {
8
+ return validator(isIBAN.name, (input, context, _this) => {
9
9
  if (typeof input === 'string' && validatorJS.isIBAN(input))
10
10
  return input;
11
11
  context.fail(_this, `Value must be a valid IBAN (International Bank Account Number)`, input);
@@ -6,7 +6,7 @@ import { validator, } from '../../core/index.js';
6
6
  * @validator isIP
7
7
  */
8
8
  export function isIP(version, options) {
9
- return validator('isIP', (input, context, _this) => {
9
+ return validator(isIP.name, (input, context, _this) => {
10
10
  if (input != null &&
11
11
  typeof input === 'string' &&
12
12
  validatorJS.isIP(input, version)) {
@@ -20,7 +20,7 @@ export function isIP(version, options) {
20
20
  * @validator isIPRange
21
21
  */
22
22
  export function isIPRange(version, options) {
23
- return validator('isIPRange', (input, context, _this) => {
23
+ return validator(isIPRange.name, (input, context, _this) => {
24
24
  if (input != null &&
25
25
  typeof input === 'string' &&
26
26
  validatorJS.isIPRange(input, version)) {
@@ -8,7 +8,7 @@ export function isISSN(options) {
8
8
  const opts = {
9
9
  case_sensitive: options?.caseSensitive,
10
10
  };
11
- return validator('isISSN', (input, context, _this) => {
11
+ return validator(isISSN.name, (input, context, _this) => {
12
12
  if (typeof input === 'string' && validatorJS.isISSN(input, opts)) {
13
13
  return input;
14
14
  }
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
5
5
  * @validator isJWT
6
6
  */
7
7
  export function isJWT(options) {
8
- return validator('isJWT', (input, context, _this) => {
8
+ return validator(isJWT.name, (input, context, _this) => {
9
9
  if (typeof input === 'string' && validatorJS.isJWT(input))
10
10
  return input;
11
11
  context.fail(_this, `Value must be valid JWT token`, input);
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
5
5
  * @validator isLowercase
6
6
  */
7
7
  export function isLowercase(options) {
8
- return validator('isLowercase', (input, context, _this) => {
8
+ return validator(isLowercase.name, (input, context, _this) => {
9
9
  if (typeof input === 'string' && validatorJS.isLowercase(input)) {
10
10
  return input;
11
11
  }
@@ -10,7 +10,7 @@ export function isMACAddress(options) {
10
10
  no_separators: options?.noSeparators,
11
11
  eui: options?.eui,
12
12
  };
13
- return validator('isMACAddress', (input, context, _this) => {
13
+ return validator(isMACAddress.name, (input, context, _this) => {
14
14
  if (input != null &&
15
15
  typeof input === 'string' &&
16
16
  validatorJS.isMACAddress(input, opts)) {
@@ -8,7 +8,7 @@ export function isMobilePhone(options) {
8
8
  const opts = {
9
9
  strictMode: options?.strictMode,
10
10
  };
11
- return validator('isMobilePhone', (input, context, _this) => {
11
+ return validator(isMobilePhone.name, (input, context, _this) => {
12
12
  if (typeof input === 'string' &&
13
13
  validatorJS.isMobilePhone(input, options?.locale, opts)) {
14
14
  return input;
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
5
5
  * @validator isObjectId
6
6
  */
7
7
  export function isObjectId(options) {
8
- return validator('isObjectId', (input, context, _this) => {
8
+ return validator(isObjectId.name, (input, context, _this) => {
9
9
  if (input != null &&
10
10
  (_isObjectIdValue(input) ||
11
11
  (typeof input === 'object' &&
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
5
5
  * @validator isPassportNumber
6
6
  */
7
7
  export function isPassportNumber(countryCode, options) {
8
- return validator('isPassportNumber', (input, context, _this) => {
8
+ return validator(isPassportNumber.name, (input, context, _this) => {
9
9
  if (typeof input === 'string' &&
10
10
  validatorJS.isPassportNumber(input, countryCode)) {
11
11
  return input;
@@ -6,7 +6,7 @@ import { validator, } from '../../core/index.js';
6
6
  * @validator isPort
7
7
  */
8
8
  export function isPort(options) {
9
- return validator('isPort', (input, context, _this) => {
9
+ return validator(isPort.name, (input, context, _this) => {
10
10
  if (typeof input === 'number')
11
11
  input = String(input);
12
12
  if (input != null &&
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
5
5
  * @validator isSWIFT
6
6
  */
7
7
  export function isSWIFT(options) {
8
- return validator('isSWIFT', (input, context, _this) => {
8
+ return validator(isSWIFT.name, (input, context, _this) => {
9
9
  if (typeof input === 'string' && validatorJS.isBIC(input))
10
10
  return input;
11
11
  context.fail(_this, `Value must be a valid a BIC (Bank Identification Code) or SWIFT code`, input);
@@ -5,7 +5,7 @@ const TIME_PATTERN = /^(\d{2}):?(\d{2})(?::?(\d{2})?(?:\.(\d{1,3}))?)?$/;
5
5
  * @validator isTime
6
6
  */
7
7
  export function isTime(options) {
8
- return validator('isTime', (input, context, _this) => {
8
+ return validator(isTime.name, (input, context, _this) => {
9
9
  if (input != null) {
10
10
  const coerce = options?.coerce ?? context.coerce;
11
11
  let str;
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
5
5
  * @validator isUppercase
6
6
  */
7
7
  export function isUppercase(options) {
8
- return validator('isUppercase', (input, context, _this) => {
8
+ return validator(isUppercase.name, (input, context, _this) => {
9
9
  if (typeof input === 'string' && validatorJS.isUppercase(input)) {
10
10
  return input;
11
11
  }
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
5
5
  * @validator isURL
6
6
  */
7
7
  export function isURL(options) {
8
- return validator('isURL', (input, context, _this) => {
8
+ return validator(isURL.name, (input, context, _this) => {
9
9
  if (input != null &&
10
10
  typeof input === 'string' &&
11
11
  validatorJS.isURL(input, options)) {
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
5
5
  * @validator isUUID
6
6
  */
7
7
  export function isUUID(version, options) {
8
- return validator('isUUID', (input, context, _this) => {
8
+ return validator(isUUID.name, (input, context, _this) => {
9
9
  if (input != null &&
10
10
  typeof input === 'string' &&
11
11
  validatorJS.isUUID(input, version)) {
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
5
5
  * @validator isVAT
6
6
  */
7
7
  export function isVATNumber(countryCode, options) {
8
- return validator('isVATNumber', (input, context, _this) => {
8
+ return validator(isVATNumber.name, (input, context, _this) => {
9
9
  if (typeof input === 'string' && validatorJS.isVAT(input, countryCode)) {
10
10
  return input;
11
11
  }
@@ -6,7 +6,7 @@ import { validator, } from '../../core/index.js';
6
6
  export function matches(format, options) {
7
7
  const regExp = format instanceof RegExp ? format : new RegExp(format);
8
8
  const formatName = options?.formatName;
9
- return validator('matches', (input, context, _this) => {
9
+ return validator(matches.name, (input, context, _this) => {
10
10
  if (input == null)
11
11
  return;
12
12
  if (typeof input === 'string' && regExp.test(input))
package/rules/index.d.ts CHANGED
@@ -55,7 +55,9 @@ export * from './type-rules/is-tuple.js';
55
55
  export * from './type-rules/is-undefined.js';
56
56
  export * from './utility-rules/all-of.js';
57
57
  export * from './utility-rules/exists.js';
58
+ export * from './utility-rules/fixed.js';
58
59
  export * from './utility-rules/get-length.js';
60
+ export * from './utility-rules/nullable.js';
59
61
  export * from './utility-rules/one-of.js';
60
62
  export * from './utility-rules/optional.js';
61
63
  export * from './utility-rules/pipe.js';
package/rules/index.js CHANGED
@@ -55,7 +55,9 @@ export * from './type-rules/is-tuple.js';
55
55
  export * from './type-rules/is-undefined.js';
56
56
  export * from './utility-rules/all-of.js';
57
57
  export * from './utility-rules/exists.js';
58
+ export * from './utility-rules/fixed.js';
58
59
  export * from './utility-rules/get-length.js';
60
+ export * from './utility-rules/nullable.js';
59
61
  export * from './utility-rules/one-of.js';
60
62
  export * from './utility-rules/optional.js';
61
63
  export * from './utility-rules/pipe.js';
@@ -4,7 +4,7 @@ import { validator, } from '../../core/index.js';
4
4
  * @validator isDefined
5
5
  */
6
6
  export function isDefined(options) {
7
- return validator('is-defined', (input, context, _this) => {
7
+ return validator(isDefined.name, (input, context, _this) => {
8
8
  if (input !== undefined)
9
9
  return input;
10
10
  context.fail(_this, `Value must be defined`, input);
@@ -4,7 +4,7 @@ import { validator, } from '../../core/index.js';
4
4
  * @validator isEmpty
5
5
  */
6
6
  export function isEmpty(options) {
7
- return validator('isEmpty', (input, context, _this) => {
7
+ return validator(isEmpty.name, (input, context, _this) => {
8
8
  if (input == null)
9
9
  return input;
10
10
  if (typeof input === 'string') {
@@ -4,7 +4,7 @@ import { validator, } from '../../core/index.js';
4
4
  * @validator isEqual
5
5
  */
6
6
  export function isEqual(compare, options) {
7
- return validator('isEqual', (input, context, _this) => {
7
+ return validator(isEqual.name, (input, context, _this) => {
8
8
  if (input == null)
9
9
  return input;
10
10
  if (input !== compare)
@@ -17,7 +17,7 @@ export function isEqual(compare, options) {
17
17
  * @validator isNotEqual
18
18
  */
19
19
  export function isNotEqual(compare, options) {
20
- return validator('isNotEqual', (input, context, _this) => {
20
+ return validator(isNotEqual.name, (input, context, _this) => {
21
21
  if (input == null)
22
22
  return input;
23
23
  if (input === compare) {
@@ -4,7 +4,7 @@ import { validator, } from '../../core/index.js';
4
4
  * @validator iGt
5
5
  */
6
6
  export function isGt(minValue, options) {
7
- return validator('isGt', (input, context, _this) => {
7
+ return validator(isGt.name, (input, context, _this) => {
8
8
  if ((typeof minValue === 'number' || typeof minValue === 'bigint') &&
9
9
  (typeof input === 'number' || typeof input === 'bigint') &&
10
10
  input > minValue) {
@@ -4,7 +4,7 @@ import type { range } from './range.js';
4
4
  * Checks if value is grater than or equal to minValue
5
5
  * @validator isGte
6
6
  */
7
- export declare function isGte<T extends range.Input>(minValue: T, options?: isGte.Options): Validator<T, T>;
7
+ export declare function isGte<T extends range.Input>(minValue: T, options?: isGte.Options): Validator<T>;
8
8
  export declare namespace isGte {
9
9
  interface Options extends ValidationOptions {
10
10
  caseInsensitive?: boolean;
@@ -4,7 +4,7 @@ import { validator, } from '../../core/index.js';
4
4
  * @validator isGte
5
5
  */
6
6
  export function isGte(minValue, options) {
7
- return validator('isGte', (input, context, _this) => {
7
+ return validator(isGte.name, (input, context, _this) => {
8
8
  if ((typeof minValue === 'number' || typeof minValue === 'bigint') &&
9
9
  (typeof input === 'number' || typeof input === 'bigint') &&
10
10
  input >= minValue) {
@@ -4,7 +4,7 @@ import { validator, } from '../../core/index.js';
4
4
  * @validator isLt
5
5
  */
6
6
  export function isLt(maxValue, options) {
7
- return validator('isLt', (input, context, _this) => {
7
+ return validator(isLt.name, (input, context, _this) => {
8
8
  if ((typeof maxValue === 'number' || typeof maxValue === 'bigint') &&
9
9
  (typeof input === 'number' || typeof input === 'bigint') &&
10
10
  input < maxValue) {
@@ -4,7 +4,7 @@ import { validator, } from '../../core/index.js';
4
4
  * @validator isLte
5
5
  */
6
6
  export function isLte(maxValue, options) {
7
- return validator('isLte', (input, context, _this) => {
7
+ return validator(isLte.name, (input, context, _this) => {
8
8
  if ((typeof maxValue === 'number' || typeof maxValue === 'bigint') &&
9
9
  (typeof input === 'number' || typeof input === 'bigint') &&
10
10
  input <= maxValue) {
@@ -4,7 +4,7 @@ import { validator, } from '../../core/index.js';
4
4
  * @validator range
5
5
  */
6
6
  export function range(minValue, maxValue, options) {
7
- return validator('range', (input, context, _this) => {
7
+ return validator(range.name, (input, context, _this) => {
8
8
  if ((typeof minValue === 'number' || typeof minValue === 'bigint') &&
9
9
  (typeof maxValue === 'number' || typeof maxValue === 'bigint') &&
10
10
  (typeof input === 'number' || typeof input === 'bigint') &&
@@ -3,4 +3,4 @@ import { validator } from '../../core/index.js';
3
3
  * Does nothing, just returns the original input value.
4
4
  * @validator isAny
5
5
  */
6
- export const isAny = () => validator('is-any', (input) => input);
6
+ export const isAny = () => validator(isAny.name, (input) => input);
@@ -5,7 +5,7 @@ import { validator } from '../../core/index.js';
5
5
  * @validator isArray
6
6
  */
7
7
  export function isArray(itemValidator, options) {
8
- return validator('isArray', (input, context, _this) => {
8
+ return validator(isArray.name, (input, context, _this) => {
9
9
  const coerce = options?.coerce ?? context.coerce;
10
10
  let output = input;
11
11
  if (output != null && coerce && !Array.isArray(output))
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
5
5
  * @validator isNumber
6
6
  */
7
7
  export function isBigint(options) {
8
- return validator('isBigint', (input, context, _this) => {
8
+ return validator(isBigint.name, (input, context, _this) => {
9
9
  const coerce = options?.coerce ?? context.coerce;
10
10
  if (typeof input === 'bigint')
11
11
  return input;
@@ -7,7 +7,7 @@ const FALSE_PATTERN = /^false|f|0|no|n$/i;
7
7
  * @validator isBoolean
8
8
  */
9
9
  export function isBoolean(options) {
10
- return validator('isBoolean', (input, context, _this) => {
10
+ return validator(isBoolean.name, (input, context, _this) => {
11
11
  const coerce = options?.coerce ?? context.coerce;
12
12
  let output = input;
13
13
  if (output != null && typeof output !== 'boolean' && coerce) {
@@ -23,6 +23,6 @@ export declare namespace isDateString {
23
23
  precisionMin?: Precision;
24
24
  precisionMax?: Precision;
25
25
  trim?: boolean;
26
- timeZone?: boolean | number;
26
+ separators?: boolean;
27
27
  }
28
28
  }
@@ -8,7 +8,7 @@ import { validator, } from '../../core/index.js';
8
8
  */
9
9
  export function isDate(options) {
10
10
  const trim = options?.trim;
11
- return validator('isDate', (input, context, _this) => {
11
+ return validator(isDate.name, (input, context, _this) => {
12
12
  const coerce = options?.coerce ?? context.coerce;
13
13
  let d;
14
14
  if (input instanceof Date)
@@ -44,9 +44,12 @@ export function isDateString(options) {
44
44
  let precisionMin = options?.precisionMin || 'minutes';
45
45
  const precisionMinIdx = Math.min(precisionMaxIdx, PRECISION_INDEX[precisionMin] || 6);
46
46
  precisionMin = (PRECISION_INDEX_KEYS[PRECISION_INDEX_VALUES.indexOf(precisionMinIdx)] || precisionMin);
47
- return validator('isDateString', (input, context, _this) => {
47
+ return validator(isDateString.name, (input, context, _this) => {
48
48
  const coerce = options?.coerce ?? context.coerce;
49
- const parsed = coerceDateString(input, trim ? precisionMax : undefined);
49
+ const parsed = coerceDateString(input, {
50
+ trimPrecision: trim ? precisionMax : undefined,
51
+ separators: options?.separators,
52
+ });
50
53
  if (parsed) {
51
54
  if (parsed.precision < precisionMinIdx) {
52
55
  context.fail(_this, `Minimum date precision should be ${precisionMin}`, input, options);
@@ -62,7 +65,9 @@ export function isDateString(options) {
62
65
  // noinspection RegExpUnnecessaryNonCapturingGroup
63
66
  const DATE_PATTERN = /^(\d{4})(?:-(0[0-9]|1[0-2]))?(?:-([0-2][0-9]|3[0-1]))?(?:[T ](?:([0-1][0-9]|2[0-4]):([0-5][0-9])(?::([0-5][0-9]))?(?:\.(\d{0,6}))?)?((?:[+-](0[0-9]|1[0-2])(?::(\d{2}))?)|Z)?)?$/;
64
67
  const DATE_PATTERN2 = /^(\d{4,14})(?:\.(\d{1,6}))?(?:(?:([+-])(0[0-9]|1[0-2])(\d{2})?)|Z)?$/;
65
- function coerceDateString(input, trimPrecision) {
68
+ function coerceDateString(input, options = {}) {
69
+ const { trimPrecision } = options;
70
+ const separators = options.separators ?? true;
66
71
  const precisionIndex = (trimPrecision ? PRECISION_INDEX[trimPrecision] : 9) || 9;
67
72
  let dateParts;
68
73
  let detectedPrecision;
@@ -122,15 +127,15 @@ function coerceDateString(input, trimPrecision) {
122
127
  detectedPrecision = Math.min(dateParts.length, 8);
123
128
  let value = dateParts[0] || '0000';
124
129
  if (precisionIndex > 1)
125
- value += '-' + (dateParts[1] || '01');
130
+ value += (separators ? '-' : '') + (dateParts[1] || '01');
126
131
  if (precisionIndex > 2)
127
- value += '-' + (dateParts[2] || '01');
132
+ value += (separators ? '-' : '') + (dateParts[2] || '01');
128
133
  if (precisionIndex > 3)
129
- value += 'T' + (dateParts[3] || '00');
134
+ value += (separators ? 'T' : '') + (dateParts[3] || '00');
130
135
  if (precisionIndex > 4)
131
- value += ':' + (dateParts[4] || '00');
136
+ value += (separators ? ':' : '') + (dateParts[4] || '00');
132
137
  if (precisionIndex > 5)
133
- value += ':' + (dateParts[5] || '00');
138
+ value += (separators ? ':' : '') + (dateParts[5] || '00');
134
139
  if (precisionIndex > 6)
135
140
  value += dateParts[6] ? '.' + dateParts[6] : '';
136
141
  if (precisionIndex > 7)
@@ -22,7 +22,7 @@ export function isEnum(values, options) {
22
22
  a[v] = true;
23
23
  return a;
24
24
  }, {});
25
- return validator('isEnum', (input, context, _this) => {
25
+ return validator(isEnum.name, (input, context, _this) => {
26
26
  if (input != null &&
27
27
  valObj[typeof input === 'string' && caseInSensitive
28
28
  ? input.toUpperCase()
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
5
5
  * @validator isUndefined
6
6
  */
7
7
  export function isInstanceOf(clazz, options) {
8
- return validator('isInstanceOf', (input, context, _this) => {
8
+ return validator(isInstanceOf.name, (input, context, _this) => {
9
9
  if ((options?.coerce ?? context.coerce) && isPlainObject(input)) {
10
10
  Object.setPrototypeOf(input, clazz.prototype);
11
11
  }
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
5
5
  * @validator isInteger
6
6
  */
7
7
  export function isInteger(options) {
8
- return validator('isInteger', (input, context, _this) => {
8
+ return validator(isInteger.name, (input, context, _this) => {
9
9
  const coerce = options?.coerce ?? context.coerce;
10
10
  let output = input;
11
11
  if (output != null && typeof output !== 'number' && coerce) {
@@ -4,7 +4,7 @@ import { validator, } from '../../core/index.js';
4
4
  * @validator isNull
5
5
  */
6
6
  export function isNull(options) {
7
- return validator('isNull', (input, context, _this) => {
7
+ return validator(isNull.name, (input, context, _this) => {
8
8
  if (input === null)
9
9
  return input;
10
10
  context.fail(_this, `Value must be null`, input);
@@ -15,7 +15,7 @@ export function isNull(options) {
15
15
  * @validator isNotNull
16
16
  */
17
17
  export function isNotNull(options) {
18
- return validator('isNotNull', (input, context, _this) => {
18
+ return validator(isNotNull.name, (input, context, _this) => {
19
19
  if (input !== null)
20
20
  return input;
21
21
  context.fail(_this, `{{label}} is null`, input);
@@ -26,7 +26,7 @@ export function isNotNull(options) {
26
26
  * @validator isNullish
27
27
  */
28
28
  export function isNullish(options) {
29
- return validator('isNullish', (input, context, _this) => {
29
+ return validator(isNullish.name, (input, context, _this) => {
30
30
  if (input == null)
31
31
  return input;
32
32
  context.fail(_this, `{{label}} is not nullish`, input);
@@ -37,7 +37,7 @@ export function isNullish(options) {
37
37
  * @validator isNotNullish
38
38
  */
39
39
  export function isNotNullish(options) {
40
- return validator('isNotNullish', (input, context, _this) => {
40
+ return validator(isNotNullish.name, (input, context, _this) => {
41
41
  if (input != null)
42
42
  return input;
43
43
  if (input === null)
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
5
5
  * @validator isNumber
6
6
  */
7
7
  export function isNumber(options) {
8
- return validator('isNumber', (input, context, _this) => {
8
+ return validator(isNumber.name, (input, context, _this) => {
9
9
  const coerce = options?.coerce ?? context.coerce;
10
10
  let output = input;
11
11
  if (output != null && typeof output !== 'number' && coerce) {
@@ -33,7 +33,7 @@ export function isObject(schema, options) {
33
33
  throw new TypeError(`Invalid definition in validation schema (${k})`);
34
34
  }
35
35
  }
36
- const _rule = validator('isObject', (input, context, _this) => {
36
+ const _rule = validator(isObject.name, (input, context, _this) => {
37
37
  let output = input;
38
38
  if (ctor && ctor[preValidation]) {
39
39
  output = ctor[preValidation](output, context, _this);
@@ -5,7 +5,7 @@ import { validator } from '../../core/index.js';
5
5
  * @validator isRecord
6
6
  */
7
7
  export function isRecord(keyRule, valueRule, options) {
8
- return validator('isRecord', (input, context, _this) => {
8
+ return validator(isRecord.name, (input, context, _this) => {
9
9
  if (!(input && typeof input === 'object')) {
10
10
  context.fail(_this, `Value must be an object`, input);
11
11
  return;
@@ -5,7 +5,7 @@ import { validator, } from '../../core/index.js';
5
5
  * @validator isString
6
6
  */
7
7
  export function isString(options) {
8
- return validator('isString', (input, context, _this) => {
8
+ return validator(isString.name, (input, context, _this) => {
9
9
  const coerce = options?.coerce ?? context.coerce;
10
10
  let output = input;
11
11
  if (output != null && typeof output !== 'string' && coerce) {
@@ -1,6 +1,6 @@
1
1
  import { validator, } from '../../core/index.js';
2
2
  export function isTuple(items, options) {
3
- return validator('isTuple', (input, context, _this) => {
3
+ return validator(isTuple.name, (input, context, _this) => {
4
4
  const coerce = options?.coerce ?? context.coerce;
5
5
  let output = input;
6
6
  if (output != null && coerce && !Array.isArray(output))
@@ -4,7 +4,7 @@ import { validator, } from '../../core/index.js';
4
4
  * @validator isUndefined
5
5
  */
6
6
  export function isUndefined(options) {
7
- return validator('isUndefined', (input, context, _this) => {
7
+ return validator(isUndefined.name, (input, context, _this) => {
8
8
  if (options?.coerce ?? context.coerce)
9
9
  return undefined;
10
10
  if (input === undefined)
@@ -4,7 +4,7 @@ import { validator } from '../../core/index.js';
4
4
  * @validator allOf
5
5
  */
6
6
  export function allOf(rules, options) {
7
- return validator('allOf', (input, context) => {
7
+ return validator(allOf.name, (input, context) => {
8
8
  let i;
9
9
  let c;
10
10
  const l = rules.length;
@@ -4,7 +4,7 @@ import { validator, } from '../../core/index.js';
4
4
  * @validator exists
5
5
  */
6
6
  export function exists(options) {
7
- return validator('exists', (input, context, _this) => {
7
+ return validator(exists.name, (input, context, _this) => {
8
8
  if (input !== undefined ||
9
9
  (context.scope &&
10
10
  Object.getOwnPropertyDescriptor(context.scope, input))) {
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Check if value is not nullish before calling nested rule
3
+ * @validator required
4
+ */
5
+ export declare function fixed<T, I>(value: T): import("../../core/validator.js").Validator<T, I, import("../../core/types.js").ExecutionOptions>;
@@ -0,0 +1,10 @@
1
+ import { validator } from '../../core/index.js';
2
+ /**
3
+ * Check if value is not nullish before calling nested rule
4
+ * @validator required
5
+ */
6
+ export function fixed(value) {
7
+ return validator(fixed.name, () => {
8
+ return value;
9
+ });
10
+ }
@@ -4,7 +4,7 @@ import { validator } from '../../core/index.js';
4
4
  * @validator getLength
5
5
  */
6
6
  export function getLength() {
7
- return validator('getLength', (input, context, _this) => {
7
+ return validator(getLength.name, (input, context, _this) => {
8
8
  if (typeof input === 'string')
9
9
  return input.length;
10
10
  if (Array.isArray(input))
@@ -0,0 +1,11 @@
1
+ import type { Nullish } from 'ts-gems';
2
+ import { type ValidationOptions, type Validator } from '../../core/index.js';
3
+ /**
4
+ * Makes the sub-rule nullable (undefined of null)
5
+ * @validator optional
6
+ */
7
+ export declare function nullable<T, I>(nested: Validator<T, I>, options?: nullable.Options): Validator<Nullish<T>, Nullish<I>, import("../../core/types.js").ExecutionOptions>;
8
+ export declare namespace nullable {
9
+ interface Options extends ValidationOptions {
10
+ }
11
+ }
@@ -0,0 +1,12 @@
1
+ import { validator, } from '../../core/index.js';
2
+ /**
3
+ * Makes the sub-rule nullable (undefined of null)
4
+ * @validator optional
5
+ */
6
+ export function nullable(nested, options) {
7
+ return validator(nullable.name, (input, context) => {
8
+ if (input == null)
9
+ return input;
10
+ return nested(input, context);
11
+ }, options);
12
+ }
@@ -4,7 +4,7 @@ import { validator } from '../../core/index.js';
4
4
  */
5
5
  export function oneOf(rules, options) {
6
6
  const l = rules.length;
7
- return validator('union', (input, context, _this) => {
7
+ return validator(oneOf.name, (input, context, _this) => {
8
8
  let i;
9
9
  let c;
10
10
  let discriminator;
@@ -1,10 +1,10 @@
1
- import type { Nullish } from 'ts-gems';
1
+ import type { Maybe } from 'ts-gems';
2
2
  import { type ValidationOptions, type Validator } from '../../core/index.js';
3
3
  /**
4
4
  * Makes the sub-rule optional
5
5
  * @validator optional
6
6
  */
7
- export declare function optional<T, I>(nested: Validator<T, I>, options?: optional.Options): Validator<Nullish<T>, Nullish<I>, import("../../core/types.js").ExecutionOptions>;
7
+ export declare function optional<T, I>(nested: Validator<T, I>, options?: optional.Options): Validator<Maybe<T>, Maybe<I>, import("../../core/types.js").ExecutionOptions>;
8
8
  export declare namespace optional {
9
9
  interface Options extends ValidationOptions {
10
10
  }
@@ -4,8 +4,8 @@ import { validator, } from '../../core/index.js';
4
4
  * @validator optional
5
5
  */
6
6
  export function optional(nested, options) {
7
- return validator('optional', (input, context) => {
8
- if (input == null)
7
+ return validator(optional.name, (input, context) => {
8
+ if (input === undefined)
9
9
  return input;
10
10
  return nested(input, context);
11
11
  }, options);
@@ -6,7 +6,7 @@ import { validator, } from '../../core/index.js';
6
6
  export function pipe(rules, options) {
7
7
  const l = rules.length;
8
8
  const returnIndex = options?.returnIndex;
9
- return validator('pipe', (input, context) => {
9
+ return validator(pipe.name, (input, context) => {
10
10
  let i;
11
11
  let c;
12
12
  let v = input;
@@ -4,7 +4,7 @@ import { validator, } from '../../core/index.js';
4
4
  * @validator required
5
5
  */
6
6
  export function required(nested, options) {
7
- return validator('required', (input, context, _this) => {
7
+ return validator(required.name, (input, context, _this) => {
8
8
  if (input == null)
9
9
  input = options?.default;
10
10
  if (input == null) {
@@ -27,9 +27,9 @@ export declare function trim(): import("../../core/validator.js").Validator<stri
27
27
  * Removes whitespace from the end of a string
28
28
  * @validator trimEnd
29
29
  */
30
- export declare const trimEnd: () => import("../../core/validator.js").Validator<string, string, import("../../core/types.js").ExecutionOptions>;
30
+ export declare function trimEnd(): import("../../core/validator.js").Validator<string, string, import("../../core/types.js").ExecutionOptions>;
31
31
  /**
32
32
  * Removes whitespace from the beginning of a string
33
33
  * @validator trimStart
34
34
  */
35
- export declare const trimStart: () => import("../../core/validator.js").Validator<string, string, import("../../core/types.js").ExecutionOptions>;
35
+ export declare function trimStart(): import("../../core/validator.js").Validator<string, string, import("../../core/types.js").ExecutionOptions>;
@@ -1,13 +1,13 @@
1
1
  import { validator } from '../../core/index.js';
2
2
  export function stringReplace(searchValue, replacer) {
3
- return validator('stringReplace', (input) => {
3
+ return validator(stringReplace.name, (input) => {
4
4
  if (input == null)
5
5
  return input;
6
6
  return String(input).replace(searchValue, replacer);
7
7
  });
8
8
  }
9
9
  export function stringSplit(splitter, limit) {
10
- return validator('stringSplit', (input) => {
10
+ return validator(stringSplit.name, (input) => {
11
11
  if (input == null)
12
12
  return input;
13
13
  return String(input).split(splitter, limit);
@@ -18,7 +18,7 @@ export function stringSplit(splitter, limit) {
18
18
  * @validator trim
19
19
  */
20
20
  export function trim() {
21
- return validator('trim', (input) => {
21
+ return validator(trim.name, (input) => {
22
22
  if (input == null)
23
23
  return input;
24
24
  return String(input).trim();
@@ -29,20 +29,22 @@ export function trim() {
29
29
  * Removes whitespace from the end of a string
30
30
  * @validator trimEnd
31
31
  */
32
- export const trimEnd = () => trimEndRule;
33
- const trimEndRule = validator('trimEnd', (input) => {
34
- if (input == null)
35
- return input;
36
- return String(input).trimEnd();
37
- });
32
+ export function trimEnd() {
33
+ return validator(trimEnd.name, (input) => {
34
+ if (input == null)
35
+ return input;
36
+ return String(input).trimEnd();
37
+ });
38
+ }
38
39
  // *************************************************************
39
40
  /**
40
41
  * Removes whitespace from the beginning of a string
41
42
  * @validator trimStart
42
43
  */
43
- export const trimStart = () => trimStartRule;
44
- const trimStartRule = validator('trimStart', (input) => {
45
- if (input == null)
46
- return input;
47
- return String(input).trimStart();
48
- });
44
+ export function trimStart() {
45
+ return validator(trimStart.name, (input) => {
46
+ if (input == null)
47
+ return input;
48
+ return String(input).trimStart();
49
+ });
50
+ }