diff --git a/acc-wizard/acc-wizard.ts.tscparams b/acc-wizard/acc-wizard.ts.tscparams deleted file mode 100644 index 934bc29ef2..0000000000 --- a/acc-wizard/acc-wizard.ts.tscparams +++ /dev/null @@ -1 +0,0 @@ ---noImplicitAny \ No newline at end of file diff --git a/connect-timeout/connect-timeout-tests.ts b/connect-timeout/connect-timeout-tests.ts index 920c7fdc67..4f77b597d9 100644 --- a/connect-timeout/connect-timeout-tests.ts +++ b/connect-timeout/connect-timeout-tests.ts @@ -3,10 +3,10 @@ /// /// -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 diff --git a/connect-timeout/connect-timeout.d.ts b/connect-timeout/connect-timeout.d.ts index 8494a3afbf..88bafbad53 100644 --- a/connect-timeout/connect-timeout.d.ts +++ b/connect-timeout/connect-timeout.d.ts @@ -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; } diff --git a/i18next-express-middleware/i18next-express-middleware-tests.ts b/i18next-express-middleware/i18next-express-middleware-tests.ts index 54e47b03cf..a696f4f8af 100644 --- a/i18next-express-middleware/i18next-express-middleware-tests.ts +++ b/i18next-express-middleware/i18next-express-middleware-tests.ts @@ -1,5 +1,48 @@ +/// /// -//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); +} diff --git a/i18next-express-middleware/i18next-express-middleware.d.ts b/i18next-express-middleware/i18next-express-middleware.d.ts index ad9f0a95d7..fe51928bfc 100644 --- a/i18next-express-middleware/i18next-express-middleware.d.ts +++ b/i18next-express-middleware/i18next-express-middleware.d.ts @@ -4,30 +4,93 @@ // Definitions: https://github.com/borisyankov/DefinitelyTyped /// +/// + +/** + * @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; +} 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; + /** + * @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; } diff --git a/i18next/i18next.d.ts b/i18next/i18next.d.ts index 38d91b603e..9256e7a45e 100644 --- a/i18next/i18next.d.ts +++ b/i18next/i18next.d.ts @@ -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 // Definitions: https://github.com/borisyankov/DefinitelyTyped // Sources: https://github.com/jamuhl/i18next/ +/// /// +/// 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; - init(options?: I18nextOptions, callback?: (err: any, t: (key: string, options?: any) => string) => void ): JQueryDeferred; + init(options?: I18nextOptions|any, callback?: (err: any, t: (key: string, options?: any) => string) => void ): JQueryDeferred; // 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