From 450a4269958da2ea62985def8163df18ec4a24b4 Mon Sep 17 00:00:00 2001 From: Andy Date: Thu, 19 Jan 2017 06:37:32 -0800 Subject: [PATCH 01/17] Set `"target": "es6"` where necessary. (#14111) --- README.md | 2 +- atom/atom-tests.ts | 11 ++++------- co-body/tsconfig.json | 1 + fs-promise/tsconfig.json | 1 + hapi-decorators/tsconfig.json | 1 + koa-hbs/tsconfig.json | 1 + koa-passport/tsconfig.json | 1 + koa-send/tsconfig.json | 1 + lodash-decorators/tsconfig.json | 1 + pg-pool/tsconfig.json | 1 + websocket/tsconfig.json | 1 + 11 files changed, 14 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 1ffdd93a1b..4940649a6e 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,7 @@ Your package should have this structure: Generate these by running `npm run new-package -- new-package-name`. -You may edit the `tsconfig.json` to add new files, to add to `"lib"`, or to add the `"jsx"` compiler option. +You may edit the `tsconfig.json` to add new files, to add `"target": "es6"` (needed for async functions), to add to `"lib"`, or to add the `"jsx"` compiler option. DefinitelyTyped members routinely monitor for new PRs, though keep in mind that the number of other PRs may slow things down. diff --git a/atom/atom-tests.ts b/atom/atom-tests.ts index 8d35578e69..37b2fb314c 100644 --- a/atom/atom-tests.ts +++ b/atom/atom-tests.ts @@ -7,6 +7,8 @@ import _atom = require("atom"); import PathWatcher = require("pathwatcher"); var File = PathWatcher.File; +const jq: JQuery = $("selector"); + class SampleView extends _atom.ScrollView { editorId:string; @@ -33,11 +35,6 @@ class SampleView extends _atom.ScrollView { } } - get jq():JQuery { - // dirty hack - return this; - } - serialize() { return { deserializer: 'SampleView', @@ -52,9 +49,9 @@ class SampleView extends _atom.ScrollView { resolveEditor(editorId:string) { var resolve = ()=> { if (this.editor) { - this.jq.trigger("title-changed"); + jq.trigger("title-changed"); } else { - var view = this.jq.parents('.pane').view(); + var view = jq.parents('.pane').view(); if (view) { view.destroyItem(this); } diff --git a/co-body/tsconfig.json b/co-body/tsconfig.json index 5c7e4122cc..32601a074a 100644 --- a/co-body/tsconfig.json +++ b/co-body/tsconfig.json @@ -1,6 +1,7 @@ { "compilerOptions": { "module": "commonjs", + "target": "es6", "lib": [ "es6" ], diff --git a/fs-promise/tsconfig.json b/fs-promise/tsconfig.json index 8cf124c15b..0c1c0f6a74 100644 --- a/fs-promise/tsconfig.json +++ b/fs-promise/tsconfig.json @@ -1,6 +1,7 @@ { "compilerOptions": { "module": "commonjs", + "target": "es6", "lib": [ "es6" ], diff --git a/hapi-decorators/tsconfig.json b/hapi-decorators/tsconfig.json index 37e80b60a7..ebd36039d9 100644 --- a/hapi-decorators/tsconfig.json +++ b/hapi-decorators/tsconfig.json @@ -1,6 +1,7 @@ { "compilerOptions": { "module": "commonjs", + "target": "es6", "lib": [ "es6" ], diff --git a/koa-hbs/tsconfig.json b/koa-hbs/tsconfig.json index 2cbbd3a89e..5e0b9691a4 100644 --- a/koa-hbs/tsconfig.json +++ b/koa-hbs/tsconfig.json @@ -1,6 +1,7 @@ { "compilerOptions": { "module": "commonjs", + "target": "es6", "lib": [ "es6" ], diff --git a/koa-passport/tsconfig.json b/koa-passport/tsconfig.json index d08d38dc0a..90d49d7c29 100644 --- a/koa-passport/tsconfig.json +++ b/koa-passport/tsconfig.json @@ -1,6 +1,7 @@ { "compilerOptions": { "module": "commonjs", + "target": "es6", "lib": [ "es6" ], diff --git a/koa-send/tsconfig.json b/koa-send/tsconfig.json index fa9266e3c4..97cf5eeb16 100644 --- a/koa-send/tsconfig.json +++ b/koa-send/tsconfig.json @@ -1,6 +1,7 @@ { "compilerOptions": { "module": "commonjs", + "target": "es6", "lib": [ "es6" ], diff --git a/lodash-decorators/tsconfig.json b/lodash-decorators/tsconfig.json index f0e0708cde..22d610d56e 100644 --- a/lodash-decorators/tsconfig.json +++ b/lodash-decorators/tsconfig.json @@ -1,6 +1,7 @@ { "compilerOptions": { "module": "commonjs", + "target": "es6", "lib": [ "es6", "dom" diff --git a/pg-pool/tsconfig.json b/pg-pool/tsconfig.json index d6e3aa4103..7d97d43d22 100644 --- a/pg-pool/tsconfig.json +++ b/pg-pool/tsconfig.json @@ -1,6 +1,7 @@ { "compilerOptions": { "module": "commonjs", + "target": "es6", "lib": [ "es6" ], diff --git a/websocket/tsconfig.json b/websocket/tsconfig.json index b57411e6ff..d77bfdfbe2 100644 --- a/websocket/tsconfig.json +++ b/websocket/tsconfig.json @@ -1,6 +1,7 @@ { "compilerOptions": { "module": "commonjs", + "target": "es6", "lib": [ "es6" ], From 461eb311875c7525cb3646909a42671964a9ceeb Mon Sep 17 00:00:00 2001 From: Pat Sissons Date: Thu, 19 Jan 2017 09:29:50 -0800 Subject: [PATCH 02/17] Updating rx-dom typings to be module style instead of ambient style (#14105) * transitioning from ambient style typings to module style typings * adding some notes to test file * merging redundant definitions * updating version to match the current rx-dom version * adding lint config --- rx-dom/index.d.ts | 199 ++++++++++++++++++++--------------------- rx-dom/rx-dom-tests.ts | 9 +- rx-dom/tslint.json | 8 ++ 3 files changed, 115 insertions(+), 101 deletions(-) create mode 100644 rx-dom/tslint.json diff --git a/rx-dom/index.d.ts b/rx-dom/index.d.ts index 00fca183d9..9b612021af 100644 --- a/rx-dom/index.d.ts +++ b/rx-dom/index.d.ts @@ -1,142 +1,141 @@ -// Type definitions for RxJS v2.5.3 +// Type definitions for RxJS 7.0 // Project: https://github.com/Reactive-Extensions/RxJS-DOM // Definitions by: oliver Weichhold // Definitions: https://github.com/borisyankov/DefinitelyTyped -/// +import * as Rx from 'rx'; -declare module Rx.DOM { - export interface AjaxSettings { - async?: boolean; - body?: string; - // This options does not seem to be used in the code yet - // contentType?: string; - crossDomain?: boolean; - headers?: any; - method?: string; - password?: string; - progressObserver?: Rx.Observer; - responseType?: string; - url?: string; - user?: string; +declare module 'rx' { + namespace DOM { + interface AjaxSettings { + async?: boolean; + body?: string; + // This options does not seem to be used in the code yet + // contentType?: string; + crossDomain?: boolean; + headers?: any; + method?: string; + password?: string; + progressObserver?: Rx.Observer; + responseType?: string; + url?: string; + user?: string; } - export interface AjaxSuccessResponse { - response: any; - status: number; - responseType: string; - xhr: XMLHttpRequest; - originalEvent: Event; + interface AjaxSuccessResponse { + response: any; + status: number; + responseType: string; + xhr: XMLHttpRequest; + originalEvent: Event; } - export interface AjaxErrorResponse { - type: string; - status: number; - xhr: XMLHttpRequest; - originalEvent: Event; + interface AjaxErrorResponse { + type: string; + status: number; + xhr: XMLHttpRequest; + originalEvent: Event; } - export interface JsonpSettings { - async?: boolean; - jsonp?: string; - jsonpCallback?: string; - url?: string; + interface JsonpSettings { + async?: boolean; + jsonp?: string; + jsonpCallback?: string; + url?: string; } - export interface JsonpSuccessResponse { - response: any; - status: number; - responseType: string; - originalEvent: Event; + interface JsonpSuccessResponse { + response: any; + status: number; + responseType: string; + originalEvent: Event; } - export interface JsonpErrorResponse { - type: string; - status: number; - originalEvent: Event; + interface JsonpErrorResponse { + type: string; + status: number; + originalEvent: Event; } - export interface GeolocationOptions { - enableHighAccuracy?: boolean; - timeout?: number; - maximumAge?: number; + interface GeolocationOptions { + enableHighAccuracy?: boolean; + timeout?: number; + maximumAge?: number; } // Events - function fromEvent(element:any, eventName:string, selector?:Function, useCapture?:boolean):Rx.Observable; + function fromEvent(element: any, eventName: string, selector?: Function, useCapture?: boolean): Rx.Observable; - function ready():Rx.Observable; + function ready(): Rx.Observable; // Event Shortcuts - function blur(element: Element, selector?:Function, useCapture?:boolean):Rx.Observable; - function change(element: Element, selector?:Function):Rx.Observable; - function click(element: Element, selector?:Function, useCapture?:boolean):Rx.Observable; - function contextmenu(element: Element, selector?:Function, useCapture?:boolean):Rx.Observable; - function dblclick(element: Element, selector?:Function, useCapture?:boolean):Rx.Observable; - function error(element: Element, selector?:Function, useCapture?:boolean):Rx.Observable; - function focus(element: Element, selector?:Function, useCapture?:boolean):Rx.Observable; - function focusin(element: Element, selector?:Function, useCapture?:boolean):Rx.Observable; - function focusout(element: Element, selector?:Function, useCapture?:boolean):Rx.Observable; - function keydown(element: Element, selector?:Function, useCapture?:boolean):Rx.Observable; - function keypress(element: Element, selector?:Function, useCapture?:boolean):Rx.Observable; - function keyup(element: Element, selector?:Function, useCapture?:boolean):Rx.Observable; - function load(element: Element, selector?:Function, useCapture?:boolean):Rx.Observable; - function mousedown(element: Element, selector?:Function, useCapture?:boolean):Rx.Observable; - function mouseenter(element: Element, selector?:Function, useCapture?:boolean):Rx.Observable; - function mouseleave(element: Element, selector?:Function, useCapture?:boolean):Rx.Observable; - function mousemove(element: Element, selector?:Function, useCapture?:boolean):Rx.Observable; - function mouseout(element: Element, selector?:Function, useCapture?:boolean):Rx.Observable; - function mouseover(element: Element, selector?:Function, useCapture?:boolean):Rx.Observable; - function mouseup(element: Element, selector?:Function, useCapture?:boolean):Rx.Observable; - function resize(element: Element, selector?:Function, useCapture?:boolean):Rx.Observable; - function scroll(element: Element, selector?:Function, useCapture?:boolean):Rx.Observable; - function select(element: Element, selector?:Function, useCapture?:boolean):Rx.Observable; - function submit(element: Element, selector?:Function, useCapture?:boolean):Rx.Observable; - function unload(element: Element, selector?:Function, useCapture?:boolean):Rx.Observable; + function blur(element: Element, selector?: Function, useCapture?: boolean): Rx.Observable; + function change(element: Element, selector?: Function): Rx.Observable; + function click(element: Element, selector?: Function, useCapture?: boolean): Rx.Observable; + function contextmenu(element: Element, selector?: Function, useCapture?: boolean): Rx.Observable; + function dblclick(element: Element, selector?: Function, useCapture?: boolean): Rx.Observable; + function error(element: Element, selector?: Function, useCapture?: boolean): Rx.Observable; + function focus(element: Element, selector?: Function, useCapture?: boolean): Rx.Observable; + function focusin(element: Element, selector?: Function, useCapture?: boolean): Rx.Observable; + function focusout(element: Element, selector?: Function, useCapture?: boolean): Rx.Observable; + function keydown(element: Element, selector?: Function, useCapture?: boolean): Rx.Observable; + function keypress(element: Element, selector?: Function, useCapture?: boolean): Rx.Observable; + function keyup(element: Element, selector?: Function, useCapture?: boolean): Rx.Observable; + function load(element: Element, selector?: Function, useCapture?: boolean): Rx.Observable; + function mousedown(element: Element, selector?: Function, useCapture?: boolean): Rx.Observable; + function mouseenter(element: Element, selector?: Function, useCapture?: boolean): Rx.Observable; + function mouseleave(element: Element, selector?: Function, useCapture?: boolean): Rx.Observable; + function mousemove(element: Element, selector?: Function, useCapture?: boolean): Rx.Observable; + function mouseout(element: Element, selector?: Function, useCapture?: boolean): Rx.Observable; + function mouseover(element: Element, selector?: Function, useCapture?: boolean): Rx.Observable; + function mouseup(element: Element, selector?: Function, useCapture?: boolean): Rx.Observable; + function resize(element: Element, selector?: Function, useCapture?: boolean): Rx.Observable; + function scroll(element: Element, selector?: Function, useCapture?: boolean): Rx.Observable; + function select(element: Element, selector?: Function, useCapture?: boolean): Rx.Observable; + function submit(element: Element, selector?: Function, useCapture?: boolean): Rx.Observable; + function unload(element: Element, selector?: Function, useCapture?: boolean): Rx.Observable; // Pointer Events - function pointerdown(element: Element, selector?:Function, useCapture?:boolean):Rx.Observable; - function pointerenter(element: Element, selector?:Function, useCapture?:boolean):Rx.Observable; - function pointerleave(element: Element, selector?:Function, useCapture?:boolean):Rx.Observable; - function pointermove(element: Element, selector?:Function, useCapture?:boolean):Rx.Observable; - function pointerout(element: Element, selector?:Function, useCapture?:boolean):Rx.Observable; - function pointerover(element: Element, selector?:Function, useCapture?:boolean):Rx.Observable; - function pointerup(element: Element, selector?:Function, useCapture?:boolean):Rx.Observable; + function pointerdown(element: Element, selector?: Function, useCapture?: boolean): Rx.Observable; + function pointerenter(element: Element, selector?: Function, useCapture?: boolean): Rx.Observable; + function pointerleave(element: Element, selector?: Function, useCapture?: boolean): Rx.Observable; + function pointermove(element: Element, selector?: Function, useCapture?: boolean): Rx.Observable; + function pointerout(element: Element, selector?: Function, useCapture?: boolean): Rx.Observable; + function pointerover(element: Element, selector?: Function, useCapture?: boolean): Rx.Observable; + function pointerup(element: Element, selector?: Function, useCapture?: boolean): Rx.Observable; // Touch Events - function touchcancel(element: Element, selector?:Function, useCapture?:boolean):Rx.Observable; - function touchend(element: Element, selector?:Function, useCapture?:boolean):Rx.Observable; - function touchmove(element: Element, selector?:Function, useCapture?:boolean):Rx.Observable; - function touchstart(element: Element, selector?:Function, useCapture?:boolean):Rx.Observable; + function touchcancel(element: Element, selector?: Function, useCapture?: boolean): Rx.Observable; + function touchend(element: Element, selector?: Function, useCapture?: boolean): Rx.Observable; + function touchmove(element: Element, selector?: Function, useCapture?: boolean): Rx.Observable; + function touchstart(element: Element, selector?: Function, useCapture?: boolean): Rx.Observable; // Ajax - function ajax(url:string):Rx.Observable; - function ajax(settings:AjaxSettings):Rx.Observable; - function get(url:string):Rx.Observable; - function getJSON(url:string):Rx.Observable; - function post(url:string, body:any):Rx.Observable; - function jsonpRequest(url:string):Rx.Observable; - function jsonpRequest(settings:JsonpSettings):Rx.Observable; + function ajax(settingsOrUrl: AjaxSettings | string): Rx.Observable; + function get(url: string): Rx.Observable; + function getJSON(url: string): Rx.Observable; + function post(url: string, body: any): Rx.Observable; + function jsonpRequest(url: string): Rx.Observable; + function jsonpRequest(settings: JsonpSettings): Rx.Observable; // Server-Sent Events - function fromEventSource(url:string, openObservable?:Rx.Observer):Rx.Observable; + function fromEventSource(url: string, openObservable?: Rx.Observer): Rx.Observable; // Web Sockets - function fromWebSocket(url:string, protocol:string, openObserver?:Rx.Observer, closingObserver?:Rx.Observer):Rx.Subject; + function fromWebSocket(url: string, protocol: string, openObserver?: Rx.Observer, closingObserver?: Rx.Observer): Rx.Subject; // Web Workers - function fromWebWorker(url:string):Rx.Subject; + function fromWebWorker(url: string): Rx.Subject; // Mutation Observers - function fromMutationObserver(target:Node, options:MutationObserverInit):Rx.Observable; + function fromMutationObserver(target: Node, options: MutationObserverInit): Rx.Observable; // Geolocation - export module geolocation { - function getCurrentPosition(geolocationOptions?:GeolocationOptions):Rx.Observable; - function watchPosition(geolocationOptions?:GeolocationOptions):Rx.Observable; + namespace geolocation { + function getCurrentPosition(geolocationOptions?: GeolocationOptions): Rx.Observable; + function watchPosition(geolocationOptions?: GeolocationOptions): Rx.Observable; } + } } -declare module "rx-dom" { - export default Rx.DOM; -} \ No newline at end of file +export = Rx; diff --git a/rx-dom/rx-dom-tests.ts b/rx-dom/rx-dom-tests.ts index 4a97a9d0d4..5aba285388 100644 --- a/rx-dom/rx-dom-tests.ts +++ b/rx-dom/rx-dom-tests.ts @@ -1,2 +1,9 @@ import * as Rx from 'rx'; -import * as DOM from 'rx-dom'; \ No newline at end of file +import * as DOM from 'rx-dom'; + +// Rx and DOM should both be the same reference +// before rx-dom import, Rx will not contain the DOM namespace +// after rx-dom import, Rx will contain the DOM namespace + +// this is the standard approach for importing rx + rx-dom +import { Observable, Subject, DOM as rxdom } from 'rx-dom'; diff --git a/rx-dom/tslint.json b/rx-dom/tslint.json new file mode 100644 index 0000000000..7ec0b302e1 --- /dev/null +++ b/rx-dom/tslint.json @@ -0,0 +1,8 @@ +{ + "extends": "../tslint.json", + "rules": { + // this package augments Rx with namespace level functions + // it would be particualrly strange to type these functions differently + "forbidden-types": false + } +} From 98b47fbc86a350d1baed86e3d0c7bf64c8decb16 Mon Sep 17 00:00:00 2001 From: pgonzal Date: Thu, 19 Jan 2017 18:30:59 +0100 Subject: [PATCH 03/17] Fix z-schema module definition and add SchemaErrorDetail (#14005) * Fix module declaration so that helper interfaces are usable again * Introduce SchemaErrorDetail since getLastError() and getLastErrors() return two distinct types; add documentation * Fix unit tests, add explicit type declarations * Transferred project ownership from Adam * Eliminated ambient external module by making Validator into a merged class and namespace --- z-schema/index.d.ts | 170 ++++++++++++++++++++++++------------- z-schema/z-schema-tests.ts | 11 ++- 2 files changed, 115 insertions(+), 66 deletions(-) diff --git a/z-schema/index.d.ts b/z-schema/index.d.ts index f49e677158..695866a7e9 100644 --- a/z-schema/index.d.ts +++ b/z-schema/index.d.ts @@ -1,13 +1,9 @@ // Type definitions for z-schema v3.16.0 // Project: https://github.com/zaggino/z-schema -// Definitions by: Adam Meadows +// Definitions by: pgonzal // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -export = ZSchema.Validator; -export as namespace ZSchema; - -declare namespace ZSchema { - +declare namespace Validator { export interface Options { asyncTimeout?: number; forceAdditional?: boolean; @@ -31,66 +27,120 @@ declare namespace ZSchema { ignoreUnknownFormats?: boolean; } - export interface SchemaError { - code: string; - description: string; + export interface SchemaError extends Error { + /** + * Implements the Error.name contract. The value is always "z-schema validation error". + */ + name: string; + + /** + * An identifier indicating the type of error. + * Example: "JSON_OBJECT_VALIDATION_FAILED" + */ message: string; - params: string[]; + + /** + * Returns details for each error that occurred during validation. + * See Options.breakOnFirstError. + */ + details: SchemaErrorDetail[]; + } + + export interface SchemaErrorDetail { + /** + * Example: "Expected type string but found type array" + */ + message: string; + /** + * An error identifier that can be used to format a custom error message. + * Example: "INVALID_TYPE" + */ + code: string; + /** + * Format parameters that can be used to format a custom error message. + * Example: ["string","array"] + */ + params: Array; + /** + * A JSON path indicating the location of the error. + * Example: "#/projects/1" + */ path: string; + /** + * The schema rule description, which is included for certain errors where + * this information is useful (e.g. to describe a constraint). + */ + description: string; + + /** + * Returns details for sub-schemas that failed to match. For example, if the schema + * uses the "oneOf" constraint to accept several alternative possibilities, each + * alternative will have its own inner detail object explaining why it failed to match. + */ + inner: SchemaErrorDetail[]; } +} - export class Validator { - - /** - * Register a custom format. - * - * @param name - name of the custom format - * @param validatorFunction - custom format validator function. - * Returns `true` if `value` matches the custom format. - */ - public static registerFormat(formatName: string, validatorFunction: (value: any) => boolean): void; +declare class Validator { + /** + * Register a custom format. + * + * @param name - name of the custom format + * @param validatorFunction - custom format validator function. + * Returns `true` if `value` matches the custom format. + */ + public static registerFormat(formatName: string, validatorFunction: (value: any) => boolean): void; - /** - * Unregister a format. - * - * @param name - name of the custom format - */ - public static unregisterFormat(name: string): void; - - /** - * Get the list of all registered formats. - * - * Both the names of the burned-in formats and the custom format names are - * returned by this function. - * - * @returns {string[]} the list of all registered format names. - */ - public static getRegisteredFormats(): string[]; - - public static getDefaultOptions(): Options; - - constructor(options: Options); + /** + * Unregister a format. + * + * @param name - name of the custom format + */ + public static unregisterFormat(name: string): void; - /** - * @param schema - JSON object representing schema - * @returns {boolean} true if schema is valid. - */ - validateSchema(schema: any): boolean; + /** + * Get the list of all registered formats. + * + * Both the names of the burned-in formats and the custom format names are + * returned by this function. + * + * @returns {string[]} the list of all registered format names. + */ + public static getRegisteredFormats(): string[]; - /** - * @param json - either a JSON string or a parsed JSON object - * @param schema - the JSON object representing the schema - * @returns true if json matches schema - */ - validate(json: any, schema: any): boolean; + public static getDefaultOptions(): Validator.Options; - /** - * @param json - either a JSON string or a parsed JSON object - * @param schema - the JSON object representing the schema - */ - validate(json: any, schema: any, callback: (err: any, valid: boolean) => void): void; + constructor(options: Validator.Options); - getLastError(): SchemaError; - getLastErrors(): SchemaError[]; - } -} \ No newline at end of file + /** + * @param schema - JSON object representing schema + * @returns {boolean} true if schema is valid. + */ + validateSchema(schema: any): boolean; + + /** + * @param json - either a JSON string or a parsed JSON object + * @param schema - the JSON object representing the schema + * @returns true if json matches schema + */ + validate(json: any, schema: any): boolean; + + /** + * @param json - either a JSON string or a parsed JSON object + * @param schema - the JSON object representing the schema + */ + validate(json: any, schema: any, callback: (err: any, valid: boolean) => void): void; + + /** + * Returns an Error object for the most recent failed validation, or null if the validation was successful. + */ + getLastError(): Validator.SchemaError; + + /** + * Returns the error details for the most recent validation, or undefined if the validation was successful. + * This is the same list as the SchemaError.details property. + */ + getLastErrors(): Validator.SchemaErrorDetail[]; +} + +export = Validator; diff --git a/z-schema/z-schema-tests.ts b/z-schema/z-schema-tests.ts index 042c5dfe62..9f1c81ff7f 100644 --- a/z-schema/z-schema-tests.ts +++ b/z-schema/z-schema-tests.ts @@ -1,13 +1,12 @@ +import Validator = require('z-schema'); -import ZSchema = require('z-schema'); - -var options = { +var options: Validator.Options = { noTypeless: true, forceItems: true, }; -var validator = new ZSchema(options); +var validator: Validator = new Validator(options); var json: any = { foo: 'bar', }; @@ -31,5 +30,5 @@ validator.validate(json, schema, function (err: any, valid: boolean) { } }); -var error = validator.getLastError(); -var errors = validator.getLastErrors(); +var error: Validator.SchemaError = validator.getLastError(); +var errors: Validator.SchemaErrorDetail[] = validator.getLastErrors(); From d7f8c99d4e8c7b455725ac8fb7c63935302531c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=AD=90=E6=AF=85?= Date: Fri, 20 Jan 2017 01:32:56 +0800 Subject: [PATCH 04/17] [gaea] Add Gaea Editor's types, namespace 'Gaea' (#13524) * add Gaea * use cli * fix * fix * update * update * fix bug * recover package.json * rename test file --- gaea-model/gaea-model-tests.ts | 8 + gaea-model/index.d.ts | 491 +++++++++++++++++++++++++++++++++ gaea-model/tsconfig.json | 20 ++ gaea-model/tslint.json | 1 + 4 files changed, 520 insertions(+) create mode 100644 gaea-model/gaea-model-tests.ts create mode 100644 gaea-model/index.d.ts create mode 100644 gaea-model/tsconfig.json create mode 100644 gaea-model/tslint.json diff --git a/gaea-model/gaea-model-tests.ts b/gaea-model/gaea-model-tests.ts new file mode 100644 index 0000000000..1615c039e8 --- /dev/null +++ b/gaea-model/gaea-model-tests.ts @@ -0,0 +1,8 @@ +function nameSpaceTest() { + let components = {} as GaeaModel.ViewportComponentInfo + // insert into parent + components.props = { + gaeaUniqueKey: '123', + gaeaName: 'componentName' + } +} \ No newline at end of file diff --git a/gaea-model/index.d.ts b/gaea-model/index.d.ts new file mode 100644 index 0000000000..769a1658d0 --- /dev/null +++ b/gaea-model/index.d.ts @@ -0,0 +1,491 @@ +// Type definitions for gaea-model 1.0 +// Project: https://github.com/ascoders/gaea-model +// Definitions by: ascoders +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +import * as React from 'react'; + +export as namespace GaeaModel; + +export type Component = React.ComponentClass; + +/** + * 组件信息 + */ +export interface ComponentProps extends React.HTMLProps { + /** + * 唯一的 key,用来唯一标识这个组件,所有盖亚内部组件都以 gaea-old- 为前缀 + */ + gaeaUniqueKey: string; + /** + * 组件的中文名 + */ + gaeaName: string; + /** + * 组件图标,为 fontAwesome + */ + gaeaIcon?: string; + /** + * 编辑信息 + */ + gaeaEdit?: ComponentPropsGaeaEdit[]; + /** + * 事件定义 + */ + gaeaEvent?: GaeaEvent; + /** + * 是否在预览模式,preivew 会传入 true + */ + gaeaPreview?: boolean; + /** + * 是否可以拖入子元素 + */ + canDragIn?: boolean; + /** + * 存储事件设置 + */ + gaeaEventData?: EventData[]; + /** + * 存储native事件设置 + */ + gaeaNativeEventData?: EventData[]; + /** + * 存储变量信息 + */ + gaeaVariables?: { + [field: string]: VariableData; + }; + + [x: string]: any; +} + +/** + * 组件配置中数组配置 + */ +export interface ComponentPropsOptionsArray extends ComponentPropsGaeaEdit { + key: string; +} + +/** + * 组件配置中数组配置的值 + */ +export interface ComponentPropsOptionsArrayValue { + /** + * ComponentPropsOptionsArray 设置的 key + */ + key: string; + /** + * 用户填入的值 + */ + value: number | string; +} + +/** + * 组件配置 选择器配置 + */ +export interface ComponentPropsOptionsSelector { + key: string; + value: string; +} + +/** + * number 配置项 + */ +export interface Number { + // 为空时,是数字,否则会以字符串加后缀形式赋值 + key: string; + value: string; +} + +/** + * 组件的值 + */ +export type ComponentPropsOptionValue = number | string | boolean | ComponentPropsOptionsArrayValue[] | any; + +/** + * 组件配置 + */ +export interface ComponentPropsGaeaEdit { + /** + * 对应字段名 + */ + field: string; + /** + * 选项名称 + */ + label: string; + /** + * 编辑器类型 + */ + editor: string; + /** + * 是否可被编辑 + */ + editable: boolean; + /** + * 是否隐藏编辑工具 + */ + hideTool: boolean; + /** + * 当 editor 为 array 时的数组配置 + * 数组中的 key,和填入的值,会作为 Array 填入到 value 中 + */ + array?: ComponentPropsOptionsArrayValue[]; + /** + * 当 editor 为 selector 时的数组配置 + */ + selector?: ComponentPropsOptionsSelector[]; + /** + * 值类型, 默认为字符串 + */ + type?: string; + /** + * 为空时的值,默认为 null + */ + emptyValue?: any; + /** + * 控制 number 单位 + */ + number?: { + units: number[]; + currentUnit: string; + max?: number; + min?: number; + step?: number; + speed?: number; + inputRange?: number[]; + outputRange?: number[]; + slider?: boolean; + }; + /** + * 枚举实例 + */ + instance?: Array<{ + [key: string]: ComponentPropsOptionValue; + }>; +} + +/** + * 组合信息 + */ +export interface ComboComponentInfo extends ViewportComponentFullInfo { + // 组合名 + name: string; +} + +/** + * 获取发布列表的返回值 + */ +export interface GetPublishListResult { + // 版本 + version: string; + // 描述 + description: string; +} + +/** + * 版本信息 + */ +export interface VersionInfo { + content: string; +} + +/** + * 事件设置 + */ +export interface GaeaEvent { + triggers: EventTriggerCondition[]; + effects: EventAction[]; +} + +export interface EventData { + type: string; + event: string; + /** + * 因为事件可能 type 相同,因此记录是第几个 + */ + typeIndex: number; + eventIndex: number; + typeData?: EventTriggerEvent; + eventData?: EventActionJumpUrl | EventActionCall | EventActionEvent; +} + +export interface EventTriggerCondition { + name: string; + // 触发类型 + type: string; + // 是否由自己的生命周期触发 + selfCallback?: boolean; +} + +export interface EventAction { + name: string; + // 动作类型 + // call: 调用传进来的方法 + // jumpUrl: 跳转一个网址 + type: string; + call?: EventCallType; +} + +/** + * 事件定义类型 + */ +export interface EventCallType { + // 调用函数名称 + functionName: string; + // 调用参数 + param?: EventCallTypeParam[]; +} + +export interface EventCallTypeParam { + label: string; + field: string; + editor: string; // text +} + +/** + * 事件触发数据类型 + */ +export interface EventTriggerEvent { + listen?: string; +} + +export interface EventUpdatePropsEvent { + /** + * 修改后的 props + */ + props: ComponentProps; +} + +/** + * 事件动作数据类型 + */ +export interface EventActionJumpUrl { + url?: string; +} + +export interface EventActionCall { + // 函数在 map 里的 key + key?: string; +} + +export interface EventActionEvent { + emit?: string; +} + +export interface ExternalParameter { + /** + * 名称 + */ + name: string; + /** + * 类型 + * number string boolean + */ + type: string; +} + +/** + * 标识哪些字段用什么变量 + */ +export interface VariableData { + // 变量类型 + // 比如是外部传参,还是全局变量 + variableType: string; + // 变量的哪个字段 + variableField: string; + // 值类型 string number boolean + valueType: string; +} + +/** + * 插件信息 + */ +export interface Plugin extends React.ComponentClass { + // 插件安放位置 + position: string; + Action?: any; + Store?: any; +} + +/******************************************************************************************************** + * DIff + ********************************************************************************************************/ +export interface Diff { + // 操作类型 + type: 'add' | 'move' | 'remove' | 'exchange' | 'update' | 'paste' | 'reset' | 'addCombo' | 'addSource'; + // 操作组件的 mapUniqueKey + mapUniqueKey: string; + // 新增操作 + add?: { + // 新增组件的唯一标识 id + uniqueId: string; + // 父级 mapKey + parentMapUniqueKey: string; + // 插入的位置 + index: number; + }; + // 移动到另一个父元素 + move?: { + // 移动到的父级 mapKey + targetParentMapUniqueKey: string; + // 移动前父级 mapKey + sourceParentMapUniqueKey: string; + // 插入的位置 + targetIndex: number; + // 移除的位置 + sourceIndex: number; + }; + // 删除组件 + remove?: DiffRemove; + // 内部交换顺序 + exchange?: { + oldIndex: number; + newIndex: number; + }; + // 更新操作 + update?: { + oldValue: ComponentProps; + newValue: ComponentProps; + }; + // 粘贴操作 + paste?: DiffRemove; + // 重置组件 + reset?: { + // 重置前的信息 + beforeProps: ComponentProps; + beforeName: string; + }; + // 新增组合 + addCombo?: { + // 父级 mapKey + parentMapUniqueKey: string; + // 父级的 index + index: number; + // 组合的完整信息(不是 copy 的, 是真正对应的 mapUniqueKey) + componentInfo: ViewportComponentFullInfo; + }; + // 新增模板 + addSource?: { + // 父级 mapKey + parentMapUniqueKey: string; + // 父级的 index + index: number; + // 组合的完整信息(不是 copy 的, 是真正对应的 mapUniqueKey) + componentInfo: ViewportComponentFullInfo; + }; +} + +export interface DiffRemove extends ViewportComponentFullInfo { + // 父级元素 mapKey + parentMapUniqueKey: string; + // 删除的位置 + index: number; +} + +/******************************************************************************************************** + * Viewport + ********************************************************************************************************/ +/** + * 在视图中的组件属性 + */ +export interface ViewportComponentInfo { + /** + * props + */ + props: ComponentProps; + /** + * 子元素(canDragIn才有) + * 只存子元素在 map 中的 key + */ + layoutChilds?: string[]; + /** + * 父级 mapUniqueKey, 这样不但方便寻找父级,还能根据是否为 null 判断是否为根元素 + */ + parentMapUniqueKey: string; +} + +/** + * 当前正在移动元素的信息 + */ +export interface MovingComponent { + // 在编辑区域的组件信息 + mapUniqueKey: string; + // 是否是新拖拽的 + isNew: boolean; + // 组件的唯一标识, 新建的时候采用 + uniqueKey: string; + // 直接给 source 就直接用 + source: string; +} + +/** + * hover 元素的信息 + */ +export interface HoverComponentSpec { + left: number; + top: number; + width: number; + height: number; + hovering: boolean; +} + +/** + * 一个独立组件的完整信息 + */ +export interface ViewportComponentFullInfo { + // 组件的 mapUniqueKey + mapUniqueKey: string; + // 组件信息 + componentInfo: ViewportComponentInfo; + // 子元素列表 (包括非直接子集) + childs: { + [mapUniqueKey: string]: ViewportComponentInfo; + }; +} + +/** + * 当前拖拽元素信息 + */ +export interface CurrentDragComponentInfo { + // 类型 + type: 'new' | 'combo' | 'viewport'; + // 开始拖拽父级的 dom + dragStartParentElement: HTMLElement; + // 开始拖拽在父级中的位置 + dragStartIndex: number; + newInfo?: { + // 唯一 key,用来实例化组件 + uniqueKey: string; + }; + comboInfo?: { + // combo 信息 + source: string; + }; + viewportInfo?: { + // 当前拖拽组件的 mapUniqueKey + mapUniqueKey: string; + // 拖拽目标的 mapUniqueKey + targetMapUniqueKey?: string; + // 拖拽目标的 index + targetIndex?: number; + }; +} + +/******************************************************************************************************** + * Event + ********************************************************************************************************/ +/** + * 鼠标移动到组件上/树对应的组件上 + */ +export interface MouseHoverComponentEvent { + mapUniqueKey: string; + type: string; +} + +/** + * 修改某个组件选中状态 + */ +export interface ComponentSelectStatusEvent { + mapUniqueKey: string; + selected: boolean; +} diff --git a/gaea-model/tsconfig.json b/gaea-model/tsconfig.json new file mode 100644 index 0000000000..05d346427a --- /dev/null +++ b/gaea-model/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "noImplicitAny": true, + "strictNullChecks": true, + "noImplicitThis": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "gaea-model-tests.ts" + ] +} diff --git a/gaea-model/tslint.json b/gaea-model/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/gaea-model/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" } From 130f8c921f57d722ef8abc442901020e62b2803d Mon Sep 17 00:00:00 2001 From: Arne Schubert Date: Thu, 19 Jan 2017 18:36:13 +0100 Subject: [PATCH 05/17] Sqlite3 fix nullChecks in static test (#14098) * Improove typing to the new guidelines * Replace Function type --- sqlite3/index.d.ts | 83 ++++++++++++++++++++-------------------- sqlite3/sqlite3-tests.ts | 2 +- sqlite3/tslint.json | 1 + 3 files changed, 43 insertions(+), 43 deletions(-) create mode 100644 sqlite3/tslint.json diff --git a/sqlite3/index.d.ts b/sqlite3/index.d.ts index 82a968d7eb..19828e2b3f 100644 --- a/sqlite3/index.d.ts +++ b/sqlite3/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for sqlite3 2.2.3 +// Type definitions for sqlite3 2.2 // Project: https://github.com/mapbox/node-sqlite3 // Definitions by: Nick Malaguti // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -23,67 +23,66 @@ export interface RunResult { } export declare class Statement { - public bind(callback?: (err: Error) => void): Statement; - public bind(...params: any[]): Statement; + bind(callback?: (err: Error) => void): Statement; + bind(...params: any[]): Statement; - public reset(callback?: (err: Error) => void): Statement; + reset(callback?: (err: Error) => void): Statement; - public finalize(callback?: (err: Error) => void): Statement; + finalize(callback?: (err: Error) => void): Statement; - public run(callback?: (err: Error) => void): Statement; - public run(params: any, callback?: (err: Error) => void): Statement; - public run(...params: any[]): Statement; + run(callback?: (err: Error) => void): Statement; + run(params: any, callback?: (err: Error) => void): Statement; + run(...params: any[]): Statement; - public get(callback?: (err: Error, row: any) => void): Statement; - public get(params: any, callback?: (err: Error, row: any) => void): Statement; - public get(...params: any[]): Statement; + get(callback?: (err: Error, row: any) => void): Statement; + get(params: any, callback?: (err: Error, row: any) => void): Statement; + get(...params: any[]): Statement; - public all(callback?: (err: Error, rows: any[]) => void): Statement; - public all(params: any, callback?: (err: Error, rows: any[]) => void): Statement; - public all(...params: any[]): Statement; + all(callback?: (err: Error, rows: any[]) => void): Statement; + all(params: any, callback?: (err: Error, rows: any[]) => void): Statement; + all(...params: any[]): Statement; - public each(callback?: (err: Error, row: any) => void, complete?: (err: Error, count: number) => void): Statement; - public each(params: any, callback?: (err: Error, row: any) => void, complete?: (err: Error, count: number) => void): Statement; - public each(...params: any[]): Statement; + each(callback?: (err: Error, row: any) => void, complete?: (err: Error, count: number) => void): Statement; + each(params: any, callback?: (err: Error, row: any) => void, complete?: (err: Error, count: number) => void): Statement; + each(...params: any[]): Statement; } export declare class Database extends events.EventEmitter { constructor(filename: string, callback?: (err: Error) => void); constructor(filename: string, mode?: number, callback?: (err: Error) => void); - public close(callback?: (err: Error) => void): void; + close(callback?: (err: Error) => void): void; - public run(sql: string, callback?: (err: Error) => void): Database; - public run(sql: string, params: any, callback?: (err: Error) => void): Database; - public run(sql: string, ...params: any[]): Database; + run(sql: string, callback?: (err: Error) => void): Database; + run(sql: string, params: any, callback?: (err: Error) => void): Database; + run(sql: string, ...params: any[]): Database; - public get(sql: string, callback?: (err: Error, row: any) => void): Database; - public get(sql: string, params: any, callback?: (err: Error, row: any) => void): Database; - public get(sql: string, ...params: any[]): Database; + get(sql: string, callback?: (err: Error, row: any) => void): Database; + get(sql: string, params: any, callback?: (err: Error, row: any) => void): Database; + get(sql: string, ...params: any[]): Database; - public all(sql: string, callback?: (err: Error, rows: any[]) => void): Database; - public all(sql: string, params: any, callback?: (err: Error, rows: any[]) => void): Database; - public all(sql: string, ...params: any[]): Database; + all(sql: string, callback?: (err: Error, rows: any[]) => void): Database; + all(sql: string, params: any, callback?: (err: Error, rows: any[]) => void): Database; + all(sql: string, ...params: any[]): Database; - public each(sql: string, callback?: (err: Error, row: any) => void, complete?: (err: Error, count: number) => void): Database; - public each(sql: string, params: any, callback?: (err: Error, row: any) => void, complete?: (err: Error, count: number) => void): Database; - public each(sql: string, ...params: any[]): Database; + each(sql: string, callback?: (err: Error, row: any) => void, complete?: (err: Error, count: number) => void): Database; + each(sql: string, params: any, callback?: (err: Error, row: any) => void, complete?: (err: Error, count: number) => void): Database; + each(sql: string, ...params: any[]): Database; - public exec(sql: string, callback?: (err: Error) => void): Database; + exec(sql: string, callback?: (err: Error) => void): Database; - public prepare(sql: string, callback?: (err: Error) => void): Statement; - public prepare(sql: string, params: any, callback?: (err: Error) => void): Statement; - public prepare(sql: string, ...params: any[]): Statement; + prepare(sql: string, callback?: (err: Error) => void): Statement; + prepare(sql: string, params: any, callback?: (err: Error) => void): Statement; + prepare(sql: string, ...params: any[]): Statement; - public serialize(callback?: () => void): void; - public parallelize(callback?: () => void): void; + serialize(callback?: () => void): void; + parallelize(callback?: () => void): void; - public on(event: "trace", listener: (sql: string) => void): this; - public on(event: "profile", listener: (sql: string, time: number) => void): this; - public on(event: "error", listener: (err: Error) => void): this; - public on(event: "open", listener: () => void): this; - public on(event: "close", listener: () => void): this; - public on(event: string, listener: Function): this; + on(event: "trace", listener: (sql: string) => void): this; + on(event: "profile", listener: (sql: string, time: number) => void): this; + on(event: "error", listener: (err: Error) => void): this; + on(event: "open" | "close", listener: () => void): this; + on(event: string, listener: (...args: any[]) => void): this; } declare function verbose(): void; diff --git a/sqlite3/sqlite3-tests.ts b/sqlite3/sqlite3-tests.ts index a264c4024f..5e13fd7840 100644 --- a/sqlite3/sqlite3-tests.ts +++ b/sqlite3/sqlite3-tests.ts @@ -2,7 +2,7 @@ import sqlite3 = require('sqlite3'); sqlite3.verbose(); -var db: sqlite3.Database; +var db: sqlite3.Database = new sqlite3.Database('chain.sqlite3', () => {}); function createDb() { console.log("createDb chain"); diff --git a/sqlite3/tslint.json b/sqlite3/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/sqlite3/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" } From aee5331d05e9ca5bbacef7af6a71324c1096bbc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Par=C3=A9?= Date: Thu, 19 Jan 2017 12:52:00 -0500 Subject: [PATCH 06/17] add npm payment (#14121) * add npm payment * tslint + test --- payment/index.d.ts | 87 ++++++++++++++++++++++++++++++++++++++++ payment/payment-tests.ts | 16 ++++++++ payment/tsconfig.json | 20 +++++++++ payment/tslint.json | 1 + 4 files changed, 124 insertions(+) create mode 100644 payment/index.d.ts create mode 100644 payment/payment-tests.ts create mode 100644 payment/tsconfig.json create mode 100644 payment/tslint.json diff --git a/payment/index.d.ts b/payment/index.d.ts new file mode 100644 index 0000000000..e635a19028 --- /dev/null +++ b/payment/index.d.ts @@ -0,0 +1,87 @@ +// Type definitions for payment 2.1 +// Project: https://github.com/jessepollak/payment#readme +// Definitions by: Alexandre Paré +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +interface Fns { + /** + * Validates a card number: + * * Validates numbers + * * Validates Luhn algorithm + * * Validates length + */ + validateCardNumber(cardNumber: string): boolean; + /** + * Validates a card expiry: + * * Validates numbers + * * Validates in the future + * * Supports year shorthand + * * Supports formatted as formatCardExpiry input value + */ + validateCardExpiry(monthYear: string, year?: string): boolean; + /** + * Validates a card CVC: + * * Validates number + * * Validates length to 4 + */ + validateCardCVC(cvc: string, type: string): boolean; + /** + * Returns a card type. Either: + * * visa + * * mastercard + * * discover + * * amex + * * jcb + * * dinersclub + * * maestro + * * laser + * * unionpay + * * elo + * + * The function will return null if the card type can't be determined. + */ + cardType(cardNumber: string): string; + /** + * Parses a credit card expiry in the form of MM/YYYY, returning an object containing the `month` and `year`. + * Shorthand years, such as `13` are also supported (and converted into the longhand, e.g. `2013`). + */ + cardExpiryVal(monthYear: string | HTMLInputElement): MonthYear; +} + +interface MonthYear { + month: number; + year: number; +} + +declare var Payment: { + /** + * Formats card numbers: + * * Includes a space between every 4 digits + * * Restricts input to numbers + * * Limits to 16 numbers + * * Supports American Express formatting + * * Adds a class of the card type (e.g. 'visa') to the input + */ + formatCardNumber(elem: HTMLInputElement): HTMLInputElement; + /** + * Formats card expiry: + * * Includes a / between the month and year + * * Restricts input to numbers + * * Restricts length + */ + formatCardExpiry(elem: HTMLInputElement): HTMLInputElement; + /** + * Formats card CVC: + * * Restricts length to 4 numbers + * * Restricts input to numbers + */ + formatCardCVC(elem: HTMLInputElement): HTMLInputElement; + /** + * General numeric input restriction. + */ + restrictNumeric(elem: HTMLInputElement): HTMLInputElement; + + fns: Fns; +}; + +export = Payment; diff --git a/payment/payment-tests.ts b/payment/payment-tests.ts new file mode 100644 index 0000000000..5601067419 --- /dev/null +++ b/payment/payment-tests.ts @@ -0,0 +1,16 @@ +import * as Payment from "payment"; + +var input = document.getElementById('input') as HTMLInputElement; + +Payment.restrictNumeric(input); +Payment.formatCardNumber(input); +Payment.formatCardExpiry(input); +Payment.formatCardCVC(input); + +var card = "1234 5678 9012 3456"; + +var cardType = Payment.fns.cardType(card); +Payment.fns.validateCardNumber(card); +Payment.fns.validateCardExpiry("1 / 20"); +Payment.fns.validateCardExpiry("1", "20"); +Payment.fns.validateCardCVC("123", cardType); \ No newline at end of file diff --git a/payment/tsconfig.json b/payment/tsconfig.json new file mode 100644 index 0000000000..0b2323bef2 --- /dev/null +++ b/payment/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "payment-tests.ts" + ] +} diff --git a/payment/tslint.json b/payment/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/payment/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" } From 205f2ffa697318710ec9984a721226d38ee5fe09 Mon Sep 17 00:00:00 2001 From: scippio Date: Thu, 19 Jan 2017 19:05:38 +0100 Subject: [PATCH 07/17] end() method with callback (#13705) added callback into end() method --- pg/index.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pg/index.d.ts b/pg/index.d.ts index 84414b451d..75f3f33dd5 100644 --- a/pg/index.d.ts +++ b/pg/index.d.ts @@ -9,7 +9,7 @@ import events = require("events"); import stream = require("stream"); - import pgTypes = require("pg-types"); +import pgTypes = require("pg-types"); export declare function connect(connection: string, callback: (err: Error, client: Client, done: (err?: any) => void) => void): void; export declare function connect(config: ClientConfig, callback: (err: Error, client: Client, done: (err?: any) => void) => void): void; @@ -92,8 +92,8 @@ export declare class Client extends events.EventEmitter { constructor(connection: string); constructor(config: ClientConfig); - connect(callback?: (err:Error) => void): void; - end(): void; + connect(callback?: (err:Error) => void): void; + end(callback?: (err: Error) => void): void; release(): void; query(queryText: string): Promise; From fd5dc234aaa7c6ea536baa5596877637a3bad2bf Mon Sep 17 00:00:00 2001 From: David Herges Date: Thu, 19 Jan 2017 22:05:26 +0100 Subject: [PATCH 08/17] update type definitions for numeraljs (#14120) --- numeral/index.d.ts | 42 +++++++++++++++++++++++++++++++++--- numeral/numeral-tests.ts | 46 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 3 deletions(-) diff --git a/numeral/index.d.ts b/numeral/index.d.ts index c19caef255..e48cfa6f3d 100644 --- a/numeral/index.d.ts +++ b/numeral/index.d.ts @@ -3,7 +3,9 @@ // Definitions by: Vincent Bortone // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -interface NumeralJSLanguage { + +// http://numeraljs.com/#locales +interface NumeralJSLocale { delimiters: { thousands: string; decimal: string; @@ -20,12 +22,43 @@ interface NumeralJSLanguage { }; } + +// http://numeraljs.com/#custom-formats +interface NumeralJsFormat { + regexps: { + format: RegExp, + unformat: RegExp, + }, + format: (value: any, format: string, roundingFunction: Function) => string, + unformat: (value: string) => number +} + +type RegisterType = 'format' | 'locale'; + +// http://numeraljs.com/#use-it interface Numeral { (value?: any): Numeral; version: string; isNumeral: boolean; - language(key?: string, values?: NumeralJSLanguage): Numeral | string; - zeroFormat(format: string): string; + + /** + * This function sets the current locale. If no arguments are passed in, + * it will simply return the current global locale key. + */ + locale(key?: string): string; + + /** + * Registers a language definition or a custom format definition. + * + * @param what Allowed values are: either 'format' or 'locale' + * @param key The key of the registerd type, e.g. 'de' for a german locale definition + * @param value The locale definition or the format definitiion + */ + register(what: RegisterType, key: string, value: NumeralJSLocale | NumeralJsFormat): NumeralJSLocale | NumeralJsFormat; + + zeroFormat(format: string): void; + nullFormat(format: string): void; + defaultFormat(format: string): void; clone(): Numeral; format(inputString?: string): string; formatCurrency(inputString?: string): string; @@ -42,6 +75,9 @@ interface Numeral { declare var numeral: Numeral; +/** + * Usage: import * as numeral from 'numeral' + */ declare module "numeral" { export = numeral; diff --git a/numeral/numeral-tests.ts b/numeral/numeral-tests.ts index 6202b16b0e..7be34cc8f9 100644 --- a/numeral/numeral-tests.ts +++ b/numeral/numeral-tests.ts @@ -41,3 +41,49 @@ var bVal: number = b.value(); // 1000 var cVal: number = c.add(10).value(); // 1010 + + +// Formats +numeral.register('format', 'percentage', { + regexps: { + format: /(%)/, + unformat: /(%)/ + }, + format: function(value, format, roundingFunction) { + return 'foo'; + }, + unformat: function(string) { + return 123; + } +}); + +var customFormatted = numeral().format('0%'); + + +// Locales +// load a locale +numeral.register('locale', 'fr', { + delimiters: { + thousands: ' ', + decimal: ',' + }, + abbreviations: { + thousand: 'k', + million: 'm', + billion: 'b', + trillion: 't' + }, + ordinal : function (number) { + return number === 1 ? 'er' : 'ème'; + }, + currency: { + symbol: '€' + } +}); + +// switch between locales +numeral.locale('fr'); + +// return the current locale +numeral.locale(); +// 'fr' From 6afd3751f739ff190c4bd3ba856a8947c5cb4eea Mon Sep 17 00:00:00 2001 From: Sergei Dorogin Date: Fri, 20 Jan 2017 00:05:40 +0300 Subject: [PATCH 09/17] jquery.fileupload (#14123) added JQueryFileUploadXhr.headers field --- jquery.fileupload/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/jquery.fileupload/index.d.ts b/jquery.fileupload/index.d.ts index 8eba9853b2..54ebb89c5c 100644 --- a/jquery.fileupload/index.d.ts +++ b/jquery.fileupload/index.d.ts @@ -284,6 +284,7 @@ interface JQueryFileUploadXhr { jqXHR: JQueryXHR; result: any; textStatus: string; + headers: {[key: string]: any}; } interface JQueryFileUploadFilesObject { From c137711a1bf5dbcd502fa9d077f414cc96ef1c97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20=C5=81aziuk?= Date: Thu, 19 Jan 2017 22:06:52 +0100 Subject: [PATCH 10/17] [parse-torrent] version bump to 5.8, webtorrent changes (#14100) * parse-torrent and dependencies * partial fix * encode-decode fix --- magnet-uri/index.d.ts | 35 +++++++++++ magnet-uri/magnet-uri-tests.ts | 8 +++ magnet-uri/tsconfig.json | 23 +++++++ magnet-uri/tslint.json | 3 + parse-torrent-file/index.d.ts | 62 +++++++++++++++++++ .../parse-torrent-file-tests.ts | 12 ++++ parse-torrent-file/tsconfig.json | 23 +++++++ parse-torrent-file/tslint.json | 3 + parse-torrent/index.d.ts | 53 +++++++--------- parse-torrent/parse-torrent-tests.ts | 35 +++++------ parse-torrent/tslint.json | 3 + webtorrent/index.d.ts | 4 +- 12 files changed, 213 insertions(+), 51 deletions(-) create mode 100644 magnet-uri/index.d.ts create mode 100644 magnet-uri/magnet-uri-tests.ts create mode 100644 magnet-uri/tsconfig.json create mode 100644 magnet-uri/tslint.json create mode 100644 parse-torrent-file/index.d.ts create mode 100644 parse-torrent-file/parse-torrent-file-tests.ts create mode 100644 parse-torrent-file/tsconfig.json create mode 100644 parse-torrent-file/tslint.json create mode 100644 parse-torrent/tslint.json diff --git a/magnet-uri/index.d.ts b/magnet-uri/index.d.ts new file mode 100644 index 0000000000..80a3e64858 --- /dev/null +++ b/magnet-uri/index.d.ts @@ -0,0 +1,35 @@ +// Type definitions for magnet-uri 5.1 +// Project: https://github.com/feross/magnet-uri +// Definitions by: Tomasz Łaziuk +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +declare const MagnetUri: MagnetUri.MagnetUri; + +declare namespace MagnetUri { + export interface MagnetUri { + (uri: string): Instance; + decode(uri: string): Instance; + encode(parsed: Instance): string; + } + + export interface Instance extends Object { + dn?: string | string[]; + tr?: string | string[]; + xs?: string | string[]; + as?: string | string[]; + ws?: string | string[]; + kt?: string[]; + ix?: number | number[]; + xt?: string | string[]; + infoHash?: string; + infoHashBuffer?: Buffer; + name?: string | string[]; + keywords?: string | string[]; + announce?: string[]; + urlList?: string[]; + } +} + +export = MagnetUri; diff --git a/magnet-uri/magnet-uri-tests.ts b/magnet-uri/magnet-uri-tests.ts new file mode 100644 index 0000000000..ee97fb3451 --- /dev/null +++ b/magnet-uri/magnet-uri-tests.ts @@ -0,0 +1,8 @@ +import * as magnet from 'magnet-uri'; + +// "Leaves of Grass" by Walt Whitman +const uri = 'magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36&dn=Leaves+of+Grass+by+Walt+Whitman.epub&tr=udp%3A%2F%2Ftracker.example4.com%3A80&tr=udp%3A%2F%2Ftracker.example5.com%3A80&tr=udp%3A%2F%2Ftracker.example3.com%3A6969&tr=udp%3A%2F%2Ftracker.example2.com%3A80&tr=udp%3A%2F%2Ftracker.example1.com%3A1337'; + +const parsed = magnet.decode(uri); +console.log(parsed); +console.log(magnet.encode(parsed)); diff --git a/magnet-uri/tsconfig.json b/magnet-uri/tsconfig.json new file mode 100644 index 0000000000..ed2ea4e527 --- /dev/null +++ b/magnet-uri/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "magnet-uri-tests.ts" + ] +} diff --git a/magnet-uri/tslint.json b/magnet-uri/tslint.json new file mode 100644 index 0000000000..ec365f164b --- /dev/null +++ b/magnet-uri/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "../tslint.json" +} diff --git a/parse-torrent-file/index.d.ts b/parse-torrent-file/index.d.ts new file mode 100644 index 0000000000..cd0837938a --- /dev/null +++ b/parse-torrent-file/index.d.ts @@ -0,0 +1,62 @@ +// Type definitions for parse-torrent-file 4.0 +// Project: https://github.com/feross/parse-torrent-file +// Definitions by: Tomasz Łaziuk +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +declare const ParseTorrentFile: ParseTorrentFile.ParseTorrentFile; + +declare namespace ParseTorrentFile { + export interface TorrentInfo { + 'name.utf-8'?: string; + name?: string; + files?: File[]; + 'piece length'?: number; + pieces?: number; + private?: boolean; + } + + export interface Torrent { + info?: TorrentInfo; + 'creation date'?: number; + 'created by'?: string; + comment?: Buffer; + 'announce-list'?: string[][]; + announce?: string; + 'url-list'?: Buffer; + } + + export interface ParseTorrentFile { + (torrent: Buffer | Torrent): Instance; + decode(torrent: Buffer | Torrent): Instance; + encode(parsed: Instance): Buffer; + } + + export interface ParsedFile { + path: string; + name: string; + length: number; + offset: number; + } + + export interface Instance extends Object { + info?: TorrentInfo; + infoBuffer?: Buffer; + infoHash?: string; + infoHashBuffer?: Buffer; + name?: string; + private?: boolean; + created?: Date; + createdBy?: string; + announce?: string[]; + urlList?: string[]; + pieceLength?: number; + lastPieceLength?: number; + pieces?: string[]; + length?: number; + files?: ParsedFile[]; + } +} + +export = ParseTorrentFile; diff --git a/parse-torrent-file/parse-torrent-file-tests.ts b/parse-torrent-file/parse-torrent-file-tests.ts new file mode 100644 index 0000000000..4a6b6a1dae --- /dev/null +++ b/parse-torrent-file/parse-torrent-file-tests.ts @@ -0,0 +1,12 @@ +import * as parseTorrentFile from 'parse-torrent-file'; +import * as fs from 'fs'; + +const torrent = fs.readFileSync(__filename); +try { + const parsed = parseTorrentFile(torrent); + console.log(parsed.name); +} catch (e) { + // the torrent file was corrupt + console.error(e); +} + diff --git a/parse-torrent-file/tsconfig.json b/parse-torrent-file/tsconfig.json new file mode 100644 index 0000000000..ea57d0f586 --- /dev/null +++ b/parse-torrent-file/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "parse-torrent-file-tests.ts" + ] +} diff --git a/parse-torrent-file/tslint.json b/parse-torrent-file/tslint.json new file mode 100644 index 0000000000..ec365f164b --- /dev/null +++ b/parse-torrent-file/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "../tslint.json" +} diff --git a/parse-torrent/index.d.ts b/parse-torrent/index.d.ts index 787f03ce6b..e256cfd2ed 100644 --- a/parse-torrent/index.d.ts +++ b/parse-torrent/index.d.ts @@ -1,40 +1,35 @@ -// Type definitions for parse-torrent +// Type definitions for parse-torrent 5.8 // Project: https://github.com/feross/parse-torrent -// Definitions by: Bazyli Brzóska +// Definitions by: Bazyli Brzóska , Tomasz Łaziuk // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// -declare var ParseTorrent:ParseTorrent.StaticInstance; -export = ParseTorrent; +import * as MagnetUri from 'magnet-uri'; +import * as ParseTorrentFile from 'parse-torrent-file'; + +declare const ParseTorrent: ParseTorrent.ParseTorrent; declare namespace ParseTorrent { - export interface ParsedTorrent { - infoHash:string; - xt?:string; - info?: { length:number, name:Buffer, 'piece length':number, pieces:Buffer }; - infoBuffer?:Buffer; - name?:string; - private?:boolean; - created?:Date; - comment?:string; - announce?:Array; - urlList?:Array; - files?:Array<{path:string, name:string, length: number, offset:number}>; - length?:number; - pieceLength?:number; - lastPieceLength?:number; - pieces?:Array; - } - interface StaticInstance { - (magnetUriOrInfoHash:string):ParsedTorrent; - (torrentFileOrInfoHash:Buffer):{ info:ParsedTorrent }; + interface ParseTorrent { + (torrent: string): MagnetUri.Instance; + (torrent: Buffer): MagnetUri.Instance | ParseTorrentFile.Instance; + (torrent: Instance | MagnetUri.Instance | ParseTorrentFile.Instance): Instance; - toMagnetURI(parsedTorrent:ParsedTorrent):string; - toTorrentFile(parsedTorrent:{ info:ParsedTorrent }):Buffer; + toMagnetURI: typeof MagnetUri.encode; + toTorrentFile: typeof ParseTorrentFile.encode; + + remote(torrent: string | Buffer | Instance | MagnetUri.Instance | ParseTorrentFile.Instance | Blob, cb?: (err: Error, torrent?: Instance) => void): void; + } + + export interface Instance extends MagnetUri.Instance, ParseTorrentFile.Instance { + infoHash: string; + name?: string; + announce?: string[]; + urlList?: string[]; + } - remote(remoteURLorLocalTorrentPath:string, onTorrentCallback?:(err:Error, parsedTorrent:ParsedTorrent)=>void):void; - remote(torrentBlob:Blob, onTorrentCallback?:(err:Error, parsedTorrent:ParsedTorrent)=>void):void; - } } + +export = ParseTorrent; diff --git a/parse-torrent/parse-torrent-tests.ts b/parse-torrent/parse-torrent-tests.ts index 0b00888c9b..dc20ff79e6 100644 --- a/parse-torrent/parse-torrent-tests.ts +++ b/parse-torrent/parse-torrent-tests.ts @@ -1,37 +1,35 @@ - - -import parseTorrent = require('parse-torrent'); +import * as parseTorrent from 'parse-torrent'; import * as fs from 'fs'; // info hash (as a hex string) -parseTorrent('d2474e86c95b19b8bcfdb92bc12c9d44667cfa36') +parseTorrent('d2474e86c95b19b8bcfdb92bc12c9d44667cfa36'); // { infoHash: 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36' } // info hash (as a Buffer) -parseTorrent(new Buffer('d2474e86c95b19b8bcfdb92bc12c9d44667cfa36', 'hex')) +parseTorrent(new Buffer('d2474e86c95b19b8bcfdb92bc12c9d44667cfa36', 'hex')); // { infoHash: 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36' } // magnet uri (as a utf8 string) -parseTorrent('magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36') +parseTorrent('magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36'); // { xt: 'urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36', // infoHash: 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36' } // magnet uri with torrent name -parseTorrent('magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36&dn=Leaves%20of%20Grass%20by%20Walt%20Whitman.epub') +parseTorrent('magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36&dn=Leaves%20of%20Grass%20by%20Walt%20Whitman.epub'); // { xt: 'urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36', // dn: 'Leaves of Grass by Walt Whitman.epub', // infoHash: 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36', // name: 'Leaves of Grass by Walt Whitman.epub' } // magnet uri with trackers -parseTorrent('magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36&tr=http%3A%2F%2Ftracker.example.com%2Fannounce') +parseTorrent('magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36&tr=http%3A%2F%2Ftracker.example.com%2Fannounce'); // { xt: 'urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36', // tr: 'http://tracker.example.com/announce', // infoHash: 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36', // announce: [ 'http://tracker.example.com/announce' ] } // .torrent file (as a Buffer) -parseTorrent(fs.readFileSync(__dirname + '/torrents/leaves.torrent')) +parseTorrent(fs.readFileSync(__dirname + '/torrents/leaves.torrent')); // { info: // { length: 362017, // name: , @@ -80,18 +78,15 @@ parseTorrent(fs.readFileSync(__dirname + '/torrents/leaves.torrent')) // 'c698de9b0dad92980906c026d8c1408fa08fe4ec' ] } var uri = parseTorrent.toMagnetURI({ - infoHash: 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36' -}) + infoHash: 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36', +}); var buf = parseTorrent.toTorrentFile({ - info: { - infoHash: 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36' - /* ... */ - } -}) + infoHash: 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36', +}); -parseTorrent.remote('d2474e86c95b19b8bcfdb92bc12c9d44667cfa36', function (err, parsedTorrent) { - // if (err) throw err - // console.log(parsedTorrent) -}) +parseTorrent.remote('d2474e86c95b19b8bcfdb92bc12c9d44667cfa36', function(err, parsedTorrent) { + // if (err) throw err + // console.log(parsedTorrent) +}); diff --git a/parse-torrent/tslint.json b/parse-torrent/tslint.json new file mode 100644 index 0000000000..ec365f164b --- /dev/null +++ b/parse-torrent/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "../tslint.json" +} diff --git a/webtorrent/index.d.ts b/webtorrent/index.d.ts index 413dee9133..074adccb74 100644 --- a/webtorrent/index.d.ts +++ b/webtorrent/index.d.ts @@ -38,8 +38,8 @@ declare namespace WebTorrent { on(event: 'torrent', callback: (torrent: Torrent) => void): this; on(event: 'error', callback: (err: Error | string) => void): this; - add(torrent: string | Buffer | ParseTorrent.ParsedTorrent, opts?: TorrentOptions, cb?: (torrent: Torrent) => any): Torrent; - add(torrent: string | Buffer | ParseTorrent.ParsedTorrent, cb?: (torrent: Torrent) => any): Torrent; + add(torrent: string | Buffer | ParseTorrent.Instance, opts?: TorrentOptions, cb?: (torrent: Torrent) => any): Torrent; + add(torrent: string | Buffer | ParseTorrent.Instance, cb?: (torrent: Torrent) => any): Torrent; seed(input: string | string[] | File | File[] | FileList | Buffer | Buffer[] | NodeJS.ReadableStream | NodeJS.ReadableStream[], opts?: TorrentOptions, cb?: (torrent: Torrent) => any): Torrent; seed(input: string | string[] | File | File[] | FileList | Buffer | Buffer[] | NodeJS.ReadableStream | NodeJS.ReadableStream[], cb?: (torrent: Torrent) => any): Torrent; From 143c1055619532dc24920ea52771295455ba9df9 Mon Sep 17 00:00:00 2001 From: Daniel Pereira Date: Thu, 19 Jan 2017 15:07:57 -0600 Subject: [PATCH 11/17] Added new "mock-raf" type definitions (#14095) * Added mock-raf * Fix tsconfig.json * Added tslint and fixed module * Update project * export just a function --- mock-raf/index.d.ts | 37 +++++++++++++++++++++++++++++++++++++ mock-raf/mock-raf-tests.ts | 9 +++++++++ mock-raf/tsconfig.json | 20 ++++++++++++++++++++ mock-raf/tslint.json | 3 +++ 4 files changed, 69 insertions(+) create mode 100644 mock-raf/index.d.ts create mode 100644 mock-raf/mock-raf-tests.ts create mode 100644 mock-raf/tsconfig.json create mode 100644 mock-raf/tslint.json diff --git a/mock-raf/index.d.ts b/mock-raf/index.d.ts new file mode 100644 index 0000000000..4d87655042 --- /dev/null +++ b/mock-raf/index.d.ts @@ -0,0 +1,37 @@ +// Type definitions for mock-raf 1.0 +// Project: https://github.com/FormidableLabs/mock-raf +// Definitions by: Daniel Pereira +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare namespace MockRaf { + + interface Options { + + /** The time that should pass during each requestAnimationFrame step in milliseconds. Default is roughly equivalent to default browser behavior. */ + time?: number; + + /** The number of steps to take. */ + count?: number; + } + + /** Creates a mockRaf instance, exposing the functions you'll use to interact with the mock. */ + interface Creator { + + /** Returns the current now value of the mock. Starts at 0 and increases with each step() taken. Useful for stubbing out performance.now() or a polyfill when using requestAnimationFrame with timers. */ + now(): number; + + /** Replacement for requestAnimationFrame or a polyfill.Adds a callback to be fired on the next step. */ + raf(callback: FrameRequestCallback): number; + + /** Replacement for cancelAnimationFrame or a polyfill.Removes all currently scheduled requestAnimationFrame callbacks from the queue. */ + cancel(handle: number): void; + + /** Takes requestAnimationFrame steps. Fires currently queued callbacks for each step and increments now time for each step. The primary way to interact with a mockRaf instance for testing. */ + step(options?: Options): void; + } + +} + +declare function MockRaf(): MockRaf.Creator; + +export = MockRaf; \ No newline at end of file diff --git a/mock-raf/mock-raf-tests.ts b/mock-raf/mock-raf-tests.ts new file mode 100644 index 0000000000..96ba9531d5 --- /dev/null +++ b/mock-raf/mock-raf-tests.ts @@ -0,0 +1,9 @@ +import * as createMockRaf from 'mock-raf'; + +const mockRaf = createMockRaf(); +const id = mockRaf.raf(() => { + console.log('RAF!!!'); +}); +mockRaf.step({ count: 10 }); +mockRaf.cancel(id); +console.log(mockRaf.now()); \ No newline at end of file diff --git a/mock-raf/tsconfig.json b/mock-raf/tsconfig.json new file mode 100644 index 0000000000..d035910a65 --- /dev/null +++ b/mock-raf/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "mock-raf-tests.ts" + ] +} \ No newline at end of file diff --git a/mock-raf/tslint.json b/mock-raf/tslint.json new file mode 100644 index 0000000000..fdc7cdc370 --- /dev/null +++ b/mock-raf/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "../tslint.json" +} \ No newline at end of file From 3a3831bc528039e45098bffc0f2a70f3611cac43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20=C5=81aziuk?= Date: Thu, 19 Jan 2017 22:08:52 +0100 Subject: [PATCH 12/17] [jfs] new typings, version 0.2.6 (#14124) * jfs v0.2.6 * node is not needed --- jfs/index.d.ts | 45 +++++++++++++++++++++++++++++++++++++++++++++ jfs/jfs-tests.ts | 44 ++++++++++++++++++++++++++++++++++++++++++++ jfs/tsconfig.json | 23 +++++++++++++++++++++++ jfs/tslint.json | 3 +++ 4 files changed, 115 insertions(+) create mode 100644 jfs/index.d.ts create mode 100644 jfs/jfs-tests.ts create mode 100644 jfs/tsconfig.json create mode 100644 jfs/tslint.json diff --git a/jfs/index.d.ts b/jfs/index.d.ts new file mode 100644 index 0000000000..ba6edb26bc --- /dev/null +++ b/jfs/index.d.ts @@ -0,0 +1,45 @@ +// Type definitions for jfs 0.2 +// Project: http://github.com/flosse/json-file-store +// Definitions by: Tomasz Łaziuk +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +declare const JsonFileStore: JsonFileStore.JsonFileStore; + +declare namespace JsonFileStore { + export interface Storable { + [key: string]: any; + } + + export interface Options { + type?: 'single' | 'memory'; + pretty?: boolean; + saveId?: boolean | string; + } + + export interface JsonFileStore { + new (name?: string, opts?: Options): Instance; + } + + export interface Instance { + save(id: K, o: V, cb?: (err?: Error, id?: K) => void): void; + save(o: V, cb?: (err?: Error, id?: string) => void): void; + + saveSync(id: K, o: V): void; + saveSync(o: V): void; + + get(id: K, cb?: (err?: Error, o?: V) => void): void; + + getSync(id: K): V | Error; + + delete(id: K, cb?: (err?: Error) => void): void; + + deleteSync(id: K): Error | void; + + all(cb: (err?: Error, all?: T) => void): void; + + allSync(): T; + } +} + +export = JsonFileStore; diff --git a/jfs/jfs-tests.ts b/jfs/jfs-tests.ts new file mode 100644 index 0000000000..0deebbd4a4 --- /dev/null +++ b/jfs/jfs-tests.ts @@ -0,0 +1,44 @@ +import * as Store from 'jfs'; + +interface TestStore { + foo: string; + bar: number; +} + +const db = new Store('data', {type: 'memory'}); + +// save with custom ID +db.save('bar', 123, function(err, id) { + // now the data is stored in the file data/anId.json +}); + +// save with generated ID +db.save(333, function(err, id) { + // id is a unique ID +}); + +// save synchronously +db.saveSync('foo', 'test'); + +db.get('bar', function(err, obj) { + // obj = { foo: ''bar' } +}); + +// get synchronously +const val = db.getSync('bar'); + +// get all available objects +db.all(function(err, objs) { + // objs is a map: ID => OBJECT +}); + +// get all synchronously +var objs = db.allSync(); + +// delete by ID +db.delete('foo', function(err) { + // the file data/myId.json was removed +}); + +// delete synchronously +db.deleteSync('bar'); diff --git a/jfs/tsconfig.json b/jfs/tsconfig.json new file mode 100644 index 0000000000..7681ab072d --- /dev/null +++ b/jfs/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "jfs-tests.ts" + ] +} diff --git a/jfs/tslint.json b/jfs/tslint.json new file mode 100644 index 0000000000..ec365f164b --- /dev/null +++ b/jfs/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "../tslint.json" +} From 2b0c5947316095d0f7979d171743eadce33afb92 Mon Sep 17 00:00:00 2001 From: Chris Khoo Date: Thu, 19 Jan 2017 13:09:22 -0800 Subject: [PATCH 13/17] add readOnly to commandDefinition (#14125) --- ckeditor/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/ckeditor/index.d.ts b/ckeditor/index.d.ts index 55a748e4c5..518c44ae2a 100644 --- a/ckeditor/index.d.ts +++ b/ckeditor/index.d.ts @@ -1318,6 +1318,7 @@ declare namespace CKEDITOR { modes?: Object; startDisabled?: boolean; exec(editor: editor, data?: Object): boolean; + readOnly?: boolean; refresh?(editor: editor, path: dom.elementPath): void; } From 25420083bd1545171c733661ce55f9395ec02efa Mon Sep 17 00:00:00 2001 From: rebelwolfson Date: Fri, 20 Jan 2017 04:15:14 +0700 Subject: [PATCH 14/17] missed API added and comments improved (#14050) * added missed api and documentation partly improved * minor improvements in API and docs * docs improvements * docs improvements * redocumenting and api updating completed * tests added and contributors field extended * indentation normalized --- graphlib/graphlib-tests.ts | 29 +- graphlib/index.d.ts | 808 +++++++++++++++++++++++++------------ 2 files changed, 584 insertions(+), 253 deletions(-) diff --git a/graphlib/graphlib-tests.ts b/graphlib/graphlib-tests.ts index feaaf5c42b..114deef66a 100644 --- a/graphlib/graphlib-tests.ts +++ b/graphlib/graphlib-tests.ts @@ -2,12 +2,31 @@ import * as graphlib from 'graphlib'; function test_graph() { - var g = new graphlib.Graph(); + var g = new graphlib.Graph({ + compound: true, + directed: true, + multigraph: true + }); g.setEdge('a', 'b'); - g.setEdge('a', 'b', 1.023); + g.setEdge('a', 'b', 1.023, 'test'); + g.setEdge({ v: 'a', w: 'b', name: 'test' }, 1.023); + g.hasEdge('a', 'b', 'test'); + g.hasEdge({ v: 'a', w: 'b', name: 'test' }); + g.removeEdge('a', 'b', 'test'); + g.removeEdge({ v: 'a', w: 'b', name: 'test' }); - g.edge('a', 'b'); - g.edge({v: 'a', w: 'b'}); + g.edge('a', 'b', 'test'); + g.edge({v: 'a', w: 'b', name: 'test'}); + g.setDefaultNodeLabel({}); + g.setDefaultNodeLabel(() => 42); + g.setDefaultEdgeLabel({}); + g.setDefaultEdgeLabel(() => 'e42'); + g.setNodes(['a', 'b', 'c'], 42); + g.setParent('d', 'a'); + g.parent('d'); + g.children('a'); + g.filterNodes(v => true); + g.setPath(['a', 'b', 'c'], 42); graphlib.json.read(graphlib.json.write(g)); @@ -20,4 +39,6 @@ function test_graph() { graphlib.alg.prim(g, e => g.edge(e)); graphlib.alg.tarjan(g); graphlib.alg.topsort(g); + graphlib.alg.preorder(g, g.nodes()); + graphlib.alg.postorder(g, g.nodes()); } diff --git a/graphlib/index.d.ts b/graphlib/index.d.ts index 1f017d5383..773cb621d1 100644 --- a/graphlib/index.d.ts +++ b/graphlib/index.d.ts @@ -1,291 +1,601 @@ // Type definitions for graphlib 2.1.1 // Project: https://github.com/cpettitt/graphlib -// Definitions by: Dan Vanderkam +// Definitions by: Dan Vanderkam , Dan Mironenko // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare module "graphlib" { - export interface GraphOptions { - directed?: boolean; // default: true. - multigraph?: boolean; // default: false. - compound?: boolean; // default: false. - } + export interface GraphOptions { + directed?: boolean; // default: true. + multigraph?: boolean; // default: false. + compound?: boolean; // default: false. + } - export interface Edge { - v: string; - w: string; - /** The name that uniquely identifies a multi-edge. */ - name?: string; - } + export interface Edge { + v: string; + w: string; + /** The name that uniquely identifies a multi-edge. */ + name?: string; + } - // TODO: add template parameters for edge and vertex labels? - export class Graph { - constructor(options?: GraphOptions); + export class Graph { + constructor(options?: GraphOptions); - /** - * Creates or updates the value for the node v in the graph. If label is supplied - * it is set as the value for the node. If label is not supplied and the node was - * created by this call then the default node label will be assigned. Returns the - * graph, allowing this to be chained with other functions. Takes O(1) time. - */ - setNode(name: string, label?: any): Graph; + /** + * Sets the default node label. This label will be assigned as default label + * in case if no label was specified while setting a node. + * Complexity: O(1). + * + * @argument label - default node label. + * @returns the graph, allowing this to be chained with other functions. + */ + setDefaultNodeLabel(label: any): Graph; - hasNode(name: string): boolean; + /** + * Sets the default node label factory function. This function will be invoked + * each time when setting a node with no label specified and returned value + * will be used as a label for node. + * Complexity: O(1). + * + * @argument labelFn - default node label factory function. + * @returns the graph, allowing this to be chained with other functions. + */ + setDefaultNodeLabel(labelFn: (v: string) => any): Graph; - /** - * Remove the node with the id v in the graph or do nothing if the node is not in - * the graph. If the node was removed this function also removes any incident - * edges. Returns the graph, allowing this to be chained with other functions. - * Takes O(|E|) time. */ - removeNode(name: string): Graph; + /** + * Creates or updates the value for the node v in the graph. If label is supplied + * it is set as the value for the node. If label is not supplied and the node was + * created by this call then the default node label will be assigned. + * Complexity: O(1). + * + * @argument name - node name. + * @argument label - value to set for node. + * @returns the graph, allowing this to be chained with other functions. + */ + setNode(name: string, label?: any): Graph; - nodes(): string[]; + /** + * Invokes setNode method for each node in names list. + * Complexity: O(|names|). + * + * @argument names - list of nodes names to be set. + * @argument label - value to set for each node in list. + * @returns the graph, allowing this to be chained with other functions. + */ + setNodes(names: string[], label?: any): Graph; - /** Returns the label for this node. */ - node(name: string): any; + /** + * Sets node p as a parent for node v. Method throws an exception in case of + * invoking it in context of noncompound graph. + * Average-case complexity: O(1). + * + * @argument v - node to be child for p. + * @argument p - node to be parent for v. + * @returns the graph, allowing this to be chained with other functions. + */ + setParent(v: string, p: string): Graph; - /** - * Creates or updates the label for the edge (v, w) with the optionally supplied - * name. If label is supplied it is set as the value for the edge. If label is not - * supplied and the edge was created by this call then the default edge label will - * be assigned. The name parameter is only useful with multigraphs. Returns the - * graph, allowing this to be chained with other functions. Takes O(1) time. - */ - setEdge(v: string, w: string, label?: any): Graph; + /** + * Gets parent node for node v. + * Complexity: O(1). + * + * @argument v - node to get parent of. + * @returns parent node name or void if v has no parent. + */ + parent(v: string): string | void; - edges(): Edge[]; + /** + * Gets list of direct children of node v. + * Complexity: O(1). + * + * @argument v - node to get children of. + * @returns children nodes names list. + */ + children(v: string): string[]; - /** Returns the label for this edge. */ - edge(v: string, w: string): any; - edge(e: Edge): any; + /** + * Creates new graph with nodes filtered via filter. Edges incident to rejected node + * are also removed. In case of compound graph, if parent is rejected by filter, + * than all its children are rejected too. + * Average-case complexity: O(|E|+|V|). + * + * @argument filter - filtration function detecting whether the node should stay or not. + * @returns new graph made from current and nodes filtered. + */ + filterNodes(filter: (v: string) => boolean): Graph; - /** - * Return all edges that point to the node v. Optionally filters those edges down to just those - * coming from node u. Behavior is undefined for undirected graphs - use nodeEdges instead. - * Returns undefined if node v is not in the graph. Takes O(|E|) time. - */ - inEdges(v: string, u?: string): Edge[]; + /** + * Sets the default edge label. This label will be assigned as default label + * in case if no label was specified while setting an edge. + * Complexity: O(1). + * + * @argument label - default edge label. + * @returns the graph, allowing this to be chained with other functions. + */ + setDefaultEdgeLabel(label: any): Graph; - /** - * Return all edges that are pointed at by node v. Optionally filters those edges down to just - * those point to w. Behavior is undefined for undirected graphs - use nodeEdges instead. - * Returns undefined if node v is not in the graph. Takes O(|E|) time. - */ - outEdges(v: string, w?: string): Edge[]; + /** + * Sets the default edge label factory function. This function will be invoked + * each time when setting an edge with no label specified and returned value + * will be used as a label for edge. + * Complexity: O(1). + * + * @argument labelFn - default edge label factory function. + * @returns the graph, allowing this to be chained with other functions. + */ + setDefaultEdgeLabel(labelFn: (v: string) => any): Graph; - /** - * Returns all edges to or from node v regardless of direction. Optionally filters those edges - * down to just those between nodes v and w regardless of direction. Returns undefined if node v - * is not in the graph. Takes O(|E|) time. - */ - nodeEdges(v: string, w?: string): Edge[]; + /** + * Establish an edges path over the nodes in nodes list. If some edge is already + * exists, it will update its label, otherwise it will create an edge between pair + * of nodes with label provided or default label if no label provided. + * Complexity: O(|nodes|). + * + * @argument nodes - list of nodes to be connected in series. + * @argument label - value to set for each edge between pairs of nodes. + * @returns the graph, allowing this to be chained with other functions. + */ + setPath(nodes: string[], label?: any): Graph; - /** - * Return all nodes that are predecessors of the specified node or undefined if node v is not in - * the graph. Behavior is undefined for undirected graphs - use neighbors instead. Takes O(|V|) - * time. - */ - predecessors(node: string): string[]; + /** + * Detects whether graph has a node with specified name or not. + + * + * @argument name - name of the node. + * @returns true if graph has node with specified name, false - otherwise. + */ + hasNode(name: string): boolean; - /** - * Return all nodes that are successors of the specified node or undefined if node v is not in - * the graph. Behavior is undefined for undirected graphs - use neighbors instead. Takes O(|V|) - * time. - */ - successors(node: string): string[]; + /** + * Remove the node with the name from the graph or do nothing if the node is not in + * the graph. If the node was removed this function also removes any incident + * edges. + * Complexity: O(1). + * + * @argument name - name of the node. + * @returns the graph, allowing this to be chained with other functions. + */ + removeNode(name: string): Graph; - /** - * Return all nodes that are predecessors or successors of the specified node or undefined if - * node v is not in the graph. Takes O(|V|) time. - */ - neighbors(node: string): string[]; + /** + * Gets all nodes of the graph. Note, the in case of compound graph subnodes are + * not included in list. + * Complexity: O(1). + * + * @returns list of graph nodes. + */ + nodes(): string[]; - isDirected(): boolean; - isMultigraph(): boolean; - isCompound(): boolean; + /** + * Gets the label of node with specified name. + * Complexity: O(|V|). + * + * @returns label value of the node. + */ + node(name: string): any; - /** Sets the label for the graph to label. */ - setGraph(label: string): void; + /** + * Creates or updates the label for the edge (v, w) with the optionally supplied + * name. If label is supplied it is set as the value for the edge. If label is not + * supplied and the edge was created by this call then the default edge label will + * be assigned. The name parameter is only useful with multigraphs. + * Complexity: O(1). + * + * @argument v - edge source node. + * @argument w - edge sink node. + * @argument label - value to associate with the edge. + * @argument name - unique name of the edge in order to identify it in multigraph. + * @returns the graph, allowing this to be chained with other functions. + */ + setEdge(v: string, w: string, label?: any, name?: string): Graph; - /** - * Returns the currently assigned label for the graph. If no label has been assigned, - * returns undefined. - */ - graph(): string; + /** + * Creates or updates the label for the specified edge. If label is supplied it is + * set as the value for the edge. If label is not supplied and the edge was created + * by this call then the default edge label will be assigned. The name parameter is + * only useful with multigraphs. + * Complexity: O(1). + * + * @argument edge - edge descriptor. + * @argument label - value to associate with the edge. + * @returns the graph, allowing this to be chained with other functions. + */ + setEdge(edge: Edge, label?: any): Graph; - /** - * Returns the number of nodes in the graph. - */ - nodeCount(): number; + /** + * Gets edges of the graph. In case of compound graph subgraphs are not considered. + * Complexity: O(|E|). + * + * @return graph edges list. + */ + edges(): Edge[]; - /** - * Returns the number of edges in the graph. - */ - edgeCount(): number; + /** + * Gets the label for the specified edge. + * Complexity: O(1). + * + * @argument v - edge source node. + * @argument w - edge sink node. + * @argument name - name of the edge (actual for multigraph). + * @returns value associated with specified edge. + */ + edge(v: string, w: string, name?: string): any; - /** Returns those nodes in the graph that have no in-edges. Takes O(|V|) time. */ - sources(): string[]; + /** + * Gets the label for the specified edge. + * Complexity: O(1). + * + * @argument edge - edge descriptor. + * @returns value associated with specified edge. + */ + edge(e: Edge): any; - /** Returns those nodes in the graph that have no out-edges. Takes O(|V|) time. */ - sinks(): string[]; - } + /** + * Detects whether the graph contains specified edge or not. No subgraphs are considered. + * Complexity: O(1). + * + * @argument v - edge source node. + * @argument w - edge sink node. + * @argument name - name of the edge (actual for multigraph). + * @returns whether the graph contains the specified edge or not. + */ + hasEdge(v: string, w: string, name?: string): boolean; - export namespace json { - /** - * Creates a JSONrepresentation of the graph that can be serialized to a string with - * JSON.stringify. The graph can later be restored using json.read. - */ - function write(g: Graph): Object; + /** + * Detects whether the graph contains specified edge or not. No subgraphs are considered. + * Complexity: O(1). + * + * @argument edge - edge descriptor. + * @returns whether the graph contains the specified edge or not. + */ + hasEdge(edge: Edge): boolean; - /** - * Takes JSON as input and returns the graph representation. For example, if we have - * serialized the graph in json-write to a string named str, we can restore it to a - * graph as follows: - * - * var g2 = graphlib.json.read(JSON.parse(str)); - * g2.nodes(); - * // ['a', 'b'] - * g2.edges() - * // [ { v: 'a', w: 'b' } ] - */ - function read(json: Object): Graph; - } + /** + * Removes the specified edge from the graph. No subgraphs are considered. + * Complexity: O(1). + * + * @argument edge - edge descriptor. + * @returns the graph, allowing this to be chained with other functions. + */ + removeEdge(edge: Edge): Graph; - export interface Path { - distance: number; - predecessor: string; - } + /** + * Removes the specified edge from the graph. No subgraphs are considered. + * Complexity: O(1). + * + * @argument v - edge source node. + * @argument w - edge sink node. + * @argument name - name of the edge (actual for multigraph). + * @returns the graph, allowing this to be chained with other functions. + */ + removeEdge(v: string, w: string, name?: string): Graph; - export namespace alg { - /** - * Finds all connected components in a graph and returns an array of these components. - * Each component is itself an array that contains the ids of nodes in the component. - * This function takes O(|V|) time. - */ - function components(g: Graph): string[][]; + /** + * Return all edges that point to the node v. Optionally filters those edges down to just those + * coming from node u. Behavior is undefined for undirected graphs - use nodeEdges instead. + * Complexity: O(|E|). + * + * @argument v - edge sink node. + * @argument w - edge source node. + * @returns edges descriptors list if v is in the graph, or undefined otherwise. + */ + inEdges(v: string, w?: string): void | Edge[]; - /** - * This function is an implementation of Dijkstra's algorithm which finds the shortest - * path from source to all other nodes in g. This function returns a map of - * v -> { distance, predecessor }. The distance property holds the sum of the weights - * from source to v along the shortest path or Number.POSITIVE_INFINITY if there is no path - * from source. The predecessor property can be used to walk the individual elements of the - * path from source to v in reverse order. - * - * It takes an optional weightFn(e) which returns the weight of the edge e. If no weightFn - * is supplied then each edge is assumed to have a weight of 1. This function throws an - * Error if any of the traversed edges have a negative edge weight. - * - * It takes an optional edgeFn(v) which returns the ids of all edges incident to the node v - * for the purposes of shortest path traversal. By default this function uses the g.outEdges. - * - * It takes O((|E| + |V|) * log |V|) time. - */ - function dijkstra( - graph: Graph, - source: string, - weightFn?: (e: Edge) => number, - edgeFn?: (v: string) => Edge[] - ): {[node: string]: Path}; + /** + * Return all edges that are pointed at by node v. Optionally filters those edges down to just + * those point to w. Behavior is undefined for undirected graphs - use nodeEdges instead. + * Complexity: O(|E|). + * + * @argument v - edge source node. + * @argument w - edge sink node. + * @returns edges descriptors list if v is in the graph, or undefined otherwise. + */ + outEdges(v: string, w?: string): void | Edge[]; - /** - * This function finds the shortest path from each node to every other reachable node in - * the graph. It is similar to alg.dijkstra, but instead of returning a single-source - * array, it returns a mapping of of source -> alg.dijksta(g, source, weightFn, edgeFn). - * - * This function takes an optional weightFn(e) which returns the weight of the edge e. - * If no weightFn is supplied then each edge is assumed to have a weight of 1. This - * function throws an Error if any of the traversed edges have a negative edge weight. - * - * This function takes an optional edgeFn(u) which returns the ids of all edges incident - * to the node u for the purposes of shortest path traversal. By default this function - * uses g.outEdges. - * - * This function takes O(|V| * (|E| + |V|) * log |V|) time. - */ - function dijkstraAll( - graph: Graph, - weightFn?: (e: Edge) => number, - edgeFn?: (v: string) => Edge[] - ): {[source: string]: {[node: string]: Path}}; + /** + * Returns all edges to or from node v regardless of direction. Optionally filters those edges + * down to just those between nodes v and w regardless of direction. + * Complexity: O(|E|). + * + * @argument v - edge adjacent node. + * @argument w - edge adjacent node. + * @returns edges descriptors list if v is in the graph, or undefined otherwise. + */ + nodeEdges(v: string, w?: string): void | Edge[]; - /** - * Given a Graph, g, this function returns all nodes that are part of a cycle. As there - * may be more than one cycle in a graph this function return an array of these cycles, - * where each cycle is itself represented by an array of ids for each node involved in - * that cycle. - * - * alg.isAcyclic is more efficient if you only need to determine whether a graph has a - * cycle or not. - */ - function findCycles(graph: Graph): string[][]; + /** + * Return all nodes that are predecessors of the specified node or undefined if node v is not in + * the graph. Behavior is undefined for undirected graphs - use neighbors instead. + * Complexity: O(|V|). + * + * @argument v - node identifier. + * @returns node identifiers list or undefined if v is not in the graph. + */ + predecessors(v: string): void | string[]; - /** - * This function is an implementation of the Floyd-Warshall algorithm, which finds the - * shortest path from each node to every other reachable node in the graph. It is similar - * to alg.dijkstraAll, but it handles negative edge weights and is more efficient for some types - * of graphs. This function returns a map of source -> { target -> { distance, predecessor }. - * The distance property holds the sum of the weights from source to target along the shortest - * path of Number.POSITIVE_INFINITY if there is no path from source. The predecessor property - * can be used to walk the individual elements of the path from source to target in reverse - * order. - * - * This function takes an optional weightFn(e) which returns the weight of the edge e. If no - * weightFunc is supplied then each edge is assumed to have a weight of 1. - * - * This function takes an optional edgeFn(v) which returns the ids of all edges incident to the - * node v for the purposes of shortest path traversal. By default this function uses the - * outEdges function on the supplied graph. - * - * This algorithm takes O(|V|^3) time. - */ - function floydWarshall( - graph: Graph, - weightFn?: (e: Edge) => number, - edgeFn?: (v: string) => Edge[] - ): {[source: string]: {[node: string]: Path}}; + /** + * Return all nodes that are successors of the specified node or undefined if node v is not in + * the graph. Behavior is undefined for undirected graphs - use neighbors instead. + * Complexity: O(|V|). + * + * @argument v - node identifier. + * @returns node identifiers list or undefined if v is not in the graph. + */ + successors(v: string): void | string[]; - /** - * Given a Graph, g, this function returns true if the graph has no cycles and returns false if it - * does. This algorithm returns as soon as it detects the first cycle. You can use alg.findCycles - * to get the actual list of cycles in the graph. - */ - function isAcyclic(graph: Graph): boolean; + /** + * Return all nodes that are predecessors or successors of the specified node or undefined if + * node v is not in the graph. + * Complexity: O(|V|). + * + * @argument v - node identifier. + * @returns node identifiers list or undefined if v is not in the graph. + */ - /** - * Prim's algorithm takes a connected undirected graph and generates a minimum spanning tree. This - * function returns the minimum spanning tree as an undirected graph. This algorithm is derived - * from the description in "Introduction to Algorithms", Third Edition, Cormen, et al., Pg 634. - * - * This function takes a weightFn(e) which returns the weight of the edge e. It throws an Error if - * the graph is not connected. - * - * This function takes O(|E| log |V|) time. - */ - function prim(graph: Graph, weightFn: (e: Edge) => number): Graph; + neighbors(v: string): void | string[]; - /** - * This function is an implementation of Tarjan's algorithm which finds all strongly connected - * components in the directed graph g. Each strongly connected component is composed of nodes that - * can reach all other nodes in the component via directed edges. A strongly connected component - * can consist of a single node if that node cannot both reach and be reached by any other - * specific node in the graph. Components of more than one node are guaranteed to have at least - * one cycle. - * - * This function returns an array of components. Each component is itself an array that contains - * the ids of all nodes in the component. - */ - function tarjan(graph: Graph): string[][]; + /** + * Whether graph was created with 'directed' flag set to true or not. + * + * @returns whether the graph edges have an orientation. + */ + isDirected(): boolean; - /** - * An implementation of topological sorting. - * - * Given a Graph g this function returns an array of nodes such that for each edge u -> v, u - * appears before v in the array. If the graph has a cycle it is impossible to generate such a - * list and CycleException is thrown. - * - * Takes O(|V| + |E|) time. - */ - function topsort(graph: Graph): string[]; - } + /** + * Whether graph was created with 'multigraph' flag set to true or not. + * + * @returns whether the pair of nodes of the graph can have multiple edges. + */ + isMultigraph(): boolean; + + /** + * Whether graph was created with 'compound' flag set to true or not. + * + * @returns whether a node of the graph can have subnodes. + */ + isCompound(): boolean; + + /** + * Sets the label of the graph. + * + * @argument label - label value. + * @returns the graph, allowing this to be chained with other functions. + */ + setGraph(label: string): Graph; + + /** + * Gets the graph label. + * + * @returns currently assigned label for the graph or undefined if no label assigned. + */ + graph(): void | string; + + /** + * Gets the number of nodes in the graph. + * Complexity: O(1). + * + * @returns nodes count. + */ + nodeCount(): number; + + /** + * Gets the number of edges in the graph. + * Complexity: O(1). + * + * @returns edges count. + */ + edgeCount(): number; + + /** + * Gets list of nodes without in-edges. + * Complexity: O(|V|). + * + * @returns the graph source nodes. + */ + sources(): string[]; + + /** + * Gets list of nodes without out-edges. + * Complexity: O(|V|). + * + * @returns the graph source nodes. + */ + sinks(): string[]; + } + + export namespace json { + /** + * Creates a JSON representation of the graph that can be serialized to a string with + * JSON.stringify. The graph can later be restored using json.read. + * + * @argument graph - target to create JSON representation of. + * @returns JSON serializable graph representation + */ + function write(graph: Graph): Object; + + /** + * Takes JSON as input and returns the graph representation. + * + * @example + * var g2 = graphlib.json.read(JSON.parse(str)); + * g2.nodes(); + * // ['a', 'b'] + * g2.edges() + * // [ { v: 'a', w: 'b' } ] + * + * @argument json - JSON serializable graph representation + * @returns graph constructed acccording to specified representation + */ + function read(json: Object): Graph; + } + + export interface Path { + distance: number; + predecessor: string; + } + + export namespace alg { + /** + * Finds all connected components in a graph and returns an array of these components. + * Each component is itself an array that contains the ids of nodes in the component. + * Complexity: O(|V|). + * + * @argument graph - graph to find components in. + * @returns array of nodes list representing components + */ + function components(graph: Graph): string[][]; + + /** + * This function is an implementation of Dijkstra's algorithm which finds the shortest + * path from source to all other nodes in graph. This function returns a map of + * v -> { distance, predecessor }. The distance property holds the sum of the weights + * from source to v along the shortest path or Number.POSITIVE_INFINITY if there is no path + * from source. The predecessor property can be used to walk the individual elements of the + * path from source to v in reverse order. + * Complexity: O((|E| + |V|) * log |V|). + * + * @argument graph - graph where to search pathes. + * @argument source - node to start pathes from. + * @argument weightFn - function which takes edge e and returns the weight of it. If no weightFn + * is supplied then each edge is assumed to have a weight of 1. This function throws an + * Error if any of the traversed edges have a negative edge weight. + * @argument edgeFn - function which takes a node v and returns the ids of all edges incident to it + * for the purposes of shortest path traversal. By default this function uses the graph.outEdges. + * @returns shortest pathes map that starts from node source + */ + function dijkstra( + graph: Graph, + source: string, + weightFn?: (e: Edge) => number, + edgeFn?: (v: string) => Edge[] + ): { [node: string]: Path }; + + /** + * This function finds the shortest path from each node to every other reachable node in + * the graph. It is similar to alg.dijkstra, but instead of returning a single-source + * array, it returns a mapping of source -> alg.dijksta(g, source, weightFn, edgeFn). + * Complexity: O(|V| * (|E| + |V|) * log |V|). + * + * @argument graph - graph where to search pathes. + * @argument weightFn - function which takes edge e and returns the weight of it. If no weightFn + * is supplied then each edge is assumed to have a weight of 1. This function throws an + * Error if any of the traversed edges have a negative edge weight. + * @argument edgeFn - function which takes a node v and returns the ids of all edges incident to it + * for the purposes of shortest path traversal. By default this function uses the graph.outEdges. + * @returns shortest pathes map. + */ + function dijkstraAll( + graph: Graph, + weightFn?: (e: Edge) => number, + edgeFn?: (v: string) => Edge[] + ): { [source: string]: { [node: string]: Path } }; + + /** + * Given a Graph, graph, this function returns all nodes that are part of a cycle. As there + * may be more than one cycle in a graph this function return an array of these cycles, + * where each cycle is itself represented by an array of ids for each node involved in + * that cycle. Method alg.isAcyclic is more efficient if you only need to determine whether a graph has a + * cycle or not. + * Complexity: O(|V| + |E|). + * + * @argument graph - graph where to search cycles. + * @returns cycles list. + */ + function findCycles(graph: Graph): string[][]; + + /** + * Given a Graph, graph, this function returns true if the graph has no cycles and returns false if it + * does. This algorithm returns as soon as it detects the first cycle. You can use alg.findCycles + * to get the actual list of cycles in the graph. + * + * @argument graph - graph to detect whether it acyclic ot not. + * @returns whether graph contain cycles or not. + */ + function isAcyclic(graph: Graph): boolean; + + /** + * This function is an implementation of the Floyd-Warshall algorithm, which finds the + * shortest path from each node to every other reachable node in the graph. It is similar + * to alg.dijkstraAll, but it handles negative edge weights and is more efficient for some types + * of graphs. This function returns a map of source -> { target -> { distance, predecessor }. + * The distance property holds the sum of the weights from source to target along the shortest + * path of Number.POSITIVE_INFINITY if there is no path from source. The predecessor property + * can be used to walk the individual elements of the path from source to target in reverse + * order. + * Complexity: O(|V|^3). + * + * @argument graph - graph where to search pathes. + * @argument weightFn - function which takes edge e and returns the weight of it. If no weightFn + * is supplied then each edge is assumed to have a weight of 1. This function throws an + * Error if any of the traversed edges have a negative edge weight. + * @argument edgeFn - function which takes a node v and returns the ids of all edges incident to it + * for the purposes of shortest path traversal. By default this function uses the graph.outEdges. + * @returns shortest pathes map. + */ + function floydWarshall( + graph: Graph, + weightFn?: (e: Edge) => number, + edgeFn?: (v: string) => Edge[] + ): { [source: string]: { [node: string]: Path } }; + + /** + * Prim's algorithm takes a connected undirected graph and generates a minimum spanning tree. This + * function returns the minimum spanning tree as an undirected graph. This algorithm is derived + * from the description in "Introduction to Algorithms", Third Edition, Cormen, et al., Pg 634. + * Complexity: O(|E| * log |V|); + * + * @argument graph - graph to generate a minimum spanning tree of. + * @argument weightFn - function which takes edge e and returns the weight of it. It throws an Error if + * the graph is not connected. + * @returns minimum spanning tree of graph. + */ + function prim(graph: Graph, weightFn: (e: Edge) => number): Graph; + + /** + * This function is an implementation of Tarjan's algorithm which finds all strongly connected + * components in the directed graph g. Each strongly connected component is composed of nodes that + * can reach all other nodes in the component via directed edges. A strongly connected component + * can consist of a single node if that node cannot both reach and be reached by any other + * specific node in the graph. Components of more than one node are guaranteed to have at least + * one cycle. + * Complexity: O(|V| + |E|). + * + * @argument graph - graph to find all strongly connected components of. + * @return an array of components. Each component is itself an array that contains + * the ids of all nodes in the component. + */ + function tarjan(graph: Graph): string[][]; + + /** + * Given a Graph graph this function applies topological sorting to it. + * If the graph has a cycle it is impossible to generate such a list and CycleException is thrown. + * Complexity: O(|V| + |E|). + * + * @argument graph - graph to apply topological sorting to. + * @returns an array of nodes such that for each edge u -> v, u appears before v in the array. + */ + function topsort(graph: Graph): string[]; + + /** + * Performs pre-order depth first traversal on the input graph. If the graph is + * undirected then this algorithm will navigate using neighbors. If the graph + * is directed then this algorithm will navigate using successors. + * + * @argument graph - depth first traversal target. + * @argument vs - nodes list to traverse. + * @returns the nodes in the order they were visited as a list of their names. + */ + function preorder(graph: Graph, vs: string[]): string[] + + /** + * Performs post-order depth first traversal on the input graph. If the graph is + * undirected then this algorithm will navigate using neighbors. If the graph + * is directed then this algorithm will navigate using successors. + * + * @argument graph - depth first traversal target. + * @argument vs - nodes list to traverse. + * @returns the nodes in the order they were visited as a list of their names. + */ + function postorder(graph: Graph, vs: string[]): string[] + } } From 9c0b54dc305023a0d7db1e33feec8d5b9e89ed1c Mon Sep 17 00:00:00 2001 From: Tim Schraepen Date: Thu, 19 Jan 2017 22:28:26 +0100 Subject: [PATCH 15/17] Introduced Types for the vkBeautify npm package (#13948) * contribution of types for vkbeautify, a prettyprinting lib * added docs to methods * now linting * fixed lint suggestions * added original project * fixed export according to review * added --allowSyntheticDefaultImports to allow export = instead of export default * namespace unnecessary --- vkbeautify/index.d.ts | 45 +++++++++++++ vkbeautify/tsconfig.json | 21 ++++++ vkbeautify/tslint.json | 1 + vkbeautify/vkbeautify-tests.ts | 119 +++++++++++++++++++++++++++++++++ 4 files changed, 186 insertions(+) create mode 100644 vkbeautify/index.d.ts create mode 100644 vkbeautify/tsconfig.json create mode 100644 vkbeautify/tslint.json create mode 100644 vkbeautify/vkbeautify-tests.ts diff --git a/vkbeautify/index.d.ts b/vkbeautify/index.d.ts new file mode 100644 index 0000000000..259fc3e058 --- /dev/null +++ b/vkbeautify/index.d.ts @@ -0,0 +1,45 @@ +// Type definitions for vkbeautify 0.99 +// Project: https://github.com/aabluedragon/vkbeautify +// Definitions by: Tim Schraepen +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +// Original project: https://github.com/vkiryukhin/vkBeautify + +// beautifying +/** + * Pretty print an xml string with the given number of whitespace, or with a given indentation pattern + */ +export function xml(text: string, amountOfWhitespaces?: number | string): string; + +/** + * Pretty print a json string with the given number of whitespace, or with a given indentation pattern + */ +export function json(text: string, amountOfWhitespaces?: number | string): string; + +/** + * Pretty print a css string with the given number of whitespace, or with a given indentation pattern + */ +export function css(text: string, amountOfWhitespaces?: number | string): string; + +/** + * Pretty print an sql string with the given number of whitespace, or with a given indentation pattern + */ +export function sql(text: string, amountOfWhitespaces?: number | string): string; + +// minifying +/** + * Minifiy an xml string, and preserve or remove comments (default) + */ +export function xmlmin(text: string, preserveComments?: boolean): string; +/** + * Minifiy a json string + */ +export function jsonmin(text: string): string; +/** + * Minifiy a css string, and preserve or remove comments (default) + */ +export function cssmin(text: string, preserveComments?: boolean): string; +/** + * Minifiy an sql string + */ +export function sqlmin(text: string): string; \ No newline at end of file diff --git a/vkbeautify/tsconfig.json b/vkbeautify/tsconfig.json new file mode 100644 index 0000000000..91709c37ae --- /dev/null +++ b/vkbeautify/tsconfig.json @@ -0,0 +1,21 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "allowSyntheticDefaultImports": true + }, + "files": [ + "index.d.ts", + "vkbeautify-tests.ts" + ] +} \ No newline at end of file diff --git a/vkbeautify/tslint.json b/vkbeautify/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/vkbeautify/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" } diff --git a/vkbeautify/vkbeautify-tests.ts b/vkbeautify/vkbeautify-tests.ts new file mode 100644 index 0000000000..bc91ffad01 --- /dev/null +++ b/vkbeautify/vkbeautify-tests.ts @@ -0,0 +1,119 @@ +import VKBeautify from 'vkbeautify'; + +/* + * Beautifying + * + * vkbeautify.xml(text [,indent_pattern]); + * vkbeautify.json(text [,indent_pattern]); + * vkbeautify.css(text [,indent_pattern]); + * vkbeautify.sql(text [,indent_pattern]); + * + * @text - String; text to beatufy; + * @indent_pattern - Integer | String; + * Integer: number of white spaces; + * String: character string to visualize indentation ( can also be a set of white spaces ) + */ + +let exampleContent = "here-be-xml-json-css-or-sql-content-that-is-about-to-get-formatted"; + +//xml +function xmlWithDefault() { + VKBeautify.xml(exampleContent); +} + +function xmlWithNumberOfSpaces() { + VKBeautify.xml(exampleContent, 3); +} + +function xmlWithStringPattern() { + VKBeautify.xml(exampleContent, ' '); +} + +//json +function jsonWithDefault() { + VKBeautify.json(exampleContent); +} + +function jsonWithNumberOfSpaces() { + VKBeautify.json(exampleContent, 3); +} + +function jsonWithStringPattern() { + VKBeautify.json(exampleContent, ' '); +} + +//css +function cssWithDefault() { + VKBeautify.css(exampleContent); +} + +function cssWithNumberOfSpaces() { + VKBeautify.css(exampleContent, 3); +} + +function cssWithStringPattern() { + VKBeautify.css(exampleContent, ' '); +} + +//sql +function sqlWithDefault() { + VKBeautify.sql(exampleContent); +} + +function sqlWithNumberOfSpaces() { + VKBeautify.sql(exampleContent, 3); +} + +function sqlWithStringPattern() { + VKBeautify.sql(exampleContent, ' '); +} + + +/* + * Minifying + * + * vkbeautify.xmlmin(text [,preserve_comments]); + * vkbeautify.jsonmin(text); + * vkbeautify.cssmin(text [,preserve_comments]); + * vkbeautify.sqlmin(text); + * + * @text - String; text to minify; + * @preserve_comments - Bool; [optional]; + * Set this flag to true to prevent removing comments from @text ( minxml and mincss functions only. ) + */ + +//xml +function xmlminWithDefault() { + VKBeautify.xmlmin(exampleContent); +} + +function xmlminWitPreserveComments() { + VKBeautify.xmlmin(exampleContent, true); +} + +function xmlminAndRemoveComments() { + VKBeautify.xmlmin(exampleContent, false); +} + +//json +function jsonmin() { + VKBeautify.jsonmin(exampleContent); +} + +//css +function cssminWithDefault() { + VKBeautify.cssmin(exampleContent); +} + +function cssminWitPreserveComments() { + VKBeautify.cssmin(exampleContent, true); +} + +function cssminAndRemoveComments() { + VKBeautify.cssmin(exampleContent, false); +} + +//sql +function sqlmin() { + VKBeautify.sqlmin(exampleContent); +} \ No newline at end of file From 1398d9e2cdc7072d33093c600055380948cf8016 Mon Sep 17 00:00:00 2001 From: Tim Gaines Date: Thu, 19 Jan 2017 16:09:53 -0800 Subject: [PATCH 16/17] Add ready event function definition (#14127) --- cropperjs/index.d.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cropperjs/index.d.ts b/cropperjs/index.d.ts index aba858bfa5..b157746301 100644 --- a/cropperjs/index.d.ts +++ b/cropperjs/index.d.ts @@ -14,6 +14,10 @@ declare namespace cropperjs { detail: Data; } export interface CropperOptions { + /** + * Function called when crop box is ready + */ + ready?: (event: CropperCustomEvent) => void; /** * Function called when crop box is moved or resized */ From 93cfad5738535b06352b4039a4ad128ec8ef2331 Mon Sep 17 00:00:00 2001 From: Ivo Senner Date: Fri, 20 Jan 2017 01:10:24 +0100 Subject: [PATCH 17/17] Add type definition for UIkit.Dropdown (#14108) --- uikit/index.d.ts | 84 ++++++++++++++++++++++++++++++++++++++++++++ uikit/uikit-tests.ts | 21 +++++++++++ 2 files changed, 105 insertions(+) diff --git a/uikit/index.d.ts b/uikit/index.d.ts index 7a828101a1..11a68c1848 100644 --- a/uikit/index.d.ts +++ b/uikit/index.d.ts @@ -6,6 +6,89 @@ /// declare namespace UIkit { + interface DropdownElement { + /** + * Show the dropdown + */ + show(): void; + /** + * Hide the dropdown + * @param {boolean} force + */ + hide(force?: boolean): void; + } + type DropdownPosition = + 'bottom-left' | + 'bottom-center' | + 'bottom-right' | + 'top-left' | + 'top-center' | + 'top-right' | + 'left-top' | + 'left-center' | + 'left-bottom' | + 'right-top' | + 'right-center' | + 'right-bottom'; + interface DropdownOptions { + /** + * Dropdown position + * @default 'bottom-left' + */ + pos?: DropdownPosition; + /** + * Dropdown trigger behaviour + * @default 'hover' + */ + mode?: 'hover'|'click'; + /** + * Remain time before auto closing dropdown in hover mode + * @default 800 + */ + remaintime?: number; + /** + * Stretch dropdown width to a specified element + * @default false + */ + justify?: string|JQuery|false; + /** + * Referenced element to keep dropdowns visibilty + * @default window + */ + boundary?: string|JQuery|Window; + /** + * Delay time in hover mode before a dropdown is shown in ms + * @default 0 + */ + delay?: number; + /** + * Dropdown selector + * @default '.uk-dropdown,.uk-dropdown-blank' + */ + dropdownSelector?: string|JQuery; + /** + * Is added to the delay time when hovering from one active dropdown to another dropdown (in ms) + * @default 250 + */ + hoverDelayIdle?: number; + /** + * Prevent automatic dropdown flip + * Possible values: 'x', 'y', true, false + * @default false + */ + preventflip?: 'x'|'y'|boolean; + } + /** + * Create a toggleable dropdown with different styles + * Documentation: {@link http://getuikit.org/docs/dropdown.html} + * + * Events: + * Name Description + * show.uk.dropdown Triggered on dropdown show + * hide.uk.dropdown Triggered on dropdown hide + * stack.uk.dropdown Triggered when a dropdown stacks to fit into screen + */ + type Dropdown = (selector: string|JQuery, options?: DropdownOptions) => DropdownElement; interface ModalElement { /** * Show the modal @@ -1347,6 +1430,7 @@ declare namespace UIkit { * */ type Upload = (element: string|JQuery, options: UploadOptions) => any; + var dropdown: Dropdown; var modal: Modal; var lightbox: LightBox; var offcanvas: OffCanvas; diff --git a/uikit/uikit-tests.ts b/uikit/uikit-tests.ts index 8b634edc33..200a7a470f 100644 --- a/uikit/uikit-tests.ts +++ b/uikit/uikit-tests.ts @@ -1,4 +1,25 @@ +function testDropdown() { + UIkit.dropdown("#parent"); + UIkit.dropdown($("#parent")); + let options: UIkit.DropdownOptions = { + pos: 'bottom-center', + mode: 'click', + remaintime: 150, + justify: false, + boundary: window, + delay: 0, + dropdownSelector: '.uk-dropdown,.uk-dropdown-blank', + hoverDelayIdle: 200, + preventflip: 'x' + }; + var dropdown = UIkit.dropdown("$parent", options); + + dropdown.show(); + dropdown.hide(); + dropdown.hide(true); + dropdown.hide(false); +} function testModal() { UIkit.modal.alert("Attention!");