koatty_validation 1.2.9 → 1.3.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/CHANGELOG.md +19 -0
- package/README.md +4 -0
- package/dist/README.md +4 -0
- package/dist/index.d.ts +107 -2
- package/dist/index.js +1369 -1349
- package/dist/index.mjs +1365 -1344
- package/dist/package.json +22 -20
- package/package.json +22 -20
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [1.3.0](https://github.com/koatty/koatty_validation/compare/v1.2.10...v1.3.0) (2024-01-03)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* 增加@CheckFunc ([d5bdc2d](https://github.com/koatty/koatty_validation/commit/d5bdc2d51cdbf6d558e376bfda51e126158d4e75))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* export ValidFuncs ([7d42023](https://github.com/koatty/koatty_validation/commit/7d42023138e9577c9646423c4c38faffba46fb10))
|
|
16
|
+
|
|
17
|
+
### [1.2.10](https://github.com/koatty/koatty_validation/compare/v1.2.9...v1.2.10) (2023-12-16)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* assign dto property ([2357642](https://github.com/koatty/koatty_validation/commit/2357642f6ac1479c839454d40ec4bd89f3fbd7b2))
|
|
23
|
+
|
|
5
24
|
### [1.2.9](https://github.com/koatty/koatty_validation/compare/v1.2.8...v1.2.9) (2023-09-01)
|
|
6
25
|
|
|
7
26
|
### [1.2.8](https://github.com/koatty/koatty_validation/compare/v1.2.7...v1.2.8) (2023-02-17)
|
package/README.md
CHANGED
|
@@ -89,6 +89,10 @@ const str = "";
|
|
|
89
89
|
// throw Error
|
|
90
90
|
FunctionValidator.IsNotEmpty(str, "cannot be empty");
|
|
91
91
|
FunctionValidator.Contains(str, {message: "must contain s", value: "s"});
|
|
92
|
+
//
|
|
93
|
+
if (!ValidFuncs.IsNotEmpty(str)) {
|
|
94
|
+
console.log("empty");
|
|
95
|
+
}
|
|
92
96
|
```
|
|
93
97
|
|
|
94
98
|
## ClassValidator
|
package/dist/README.md
CHANGED
|
@@ -89,6 +89,10 @@ const str = "";
|
|
|
89
89
|
// throw Error
|
|
90
90
|
FunctionValidator.IsNotEmpty(str, "cannot be empty");
|
|
91
91
|
FunctionValidator.Contains(str, {message: "must contain s", value: "s"});
|
|
92
|
+
//
|
|
93
|
+
if (!ValidFuncs.IsNotEmpty(str)) {
|
|
94
|
+
console.log("empty");
|
|
95
|
+
}
|
|
92
96
|
```
|
|
93
97
|
|
|
94
98
|
## ClassValidator
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* @Author: richen
|
|
3
|
-
* @Date:
|
|
3
|
+
* @Date: 2024-01-03 14:41:03
|
|
4
4
|
* @License: BSD (3-Clause)
|
|
5
5
|
* @Copyright (c) - <richenlin(at)gmail.com>
|
|
6
6
|
* @HomePage: https://koatty.org/
|
|
@@ -9,6 +9,14 @@ import { CountryCode } from 'libphonenumber-js';
|
|
|
9
9
|
import { IsIpVersion } from 'class-validator';
|
|
10
10
|
import { ValidationOptions } from 'class-validator';
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Use a custom function for validation
|
|
14
|
+
* @param func
|
|
15
|
+
* @param validationOptions
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
export declare function CheckFunc(func: (value: unknown) => boolean, validationOptions?: ValidationOptions): PropertyDecorator;
|
|
19
|
+
|
|
12
20
|
/**
|
|
13
21
|
* Check the base types.
|
|
14
22
|
*
|
|
@@ -126,7 +134,7 @@ export declare function IsCnName(validationOptions?: ValidationOptions): Propert
|
|
|
126
134
|
export declare function IsDate(validationOptions?: ValidationOptions): PropertyDecorator;
|
|
127
135
|
|
|
128
136
|
/**
|
|
129
|
-
*
|
|
137
|
+
* Alias of Expose
|
|
130
138
|
*
|
|
131
139
|
* @export
|
|
132
140
|
* @returns {PropertyDecorator}
|
|
@@ -405,6 +413,103 @@ declare class ValidateClass {
|
|
|
405
413
|
*/
|
|
406
414
|
export declare function Validated(): MethodDecorator;
|
|
407
415
|
|
|
416
|
+
/**
|
|
417
|
+
* Validator Functions
|
|
418
|
+
*/
|
|
419
|
+
export declare const ValidFuncs: {
|
|
420
|
+
/**
|
|
421
|
+
* Checks value is not empty, undefined, null, '', NaN, [], {} and any empty string(including spaces,
|
|
422
|
+
* tabs, formfeeds, etc.), returns false
|
|
423
|
+
*/
|
|
424
|
+
IsNotEmpty: (value: unknown) => boolean;
|
|
425
|
+
/**
|
|
426
|
+
* Checks if a given value is a real date.
|
|
427
|
+
*/
|
|
428
|
+
IsDate: (value: unknown) => boolean;
|
|
429
|
+
/**
|
|
430
|
+
* Checks if the string is an email. If given value is not a string, then it returns false.
|
|
431
|
+
*/
|
|
432
|
+
IsEmail: (value: unknown, options?: IsEmailOptions) => boolean;
|
|
433
|
+
/**
|
|
434
|
+
* Checks if the string is an IP (version 4 or 6). If given value is not a string, then it returns false.
|
|
435
|
+
*/
|
|
436
|
+
IsIP: (value: unknown, version?: any) => boolean;
|
|
437
|
+
/**
|
|
438
|
+
* Checks if the string is a valid phone number.
|
|
439
|
+
* @param value — the potential phone number string to test
|
|
440
|
+
* @param region 2 characters uppercase country code (e.g. DE, US, CH). If users must enter the intl.
|
|
441
|
+
* prefix (e.g. +41), then you may pass "ZZ" or null as region.
|
|
442
|
+
* See [google-libphonenumber, metadata.js:countryCodeToRegionCodeMap on github]
|
|
443
|
+
* {@link https://github.com/ruimarinho/google-libphonenumber/blob/1e46138878cff479aafe2ce62175c6c49cb58720/src/metadata.js#L33}
|
|
444
|
+
*/
|
|
445
|
+
IsPhoneNumber: (value: string, region?: CountryCode) => boolean;
|
|
446
|
+
/**
|
|
447
|
+
* Checks if the string is an url. If given value is not a string, then it returns false.
|
|
448
|
+
*/
|
|
449
|
+
IsUrl: (value: string, options?: IsURLOptions) => boolean;
|
|
450
|
+
/**
|
|
451
|
+
* check if the string is a hash of type algorithm. Algorithm is one of
|
|
452
|
+
* ['md4', 'md5', 'sha1', 'sha256', 'sha384', 'sha512', 'ripemd128', 'ripemd160', 'tiger128', 'tiger160', 'tiger192', 'crc32', 'crc32b']
|
|
453
|
+
*/
|
|
454
|
+
IsHash: (value: unknown, algorithm: HashAlgorithm) => boolean;
|
|
455
|
+
/**
|
|
456
|
+
* Checks if value is a chinese name.
|
|
457
|
+
*/
|
|
458
|
+
IsCnName: (value: any) => boolean;
|
|
459
|
+
/**
|
|
460
|
+
* Checks if value is a idcard number.
|
|
461
|
+
*/
|
|
462
|
+
IsIdNumber: (value: any) => boolean;
|
|
463
|
+
/**
|
|
464
|
+
* Checks if value is a zipCode.
|
|
465
|
+
*/
|
|
466
|
+
IsZipCode: (value: any) => boolean;
|
|
467
|
+
/**
|
|
468
|
+
* Checks if value is a mobile phone number.
|
|
469
|
+
*/
|
|
470
|
+
IsMobile: (value: any) => boolean;
|
|
471
|
+
/**
|
|
472
|
+
* Checks if value is a plateNumber.
|
|
473
|
+
*/
|
|
474
|
+
IsPlateNumber: (value: any) => boolean;
|
|
475
|
+
/**
|
|
476
|
+
* Checks if value matches ("===") the comparison.
|
|
477
|
+
*/
|
|
478
|
+
Equals: (value: unknown, comparison: unknown) => boolean;
|
|
479
|
+
/**
|
|
480
|
+
* Checks if value does not match ("!==") the comparison.
|
|
481
|
+
*/
|
|
482
|
+
NotEquals: (value: unknown, comparison: unknown) => boolean;
|
|
483
|
+
/**
|
|
484
|
+
* Checks if the string contains the seed. If given value is not a string, then it returns false.
|
|
485
|
+
*/
|
|
486
|
+
Contains: (value: unknown, seed: string) => boolean;
|
|
487
|
+
/**
|
|
488
|
+
* Checks if given value is in a array of allowed values.
|
|
489
|
+
*/
|
|
490
|
+
IsIn: (value: unknown, possibleValues: unknown[]) => boolean;
|
|
491
|
+
/**
|
|
492
|
+
* Checks if given value not in a array of allowed values.
|
|
493
|
+
*/
|
|
494
|
+
IsNotIn: (value: unknown, possibleValues: unknown[]) => boolean;
|
|
495
|
+
/**
|
|
496
|
+
* Checks if the first number is greater than or equal to the second.
|
|
497
|
+
*/
|
|
498
|
+
Gt: (num: unknown, min: number) => boolean;
|
|
499
|
+
/**
|
|
500
|
+
* Checks if the first number is less than or equal to the second.
|
|
501
|
+
*/
|
|
502
|
+
Lt: (num: unknown, max: number) => boolean;
|
|
503
|
+
/**
|
|
504
|
+
* Checks if the first number is greater than or equal to the second.
|
|
505
|
+
*/
|
|
506
|
+
Gte: (num: unknown, min: number) => boolean;
|
|
507
|
+
/**
|
|
508
|
+
* Checks if the first number is less than or equal to the second.
|
|
509
|
+
*/
|
|
510
|
+
Lte: (num: unknown, max: number) => boolean;
|
|
511
|
+
};
|
|
512
|
+
|
|
408
513
|
export declare type ValidOtpions = {
|
|
409
514
|
message: string;
|
|
410
515
|
value: any;
|