Add type definitions for the connect-slashes middleware

This commit is contained in:
Sam Herrmann 2015-04-19 09:28:42 -04:00
parent e57df787f4
commit 266fc895f8
2 changed files with 93 additions and 0 deletions

View File

@ -0,0 +1,53 @@
/// <reference path="../express/express.d.ts"/>
import express = require('express');
import slashes = require('connect-slashes');
var app = express();
// Using default settings...
app.use(slashes());
// Remove slashes instead of adding them...
app.use(slashes(false));
// With additional options defined inline...
app.use(slashes(true, {
base: '/blog',
code: 302,
headers: {
'Cache-Control': 'public',
'Accpet': 'application/json'
}
}));
// Defining an options object and referencing
// it in the constructor...
var options: slashes.Options = {
base: '/blog',
code: 302,
headers: {
'Cache-Control': 'public',
'Accpet': 'application/json'
}
};
app.use(slashes(true, options));
// Defining an options object with only
// some properties...
var options: slashes.Options = {
base: '/blog'
}
var options: slashes.Options = {
code: 302
}
var options: slashes.Options = {
headers: {
'Cache-Control': 'public',
'Accpet': 'application/json'
}
}

40
connect-slashes/connect-slashes.d.ts vendored Normal file
View File

@ -0,0 +1,40 @@
// Type definitions for connect-slashes
// Project: https://github.com/avinoamr/connect-slashes
// Definitions by: Sam Herrmann <https://github.com/samherrmann>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/* =================== USAGE ===================
import express = require('express');
import slashes = require('connect-slashes');
var app = express();
app.use(slashes());
=============================================== */
/// <reference path="../express/express.d.ts" />
declare module "connect-slashes" {
import express = require('express');
/**
* @see https://github.com/avinoamr/connect-slashes#usage
*/
function slashes (addTrailingSlashes?: boolean, options?: slashes.Options): express.RequestHandler;
module slashes {
/**
* Additional settings
* @see https://github.com/avinoamr/connect-slashes#additional-settings
*/
interface Options {
base?: string;
code?: number;
headers?: {[field: string]: string};
}
}
export = slashes;
}