diff --git a/adal/index.d.ts b/adal/index.d.ts index abff003e97..18ca3d8079 100644 --- a/adal/index.d.ts +++ b/adal/index.d.ts @@ -17,14 +17,18 @@ declare namespace adal { clientId: string; redirectUri?: string; instance?: string; - cacheLocation?: string; + endpoints?: any; // If you need to send CORS api requests. + popUp?: boolean; + localLoginUrl?: string; displayCall?: (urlNavigate: string) => any; + postLogoutRedirectUri?: string; // redirect url after succesful logout operation + cacheLocation?: string; + anonymousEndpoints?: string[]; + expireOffsetSeconds?: number; correlationId?: string; loginResource?: string; resource?: string; - endpoints?: any; // If you need to send CORS api requests. extraQueryParameter?: string; - postLogoutRedirectUri?: string; // redirect url after succesful logout operation } interface User { diff --git a/angular/index.d.ts b/angular/index.d.ts index bd4cd76f59..bae6351cfb 100644 --- a/angular/index.d.ts +++ b/angular/index.d.ts @@ -901,8 +901,17 @@ declare namespace angular { */ interface ILocationService { absUrl(): string; + + /** + * Returns the hash fragment + */ hash(): string; - hash(newHash: string): ILocationService; + + /** + * Changes the hash fragment and returns `$location` + */ + hash(newHash: string|null): ILocationService; + host(): string; /** @@ -942,7 +951,7 @@ declare namespace angular { * @param search New search params * @param paramValue If search is a string or a Number, then paramValue will override only a single search property. If paramValue is null, the property specified via the first argument will be deleted. If paramValue is an array, it will override the property of the search component of $location specified via the first argument. If paramValue is true, the property specified via the first argument will be added with no value nor trailing equal sign. */ - search(search: string, paramValue: string|number|string[]|boolean): ILocationService; + search(search: string, paramValue: string|number|null|string[]|boolean): ILocationService; state(): any; state(state: any): ILocationService; diff --git a/connect-ensure-login/connect-ensure-login-tests.ts b/connect-ensure-login/connect-ensure-login-tests.ts new file mode 100644 index 0000000000..68ce1a76a2 --- /dev/null +++ b/connect-ensure-login/connect-ensure-login-tests.ts @@ -0,0 +1,13 @@ +import login = require("connect-ensure-login"); + +login.ensureLoggedIn(); +login.ensureLoggedIn("/login"); +login.ensureLoggedIn({ + redirectTo: "/login", +}); + +login.ensureLoggedOut(); +login.ensureLoggedOut("/"); +login.ensureLoggedOut({ + redirectTo: "/", +}); \ No newline at end of file diff --git a/connect-ensure-login/index.d.ts b/connect-ensure-login/index.d.ts new file mode 100644 index 0000000000..d542f63a90 --- /dev/null +++ b/connect-ensure-login/index.d.ts @@ -0,0 +1,73 @@ +// Type definitions for connect-ensure-login 0.1 +// Project: https://github.com/jaredhanson/connect-ensure-login +// Definitions by: Pavel Puchkov +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import { RequestHandler } from "express"; + +interface LoggedInOptions { + /** + * URL to redirect to for login, defaults to _/login_ + */ + redirectTo?: string; + /** + * set redirectTo in session, defaults to _true_ + */ + setRedirectTo?: boolean; +} +interface LoggedOutOptions { + /** + * URL to redirect to in logged in, defaults to _/_ + */ + redirectTo?: string; +} + +/** +* Ensure that a user is logged in before proceeding to next route middleware. +* +* This middleware ensures that a user is logged in. If a request is received +* that is unauthenticated, the request will be redirected to a login page (by +* default to `/login`). +* +* Additionally, `returnTo` will be be set in the session to the URL of the +* current request. After authentication, this value can be used to redirect +* the user to the page that was originally requested. +* +* Examples: +* +* app.get('/profile', +* ensureLoggedIn(), +* function(req, res) { ... }); +* +* app.get('/profile', +* ensureLoggedIn('/signin'), +* function(req, res) { ... }); +* +* app.get('/profile', +* ensureLoggedIn({ redirectTo: '/session/new', setReturnTo: false }), +* function(req, res) { ... }); +*/ +export declare function ensureLoggedIn(options?: LoggedInOptions | string): RequestHandler; + +/** +* Ensure that no user is logged in before proceeding to next route middleware. +* +* This middleware ensures that no user is logged in. If a request is received +* that is authenticated, the request will be redirected to another page (by +* default to `/`). +* +* Examples: +* +* app.get('/login', +* ensureLoggedOut(), +* function(req, res) { ... }); +* +* app.get('/login', +* ensureLoggedOut('/home'), +* function(req, res) { ... }); +* +* app.get('/login', +* ensureLoggedOut({ redirectTo: '/home' }), +* function(req, res) { ... }); +*/ +export declare function ensureLoggedOut(options?: LoggedOutOptions | string): RequestHandler; \ No newline at end of file diff --git a/connect-ensure-login/tsconfig.json b/connect-ensure-login/tsconfig.json new file mode 100644 index 0000000000..d683bed903 --- /dev/null +++ b/connect-ensure-login/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", + "connect-ensure-login-tests.ts" + ] +} diff --git a/connect-ensure-login/tslint.json b/connect-ensure-login/tslint.json new file mode 100644 index 0000000000..f9e30021f4 --- /dev/null +++ b/connect-ensure-login/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "../tslint.json" +} diff --git a/decay/decay-tests.ts b/decay/decay-tests.ts new file mode 100644 index 0000000000..41b67b6068 --- /dev/null +++ b/decay/decay-tests.ts @@ -0,0 +1,22 @@ +import {redditHot, hackerHot, wilsonScore} from 'decay'; + +const upvotes = 42; +const downvotes = 12; +const posted = new Date(2017, 1, 1); + +let score: number; + +let redditCalculator = redditHot(); +score = redditCalculator(upvotes, downvotes, posted); +redditCalculator = redditHot(10000); +score = redditCalculator(upvotes, downvotes, posted); + +let hackerCalculator = hackerHot(); +score = hackerCalculator(upvotes, posted); +hackerCalculator = hackerHot(1.6); +score = hackerCalculator(upvotes, posted); + +let wilsonCalculator = wilsonScore(); +score = wilsonCalculator(upvotes, downvotes); +wilsonCalculator = wilsonScore(1.0); +score = wilsonCalculator(upvotes, downvotes); \ No newline at end of file diff --git a/decay/index.d.ts b/decay/index.d.ts new file mode 100644 index 0000000000..1f8fcabe09 --- /dev/null +++ b/decay/index.d.ts @@ -0,0 +1,52 @@ +// Type definitions for decay 1.0 +// Project: https://github.com/clux/decay +// Definitions by: Eric Naeseth +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/** + * Creates a function to rank posts using Reddit's "hot" algorithm. + * @param decay controls how quickly rankings drop with time + * @return calculator function + */ +export function redditHot(decay?: number): RedditHotFunction; + +/** + * Creates a function to rank posts using the Hacker News "hot" algorithm. + * @param gravity controls how quickly rankings drop with time + * @return calculator function + */ +export function hackerHot(gravity?: number): HackerNewsHotFunction; + +/** + * Creates a function to rank posts using the Wilson score interval sort (Reddit's "best" + * algorithm). + * @param confidence statistical confidence + * @return calculator function + * @see {@link https://redditblog.com/2009/10/15/reddits-new-comment-sorting-system/ Reddit's writeup} + */ +export function wilsonScore(confidence?: number): WilsonScoreFunction; + +/** + * Computes a ranking using Reddit's "hot" algorithm. + * @param upvotes number of upvotes the post has received + * @param downvotes number of upvotes the post has received + * @param date when the post was posted + * @return ranking + */ +export type RedditHotFunction = (upvotes: number, downvotes: number, date: Date) => number; + +/** + * Computes a ranking using the Hacker News "hot" algorithm. + * @param votes number of upvotes the post has received + * @param date when the post was posted + * @return ranking + */ +export type HackerNewsHotFunction = (votes: number, date: Date) => number; + +/** + * Computes a ranking using the Wilson score (Reddit's "best" algorithm). + * @param upvotes number of upvotes the post has received + * @param downvotes number of upvotes the post has received + * @return ranking + */ +export type WilsonScoreFunction = (upvotes: number, downvotes: number) => number; diff --git a/decay/tsconfig.json b/decay/tsconfig.json new file mode 100644 index 0000000000..bd236be020 --- /dev/null +++ b/decay/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", + "decay-tests.ts" + ] +} diff --git a/decay/tslint.json b/decay/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/decay/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" } diff --git a/dot/index.d.ts b/dot/index.d.ts index 6bc646b771..893b611d6c 100644 --- a/dot/index.d.ts +++ b/dot/index.d.ts @@ -1,50 +1,42 @@ -// Type definitions for doT v1.0.1 +// Type definitions for doT 1.1 // Project: https://github.com/olado/doT // Definitions by: ZombieHunter // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -declare var doT: doT.doTStatic; +export as namespace doT; -declare namespace doT { +/** Version number */ +export const version: string; - interface doTStatic { - /** - * Version number - */ - version: string; - /** - * Default template settings - */ - templateSettings: TemplateSettings; +/** Default template settings */ +export const templateSettings: TemplateSettings; - /** - * Compile template - */ - template(tmpl: string, c?: TemplateSettings, def?: Object): Function; +type RenderFunction = (...args: any[]) => string; - /** - * For express - */ - compile(tmpl: string, def?: Object): Function; - } +/** Compile template */ +export function template(tmpl: string, c?: TemplateSettings, def?: {}): RenderFunction; - interface TemplateSettings { - evaluate: RegExp; - interpolate: RegExp; - encode: RegExp; - use: RegExp; - useParams: RegExp; - define: RegExp; - defineParams: RegExp; - conditional: RegExp; - iterate: RegExp; - varname: string; - strip: boolean; - append: boolean; - selfcontained: boolean; - } +/** For express */ +export function compile(tmpl: string, def?: {}): RenderFunction; + +interface TemplateSettings { + evaluate: RegExp; + interpolate: RegExp; + encode: RegExp; + use: RegExp; + useParams: RegExp; + define: RegExp; + defineParams: RegExp; + conditional: RegExp; + iterate: RegExp; + varname: string; + strip: boolean; + append: boolean; + selfcontained: boolean; } -interface String { - encodeHTML(): string; +declare global { + interface String { + encodeHTML(): string; + } } diff --git a/dot/tslint.json b/dot/tslint.json new file mode 100644 index 0000000000..2221e40e4a --- /dev/null +++ b/dot/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" } \ No newline at end of file diff --git a/dotenv/dotenv-tests.ts b/dotenv/dotenv-tests.ts index 3d9af0f52e..f609dd4745 100644 --- a/dotenv/dotenv-tests.ts +++ b/dotenv/dotenv-tests.ts @@ -1,12 +1,13 @@ import dotenv = require('dotenv'); // typically, result will be an Object -let env = dotenv.config({ +const env = dotenv.config({ silent: true }); +const dbUrl: string | null = !env ? null : env['DATABASE_URL']; // ... but it might also be `false` -let result = dotenv.config({ +const result = dotenv.config({ path: '.non-existing-env' }); @@ -17,3 +18,9 @@ dotenv.config({ dotenv.config({ encoding: 'utf8' }); + +const parsed = dotenv.parse("ENVIRONMENT=production\nDEBUG=no\n"); +const debug: string = parsed['DEBUG']; + +const parsedFromBuffer = dotenv.parse(new Buffer("JUSTICE=league\n")); +const justice: string = parsedFromBuffer['JUSTICE']; diff --git a/dotenv/index.d.ts b/dotenv/index.d.ts index a326ceaa58..7e015ca8cd 100644 --- a/dotenv/index.d.ts +++ b/dotenv/index.d.ts @@ -1,15 +1,22 @@ -// Type definitions for dotenv 2.0.0 +// Type definitions for dotenv 2.0 // Project: https://github.com/motdotla/dotenv -// Definitions by: Jussi Kinnula , Borek Bernard +// Definitions by: Jussi Kinnula , Borek Bernard , Eric Naeseth // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +/// + +/** + * Parses a string or buffer in the .env file format into an object. + */ +export function parse(src: string | Buffer): {[name: string]: string}; + /** * Loads `.env` into `process.env`. * * @param options * @return Object Object with the parsed keys and values, e.g., 'KEY=value' becomes { KEY: 'value' } */ -export function config(options?: DotenvOptions): Object | false; +export function config(options?: DotenvOptions): {[name: string]: string} | false; export interface DotenvOptions { /** diff --git a/dotenv/tslint.json b/dotenv/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/dotenv/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" } diff --git a/geodesy/geodesy-tests.ts b/geodesy/geodesy-tests.ts new file mode 100644 index 0000000000..53c3b5c05c --- /dev/null +++ b/geodesy/geodesy-tests.ts @@ -0,0 +1,118 @@ +import { + Mgrs, + Utm, + Dms, + Vector3d, + OsGridRef, + LatLonEllipsoidal as LatLon } from 'geodesy'; + +/** + * Mgrs + */ +const mgrs = new Mgrs(31, 'U', 'D', 'Q', 48251, 11932); +const bandMgrs = mgrs.band; +const datumMgrs = mgrs.datum; +const e100kMgrs = mgrs.e100k; +const e100kLettersMgrs = mgrs.e100kLetters; +const eastingMgrs = mgrs.easting; +const latBandsMgrs = mgrs.latBands; +const n100kMgrs = mgrs.n100k; +const n100kLettersMgrs = mgrs.n100kLetters; +const northingMgrs = mgrs.northing; +const zoneMgrs = mgrs.zone; +mgrs.toString(); +mgrs.toUtm(); + + +// Static Functions +Mgrs.parse('31U DQ 48251 11932'); + +/** + * Utm + */ +const utm = new Utm(31, 'N', 448251, 5411932); +const convergenceUtm = utm.convergence; +const datumUtm = utm.datum; +const eastingUtm = utm.easting; +const hemisphereUtm = utm.hemisphere; +const northingUtm = utm.northing; +const scaleUtm = utm.scale; +utm.toLatLonE(); +utm.toMgrs(); +utm.toString(); + +// Static Functions +Utm.parse('31 N 448251 5411932'); + +/** + * Dms + */ + +Dms.separator = '\u202f'; + +// Static Functions +Dms.parseDMS('51° 28′ 40.12″ N'); + +Dms.toDMS(45); +Dms.toDMS(45, 'dm'); +Dms.toDMS(45, 'd', 2); +Dms.toDMS(45, 'dms', 4); + +Dms.toLat(45); +Dms.toLat(45, 'dm'); +Dms.toLat(45, 'd', 2); +Dms.toLat(45, 'dms', 4); + +Dms.toLon(45); +Dms.toLon(45, 'dm'); +Dms.toLon(45, 'd', 2); +Dms.toLon(45, 'dms', 4); + +Dms.toBrng(90); +Dms.toBrng(90, 'dm'); +Dms.toBrng(90, 'd', 2); +Dms.toBrng(90, 'dms', 4); + +Dms.compassPoint(180); +Dms.compassPoint(180, 1); +Dms.compassPoint(180, 2); +Dms.compassPoint(180, 3); + +/** + * Vector3d + */ +const v1 = new Vector3d(4, 23, 13); +const v2 = new Vector3d(5, 42, 33); +const v3 = new Vector3d(8, 12, 43); + +v1.cross(v2).dot(v3); + +/** + * LatLon + */ +const latlon = new LatLon(52.65798, 1.71605); +const latlonWGS84 = new LatLon(51.4778, -0.0016, LatLon.datum.WGS84); +const pWGS84 = new LatLon(51.4778, -0.0016, LatLon.datum.WGS84); +const pOSGB = pWGS84.convertDatum(LatLon.datum.OSGB36); + +latlon.toUtm(); +latlon.toCartesian(); +latlon.toString(); +latlon.toString('dm'); +latlon.toString('d', 0); + +const mgrsGrid = new LatLon(45.4215296, -75.697193).toUtm().toMgrs(); +mgrsGrid.toString(6); + +/** + * OsGridRef + */ +const gridref = new OsGridRef(651409, 313177); +const osgrid = new OsGridRef(651409.903, 313177.270); +new OsGridRef(651409, 313177).toString(); + +// Static Functions +OsGridRef.latLonToOsGrid(latlon); +OsGridRef.osGridToLatLon(gridref); +OsGridRef.osGridToLatLon(gridref, LatLon.datum.OSGB36); +OsGridRef.parse('TG 51409 13177'); diff --git a/geodesy/index.d.ts b/geodesy/index.d.ts new file mode 100644 index 0000000000..d5436f073d --- /dev/null +++ b/geodesy/index.d.ts @@ -0,0 +1,149 @@ +// Type definitions for geodesy 1.1 +// Project: https://github.com/chrisveness/geodesy +// Definitions by: Denis Carriere +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export type format = 'd' | 'dm' | 'dms'; +export type datum = 'ED50'| 'Irl1975'| 'NAD27'| 'NAD83'| 'NTF'| 'OSGB36'| 'Potsdam'| 'TokyoJapan'| 'WGS72'| 'WGS84'; +export type hemisphere = 'N' | 'S'; +export type ellipsoid = 'WGS84' | 'Airy1830' | 'AiryModified' | 'Bessel1841' | 'Clarke1866' | 'Clarke1880IGN' | 'GRS80' | 'Intl1924' | 'WGS72'; +export type transform = [number, number, number, number, number, number, number]; +export type LatLon = LatLonEllipsoidal; + +export interface Datum { + ellipsoid: Ellipsoid; + transform: [number, number, number, number, number, number, number]; +} + +export interface Datums { + ED50: Datum; + Irl1975: Datum; + NAD27: Datum; + NAD83: Datum; + NTF: Datum; + OSGB36: Datum; + Potsdam: Datum; + TokyoJapan: Datum; + WGS72: Datum; + WGS84: Datum; +} + +export interface Ellipsoid { + a: number; + b: number; + f: number; +} + +export interface Ellipsoids { + WGS84: Ellipsoid; + GRS80: Ellipsoid; + Airy1830: Ellipsoid; + AiryModified: Ellipsoid; + Intl1924: Ellipsoid; + Bessel1841: Ellipsoid; +} + +export declare class Mgrs { + zone: number; + band: string; + e100k: string; + n100k: string; + easting: number; + northing: number; + datum: datum; + latBands: string; + e100kLetters: string; + n100kLetters: string; + constructor( + zone: number, + band: string, + e100k: string, + n100k: string, + easting: number, + northing: number, + datum?: datum + ) + static parse(mgrsGridRef: string): Mgrs; + toUtm(): Utm; + toString(digits?: 2 | 4 | 6 | 8 | 10): string; +} + +export declare class Utm { + zone: number; + hemisphere: hemisphere; + easting: number; + northing: number; + datum: Datum; + convergence: number; + scale: number; + constructor( + zone: number, + hemisphere: hemisphere, + easting: number, + northing: number, + datum?: datum, + convergence?: number, + scale?: number + ); + static parse(utmCoord: string, datum?: datum): Utm; + toLatLonE(): LatLon; + toMgrs(): Mgrs; + toString(digits?: number): string; +} + +export declare namespace Dms { + export let separator: string; +} + +export declare class Dms { + static parseDMS(dmsStr: string): number; + static toDMS(deg: number, format?: format, dp?: 0 | 2 | 4): string; + static toLat(deg: number, format?: format, dp?: 0 | 2 | 4): string; + static toLon(deg: number, format?: format, dp?: 0 | 2 | 4): string; + static toBrng(deg: number, format?: format, dp?: 0 | 2 | 4): string; + static compassPoint(bearing: number, precision?: 1 | 2 | 3): string; +} + +export declare class Vector3d { + x: number; + y: number; + z: number; + constructor(x: number, y: number, z: number); + plus(v: Vector3d): Vector3d; + minus(v: Vector3d): Vector3d; + times(x: number): Vector3d; + dividedBy(x: number): Vector3d; + dot(v: Vector3d): number; + cross(v: Vector3d): Vector3d; + negate(): Vector3d; + length(): number; + unit(): Vector3d; + angleTo(v: Vector3d, n?: Vector3d): number; + rotateAround(axis: Vector3d, theta: number): Vector3d; + toString(precision?: number): string; + toLatLonE(datum: Datum): LatLon; + applyTransform(t: number[]): Vector3d; +} + +export declare class OsGridRef { + easting: number; + northing: number; + constructor(easting: number, northing: number); + static latLonToOsGrid(p: LatLon): OsGridRef; + static osGridToLatLon(gridref: OsGridRef, datum?: Datum): LatLon; + static parse(gridref: string): OsGridRef; + toString(digits?: number): string; +} + +export declare class LatLonEllipsoidal { + lat: number; + lon: number; + datum: Datum; + constructor(lat: number, lon: number, datum?: Datum); + toUtm(): Utm; + convertDatum(toDatum: Datum): LatLon; + toCartesian(): Vector3d; + toString(format?: format, dp?: 0 | 2 | 4): string; + static datum: Datums; + static ellipsoid: Ellipsoids; +} diff --git a/geodesy/tsconfig.json b/geodesy/tsconfig.json new file mode 100644 index 0000000000..b73fab8bb3 --- /dev/null +++ b/geodesy/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", + "geodesy-tests.ts" + ] +} diff --git a/geodesy/tslint.json b/geodesy/tslint.json new file mode 100644 index 0000000000..2221e40e4a --- /dev/null +++ b/geodesy/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" } \ No newline at end of file diff --git a/geojson/index.d.ts b/geojson/index.d.ts index 38715a9a27..f6261d81fe 100644 --- a/geojson/index.d.ts +++ b/geojson/index.d.ts @@ -130,3 +130,7 @@ declare namespace GeoJSON { properties: { href: string; type: string } } } + +declare module 'geojson' { + export = GeoJSON; +} diff --git a/leaflet-draw/index.d.ts b/leaflet-draw/index.d.ts index 3cced930c2..9668940c3a 100644 --- a/leaflet-draw/index.d.ts +++ b/leaflet-draw/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for leaflet-draw 0.4.6 +// Type definitions for leaflet-draw 0.4 // Project: https://github.com/Leaflet/Leaflet.draw // Definitions by: Matt Guest , Ryan Blace // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped diff --git a/leaflet-draw/package.json b/leaflet-draw/package.json deleted file mode 100644 index fa93c2516c..0000000000 --- a/leaflet-draw/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "dependencies": { - "@types/leaflet": "^1.0" - } -} diff --git a/leaflet-draw/tsconfig.json b/leaflet-draw/tsconfig.json index caa0de4183..5827e02ff7 100644 --- a/leaflet-draw/tsconfig.json +++ b/leaflet-draw/tsconfig.json @@ -6,6 +6,9 @@ "noImplicitThis": true, "strictNullChecks": false, "baseUrl": "../", + "typeRoots": [ + "../" + ], "types": [], "noEmit": true, "forceConsistentCasingInFileNames": true diff --git a/leaflet-draw/tslint.json b/leaflet-draw/tslint.json new file mode 100644 index 0000000000..9bc375c06b --- /dev/null +++ b/leaflet-draw/tslint.json @@ -0,0 +1,6 @@ +{ + "extends": "../tslint.json", + "rules": { + "no-empty-interface": false + } +} \ No newline at end of file diff --git a/leaflet/index.d.ts b/leaflet/index.d.ts index 71f7c1824a..c031df81bc 100644 --- a/leaflet/index.d.ts +++ b/leaflet/index.d.ts @@ -963,7 +963,8 @@ declare namespace L { position?: ControlPosition; } - export interface Control { + export class Control extends Class { + constructor (options?: ControlOptions); getPosition(): ControlPosition; setPosition(position: ControlPosition): this; getContainer(): HTMLElement; diff --git a/leaflet/leaflet-tests.ts b/leaflet/leaflet-tests.ts index b36337aa6c..c6dca97f5d 100644 --- a/leaflet/leaflet-tests.ts +++ b/leaflet/leaflet-tests.ts @@ -390,3 +390,18 @@ class MyDivIcon extends L.DivIcon { super(); } } + +let myControlClass = L.Control.extend({}); +let myControl = new myControlClass(); + +L.Control.include({}); +L.Control.mergeOptions({}); +L.Control.addInitHook(() => {}); + +export class MyNewControl extends L.Control { + constructor() { + super({ + position: 'topleft' + }); + } +} diff --git a/mongoose/v3/index.d.ts b/mongoose/v3/index.d.ts index f5d831b205..80cca9da2f 100644 --- a/mongoose/v3/index.d.ts +++ b/mongoose/v3/index.d.ts @@ -309,10 +309,16 @@ declare module "mongoose" { (...hookArgs:any[]): any; } + interface CappedOptions { + size: number; + max?: number; + autoIndexId?: boolean; + } + export interface SchemaOption { autoIndex?: boolean; bufferCommands?: boolean; - capped?: boolean; + capped?: boolean | number | CappedOptions; collection?: string; id?: boolean; _id?: boolean; diff --git a/mysql/index.d.ts b/mysql/index.d.ts index 74469591a1..8df59f3d6b 100644 --- a/mysql/index.d.ts +++ b/mysql/index.d.ts @@ -14,7 +14,7 @@ declare function createPool(config: IPoolConfig): IPool; declare function createPoolCluster(config?: IPoolClusterConfig): IPoolCluster; declare function escape(value: any): string; declare function format(sql: string): string; -declare function format(sql: string, values: Array): string; +declare function format(sql: string, values: any[]): string; declare function format(sql: string, values: any): string; interface IMySql { @@ -24,15 +24,15 @@ interface IMySql { createPoolCluster(config?: IPoolClusterConfig): IPoolCluster; escape(value: any): string; format(sql: string): string; - format(sql: string, values: Array): string; + format(sql: string, values: any[]): string; format(sql: string, values: any): string; } interface IConnectionStatic { createQuery(sql: string): IQuery; createQuery(sql: string, callback: (err: IError, ...args: any[]) => void): IQuery; - createQuery(sql: string, values: Array): IQuery; - createQuery(sql: string, values: Array, callback: (err: IError, ...args: any[]) => void): IQuery; + createQuery(sql: string, values: any[]): IQuery; + createQuery(sql: string, values: any[], callback: (err: IError, ...args: any[]) => void): IQuery; } interface IConnection { @@ -67,10 +67,10 @@ interface IConnection { escape(value: any): string; escapeId(value: string): string; - escapeId(values: Array): string; + escapeId(values: string[]): string; format(sql: string): string; - format(sql: string, values: Array): string; + format(sql: string, values: any[]): string; format(sql: string, values: any): string; on(ev: string, callback: (...args: any[]) => void): IConnection; @@ -151,24 +151,24 @@ interface IQuery { on(ev: string, callback: (...args: any[]) => void): IQuery; on(ev: 'error', callback: (err: IError) => void): IQuery; - on(ev: 'fields', callback: (fields: any, index: number) => void): IQuery; + on(ev: 'fields', callback: (fields: IFieldInfo[], index: number) => void): IQuery; on(ev: 'result', callback: (row: any, index: number) => void): IQuery; on(ev: 'end', callback: () => void): IQuery; } interface IQueryFunction { (sql: string): IQuery; - (sql: string, callback: (err: IError, ...args: any[]) => void): IQuery; - (sql: string, values: Array): IQuery; - (sql: string, values: Array, callback: (err: IError, ...args: any[]) => void): IQuery; + (sql: string, callback: (err: IError, results?: any, fields?: IFieldInfo[]) => void): IQuery; + (sql: string, values: any[]): IQuery; + (sql: string, values: any[], callback: (err: IError, results?: any, fields?: IFieldInfo[]) => void): IQuery; (sql: string, values: any): IQuery; - (sql: string, values: any, callback: (err: IError, ...args: any[]) => void): IQuery; + (sql: string, values: any, callback: (err: IError, results?: any, fields?: IFieldInfo[]) => void): IQuery; (options: IQueryOptions): IQuery; - (options: IQueryOptions, callback: (err: IError, ...args: any[]) => void): IQuery; - (options: IQueryOptions, values: Array): IQuery; - (options: IQueryOptions, values: Array, callback: (err: IError, ...args: any[]) => void): IQuery; + (options: IQueryOptions, callback: (err: IError, results?: any, fields?: IFieldInfo[]) => void): IQuery; + (options: IQueryOptions, values: any[]): IQuery; + (options: IQueryOptions, values: any[], callback: (err: IError, results?: any, fields?: IFieldInfo[]) => void): IQuery; (options: IQueryOptions, values: any): IQuery; - (options: IQueryOptions, values: any, callback: (err: IError, ...args: any[]) => void): IQuery; + (options: IQueryOptions, values: any, callback: (err: IError, results?: any, fields?: IFieldInfo[]) => void): IQuery; } interface IQueryOptions { @@ -362,7 +362,7 @@ interface IConnectionConfig extends IConnectionOptions { /** * List of connection flags to use other than the default ones. It is also possible to blacklist default ones */ - flags?: Array; + flags?: string[]; /** * object with ssl parameters or a string containing name of ssl profile @@ -447,12 +447,12 @@ interface ISslCredentials { /** * Either a string or list of strings of PEM encoded CA certificates to trust. */ - ca?: Array; + ca?: string[]; /** * Either a string or list of strings of PEM encoded CRLs (Certificate Revocation List) */ - crl?: Array; + crl?: string[]; /** * A string describing the ciphers to use or exclude diff --git a/passport/index.d.ts b/passport/index.d.ts index 26ae940a2f..9f6641c552 100644 --- a/passport/index.d.ts +++ b/passport/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for Passport 0.3 // Project: http://passportjs.org -// Definitions by: Horiuchi_H +// Definitions by: Horiuchi_H , Eric Naeseth // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare namespace Express { @@ -60,6 +60,11 @@ declare module 'passport' { transformAuthInfo(fn: (info: any, done: (err: any, info: any) => void) => void): void; } + interface PassportStatic extends Passport { + Passport: {new(): Passport}; + Authenticator: {new(): Passport}; + } + interface Strategy { name?: string; authenticate(req: express.Request, options?: any): void; @@ -91,7 +96,7 @@ declare module 'passport' { } } - const passport: passport.Passport; + const passport: passport.PassportStatic; export = passport; } diff --git a/passport/passport-tests.ts b/passport/passport-tests.ts index 43630f5c9f..4c1778df7f 100644 --- a/passport/passport-tests.ts +++ b/passport/passport-tests.ts @@ -108,3 +108,8 @@ function ensureAuthenticated(req: express.Request, res: express.Response, next: } } +const passportInstance: passport.Passport = new passport.Passport() +passportInstance.use(new TestStrategy()) + +const authenticator: passport.Passport = new passport.Authenticator() +authenticator.use(new TestStrategy()) \ No newline at end of file diff --git a/polymer/index.d.ts b/polymer/index.d.ts index 65217fd12f..10b21940c4 100644 --- a/polymer/index.d.ts +++ b/polymer/index.d.ts @@ -318,6 +318,8 @@ declare namespace polymer { interface PolymerStatic { Settings: Settings; + isInstance(element: string): boolean; + Base: Base; dom: DomApiStatic; (prototype: Base | { new (): Base }): webcomponents.CustomElementConstructor; @@ -332,4 +334,3 @@ declare namespace polymer { } declare var Polymer: polymer.PolymerStatic; - diff --git a/react-bootstrap/index.d.ts b/react-bootstrap/index.d.ts index 12dbc5fd09..7cfa207108 100644 --- a/react-bootstrap/index.d.ts +++ b/react-bootstrap/index.d.ts @@ -744,6 +744,7 @@ declare namespace ReactBootstrap { interface GridProps extends React.HTMLProps { componentClass?: React.ReactType; fluid?: boolean; + bsClass?: string; } type Grid = React.ClassicComponent; var Grid: React.ClassicComponentClass; diff --git a/react-native/index.d.ts b/react-native/index.d.ts index 3bb716d1db..c9a9b76dc5 100644 --- a/react-native/index.d.ts +++ b/react-native/index.d.ts @@ -21,102 +21,6 @@ export = React; //react-native "extends" react declare module "react" { - /** - * Represents the completion of an asynchronous operation - * @see lib.es6.d.ts - */ - export interface Promise { - /** - * Attaches callbacks for the resolution and/or rejection of the Promise. - * @param onfulfilled The callback to execute when the Promise is resolved. - * @param onrejected The callback to execute when the Promise is rejected. - * @returns A Promise for the completion of which ever callback is executed. - */ - then(onfulfilled?: (value: T) => TResult | Promise, onrejected?: (reason: any) => TResult | Promise): Promise; - - /** - * Attaches a callback for only the rejection of the Promise. - * @param onrejected The callback to execute when the Promise is rejected. - * @returns A Promise for the completion of the callback. - */ - catch(onrejected?: (reason: any) => T | Promise): Promise; - - - // not in lib.es6.d.ts but called by react-native - done(callback?: (value: T) => void): void; - } - - export interface PromiseConstructor { - /** - * A reference to the prototype. - */ - prototype: Promise; - - /** - * Creates a new Promise. - * @param init A callback used to initialize the promise. This callback is passed two arguments: - * a resolve callback used resolve the promise with a value or the result of another promise, - * and a reject callback used to reject the promise with a provided reason or error. - */ - new (init: (resolve: (value?: T | Promise) => void, reject: (reason?: any) => void) => void): Promise; - - (init: (resolve: (value?: T | Promise) => void, reject: (reason?: any) => void) => void): Promise; - - /** - * Creates a Promise that is resolved with an array of results when all of the provided Promises - * resolve, or rejected when any Promise is rejected. - * @param values An array of Promises. - * @returns A new Promise. - */ - all(values: (T | Promise)[]): Promise; - - /** - * Creates a Promise that is resolved with an array of results when all of the provided Promises - * resolve, or rejected when any Promise is rejected. - * @param values An array of values. - * @returns A new Promise. - */ - all(values: Promise[]): Promise; - - /** - * Creates a Promise that is resolved or rejected when any of the provided Promises are resolved - * or rejected. - * @param values An array of Promises. - * @returns A new Promise. - */ - race(values: (T | Promise)[]): Promise; - - /** - * Creates a new rejected promise for the provided reason. - * @param reason The reason the promise was rejected. - * @returns A new rejected Promise. - */ - reject(reason: any): Promise; - - /** - * Creates a new rejected promise for the provided reason. - * @param reason The reason the promise was rejected. - * @returns A new rejected Promise. - */ - reject(reason: any): Promise; - - /** - * Creates a new resolved promise for the provided value. - * @param value A promise. - * @returns A promise whose internal state matches the provided promise. - */ - resolve(value: T | Promise): Promise; - - /** - * Creates a new resolved promise . - * @returns A resolved promise. - */ - resolve(): Promise; - } - - // @see lib.es6.d.ts - export var Promise: PromiseConstructor; - export type MeasureOnSuccessCallback = ( x: number, y: number, @@ -5634,7 +5538,7 @@ declare module "react" { * Fires when a user has finished scrolling. */ onScrollEndDrag?: (event?: NativeSyntheticEvent) => void - + /** * Fires when scroll view has finished moving */ @@ -6132,43 +6036,43 @@ declare module "react" { /** * Sets value for key and calls callback on completion, along with an Error if there is any */ - setItem(key: string, value: string, callback?: (error?: Error) => void): Promise + setItem(key: string, value: string, callback?: (error?: Error) => void): Promise - removeItem(key: string, callback?: (error?: Error) => void): Promise + removeItem(key: string, callback?: (error?: Error) => void): Promise /** * Merges existing value with input value, assuming they are stringified json. Returns a Promise object. * Not supported by all native implementation */ - mergeItem(key: string, value: string, callback?: (error?: Error) => void): Promise + mergeItem(key: string, value: string, callback?: (error?: Error) => void): Promise /** * Erases all AsyncStorage for all clients, libraries, etc. You probably don't want to call this. * Use removeItem or multiRemove to clear only your own keys instead. */ - clear(callback?: (error?: Error) => void): Promise + clear(callback?: (error?: Error) => void): Promise /** * Gets all keys known to the app, for all callers, libraries, etc */ - getAllKeys(callback?: (error?: Error, keys?: string[]) => void): Promise + getAllKeys(callback?: (error?: Error, keys?: string[]) => void): Promise /** * multiGet invokes callback with an array of key-value pair arrays that matches the input format of multiSet */ - multiGet(keys: string[], callback?: (errors?: Error[], result?: string[][]) => void): Promise + multiGet(keys: string[], callback?: (errors?: Error[], result?: [string, string][]) => void): Promise<[string, string][]> /** * multiSet and multiMerge take arrays of key-value array pairs that match the output of multiGet, * * multiSet([['k1', 'val1'], ['k2', 'val2']], cb); */ - multiSet(keyValuePairs: string[][], callback?: (errors?: Error[]) => void): Promise + multiSet(keyValuePairs: string[][], callback?: (errors?: Error[]) => void): Promise /** * Delete all the keys in the keys array. */ - multiRemove(keys: string[], callback?: (errors?: Error[]) => void): Promise + multiRemove(keys: string[], callback?: (errors?: Error[]) => void): Promise /** * Merges existing values with input values, assuming they are stringified json. @@ -6176,7 +6080,7 @@ declare module "react" { * * Not supported by all native implementations. */ - multiMerge(keyValuePairs: string[][], callback?: (errors?: Error[]) => void): Promise + multiMerge(keyValuePairs: string[][], callback?: (errors?: Error[]) => void): Promise } export type BackPressEventName = "hardwareBackPress" diff --git a/react-virtualized/index.d.ts b/react-virtualized/index.d.ts index 345dcc79db..ab43deb8b7 100644 --- a/react-virtualized/index.d.ts +++ b/react-virtualized/index.d.ts @@ -1,6 +1,6 @@ -// Type definitions for react-virtualized +// Type definitions for react-virtualized 8.9.0 // Project: https://github.com/bvaughn/react-virtualized -// Definitions by: Ian Ker-Seymer +// Definitions by: Andrew de Waal // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// @@ -50,6 +50,26 @@ declare module "react-virtualized" { type GridProps = any; export class Grid extends React.Component { } + interface ListProps { + className?: string; + autoHeight?: boolean; + estimatedRowSize?: number; + height: number; + noRowsRenderer?: Function; + onRowsRendered?: (info: { overscanStartIndex: number, overscanStopIndex: number, startIndex: number, stopIndex: number }) => void; + onScroll?: (info: { clientHeight: number, scrollHeight: number, scrollTop: number }) => void; + overscanRowCount?: number; + rowHeight: number | ((info: { index: number }) => number); + rowRenderer: (info: { index: number, isScrolling: boolean }) => React.ReactNode; + rowCount: number; + scrollToAlignment?: string; + scrollToIndex?: number; + scrollTop?: number; + style?: React.CSSProperties; + tabIndex?: number; + width: number; + } + export class List extends React.Component { } /* * Higher-Order Components diff --git a/react-virtualized/react-virtualized-tests.tsx b/react-virtualized/react-virtualized-tests.tsx index 6c799746fd..791e4df9a0 100644 --- a/react-virtualized/react-virtualized-tests.tsx +++ b/react-virtualized/react-virtualized-tests.tsx @@ -19,6 +19,7 @@ import { InfiniteLoader, ScrollSync, WindowScroller, + List } from "react-virtualized"; /* @@ -107,6 +108,26 @@ function GridTest() { ); } +function ListTest() { + // List data + const list = [ + {name: 'Brian Vaughn', occupation: 'Software Engineer', location: 'San Jose, CA, 95125' /* ... */} + // And so on... + ]; + + // Render your List + ReactDOM.render( + list[index]} + />, + document.getElementById('example') + ); +} + function VirtualScrollTest() { // List data as an array of strings const list = [ diff --git a/webpack-dev-middleware/index.d.ts b/webpack-dev-middleware/index.d.ts new file mode 100644 index 0000000000..e173d4e3d4 --- /dev/null +++ b/webpack-dev-middleware/index.d.ts @@ -0,0 +1,49 @@ +// Type definitions for webpack-dev-middleware 1.9 +// Project: http://github.com/webpack/webpack-dev-middleware +// Definitions by: Benjamin Lim +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import { NextHandleFunction } from 'connect'; +import { compiler } from 'webpack'; + +export = WebpackDevMiddleware; + +declare function WebpackDevMiddleware(compiler: compiler.Compiler, options: WebpackDevMiddleware.Options): WebpackDevMiddleware.WebpackDevMiddleware & NextHandleFunction; + +declare namespace WebpackDevMiddleware { + interface Options { + noInfo?: boolean; + quiet?: boolean; + lazy?: boolean; + watchOptions?: compiler.WatchOptions; + publicPath: string; + index?: string; + headers?: { + [name: string]: string; + }; + stats?: compiler.StatsToStringOptions; + reporter?: Reporter | null; + serverSideRender?: boolean; + + log?: Logger; + warn?: Logger; + error?: Logger; + filename?: string; + } + + interface ReporterOptions { + state: boolean; + stats: compiler.Stats; + options: Options; + } + + type Reporter = (reporterOptions: ReporterOptions) => void; + + type Logger = (message: any) => void; + + interface WebpackDevMiddleware { + close(callback?: () => void): void; + invalidate(callback?: (stats: compiler.Stats) => void): void; + waitUntilValid(callback?: (stats: compiler.Stats) => void): void; + } +} diff --git a/webpack-dev-middleware/tsconfig.json b/webpack-dev-middleware/tsconfig.json new file mode 100644 index 0000000000..4ed359215b --- /dev/null +++ b/webpack-dev-middleware/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", + "webpack-dev-middleware-tests.ts" + ] +} diff --git a/webpack-dev-middleware/tslint.json b/webpack-dev-middleware/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/webpack-dev-middleware/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" } diff --git a/webpack-dev-middleware/webpack-dev-middleware-tests.ts b/webpack-dev-middleware/webpack-dev-middleware-tests.ts new file mode 100644 index 0000000000..b204fbe5d8 --- /dev/null +++ b/webpack-dev-middleware/webpack-dev-middleware-tests.ts @@ -0,0 +1,33 @@ +import * as express from 'express'; +import * as webpack from 'webpack'; +import * as webpackDevMiddleware from 'webpack-dev-middleware'; + +const compiler = webpack({}); +const webpackDevMiddlewareInstance = webpackDevMiddleware(compiler, { + noInfo: false, + quiet: false, + lazy: true, + watchOptions: { + aggregateTimeout: 300, + poll: true, + }, + publicPath: '/assets/', + index: 'index.html', + headers: { + 'X-Custom-Header': 'yes' + }, + stats: { + colors: true, + }, + reporter: null, + serverSideRender: false, +}); + +const app = express(); +app.use(webpackDevMiddlewareInstance); + +webpackDevMiddlewareInstance.close(); +webpackDevMiddlewareInstance.invalidate(); +webpackDevMiddlewareInstance.waitUntilValid(function(){ + console.log('Package is in a valid state'); +}); diff --git a/webpack/index.d.ts b/webpack/index.d.ts index de9e2c89a2..c2a435da6e 100644 --- a/webpack/index.d.ts +++ b/webpack/index.d.ts @@ -1,6 +1,6 @@ -// Type definitions for webpack 2.1 +// Type definitions for webpack 2.2 // Project: https://github.com/webpack/webpack -// Definitions by: Qubo +// Definitions by: Qubo , Matt Lewis // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// @@ -543,7 +543,12 @@ declare namespace webpack { * When there are errors while compiling this plugin skips the emitting phase (and recording phase), * so there are no assets emitted that include errors. The emitted flag in the stats is false for all assets. */ - NoErrorsPlugin: NoErrorsPluginStatic; + NoEmitOnErrorsPlugin: NoEmitOnErrorsPluginStatic; + /** + * Alias for NoEmitOnErrorsPlugin + * @deprecated + */ + NoErrorsPlugin: NoEmitOnErrorsPluginStatic; /** * Does not watch specified files matching provided paths or RegExps. */ @@ -553,6 +558,12 @@ declare namespace webpack { * Helps with debugging, but increases bundle size. */ NamedModulesPlugin: NamedModulesPluginStatic; + /** + * Some loaders need context information and read them from the configuration. + * This need to be passed via loader options in the long-term. See loader documentation for relevant options. + * To keep compatibility with old loaders, these options can be passed via this plugin. + */ + LoaderOptionsPlugin: LoaderOptionsPluginStatic; } interface Optimize { @@ -706,7 +717,7 @@ declare namespace webpack { new (): Plugin; } - interface NoErrorsPluginStatic { + interface NoEmitOnErrorsPluginStatic { new (): Plugin; } @@ -718,6 +729,10 @@ declare namespace webpack { new (): Plugin; } + interface LoaderOptionsPluginStatic { + new (options: any): Plugin; + } + namespace optimize { interface DedupePluginStatic { new (): Plugin; diff --git a/webpack/webpack-tests.ts b/webpack/webpack-tests.ts index 770f96aec7..8cdb92c94b 100644 --- a/webpack/webpack-tests.ts +++ b/webpack/webpack-tests.ts @@ -363,7 +363,11 @@ plugin = new webpack.EvalSourceMapDevToolPlugin(false); plugin = new webpack.HotModuleReplacementPlugin(); plugin = new webpack.ExtendedAPIPlugin(); plugin = new webpack.NoErrorsPlugin(); +plugin = new webpack.NoEmitOnErrorsPlugin(); plugin = new webpack.WatchIgnorePlugin(paths); +plugin = new webpack.LoaderOptionsPlugin({ + debug: true +}); // // http://webpack.github.io/docs/node.js-api.html diff --git a/yeoman-generator/index.d.ts b/yeoman-generator/index.d.ts index 48c706657e..0110e536d6 100644 --- a/yeoman-generator/index.d.ts +++ b/yeoman-generator/index.d.ts @@ -1,250 +1,116 @@ -// Type definitions for yeoman-generator +// Type definitions for yeoman-generator 1.0 // Project: https://github.com/yeoman/generator -// Definitions by: Kentaro Okuno +// Definitions by: Kentaro Okuno , Jay Anslow // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -/// -export = yo; +import { EventEmitter } from 'events'; +import { Questions, Answers } from 'inquirer'; -declare namespace yo { - export interface IYeomanGenerator { - argument(name: string, config: IArgumentConfig): void; - composeWith(namespace: string, options: any, settings?: IComposeSetting): IYeomanGenerator; - defaultFor(name: string): void; - destinationRoot(rootPath?: string): string; - destinationPath(...path: string[]): string; - determineAppname(): void; - getCollisionFilter(): (output: any) => void; - hookFor(name: string, config: IHookConfig): void; - option(name: string, config: IYeomanGeneratorOption): void; - rootGeneratorName(): string; - run(args?: any): void; - run(args: any, callback?: Function): void; - runHooks(callback?: Function): void; - sourceRoot(rootPath?: string): string; - templatePath(...path: string[]): string; - prompt(opt: IPromptOptions | IPromptOptions[], callback: (answers: any) => void): void; - prompt(opt: IPromptOptions | IPromptOptions[]): PromiseLike; - npmInstall(packages?: string[] | string, options?: any, cb?: Function): void; - installDependencies(options?: IInstallDependencyOptions): void; - spawnCommand(name: string, args?: string[], options?: Object): void; - spawnCommandSync(name: string, args?: string[], options?: Object): void; - options: { [key: string]: any }; - fs: IMemFsEditor; +declare type Callback = (err: any) => void; + +declare namespace Base { + class Storage { + constructor(name: string, fs: MemFsEditor, configPath: string); + + defaults(defaults: {}): {}; + delete(key: string): void; + get(key: string): any; + getAll(): { [key: string]: any }; + save(): void; + set(key: string, value: any): any; } - - export class YeomanGeneratorBase extends NodeJS.EventEmitter implements IYeomanGenerator { - argument(name: string, config: IArgumentConfig): void; - composeWith(namespace: string, options: any, settings?: IComposeSetting): IYeomanGenerator; - defaultFor(name: string): void; - destinationRoot(rootPath?: string): string; - destinationPath(...path: string[]): string; - determineAppname(): void; - getCollisionFilter(): (output: any) => void; - hookFor(name: string, config: IHookConfig): void; - option(name: string, config?: IYeomanGeneratorOption): void; - rootGeneratorName(): string; - run(args?: any): void; - run(args: any, callback?: Function): void; - runHooks(callback?: Function): void; - sourceRoot(rootPath?: string): string; - templatePath(...path: string[]): string; - addListener(event: string, listener: Function): this; - on(event: string, listener: Function): this; - once(event: string, listener: Function): this; - removeListener(event: string, listener: Function): this; - removeAllListeners(event?: string): this; - setMaxListeners(n: number): this; - getMaxListeners(): number; - listeners(event: string): Function[]; - emit(event: string, ...args: any[]): boolean; - listenerCount(type: string): number; - - async(): any; - prompt(opt: IPromptOptions | IPromptOptions[], callback: (answers: any) => void): void; - prompt(opt: IPromptOptions | IPromptOptions[]): PromiseLike; - log(message: string) : void; - npmInstall(packages: string[], options?: any, cb?: Function) :void; - installDependencies(options?: IInstallDependencyOptions): void; - spawnCommand(name: string, args?: string[], options?: Object): void; - spawnCommandSync(name: string, args?: string[], options?: Object): void; - - appname: string; - gruntfile: IGruntFileStatic; - options: { [key: string]: any }; - fs: IMemFsEditor; - } - - export interface IMemFsEditor { - read(filepath: string, options?: Object): string; - readJSON(filepath: string, defaults?: Object): Object; - write(filepath: string, contents: string): void; - writeJSON(filepath: string, contents: Object, replacer?: Function, space?: number): void; - delete(filepath: string, options?: Object): void; - copy(from: string, to: string, options?: Object): void; - copyTpl(from: string, to: string, context: Object, options?: Object): void; - move(from: string, to: string, options?: Object): void; - exists(filepath: string): boolean; - commit(callback: Function): void; - commit(filters: any[], callback: Function): void; - } - - export interface IInstallDependencyOptions { + interface InstallOptions { npm?: boolean; bower?: boolean; + yarn?: boolean; skipMessage?: boolean; - callback?: Function; + callback?: Callback; } - - export interface IChoice { - name: string; - value: string; - short?: string; - } - - export interface IPromptOptions{ - type?: string; - name: string; - message: string | ((answers: Object) => string); - choices?: any[] | ((answers: Object) => any); - default?: string | number | string[] | number[] | ((answers: Object) => (string | number | string[] | number[])); - validate?: ((input: any) => boolean | string); - filter?: ((input: any) => any); - when?: ((answers: Object) => boolean) | boolean; - store?: boolean; - } - - export interface IGruntFileStatic { - loadNpmTasks(pluginName: string): void; - insertConfig(name:string, config:any):void; - registerTask(name:string, tasks:any):void; - insertVariable(name:string, value:any):void; - prependJavaScript(code:string):void; - } - - export interface IArgumentConfig { - desc: string; + interface ArgumentConfig { + description?: string; required?: boolean; optional?: boolean; - type: any; - defaults?: any; + type?: typeof String|typeof Number|typeof Array|typeof Object; + default?: any; } - - export interface IComposeSetting { - local?: string; - link?: string; - } - - export interface IHookConfig { - as: string; - args: any; - options: any; - } - - export interface IYeomanGeneratorOption { + interface OptionConfig { alias?: string; - defaults?: any; - desc?: string; + default?: any; + description?: string; hide?: boolean; - type?: any; + type?: typeof Boolean|typeof String|typeof Number; } - - export interface IQueueProps { - initializing: () => void; - prompting?: () => void; - configuring?: () => void; - default?: () => void; - writing: { - [target: string]: () => void; - }; - conflicts?: () => void; - install?: () => void; - end: () => void; - } - - export interface INamedBase extends IYeomanGenerator { - } - - export interface IBase extends INamedBase { - } - - export interface IAssert { - file(path: string): void; - file(paths: string[]): void; - fileContent(file: string, reg: RegExp): void; - - /** @param {[String, RegExp][]} pairs */ - fileContent(pairs: any[][]): void; - - /** @param {[String, RegExp][]|String[]} pairs */ - files(pairs: any[]): void; - - /** - * @param {Object} subject - * @param {Object|Array} methods - */ - implement(subject: any, methods: any): void; - noFile(file: string): void; - noFileContent(file: string, reg: RegExp): void; - - /** @param {[String, RegExp][]} pairs */ - noFileContent(pairs: any[][]): void; - - /** - * @param {Object} subject - * @param {Object|Array} methods - */ - noImplement(subject: any, methods: any): void; - - textEqual(value: string, expected: string): void; - } - - export interface ITestHelper { - createDummyGenerator(): IYeomanGenerator; - createGenerator(name: string, dependencies: any[], args: any, options: any): IYeomanGenerator; - decorate(context: any, method: string, replacement: Function, options: any): void; - gruntfile(options: any, done: Function): void; - mockPrompt(generator: IYeomanGenerator, answers: any): void; - registerDependencies(dependencies: string[]): void; - restore(): void; - - /** @param {String|Function} generator */ - run(generator: any): IRunContext; - } - - export interface IRunContext { - async(): Function; - inDir(dirPath: string): IRunContext; - - /** @param {String|String[]} args */ - withArguments(args: any): IRunContext; - withGenerators(dependencies: string[]): IRunContext; - withOptions(options: any): IRunContext; - withPrompts(answers: any): IRunContext; - } - - /** @type file file-utils */ - var file: any; - var assert: IAssert; - var test: ITestHelper; - - // "generators" is deprecated - namespace generators { - - export class NamedBase extends YeomanGeneratorBase implements INamedBase { - constructor(args: string | string[], options: any); - } - - export class Base extends NamedBase implements IBase { - static extend(protoProps: IQueueProps, staticProps?: any): IYeomanGenerator; - } - } - - export class NamedBase extends YeomanGeneratorBase implements INamedBase { - constructor(args: string | string[], options: any); - } - - export class Base extends NamedBase implements IBase { - static extend(protoProps: IQueueProps, staticProps?: any): IYeomanGenerator; + interface MemFsEditor { + read(filepath: string, options?: {}): string; + readJSON(filepath: string, defaults?: {}): any; + write(filepath: string, contents: string): void; + writeJSON(filepath: string, contents: {}, replacer?: (key: string, value: any) => any, space?: number): void; + extendJSON(filepath: string, contents: {}, replacer?: (key: string, value: any) => any, space?: number): void; + delete(filepath: string, options?: {}): void; + copy(from: string, to: string, options?: {}): void; + copyTpl(from: string, to: string, context: {}, templateOptions?: {}, copyOptions?: {}): void; + move(from: string, to: string, options?: {}): void; + exists(filepath: string): boolean; + commit(callback: Callback): void; + commit(filters: any[], callback: Callback): void; } } + +declare class Base extends EventEmitter { + static extend(protoProps?: any, staticProps?: any): Base; + + constructor(args: string|string[], options: {}); + + env: {}; + args: {}; + resolved: string; + description: string; + appname: string; + config: Base.Storage; + fs: Base.MemFsEditor; + log(message?: string, context?: any): void; + + argument(name: string, config: Base.ArgumentConfig): this; + composeWith(namespace: string, options: { [name: string]: any }, settings?: { local: string, link: 'weak'|'strong' }): this; + destinationPath(...path: string[]): string; + destinationRoot(rootPath?: string): string; + determineAppname(): string; + option(name: string, config: Base.OptionConfig): this; + prompt(questions: Questions): Promise; + registerTransformStream(stream: {}|Array<{}>): this; + rootGeneratorName(): string; + rootGeneratorVersion(): string; + run(cb?: Callback): this; + sourceRoot(rootPath?: string): string; + templatePath(...path: string[]): string; + + // actions/help mixin + argumentsHelp(): string; + desc(description: string): this; + help(): string; + optionsHelp(): string; + usage(): string; + + // actions/spawn_command mixin + spawnCommand(command: string, args: string[], opt?: {}): any; + spawnCommandSync(command: string, args: string[], opt?: {}): any; + + // actions/install mixin + bowerInstall(component?: string|string[], options?: {}, cb?: Callback, spawnOptions?: {}): this; + installDependencies(options?: Base.InstallOptions): this; + npmInstall(pkgs?: string|string[], options?: {}, cb?: Callback, spawnOptions?: {}): this; + runInstall(installer: string, paths?: string|string[], options?: {}, cb?: Callback, spawnOptions?: {}): this; + yarnInstall(pkgs?: string|string[], options?: {}, cb?: Callback, spawnOptions?: {}): this; + + // actions/user mixin + readonly user: { + readonly git: { + email(): string; + name(): string; + }; + readonly github: { + username(): string; + } + }; +} +export = Base; diff --git a/yeoman-generator/tsconfig.json b/yeoman-generator/tsconfig.json index a86e42c3ff..9e25a269e7 100644 --- a/yeoman-generator/tsconfig.json +++ b/yeoman-generator/tsconfig.json @@ -4,7 +4,7 @@ "target": "es6", "noImplicitAny": true, "noImplicitThis": true, - "strictNullChecks": false, + "strictNullChecks": true, "baseUrl": "../", "typeRoots": [ "../" @@ -17,4 +17,4 @@ "index.d.ts", "yeoman-generator-tests.ts" ] -} \ No newline at end of file +} diff --git a/yeoman-generator/tslint.json b/yeoman-generator/tslint.json new file mode 100644 index 0000000000..ec365f164b --- /dev/null +++ b/yeoman-generator/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "../tslint.json" +} diff --git a/yeoman-generator/yeoman-generator-tests.ts b/yeoman-generator/yeoman-generator-tests.ts index 7fe4c993d1..fb3be4ce05 100644 --- a/yeoman-generator/yeoman-generator-tests.ts +++ b/yeoman-generator/yeoman-generator-tests.ts @@ -1,202 +1,150 @@ +import Base = require('yeoman-generator'); +import { Questions, Answers } from 'inquirer'; +import { EventEmitter } from 'events'; -import yeoman = require('yeoman-generator'); +class MyES2015Generator extends Base {} -var base = yeoman.generators.Base; -var namedBase = yeoman.generators.NamedBase; +const MyGenerator = Base.extend({ + writing: function(this: Base): void { + this.fs.write('var foo = 1;', this.destinationPath('index.js')); + } +}) -var generator = base.extend({ - initializing: function() { - return; - }, - writing: { - app: function() { - return; - }, - other: function() { - return; - } - }, - end: function() { - return; +const generator = new MyES2015Generator(['arg1', 'arg2'], { opt1: 'foo', opt2: 3, opt3: false }); +const eventEmitter: EventEmitter = generator; + +const env: Object = generator.env; +const args: Object = generator.args; +const resolved: string = generator.resolved; +const description: string = generator.description; +const appname: string = generator.appname; +const config: Base.Storage = generator.config; +const fs: Base.MemFsEditor = generator.fs; +generator.log('my message'); + +generator.argument('arg1', {}); +generator.argument('arg2', { + description: 'second argument', + required: false, + optional: true, + type: String, + default: 'foo', +}); +generator.argument('arg2', { + description: 'second argument', + required: false, + type: Number, + default: 3, +}); +generator.argument('arg3', { + optional: true, + type: Array, + default: ['an item'], +}); +generator.argument('arg4', { + type: Object, + default: {}, +}); + +const argsHelp = generator.argumentsHelp(); + +generator.installDependencies(); +generator.installDependencies({ + bower: true, + npm: true, + callback: function () { + console.log('Everything is ready!'); } }); -generator.argument('name', { - desc: 'desc', - required: true, - optional: true, - type: 'any', - defaults: 'any', -}); +generator.bowerInstall(); +generator.bowerInstall('pkg'); +generator.bowerInstall(['pkg1', 'pkg2']); +generator.bowerInstall('pkg', {}); +generator.bowerInstall('pkg', { 'custom-option': 3 }, () => {}); +generator.bowerInstall('pkg', {}, () => {}, {}); -var compose = generator.composeWith('namespace', 'any', { - local: 'local', - link: 'link' -}); - -compose.defaultFor('name'); -compose.destinationRoot() === 'string'; -compose.destinationRoot('rootPath') === 'string'; -compose.determineAppname(); -compose.getCollisionFilter()('output'); -compose.hookFor('name', { - as: 'string', - args: 'any', - options: 'any' -}); -compose.option('name', { - alias: 'string', - defaults: 'any', - desc: 'string', - hide: true, - type: 'any' -}); -var returnString: boolean; -returnString = compose.rootGeneratorName() === 'string'; -compose.run('args'); -compose.run('args', () => { - return; -}); -compose.runHooks(() => { - return; -}); -compose.sourceRoot('rootPath') === 'string'; -compose.sourceRoot() === 'string'; - -var assert = yeoman.assert; - -assert.file('path'); -assert.file(['paths', 'paths']); -assert.fileContent('file', /.*/); -assert.fileContent([ - ['string', /.*/], - ['string', /.*/], - ['string', /.*/] -]); -assert.files([ - ['string', /.*/], - 'string', - ['string', /.*/], - 'string' -]); -assert.implement('subject', 'methods'); -assert.noFile('file'); -assert.noFileContent('file', /.*/); -assert.noFileContent([ - ['string', /.*/], - ['string', /.*/], - ['string', /.*/] -]); -assert.noImplement('subject', 'methods'); -assert.textEqual('value', 'expected'); - -var test = yeoman.test; -var dummyGen = test.createDummyGenerator(); -dummyGen.determineAppname(); - -var createdGen = test.createGenerator('name', ['any', 'amy'], 'args', 'options'); -createdGen.determineAppname(); - -test.decorate('context', 'method', () => { - return; // replacement -}, 'options'); -test.gruntfile('options', () => { - return; // done -}); -test.mockPrompt(createdGen, 'answers'); -test.registerDependencies(['dependencies', 'dependencies']); -test.restore(); -var runContext = test.run('generator'); - -runContext.async()(); -runContext.inDir('dirPath') - .withArguments('args') - .withGenerators(['deps', 'deps']) - .withOptions('opts') - .withPrompts('answers'); - -// http://yeoman.io/generator/Base.html#destinationPath -generator.destinationPath() === 'string'; -generator.destinationPath('path1') === 'string'; -generator.destinationPath('path1', 'path2') === 'string'; -generator.destinationPath('path1', 'path2', 'path3') === 'string'; - -// http://yeoman.io/generator/Base.html#templatePath -generator.templatePath() === 'string'; -generator.templatePath('path1') === 'string'; -generator.templatePath('path1', 'path2') === 'string'; -generator.templatePath('path1', 'path2', 'path3') === 'string'; - -// http://yeoman.io/generator/Base.html#npmInstall generator.npmInstall(); generator.npmInstall('pkg'); -generator.npmInstall([ 'pkg1', 'pkg2' ]); +generator.npmInstall(['pkg1', 'pkg2']); generator.npmInstall('pkg', {}); -generator.npmInstall('pkg', {}, () => {}); +generator.npmInstall('pkg', { 'custom-option': 3 }, () => {}); +generator.npmInstall('pkg', {}, () => {}, {}); -// http://yeoman.io/generator/Base.html#installDependencies -generator.installDependencies(); -generator.installDependencies({}); -generator.installDependencies({ npm: true }); -generator.installDependencies({ bower: true }); -generator.installDependencies({ skipMessage: true }); -generator.installDependencies({ callback: () => {} }); +generator.yarnInstall(); +generator.yarnInstall('pkg'); +generator.yarnInstall(['pkg1', 'pkg2']); +generator.yarnInstall('pkg', {}); +generator.yarnInstall('pkg', { 'custom-option': 3 }, () => {}); +generator.yarnInstall('pkg', {}, () => {}, {}); + +generator.runInstall('installer'); +generator.runInstall('installer', 'pkg'); +generator.runInstall('installer', ['pkg1', 'pkg2']); +generator.runInstall('installer', 'pkg', {}); +generator.runInstall('installer', 'pkg', { 'custom-option': 3 }, () => {}); +generator.runInstall('installer', 'pkg', {}, () => {}, {}); + + +const composed1: Base = generator.composeWith('bootstrap', { sass: true }); +const composed2: Base = generator.composeWith(require.resolve('generator-bootstrap/app/main.js'), { sass: true }); + +generator.desc('new description'); + +const dPath1: string = generator.destinationPath(); +const dPath2: string = generator.destinationPath('foo'); +const dPath3: string = generator.destinationPath(...['many', 'parts']); + +const appname2: string = generator.determineAppname(); + +const gitEmail: string = generator.user.git.email(); +const gitName: string = generator.user.git.name(); +const githubUsername: string = generator.user.github.username(); + +const help: string = generator.help(); + +generator.option('name', {}); +generator.option('opt2', { + description: 'a description', + type: Boolean, + alias: 'h', + default: false, + hide: false, +}); +generator.option('opt3', { + type: String, + default: 'default value', +}); +generator.option('opt4', { + type: Number, + default: 3.2, +}); + +const optionsHelp: string = generator.optionsHelp(); + +const answers: Promise = generator.prompt([] as Questions); + +generator.registerTransformStream([]); + +const rootGeneratorName: string = generator.rootGeneratorName(); +const rootGeneratorVersion: string = generator.rootGeneratorVersion(); + +generator.run(); +generator.run(() => undefined); + +const sourceRoot: string = generator.sourceRoot(); +const sourceRoot2: string = generator.sourceRoot('new root'); -// http://yeoman.io/generator/Base.html#spawnCommand generator.spawnCommand('command', []); generator.spawnCommand('command', [ '-arg' ]); generator.spawnCommand('command', [], {}); -// http://yeoman.io/generator/Base.html#spawnCommandSync generator.spawnCommandSync('command', []); generator.spawnCommandSync('command', [ '-arg' ]); generator.spawnCommandSync('command', [], {}); -// http://yeoman.io/generator/Base.html#option -generator.options['opt'] === 'string'; +const tPath1: string = generator.templatePath(); +const tPath2: string = generator.templatePath('foo'); +const tPath3: string = generator.templatePath(...['many', 'parts']); -// http://yeoman.io/generator/Base.html#prompt -// https://github.com/SBoudrias/Inquirer.js -generator.prompt({ name: 'Name', message: 'Message' }, (answer) => {}); -generator.prompt({ name: 'Name', message: (answers) => 'Message' }, (answer) => {}); -generator.prompt({ name: 'Name', message: '', choices: [ 'c1', 'c2' ] }, (answer) => {}); -generator.prompt({ name: 'Name', message: '', choices: [ { name: 'Choice 1', value: 'c1' } ] }, (answer) => {}); -generator.prompt({ name: 'Name', message: '', choices: (answers) => [ 'c1', 'c2' ] }, (answer) => {}); -generator.prompt({ name: 'Name', message: '', choices: (answers) => [ { name: 'Choice 1', value: 'c1' } ] }, (answer) => {}); -generator.prompt({ name: 'Name', message: '', choices: (answers) => [ { name: 'Choice 1', value: 'c1', short: '1' } ] }, (answer) => {}); -generator.prompt({ name: 'Name', message: '', default: 'string' }, (answer) => {}); -generator.prompt({ name: 'Name', message: '', default: 10 }, (answer) => {}); -generator.prompt({ name: 'Name', message: '', default: [ 'string' ] }, (answer) => {}); -generator.prompt({ name: 'Name', message: '', default: [ 10 ] }, (answer) => {}); -generator.prompt({ name: 'Name', message: '', default: (answers) => [ 'string' ] }, (answer) => {}); -generator.prompt({ name: 'Name', message: '', default: (answers) => [ 10 ] }, (answer) => {}); -generator.prompt({ name: 'Name', message: '', default: (answers) => 'string' }, (answer) => {}); -generator.prompt({ name: 'Name', message: '', default: (answers) => 10 }, (answer) => {}); -generator.prompt({ name: 'Name', message: '', type: "list" }, (answer) => {}); -generator.prompt({ name: 'Name', message: '', validate: (input) => true }, (answer) => {}); -generator.prompt({ name: 'Name', message: '', validate: (input) => "Error" }, (answer) => {}); -generator.prompt({ name: 'Name', message: '', filter: (input: any) => input }, (answer) => {}); -generator.prompt({ name: 'Name', message: '', when: (answers) => true }, (answer) => {}); -generator.prompt({ name: 'Name', message: '', when: true }, (answer) => {}); - -// http://yeoman.io/generator/Base.html -// https://github.com/SBoudrias/mem-fs-editor -generator.fs.read("file") === "string"; -generator.fs.read("file", {}) === "string"; -generator.fs.readJSON("file") === {}; -generator.fs.readJSON("file", {}) === {}; -generator.fs.write("file", "contents"); -generator.fs.writeJSON("file", {}); -generator.fs.writeJSON("file", {}, () => {}); -generator.fs.writeJSON("file", {}, () => {}, 2); -generator.fs.delete("file"); -generator.fs.delete("file", {}); -generator.fs.copy("from", "to"); -generator.fs.copy("from", "to", {}); -generator.fs.copyTpl("from", "to", {}); -generator.fs.copyTpl("from", "to", {}, {}); -generator.fs.move("from", "to"); -generator.fs.move("from", "to", {}); -generator.fs.exists("file") === true; -generator.fs.commit(() => {}); -generator.fs.commit([], () => {}); +const usage: string = generator.usage();