mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-11 10:59:55 +08:00
Add express-validator to not needed packages (#16633)
* Update notNeededPackages.json * Delete tsconfig.json * Delete index.d.ts * Delete express-validator-tests.ts
This commit is contained in:
@@ -132,6 +132,12 @@
|
||||
"sourceRepoURL": "https://github.com/primus/eventemitter3",
|
||||
"asOfVersion": "2.0.2"
|
||||
},
|
||||
{
|
||||
"libraryName": "express-validator",
|
||||
"typingsPackageName": "express-validator",
|
||||
"sourceRepoURL": "https://github.com/ctavan/express-validator",
|
||||
"asOfVersion": "3.0.0"
|
||||
},
|
||||
{
|
||||
"libraryName": "JSON-Patch",
|
||||
"typingsPackageName": "fast-json-patch",
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
/* Usage Example from https://github.com/ctavan/express-validator */
|
||||
|
||||
import util = require('util')
|
||||
import express = require('express')
|
||||
import expressValidator = require('express-validator')
|
||||
var app = express();
|
||||
|
||||
app.use(expressValidator());
|
||||
|
||||
app.post('/:urlparam', function(req: express.Request, res: express.Response) {
|
||||
|
||||
// checkBody only checks req.body; none of the other req parameters
|
||||
// Similarly checkParams only checks in req.params (URL params) and
|
||||
// checkQuery only checks req.query (GET params).
|
||||
req.checkBody('postparam', 'Invalid postparam').notEmpty().isInt();
|
||||
req.checkParams('urlparam', 'Invalid urlparam').isAlpha().matches(/test?/i).matches('test?', 'i');
|
||||
req.checkQuery('getparam', 'Invalid getparam').isInt();
|
||||
req.checkHeaders('testHeader', 'Invalid testHeader').isLowercase().isUppercase();
|
||||
req.checkFiles('testFiles', 'Invalid testFiles').isURL();
|
||||
|
||||
// OR assert can be used to check on all 3 types of params.
|
||||
// req.assert('postparam', 'Invalid postparam').notEmpty().isInt();
|
||||
// req.assert('urlparam', 'Invalid urlparam').isAlpha();
|
||||
// req.assert('getparam', 'Invalid getparam').isInt();
|
||||
|
||||
req.filter('postparam').toBoolean();
|
||||
req.sanitize('postparam').blacklist('t').blacklist(['<script', '</script>']).whitelist('hello').whitelist(['h', 'e', 'l']);
|
||||
req.sanitizeBody('postvar').trim().stripLow().escape();
|
||||
req.sanitizeQuery('queryvar').toDate();
|
||||
req.sanitizeParams('urlparam').toFloat().toInt().toInt(10);
|
||||
req.sanitizeHeaders('header').normalizeEmail();
|
||||
|
||||
|
||||
var errors = req.validationErrors();
|
||||
var mappedErrors = req.validationErrors(true);
|
||||
|
||||
if (errors) {
|
||||
res.status(400).send('There have been validation errors: ' + util.inspect(errors));
|
||||
return;
|
||||
}
|
||||
res.json({
|
||||
urlparam: req.param('urlparam'),
|
||||
getparam: req.param('getparam'),
|
||||
postparam: req.param('postparam')
|
||||
});
|
||||
});
|
||||
|
||||
app.listen(8888);
|
||||
244
types/express-validator/index.d.ts
vendored
244
types/express-validator/index.d.ts
vendored
@@ -1,244 +0,0 @@
|
||||
// Type definitions for express-validator 2.20.4
|
||||
// Project: https://github.com/ctavan/express-validator
|
||||
// Definitions by: Nathan Ridley <https://github.com/axefrog/>, Jonathan Häberle <http://dreampulse.de>, Peter Harris <https://github.com/codeanimal/>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="express" />
|
||||
|
||||
// Add RequestValidation Interface on to Express's Request Interface.
|
||||
declare namespace Express {
|
||||
interface Request extends ExpressValidator.RequestValidation {}
|
||||
}
|
||||
|
||||
// External express-validator module.
|
||||
declare module "express-validator" {
|
||||
import express = require('express');
|
||||
|
||||
/**
|
||||
*
|
||||
* @middlewareOptions see: https://github.com/ctavan/express-validator#middleware-options
|
||||
*/
|
||||
function ExpressValidator(middlewareOptions?:any):express.RequestHandler;
|
||||
|
||||
export = ExpressValidator;
|
||||
}
|
||||
|
||||
// Internal Module.
|
||||
declare namespace ExpressValidator {
|
||||
|
||||
export interface ValidationError {
|
||||
msg: string;
|
||||
param: string;
|
||||
}
|
||||
|
||||
interface ValidatorFunction { (item: string | {}, message?: string): Validator; }
|
||||
interface ValidatorExtraFunction extends ValidatorFunction { (matchIndex: number, message?: string): Validator; }
|
||||
interface SanitizerFunction { (item: string): Sanitizer; }
|
||||
interface Dictionary<T> { [key: string]: T; }
|
||||
|
||||
export interface RequestValidation {
|
||||
assert: ValidatorExtraFunction;
|
||||
validate: ValidatorExtraFunction;
|
||||
check: ValidatorExtraFunction;
|
||||
checkBody: ValidatorFunction;
|
||||
checkFiles: ValidatorFunction;
|
||||
checkHeaders: ValidatorFunction;
|
||||
checkParams: ValidatorFunction;
|
||||
checkQuery: ValidatorFunction;
|
||||
|
||||
filter: SanitizerFunction;
|
||||
sanitize: SanitizerFunction;
|
||||
sanitizeBody: SanitizerFunction;
|
||||
sanitizeQuery: SanitizerFunction;
|
||||
sanitizeParams: SanitizerFunction;
|
||||
sanitizeHeaders: SanitizerFunction;
|
||||
|
||||
onValidationError(errback: (msg: string) => void): void;
|
||||
validationErrors(mapped?: boolean): Dictionary<MappedError> | MappedError[];
|
||||
validationErrors<T>(mapped?: boolean): Dictionary<T> | T[];
|
||||
asyncValidationErrors(mapped?: boolean): Promise<MappedError[] | Dictionary<MappedError>>;
|
||||
asyncValidationErrors<T>(mapped?: boolean): Promise<T[] | Dictionary<T>>;
|
||||
}
|
||||
|
||||
export interface Validator {
|
||||
/**
|
||||
* Alias for regex()
|
||||
*/
|
||||
is(): Validator;
|
||||
/**
|
||||
* Alias for notRegex()
|
||||
*/
|
||||
not(): Validator;
|
||||
isEmail(options?:{}): Validator;
|
||||
/**
|
||||
* Accepts http, https, ftp
|
||||
*/
|
||||
isURL(): Validator;
|
||||
isFQDN(options?: MinMaxOptions): Validator;
|
||||
|
||||
/**
|
||||
* Combines isIPv4 and isIPv6
|
||||
*/
|
||||
isIP(): Validator;
|
||||
isIPv4(): Validator;
|
||||
isIPv6(): Validator;
|
||||
isMACAddress(): Validator;
|
||||
isISBN(version?: number): Validator;
|
||||
isISIN(): Validator;
|
||||
isISO8601(): Validator;
|
||||
isMobilePhone(locale: string): Validator;
|
||||
isMongoId(): Validator;
|
||||
isMultibyte(): Validator;
|
||||
isAlpha(locale?: string): Validator;
|
||||
isAlphanumeric(locale?: string): Validator;
|
||||
isAscii(): Validator;
|
||||
isBase64(): Validator;
|
||||
isBoolean(): Validator;
|
||||
isByteLength(options: MinMaxOptions): Validator;
|
||||
isCurrency(options: {}): Validator;
|
||||
isDataURI(): Validator;
|
||||
isDivisibleBy(num: number): Validator;
|
||||
isNumeric(): Validator;
|
||||
isHexadecimal(): Validator;
|
||||
/**
|
||||
* Accepts valid hexcolors with or without # prefix
|
||||
*/
|
||||
isHexColor(): Validator;
|
||||
/**
|
||||
* isNumeric accepts zero padded numbers, e.g. '001', isInt doesn't
|
||||
*/
|
||||
isInt(options?: MinMaxOptions): Validator;
|
||||
isLowercase(): Validator;
|
||||
isUppercase(): Validator;
|
||||
isDecimal(): Validator;
|
||||
/**
|
||||
* Alias for isDecimal
|
||||
*/
|
||||
isFloat(): Validator;
|
||||
isFullWidth(): Validator;
|
||||
isHalfWidth(): Validator;
|
||||
isVariableWidth(): Validator;
|
||||
/**
|
||||
* Check if length is 0
|
||||
*/
|
||||
isNull(): Validator;
|
||||
/**
|
||||
* Not just whitespace (input.trim().length !== 0)
|
||||
*/
|
||||
notEmpty(): Validator;
|
||||
equals(equals:any): Validator;
|
||||
contains(str:string): Validator;
|
||||
|
||||
/**
|
||||
* Usage: matches(/[a-z]/i) or matches('[a-z]','i')
|
||||
*/
|
||||
matches(pattern:string, modifiers?:string): Validator;
|
||||
matches(pattern: RegExp): Validator;
|
||||
|
||||
/**
|
||||
* max is optional
|
||||
*/
|
||||
len(min:number, max?:number): Validator;
|
||||
/**
|
||||
* Version can be 3, 4 or 5 or empty, see http://en.wikipedia.org/wiki/Universally_unique_identifier
|
||||
*/
|
||||
isUUID(version?:number): Validator;
|
||||
/**
|
||||
* Alias for isUUID(3)
|
||||
*/
|
||||
isUUIDv3(): Validator;
|
||||
/**
|
||||
* Alias for isUUID(4)
|
||||
*/
|
||||
isUUIDv4(): Validator;
|
||||
/**
|
||||
* Alias for isUUID(5)
|
||||
*/
|
||||
isUUIDv5(): Validator;
|
||||
/**
|
||||
* Uses Date.parse() - regex is probably a better choice
|
||||
*/
|
||||
isDate(): Validator;
|
||||
/**
|
||||
* Argument is optional and defaults to today. Comparison is non-inclusive
|
||||
*/
|
||||
isAfter(date?:Date): Validator;
|
||||
/**
|
||||
* Argument is optional and defaults to today. Comparison is non-inclusive
|
||||
*/
|
||||
isBefore(date?:Date): Validator;
|
||||
isIn(options:string): Validator;
|
||||
isIn(options:string[]): Validator;
|
||||
notIn(options:string): Validator;
|
||||
notIn(options:string[]): Validator;
|
||||
max(val:string): Validator;
|
||||
min(val:string): Validator;
|
||||
isJSON(): Validator;
|
||||
isLength(options: MinMaxOptions): Validator;
|
||||
isWhitelisted(chars: string): Validator;
|
||||
/**
|
||||
* Will work against Visa, MasterCard, American Express, Discover, Diners Club, and JCB card numbering formats
|
||||
*/
|
||||
isCreditCard(): Validator;
|
||||
/**
|
||||
* Check an input only when the input exists
|
||||
*/
|
||||
isSurrogatePar(): Validator;
|
||||
|
||||
optional(options?: { checkFalsy?: boolean }): Validator;
|
||||
withMessage(message: string): Validator;
|
||||
}
|
||||
|
||||
interface Sanitizer {
|
||||
/**
|
||||
* Trim optional `chars`, default is to trim whitespace (\r\n\t )
|
||||
*/
|
||||
trim(...chars:string[]): Sanitizer;
|
||||
ltrim(...chars:string[]): Sanitizer;
|
||||
rtrim(...chars:string[]): Sanitizer;
|
||||
stripLow(keep_new_lines?: boolean): Sanitizer;
|
||||
toFloat(): Sanitizer;
|
||||
toInt(radix?: number): Sanitizer;
|
||||
/**
|
||||
* True unless str = '0', 'false', or str.length == 0. In strict mode only '1' and 'true' return true.
|
||||
*/
|
||||
toBoolean(strict?: boolean): Sanitizer;
|
||||
|
||||
/**
|
||||
* Convert the input string to a date, or null if the input is not a date.
|
||||
*/
|
||||
toDate(): Sanitizer;
|
||||
|
||||
/**
|
||||
* Escape &, <, >, and "
|
||||
*/
|
||||
escape(): Sanitizer;
|
||||
|
||||
/**
|
||||
* Replaces HTML encoded entities with <, >, &, ', " and /.
|
||||
*/
|
||||
unescape(): Sanitizer;
|
||||
|
||||
blacklist(chars: string): Sanitizer;
|
||||
blacklist(chars: string[]): Sanitizer;
|
||||
whitelist(chars: string): Sanitizer;
|
||||
whitelist(chars: string[]): Sanitizer;
|
||||
|
||||
normalizeEmail(options?: { lowercase?: boolean; remove_dots?: boolean; remove_extensions?: boolean }): Sanitizer;
|
||||
|
||||
/**
|
||||
* !!! XSS sanitization was removed from the library (see: https://github.com/chriso/validator.js#xss-sanitization)
|
||||
*/
|
||||
}
|
||||
|
||||
interface MappedError {
|
||||
param: string;
|
||||
msg: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
interface MinMaxOptions {
|
||||
min?: number;
|
||||
max?: number;
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": false,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"express-validator-tests.ts"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user