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.
- package/constants.js +1 -1
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +3 -3
- package/rules/format-rules/is-alpha.js +1 -1
- package/rules/format-rules/is-alphanumeric.js +1 -1
- package/rules/format-rules/is-ascii.js +1 -1
- package/rules/format-rules/is-base64.js +1 -1
- package/rules/format-rules/is-btc-address.js +1 -1
- package/rules/format-rules/is-credit-card.js +1 -1
- package/rules/format-rules/is-decimal.js +1 -1
- package/rules/format-rules/is-ean.js +1 -1
- package/rules/format-rules/is-email.js +1 -1
- package/rules/format-rules/is-eth-address.js +1 -1
- package/rules/format-rules/is-fqdn.js +1 -1
- package/rules/format-rules/is-hash.js +1 -1
- package/rules/format-rules/is-hex-color.js +1 -1
- package/rules/format-rules/is-hex.js +1 -1
- package/rules/format-rules/is-iban.js +1 -1
- package/rules/format-rules/is-ip.js +2 -2
- package/rules/format-rules/is-issn.js +1 -1
- package/rules/format-rules/is-jwt.js +1 -1
- package/rules/format-rules/is-lowercase.js +1 -1
- package/rules/format-rules/is-mac-address.js +1 -1
- package/rules/format-rules/is-mobile-phone.js +1 -1
- package/rules/format-rules/is-object-id.js +1 -1
- package/rules/format-rules/is-passport-number.js +1 -1
- package/rules/format-rules/is-port.js +1 -1
- package/rules/format-rules/is-swift.js +1 -1
- package/rules/format-rules/is-time.js +1 -1
- package/rules/format-rules/is-uppercase.js +1 -1
- package/rules/format-rules/is-url.js +1 -1
- package/rules/format-rules/is-uuid.js +1 -1
- package/rules/format-rules/is-vat-number.js +1 -1
- package/rules/format-rules/matches.js +1 -1
- package/rules/index.d.ts +2 -0
- package/rules/index.js +2 -0
- package/rules/logical-rules/is-defined.js +1 -1
- package/rules/logical-rules/is-empty.js +1 -1
- package/rules/logical-rules/is-equal.js +2 -2
- package/rules/logical-rules/is-gt.js +1 -1
- package/rules/logical-rules/is-gte.d.ts +1 -1
- package/rules/logical-rules/is-gte.js +1 -1
- package/rules/logical-rules/is-lt.js +1 -1
- package/rules/logical-rules/is-lte.js +1 -1
- package/rules/logical-rules/range.js +1 -1
- package/rules/type-rules/is-any.js +1 -1
- package/rules/type-rules/is-array.js +1 -1
- package/rules/type-rules/is-bigint.js +1 -1
- package/rules/type-rules/is-boolean.js +1 -1
- package/rules/type-rules/is-date.d.ts +1 -1
- package/rules/type-rules/is-date.js +14 -9
- package/rules/type-rules/is-enum.js +1 -1
- package/rules/type-rules/is-instanceof.js +1 -1
- package/rules/type-rules/is-integer.js +1 -1
- package/rules/type-rules/is-null.js +4 -4
- package/rules/type-rules/is-number.js +1 -1
- package/rules/type-rules/is-object.js +1 -1
- package/rules/type-rules/is-record.js +1 -1
- package/rules/type-rules/is-string.js +1 -1
- package/rules/type-rules/is-tuple.js +1 -1
- package/rules/type-rules/is-undefined.js +1 -1
- package/rules/utility-rules/all-of.js +1 -1
- package/rules/utility-rules/exists.js +1 -1
- package/rules/utility-rules/fixed.d.ts +5 -0
- package/rules/utility-rules/fixed.js +10 -0
- package/rules/utility-rules/get-length.js +1 -1
- package/rules/utility-rules/nullable.d.ts +11 -0
- package/rules/utility-rules/nullable.js +12 -0
- package/rules/utility-rules/one-of.js +1 -1
- package/rules/utility-rules/optional.d.ts +2 -2
- package/rules/utility-rules/optional.js +2 -2
- package/rules/utility-rules/pipe.js +1 -1
- package/rules/utility-rules/required.js +1 -1
- package/rules/utility-rules/string-utils.d.ts +2 -2
- package/rules/utility-rules/string-utils.js +17 -15
package/constants.js
CHANGED
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
|
|
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.
|
|
10
|
-
"date-fns": "^4.1
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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') &&
|
|
@@ -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(
|
|
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(
|
|
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(
|
|
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) {
|
|
@@ -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(
|
|
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(
|
|
47
|
+
return validator(isDateString.name, (input, context, _this) => {
|
|
48
48
|
const coerce = options?.coerce ?? context.coerce;
|
|
49
|
-
const parsed = coerceDateString(input,
|
|
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,
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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 exists
|
|
5
5
|
*/
|
|
6
6
|
export function exists(options) {
|
|
7
|
-
return validator(
|
|
7
|
+
return validator(exists.name, (input, context, _this) => {
|
|
8
8
|
if (input !== undefined ||
|
|
9
9
|
(context.scope &&
|
|
10
10
|
Object.getOwnPropertyDescriptor(context.scope, input))) {
|
|
@@ -4,7 +4,7 @@ import { validator } from '../../core/index.js';
|
|
|
4
4
|
* @validator getLength
|
|
5
5
|
*/
|
|
6
6
|
export function getLength() {
|
|
7
|
-
return validator(
|
|
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(
|
|
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 {
|
|
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<
|
|
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(
|
|
8
|
-
if (input
|
|
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(
|
|
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(
|
|
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
|
|
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
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
+
}
|