extensible-validator
Advanced tools
Comparing version 2.2.6 to 2.2.7
@@ -9,5 +9,6 @@ import { Schema } from './Schema'; | ||
private _castFormat?; | ||
private _utc; | ||
constructor(); | ||
protected typeTest: (this: DateSchema<Date>, value: any) => boolean; | ||
format(format: string): this; | ||
format(format: string, utc?: boolean): this; | ||
castFormat(format: string): DateSchema<string>; | ||
@@ -14,0 +15,0 @@ cast(value: any): TResult; |
@@ -14,2 +14,3 @@ "use strict"; | ||
this._parseFormat = 'YYYY-MM-DDTHH:mm:ss.SSSZ'; | ||
this._utc = true; | ||
this.typeTest = function (value) { | ||
@@ -25,6 +26,7 @@ return (value === '' || | ||
} | ||
format(format) { | ||
format(format, utc = true) { | ||
return this.clone(schema => { | ||
schema._parseFormat = format; | ||
schema._messages.type = schema._messages.format(format); | ||
schema._utc = utc; | ||
}); | ||
@@ -41,6 +43,7 @@ } | ||
} | ||
const m = this._utc ? moment.utc : moment; | ||
if (this._castFormat) { | ||
return (value instanceof Date | ||
? moment(value) | ||
: moment(value, this._parseFormat)).format(this._castFormat); | ||
? m(value) | ||
: m(value, this._parseFormat)).format(this._castFormat); | ||
} | ||
@@ -50,3 +53,3 @@ else { | ||
? value | ||
: moment(value, this._parseFormat).toDate()); | ||
: m(value, this._parseFormat).toDate()); | ||
} | ||
@@ -53,0 +56,0 @@ } |
@@ -8,3 +8,3 @@ import { Schema } from './Schema'; | ||
/** | ||
* Requires the valufe to be a number, or a string representing a number. | ||
* Requires the value to be a number, or a string representing a number. | ||
*/ | ||
@@ -11,0 +11,0 @@ export declare class NumberSchema extends Schema<number | undefined | null, typeof numberMessages> { |
@@ -15,3 +15,3 @@ "use strict"; | ||
/** | ||
* Requires the valufe to be a number, or a string representing a number. | ||
* Requires the value to be a number, or a string representing a number. | ||
*/ | ||
@@ -18,0 +18,0 @@ class NumberSchema extends Schema_1.Schema { |
{ | ||
"name": "extensible-validator", | ||
"version": "2.2.6", | ||
"version": "2.2.7", | ||
"description": "Typescript-friendly and extensible object and value validation", | ||
@@ -13,3 +13,3 @@ "main": "dist/index.js", | ||
}, | ||
"author": "Stewart Mackenzie-Leigh", | ||
"author": "Stewart Everett", | ||
"license": "ISC", | ||
@@ -16,0 +16,0 @@ "devDependencies": { |
# extensible-validator | ||
Typescript-friendly and extensible object and value validation. It looks mostly like | ||
[joi](https://www.npmjs.com/package/joi), | ||
but is more extensible and auto-complete friendly. | ||
Typescript-friendly and extensible object and value validation. | ||
@@ -7,0 +5,0 @@ Also, unlike like other libraries where `validate` throws an error, I just return an array of errors, which could be empty. Throwing an error in the case of bad input from a function which exists to consider the case of bad input is ugly as hell. |
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
38349
679
62