koa-fluent-validation
Advanced tools
Comparing version 0.14.0 to 1.0.0
@@ -1,2 +0,2 @@ | ||
/// <reference types="validator" /> | ||
import v from 'validator'; | ||
export declare type FilterFn = (val: string, ...args: any[]) => any; | ||
@@ -14,3 +14,3 @@ export interface Filter { | ||
padEnd(len: number, fill?: string): Filters; | ||
normalizeEmail(options?: ValidatorJS.NormalizeEmailOptions): Filters; | ||
normalizeEmail(options?: v.NormalizeEmailOptions): Filters; | ||
toInt(radix?: number): Filters; | ||
@@ -31,3 +31,3 @@ toBoolean(): Filters; | ||
padEnd(len: number, fill?: string): Filters; | ||
normalizeEmail(options?: ValidatorJS.NormalizeEmailOptions): Filters; | ||
normalizeEmail(options?: v.NormalizeEmailOptions): Filters; | ||
toInt(radix?: number): Filters; | ||
@@ -34,0 +34,0 @@ toBoolean(strict?: boolean): Filters; |
@@ -53,4 +53,3 @@ "use strict"; | ||
normalizeEmail(options) { | ||
return this.addFilter((value, options) => (typeof value === 'string' && | ||
validator_1.default.normalizeEmail(value, options)) || | ||
return this.addFilter((value, options) => (typeof value === 'string' && validator_1.default.normalizeEmail(value, options)) || | ||
value, options); | ||
@@ -57,0 +56,0 @@ } |
@@ -1,2 +0,2 @@ | ||
/// <reference types="validator" /> | ||
import v from 'validator'; | ||
export declare type ValidatorFn = (context: ValidatorContext, ...args: any[]) => boolean; | ||
@@ -21,9 +21,9 @@ export declare type TPred = (value: any) => boolean; | ||
string(): Validators; | ||
email(options?: ValidatorJS.IsEmailOptions): Validators; | ||
email(options?: v.IsEmailOptions): Validators; | ||
uuid(version?: UUIDVersion): Validators; | ||
number(strict?: boolean): Validators; | ||
float(strict?: boolean, options?: ValidatorJS.IsFloatOptions): Validators; | ||
currency(options?: ValidatorJS.IsCurrencyOptions): Validators; | ||
float(strict?: boolean, options?: v.IsFloatOptions): Validators; | ||
currency(options?: v.IsCurrencyOptions): Validators; | ||
decimal(strict?: boolean): Validators; | ||
int(strict?: boolean, options?: ValidatorJS.IsIntOptions): Validators; | ||
int(strict?: boolean, options?: v.IsIntOptions): Validators; | ||
length(min?: number, max?: number): Validators; | ||
@@ -33,8 +33,8 @@ base64(): Validators; | ||
in(values: any[]): Validators; | ||
url(options?: ValidatorJS.IsURLOptions): Validators; | ||
url(options?: v.IsURLOptions): Validators; | ||
contains(seed: string): Validators; | ||
min(num: number, strict?: boolean): Validators; | ||
max(num: number, strict?: boolean): Validators; | ||
mobilePhone(locale?: ValidatorJS.MobilePhoneLocale): Validators; | ||
ipAddress(version?: number): Validators; | ||
mobilePhone(locale?: v.MobilePhoneLocale): Validators; | ||
ipAddress(version?: '4' | '6'): Validators; | ||
creditCard(): Validators; | ||
@@ -56,9 +56,9 @@ test(regex: RegExp): Validators; | ||
string(): Validators; | ||
email(options?: ValidatorJS.IsEmailOptions): Validators; | ||
email(options?: v.IsEmailOptions): Validators; | ||
uuid(version?: UUIDVersion): Validators; | ||
number(strict?: boolean): Validators; | ||
float(strict?: boolean, options?: ValidatorJS.IsFloatOptions): Validators; | ||
currency(options?: ValidatorJS.IsCurrencyOptions): Validators; | ||
float(strict?: boolean, options?: v.IsFloatOptions): Validators; | ||
currency(options?: v.IsCurrencyOptions): Validators; | ||
decimal(strict?: boolean): Validators; | ||
int(strict?: boolean, options?: ValidatorJS.IsIntOptions): Validators; | ||
int(strict?: boolean, options?: v.IsIntOptions): Validators; | ||
length(min?: number, max?: number): Validators; | ||
@@ -68,8 +68,8 @@ base64(): Validators; | ||
in(values: any[]): Validators; | ||
url(options?: ValidatorJS.IsURLOptions): Validators; | ||
url(options?: v.IsURLOptions): Validators; | ||
contains(seed: string): Validators; | ||
min(num: number, strict?: boolean): Validators; | ||
max(num: number, strict?: boolean): Validators; | ||
mobilePhone(locale?: ValidatorJS.MobilePhoneLocale): Validators; | ||
ipAddress(version?: number): Validators; | ||
mobilePhone(locale?: v.MobilePhoneLocale): Validators; | ||
ipAddress(version?: '4' | '6'): Validators; | ||
creditCard(): Validators; | ||
@@ -76,0 +76,0 @@ test(regex: RegExp): Validators; |
@@ -72,3 +72,3 @@ "use strict"; | ||
email(options) { | ||
return this.addValidator(({ value }, options) => (!helpers_1.exists(value) ? true : validator_1.default.isEmail(value.toString(), options)), 'is an invalid email.', options); | ||
return this.addValidator(({ value }, options) => !helpers_1.exists(value) ? true : validator_1.default.isEmail(value.toString(), options), 'is an invalid email.', options); | ||
} | ||
@@ -128,8 +128,6 @@ uuid(version = 4) { | ||
? true | ||
: typeof value === 'string' && validator_1.default.isLength(value, min, max), `is an invalid string or does not have a min length of ${min}${max ? ` and a max length of ${max}` : ''}.`, min, max); | ||
: typeof value === 'string' && validator_1.default.isLength(value, { min, max }), `is an invalid string or does not have a min length of ${min}${max ? ` and a max length of ${max}` : ''}.`, min, max); | ||
} | ||
base64() { | ||
return this.addValidator(({ value }) => !helpers_1.exists(value) | ||
? true | ||
: typeof value === 'string' && validator_1.default.isBase64(value), 'is an invalid base64 string.'); | ||
return this.addValidator(({ value }) => !helpers_1.exists(value) ? true : typeof value === 'string' && validator_1.default.isBase64(value), 'is an invalid base64 string.'); | ||
} | ||
@@ -186,5 +184,3 @@ boolean() { | ||
mobilePhone(locale = 'en-US') { | ||
return this.addValidator(({ value }, locale) => !helpers_1.exists(value) | ||
? true | ||
: validator_1.default.isMobilePhone(value.toString(), locale), `is an invalid phone number for ${locale}.`, locale); | ||
return this.addValidator(({ value }, locale) => !helpers_1.exists(value) ? true : validator_1.default.isMobilePhone(value.toString(), locale), `is an invalid phone number for ${locale}.`, locale); | ||
} | ||
@@ -191,0 +187,0 @@ ipAddress(version) { |
{ | ||
"name": "koa-fluent-validation", | ||
"version": "0.14.0", | ||
"version": "1.0.0", | ||
"main": "dist/index.js", | ||
@@ -28,4 +28,4 @@ "types": "dist/index.d.ts", | ||
"devDependencies": { | ||
"@types/jest": "^24.0.18", | ||
"@types/koa": "^2.0.49", | ||
"@types/jest": "^24.0.23", | ||
"@types/koa": "^2.11.0", | ||
"@types/koa-bodyparser": "^5.0.2", | ||
@@ -35,14 +35,14 @@ "@types/koa-router": "^7.0.42", | ||
"@types/lodash.set": "^4.3.6", | ||
"@types/validator": "^10.11.3", | ||
"@typescript-eslint/eslint-plugin": "^2.1.0", | ||
"@typescript-eslint/parser": "^2.1.0", | ||
"concurrently": "^4.1.2", | ||
"eslint": "^6.3.0", | ||
"eslint-config-prettier": "^6.2.0", | ||
"@types/validator": "^12.0.1", | ||
"@typescript-eslint/eslint-plugin": "^2.9.0", | ||
"@typescript-eslint/parser": "^2.9.0", | ||
"concurrently": "^5.0.0", | ||
"eslint": "^6.7.1", | ||
"eslint-config-prettier": "^6.7.0", | ||
"eslint-plugin-import": "^2.18.2", | ||
"jest": "^24.9.0", | ||
"prettier": "^1.18.2", | ||
"ts-jest": "^24.0.2", | ||
"tslint": "^5.19.0", | ||
"typescript": "^3.6.2" | ||
"prettier": "^1.19.1", | ||
"ts-jest": "^24.2.0", | ||
"tslint": "^5.20.1", | ||
"typescript": "^3.7.2" | ||
}, | ||
@@ -52,4 +52,4 @@ "dependencies": { | ||
"lodash.set": "^4.3.2", | ||
"validator": "^11.1.0" | ||
"validator": "^12.1.0" | ||
} | ||
} |
@@ -17,4 +17,4 @@ # koa-fluent-validation | ||
- NodeJS >= 7.6 | ||
- **For validating parameters, [koa-router](https://github.com/alexmingoia/koa-router)'s implementation is used with `ctx.params`.** | ||
- NodeJS >= 7.6 | ||
- **For validating parameters, [koa-router](https://github.com/alexmingoia/koa-router)'s implementation is used with `ctx.params`.** | ||
@@ -36,12 +36,12 @@ ## Usage | ||
app.use(async (ctx, next) => { | ||
try { | ||
await next(); | ||
} catch (e) { | ||
if (e.status === 422) { | ||
ctx.body = ctx.validationErrors; | ||
return; | ||
} | ||
try { | ||
await next(); | ||
} catch (e) { | ||
if (e.status === 422) { | ||
ctx.body = ctx.validationErrors; | ||
return; | ||
} | ||
// ... some other handling here etc | ||
} | ||
// ... some other handling here etc | ||
} | ||
}); | ||
@@ -51,23 +51,23 @@ | ||
app.use(async (ctx, next) => { | ||
if (ctx.method !== 'POST') { | ||
ctx.throw(404); | ||
return; | ||
} | ||
if (ctx.method !== 'POST') { | ||
ctx.throw(404); | ||
return; | ||
} | ||
ctx.validateBody( | ||
{ | ||
firstName: v() | ||
.required() | ||
.string(), | ||
lastName: v() | ||
.required() | ||
.string(), | ||
}, | ||
{ | ||
firstName: f().trim(), | ||
lastName: f().trim(), | ||
}, | ||
); | ||
ctx.validateBody( | ||
{ | ||
firstName: v() | ||
.required() | ||
.string(), | ||
lastName: v() | ||
.required() | ||
.string(), | ||
}, | ||
{ | ||
firstName: f().trim(), | ||
lastName: f().trim(), | ||
}, | ||
); | ||
// your code here | ||
// your code here | ||
}); | ||
@@ -84,2 +84,2 @@ | ||
- [] Filter Tests | ||
- [] Filter Tests |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
42439
576
+ Addedvalidator@12.2.0(transitive)
- Removedvalidator@11.1.0(transitive)
Updatedvalidator@^12.1.0