Update definitions for "i18next-express-middleware", "i18next" and

"connect-timeout".
Remove "tscparams" file for "acc-wizard".
This commit is contained in:
Cyril Schumacher
2016-01-07 16:23:33 +01:00
parent 7e3bc700b3
commit 5f2a5d25bb
6 changed files with 132 additions and 21 deletions

View File

@@ -1 +0,0 @@
--noImplicitAny

View File

@@ -3,10 +3,10 @@
/// <reference path="../cookie-parser/cookie-parser.d.ts" />
/// <reference path="../express/express.d.ts" />
import express = require("express");
import timeout = require("connect-timeout");
import bodyParser = require("body-parser");
import cookieParser = require("cookie-parser");
import * as express from "express";
import timeout from "connect-timeout";
import * as bodyParser from "body-parser";
import * as cookieParser from "cookie-parser";
// example of using this top-level; note the use of haltOnTimedout
// after every middleware; it will stop the request flow on a timeout

View File

@@ -23,6 +23,10 @@ declare module Express {
declare module "connect-timeout" {
import express = require("express");
/**
* @summary Interface for timeout options.
* @interface
*/
interface TimeoutOptions extends Object {
/**
* @summary Controls if this module will "respond" in the form of forwarding an error.
@@ -31,6 +35,5 @@ declare module "connect-timeout" {
respond: boolean;
}
function timeout(timeout: string, options?: TimeoutOptions): express.RequestHandler;
export = timeout;
export default function timeout(timeout: string, options?: TimeoutOptions): express.RequestHandler;
}

View File

@@ -1,5 +1,48 @@
///<reference path="../i18next/i18next.d.ts"/>
///<reference path="i18next-express-middleware.d.ts"/>
//import express = require("express");
//import i18next = require("i18next");
import * as express from "express";
import * as i18next from "i18next";
import middleware = require("i18next-express-middleware");
function requestObjectTest() {
var i18nextOptions = {};
i18next
.use(middleware.LanguageDetector)
.init(i18nextOptions);
var app = express();
app.use(middleware.handle(i18next, {
ignoreRoutes: ["/foo"],
removeLngFromUrl: false
}));
}
function detectorOptionsTest() {
var options = {
// order and from where user language should be detected
order: [/*'path', 'session', */ 'querystring', 'cookie', 'header'],
// keys or params to lookup language from
lookupQuerystring: 'lng',
lookupCookie: 'i18next',
lookupSession: 'lng',
lookupFromPathIndex: 0,
// cache user language
caches: false, // ['cookie']
// optional expire and domain for set cookie
cookieExpirationDate: new Date(),
cookieDomain: 'myDomain'
};
i18next
.use(middleware.LanguageDetector)
.init({
detection: options
});
var lngDetector = new middleware.LanguageDetector(null, options);
lngDetector.init(options);
}

View File

@@ -4,30 +4,93 @@
// Definitions: https://github.com/borisyankov/DefinitelyTyped
///<reference path="../express/express.d.ts"/>
///<reference path="../i18next/i18next.d.ts"/>
/**
* @summary Interface for Language detector options.
* @interface
*/
interface LanguageDetectorOptions {
caches?: boolean;
cookieDomain?: string;
cookieExpirationDate?: Date;
lookupCookie?: string;
lookupFromPathIndex?: number;
lookupQuerystring?: string;
lookupSession?: string;
order?: Array<string>;
}
declare module "i18next-express-middleware" {
import express = require("express");
import i18next = require("i18next");
/**
* @summary Interface for middleware to use i18next in express.js.
* @interface
*/
export interface i18nextExpressMiddleware {
LanguageDetector(): express.Handler;
missingKeyHandler(): express.Handler;
}
interface LanguageDetectorOptions {
caches: boolean;
cookieDomain: string;
cookieExpirationDate: Date;
lookupCookie: string;
lookupFromPathIndex: number;
lookupQuerystring: string;
lookupSession: string;
order: Array<string>;
/**
* @summary Interface for own detection functionality.
*/
export interface i18nextCustomDetection {
name: string;
lookup: (req: express.Request, res: express.Response, options?: Object) => void;
cacheUserLanguage: (req: express.Request, res: express.Response, lng?: any, options?: Object) => void;
}
/**
* @summary Detects user language from current request.
* @class
*/
export class LanguageDetector {
/**
* @summary Constructor.
* @constructor
* @param {any} services The services.
* @param {Object} options The options.
* @param {Object} allOptions The all options.
*/
constructor(services?: any, options?: Object, allOptions?: Object);
addDetector(detector: any): void;
/**
* @summary Adds detector.
* @param {i18nextCustomDetection} detector The detector to add.
*/
addDetector(detector: i18nextCustomDetection): void;
// NOTE: add documentation
cacheUserLanguage(req: express.Request, res: express.Response, detectionOrder: any): void;
/**
* @summary Detects the language.
* @param {Request} req The HTTP request.
* @param {Response} res The HTTP response.
* @param {detectionOrder} detectionOrder The detection order.
*/
detect(req: express.Request, res: express.Response, detectionOrder: any): void;
/**
* @summary Initializes class.
* @param {any} services The services.
* @param {Object} options The options.
* @param {Object} allOptions The all options.
*/
init(services: any, options?: Object, allOptions?: Object): void;
}
export function getResourcesHandler(i18next: I18nextStatic, options: Object): express.Handler;
export function handle(i18next: I18nextStatic, options?: Object): express.Handler;
/**
* @summary Gets handler for missing key.
* @param {I18nextStatic} i18next The i18next.
* @param {Object} options The options.
* @return {express.Handler} The express handler.
*/
export function missingKeyHandler(i18next: I18nextStatic, options: Object): express.Handler;
}

View File

@@ -1,11 +1,13 @@
// Type definitions for i18next v1.5.10
// Type definitions for i18next v2.0.17
// Project: http://i18next.com
// Definitions by: Maarten Docter <https://github.com/mdocter>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
// Sources: https://github.com/jamuhl/i18next/
/// <reference path="../express/express.d.ts" />
/// <reference path="../jquery/jquery.d.ts" />
/// <reference path="../i18next-express-middleware/i18next-express-middleware.d.ts" />
interface IResourceStore {
[language: string]: IResourceStoreLanguage;
@@ -99,7 +101,7 @@ interface I18nextStatic {
regexEscape(str: string): string;
};
init(callback?: (err: any, t: (key: string, options?: any) => string) => void ): JQueryDeferred<any>;
init(options?: I18nextOptions, callback?: (err: any, t: (key: string, options?: any) => string) => void ): JQueryDeferred<any>;
init(options?: I18nextOptions|any, callback?: (err: any, t: (key: string, options?: any) => string) => void ): JQueryDeferred<any>; // NOTE: remove any for 'options' parameter.
lng(): string;
loadNamespace(namespace: string, callback?: () => void ): void;
loadNamespaces(namespaces: string[], callback?: () => void ): void;
@@ -124,6 +126,7 @@ interface I18nextStatic {
t(key: string, options?: I18nTranslateOptions): string;
translate(key: string, options?: I18nTranslateOptions): string;
exists(key: string, options?: any): boolean;
use(module: any): I18nextStatic;
}
// jQuery extensions