mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-01 09:01:45 +08:00
Updated Validator API to v5.7.0 (#11209)
This commit is contained in:
committed by
Masahiro Wakame
parent
e9bd268321
commit
2b69abecc8
@@ -4,9 +4,9 @@ import * as validator from 'validator';
|
||||
|
||||
let any: any;
|
||||
|
||||
/**************
|
||||
* Validators *
|
||||
**************/
|
||||
// **************
|
||||
// * Validators *
|
||||
// **************
|
||||
|
||||
{
|
||||
let result: boolean;
|
||||
@@ -16,7 +16,7 @@ let any: any;
|
||||
result = validator.equals('sample', 'sample');
|
||||
|
||||
result = validator.isAfter('sample');
|
||||
result = validator.isAfter('sample', new Date());
|
||||
result = validator.isAfter('sample', new Date().toString());
|
||||
|
||||
result = validator.isAlpha('sample');
|
||||
|
||||
@@ -27,7 +27,7 @@ let any: any;
|
||||
result = validator.isBase64('sample');
|
||||
|
||||
result = validator.isBefore('sample');
|
||||
result = validator.isBefore('sample', new Date());
|
||||
result = validator.isBefore('sample', new Date().toString());
|
||||
|
||||
result = validator.isBoolean('sample');
|
||||
|
||||
@@ -42,6 +42,8 @@ let any: any;
|
||||
result = validator.isCurrency('sample');
|
||||
result = validator.isCurrency('sample', isCurrencyOptions);
|
||||
|
||||
result = validator.isDataURI('sample');
|
||||
|
||||
result = validator.isDate('sample');
|
||||
|
||||
result = validator.isDecimal('sample');
|
||||
@@ -95,6 +97,8 @@ let any: any;
|
||||
|
||||
result = validator.isMACAddress('sample');
|
||||
|
||||
result = validator.isMD5('sample');
|
||||
|
||||
result = validator.isMobilePhone('sample', 'en-US');
|
||||
|
||||
result = validator.isMongoId('sample');
|
||||
@@ -113,6 +117,7 @@ let any: any;
|
||||
|
||||
result = validator.isUUID('sample');
|
||||
result = validator.isUUID('sample', 5);
|
||||
result = validator.isUUID('sample', 'all');
|
||||
|
||||
result = validator.isUppercase('sample');
|
||||
|
||||
@@ -125,9 +130,9 @@ let any: any;
|
||||
result = validator.matches('foobar', 'foo', 'i');
|
||||
}
|
||||
|
||||
/**************
|
||||
* Sanitizers *
|
||||
**************/
|
||||
// **************
|
||||
// * Sanitizers *
|
||||
// **************
|
||||
|
||||
{
|
||||
let result: string;
|
||||
@@ -136,6 +141,8 @@ let any: any;
|
||||
|
||||
result = validator.escape('sample');
|
||||
|
||||
result = validator.unescape('sample');
|
||||
|
||||
result = validator.ltrim('sample');
|
||||
result = validator.ltrim('sample', ' ');
|
||||
|
||||
@@ -175,16 +182,14 @@ let any: any;
|
||||
{
|
||||
let result: string;
|
||||
|
||||
result = validator.toString(any);
|
||||
|
||||
result = validator.trim('sample');
|
||||
result = validator.trim('sample', ' ');
|
||||
|
||||
result = validator.whitelist('sample', 'abc');
|
||||
}
|
||||
|
||||
/**************
|
||||
* Extensions *
|
||||
**************/
|
||||
// **************
|
||||
// * Extensions *
|
||||
// **************
|
||||
|
||||
validator.extend<(str: string, options: {}) => boolean>('isTest', (str: any, options: {}) => !str);
|
||||
|
||||
59
validator/validator.d.ts
vendored
59
validator/validator.d.ts
vendored
@@ -1,14 +1,14 @@
|
||||
// Type definitions for validator.js v4.5.1
|
||||
// Type definitions for validator.js v5.7.0
|
||||
// Project: https://github.com/chriso/validator.js
|
||||
// Definitions by: tgfjt <https://github.com/tgfjt>, Ilya Mochalov <https://github.com/chrootsu>
|
||||
// Definitions by: tgfjt <https://github.com/tgfjt>, Ilya Mochalov <https://github.com/chrootsu>, Ayman Nedjmeddine <https://github.com/IOAyman>, Louy Alakkad <https://github.com/louy>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare namespace ValidatorJS {
|
||||
interface ValidatorStatic {
|
||||
|
||||
/**************
|
||||
* Validators *
|
||||
**************/
|
||||
// **************
|
||||
// * Validators *
|
||||
// **************
|
||||
|
||||
// check if the string contains the seed.
|
||||
contains(str: string, elem: any): boolean;
|
||||
@@ -17,7 +17,7 @@ declare namespace ValidatorJS {
|
||||
equals(str: string, comparison: any): boolean;
|
||||
|
||||
// check if the string is a date that's after the specified date (defaults to now).
|
||||
isAfter(str: string, date?: Date): boolean;
|
||||
isAfter(str: string, date?: string): boolean;
|
||||
|
||||
// check if the string contains only letters (a-zA-Z).
|
||||
isAlpha(str: string): boolean;
|
||||
@@ -32,7 +32,7 @@ declare namespace ValidatorJS {
|
||||
isBase64(str: string): boolean;
|
||||
|
||||
// check if the string is a date that's before the specified date.
|
||||
isBefore(str: string, date?: Date): boolean;
|
||||
isBefore(str: string, date?: string): boolean;
|
||||
|
||||
// check if a string is a boolean.
|
||||
isBoolean(str: string): boolean;
|
||||
@@ -47,6 +47,9 @@ declare namespace ValidatorJS {
|
||||
// check if the string is a valid currency amount.
|
||||
isCurrency(str: string, options?: IsCurrencyOptions): boolean;
|
||||
|
||||
// check if the string is a data uri format (https://developer.mozilla.org/en-US/docs/Web/HTTP/data_URIs)
|
||||
isDataURI(str: string): boolean;
|
||||
|
||||
// check if the string is a date.
|
||||
isDate(str: string): boolean;
|
||||
|
||||
@@ -110,8 +113,14 @@ declare namespace ValidatorJS {
|
||||
// check if the string is a MAC address.
|
||||
isMACAddress(str: string): boolean;
|
||||
|
||||
// check if the string is a mobile phone number, (locale is one of ['zh-CN', 'zh-TW', 'en-ZA', 'en-AU', 'en-HK',
|
||||
// 'pt-PT', 'fr-FR', 'el-GR', 'en-GB', 'en-US', 'en-ZM', 'ru-RU', 'nb-NO', 'nn-NO', 'vi-VN', 'en-NZ', 'en-IN']).
|
||||
// check if the string is a MD5 hash.
|
||||
isMD5(str: string): boolean;
|
||||
|
||||
// check if the string is a mobile phone number, (locale is one of
|
||||
// ['ar-DZ', 'ar-SA', 'ar-SY', 'cs-CZ', 'de-DE', 'da-DK', 'el-GR', 'en-AU', 'en-GB', 'en-HK',
|
||||
// 'en-IN', 'en-NZ', 'en-US', 'en-CA', 'en-ZA', 'en-ZM', 'es-ES', 'fi-FI', 'fr-FR', 'hu-HU',
|
||||
// 'it-IT', 'ja-JP', 'ms-MY', 'nb-NO', 'nn-NO', 'pl-PL', 'pt-PT', 'ru-RU', 'sr-RS', 'tr-TR',
|
||||
// 'vi-VN', 'zh-CN', 'zh-TW']).
|
||||
isMobilePhone(str: string, locale: string): boolean;
|
||||
|
||||
// check if the string is a valid hex-encoded representation of a MongoDB ObjectId
|
||||
@@ -133,8 +142,8 @@ declare namespace ValidatorJS {
|
||||
// check if the string is an URL.
|
||||
isURL(str: string, options?: IsURLOptions): boolean;
|
||||
|
||||
// check if the string is a UUID (version 3, 4 or 5).
|
||||
isUUID(str: string, version?: number): boolean;
|
||||
// check if the string is a UUID. Must be one of ['3', '4', '5', 'all'], default is all.
|
||||
isUUID(str: string, version?: string|number): boolean;
|
||||
|
||||
// check if the string is uppercase.
|
||||
isUppercase(str: string): boolean;
|
||||
@@ -146,11 +155,11 @@ declare namespace ValidatorJS {
|
||||
isWhitelisted(str: string, chars: string|string[]): boolean;
|
||||
|
||||
// check if string matches the pattern.
|
||||
matches(str: string, pattern: any, modifiers?: string): boolean;
|
||||
matches(str: string, pattern: RegExp|string, modifiers?: string): boolean;
|
||||
|
||||
/**************
|
||||
* Sanitizers *
|
||||
**************/
|
||||
// **************
|
||||
// * Sanitizers *
|
||||
// **************
|
||||
|
||||
// remove characters that appear in the blacklist. The characters are used in a RegExp and so you will need
|
||||
// to escape some chars, e.g. blacklist(input, '\\[\\]').
|
||||
@@ -159,6 +168,9 @@ declare namespace ValidatorJS {
|
||||
// replace <, >, &, ', " and / with HTML entities.
|
||||
escape(input: string): string;
|
||||
|
||||
// replaces HTML encoded entities with <, >, &, ', " and /.
|
||||
unescape(input: string): string;
|
||||
|
||||
// trim characters from the left-side of the input.
|
||||
ltrim(input: any, chars?: string): string;
|
||||
|
||||
@@ -185,9 +197,6 @@ declare namespace ValidatorJS {
|
||||
// convert the input to an integer, or NaN if the input is not an integer.
|
||||
toInt(input: any, radix?: number): number; // number or NaN
|
||||
|
||||
// convert the input to a string.
|
||||
toString(input: any): string;
|
||||
|
||||
// trim characters (whitespace by default) from both sides of the input.
|
||||
trim(input: any, chars?: string): string;
|
||||
|
||||
@@ -195,9 +204,9 @@ declare namespace ValidatorJS {
|
||||
// need to escape some chars, e.g. whitelist(input, '\\[\\]').
|
||||
whitelist(input: string, chars: string): string;
|
||||
|
||||
/**************
|
||||
* Extensions *
|
||||
**************/
|
||||
// **************
|
||||
// * Extensions *
|
||||
// **************
|
||||
|
||||
// add your own validators.
|
||||
// Note: that the first argument will be automatically coerced to a string.
|
||||
@@ -263,10 +272,11 @@ declare namespace ValidatorJS {
|
||||
protocols?: string[];
|
||||
require_tld?: boolean;
|
||||
require_protocol?: boolean;
|
||||
require_host: boolean;
|
||||
require_valid_protocol?: boolean;
|
||||
allow_underscores?: boolean;
|
||||
host_whitelist?: boolean;
|
||||
host_blacklist?: boolean;
|
||||
host_whitelist?: (string|RegExp)[];
|
||||
host_blacklist?: (string|RegExp)[];
|
||||
allow_trailing_dot?: boolean;
|
||||
allow_protocol_relative_urls?: boolean;
|
||||
}
|
||||
@@ -280,8 +290,7 @@ declare namespace ValidatorJS {
|
||||
}
|
||||
|
||||
declare module "validator" {
|
||||
let validator: ValidatorJS.ValidatorStatic;
|
||||
namespace validator {}
|
||||
const validator: ValidatorJS.ValidatorStatic;
|
||||
export = validator;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user