valgen 4.0.0-alpha.2 → 4.0.0-alpha.3
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/cjs/rules/index.js +1 -0
- package/cjs/rules/is-bigint.js +21 -0
- package/cjs/rules/is-date.js +8 -8
- package/cjs/rules/is-number.js +1 -1
- package/esm/rules/index.js +1 -0
- package/esm/rules/is-bigint.js +17 -0
- package/esm/rules/is-date.js +8 -8
- package/esm/rules/is-number.js +1 -1
- package/package.json +1 -1
- package/typings/rules/index.d.ts +1 -0
- package/typings/rules/is-bigint.d.ts +7 -0
- package/typings/rules/is-date.d.ts +1 -1
package/cjs/rules/index.js
CHANGED
|
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./is-any.js"), exports);
|
|
18
18
|
__exportStar(require("./is-array.js"), exports);
|
|
19
|
+
__exportStar(require("./is-bigint.js"), exports);
|
|
19
20
|
__exportStar(require("./is-boolean.js"), exports);
|
|
20
21
|
__exportStar(require("./is-date.js"), exports);
|
|
21
22
|
__exportStar(require("./is-empty.js"), exports);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isBigint = void 0;
|
|
4
|
+
const index_js_1 = require("../core/index.js");
|
|
5
|
+
/**
|
|
6
|
+
* Validates if value is "BigInt".
|
|
7
|
+
* Converts input value to number if coerce option is set to 'true'.
|
|
8
|
+
* @validator isNumber
|
|
9
|
+
*/
|
|
10
|
+
function isBigint(options) {
|
|
11
|
+
return (0, index_js_1.validator)('isBigint', function (input, context) {
|
|
12
|
+
if (input != null && typeof input !== 'bigint' && context.coerce) {
|
|
13
|
+
if (typeof input === 'string' || typeof input === 'number')
|
|
14
|
+
input = BigInt(input);
|
|
15
|
+
}
|
|
16
|
+
if (typeof input === 'bigint')
|
|
17
|
+
return input;
|
|
18
|
+
context.failure(`{{label}} is not a valid BigInt`);
|
|
19
|
+
}, options);
|
|
20
|
+
}
|
|
21
|
+
exports.isBigint = isBigint;
|
package/cjs/rules/is-date.js
CHANGED
|
@@ -43,16 +43,16 @@ exports.isDate = isDate;
|
|
|
43
43
|
* @validator isDateString
|
|
44
44
|
*/
|
|
45
45
|
function isDateString(options) {
|
|
46
|
+
const inputFormat = options?.format;
|
|
47
|
+
const coerceFormat = Array.isArray(options?.format) ? options?.format[0] : options?.format;
|
|
46
48
|
return (0, index_js_1.validator)('isDateString', function (input, context) {
|
|
47
|
-
if (
|
|
48
|
-
const d = (0, dayjs_1.default)(input);
|
|
49
|
-
if (d.isValid())
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if (typeof input === 'string') {
|
|
53
|
-
const d = (0, dayjs_1.default)(input, options?.format);
|
|
54
|
-
if (d.isValid())
|
|
49
|
+
if (typeof input === 'string' || input instanceof Date) {
|
|
50
|
+
const d = (0, dayjs_1.default)(input, inputFormat);
|
|
51
|
+
if (d.isValid()) {
|
|
52
|
+
if (context.coerce && options?.format || input instanceof Date)
|
|
53
|
+
return coerceFormat ? d.format(coerceFormat) : d.toISOString();
|
|
55
54
|
return input;
|
|
55
|
+
}
|
|
56
56
|
}
|
|
57
57
|
context.failure({
|
|
58
58
|
message: `{{label}} is not a valid date formatted${options?.format ? " (" + options.format + ")" : ''} string`,
|
package/cjs/rules/is-number.js
CHANGED
|
@@ -20,7 +20,7 @@ function isNumber(options) {
|
|
|
20
20
|
}
|
|
21
21
|
if (typeof input === 'number' && !isNaN(input))
|
|
22
22
|
return input;
|
|
23
|
-
context.failure(`{{label}} not a valid number`);
|
|
23
|
+
context.failure(`{{label}} is not a valid number`);
|
|
24
24
|
}, options);
|
|
25
25
|
}
|
|
26
26
|
exports.isNumber = isNumber;
|
package/esm/rules/index.js
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { validator } from '../core/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Validates if value is "BigInt".
|
|
4
|
+
* Converts input value to number if coerce option is set to 'true'.
|
|
5
|
+
* @validator isNumber
|
|
6
|
+
*/
|
|
7
|
+
export function isBigint(options) {
|
|
8
|
+
return validator('isBigint', function (input, context) {
|
|
9
|
+
if (input != null && typeof input !== 'bigint' && context.coerce) {
|
|
10
|
+
if (typeof input === 'string' || typeof input === 'number')
|
|
11
|
+
input = BigInt(input);
|
|
12
|
+
}
|
|
13
|
+
if (typeof input === 'bigint')
|
|
14
|
+
return input;
|
|
15
|
+
context.failure(`{{label}} is not a valid BigInt`);
|
|
16
|
+
}, options);
|
|
17
|
+
}
|
package/esm/rules/is-date.js
CHANGED
|
@@ -36,16 +36,16 @@ export function isDate(options) {
|
|
|
36
36
|
* @validator isDateString
|
|
37
37
|
*/
|
|
38
38
|
export function isDateString(options) {
|
|
39
|
+
const inputFormat = options?.format;
|
|
40
|
+
const coerceFormat = Array.isArray(options?.format) ? options?.format[0] : options?.format;
|
|
39
41
|
return validator('isDateString', function (input, context) {
|
|
40
|
-
if (
|
|
41
|
-
const d = dayjs(input);
|
|
42
|
-
if (d.isValid())
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (typeof input === 'string') {
|
|
46
|
-
const d = dayjs(input, options?.format);
|
|
47
|
-
if (d.isValid())
|
|
42
|
+
if (typeof input === 'string' || input instanceof Date) {
|
|
43
|
+
const d = dayjs(input, inputFormat);
|
|
44
|
+
if (d.isValid()) {
|
|
45
|
+
if (context.coerce && options?.format || input instanceof Date)
|
|
46
|
+
return coerceFormat ? d.format(coerceFormat) : d.toISOString();
|
|
48
47
|
return input;
|
|
48
|
+
}
|
|
49
49
|
}
|
|
50
50
|
context.failure({
|
|
51
51
|
message: `{{label}} is not a valid date formatted${options?.format ? " (" + options.format + ")" : ''} string`,
|
package/esm/rules/is-number.js
CHANGED
package/package.json
CHANGED
package/typings/rules/index.d.ts
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ValidationOptions } from '../core/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Validates if value is "BigInt".
|
|
4
|
+
* Converts input value to number if coerce option is set to 'true'.
|
|
5
|
+
* @validator isNumber
|
|
6
|
+
*/
|
|
7
|
+
export declare function isBigint(options?: ValidationOptions): import("../core/validator.js").Validator<bigint, unknown, import("../core/types.js").ExecutionOptions>;
|
|
@@ -9,7 +9,7 @@ export interface IsDateOptions extends ValidationOptions {
|
|
|
9
9
|
*/
|
|
10
10
|
export declare function isDate(options?: IsDateOptions): import("../core/validator.js").Validator<Date, string | number | Date, import("../core/types.js").ExecutionOptions>;
|
|
11
11
|
export interface IsDateStringOptions extends ValidationOptions {
|
|
12
|
-
format?: string;
|
|
12
|
+
format?: string | string[];
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
15
|
* Validates if value is DFS (date formatted string).
|