Skip to content

Commit

Permalink
Adding express-mongo-sanitize typings (DefinitelyTyped#20463)
Browse files Browse the repository at this point in the history
  • Loading branch information
EricByers authored and weswigham committed Oct 10, 2017
1 parent a97f575 commit 39a7427
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
26 changes: 26 additions & 0 deletions types/express-mongo-sanitize/express-mongo-sanitize-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import * as express from 'express';
import * as mongoSanitize from 'express-mongo-sanitize';

const app: express.Express = express();

app.use(mongoSanitize());

app.use(mongoSanitize({
replaceWith: '_'
}));

interface TestPayload {
foo: string;
}

const testPayload: TestPayload = {
foo: 'bar'
};

const sanitize1: TestPayload = mongoSanitize.sanitize(testPayload);

const sanitize2: TestPayload = mongoSanitize.sanitize(testPayload, {
replaceWith: '_'
});

const isCorrect: boolean = mongoSanitize.has(testPayload);
19 changes: 19 additions & 0 deletions types/express-mongo-sanitize/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Type definitions for express-mongo-sanitize 1.3
// Project: https://github.com/fiznool/express-mongo-sanitize#readme
// Definitions by: Eric Byers <https://github.com/ericbyers>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

import express = require('express');

interface MongoSanitizeOptions {
replaceWith: any;
}

declare namespace expressMongoSanitize {
function sanitize<T>(payload: T, options?: MongoSanitizeOptions): T;
function has(payload: any): boolean;
}

declare function expressMongoSanitize(options?: MongoSanitizeOptions): (req: express.Request, res: express.Response, next: express.NextFunction) => void;

export = expressMongoSanitize;
23 changes: 23 additions & 0 deletions types/express-mongo-sanitize/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"strictFunctionTypes": true
},
"files": [
"index.d.ts",
"express-mongo-sanitize-tests.ts"
]
}
1 change: 1 addition & 0 deletions types/express-mongo-sanitize/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }

0 comments on commit 39a7427

Please sign in to comment.