From f9cc9a72d9df4ace8933f23eec227197b0cd8a31 Mon Sep 17 00:00:00 2001 From: Kacper Polak Date: Fri, 2 Jun 2017 15:53:55 +0200 Subject: [PATCH] Add express-validator to not needed packages (#16633) * Update notNeededPackages.json * Delete tsconfig.json * Delete index.d.ts * Delete express-validator-tests.ts --- notNeededPackages.json | 6 + .../express-validator-tests.ts | 48 ---- types/express-validator/index.d.ts | 244 ------------------ types/express-validator/tsconfig.json | 22 -- 4 files changed, 6 insertions(+), 314 deletions(-) delete mode 100644 types/express-validator/express-validator-tests.ts delete mode 100644 types/express-validator/index.d.ts delete mode 100644 types/express-validator/tsconfig.json diff --git a/notNeededPackages.json b/notNeededPackages.json index 345e20679f..edeae2fa7e 100644 --- a/notNeededPackages.json +++ b/notNeededPackages.json @@ -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", diff --git a/types/express-validator/express-validator-tests.ts b/types/express-validator/express-validator-tests.ts deleted file mode 100644 index 9c374d9948..0000000000 --- a/types/express-validator/express-validator-tests.ts +++ /dev/null @@ -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(['']).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); diff --git a/types/express-validator/index.d.ts b/types/express-validator/index.d.ts deleted file mode 100644 index 0416b4db44..0000000000 --- a/types/express-validator/index.d.ts +++ /dev/null @@ -1,244 +0,0 @@ -// Type definitions for express-validator 2.20.4 -// Project: https://github.com/ctavan/express-validator -// Definitions by: Nathan Ridley , Jonathan Häberle , Peter Harris -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -/// - -// 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 { [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[]; - validationErrors(mapped?: boolean): Dictionary | T[]; - asyncValidationErrors(mapped?: boolean): Promise>; - asyncValidationErrors(mapped?: boolean): Promise>; - } - - 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; - } -} diff --git a/types/express-validator/tsconfig.json b/types/express-validator/tsconfig.json deleted file mode 100644 index cd9c9145d7..0000000000 --- a/types/express-validator/tsconfig.json +++ /dev/null @@ -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" - ] -} \ No newline at end of file