From 3bd078da5369b8e2efb55a8d113578c1dc63d2fb Mon Sep 17 00:00:00 2001 From: Jakub Skopal Date: Sat, 1 Oct 2016 18:41:37 +0200 Subject: [PATCH 01/45] changed versionKey in Schema spec to string --- mongoose/mongoose.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mongoose/mongoose.d.ts b/mongoose/mongoose.d.ts index 9e5600e696..928949ec59 100644 --- a/mongoose/mongoose.d.ts +++ b/mongoose/mongoose.d.ts @@ -696,7 +696,7 @@ declare module "mongoose" { /** defaults to true */ validateBeforeSave?: boolean; /** defaults to "__v" */ - versionKey?: boolean; + versionKey?: string; /** * skipVersioning allows excluding paths from * versioning (the internal revision will not be From ee1fbc5e9cab1afa9aa0a20be657c22629a1e43f Mon Sep 17 00:00:00 2001 From: unHealthy Date: Sun, 2 Oct 2016 16:33:02 +0800 Subject: [PATCH 02/45] better structure --- passport/passport.d.ts | 82 ++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 48 deletions(-) diff --git a/passport/passport.d.ts b/passport/passport.d.ts index 088156b2d3..5231b1fdac 100644 --- a/passport/passport.d.ts +++ b/passport/passport.d.ts @@ -27,30 +27,11 @@ declare namespace Express { declare module 'passport' { import express = require('express'); - function use(strategy: Strategy): Passport; - function use(name: string, strategy: Strategy): Passport; - function unuse(name: string): Passport; - function framework(fw: Framework): Passport; - function initialize(options?: { userProperty: string; }): express.Handler; - function session(options?: { pauseStream: boolean; }): express.Handler; - - function authenticate(strategy: string, callback?: Function): express.Handler; - function authenticate(strategy: string, options: Object, callback?: Function): express.Handler; - function authenticate(strategies: string[], callback?: Function): express.Handler; - function authenticate(strategies: string[], options: Object, callback?: Function): express.Handler; - function authorize(strategy: string, callback?: Function): express.Handler; - function authorize(strategy: string, options: Object, callback?: Function): express.Handler; - function authorize(strategies: string[], callback?: Function): express.Handler; - function authorize(strategies: string[], options: Object, callback?: Function): express.Handler; - function serializeUser(fn: (user: any, done: (err: any, id: any) => void) => void): void; - function deserializeUser(fn: (id: any, done: (err: any, user: any) => void) => void): void; - function transformAuthInfo(fn: (info: any, done: (err: any, info: any) => void) => void): void; - interface Passport { - use(strategy: Strategy): Passport; - use(name: string, strategy: Strategy): Passport; + use(strategy: passport.Strategy): Passport; + use(name: string, strategy: passport.Strategy): Passport; unuse(name: string): Passport; - framework(fw: Framework): Passport; + framework(fw: passport.Framework): Passport; initialize(options?: { userProperty: string; }): express.Handler; session(options?: { pauseStream: boolean; }): express.Handler; @@ -66,33 +47,38 @@ declare module 'passport' { deserializeUser(fn: (id: any, done: (err: any, user: any) => void) => void): void; transformAuthInfo(fn: (info: any, done: (err: any, info: any) => void) => void): void; } + const passport: Passport; + export = passport; - interface Strategy { - name?: string; - authenticate(req: express.Request, options?: Object): void; + namespace passport { + interface Strategy { + name?: string; + authenticate(req: express.Request, options?: Object): void; + } + + interface Profile { + provider: string; + id: string; + displayName: string; + name?: { + familyName: string; + givenName: string; + middleName?: string; + }; + emails?: { + value: string; + type?: string; + }[]; + photos?: { + value: string; + }[]; + } + + interface Framework { + initialize(passport: Passport, options?: Object): Function; + authenticate(passport: Passport, name: string, options?: Object, callback?: Function): Function; + authorize?(passport: Passport, name: string, options?: Object, callback?: Function): Function; + } } - interface Profile { - provider: string; - id: string; - displayName: string; - name?: { - familyName: string; - givenName: string; - middleName?: string; - }; - emails?: { - value: string; - type?: string; - }[]; - photos?: { - value: string; - }[]; - } - - interface Framework { - initialize(passport: Passport, options?: Object): Function; - authenticate(passport: Passport, name: string, options?: Object, callback?: Function): Function; - authorize?(passport: Passport, name: string, options?: Object, callback?: Function): Function; - } } From 55c35bf01e8e1d1e0b81711583d4bf568431ea21 Mon Sep 17 00:00:00 2001 From: Eric Wieser Date: Sun, 2 Oct 2016 01:03:02 +0100 Subject: [PATCH 03/45] Add argumentless Q() --- q/Q-tests.ts | 1 + q/Q.d.ts | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/q/Q-tests.ts b/q/Q-tests.ts index e59f2dc1b3..eaa1241016 100644 --- a/q/Q-tests.ts +++ b/q/Q-tests.ts @@ -4,6 +4,7 @@ import q = require('q'); Q(8).then(x => console.log(x.toExponential())); +Q().then(() => console.log("nothing")); var delay = function (delay: number) { var d = Q.defer(); diff --git a/q/Q.d.ts b/q/Q.d.ts index 1fa4642121..55ac3df6a1 100644 --- a/q/Q.d.ts +++ b/q/Q.d.ts @@ -12,6 +12,10 @@ declare function Q(promise: Q.IPromise): Q.Promise; * If value is not a promise, returns a promise that is fulfilled with value. */ declare function Q(value: T): Q.Promise; +/** + * Calling with nothing at all creates a void promise + */ +declare function Q(): Q.Promise; declare namespace Q { interface IPromise { From 4aa07d54c7c522f7a983e6c75663bc35f51e27ba Mon Sep 17 00:00:00 2001 From: Sam Verschueren Date: Mon, 3 Oct 2016 14:24:21 +0200 Subject: [PATCH 04/45] add definitions for tz-format (#11565) * add definitions for tz-format * fix return type --- tz-format/tz-format-tests.ts | 6 ++++++ tz-format/tz-format.d.ts | 10 ++++++++++ 2 files changed, 16 insertions(+) create mode 100644 tz-format/tz-format-tests.ts create mode 100644 tz-format/tz-format.d.ts diff --git a/tz-format/tz-format-tests.ts b/tz-format/tz-format-tests.ts new file mode 100644 index 0000000000..54e17eeb38 --- /dev/null +++ b/tz-format/tz-format-tests.ts @@ -0,0 +1,6 @@ +/// + +import * as format from 'tz-format'; + +format(); +format(new Date()); diff --git a/tz-format/tz-format.d.ts b/tz-format/tz-format.d.ts new file mode 100644 index 0000000000..fa8b1c000b --- /dev/null +++ b/tz-format/tz-format.d.ts @@ -0,0 +1,10 @@ +// Type definitions for tz-format +// Project: https://github.com/SamVerschueren/tz-format +// Definitions by: Sam Verschueren +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare module "tz-format" { + function format(date?: Date): string; + namespace format { } + export = format; +} From 76eedd816aeb57b2ab3e551a8b36f6008a4268b3 Mon Sep 17 00:00:00 2001 From: Erkie Date: Mon, 3 Oct 2016 14:24:53 +0200 Subject: [PATCH 05/45] Create typings for ngeohash (#11634) --- ngeohash/ngeohash-tests.ts | 10 ++++++++++ ngeohash/ngeohash.d.ts | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 ngeohash/ngeohash-tests.ts create mode 100644 ngeohash/ngeohash.d.ts diff --git a/ngeohash/ngeohash-tests.ts b/ngeohash/ngeohash-tests.ts new file mode 100644 index 0000000000..0ff987802e --- /dev/null +++ b/ngeohash/ngeohash-tests.ts @@ -0,0 +1,10 @@ +/// + +import geohash = require('ngeohash'); + +console.log(geohash.encode(37.8324, 112.5584)); +// prints ww8p1r4t8 + +var latlon = geohash.decode('ww8p1r4t8'); +console.log(latlon.latitude); +console.log(latlon.longitude); diff --git a/ngeohash/ngeohash.d.ts b/ngeohash/ngeohash.d.ts new file mode 100644 index 0000000000..25c8f29e5b --- /dev/null +++ b/ngeohash/ngeohash.d.ts @@ -0,0 +1,32 @@ +// Type definitions for ngeohash v0.6.0 +// Project: https://github.com/sunng87/node-geohash +// Definitions by: Erik Rothoff Andersson +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped/ + +declare namespace ngeohash { + interface GeographicPoint { + latitude: number; + longitude: number; + } + + type GeographicBoundingBox = [number, number, number, number]; + type NSEW = [number, number]; + + function encode(latitude: number, longitude: number, precision?: number): string; + function decode(hashstring: string): GeographicPoint; + function decode_bbox(hashstring: string): GeographicBoundingBox; + function bboxes(minlat: number, minlon: number, maxlat: number, maxlon: number, precision?: number): Array; + function neighbor(hashstring: string, direction: NSEW): string; + function neighbors(hashstring: string): Array; + + function encode_int(latitude: number, longitude: number, bitDepth?: number): number; + function decode_int(hashinteger: number, bitDepth?: number): GeographicPoint; + function decode_bbox_int(hashinteger: number, bitDepth?: number): GeographicBoundingBox; + function bboxes_int(minlat: number, minlon: number, maxlat: number, maxlon: number, bitDepth?: number): number; + function neighbor_int(hashinteger: number, direction: NSEW, bitDepth?: number): number; + function neighbors_int(hashinteger: number, bitDepth?: number): number; +} + +declare module "ngeohash" { + export = ngeohash; +} From a4a4b87bc91507afa71664b7c1612798ab11896f Mon Sep 17 00:00:00 2001 From: Stefan Dobrev Date: Mon, 3 Oct 2016 15:27:59 +0300 Subject: [PATCH 06/45] [nprogress] Update configuration properties (#11627) Update a couple of nprogress configuration properties: * `ease` is renamed to `easing`. * `trickleRate` is removed. * `parent` is added. More info [here](https://github.com/rstacruz/nprogress/blob/master/nprogress.js#L19-L31) --- nprogress/NProgress-tests.ts | 6 +++--- nprogress/NProgress.d.ts | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/nprogress/NProgress-tests.ts b/nprogress/NProgress-tests.ts index 3d07cafa2b..2a62eb27b2 100644 --- a/nprogress/NProgress-tests.ts +++ b/nprogress/NProgress-tests.ts @@ -21,13 +21,13 @@ function test_configuration() { }); NProgress.configure({ - ease: 'ease', + easing: 'ease', minimum: 0.09, showSpinner: false, speed: 420, template: "
blah
", trickle: false, - trickleRate: 0.42, - trickleSpeed: 42 + trickleSpeed: 42, + parent: 'body', }); } diff --git a/nprogress/NProgress.d.ts b/nprogress/NProgress.d.ts index 646290fee9..0f84d8af46 100644 --- a/nprogress/NProgress.d.ts +++ b/nprogress/NProgress.d.ts @@ -68,16 +68,16 @@ interface NProgressStatic { interface NProgressConfigureOptions { + /** + * CSS selector to change the parent DOM element of the progress. Default is body. + */ + parent?: string + /** * The minimum progress percentage. Default is 0.08. */ minimum?: number; - /** - * How much to increase per trickle. Example: .02. Default is true. - */ - trickleRate?: number; - /** * How often to trickle, in milliseconds. Default is 800. */ @@ -94,9 +94,9 @@ interface NProgressConfigureOptions { trickle?: boolean; /** - * The CSS easing animation to use. Default is 'ease'. + * The CSS easing animation to use. Default is 'linear'. */ - ease?: string; + easing?: string; /** * The animation speed in milliseconds. Default is 200. From 8a47541d7ed17b87ddeb6d5edf28600a2f5cbd17 Mon Sep 17 00:00:00 2001 From: Garth Kidd Date: Mon, 3 Oct 2016 23:28:13 +1100 Subject: [PATCH 07/45] Fix leaflet L.GeoJSON.addData et al (#11590) (#11591) --- leaflet/leaflet.d.ts | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/leaflet/leaflet.d.ts b/leaflet/leaflet.d.ts index e203a066ec..50051df19d 100644 --- a/leaflet/leaflet.d.ts +++ b/leaflet/leaflet.d.ts @@ -815,36 +815,34 @@ declare namespace L { * Represents a GeoJSON object or an array of GeoJSON objects. * Allows you to parse GeoJSON data and display it on the map. Extends FeatureGroup. */ - export interface GeoJSON extends FeatureGroup {} - - export namespace GeoJSON { + export interface GeoJSON extends FeatureGroup { /** * Adds a GeoJSON object to the layer. */ - export function addData(data: Object): Layer; + addData(data: Object): Layer; /** * Resets the given vector layer's style to the original GeoJSON style, * useful for resetting style after hover events. */ - export function resetStyle(layer: Layer): Layer; + resetStyle(layer: Layer): Layer; /** * Changes styles of GeoJSON vector layers with the given style function. */ - export function setStyle(style: PathOptions | StyleFunction): Layer; + setStyle(style: PathOptions | StyleFunction): this; /** * Creates a Layer from a given GeoJSON feature. Can use a custom pointToLayer * and/or coordsToLatLng functions if provided as options. */ - export function geometryToLayer(featureData: Object, options?: GeoJSONOptions): Layer; + geometryToLayer(featureData: Object, options?: GeoJSONOptions): Layer; /** * Creates a LatLng object from an array of 2 numbers (longitude, latitude) or * 3 numbers (longitude, latitude, altitude) used in GeoJSON for points. */ - export function coordsToLatLng(coords: [number, number] | [number, number, number]): LatLng; + coordsToLatLng(coords: [number, number] | [number, number, number]): LatLng; /** * Creates a multidimensional array of LatLngs from a GeoJSON coordinates array. @@ -852,24 +850,24 @@ declare namespace L { * arrays of points, etc., 0 by default). * Can use a custom coordsToLatLng function. */ - export function coordsToLatLngs(coords: Array, levelsDeep?: number, coordsToLatLng?: (coords: [number, number] | [number, number, number]) => LatLng): LatLng[]; // Not entirely sure how to define arbitrarily nested arrays + coordsToLatLngs(coords: Array, levelsDeep?: number, coordsToLatLng?: (coords: [number, number] | [number, number, number]) => LatLng): LatLng[]; // Not entirely sure how to define arbitrarily nested arrays /** * Reverse of coordsToLatLng */ - export function latLngToCoords(latlng: LatLng): [number, number] | [number, number, number]; + latLngToCoords(latlng: LatLng): [number, number] | [number, number, number]; /** * Reverse of coordsToLatLngs closed determines whether the first point should be * appended to the end of the array to close the feature, only used when levelsDeep is 0. * False by default. */ - export function latLngsToCoords(latlngs: Array, levelsDeep?: number, closed?: boolean): [number, number] | [number, number, number]; + latLngsToCoords(latlngs: Array, levelsDeep?: number, closed?: boolean): [number, number] | [number, number, number]; /** * Normalize GeoJSON geometries/features into GeoJSON features. */ - export function asFeature(geojson: Object): Object; + asFeature(geojson: Object): Object; } /** From 7b1e7800456dad6e1092113bc22fe737bc017e7b Mon Sep 17 00:00:00 2001 From: Julien Chaumond Date: Mon, 3 Oct 2016 14:41:58 +0200 Subject: [PATCH 08/45] NotificationAlertOptions can have a subtitle (#11638) --- apn/apn.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/apn/apn.d.ts b/apn/apn.d.ts index cf11b13c0e..c77f3ddf6d 100644 --- a/apn/apn.d.ts +++ b/apn/apn.d.ts @@ -137,6 +137,7 @@ declare module "apn" { } export interface NotificationAlertOptions { title?:string; + subtitle?:string; body:string; "title-loc-key"?:string; "title-loc-args"?:string[]; From ddd4bae5eeaac9a48f801a82a963b902705d527f Mon Sep 17 00:00:00 2001 From: AJ Ortega Date: Mon, 3 Oct 2016 05:43:39 -0700 Subject: [PATCH 09/45] Parse5 comment data (#11649) * Add test for data * Update parse5.d.ts --- parse5/parse5-tests.ts | 1 + parse5/parse5.d.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/parse5/parse5-tests.ts b/parse5/parse5-tests.ts index 05e1ea683e..81c29395ee 100644 --- a/parse5/parse5-tests.ts +++ b/parse5/parse5-tests.ts @@ -60,5 +60,6 @@ fragment.quirksMode = true; fragment.namespaceURI = ''; fragment.nodeName = ''; fragment.value = ''; +fragment.data = ''; fragment = fragment.childNodes[0]; fragment = fragment.parentNode; diff --git a/parse5/parse5.d.ts b/parse5/parse5.d.ts index bb77d6c0c3..99dc2263a4 100644 --- a/parse5/parse5.d.ts +++ b/parse5/parse5.d.ts @@ -56,6 +56,7 @@ declare module 'parse5' { export interface ASTNode { attrs: ASTAttribute[]; childNodes?: ASTNode[]; + data?: string; namespaceURI?: string; parentNode?: ASTNode; nodeName: string; From ebfa2f08edfe5f5398357c63339a462e702d9484 Mon Sep 17 00:00:00 2001 From: Thodoris Greasidis Date: Mon, 3 Oct 2016 15:57:09 +0300 Subject: [PATCH 10/45] feat: add localforage-cordovasqlitedriver definition (#11650) --- .../localforage-cordovasqlitedriver-tests.ts | 56 +++++++++++++++++++ .../localforage-cordovasqlitedriver.d.ts | 11 ++++ 2 files changed, 67 insertions(+) create mode 100644 localforage-cordovasqlitedriver/localforage-cordovasqlitedriver-tests.ts create mode 100644 localforage-cordovasqlitedriver/localforage-cordovasqlitedriver.d.ts diff --git a/localforage-cordovasqlitedriver/localforage-cordovasqlitedriver-tests.ts b/localforage-cordovasqlitedriver/localforage-cordovasqlitedriver-tests.ts new file mode 100644 index 0000000000..d6a9ac4ae2 --- /dev/null +++ b/localforage-cordovasqlitedriver/localforage-cordovasqlitedriver-tests.ts @@ -0,0 +1,56 @@ +/// + +declare var cordovaSQLiteDriver: LocalForageDriver; + +() => { + + var driverName: string = cordovaSQLiteDriver._driver; + + var config = { + driver: driverName, + name: 'localforage' + }; + + cordovaSQLiteDriver._initStorage(config); + + cordovaSQLiteDriver.clear((err: any) => { + var newError: any = err; + }); + + cordovaSQLiteDriver.length((err: any, num: number) => { + var newError: any = err; + var newNumber: number = num; + }); + + cordovaSQLiteDriver.key(0, (err: any, value: string) => { + var newError: any = err; + var newValue: string = value; + }); + + cordovaSQLiteDriver.keys((err: any, keys: Array) => { + var newError: any = err; + var newArray: Array = keys; + }); + + cordovaSQLiteDriver.getItem("key",(err: any, str: string) => { + var newError: any = err; + var newStr: string = str + }); + + cordovaSQLiteDriver.setItem("key", "value", (err: any, str: string) => { + var newError: any = err; + var newStr: string = str + }); + + cordovaSQLiteDriver.setItem("key", "value", (str: string) => { + var newStr: string = str; + }); + + cordovaSQLiteDriver.removeItem("key",(err: any) => { + var newError: any = err; + }); + + cordovaSQLiteDriver.removeItem("key", (err: any) => { + var newError: any = err; + }); +} \ No newline at end of file diff --git a/localforage-cordovasqlitedriver/localforage-cordovasqlitedriver.d.ts b/localforage-cordovasqlitedriver/localforage-cordovasqlitedriver.d.ts new file mode 100644 index 0000000000..22327f12b9 --- /dev/null +++ b/localforage-cordovasqlitedriver/localforage-cordovasqlitedriver.d.ts @@ -0,0 +1,11 @@ +// Type definitions for localforage-cordovasqlitedriver module v1.0+ +// Project: https://github.com/thgreasi/localForage-cordovaSQLiteDriver +// Definitions by: Thodoris Greasidis +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +declare module "localforage-cordovasqlitedriver" { + var cordovaSQLiteDriver: LocalForageDriver; + export = cordovaSQLiteDriver; +} From e35513ae8fe0209e86eb72958efc3f9fc5c80eda Mon Sep 17 00:00:00 2001 From: Cyril Schumacher Date: Mon, 3 Oct 2016 15:05:12 +0200 Subject: [PATCH 11/45] Fix export for "bunyan-config" and improve definitions (#11653) * Fix export for "bunyan-config". * Update definitions. Replace "Object" to "{}" type. Add "express" property in "VitalSigns" class. --- bunyan-config/bunyan-config-tests.ts | 2 +- bunyan-config/bunyan-config.d.ts | 2 +- express-mung/express-mung.d.ts | 4 ++-- vitalsigns/vitalsigns-tests.ts | 10 +++++++--- vitalsigns/vitalsigns.d.ts | 16 +++++++++++++--- 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/bunyan-config/bunyan-config-tests.ts b/bunyan-config/bunyan-config-tests.ts index 6a15aff601..71d22ee2a4 100644 --- a/bunyan-config/bunyan-config-tests.ts +++ b/bunyan-config/bunyan-config-tests.ts @@ -1,7 +1,7 @@ /// import * as bunyan from "bunyan"; -import bunyanConfig from "bunyan-config"; +import bunyanConfig = require("bunyan-config"); var jsonConfig = { name: "myLogger", diff --git a/bunyan-config/bunyan-config.d.ts b/bunyan-config/bunyan-config.d.ts index 68a095b9b8..fb68702aee 100644 --- a/bunyan-config/bunyan-config.d.ts +++ b/bunyan-config/bunyan-config.d.ts @@ -27,5 +27,5 @@ declare module "bunyan-config" { * @return {LoggerOptions} A logger options. */ function bunyanConfig(jsonConfig?: Configuration): bunyan.LoggerOptions; - export default bunyanConfig; + export = bunyanConfig; } diff --git a/express-mung/express-mung.d.ts b/express-mung/express-mung.d.ts index 6dfee7d557..6f9a844c7a 100644 --- a/express-mung/express-mung.d.ts +++ b/express-mung/express-mung.d.ts @@ -10,8 +10,8 @@ declare module "express-mung" { import { Request, Response } from "express"; import * as http from "http"; - type Transform = (body: {}, request: Request, response: Response) => {}; - type TransformHeader = (body: http.IncomingMessage, request: Request, response: Response) => {}; + type Transform = (body: {}, request: Request, response: Response) => any; + type TransformHeader = (body: http.IncomingMessage, request: Request, response: Response) => any; /** * Transform the JSON body of the response. diff --git a/vitalsigns/vitalsigns-tests.ts b/vitalsigns/vitalsigns-tests.ts index 1e22dec433..8136dfcfbd 100644 --- a/vitalsigns/vitalsigns-tests.ts +++ b/vitalsigns/vitalsigns-tests.ts @@ -1,11 +1,12 @@ /// +import * as express from "express"; import VitalSigns = require("vitalsigns"); var vitals = new VitalSigns(); vitals.monitor('cpu'); -vitals.monitor('mem', {units: 'MB'}); +vitals.monitor('mem', { units: 'MB' }); vitals.monitor('tick'); vitals.unhealthyWhen('cpu', 'usage').equals(100); @@ -13,7 +14,7 @@ vitals.unhealthyWhen('tick', 'maxMs').greaterThan(500); vitals.monitor({ connections: () => new Object() -}, {name: 'game'}); +}, { name: 'game' }); var vitals = new VitalSigns({ autoCheck: 5000, @@ -21,5 +22,8 @@ var vitals = new VitalSigns({ httpUnhealthy: 503 }); -vitals.monitor('cpu', {name: 'foo'}); +vitals.monitor('cpu', { name: 'foo' }); vitals.unhealthyWhen('foo', 'bar').not.greaterThan(5); + +var app = express(); +app.get('/health', vitals.express); diff --git a/vitalsigns/vitalsigns.d.ts b/vitalsigns/vitalsigns.d.ts index c74a42f08a..f58a88962d 100644 --- a/vitalsigns/vitalsigns.d.ts +++ b/vitalsigns/vitalsigns.d.ts @@ -3,7 +3,11 @@ // Definitions by: Cyril Schumacher // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +/// + declare module "vitalsigns" { + import { RequestHandler } from "express"; + namespace vitalsigns { /** * Contraint. @@ -148,6 +152,12 @@ declare module "vitalsigns" { */ destroy(): void; + /** + * Gets a request handler. + * @type {RequestHandler} + */ + express: RequestHandler; + /** * Retrieves an array of human-readable messages that define the specific health constraints that failed when running the last health check. * @returns {Array} An array of failure messages. @@ -160,7 +170,7 @@ declare module "vitalsigns" { * @param {ReportOptions} [options] A mapping of options to customize this report. * @return {Object} The full health report. */ - getReport(options?: vitalsigns.ReportOptions): Object; + getReport(options?: vitalsigns.ReportOptions): {}; /** * Generates a health report and checks each health constraint against it. Any constraints that fail will be added to the 'failed' array in the form of @@ -168,14 +178,14 @@ declare module "vitalsigns" { * @param {Object} [report] A report object on which to run the health constraints. If omitted, this function will generate a health report automatically. * @return {boolean} true if all health constraints passed; false otherwise. */ - isHealthy(report?: Object): boolean; + isHealthy(report?: {}): boolean; /** * Registers monitor. * @param {string} monitorName A monitor name. * @param {MonitorField} [field] Options. */ - monitor(monitor: string | vitalsigns.Monitor | Object, field?: vitalsigns.MonitorField): void; + monitor(monitor: string | vitalsigns.Monitor | {}, field?: vitalsigns.MonitorField): void; /** * Defines a new health constraint in a chainable, more easily readable format. From 0961889be53327e3a23a72d18c604e2a933a4575 Mon Sep 17 00:00:00 2001 From: Ciro Date: Mon, 3 Oct 2016 15:05:26 +0200 Subject: [PATCH 12/45] Update ejs.d.ts (#11467) This typings give an error when templating HTML Error: Cannot invoke an expression whose type lacks a call signature. my code ```javascript var templateFunction = EJS.compile(SOMESTRTEMPLATE); myDomElement.innerHTML = templateFunction(someDataObject) // <= ERROR ``` --- ejs/ejs.d.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ejs/ejs.d.ts b/ejs/ejs.d.ts index 6e2347fbc5..e80b5794a1 100644 --- a/ejs/ejs.d.ts +++ b/ejs/ejs.d.ts @@ -16,9 +16,8 @@ declare module "ejs" { function renderFile(path: string, data?: Data, opts?: Options, cb?: Function): any;// TODO RenderFileCallback return type function clearCache(): any; - function TemplateFunction(data: Data): any; interface TemplateFunction { - dependencies: Dependencies; + (data: Data): any; } interface Options { cache?: any; From 78cbe0e71339c254eca4e9e22e7f612a8b60605b Mon Sep 17 00:00:00 2001 From: spacejack Date: Mon, 3 Oct 2016 09:12:44 -0400 Subject: [PATCH 13/45] Added hyperscript module (#11661) --- hyperscript/hyperscript-tests.ts | 58 ++++++++++++++++++++++++++++++++ hyperscript/hyperscript.d.ts | 19 +++++++++++ 2 files changed, 77 insertions(+) create mode 100644 hyperscript/hyperscript-tests.ts create mode 100644 hyperscript/hyperscript.d.ts diff --git a/hyperscript/hyperscript-tests.ts b/hyperscript/hyperscript-tests.ts new file mode 100644 index 0000000000..b850bbf4cb --- /dev/null +++ b/hyperscript/hyperscript-tests.ts @@ -0,0 +1,58 @@ +/// +import * as h from 'hyperscript' + +// Test/example code adapted from https://github.com/dominictarr/hyperscript/blob/master/README.md + +// example +h('div#page', + h('div#header', + h('h1.classy', 'h', { style: {'background-color': '#22f'} })), + h('div#menu', { style: {'background-color': '#2f2'} }, + h('ul', + h('li', 'one'), + h('li', 'two'), + h('li', 'three'))), + h('h2', 'content title', { style: {'background-color': '#f22'} }), + h('p', + "so it's just like a templating engine,\n", + "but easy to use inline with javascript\n"), + h('p', + "the intension is for this to be used to create\n", + "reusable, interactive html widgets. ")) + +// event +h('a', {href: '#', + onclick: function (e: Event) { + alert('you are 1,000,000th visitor!') + e.preventDefault() + } +}, 'click here to win a prize') + +// array of children +const obj: {[id: string]: string} = { + a: 'Apple', + b: 'Banana', + c: 'Cherry', + d: 'Durian', + e: 'Elder Berry' +} +h('table', + h('tr', h('th', 'letter'), h('th', 'fruit')), + Object.keys(obj).map(function (k) { + return h('tr', + h('th', k), + h('td', obj[k]) + ) + }) +) + +// new context +const h2 = h.context() +h2('a', {href: '#', + onclick: function (e: Event) { + alert('you are 1,000,000th visitor!') + e.preventDefault() + } +}, "Click this") + +h2.cleanup() diff --git a/hyperscript/hyperscript.d.ts b/hyperscript/hyperscript.d.ts new file mode 100644 index 0000000000..4274365404 --- /dev/null +++ b/hyperscript/hyperscript.d.ts @@ -0,0 +1,19 @@ +// Type definitions for hyperscript +// Project: https://github.com/dominictarr/hyperscript +// Definitions by: Mike Linkovich +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare module 'hyperscript' { + + interface HyperScript { + /** Creates an HTML element */ + (tagName: string, ...args: any[]): HTMLElement; + /** Cleans up any event handlers created by this hyperscript context */ + cleanup(): void; + /** Creates a new hyperscript context */ + context(): HyperScript; + } + + const h: HyperScript; + export = h; +} From f3bafd505e08c3813e5a25881aa5fbd5c2876f8d Mon Sep 17 00:00:00 2001 From: Boris Cherny Date: Mon, 3 Oct 2016 06:13:03 -0700 Subject: [PATCH 14/45] update parsimmon typings for parsimmon 0.9.2 (#11648) * update parsimmon typings for parsimmon 0.9.2 * add overloads for parsimmon#seq * code review --- parsimmon/parsimmon-tests.ts | 33 +++++- parsimmon/parsimmon.d.ts | 223 ++++++++++++++++++++++++----------- 2 files changed, 184 insertions(+), 72 deletions(-) diff --git a/parsimmon/parsimmon-tests.ts b/parsimmon/parsimmon-tests.ts index 569328296f..69a31ee57a 100644 --- a/parsimmon/parsimmon-tests.ts +++ b/parsimmon/parsimmon-tests.ts @@ -108,7 +108,8 @@ strPar = P.regex(regex); fooPar = P.succeed(foo); fooArrPar = P.seq(fooPar, fooPar); -anyArrPar = P.seq(barPar, fooPar, numPar); +var par: Parser<[Bar, Foo, number]> = P.seq(barPar, fooPar, numPar); +var par2: Parser = P.seq(barPar, fooPar, numPar).map(([a, b, c]: [Bar, Foo, number]) => 42); fooPar = P.custom((success, failure) => (stream, i) => { str = stream; num = i; return success(num, foo); }); fooPar = P.custom((success, failure) => (stream, i) => failure(num, str)); @@ -139,3 +140,33 @@ strPar = P.any; strPar = P.all; voidPar = P.eof; numPar = P.index; + +// -- -- -- -- -- -- -- -- -- -- -- -- -- + +bool = P.isParser(numPar); +bool = P.isParser(null); +bool = P.isParser(42); + +strPar = P.oneOf('a'); +strPar = P.noneOf('a'); + +strPar = P.regex(/foo/); +strPar = P.regex(/foo/, 3); +strPar = P.regexp(/bar/); +strPar = P.regexp(/bar/, 3); + +fooPar = P.of(foo); + +str = P.formatError('foo', strPar.parse('bar')); + +strPar = P.seqMap(P.digit, (a: string) => 'foo'); +numPar = P.seqMap(P.digit, P.digits, (a: string, b: string) => 42); +strPar = P.seqMap(P.digit, P.digits, P.letter, (a: string, b: string, c: string) => 'foo'); +strPar = P.seqMap(P.digit, P.digits, P.letter, P.letters.map(Number), (a: string, b: string, c: string, d: number) => 'foo'); + +strPar = P.sepBy(P.string('foo'), P.string('bar')); +strPar = P.sepBy1(P.string('foo'), P.string('bar')); + +strPar = P.test((a: string) => false); + +strPar = P.takeWhile((a: string) => true); \ No newline at end of file diff --git a/parsimmon/parsimmon.d.ts b/parsimmon/parsimmon.d.ts index ab6ceab4df..2004fb00bf 100644 --- a/parsimmon/parsimmon.d.ts +++ b/parsimmon/parsimmon.d.ts @@ -1,6 +1,6 @@ -// Type definitions for Parsimmon 0.5.0 +// Type definitions for Parsimmon 0.9.2 // Project: https://github.com/jneen/parsimmon -// Definitions by: Bart van der Schoor , Mizunashi Mana +// Definitions by: Bart van der Schoor , Mizunashi Mana , Boris Cherny // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TODO convert to generics @@ -24,153 +24,234 @@ declare module 'parsimmon' { } export interface Parser { - /* - parse the string + /** + * parse the string */ parse(input: string): Result; - /* - returns a new parser which tries parser, and if it fails uses otherParser. + /** + * returns a new parser which tries parser, and if it fails uses otherParser. */ or(otherParser: Parser): Parser; or(otherParser: Parser): Parser; - /* - returns a new parser which tries parser, and on success calls the given function with the result of the parse, which is expected to return another parser, which will be tried next + /** + * returns a new parser which tries parser, and on success calls the given function + * with the result of the parse, which is expected to return another parser, which + * will be tried next */ chain(next: (result: T) => Parser): Parser; - /* - returns a new parser which tries parser, and on success calls the given function with the result of the parse, which is expected to return another parser. + /** + * returns a new parser which tries parser, and on success calls the given function + * with the result of the parse, which is expected to return another parser. */ then(call: (result: T) => Parser): Parser; - /* - expects anotherParser to follow parser, and yields the result of anotherParser. NB: the result of parser here is ignored. + /** + * expects anotherParser to follow parser, and yields the result of anotherParser. + * NB: the result of parser here is ignored. */ then(anotherParser: Parser): Parser; - /* - transforms the output of parser with the given function. + /** + * transforms the output of parser with the given function. */ map(call: (result: T) => U): Parser; - /* - expects otherParser after parser, but preserves the yield value of parser. + /** + * expects otherParser after parser, but preserves the yield value of parser. */ skip(otherParser: Parser): Parser; - /* - returns a new parser with the same behavior, but which yields aResult. + /** + * returns a new parser with the same behavior, but which yields aResult. */ result(aResult: U): Parser; - /* - expects parser zero or more times, and yields an array of the results. + /** + * expects parser zero or more times, and yields an array of the results. */ many(): Parser; - /* - expects parser exactly n times, and yields an array of the results. + /** + * expects parser exactly n times, and yields an array of the results. */ times(n: number): Parser; - /* - expects parser between min and max times, and yields an array of the results. + /** + * expects parser between min and max times, and yields an array of the results. */ times(min: number, max: number): Parser; - /* - expects parser at most n times. Yields an array of the results. + /** + * expects parser at most n times. Yields an array of the results. */ atMost(n: number): Parser; - /* - expects parser at least n times. Yields an array of the results. + /** + * expects parser at least n times. Yields an array of the results. */ atLeast(n: number): Parser; - /* - returns a new parser whose failure message is the passed description. + /** + * returns a new parser whose failure message is the passed description. */ mark(): Parser>; - + /** + * Returns a new parser whose failure message is description. + * For example, string('x').desc('the letter x') will indicate that 'the letter x' was expected. + */ desc(description: string): Parser; } - /* - is a parser that expects to find "my-string", and will yield the same. - */ - export function string(mystring: string): Parser; - /* - is a parser that expects the stream to match the given regex. + /** + * Returns true if obj is a Parsimmon parser, otherwise false. */ - export function regex(myregex: RegExp): Parser; + export function isParser(obj: any): boolean; - /* - is a parser that doesn't consume any of the string, and yields result. + /** + * is a parser that expects to find "my-string", and will yield the same. + */ + export function string(string: string): Parser; + + /** + * Returns a parser that looks for exactly one character from string, and yields that character. + */ + export function oneOf(string: string): Parser; + + /** + * Returns a parser that looks for exactly one character NOT from string, and yields that character. + */ + export function noneOf(string: string): Parser; + + /** + * Returns a parser that looks for a match to the regexp and yields the given match group + * (defaulting to the entire match). The regexp will always match starting at the current + * parse location. The regexp may only use the following flags: imu. Any other flag will + * result in an error being thrown. + */ + export function regexp(myregex: RegExp, group?: number): Parser; + + /** + * This was the original name for Parsimmon.regexp, but now it is just an alias. + */ + export function regex(myregex: RegExp, group?: number): Parser; + + /** + * Returns a parser that doesn't consume any of the string, and yields result. */ export function succeed(result: U): Parser; - /* - accepts a variable number of parsers that it expects to find in order, yielding an array of the results. + /** + * This is an alias for Parsimmon.succeed(result). */ - export function seq(...parsers: Parser[]): Parser; + export function of(result: U): Parser; + + /** + * accepts a variable number of parsers that it expects to find in order, yielding an array of the results. + */ + export function seq(p1: Parser): Parser<[T]>; + export function seq(p1: Parser, p2: Parser): Parser<[T, U]>; + export function seq(p1: Parser, p2: Parser, p3: Parser): Parser<[T, U, V]>; + export function seq(p1: Parser, p2: Parser, p3: Parser, p4: Parser): Parser<[T, U, V, W]>; + export function seq(p1: Parser, p2: Parser, p3: Parser, p4: Parser, p5: Parser): Parser<[T, U, V, W, X]>; + export function seq(p1: Parser, p2: Parser, p3: Parser, p4: Parser, p5: Parser, p6: Parser): Parser<[T, U, V, W, X, Y]>; + export function seq(p1: Parser, p2: Parser, p3: Parser, p4: Parser, p5: Parser, p6: Parser, p7: Parser): Parser<[T, U, V, W, X, Y, Z]>; + export function seq(...parsers: Parser[]): Parser; export function seq(...parsers: Parser[]): Parser; + /** + * Takes the string passed to parser.parse(string) and the error returned from + * parser.parse(string) and turns it into a human readable error message string. + * Note that there are certainly better ways to format errors, so feel free to write your own. + */ + export function formatError(string: string, error: Result): string; + + /** + * Matches all parsers sequentially, and passes their results as the arguments to a function. + * Similar to calling Parsimmon.seq and then .map, but the values are not put in an array. + */ + export function seqMap(p1: Parser, cb: (a1: T) => U): Parser; + export function seqMap(p1: Parser, p2: Parser, cb: (a1: T, a2: U) => V): Parser; + export function seqMap(p1: Parser, p2: Parser, p3: Parser, cb: (a1: T, a2: U, a3: V) => W): Parser; + export function seqMap(p1: Parser, p2: Parser, p3: Parser, p4: Parser, cb: (a1: T, a2: U, a3: V, a4: W) => X): Parser; + export function seqMap(p1: Parser, p2: Parser, p3: Parser, p4: Parser, p5: Parser, cb: (a1: T, a2: U, a3: V, a4: W, a5: X) => Y): Parser; + export function seqMap(p1: Parser, p2: Parser, p3: Parser, p4: Parser, p5: Parser, p6: Parser, cb: (a1: T, a2: U, a3: V, a4: W, a5: X, a6: Y) => Z): Parser; + export type SuccessFunctionType = (index: number, result: U) => Result; export type FailureFunctionType = (index: number, msg: string) => Result; export type ParseFunctionType = (stream: StreamType, index: number) => Result; - /* - allows to add custom primitive parsers. + /** + * allows to add custom primitive parsers. */ export function custom(parsingFunction: (success: SuccessFunctionType, failure: FailureFunctionType) => ParseFunctionType): Parser; - /* - accepts a variable number of parsers, and yields the value of the first one that succeeds, backtracking in between. + /** + * accepts a variable number of parsers, and yields the value of the first one that succeeds, + * backtracking in between. */ export function alt(...parsers: Parser[]): Parser; export function alt(...parsers: Parser[]): Parser; - /* - accepts a function that returns a parser, which is evaluated the first time the parser is used. This is useful for referencing parsers that haven't yet been defined. + /** + * Accepts two parsers, and expects zero or more matches for content, separated by separator, yielding an array. + */ + export function sepBy(content: Parser, separator: Parser): Parser + + /** + * This is the same as Parsimmon.sepBy, but matches the content parser at least once. + */ + export function sepBy1(content: Parser, separator: Parser): Parser + + /** + * accepts a function that returns a parser, which is evaluated the first time the parser is used. + * This is useful for referencing parsers that haven't yet been defined. */ export function lazy(f: () => Parser): Parser; export function lazy(description: string, f: () => Parser): Parser; - /* - fail paring with a message + /** + * fail paring with a message */ export function fail(message: string): Parser; export function fail(message: string): Parser; - /* - is equivalent to Parsimmon.regex(/[a-z]/i) + /** + * is equivalent to Parsimmon.regex(/[a-z]/i) */ export var letter: Parser; - /* - is equivalent to Parsimmon.regex(/[a-z]*`/i) + /** + * is equivalent to Parsimmon.regex(/[a-z]*`/i) */ export var letters: Parser; - /* - is equivalent to Parsimmon.regex(/[0-9]/) + /** + * is equivalent to Parsimmon.regex(/[0-9]/) */ export var digit: Parser; - /* - is equivalent to Parsimmon.regex(/[0-9]*`/) + /** + * is equivalent to Parsimmon.regex(/[0-9]*`/) */ export var digits: Parser; - /* - is equivalent to Parsimmon.regex(/\s+/) + /** + * is equivalent to Parsimmon.regex(/\s+/) */ export var whitespace: Parser; - /* - is equivalent to Parsimmon.regex(/\s*`/) + /** + * is equivalent to Parsimmon.regex(/\s*`/) */ export var optWhitespace: Parser; - /* - consumes and yields the next character of the stream. + /** + * consumes and yields the next character of the stream. */ export var any: Parser; - /* - consumes and yields the entire remainder of the stream. + /** + * consumes and yields the entire remainder of the stream. */ export var all: Parser; - /* - expects the end of the stream. + /** + * expects the end of the stream. */ export var eof: Parser; - /* - is a parser that yields the current index of the parse. + /** + * is a parser that yields the current index of the parse. */ export var index: Parser; + /** + * Returns a parser that yield a single character if it passes the predicate + */ + export function test(predicate: (char: string) => boolean): Parser; + /** + * Returns a parser yield a string containing all the next characters that pass the predicate + */ + export function takeWhile(predicate: (char: string) => boolean): Parser; } export = Parsimmon; From e41b464073847847e97cb74d4e33d93bc2e1c5c0 Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Mon, 3 Oct 2016 15:14:07 +0200 Subject: [PATCH 15/45] Fix babel-traverse buildCodeFrameError signature (#11654) The Error argument is not an error instance, instead it is a constructor function that returns an error instance. Additionally, the constructor function is optional, by default SyntaxError is used --- babel-traverse/babel-traverse.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/babel-traverse/babel-traverse.d.ts b/babel-traverse/babel-traverse.d.ts index 17cbda2f23..6970c39f6f 100644 --- a/babel-traverse/babel-traverse.d.ts +++ b/babel-traverse/babel-traverse.d.ts @@ -346,7 +346,7 @@ declare module "babel-traverse" { getData(key: string, def?: any): any; - buildCodeFrameError(msg: string, Error: Error): Error; + buildCodeFrameError(msg: string, Error?: new (msg: string) => TError): TError; traverse(visitor: Visitor, state?: any): void; From 261a54b353c16a41380eb8d617c4eda47af9ef0a Mon Sep 17 00:00:00 2001 From: Boriss Nazarovs Date: Mon, 3 Oct 2016 16:15:29 +0300 Subject: [PATCH 16/45] Added type definition for riot library (#11664) * Added type definition for riot * Added type information for compile function, version, settings and template error handler * Updated namespace name Riot -> riot * Renamed riot-test.ts -> riot-tests.ts --- riot/riot-tests.ts | 215 +++++++++++++++++++++++ riot/riot.d.ts | 425 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 640 insertions(+) create mode 100644 riot/riot-tests.ts create mode 100644 riot/riot.d.ts diff --git a/riot/riot-tests.ts b/riot/riot-tests.ts new file mode 100644 index 0000000000..fa94a5e239 --- /dev/null +++ b/riot/riot-tests.ts @@ -0,0 +1,215 @@ +/// + +import * as riot from 'riot'; + +// Version +console.log(riot.version.charAt(0)); + +// Settings +riot.settings.brackets = '[% %]'; + +// errorHandler +riot.util.tmpl.errorHandler = function (err: riot.TemplateError) { + console.error(err.message + ' in ' + err.riotData.tagName); +}; + +// vdom +console.log(riot.vdom[0].opts); + +const mockOpts: any = { + foo: true, + bar: 1, + baz: [1, '2', [3]] +}; + +const tag = riot.mount('test')[0]; + +// Mounting +// mount all custom tags with a class name .customer +var tags: riot.Tag[] = riot.mount('.customer'); +console.log(tags.length); +// mount tag and pass an object as options +riot.mount('account', mockOpts); +// mounts custom tag "my-tag" to div#main with some options +riot.mount('div#main', 'my-tag', mockOpts); +// mounts "users" tag to #slide node and some options +riot.mount(document.getElementById('slide'), 'users', mockOpts); + +// Rendering +console.log(riot.render('test', mockOpts).substr(0, 10)); + +// Updating +// update tag instance +tag.update(); +// update tag instance with context data +tag.update(mockOpts); +// update all mounted tags +riot.update(); + +// Unmounting +// unmount tag +tag.unmount(); +// unmount tag and keep parent tag +tag.unmount(true); + +// Nested tags +// tag should have `tags` property +console.log(tag.tags); +// nested tags can be accessed by name +// multiple tags with same name are collected into array +const nestedTag = tag.tags['test']; +if (nestedTag instanceof riot.Tag) { + nestedTag.unmount(); +} else if (nestedTag instanceof Array) { + nestedTag.push(tag); +} + +// Mixins +interface OptsMixin extends riot.TagMixin { + getOpts(): any; + setOpts(opts: any, update: boolean): OptsMixin; +} +const optsMixin: OptsMixin = { + init() { + this.on('updated', function() { console.log('Updated!') }); + }, + + getOpts() { + return this.opts; + }, + + setOpts(opts, update): OptsMixin { + this.opts = opts; + if (!update) this.update(); + return this; + } +}; +// mixin object +tag.mixin(optsMixin); +// register shared mixin +riot.mixin('optsMixin', optsMixin); +// use shared mixin +tag.mixin('optsMixin'); +// register global mixin and add it to all tag instances +riot.mixin(optsMixin); +// using mixin in tag instances +abstract class TagWithOptsMixin extends riot.Tag implements OptsMixin { + getOpts: () => any; + setOpts: (opts: any, update: boolean) => this; +} +(tag).setOpts(mockOpts, true).getOpts(); + + +// Manual construction +riot.tag('timer', + '

Seconds Elapsed: { time }

', + 'timer { display: block; border: 2px }', + 'class="tic-toc"', + function (opts) { + var self = this; + this.time = opts.start || 0; + + this.tick = function () { + self.update({ time: ++self.time }) + }; + + var timer = setInterval(this.tick, 1000); + + this.on('unmount', function () { + clearInterval(timer) + }); + }); + +// Observable +const cb = () => true; +// can create new observable object +riot.observable().on('test', cb); +// can add observable functionality to existing object +riot.observable({}).on('test', cb); +// all observable methods support fluent interface +riot.observable().on('test', cb).one('test', cb).off('test').off('test', cb) + .trigger('test').trigger('test', 1, 'arg1').on('test', cb); +// tags are observable +tag.on('test', cb).one('test', cb).off('test').off('test', cb) + .trigger('test').trigger('test', 1, 'arg1').unmount(); + + +// Custom tag +class MyTag extends riot.Tag { + public msg: string; + constructor(el: Node) { + super({ tmpl: MyTag.template() }, { root: el }); + this.msg = 'hello'; + } + bye() { + this.msg = 'goodbye'; + } + static template() { + return `

{ msg }

`; + } +} + +new MyTag(document.getElementById('my-div')).bye(); + +// Router +// URL change callback +riot.route(function(collection, id, action) { + console.log(collection + id + action); +}); +// route with filter +riot.route('/fruit', function(name) { + console.log('The list of fruits'); +}); +// query +riot.route('/search..', function() { + var q = riot.route.query(); + console.log('Search keyword: ' + q['keyword']) +}); +// new routing context +var subRoute = riot.route.create(); +subRoute('/fruit/apple', function() { /* */ }); +subRoute.stop(); +// route to URL +riot.route('customers/267393/edit'); +riot.route('customers/267393/edit', 'Editing customer page'); +riot.route('not-found', 'Not found', true); +// start +riot.route.start(); +riot.route.start(true); +// stop +riot.route.stop(); +// exec +riot.route.exec(); +riot.route.exec(cb); +// base +riot.route.base('/app'); +// parser +const firstParser = function first(path: string): string[] { + const raw = path.slice(2).split('?'); + return raw[0].split('/'); +}; +riot.route.parser(firstParser); +const secondParser = function second(path: string, filter: string): string[] { + const re = new RegExp('^' + filter.replace(/\*/g, '([^/?#]+?)').replace(/\.\./, '.*') + '$'); + const args = path.match(re); + if (args) { + return args.slice(1); + } +}; +riot.route.parser(firstParser, secondParser); + +// Compile +// compiling all tags +riot.compile(function() { + riot.mount('*') +}); +// compiling url +riot.compile('my/tags.tag', function() { + // the loaded tags are ready to be used +}); +// compiling tag definition +let compiled = riot.compile(`

Hello, World!

`); +console.log(compiled.charAt(0)); +// compiling without execution +compiled = riot.compile(`

Hello, World!

`, true); +console.log(compiled.charAt(0)); diff --git a/riot/riot.d.ts b/riot/riot.d.ts new file mode 100644 index 0000000000..3abb3fa147 --- /dev/null +++ b/riot/riot.d.ts @@ -0,0 +1,425 @@ +// Type definitions for riot v2.6.0 +// Project: https://github.com/riot/riot +// Definitions by: Boriss Nazarovs +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare namespace riot { + /** + * Current version number as string + */ + const version: string; + + /** + * Riot settings + */ + interface Settings { + /** + * Setting used to customize the start and end tokens of the expression + */ + brackets: string; + } + + const settings: Settings; + + interface TemplateError extends Error { + riotData: { + tagName: string; + } + } + + interface Util { + tmpl: { + errorHandler(error: TemplateError): void; + } + } + + const util: Util; + + /** + * Internal riot tags cache + */ + const vdom: Tag[]; + + interface Observable { + /** + * Register callback for specified events. + * Callback is executed each time event is triggered + * @param events Space separated list of events or wildcard '*' that matches all events + * @param callback Callback function + */ + on?(events: string, callback: Function): Observable; + + /** + * Register callback for specified events. + * Callback is executed at most once. + * @param events Space separated list of events. + * @param callback Callback function + */ + one?(events: string, callback: Function): Observable; + + /** + * Remove all registered callbacks for specified events + * @param events Space separated list of events or wildcard '*' that matches all events + */ + off?(events: string): Observable; + + /** + * Remove specified callback for specified events + * @param events Space separated list of events or wildcard '*' that matches all events + * @param callback Callback function to remove + */ + off?(events: string, callback: Function): Observable; + + /** + * Execute all callback functions registered for specified list of events + * @param events Space separated list of events + * @param args Arguments provided to callbacks + */ + trigger?(events: string, ...args: any[]): Observable; + } + + /** + * Riot Router + */ + interface Route { + /** + * Register callback that is executed when the URL changes + * @param callback Callback function + */ + (callback: (...args: any[]) => void): void; + + /** + * Register callback that is executed when the URL changes and new URL matches specified filter + * @param filter URL filter + * @param callback Callback function + */ + (filter: string, callback: (...any: string[]) => void): void; + + /** + * Change the browser URL and notify all the listeners registered with `Route(callback)` + * @param to New URL + * @param title Document title for new URL + * @param shouldReplace Should new url replace the current history + */ + (to: string, title?: string, shouldReplace?: boolean): void; + + /** + * Return a new routing context + */ + create(): Route; + + /** + * Start listening for url changes + * @param autoExec Should router exec routing on the current url + */ + start(autoExec?: boolean): void; + + /** + * Stop all the routings. + * Removes the listeners and clears the callbacks. + */ + stop(): void; + + /** + * Study the current browser path “in place” and emit routing without waiting for it to change. + */ + exec(): void; + + /** + * @deprecated + */ + exec(callback: Function): void; + + /** + * Extract query from the url + */ + query(): { [key: string]: string }; + + /** + * Change the base path + * @param base Base path + */ + base(base: string): void; + + /** + * Change the default parsers to the custom ones. + * @param parser Replacement parser for default parser + * @param secondParser Replacement parser for handling url filters + */ + parser(parser: (path: string) => any[], secondParser?: (path: string, filter: string) => any[]): void; + } + + /** + * Adds Observer support for the given object or + * if the argument is empty a new observable instance is created and returned. + * @param el Object to become observable + */ + function observable(el?: any): Observable; + + const route: Route; + + /** + * Mount custom tags with specified tag name. Returns an array of mounted tag instances. + * @param selector Tag selector. + * It can be tag name, css selector or special '*' selector that matches all tags on the page. + * @param opts Optional object passed for the tags to consume. + */ + function mount(selector: string, opts?: any): Tag[]; + + /** + * Mount a custom tag on DOM nodes matching provided selector. Returns an array of mounted tag instances. + * @param selector CSS selector + * @param tagName Custom tag name + * @param opts Optional object passed for the tag to consume. + */ + function mount(selector: string, tagName: string, opts?: any): Tag[]; + + /** + * Mount a custom tag on a given DOM node. Returns an array of mounted tag instances. + * @param domNode DOM node + * @param tagName Tag name + * @param opts Optional object passed for the tag to consume. + */ + function mount(domNode: Node, tagName: string, opts?: any): Tag[]; + + /** + * Render a tag to html. This method is only available on server-side. + * @param tagName Custom tag name + * @param opts Optional object passed for the tag to consume. + */ + function render(tagName: string, opts?: any): string; + + /** + * Update all the mounted tags and their expressions on the page. + * Returns an array of tag instances that are mounted on the page. + */ + function update(): Tag[]; + + /** + * Register a global mixin and automatically add it to all tag instances. + * @param mixinObject Mixin object + */ + function mixin(mixinObject: TagMixin): void; + + /** + * Register a shared mixin, globally available to be used in any tag using `TagInstance.mixin(mixinName)` + * @param mixinName Name of the mixin + * @param mixinObject Mixin object + */ + function mixin(mixinName: string, mixinObject: TagMixin): void; + + /** + * Create a new custom tag “manually” without the compiler. Returns name of the tag. + * @param tagName The tag name + * @param html The layout with expressions + * @param css The style of the tag + * @param attrs String of attributes for the tag + * @param constructor The initialization function being called before + * the tag expressions are calculated and before the tag is mounted + */ + function tag(tagName: string, html: string, css?: string, attrs?: string, constructor?: (opts: any) => void): string; + + + interface TagImplementation { + /** + * Tag template + */ + tmpl: string; + /** + * The callback function called on the mount event + * @param opts Tag options object + */ + fn?(opts: any): void; + /** + * Root tag html attributes as object (key => value) + */ + attrs?: { + [key: string]: any; + } + } + + interface TagConfiguration { + /** + * DOM node where you will mount the tag template + */ + root: Node; + /** + * Tag options + */ + opts?: any; + /** + * Is it used in as loop tag + */ + isLoop?: boolean; + /** + * Is already registered using `riot.tag` + */ + hasImpl?: boolean; + /** + * Loop item in the loop assigned to this instance + */ + item?: any; + } + + interface TagInterface extends Observable { + /** + * options object + */ + opts?: any; + /** + * the parent tag if any + */ + parent?: Tag; + /** + * root DOM node + */ + root?: Node; + /** + * nested custom tags + */ + tags?: { + [key: string]: Tag | Tag[]; + }; + + /** + * Updates all the expressions on the current tag instance as well as on all the children. + * @param data Context data + */ + update?(data?: any): void; + + /** + * Extend tag with functionality available on shared mixin registered with `riot.mixin(mixinName, mixinObject)` + * @param mixinName Name of shared mixin + */ + mixin?(mixinName: string): void; + + /** + * Extend tag functionality with functionality available on provided mixin object. + * @param mixinObject Mixin object + */ + mixin?(mixinObject: TagMixin): void; + + /** + * Mount the tag + */ + mount?(): void; + + /** + * Detach the tag and its children from the page. + * @param keepTheParent If `true` unmounting tag doesn't remove the parent tag + */ + unmount?(keepTheParent?: boolean): void; + } + + + class Tag implements TagInterface { + /** + * Tag constructor + * @param impl Tag implementation + * @param conf Tag configuration + * @param innerHTML HTML that can be used replacing a nested `yield` tag in its template + */ + constructor(impl: TagImplementation, conf: TagConfiguration, innerHTML?: string); + + /** + * options object + */ + opts: any; + /** + * the parent tag if any + */ + parent: Tag; + /** + * root DOM node + */ + root: Node; + /** + * nested custom tags + */ + tags: { + [key: string]: Tag | Tag[]; + }; + + /** + * Updates all the expressions on the current tag instance as well as on all the children. + * @param data Context data + */ + update(data?: any): void; + + /** + * Extend tag with functionality available on shared mixin registered with `riot.mixin(mixinName, mixinObject)` + * @param mixinName Name of shared mixin + */ + mixin(mixinName: string): void; + + /** + * Extend tag functionality with functionality available on provided mixin object. + * @param mixinObject Mixin object + */ + mixin(mixinObject: TagMixin): void; + + /** + * Mount the tag + */ + mount(): void; + + /** + * Detach the tag and its children from the page. + * @param keepTheParent If `true` unmounting tag doesn't remove the parent tag + */ + unmount(keepTheParent?: boolean): void; + + // Observable methods + on(events: string, callback: Function): this; + one(events: string, callback: Function): this; + off(events: string): this; + off(events: string, callback: Function): this; + trigger(events: string, ...args: any[]): this; + } + + /** + * Mixin object for extending tag functionality. + * When it gets mixed in it has access to all tag properties. + * It should not override any built in tag properties + */ + interface TagMixin extends TagInterface { + /** + * Special method which can initialize + * the mixin when it's loaded to the tag and is not + * accessible from the tag its mixed in + */ + init?(): void; + } + + /** + * Compile all tags defined with