├── .gitignore ├── .gitmodules ├── .npmignore ├── .travis.yml ├── LICENSE ├── Makefile ├── README.md ├── index.js ├── lib ├── lib.core.d.ts ├── lib.core.es6.d.ts ├── lib.d.ts ├── lib.dom.d.ts ├── lib.es6.d.ts ├── lib.scriptHost.d.ts └── lib.webworker.d.ts ├── package.json ├── src ├── compositeCompilerHost.ts ├── index.ts └── types.ts ├── test ├── args │ ├── commonjs.txt │ └── with-files.txt ├── cases │ ├── 2dArrays.js │ ├── 2dArrays.ts │ ├── constructorOverloads.errors │ ├── constructorOverloads.js │ ├── constructorOverloads.js.expected │ ├── constructorOverloads.ts │ ├── fleet.error.ts │ ├── fleet.ts │ ├── navy.error.js │ ├── navy.errors │ ├── navy.js │ ├── ship.error.ts │ └── ship.ts ├── compiler.ts └── compositeCompilerHost.ts ├── tsd.json └── typings ├── chai └── chai.d.ts ├── mocha └── mocha.d.ts ├── node └── node.d.ts └── tsd.d.ts /.gitignore: -------------------------------------------------------------------------------- 1 | lib-cov 2 | *.seed 3 | *.log 4 | *.csv 5 | *.dat 6 | *.out 7 | *.pid 8 | *.gz 9 | pids 10 | logs 11 | results 12 | npm-debug.log 13 | node_modules 14 | .DS_Store 15 | test/*.js 16 | test/tmp/* 17 | source/*.js 18 | source/**/*.js 19 | source/**/**/*.js 20 | source/**/**/**/*.js 21 | source/**/**/**/**/*.js 22 | tmp -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "src/typescript"] 2 | path = src/typescript 3 | url = https://github.com/Microsoft/TypeScript.git 4 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | src/ 2 | test/ 3 | typings/ 4 | 5 | tsd.json 6 | build.sh 7 | run-tests.sh 8 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | 3 | node_js: 4 | - "0.10" 5 | - "0.11" 6 | 7 | before_script: 8 | - make build 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 The Blacksmith (a.k.a Saulo Vallory) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | build: 2 | @echo " Building..." 3 | @cp src/typescript/bin/lib.* lib/ 4 | @node ./src/typescript/bin/tsc.js -m commonjs -t ES5 src/index.ts --out index.js 5 | @echo " Done!" 6 | 7 | .PHONY: build 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | typescript-compiler 2 | =================== 3 | 4 | Typescript compiler wrapper. Exposes the TypeScript command line compiler to your code. 5 | 6 | [![Build Status](https://travis-ci.org/theblacksmith/typescript-compiler.svg?branch=master)](https://travis-ci.org/theblacksmith/typescript-compiler) [![Flattr this git repo](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=theblacksmith&url=https%3A%2F%2Fgithub.com%2Ftheblacksmith%2Ftypescript-compiler) 7 | 8 | Installing 9 | ----------------------- 10 | 11 | $ npm install typescript-compiler 12 | 13 | Usage 14 | ----------------------- 15 | 16 | Require the compiler... 17 | 18 | ```javascript 19 | var tsc = require('typescript-compiler'); 20 | ``` 21 | 22 | call it like this... 23 | 24 | ```javascript 25 | tsc.compile(['a.ts', 'b.ts'], ['--out', 'out.js']) 26 | ``` 27 | 28 | or this.. 29 | 30 | ```javascript 31 | var js = tsc.compileString('class TSC { awesome: boolean = true; }') 32 | ``` 33 | 34 | or even this! 35 | 36 | ```javascript 37 | var result = tsc.compileStrings({ 38 | 'ship.ts' : 'module Navy { export class Ship { isSunk: boolean; } }', 39 | 'fleet.ts': '///\n' + 40 | 'module Navy { \n' + 41 | 'export class Fleet { ships: Ship[] } '+ 42 | '}' 43 | }) 44 | ``` 45 | 46 | _Did you notice you can use **///<reference />** tags?_ 47 | 48 | ## Module Interface 49 | 50 | **Note:** A `?` indicates an optional parameter 51 | 52 | ### Common Parameters 53 | 54 | All Methods accept the following parameters: 55 | 56 | > **tscArgs?** : `string[]`|`string`,
57 | >         The same [arguments you can pass to tsc](#tsc-arguments) when you run it from the command line
58 | > **options?** : [`CompilerOptions`],
59 | >         Options to be passed to the compiler
60 | > **onError?** : _fn_ ( [`Diagnostic`] )
61 | >         A function you want called for each error the compiler encounters. 62 | 63 | ### Compilation Methods 64 | 65 | #### `compile(files, tscArgs?, options?, onError?)` 66 | 67 | > **input** : `string`|`string[]`
68 | >         The name of the file or an array of file names to compile.
69 | > **returns** [`CompilationResult`] 70 | 71 |         _Compiles one or many files_ 72 | 73 | #####         Example 74 | 75 | > ```javascript 76 | > tsc.compile(['test/cases/ship.ts', 'test/cases/fleet.ts'], 77 | > '-m commonjs -t ES5 --out test/tmp/navy.js'); 78 | > ``` 79 | 80 | #### `compileString(input, tscArgs?, options?, onError?)` 81 | 82 | > **input** : [`Map`]|[`StringSource[]`][`StringSource`]|`string[]`
83 | >         The source to compile or an array of sources. The source(s) can be passed as strings or [`StringSource`] objects.
84 | > **returns** `string` 85 | 86 |         _Compiles a string_ 87 | 88 | #####         Example 89 | 90 | > ```javascript 91 | > tsc.compileString('module Navy { class Ship { isSunk: boolean; } }') 92 | > ``` 93 | 94 | #### `compileStrings(input, tscArgs?, options?, onError?)` 95 | 96 | > **input** : [`Map`]|[`StringSource`]|`string[]`
97 | >     A collection of sources to be compiled.
98 | > **returns** [`CompilationResult`] 99 | 100 |         Compiles one or many strings 101 | 102 | #####         Example 103 | 104 | > ```javascript 105 | > tsc.compileStrings({ 106 | > "ship.ts" : 'module Navy { export class Ship { isSunk: boolean; }}', 107 | > "fleet.ts": '///\n' + 108 | > 'module Navy { export class Fleet { ships: Ship[] }}' 109 | > }, 110 | > // tscArgs 111 | > '--module commonjs -t ES5 --out navy.js', 112 | > // options (DEPRECATED, will be removed in the next version) 113 | > null, 114 | > // onError 115 | > function(e) { console.log(e) } 116 | > ) 117 | > ``` 118 | 119 | 120 | #### TSC arguments 121 | 122 | When in doubt about what you can pass in the `tscArgs` param you can run the compiler from the command line to get some help. Every option you see below is accepted as a value for the `tscArgs` array. 123 | 124 | ``` 125 | $ tsc 126 | Version 1.1.0.1 127 | Syntax: tsc [options] [file ...] 128 | 129 | Examples: tsc hello.ts 130 | tsc --out foo.js foo.ts 131 | tsc @args.txt 132 | 133 | Options: 134 | -d, --declaration Generates corresponding '.d.ts' file. 135 | -h, --help Print this message. 136 | --mapRoot Specifies the location where debugger should locate map files instead of generated locations. 137 | -m, --module Specify module code generation: 'commonjs' or 'amd' 138 | --noImplicitAny Warn on expressions and declarations with an implied 'any' type. 139 | --out Concatenate and emit output to single file. 140 | --outDir Redirect output structure to the directory. 141 | --removeComments Do not emit comments to output. 142 | --sourceMap Generates corresponding '.map' file. 143 | --sourceRoot Specifies the location where debugger should locate TypeScript files instead of source locations. 144 | -t, --target Specify ECMAScript target version: 'ES3' (default), or 'ES5' 145 | -v, --version Print the compiler's version. 146 | -w, --watch Watch input files. 147 | @ Insert command line options and files from a file. 148 | ``` 149 | 150 | [`CompilerOptions`]: https://github.com/theblacksmith/typescript-compiler/wiki/Interfaces#compileroptions 151 | [`Diagnostic`]: https://github.com/theblacksmith/typescript-compiler/wiki/Interfaces#diagnostic 152 | [`CompilationResult`]: https://github.com/theblacksmith/typescript-compiler/wiki/Interfaces#compilationresult 153 | [`StringSource`]: https://github.com/theblacksmith/typescript-compiler/wiki/Interfaces#stringsource-class 154 | [`Map`]: https://github.com/theblacksmith/typescript-compiler/wiki/Interfaces#map 155 | -------------------------------------------------------------------------------- /lib/lib.core.d.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) Microsoft Corporation. All rights reserved. 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | this file except in compliance with the License. You may obtain a copy of the 5 | License at http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 10 | MERCHANTABLITY OR NON-INFRINGEMENT. 11 | 12 | See the Apache Version 2.0 License for specific language governing permissions 13 | and limitations under the License. 14 | ***************************************************************************** */ 15 | 16 | /// 17 | 18 | ///////////////////////////// 19 | /// ECMAScript APIs 20 | ///////////////////////////// 21 | 22 | declare var NaN: number; 23 | declare var Infinity: number; 24 | 25 | /** 26 | * Evaluates JavaScript code and executes it. 27 | * @param x A String value that contains valid JavaScript code. 28 | */ 29 | declare function eval(x: string): any; 30 | 31 | /** 32 | * Converts A string to an integer. 33 | * @param s A string to convert into a number. 34 | * @param radix A value between 2 and 36 that specifies the base of the number in numString. 35 | * If this argument is not supplied, strings with a prefix of '0x' are considered hexadecimal. 36 | * All other strings are considered decimal. 37 | */ 38 | declare function parseInt(s: string, radix?: number): number; 39 | 40 | /** 41 | * Converts a string to a floating-point number. 42 | * @param string A string that contains a floating-point number. 43 | */ 44 | declare function parseFloat(string: string): number; 45 | 46 | /** 47 | * Returns a Boolean value that indicates whether a value is the reserved value NaN (not a number). 48 | * @param number A numeric value. 49 | */ 50 | declare function isNaN(number: number): boolean; 51 | 52 | /** 53 | * Determines whether a supplied number is finite. 54 | * @param number Any numeric value. 55 | */ 56 | declare function isFinite(number: number): boolean; 57 | 58 | /** 59 | * Gets the unencoded version of an encoded Uniform Resource Identifier (URI). 60 | * @param encodedURI A value representing an encoded URI. 61 | */ 62 | declare function decodeURI(encodedURI: string): string; 63 | 64 | /** 65 | * Gets the unencoded version of an encoded component of a Uniform Resource Identifier (URI). 66 | * @param encodedURIComponent A value representing an encoded URI component. 67 | */ 68 | declare function decodeURIComponent(encodedURIComponent: string): string; 69 | 70 | /** 71 | * Encodes a text string as a valid Uniform Resource Identifier (URI) 72 | * @param uri A value representing an encoded URI. 73 | */ 74 | declare function encodeURI(uri: string): string; 75 | 76 | /** 77 | * Encodes a text string as a valid component of a Uniform Resource Identifier (URI). 78 | * @param uriComponent A value representing an encoded URI component. 79 | */ 80 | declare function encodeURIComponent(uriComponent: string): string; 81 | 82 | interface PropertyDescriptor { 83 | configurable?: boolean; 84 | enumerable?: boolean; 85 | value?: any; 86 | writable?: boolean; 87 | get? (): any; 88 | set? (v: any): void; 89 | } 90 | 91 | interface PropertyDescriptorMap { 92 | [s: string]: PropertyDescriptor; 93 | } 94 | 95 | interface Object { 96 | /** The initial value of Object.prototype.constructor is the standard built-in Object constructor. */ 97 | constructor: Function; 98 | 99 | /** Returns a string representation of an object. */ 100 | toString(): string; 101 | 102 | /** Returns a date converted to a string using the current locale. */ 103 | toLocaleString(): string; 104 | 105 | /** Returns the primitive value of the specified object. */ 106 | valueOf(): Object; 107 | 108 | /** 109 | * Determines whether an object has a property with the specified name. 110 | * @param v A property name. 111 | */ 112 | hasOwnProperty(v: string): boolean; 113 | 114 | /** 115 | * Determines whether an object exists in another object's prototype chain. 116 | * @param v Another object whose prototype chain is to be checked. 117 | */ 118 | isPrototypeOf(v: Object): boolean; 119 | 120 | /** 121 | * Determines whether a specified property is enumerable. 122 | * @param v A property name. 123 | */ 124 | propertyIsEnumerable(v: string): boolean; 125 | } 126 | 127 | interface ObjectConstructor { 128 | new (value?: any): Object; 129 | (): any; 130 | (value: any): any; 131 | 132 | /** A reference to the prototype for a class of objects. */ 133 | prototype: Object; 134 | 135 | /** 136 | * Returns the prototype of an object. 137 | * @param o The object that references the prototype. 138 | */ 139 | getPrototypeOf(o: any): any; 140 | 141 | /** 142 | * Gets the own property descriptor of the specified object. 143 | * An own property descriptor is one that is defined directly on the object and is not inherited from the object's prototype. 144 | * @param o Object that contains the property. 145 | * @param p Name of the property. 146 | */ 147 | getOwnPropertyDescriptor(o: any, p: string): PropertyDescriptor; 148 | 149 | /** 150 | * Returns the names of the own properties of an object. The own properties of an object are those that are defined directly 151 | * on that object, and are not inherited from the object's prototype. The properties of an object include both fields (objects) and functions. 152 | * @param o Object that contains the own properties. 153 | */ 154 | getOwnPropertyNames(o: any): string[]; 155 | 156 | /** 157 | * Creates an object that has the specified prototype, and that optionally contains specified properties. 158 | * @param o Object to use as a prototype. May be null 159 | * @param properties JavaScript object that contains one or more property descriptors. 160 | */ 161 | create(o: any, properties?: PropertyDescriptorMap): any; 162 | 163 | /** 164 | * Adds a property to an object, or modifies attributes of an existing property. 165 | * @param o Object on which to add or modify the property. This can be a native JavaScript object (that is, a user-defined object or a built in object) or a DOM object. 166 | * @param p The property name. 167 | * @param attributes Descriptor for the property. It can be for a data property or an accessor property. 168 | */ 169 | defineProperty(o: any, p: string, attributes: PropertyDescriptor): any; 170 | 171 | /** 172 | * Adds one or more properties to an object, and/or modifies attributes of existing properties. 173 | * @param o Object on which to add or modify the properties. This can be a native JavaScript object or a DOM object. 174 | * @param properties JavaScript object that contains one or more descriptor objects. Each descriptor object describes a data property or an accessor property. 175 | */ 176 | defineProperties(o: any, properties: PropertyDescriptorMap): any; 177 | 178 | /** 179 | * Prevents the modification of attributes of existing properties, and prevents the addition of new properties. 180 | * @param o Object on which to lock the attributes. 181 | */ 182 | seal(o: any): any; 183 | 184 | /** 185 | * Prevents the modification of existing property attributes and values, and prevents the addition of new properties. 186 | * @param o Object on which to lock the attributes. 187 | */ 188 | freeze(o: any): any; 189 | 190 | /** 191 | * Prevents the addition of new properties to an object. 192 | * @param o Object to make non-extensible. 193 | */ 194 | preventExtensions(o: any): any; 195 | 196 | /** 197 | * Returns true if existing property attributes cannot be modified in an object and new properties cannot be added to the object. 198 | * @param o Object to test. 199 | */ 200 | isSealed(o: any): boolean; 201 | 202 | /** 203 | * Returns true if existing property attributes and values cannot be modified in an object, and new properties cannot be added to the object. 204 | * @param o Object to test. 205 | */ 206 | isFrozen(o: any): boolean; 207 | 208 | /** 209 | * Returns a value that indicates whether new properties can be added to an object. 210 | * @param o Object to test. 211 | */ 212 | isExtensible(o: any): boolean; 213 | 214 | /** 215 | * Returns the names of the enumerable properties and methods of an object. 216 | * @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object. 217 | */ 218 | keys(o: any): string[]; 219 | } 220 | 221 | /** 222 | * Provides functionality common to all JavaScript objects. 223 | */ 224 | declare var Object: ObjectConstructor; 225 | 226 | /** 227 | * Creates a new function. 228 | */ 229 | interface Function { 230 | /** 231 | * Calls the function, substituting the specified object for the this value of the function, and the specified array for the arguments of the function. 232 | * @param thisArg The object to be used as the this object. 233 | * @param argArray A set of arguments to be passed to the function. 234 | */ 235 | apply(thisArg: any, argArray?: any): any; 236 | 237 | /** 238 | * Calls a method of an object, substituting another object for the current object. 239 | * @param thisArg The object to be used as the current object. 240 | * @param argArray A list of arguments to be passed to the method. 241 | */ 242 | call(thisArg: any, ...argArray: any[]): any; 243 | 244 | /** 245 | * For a given function, creates a bound function that has the same body as the original function. 246 | * The this object of the bound function is associated with the specified object, and has the specified initial parameters. 247 | * @param thisArg An object to which the this keyword can refer inside the new function. 248 | * @param argArray A list of arguments to be passed to the new function. 249 | */ 250 | bind(thisArg: any, ...argArray: any[]): any; 251 | 252 | prototype: any; 253 | length: number; 254 | 255 | // Non-standard extensions 256 | arguments: any; 257 | caller: Function; 258 | } 259 | 260 | interface FunctionConstructor { 261 | /** 262 | * Creates a new function. 263 | * @param args A list of arguments the function accepts. 264 | */ 265 | new (...args: string[]): Function; 266 | (...args: string[]): Function; 267 | prototype: Function; 268 | } 269 | 270 | declare var Function: FunctionConstructor; 271 | 272 | interface IArguments { 273 | [index: number]: any; 274 | length: number; 275 | callee: Function; 276 | } 277 | 278 | interface String { 279 | /** Returns a string representation of a string. */ 280 | toString(): string; 281 | 282 | /** 283 | * Returns the character at the specified index. 284 | * @param pos The zero-based index of the desired character. 285 | */ 286 | charAt(pos: number): string; 287 | 288 | /** 289 | * Returns the Unicode value of the character at the specified location. 290 | * @param index The zero-based index of the desired character. If there is no character at the specified index, NaN is returned. 291 | */ 292 | charCodeAt(index: number): number; 293 | 294 | /** 295 | * Returns a string that contains the concatenation of two or more strings. 296 | * @param strings The strings to append to the end of the string. 297 | */ 298 | concat(...strings: string[]): string; 299 | 300 | /** 301 | * Returns the position of the first occurrence of a substring. 302 | * @param searchString The substring to search for in the string 303 | * @param position The index at which to begin searching the String object. If omitted, search starts at the beginning of the string. 304 | */ 305 | indexOf(searchString: string, position?: number): number; 306 | 307 | /** 308 | * Returns the last occurrence of a substring in the string. 309 | * @param searchString The substring to search for. 310 | * @param position The index at which to begin searching. If omitted, the search begins at the end of the string. 311 | */ 312 | lastIndexOf(searchString: string, position?: number): number; 313 | 314 | /** 315 | * Determines whether two strings are equivalent in the current locale. 316 | * @param that String to compare to target string 317 | */ 318 | localeCompare(that: string): number; 319 | 320 | /** 321 | * Matches a string with a regular expression, and returns an array containing the results of that search. 322 | * @param regexp A variable name or string literal containing the regular expression pattern and flags. 323 | */ 324 | match(regexp: string): RegExpMatchArray; 325 | 326 | /** 327 | * Matches a string with a regular expression, and returns an array containing the results of that search. 328 | * @param regexp A regular expression object that contains the regular expression pattern and applicable flags. 329 | */ 330 | match(regexp: RegExp): RegExpMatchArray; 331 | 332 | /** 333 | * Replaces text in a string, using a regular expression or search string. 334 | * @param searchValue A String object or string literal that represents the regular expression 335 | * @param replaceValue A String object or string literal containing the text to replace for every successful match of rgExp in stringObj. 336 | */ 337 | replace(searchValue: string, replaceValue: string): string; 338 | 339 | /** 340 | * Replaces text in a string, using a regular expression or search string. 341 | * @param searchValue A String object or string literal that represents the regular expression 342 | * @param replaceValue A function that returns the replacement text. 343 | */ 344 | replace(searchValue: string, replaceValue: (substring: string, ...args: any[]) => string): string; 345 | 346 | /** 347 | * Replaces text in a string, using a regular expression or search string. 348 | * @param searchValue A Regular Expression object containing the regular expression pattern and applicable flags 349 | * @param replaceValue A String object or string literal containing the text to replace for every successful match of rgExp in stringObj. 350 | */ 351 | replace(searchValue: RegExp, replaceValue: string): string; 352 | 353 | /** 354 | * Replaces text in a string, using a regular expression or search string. 355 | * @param searchValue A Regular Expression object containing the regular expression pattern and applicable flags 356 | * @param replaceValue A function that returns the replacement text. 357 | */ 358 | replace(searchValue: RegExp, replaceValue: (substring: string, ...args: any[]) => string): string; 359 | 360 | /** 361 | * Finds the first substring match in a regular expression search. 362 | * @param regexp The regular expression pattern and applicable flags. 363 | */ 364 | search(regexp: string): number; 365 | 366 | /** 367 | * Finds the first substring match in a regular expression search. 368 | * @param regexp The regular expression pattern and applicable flags. 369 | */ 370 | search(regexp: RegExp): number; 371 | 372 | /** 373 | * Returns a section of a string. 374 | * @param start The index to the beginning of the specified portion of stringObj. 375 | * @param end The index to the end of the specified portion of stringObj. The substring includes the characters up to, but not including, the character indicated by end. 376 | * If this value is not specified, the substring continues to the end of stringObj. 377 | */ 378 | slice(start?: number, end?: number): string; 379 | 380 | /** 381 | * Split a string into substrings using the specified separator and return them as an array. 382 | * @param separator A string that identifies character or characters to use in separating the string. If omitted, a single-element array containing the entire string is returned. 383 | * @param limit A value used to limit the number of elements returned in the array. 384 | */ 385 | split(separator: string, limit?: number): string[]; 386 | 387 | /** 388 | * Split a string into substrings using the specified separator and return them as an array. 389 | * @param separator A Regular Express that identifies character or characters to use in separating the string. If omitted, a single-element array containing the entire string is returned. 390 | * @param limit A value used to limit the number of elements returned in the array. 391 | */ 392 | split(separator: RegExp, limit?: number): string[]; 393 | 394 | /** 395 | * Returns the substring at the specified location within a String object. 396 | * @param start The zero-based index number indicating the beginning of the substring. 397 | * @param end Zero-based index number indicating the end of the substring. The substring includes the characters up to, but not including, the character indicated by end. 398 | * If end is omitted, the characters from start through the end of the original string are returned. 399 | */ 400 | substring(start: number, end?: number): string; 401 | 402 | /** Converts all the alphabetic characters in a string to lowercase. */ 403 | toLowerCase(): string; 404 | 405 | /** Converts all alphabetic characters to lowercase, taking into account the host environment's current locale. */ 406 | toLocaleLowerCase(): string; 407 | 408 | /** Converts all the alphabetic characters in a string to uppercase. */ 409 | toUpperCase(): string; 410 | 411 | /** Returns a string where all alphabetic characters have been converted to uppercase, taking into account the host environment's current locale. */ 412 | toLocaleUpperCase(): string; 413 | 414 | /** Removes the leading and trailing white space and line terminator characters from a string. */ 415 | trim(): string; 416 | 417 | /** Returns the length of a String object. */ 418 | length: number; 419 | 420 | // IE extensions 421 | /** 422 | * Gets a substring beginning at the specified location and having the specified length. 423 | * @param from The starting position of the desired substring. The index of the first character in the string is zero. 424 | * @param length The number of characters to include in the returned substring. 425 | */ 426 | substr(from: number, length?: number): string; 427 | 428 | [index: number]: string; 429 | } 430 | 431 | interface StringConstructor { 432 | new (value?: any): String; 433 | (value?: any): string; 434 | prototype: String; 435 | fromCharCode(...codes: number[]): string; 436 | } 437 | 438 | /** 439 | * Allows manipulation and formatting of text strings and determination and location of substrings within strings. 440 | */ 441 | declare var String: StringConstructor; 442 | 443 | interface Boolean { 444 | } 445 | 446 | interface BooleanConstructor { 447 | new (value?: any): Boolean; 448 | (value?: any): boolean; 449 | prototype: Boolean; 450 | } 451 | 452 | declare var Boolean: BooleanConstructor; 453 | 454 | interface Number { 455 | /** 456 | * Returns a string representation of an object. 457 | * @param radix Specifies a radix for converting numeric values to strings. This value is only used for numbers. 458 | */ 459 | toString(radix?: number): string; 460 | 461 | /** 462 | * Returns a string representing a number in fixed-point notation. 463 | * @param fractionDigits Number of digits after the decimal point. Must be in the range 0 - 20, inclusive. 464 | */ 465 | toFixed(fractionDigits?: number): string; 466 | 467 | /** 468 | * Returns a string containing a number represented in exponential notation. 469 | * @param fractionDigits Number of digits after the decimal point. Must be in the range 0 - 20, inclusive. 470 | */ 471 | toExponential(fractionDigits?: number): string; 472 | 473 | /** 474 | * Returns a string containing a number represented either in exponential or fixed-point notation with a specified number of digits. 475 | * @param precision Number of significant digits. Must be in the range 1 - 21, inclusive. 476 | */ 477 | toPrecision(precision?: number): string; 478 | } 479 | 480 | interface NumberConstructor { 481 | new (value?: any): Number; 482 | (value?: any): number; 483 | prototype: Number; 484 | 485 | /** The largest number that can be represented in JavaScript. Equal to approximately 1.79E+308. */ 486 | MAX_VALUE: number; 487 | 488 | /** The closest number to zero that can be represented in JavaScript. Equal to approximately 5.00E-324. */ 489 | MIN_VALUE: number; 490 | 491 | /** 492 | * A value that is not a number. 493 | * In equality comparisons, NaN does not equal any value, including itself. To test whether a value is equivalent to NaN, use the isNaN function. 494 | */ 495 | NaN: number; 496 | 497 | /** 498 | * A value that is less than the largest negative number that can be represented in JavaScript. 499 | * JavaScript displays NEGATIVE_INFINITY values as -infinity. 500 | */ 501 | NEGATIVE_INFINITY: number; 502 | 503 | /** 504 | * A value greater than the largest number that can be represented in JavaScript. 505 | * JavaScript displays POSITIVE_INFINITY values as infinity. 506 | */ 507 | POSITIVE_INFINITY: number; 508 | } 509 | 510 | /** An object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers. */ 511 | declare var Number: NumberConstructor; 512 | 513 | interface TemplateStringsArray extends Array { 514 | raw: string[]; 515 | } 516 | 517 | interface Math { 518 | /** The mathematical constant e. This is Euler's number, the base of natural logarithms. */ 519 | E: number; 520 | /** The natural logarithm of 10. */ 521 | LN10: number; 522 | /** The natural logarithm of 2. */ 523 | LN2: number; 524 | /** The base-2 logarithm of e. */ 525 | LOG2E: number; 526 | /** The base-10 logarithm of e. */ 527 | LOG10E: number; 528 | /** Pi. This is the ratio of the circumference of a circle to its diameter. */ 529 | PI: number; 530 | /** The square root of 0.5, or, equivalently, one divided by the square root of 2. */ 531 | SQRT1_2: number; 532 | /** The square root of 2. */ 533 | SQRT2: number; 534 | /** 535 | * Returns the absolute value of a number (the value without regard to whether it is positive or negative). 536 | * For example, the absolute value of -5 is the same as the absolute value of 5. 537 | * @param x A numeric expression for which the absolute value is needed. 538 | */ 539 | abs(x: number): number; 540 | /** 541 | * Returns the arc cosine (or inverse cosine) of a number. 542 | * @param x A numeric expression. 543 | */ 544 | acos(x: number): number; 545 | /** 546 | * Returns the arcsine of a number. 547 | * @param x A numeric expression. 548 | */ 549 | asin(x: number): number; 550 | /** 551 | * Returns the arctangent of a number. 552 | * @param x A numeric expression for which the arctangent is needed. 553 | */ 554 | atan(x: number): number; 555 | /** 556 | * Returns the angle (in radians) from the X axis to a point (y,x). 557 | * @param y A numeric expression representing the cartesian y-coordinate. 558 | * @param x A numeric expression representing the cartesian x-coordinate. 559 | */ 560 | atan2(y: number, x: number): number; 561 | /** 562 | * Returns the smallest number greater than or equal to its numeric argument. 563 | * @param x A numeric expression. 564 | */ 565 | ceil(x: number): number; 566 | /** 567 | * Returns the cosine of a number. 568 | * @param x A numeric expression that contains an angle measured in radians. 569 | */ 570 | cos(x: number): number; 571 | /** 572 | * Returns e (the base of natural logarithms) raised to a power. 573 | * @param x A numeric expression representing the power of e. 574 | */ 575 | exp(x: number): number; 576 | /** 577 | * Returns the greatest number less than or equal to its numeric argument. 578 | * @param x A numeric expression. 579 | */ 580 | floor(x: number): number; 581 | /** 582 | * Returns the natural logarithm (base e) of a number. 583 | * @param x A numeric expression. 584 | */ 585 | log(x: number): number; 586 | /** 587 | * Returns the larger of a set of supplied numeric expressions. 588 | * @param values Numeric expressions to be evaluated. 589 | */ 590 | max(...values: number[]): number; 591 | /** 592 | * Returns the smaller of a set of supplied numeric expressions. 593 | * @param values Numeric expressions to be evaluated. 594 | */ 595 | min(...values: number[]): number; 596 | /** 597 | * Returns the value of a base expression taken to a specified power. 598 | * @param x The base value of the expression. 599 | * @param y The exponent value of the expression. 600 | */ 601 | pow(x: number, y: number): number; 602 | /** Returns a pseudorandom number between 0 and 1. */ 603 | random(): number; 604 | /** 605 | * Returns a supplied numeric expression rounded to the nearest number. 606 | * @param x The value to be rounded to the nearest number. 607 | */ 608 | round(x: number): number; 609 | /** 610 | * Returns the sine of a number. 611 | * @param x A numeric expression that contains an angle measured in radians. 612 | */ 613 | sin(x: number): number; 614 | /** 615 | * Returns the square root of a number. 616 | * @param x A numeric expression. 617 | */ 618 | sqrt(x: number): number; 619 | /** 620 | * Returns the tangent of a number. 621 | * @param x A numeric expression that contains an angle measured in radians. 622 | */ 623 | tan(x: number): number; 624 | } 625 | /** An intrinsic object that provides basic mathematics functionality and constants. */ 626 | declare var Math: Math; 627 | 628 | /** Enables basic storage and retrieval of dates and times. */ 629 | interface Date { 630 | /** Returns a string representation of a date. The format of the string depends on the locale. */ 631 | toString(): string; 632 | /** Returns a date as a string value. */ 633 | toDateString(): string; 634 | /** Returns a time as a string value. */ 635 | toTimeString(): string; 636 | /** Returns a value as a string value appropriate to the host environment's current locale. */ 637 | toLocaleString(): string; 638 | /** Returns a date as a string value appropriate to the host environment's current locale. */ 639 | toLocaleDateString(): string; 640 | /** Returns a time as a string value appropriate to the host environment's current locale. */ 641 | toLocaleTimeString(): string; 642 | /** Returns the stored time value in milliseconds since midnight, January 1, 1970 UTC. */ 643 | valueOf(): number; 644 | /** Gets the time value in milliseconds. */ 645 | getTime(): number; 646 | /** Gets the year, using local time. */ 647 | getFullYear(): number; 648 | /** Gets the year using Universal Coordinated Time (UTC). */ 649 | getUTCFullYear(): number; 650 | /** Gets the month, using local time. */ 651 | getMonth(): number; 652 | /** Gets the month of a Date object using Universal Coordinated Time (UTC). */ 653 | getUTCMonth(): number; 654 | /** Gets the day-of-the-month, using local time. */ 655 | getDate(): number; 656 | /** Gets the day-of-the-month, using Universal Coordinated Time (UTC). */ 657 | getUTCDate(): number; 658 | /** Gets the day of the week, using local time. */ 659 | getDay(): number; 660 | /** Gets the day of the week using Universal Coordinated Time (UTC). */ 661 | getUTCDay(): number; 662 | /** Gets the hours in a date, using local time. */ 663 | getHours(): number; 664 | /** Gets the hours value in a Date object using Universal Coordinated Time (UTC). */ 665 | getUTCHours(): number; 666 | /** Gets the minutes of a Date object, using local time. */ 667 | getMinutes(): number; 668 | /** Gets the minutes of a Date object using Universal Coordinated Time (UTC). */ 669 | getUTCMinutes(): number; 670 | /** Gets the seconds of a Date object, using local time. */ 671 | getSeconds(): number; 672 | /** Gets the seconds of a Date object using Universal Coordinated Time (UTC). */ 673 | getUTCSeconds(): number; 674 | /** Gets the milliseconds of a Date, using local time. */ 675 | getMilliseconds(): number; 676 | /** Gets the milliseconds of a Date object using Universal Coordinated Time (UTC). */ 677 | getUTCMilliseconds(): number; 678 | /** Gets the difference in minutes between the time on the local computer and Universal Coordinated Time (UTC). */ 679 | getTimezoneOffset(): number; 680 | /** 681 | * Sets the date and time value in the Date object. 682 | * @param time A numeric value representing the number of elapsed milliseconds since midnight, January 1, 1970 GMT. 683 | */ 684 | setTime(time: number): number; 685 | /** 686 | * Sets the milliseconds value in the Date object using local time. 687 | * @param ms A numeric value equal to the millisecond value. 688 | */ 689 | setMilliseconds(ms: number): number; 690 | /** 691 | * Sets the milliseconds value in the Date object using Universal Coordinated Time (UTC). 692 | * @param ms A numeric value equal to the millisecond value. 693 | */ 694 | setUTCMilliseconds(ms: number): number; 695 | 696 | /** 697 | * Sets the seconds value in the Date object using local time. 698 | * @param sec A numeric value equal to the seconds value. 699 | * @param ms A numeric value equal to the milliseconds value. 700 | */ 701 | setSeconds(sec: number, ms?: number): number; 702 | /** 703 | * Sets the seconds value in the Date object using Universal Coordinated Time (UTC). 704 | * @param sec A numeric value equal to the seconds value. 705 | * @param ms A numeric value equal to the milliseconds value. 706 | */ 707 | setUTCSeconds(sec: number, ms?: number): number; 708 | /** 709 | * Sets the minutes value in the Date object using local time. 710 | * @param min A numeric value equal to the minutes value. 711 | * @param sec A numeric value equal to the seconds value. 712 | * @param ms A numeric value equal to the milliseconds value. 713 | */ 714 | setMinutes(min: number, sec?: number, ms?: number): number; 715 | /** 716 | * Sets the minutes value in the Date object using Universal Coordinated Time (UTC). 717 | * @param min A numeric value equal to the minutes value. 718 | * @param sec A numeric value equal to the seconds value. 719 | * @param ms A numeric value equal to the milliseconds value. 720 | */ 721 | setUTCMinutes(min: number, sec?: number, ms?: number): number; 722 | /** 723 | * Sets the hour value in the Date object using local time. 724 | * @param hours A numeric value equal to the hours value. 725 | * @param min A numeric value equal to the minutes value. 726 | * @param sec A numeric value equal to the seconds value. 727 | * @param ms A numeric value equal to the milliseconds value. 728 | */ 729 | setHours(hours: number, min?: number, sec?: number, ms?: number): number; 730 | /** 731 | * Sets the hours value in the Date object using Universal Coordinated Time (UTC). 732 | * @param hours A numeric value equal to the hours value. 733 | * @param min A numeric value equal to the minutes value. 734 | * @param sec A numeric value equal to the seconds value. 735 | * @param ms A numeric value equal to the milliseconds value. 736 | */ 737 | setUTCHours(hours: number, min?: number, sec?: number, ms?: number): number; 738 | /** 739 | * Sets the numeric day-of-the-month value of the Date object using local time. 740 | * @param date A numeric value equal to the day of the month. 741 | */ 742 | setDate(date: number): number; 743 | /** 744 | * Sets the numeric day of the month in the Date object using Universal Coordinated Time (UTC). 745 | * @param date A numeric value equal to the day of the month. 746 | */ 747 | setUTCDate(date: number): number; 748 | /** 749 | * Sets the month value in the Date object using local time. 750 | * @param month A numeric value equal to the month. The value for January is 0, and other month values follow consecutively. 751 | * @param date A numeric value representing the day of the month. If this value is not supplied, the value from a call to the getDate method is used. 752 | */ 753 | setMonth(month: number, date?: number): number; 754 | /** 755 | * Sets the month value in the Date object using Universal Coordinated Time (UTC). 756 | * @param month A numeric value equal to the month. The value for January is 0, and other month values follow consecutively. 757 | * @param date A numeric value representing the day of the month. If it is not supplied, the value from a call to the getUTCDate method is used. 758 | */ 759 | setUTCMonth(month: number, date?: number): number; 760 | /** 761 | * Sets the year of the Date object using local time. 762 | * @param year A numeric value for the year. 763 | * @param month A zero-based numeric value for the month (0 for January, 11 for December). Must be specified if numDate is specified. 764 | * @param date A numeric value equal for the day of the month. 765 | */ 766 | setFullYear(year: number, month?: number, date?: number): number; 767 | /** 768 | * Sets the year value in the Date object using Universal Coordinated Time (UTC). 769 | * @param year A numeric value equal to the year. 770 | * @param month A numeric value equal to the month. The value for January is 0, and other month values follow consecutively. Must be supplied if numDate is supplied. 771 | * @param date A numeric value equal to the day of the month. 772 | */ 773 | setUTCFullYear(year: number, month?: number, date?: number): number; 774 | /** Returns a date converted to a string using Universal Coordinated Time (UTC). */ 775 | toUTCString(): string; 776 | /** Returns a date as a string value in ISO format. */ 777 | toISOString(): string; 778 | /** Used by the JSON.stringify method to enable the transformation of an object's data for JavaScript Object Notation (JSON) serialization. */ 779 | toJSON(key?: any): string; 780 | } 781 | 782 | interface DateConstructor { 783 | new (): Date; 784 | new (value: number): Date; 785 | new (value: string): Date; 786 | new (year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): Date; 787 | (): string; 788 | prototype: Date; 789 | /** 790 | * Parses a string containing a date, and returns the number of milliseconds between that date and midnight, January 1, 1970. 791 | * @param s A date string 792 | */ 793 | parse(s: string): number; 794 | /** 795 | * Returns the number of milliseconds between midnight, January 1, 1970 Universal Coordinated Time (UTC) (or GMT) and the specified date. 796 | * @param year The full year designation is required for cross-century date accuracy. If year is between 0 and 99 is used, then year is assumed to be 1900 + year. 797 | * @param month The month as an number between 0 and 11 (January to December). 798 | * @param date The date as an number between 1 and 31. 799 | * @param hours Must be supplied if minutes is supplied. An number from 0 to 23 (midnight to 11pm) that specifies the hour. 800 | * @param minutes Must be supplied if seconds is supplied. An number from 0 to 59 that specifies the minutes. 801 | * @param seconds Must be supplied if milliseconds is supplied. An number from 0 to 59 that specifies the seconds. 802 | * @param ms An number from 0 to 999 that specifies the milliseconds. 803 | */ 804 | UTC(year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): number; 805 | now(): number; 806 | } 807 | 808 | declare var Date: DateConstructor; 809 | 810 | interface RegExpMatchArray extends Array { 811 | index?: number; 812 | input?: string; 813 | } 814 | 815 | interface RegExpExecArray extends Array { 816 | index: number; 817 | input: string; 818 | } 819 | 820 | interface RegExp { 821 | /** 822 | * Executes a search on a string using a regular expression pattern, and returns an array containing the results of that search. 823 | * @param string The String object or string literal on which to perform the search. 824 | */ 825 | exec(string: string): RegExpExecArray; 826 | 827 | /** 828 | * Returns a Boolean value that indicates whether or not a pattern exists in a searched string. 829 | * @param string String on which to perform the search. 830 | */ 831 | test(string: string): boolean; 832 | 833 | /** Returns a copy of the text of the regular expression pattern. Read-only. The rgExp argument is a Regular expression object. It can be a variable name or a literal. */ 834 | source: string; 835 | 836 | /** Returns a Boolean value indicating the state of the global flag (g) used with a regular expression. Default is false. Read-only. */ 837 | global: boolean; 838 | 839 | /** Returns a Boolean value indicating the state of the ignoreCase flag (i) used with a regular expression. Default is false. Read-only. */ 840 | ignoreCase: boolean; 841 | 842 | /** Returns a Boolean value indicating the state of the multiline flag (m) used with a regular expression. Default is false. Read-only. */ 843 | multiline: boolean; 844 | 845 | lastIndex: number; 846 | 847 | // Non-standard extensions 848 | compile(): RegExp; 849 | } 850 | 851 | interface RegExpConstructor { 852 | new (pattern: string, flags?: string): RegExp; 853 | (pattern: string, flags?: string): RegExp; 854 | prototype: RegExp; 855 | 856 | // Non-standard extensions 857 | $1: string; 858 | $2: string; 859 | $3: string; 860 | $4: string; 861 | $5: string; 862 | $6: string; 863 | $7: string; 864 | $8: string; 865 | $9: string; 866 | lastMatch: string; 867 | } 868 | 869 | declare var RegExp: RegExpConstructor; 870 | 871 | interface Error { 872 | name: string; 873 | message: string; 874 | } 875 | 876 | interface ErrorConstructor { 877 | new (message?: string): Error; 878 | (message?: string): Error; 879 | prototype: Error; 880 | } 881 | 882 | declare var Error: ErrorConstructor; 883 | 884 | interface EvalError extends Error { 885 | } 886 | 887 | interface EvalErrorConstructor { 888 | new (message?: string): EvalError; 889 | (message?: string): EvalError; 890 | prototype: EvalError; 891 | } 892 | 893 | declare var EvalError: EvalErrorConstructor; 894 | 895 | interface RangeError extends Error { 896 | } 897 | 898 | interface RangeErrorConstructor { 899 | new (message?: string): RangeError; 900 | (message?: string): RangeError; 901 | prototype: RangeError; 902 | } 903 | 904 | declare var RangeError: RangeErrorConstructor; 905 | 906 | interface ReferenceError extends Error { 907 | } 908 | 909 | interface ReferenceErrorConstructor { 910 | new (message?: string): ReferenceError; 911 | (message?: string): ReferenceError; 912 | prototype: ReferenceError; 913 | } 914 | 915 | declare var ReferenceError: ReferenceErrorConstructor; 916 | 917 | interface SyntaxError extends Error { 918 | } 919 | 920 | interface SyntaxErrorConstructor { 921 | new (message?: string): SyntaxError; 922 | (message?: string): SyntaxError; 923 | prototype: SyntaxError; 924 | } 925 | 926 | declare var SyntaxError: SyntaxErrorConstructor; 927 | 928 | interface TypeError extends Error { 929 | } 930 | 931 | interface TypeErrorConstructor { 932 | new (message?: string): TypeError; 933 | (message?: string): TypeError; 934 | prototype: TypeError; 935 | } 936 | 937 | declare var TypeError: TypeErrorConstructor; 938 | 939 | interface URIError extends Error { 940 | } 941 | 942 | interface URIErrorConstructor { 943 | new (message?: string): URIError; 944 | (message?: string): URIError; 945 | prototype: URIError; 946 | } 947 | 948 | declare var URIError: URIErrorConstructor; 949 | 950 | interface JSON { 951 | /** 952 | * Converts a JavaScript Object Notation (JSON) string into an object. 953 | * @param text A valid JSON string. 954 | * @param reviver A function that transforms the results. This function is called for each member of the object. 955 | * If a member contains nested objects, the nested objects are transformed before the parent object is. 956 | */ 957 | parse(text: string, reviver?: (key: any, value: any) => any): any; 958 | /** 959 | * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. 960 | * @param value A JavaScript value, usually an object or array, to be converted. 961 | */ 962 | stringify(value: any): string; 963 | /** 964 | * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. 965 | * @param value A JavaScript value, usually an object or array, to be converted. 966 | * @param replacer A function that transforms the results. 967 | */ 968 | stringify(value: any, replacer: (key: string, value: any) => any): string; 969 | /** 970 | * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. 971 | * @param value A JavaScript value, usually an object or array, to be converted. 972 | * @param replacer Array that transforms the results. 973 | */ 974 | stringify(value: any, replacer: any[]): string; 975 | /** 976 | * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. 977 | * @param value A JavaScript value, usually an object or array, to be converted. 978 | * @param replacer A function that transforms the results. 979 | * @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read. 980 | */ 981 | stringify(value: any, replacer: (key: string, value: any) => any, space: any): string; 982 | /** 983 | * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. 984 | * @param value A JavaScript value, usually an object or array, to be converted. 985 | * @param replacer Array that transforms the results. 986 | * @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read. 987 | */ 988 | stringify(value: any, replacer: any[], space: any): string; 989 | } 990 | /** 991 | * An intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format. 992 | */ 993 | declare var JSON: JSON; 994 | 995 | 996 | ///////////////////////////// 997 | /// ECMAScript Array API (specially handled by compiler) 998 | ///////////////////////////// 999 | 1000 | interface Array { 1001 | /** 1002 | * Gets or sets the length of the array. This is a number one higher than the highest element defined in an array. 1003 | */ 1004 | length: number; 1005 | /** 1006 | * Returns a string representation of an array. 1007 | */ 1008 | toString(): string; 1009 | toLocaleString(): string; 1010 | /** 1011 | * Appends new elements to an array, and returns the new length of the array. 1012 | * @param items New elements of the Array. 1013 | */ 1014 | push(...items: T[]): number; 1015 | /** 1016 | * Removes the last element from an array and returns it. 1017 | */ 1018 | pop(): T; 1019 | /** 1020 | * Combines two or more arrays. 1021 | * @param items Additional items to add to the end of array1. 1022 | */ 1023 | concat(...items: U[]): T[]; 1024 | /** 1025 | * Combines two or more arrays. 1026 | * @param items Additional items to add to the end of array1. 1027 | */ 1028 | concat(...items: T[]): T[]; 1029 | /** 1030 | * Adds all the elements of an array separated by the specified separator string. 1031 | * @param separator A string used to separate one element of an array from the next in the resulting String. If omitted, the array elements are separated with a comma. 1032 | */ 1033 | join(separator?: string): string; 1034 | /** 1035 | * Reverses the elements in an Array. 1036 | */ 1037 | reverse(): T[]; 1038 | /** 1039 | * Removes the first element from an array and returns it. 1040 | */ 1041 | shift(): T; 1042 | /** 1043 | * Returns a section of an array. 1044 | * @param start The beginning of the specified portion of the array. 1045 | * @param end The end of the specified portion of the array. 1046 | */ 1047 | slice(start?: number, end?: number): T[]; 1048 | 1049 | /** 1050 | * Sorts an array. 1051 | * @param compareFn The name of the function used to determine the order of the elements. If omitted, the elements are sorted in ascending, ASCII character order. 1052 | */ 1053 | sort(compareFn?: (a: T, b: T) => number): T[]; 1054 | 1055 | /** 1056 | * Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements. 1057 | * @param start The zero-based location in the array from which to start removing elements. 1058 | */ 1059 | splice(start: number): T[]; 1060 | 1061 | /** 1062 | * Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements. 1063 | * @param start The zero-based location in the array from which to start removing elements. 1064 | * @param deleteCount The number of elements to remove. 1065 | * @param items Elements to insert into the array in place of the deleted elements. 1066 | */ 1067 | splice(start: number, deleteCount: number, ...items: T[]): T[]; 1068 | 1069 | /** 1070 | * Inserts new elements at the start of an array. 1071 | * @param items Elements to insert at the start of the Array. 1072 | */ 1073 | unshift(...items: T[]): number; 1074 | 1075 | /** 1076 | * Returns the index of the first occurrence of a value in an array. 1077 | * @param searchElement The value to locate in the array. 1078 | * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0. 1079 | */ 1080 | indexOf(searchElement: T, fromIndex?: number): number; 1081 | 1082 | /** 1083 | * Returns the index of the last occurrence of a specified value in an array. 1084 | * @param searchElement The value to locate in the array. 1085 | * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at the last index in the array. 1086 | */ 1087 | lastIndexOf(searchElement: T, fromIndex?: number): number; 1088 | 1089 | /** 1090 | * Determines whether all the members of an array satisfy the specified test. 1091 | * @param callbackfn A function that accepts up to three arguments. The every method calls the callbackfn function for each element in array1 until the callbackfn returns false, or until the end of the array. 1092 | * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. 1093 | */ 1094 | every(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any): boolean; 1095 | 1096 | /** 1097 | * Determines whether the specified callback function returns true for any element of an array. 1098 | * @param callbackfn A function that accepts up to three arguments. The some method calls the callbackfn function for each element in array1 until the callbackfn returns true, or until the end of the array. 1099 | * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. 1100 | */ 1101 | some(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any): boolean; 1102 | 1103 | /** 1104 | * Performs the specified action for each element in an array. 1105 | * @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array. 1106 | * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. 1107 | */ 1108 | forEach(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any): void; 1109 | 1110 | /** 1111 | * Calls a defined callback function on each element of an array, and returns an array that contains the results. 1112 | * @param callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array. 1113 | * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. 1114 | */ 1115 | map(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): U[]; 1116 | 1117 | /** 1118 | * Returns the elements of an array that meet the condition specified in a callback function. 1119 | * @param callbackfn A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array. 1120 | * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. 1121 | */ 1122 | filter(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any): T[]; 1123 | 1124 | /** 1125 | * Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. 1126 | * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array. 1127 | * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. 1128 | */ 1129 | reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T; 1130 | /** 1131 | * Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. 1132 | * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array. 1133 | * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. 1134 | */ 1135 | reduce(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; 1136 | 1137 | /** 1138 | * Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. 1139 | * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array. 1140 | * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. 1141 | */ 1142 | reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T; 1143 | /** 1144 | * Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. 1145 | * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array. 1146 | * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. 1147 | */ 1148 | reduceRight(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; 1149 | 1150 | [n: number]: T; 1151 | } 1152 | 1153 | interface ArrayConstructor { 1154 | new (arrayLength?: number): any[]; 1155 | new (arrayLength: number): T[]; 1156 | new (...items: T[]): T[]; 1157 | (arrayLength?: number): any[]; 1158 | (arrayLength: number): T[]; 1159 | (...items: T[]): T[]; 1160 | isArray(arg: any): boolean; 1161 | prototype: Array; 1162 | } 1163 | 1164 | declare var Array: ArrayConstructor; 1165 | -------------------------------------------------------------------------------- /lib/lib.scriptHost.d.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) Microsoft Corporation. All rights reserved. 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | this file except in compliance with the License. You may obtain a copy of the 5 | License at http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 10 | MERCHANTABLITY OR NON-INFRINGEMENT. 11 | 12 | See the Apache Version 2.0 License for specific language governing permissions 13 | and limitations under the License. 14 | ***************************************************************************** */ 15 | 16 | /// 17 | 18 | 19 | ///////////////////////////// 20 | /// Windows Script Host APIS 21 | ///////////////////////////// 22 | 23 | declare var ActiveXObject: { new (s: string): any; }; 24 | 25 | interface ITextWriter { 26 | Write(s: string): void; 27 | WriteLine(s: string): void; 28 | Close(): void; 29 | } 30 | 31 | declare var WScript: { 32 | Echo(s: any): void; 33 | StdErr: ITextWriter; 34 | StdOut: ITextWriter; 35 | Arguments: { length: number; Item(n: number): string; }; 36 | ScriptFullName: string; 37 | Quit(exitCode?: number): number; 38 | } 39 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "typescript-compiler", 3 | "version": "1.4.1-2", 4 | "description": "Typescript compiler wrapper", 5 | "main": "index.js", 6 | "scripts": { 7 | "build": "make build", 8 | "test": "make build && mocha --compilers ts:typescript-require" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/theblacksmith/typescript-compiler.git" 13 | }, 14 | "keywords": [ 15 | "TypeScript", 16 | "compiler", 17 | "language", 18 | "javascript", 19 | "api" 20 | ], 21 | "author": "The Blacksmith (a.k.a. Saulo Vallory)", 22 | "license": "MIT", 23 | "bugs": { 24 | "url": "https://github.com/theblacksmith/typescript-compiler/issues" 25 | }, 26 | "homepage": "https://github.com/theblacksmith/typescript-compiler", 27 | "readmeFilename": "README.md", 28 | "devDependencies": { 29 | "chai": "^1.10.0", 30 | "mocha": "^2.0.1", 31 | "typescript-require": ">=0.2.7" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/compositeCompilerHost.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | /// 5 | /// 6 | /// 7 | /// 8 | /// 9 | /// 10 | /// 11 | 12 | var path = require('path'); 13 | var fs = require('fs') 14 | 15 | module tsc { 16 | 17 | function shallowClone(obj) { 18 | var clone: ts.Map = {}; 19 | for (var k in obj) if (obj.hasOwnProperty(k)) { 20 | clone[k] = obj[k]; 21 | } 22 | return clone; 23 | } 24 | 25 | export class CompositeCompilerHost implements ts.CompilerHost { 26 | 27 | private _currentDirectory: string; 28 | private _writer: IResultWriterFn; 29 | private _sources: ts.Map = {}; 30 | private _outputs: ts.Map = {}; 31 | public options: CompilerOptions; 32 | 33 | /** 34 | * Whether to search for files if a string source isn't found or not 35 | */ 36 | fallbackToFiles: boolean = false; 37 | 38 | get sources(): ts.Map { 39 | return shallowClone(this._sources); 40 | } 41 | 42 | get outputs(): ts.Map { 43 | return shallowClone(this._outputs); 44 | } 45 | 46 | readsFrom: SourceType = SourceType.File; 47 | writesTo: SourceType = SourceType.File; 48 | 49 | constructor(options : CompilerOptions) { 50 | this.readsFrom = SourceType.File; 51 | this.getSourceFile = this._readFromFile; 52 | 53 | this.writesTo = SourceType.File; 54 | this.writeFile = this._writeToFile; 55 | 56 | this.options = options || {}; 57 | this.options.defaultLibFilename = this.options.defaultLibFilename || ''; 58 | } 59 | 60 | // Implementing CompilerHost interface 61 | getSourceFile: ISourceReaderFn; 62 | 63 | // Implementing CompilerHost interface 64 | writeFile: IResultWriterFn; 65 | 66 | // Implementing CompilerHost interface 67 | getNewLine = (): string => ts.sys.newLine; 68 | 69 | // Implementing CompilerHost interface 70 | useCaseSensitiveFileNames(): boolean { 71 | return ts.sys.useCaseSensitiveFileNames; 72 | } 73 | 74 | // Implementing CompilerHost interface 75 | getCurrentDirectory(): string { 76 | if(this.getSourceFile === this._readFromStrings) 77 | return ''; 78 | 79 | return this._currentDirectory || (this._currentDirectory = ts.sys.getCurrentDirectory()); 80 | } 81 | 82 | // Implementing CompilerHost interface 83 | getDefaultLibFilename(): string { 84 | return this.options.defaultLibFilename || path.join(__dirname, "lib", "lib.d.ts"); 85 | } 86 | 87 | // Implementing CompilerHost interface 88 | getCanonicalFileName(fileName: string): string { 89 | // if underlying system can distinguish between two files whose names differs only in cases then file name already in canonical form. 90 | // otherwise use toLowerCase as a canonical form. 91 | return ts.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase(); 92 | } 93 | 94 | readFromStrings(fallbackToFiles: boolean = false): CompositeCompilerHost { 95 | this.fallbackToFiles = fallbackToFiles; 96 | this.readsFrom = SourceType.String; 97 | this.getSourceFile = this._readFromStrings; 98 | return this; 99 | } 100 | 101 | readFromFiles(): CompositeCompilerHost { 102 | this.readsFrom = SourceType.File; 103 | this.getSourceFile = this._readFromFile; 104 | return this; 105 | } 106 | 107 | addSource(contents: string) 108 | addSource(contents: Source) 109 | addSource(name: string, contents: string) 110 | addSource(nameOrContents, contents?): CompositeCompilerHost { 111 | var source; 112 | 113 | if(typeof contents == 'undefined') 114 | source = new StringSource(nameOrContents); 115 | else 116 | source = new StringSource(contents, nameOrContents); 117 | 118 | this._sources[source.filename] = source.contents; 119 | return this; 120 | } 121 | 122 | getSourcesFilenames(): string[] { 123 | var keys = []; 124 | 125 | for(var k in this.sources) if(this.sources.hasOwnProperty(k)) 126 | keys.push(k); 127 | 128 | return keys; 129 | } 130 | 131 | writeToString(): CompositeCompilerHost { 132 | this.writesTo = SourceType.String; 133 | this.writeFile = this._writeToString; 134 | return this; 135 | } 136 | 137 | writeToFiles(): CompositeCompilerHost { 138 | this.writesTo = SourceType.File; 139 | this.writeFile = this._writeToFile; 140 | return this; 141 | } 142 | 143 | redirectOutput(writer: boolean) 144 | redirectOutput(writer: IResultWriterFn) 145 | redirectOutput(writer): CompositeCompilerHost { 146 | if(typeof writer == 'function') 147 | this._writer = writer; 148 | else 149 | this._writer = null; 150 | 151 | return this; 152 | } 153 | 154 | ////////////////////////////// 155 | // private methods 156 | ////////////////////////////// 157 | 158 | private _readFromStrings(filename: string, languageVersion: ts.ScriptTarget, onError?: (message: string) => void): ts.SourceFile { 159 | 160 | if (path.normalize(filename) === this.getDefaultLibFilename()) 161 | return this._readFromFile(filename, languageVersion, onError); 162 | 163 | if (this._sources[filename]) 164 | return ts.createSourceFile(filename, this._sources[filename], languageVersion, /*version:*/ "0"); 165 | 166 | if(this.fallbackToFiles) 167 | return this._readFromFile(filename, languageVersion, onError); 168 | 169 | return undefined; 170 | } 171 | 172 | private _writeToString(filename: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void) { 173 | 174 | this._outputs[filename] = data; 175 | 176 | if(this._writer) 177 | this._writer(filename, data, writeByteOrderMark, onError); 178 | } 179 | 180 | private _readFromFile(filename: string, languageVersion: ts.ScriptTarget, onError?: (message: string) => void): ts.SourceFile { 181 | try { 182 | var text = ts.sys.readFile(path.normalize(filename)); 183 | } 184 | catch (e) { 185 | if (onError) { 186 | onError(e.message); 187 | } 188 | 189 | text = ""; 190 | } 191 | return text !== undefined ? ts.createSourceFile(filename, text, languageVersion, /*version:*/ "0") : undefined; 192 | } 193 | 194 | private _writeToFile(fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void) { 195 | var existingDirectories: ts.Map = {}; 196 | 197 | function directoryExists(directoryPath: string): boolean { 198 | if (ts.hasProperty(existingDirectories, directoryPath)) { 199 | return true; 200 | } 201 | if (ts.sys.directoryExists(directoryPath)) { 202 | existingDirectories[directoryPath] = true; 203 | return true; 204 | } 205 | return false; 206 | } 207 | 208 | function ensureDirectoriesExist(directoryPath: string) { 209 | if (directoryPath.length > ts.getRootLength(directoryPath) && !directoryExists(directoryPath)) { 210 | var parentDirectory = ts.getDirectoryPath(directoryPath); 211 | ensureDirectoriesExist(parentDirectory); 212 | ts.sys.createDirectory(directoryPath); 213 | } 214 | } 215 | 216 | try { 217 | if(this._writer) { 218 | this._writer(fileName, data, writeByteOrderMark, onError); 219 | } 220 | else { 221 | ensureDirectoriesExist(ts.getDirectoryPath(ts.normalizePath(fileName))); 222 | ts.sys.writeFile(fileName, data, writeByteOrderMark); 223 | } 224 | this._outputs[fileName] = (writeByteOrderMark ? '\uFEFF' : '') + data; 225 | } 226 | catch (e) { 227 | if (onError) onError(e.message); 228 | } 229 | } 230 | } 231 | } 232 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | /// 5 | /// 6 | /// 7 | /// 8 | /// 9 | /// 10 | /// 11 | 12 | /// 13 | 14 | module tsc { 15 | 16 | function formatError(diagnostic: ts.Diagnostic) { 17 | var output = ""; 18 | if (diagnostic.file) { 19 | var loc = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start); 20 | output += diagnostic.file.filename + "(" + loc.line + "," + loc.character + "): "; 21 | } 22 | var category = ts.DiagnosticCategory[diagnostic.category].toLowerCase(); 23 | output += category + " TS" + diagnostic.code + ": " + diagnostic.messageText + ts.sys.newLine; 24 | return output; 25 | } 26 | 27 | function forwardErrors(errors, onError) { 28 | if(typeof onError == 'function') { 29 | errors.forEach(e => { 30 | e.formattedMessage = formatError(e); 31 | onError(e) 32 | }) 33 | } 34 | } 35 | 36 | function _compile(host: CompositeCompilerHost, sources: Source[], tscArgs: string, options?: CompilerOptions, onError?: (message) => void) 37 | function _compile(host: CompositeCompilerHost, sources: Source[], tscArgs: string[], options?: CompilerOptions, onError?: (message) => void) 38 | function _compile(host: CompositeCompilerHost, sources: Source[], tscArgs?, options?: CompilerOptions, onError?: (message) => void) : CompilationResult { 39 | 40 | if(typeof tscArgs == "string") 41 | tscArgs = tscArgs.split(' '); 42 | else 43 | tscArgs = tscArgs || []; 44 | 45 | var commandLine = ts.parseCommandLine(tscArgs); 46 | var files; 47 | 48 | if(host.readsFrom == SourceType.String) { 49 | sources.forEach(s => host.addSource(s.filename, s.contents)); 50 | files = host.getSourcesFilenames(); 51 | } 52 | else { 53 | files = ts.map(sources, s => s.filename).concat(commandLine.filenames); 54 | } 55 | 56 | var program = ts.createProgram(files, commandLine.options, host); 57 | 58 | // Query for early errors 59 | var errors = program.getDiagnostics(); 60 | // todo: make async 61 | forwardErrors(errors, onError); 62 | 63 | // Do not generate code in the presence of early errors 64 | if (!errors.length) { 65 | // Type check and get semanic errors 66 | var checker = program.getTypeChecker(/*fullTypeCheckMode*/ true); 67 | var semanticErrors = checker.getDiagnostics(); 68 | // todo: make async 69 | forwardErrors(semanticErrors, onError); 70 | 71 | // Generate output 72 | var emitResult = checker.emitFiles(); 73 | // todo: make async 74 | forwardErrors(emitResult.diagnostics, onError); 75 | 76 | errors = ts.concatenate(semanticErrors, emitResult.diagnostics); 77 | } 78 | 79 | return { 80 | sources: host.outputs, 81 | sourceMaps: emitResult && emitResult.sourceMaps ? emitResult.sourceMaps : [], 82 | errors: ts.map(errors, e => { 83 | return formatError(e) 84 | }) 85 | }; 86 | } 87 | 88 | export function compileWithHost(host: CompositeCompilerHost, sources: Source[], tscArgs: ts.ParsedCommandLine, options?: CompilerOptions, onError?: (message) => void) 89 | export function compileWithHost(host: CompositeCompilerHost, sources: Source[], tscArgs: string[], options?: CompilerOptions, onError?: (message) => void) 90 | export function compileWithHost(host: CompositeCompilerHost, sources: Source[], tscArgs, options?: CompilerOptions, onError?: (message) => void) { 91 | return _compile(host, sources, tscArgs, options, onError); 92 | } 93 | 94 | export function compile(files: string, tscArgs?: string, options?: CompilerOptions, onError?: (message) => void) 95 | export function compile(files: string, tscArgs?: string[], options?: CompilerOptions, onError?: (message) => void) 96 | export function compile(files: string[], tscArgs?: string, options?: CompilerOptions, onError?: (message) => void) 97 | export function compile(files: string[], tscArgs?: string[], options?: CompilerOptions, onError?: (message) => void) 98 | export function compile(files, tscArgs?, options?, onError?: (message) => void) : CompilationResult { 99 | 100 | if(typeof files == 'string') 101 | files = [files]; 102 | 103 | return _compile(new CompositeCompilerHost(options), 104 | ts.map(files, (f) => new FileSource(f)), 105 | tscArgs, options, onError); 106 | } 107 | 108 | export function compileStrings(input: ts.Map, tscArgs?: string, options?: CompilerOptions, onError?: (message) => void) 109 | export function compileStrings(input: ts.Map, tscArgs?: string[], options?: CompilerOptions, onError?: (message) => void) 110 | export function compileStrings(input: StringSource[], tscArgs?: string, options?: CompilerOptions, onError?: (message) => void) 111 | export function compileStrings(input: StringSource[], tscArgs?: string[], options?: CompilerOptions, onError?: (message) => void) 112 | export function compileStrings(input: string[], tscArgs?: string, options?: CompilerOptions, onError?: (message) => void) 113 | export function compileStrings(input: string[], tscArgs?: string[], options?: CompilerOptions, onError?: (message) => void) 114 | export function compileStrings(input, tscArgs?, options?: CompilerOptions, onError?: (message) => void): CompilationResult { 115 | 116 | var host = new CompositeCompilerHost(options) 117 | .readFromStrings() 118 | .writeToString(); 119 | 120 | var sources = []; 121 | 122 | if(Array.isArray(input) && input.length) { 123 | // string[] 124 | if(typeof input[0] == 'string') { 125 | sources = ts.map(input, s => new StringSource(s)); 126 | } 127 | // Source[] 128 | else if(input[0] instanceof StringSource) { 129 | sources.concat(input); 130 | } 131 | else 132 | throw new Error('Invalid value for input argument') 133 | } 134 | // dictionary 135 | else if(typeof input == 'object') { 136 | for(var k in input) if (input.hasOwnProperty(k)) 137 | sources.push(new StringSource(input[k], k)); 138 | } 139 | else 140 | throw new Error('Invalid value for input argument') 141 | 142 | return _compile(host, sources, tscArgs, options, onError); 143 | } 144 | 145 | export function compileString(input: StringSource, tscArgs?: string, options?: CompilerOptions, onError?: (message) => void) 146 | export function compileString(input: StringSource, tscArgs?: string[], options?: CompilerOptions, onError?: (message) => void) 147 | export function compileString(input: string, tscArgs?: string, options?: CompilerOptions, onError?: (message) => void) 148 | export function compileString(input: string, tscArgs?: string, options?: CompilerOptions, onError?: (message) => void) 149 | export function compileString(input, tscArgs?, options?: CompilerOptions, onError?: (message) => void): string { 150 | if(typeof input != "string" && !(input instanceof StringSource)) 151 | throw new Error("typescript-compiler#compileString: input parameter should be either a string or a StringSource object") 152 | 153 | if(input == '') return ''; 154 | 155 | var result: string = ''; 156 | 157 | var host = new CompositeCompilerHost(options) 158 | .readFromStrings() 159 | .writeToString() 160 | .redirectOutput((filename, data) => result += data); 161 | 162 | _compile(host, [input instanceof StringSource ? input : new StringSource(input, 'string.ts')], tscArgs, options, onError); 163 | 164 | return result; 165 | } 166 | } 167 | 168 | module.exports = tsc; 169 | -------------------------------------------------------------------------------- /src/types.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | module tsc { 5 | 6 | export enum SourceType { File, String } 7 | 8 | export interface Source { 9 | type: SourceType; 10 | filename?: string; 11 | contents?: string; 12 | } 13 | 14 | export class StringSource implements Source { 15 | private static _counter = 0; 16 | 17 | type: SourceType = SourceType.String; 18 | 19 | constructor(public contents: string, public filename: string = StringSource._nextFilename()) { 20 | } 21 | 22 | private static _nextFilename() { 23 | return "input_string" + (++StringSource._counter) + '.ts'; 24 | } 25 | 26 | resetCounter() { 27 | StringSource._counter = 0; 28 | } 29 | } 30 | 31 | export class FileSource implements Source { 32 | type: SourceType = SourceType.File; 33 | 34 | constructor(public filename: string) { 35 | } 36 | } 37 | 38 | export interface CompilationResult { 39 | sources: { [index: string]: string }; 40 | sourceMaps: {}; 41 | errors: string[]; 42 | } 43 | 44 | export interface CompilerOptions { 45 | defaultLibFilename?: string; 46 | } 47 | 48 | export interface ISourceReaderFn { 49 | (filename: string, languageVersion?: ts.ScriptTarget, onError?: (message: string) => void): ts.SourceFile; 50 | } 51 | 52 | export interface IResultWriterFn { 53 | (filename: string, data: string, writeByteOrderMark?: boolean, onError?: (message: string) => void); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /test/args/commonjs.txt: -------------------------------------------------------------------------------- 1 | -t es5 -m commonjs 2 | -------------------------------------------------------------------------------- /test/args/with-files.txt: -------------------------------------------------------------------------------- 1 | test/cases/2dArrays.ts -t es5 -m commonjs --out test/tmp/2dArrays.js 2 | -------------------------------------------------------------------------------- /test/cases/2dArrays.js: -------------------------------------------------------------------------------- 1 | var Cell = (function () { 2 | function Cell() { 3 | } 4 | return Cell; 5 | })(); 6 | var Ship = (function () { 7 | function Ship() { 8 | } 9 | return Ship; 10 | })(); 11 | var Board = (function () { 12 | function Board() { 13 | } 14 | Board.prototype.allShipsSunk = function () { 15 | return this.ships.every(function (val) { 16 | return val.isSunk; 17 | }); 18 | }; 19 | return Board; 20 | })(); 21 | -------------------------------------------------------------------------------- /test/cases/2dArrays.ts: -------------------------------------------------------------------------------- 1 | class Cell { 2 | } 3 | 4 | class Ship { 5 | isSunk: boolean; 6 | } 7 | 8 | class Board { 9 | ships: Ship[]; 10 | cells: Cell[]; 11 | 12 | private allShipsSunk() { 13 | return this.ships.every(function (val) { return val.isSunk; }); 14 | } 15 | } -------------------------------------------------------------------------------- /test/cases/constructorOverloads.errors: -------------------------------------------------------------------------------- 1 | test/cases/constructorOverloads.ts(2,5): error TS2392: Multiple constructor implementations are not allowed. 2 | test/cases/constructorOverloads.ts(3,5): error TS2392: Multiple constructor implementations are not allowed. 3 | -------------------------------------------------------------------------------- /test/cases/constructorOverloads.js: -------------------------------------------------------------------------------- 1 | var C = (function () { 2 | function C(x) { 3 | } 4 | return C; 5 | })(); 6 | var D = (function () { 7 | function D(x) { 8 | } 9 | return D; 10 | })(); 11 | -------------------------------------------------------------------------------- /test/cases/constructorOverloads.js.expected: -------------------------------------------------------------------------------- 1 | var C = (function () { 2 | function C(x) { 3 | } 4 | return C; 5 | })(); 6 | var D = (function () { 7 | function D(x) { 8 | } 9 | return D; 10 | })(); 11 | -------------------------------------------------------------------------------- /test/cases/constructorOverloads.ts: -------------------------------------------------------------------------------- 1 | class C { 2 | constructor(x) { } 3 | constructor(y, x) { } // illegal, 2 constructor implementations 4 | } 5 | 6 | class D { 7 | constructor(x: number); 8 | constructor(y: string); // legal, overload signatures for 1 implementation 9 | constructor(x) { } 10 | } 11 | 12 | interface I { 13 | new (x); 14 | new (x, y); // legal, overload signatures for (presumably) 1 implementation 15 | } -------------------------------------------------------------------------------- /test/cases/fleet.error.ts: -------------------------------------------------------------------------------- 1 | /// 2 | module Nav { export class Fleet { ships: Ship[] } } 3 | -------------------------------------------------------------------------------- /test/cases/fleet.ts: -------------------------------------------------------------------------------- 1 | /// 2 | module Navy { export class Fleet { ships: Ship[] } } 3 | -------------------------------------------------------------------------------- /test/cases/navy.error.js: -------------------------------------------------------------------------------- 1 | var Navy; 2 | (function (Navy) { 3 | var Ship = (function () { 4 | function Ship() { 5 | } 6 | return Ship; 7 | })(); 8 | Navy.Ship = Ship; 9 | })(Navy || (Navy = {})); 10 | /// 11 | var Nav; 12 | (function (Nav) { 13 | var Fleet = (function () { 14 | function Fleet() { 15 | } 16 | return Fleet; 17 | })(); 18 | Nav.Fleet = Fleet; 19 | })(Nav || (Nav = {})); 20 | -------------------------------------------------------------------------------- /test/cases/navy.errors: -------------------------------------------------------------------------------- 1 | test/cases/fleet.error.ts(2,42): error TS2304: Cannot find name 'Ship'. 2 | test/cases/ship.error.ts(1,43): error TS2304: Cannot find name 'booleano'. 3 | -------------------------------------------------------------------------------- /test/cases/navy.js: -------------------------------------------------------------------------------- 1 | var Navy; 2 | (function (Navy) { 3 | var Ship = (function () { 4 | function Ship() { 5 | } 6 | return Ship; 7 | })(); 8 | Navy.Ship = Ship; 9 | })(Navy || (Navy = {})); 10 | /// 11 | var Navy; 12 | (function (Navy) { 13 | var Fleet = (function () { 14 | function Fleet() { 15 | } 16 | return Fleet; 17 | })(); 18 | Navy.Fleet = Fleet; 19 | })(Navy || (Navy = {})); 20 | -------------------------------------------------------------------------------- /test/cases/ship.error.ts: -------------------------------------------------------------------------------- 1 | module Navy { export class Ship { isSunk: booleano; } } 2 | -------------------------------------------------------------------------------- /test/cases/ship.ts: -------------------------------------------------------------------------------- 1 | module Navy { export class Ship { isSunk: boolean; } } 2 | -------------------------------------------------------------------------------- /test/compiler.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | 5 | import chai = require('chai'); 6 | import fs = require('fs'); 7 | 8 | var expect = chai.expect; 9 | var tsc = require('..'); 10 | 11 | describe('typescript-compiler', () => { 12 | 13 | describe('@ argument support', () => { 14 | it('Should parse args from a file', () => { 15 | var error; 16 | var result = tsc.compileString( 17 | 'export class ArgTest { public worked : boolean = true; }', 18 | '@test/args/commonjs.txt', null, (e) => error = e.formattedMessage); 19 | 20 | expect(error).to.be.empty(error); 21 | }); 22 | 23 | it('Should parse files inside an args file', () => { 24 | var error; 25 | var expected = fs.readFileSync('test/cases/2dArrays.js').toString(); 26 | 27 | var result = tsc.compile([], '@test/args/with-files.txt', null, (e) => error = e.formattedMessage); 28 | 29 | expect(error).to.be.empty(error); 30 | expect(result.sources['test/tmp/2dArrays.js'].split(/[\r\n]+/)).to.deep.equal(expected.split(/[\r\n]+/)); 31 | }); 32 | }) 33 | 34 | describe('#compile', () => { 35 | 36 | it('should generate the same output tsc does', () => { 37 | var expected = fs.readFileSync('test/cases/2dArrays.js').toString(); 38 | var result = tsc.compile('test/cases/2dArrays.ts', '--out test/tmp/2dArrays.js'); 39 | 40 | expect(result.sources['test/tmp/2dArrays.js'].split(/[\r\n]+/)).to.deep.equal(expected.split(/[\r\n]+/)); 41 | }) 42 | 43 | it('should be able to compile many files at once', () => { 44 | // tsc -m commonjs -t ES5 test/cases/fleet.error.ts --out test/cases/navy.error.js 45 | var expected_output = fs.readFileSync('test/cases/navy.js').toString(); 46 | 47 | var result = tsc.compile(['test/cases/ship.ts', 'test/cases/fleet.ts'], 48 | '-m commonjs -t ES5 --out test/tmp/navy.js'); 49 | 50 | expect(result.sources['test/tmp/navy.js'].split(/[\r\n]+/)).to.deep.equal(expected_output.split(/[\r\n]+/)) 51 | expect(result.errors.length).to.equal(0) 52 | }) 53 | 54 | it('should return errors exactly like tsc', () => { 55 | var expected_output = fs.readFileSync('test/cases/constructorOverloads.js').toString(); 56 | var expected_errors = fs.readFileSync('test/cases/constructorOverloads.errors').toString().trim().split('\n'); 57 | var result = tsc.compile('test/cases/constructorOverloads.ts'); 58 | 59 | expect(result.sources['test/cases/constructorOverloads.js'].split(/[\r\n]+/)).to.deep.equal(expected_output.split(/[\r\n]+/)) 60 | expect(result.errors.length).to.be.equal(expected_errors.length) 61 | expect(result.errors[0].trim()).to.be.equal(expected_errors[0].trim()) 62 | }) 63 | 64 | it('should forward errors to callback', () => { 65 | var callbackCalled = false; 66 | var result = tsc.compile('test/cases/constructorOverloads.ts', null, null, (e) => { 67 | callbackCalled = true 68 | }); 69 | expect(callbackCalled).to.be.true; 70 | }) 71 | }) 72 | 73 | describe('#compileString', () => { 74 | 75 | it('should generate the same output tsc does', () => { 76 | var source = fs.readFileSync('test/cases/2dArrays.ts').toString(); 77 | var expected = fs.readFileSync('test/cases/2dArrays.js').toString(); 78 | var result = tsc.compileString(source); 79 | 80 | expect(result.split(/[\r\n]+/)).to.deep.equal(expected.split(/[\r\n]+/)); 81 | }) 82 | 83 | it('should return errors exactly like tsc', () => { 84 | var errors = []; 85 | var source = fs.readFileSync('test/cases/constructorOverloads.ts').toString(); 86 | var expected_errors = fs.readFileSync('test/cases/constructorOverloads.errors') 87 | .toString() 88 | .replace(/test\/cases\/constructorOverloads/g, 'string') 89 | .trim().split('\n'); 90 | 91 | var result = tsc.compileString(source, null, null, (e) => { 92 | errors.push(e.formattedMessage.trim()) 93 | }); 94 | 95 | expect(errors).to.deep.equal(expected_errors) 96 | }) 97 | 98 | it('should return an empty result when input is empty', () => { 99 | var result = tsc.compileString(''); 100 | expect(result).to.be.empty; 101 | }) 102 | 103 | it('should forward errors to callback', () => { 104 | var errorMsg = ''; 105 | var result = tsc.compileString('var a : SomeFakeType', null, null, (e) => { 106 | errorMsg = e.messageText 107 | }); 108 | expect(errorMsg).to.equal('Cannot find name \'SomeFakeType\'.'); 109 | }) 110 | }) 111 | 112 | describe('#compileStrings', () => { 113 | 114 | var sources = { 115 | 'ship.ts': 'module Navy { export class Ship { isSunk: boolean; } }', 116 | 'fleet.ts': '///\nmodule Navy { export class Fleet { ships: Ship[] } }' 117 | }; 118 | 119 | var sources_with_errors = { 120 | 'test/cases/ship.error.ts': 'module Navy { export class Ship { isSunk: booleano; } }', 121 | 'test/cases/fleet.error.ts': '///\nmodule Nav { export class Fleet { ships: Ship[] } }' 122 | }; 123 | 124 | it('should generate the same output tsc does', () => { 125 | var result = tsc.compileStrings(sources, '-m commonjs -t ES5 --out navy.js') 126 | // tsc -m commonjs -t ES5 test/cases/fleet.ts --out test/cases/navy.js 127 | var expected_result = fs.readFileSync('test/cases/navy.js').toString(); 128 | 129 | expect(result.sources['navy.js'].split(/[\r\n]+/)).to.deep.equal(expected_result.split(/[\r\n]+/)); 130 | }) 131 | 132 | it('should return errors exactly like tsc', () => { 133 | // tsc -m commonjs -t ES5 test/cases/fleet.error.ts --out test/cases/navy.error.js 134 | var expected_output = fs.readFileSync('test/cases/navy.error.js').toString(); 135 | var expected_errors = fs.readFileSync('test/cases/navy.errors').toString().trim().split('\n'); 136 | var result = tsc.compileStrings(sources_with_errors, '-m commonjs -t ES5 --out navy.js'); 137 | 138 | expect(result.sources['navy.js'].split(/[\r\n]+/)).to.deep.equal(expected_output.split(/[\r\n]+/)) 139 | expect(result.errors.length).to.be.equal(expected_errors.length) 140 | expect(result.errors[0].trim()).to.be.equal(expected_errors[0].trim()) 141 | }) 142 | 143 | it('should allow references between strings', () => { 144 | var out = tsc.compileStrings(sources, '-m commonjs --out all.js'); 145 | }) 146 | 147 | it('should forward errors to callback', () => { 148 | var callbackCount = 0; 149 | var result = tsc.compileStrings(sources_with_errors, null, null, (e) => { 150 | callbackCount++ 151 | }); 152 | expect(callbackCount).to.equal(2); 153 | }) 154 | }) 155 | }) 156 | -------------------------------------------------------------------------------- /test/compositeCompilerHost.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | 5 | import chai = require('chai'); 6 | import fs = require('fs'); 7 | 8 | var expect = chai.expect; 9 | var tsc = require('..'); 10 | 11 | describe('CompositeCompilerHost', () => { 12 | 13 | it('Should accept custom lib.d.ts locations', () => { 14 | var cch = new tsc.CompositeCompilerHost({ defaultLibFilename: 'some/random/lib.d.ts' }); 15 | 16 | expect(cch.getDefaultLibFilename()).to.equal('some/random/lib.d.ts'); 17 | }); 18 | 19 | }); 20 | -------------------------------------------------------------------------------- /tsd.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "v4", 3 | "repo": "borisyankov/DefinitelyTyped", 4 | "ref": "master", 5 | "path": "typings", 6 | "bundle": "typings/tsd.d.ts", 7 | "installed": { 8 | "mocha/mocha.d.ts": { 9 | "commit": "39531c32fe899cada2cc7e615610644fb6508416" 10 | }, 11 | "chai/chai.d.ts": { 12 | "commit": "39531c32fe899cada2cc7e615610644fb6508416" 13 | }, 14 | "node/node.d.ts": { 15 | "commit": "39531c32fe899cada2cc7e615610644fb6508416" 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /typings/chai/chai.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for chai 1.7.2 2 | // Project: http://chaijs.com/ 3 | // Definitions by: Jed Hunsaker , Bart van der Schoor 4 | // Definitions: https://github.com/borisyankov/DefinitelyTyped 5 | 6 | declare module chai { 7 | export class AssertionError { 8 | constructor(message: string, _props?: any, ssf?: Function); 9 | name: string; 10 | message: string; 11 | showDiff: boolean; 12 | stack: string; 13 | } 14 | 15 | function should(); 16 | 17 | function expect(target: any, message?: string): Expect; 18 | 19 | export var assert: Assert; 20 | export var config: Config; 21 | 22 | export interface Config { 23 | includeStack: boolean; 24 | } 25 | 26 | // Provides a way to extend the internals of Chai 27 | function use(fn: (chai: any, utils: any) => void): any; 28 | 29 | interface ExpectStatic { 30 | (target: any): Expect; 31 | } 32 | 33 | interface Assertions { 34 | attr(name: string, value?: string): any; 35 | css(name: string, value?: string): any; 36 | data(name: string, value?: string): any; 37 | class(className: string): any; 38 | id(id: string): any; 39 | html(html: string): any; 40 | text(text: string): any; 41 | value(value: string): any; 42 | visible: any; 43 | hidden: any; 44 | selected: any; 45 | checked: any; 46 | disabled: any; 47 | empty: any; 48 | exist: any; 49 | } 50 | 51 | interface Expect extends LanguageChains, NumericComparison, TypeComparison, Assertions { 52 | not: Expect; 53 | deep: Deep; 54 | a: TypeComparison; 55 | an: TypeComparison; 56 | include: Include; 57 | contain: Include; 58 | ok: Expect; 59 | true: Expect; 60 | false: Expect; 61 | null: Expect; 62 | undefined: Expect; 63 | exist: Expect; 64 | empty: Expect; 65 | arguments: Expect; 66 | Arguments: Expect; 67 | equal: Equal; 68 | equals: Equal; 69 | eq: Equal; 70 | eql: Equal; 71 | eqls: Equal; 72 | property: Property; 73 | ownProperty: OwnProperty; 74 | haveOwnProperty: OwnProperty; 75 | length: Length; 76 | lengthOf: Length; 77 | match(RegularExpression: RegExp, message?: string): Expect; 78 | string(string: string, message?: string): Expect; 79 | keys: Keys; 80 | key(string: string): Expect; 81 | throw: Throw; 82 | throws: Throw; 83 | Throw: Throw; 84 | respondTo(method: string, message?: string): Expect; 85 | itself: Expect; 86 | satisfy(matcher: Function, message?: string): Expect; 87 | closeTo(expected: number, delta: number, message?: string): Expect; 88 | members: Members; 89 | } 90 | 91 | interface LanguageChains { 92 | to: Expect; 93 | be: Expect; 94 | been: Expect; 95 | is: Expect; 96 | that: Expect; 97 | and: Expect; 98 | have: Expect; 99 | has: Expect; 100 | with: Expect; 101 | at: Expect; 102 | of: Expect; 103 | same: Expect; 104 | } 105 | 106 | interface NumericComparison { 107 | above: NumberComparer; 108 | gt: NumberComparer; 109 | greaterThan: NumberComparer; 110 | least: NumberComparer; 111 | gte: NumberComparer; 112 | below: NumberComparer; 113 | lt: NumberComparer; 114 | lessThan: NumberComparer; 115 | most: NumberComparer; 116 | lte: NumberComparer; 117 | within(start: number, finish: number, message?: string): Expect; 118 | } 119 | 120 | interface NumberComparer { 121 | (value: number, message?: string): Expect; 122 | } 123 | 124 | interface TypeComparison { 125 | (type: string, message?: string): Expect; 126 | instanceof: InstanceOf; 127 | instanceOf: InstanceOf; 128 | } 129 | 130 | interface InstanceOf { 131 | (constructor: Object, message?: string): Expect; 132 | } 133 | 134 | interface Deep { 135 | equal: Equal; 136 | property: Property; 137 | } 138 | 139 | interface Equal { 140 | (value: any, message?: string): Expect; 141 | } 142 | 143 | interface Property { 144 | (name: string, value?: any, message?: string): Expect; 145 | } 146 | 147 | interface OwnProperty { 148 | (name: string, message?: string): Expect; 149 | } 150 | 151 | interface Length extends LanguageChains, NumericComparison { 152 | (length: number, message?: string): Expect; 153 | } 154 | 155 | interface Include { 156 | (value: Object, message?: string): Expect; 157 | (value: string, message?: string): Expect; 158 | (value: number, message?: string): Expect; 159 | keys: Keys; 160 | members: Members; 161 | } 162 | 163 | interface Keys { 164 | (...keys: string[]): Expect; 165 | (keys: any[]): Expect; 166 | } 167 | 168 | interface Members { 169 | (set: any[], message?: string): Expect; 170 | } 171 | 172 | interface Throw { 173 | (): Expect; 174 | (expected: string, message?: string): Expect; 175 | (expected: RegExp, message?: string): Expect; 176 | (constructor: Error, expected?: string, message?: string): Expect; 177 | (constructor: Error, expected?: RegExp, message?: string): Expect; 178 | (constructor: Function, expected?: string, message?: string): Expect; 179 | (constructor: Function, expected?: RegExp, message?: string): Expect; 180 | } 181 | 182 | export interface Assert { 183 | (express: any, msg?: string):void; 184 | 185 | fail(actual?: any, expected?: any, msg?: string, operator?: string):void; 186 | 187 | ok(val: any, msg?: string):void; 188 | notOk(val: any, msg?: string):void; 189 | 190 | equal(act: any, exp: any, msg?: string):void; 191 | notEqual(act: any, exp: any, msg?: string):void; 192 | 193 | strictEqual(act: any, exp: any, msg?: string):void; 194 | notStrictEqual(act: any, exp: any, msg?: string):void; 195 | 196 | deepEqual(act: any, exp: any, msg?: string):void; 197 | notDeepEqual(act: any, exp: any, msg?: string):void; 198 | 199 | isTrue(val: any, msg?: string):void; 200 | isFalse(val: any, msg?: string):void; 201 | 202 | isNull(val: any, msg?: string):void; 203 | isNotNull(val: any, msg?: string):void; 204 | 205 | isUndefined(val: any, msg?: string):void; 206 | isDefined(val: any, msg?: string):void; 207 | 208 | isFunction(val: any, msg?: string):void; 209 | isNotFunction(val: any, msg?: string):void; 210 | 211 | isObject(val: any, msg?: string):void; 212 | isNotObject(val: any, msg?: string):void; 213 | 214 | isArray(val: any, msg?: string):void; 215 | isNotArray(val: any, msg?: string):void; 216 | 217 | isString(val: any, msg?: string):void; 218 | isNotString(val: any, msg?: string):void; 219 | 220 | isNumber(val: any, msg?: string):void; 221 | isNotNumber(val: any, msg?: string):void; 222 | 223 | isBoolean(val: any, msg?: string):void; 224 | isNotBoolean(val: any, msg?: string):void; 225 | 226 | typeOf(val: any, type: string, msg?: string):void; 227 | notTypeOf(val: any, type: string, msg?: string):void; 228 | 229 | instanceOf(val: any, type: Function, msg?: string):void; 230 | notInstanceOf(val: any, type: Function, msg?: string):void; 231 | 232 | include(exp: string, inc: any, msg?: string):void; 233 | include(exp: any[], inc: any, msg?: string):void; 234 | 235 | notInclude(exp: string, inc: any, msg?: string):void; 236 | notInclude(exp: any[], inc: any, msg?: string):void; 237 | 238 | match(exp: any, re: RegExp, msg?: string):void; 239 | notMatch(exp: any, re: RegExp, msg?: string):void; 240 | 241 | property(obj: Object, prop: string, msg?: string):void; 242 | notProperty(obj: Object, prop: string, msg?: string):void; 243 | deepProperty(obj: Object, prop: string, msg?: string):void; 244 | notDeepProperty(obj: Object, prop: string, msg?: string):void; 245 | 246 | propertyVal(obj: Object, prop: string, val: any, msg?: string):void; 247 | propertyNotVal(obj: Object, prop: string, val: any, msg?: string):void; 248 | 249 | deepPropertyVal(obj: Object, prop: string, val: any, msg?: string):void; 250 | deepPropertyNotVal(obj: Object, prop: string, val: any, msg?: string):void; 251 | 252 | lengthOf(exp: any, len: number, msg?: string):void; 253 | //alias frenzy 254 | throw(fn: Function, msg?: string):void; 255 | throw(fn: Function, regExp: RegExp):void; 256 | throw(fn: Function, errType: Function, msg?: string):void; 257 | throw(fn: Function, errType: Function, regExp: RegExp):void; 258 | 259 | throws(fn: Function, msg?: string):void; 260 | throws(fn: Function, regExp: RegExp):void; 261 | throws(fn: Function, errType: Function, msg?: string):void; 262 | throws(fn: Function, errType: Function, regExp: RegExp):void; 263 | 264 | Throw(fn: Function, msg?: string):void; 265 | Throw(fn: Function, regExp: RegExp):void; 266 | Throw(fn: Function, errType: Function, msg?: string):void; 267 | Throw(fn: Function, errType: Function, regExp: RegExp):void; 268 | 269 | doesNotThrow(fn: Function, msg?: string):void; 270 | doesNotThrow(fn: Function, regExp: RegExp):void; 271 | doesNotThrow(fn: Function, errType: Function, msg?: string):void; 272 | doesNotThrow(fn: Function, errType: Function, regExp: RegExp):void; 273 | 274 | operator(val: any, operator: string, val2: any, msg?: string):void; 275 | closeTo(act: number, exp: number, delta: number, msg?: string):void; 276 | 277 | sameMembers(set1: any[], set2: any[], msg?: string):void; 278 | includeMembers(set1: any[], set2: any[], msg?: string):void; 279 | 280 | ifError(val: any, msg?: string):void; 281 | } 282 | } 283 | 284 | declare module "chai" { 285 | export = chai; 286 | } 287 | -------------------------------------------------------------------------------- /typings/mocha/mocha.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for mocha 1.17.1 2 | // Project: http://visionmedia.github.io/mocha/ 3 | // Definitions by: Kazi Manzur Rashid , otiai10 4 | // Definitions: https://github.com/borisyankov/DefinitelyTyped 5 | 6 | interface Mocha { 7 | // Setup mocha with the given setting options. 8 | setup(options: MochaSetupOptions): Mocha; 9 | 10 | //Run tests and invoke `fn()` when complete. 11 | run(callback?: () => void): void; 12 | 13 | // Set reporter as function 14 | reporter(reporter: () => void): Mocha; 15 | 16 | // Set reporter, defaults to "dot" 17 | reporter(reporter: string): Mocha; 18 | 19 | // Enable growl support. 20 | growl(): Mocha 21 | } 22 | 23 | interface MochaSetupOptions { 24 | //milliseconds to wait before considering a test slow 25 | slow?: number; 26 | 27 | // timeout in milliseconds 28 | timeout?: number; 29 | 30 | // ui name "bdd", "tdd", "exports" etc 31 | ui?: string; 32 | 33 | //array of accepted globals 34 | globals?: any[]; 35 | 36 | // reporter instance (function or string), defaults to `mocha.reporters.Dot` 37 | reporter?: any; 38 | 39 | // bail on the first test failure 40 | bail?: Boolean; 41 | 42 | // ignore global leaks 43 | ignoreLeaks?: Boolean; 44 | 45 | // grep string or regexp to filter tests with 46 | grep?: any; 47 | } 48 | 49 | interface MochaDone { 50 | (error?: Error): void; 51 | } 52 | 53 | declare var mocha: Mocha; 54 | 55 | declare var describe : { 56 | (description: string, spec: () => void): void; 57 | only(description: string, spec: () => void): void; 58 | skip(description: string, spec: () => void): void; 59 | timeout(ms: number): void; 60 | } 61 | 62 | // alias for `describe` 63 | declare var context : { 64 | (contextTitle: string, spec: () => void): void; 65 | only(contextTitle: string, spec: () => void): void; 66 | skip(contextTitle: string, spec: () => void): void; 67 | timeout(ms: number): void; 68 | } 69 | 70 | declare var it: { 71 | (expectation: string, assertion?: () => void): void; 72 | (expectation: string, assertion?: (done: MochaDone) => void): void; 73 | only(expectation: string, assertion?: () => void): void; 74 | only(expectation: string, assertion?: (done: MochaDone) => void): void; 75 | skip(expectation: string, assertion?: () => void): void; 76 | skip(expectation: string, assertion?: (done: MochaDone) => void): void; 77 | timeout(ms: number): void; 78 | }; 79 | 80 | declare function before(action: () => void): void; 81 | 82 | declare function before(action: (done: MochaDone) => void): void; 83 | 84 | declare function setup(action: () => void): void; 85 | 86 | declare function setup(action: (done: MochaDone) => void): void; 87 | 88 | declare function after(action: () => void): void; 89 | 90 | declare function after(action: (done: MochaDone) => void): void; 91 | 92 | declare function teardown(action: () => void): void; 93 | 94 | declare function teardown(action: (done: MochaDone) => void): void; 95 | 96 | declare function beforeEach(action: () => void): void; 97 | 98 | declare function beforeEach(action: (done: MochaDone) => void): void; 99 | 100 | declare function suiteSetup(action: () => void): void; 101 | 102 | declare function suiteSetup(action: (done: MochaDone) => void): void; 103 | 104 | declare function afterEach(action: () => void): void; 105 | 106 | declare function afterEach(action: (done: MochaDone) => void): void; 107 | 108 | declare function suiteTeardown(action: () => void): void; 109 | 110 | declare function suiteTeardown(action: (done: MochaDone) => void): void; 111 | -------------------------------------------------------------------------------- /typings/node/node.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for Node.js v0.10.1 2 | // Project: http://nodejs.org/ 3 | // Definitions by: Microsoft TypeScript , DefinitelyTyped 4 | // Definitions: https://github.com/borisyankov/DefinitelyTyped 5 | 6 | /************************************************ 7 | * * 8 | * Node.js v0.10.1 API * 9 | * * 10 | ************************************************/ 11 | 12 | /************************************************ 13 | * * 14 | * GLOBAL * 15 | * * 16 | ************************************************/ 17 | declare var process: NodeJS.Process; 18 | declare var global: any; 19 | 20 | declare var __filename: string; 21 | declare var __dirname: string; 22 | 23 | declare function setTimeout(callback: (...args: any[]) => void, ms: number, ...args: any[]): NodeJS.Timer; 24 | declare function clearTimeout(timeoutId: NodeJS.Timer): void; 25 | declare function setInterval(callback: (...args: any[]) => void, ms: number, ...args: any[]): NodeJS.Timer; 26 | declare function clearInterval(intervalId: NodeJS.Timer): void; 27 | declare function setImmediate(callback: (...args: any[]) => void, ...args: any[]): any; 28 | declare function clearImmediate(immediateId: any): void; 29 | 30 | declare var require: { 31 | (id: string): any; 32 | resolve(id:string): string; 33 | cache: any; 34 | extensions: any; 35 | main: any; 36 | }; 37 | 38 | declare var module: { 39 | exports: any; 40 | require(id: string): any; 41 | id: string; 42 | filename: string; 43 | loaded: boolean; 44 | parent: any; 45 | children: any[]; 46 | }; 47 | 48 | // Same as module.exports 49 | declare var exports: any; 50 | declare var SlowBuffer: { 51 | new (str: string, encoding?: string): Buffer; 52 | new (size: number): Buffer; 53 | new (size: Uint8Array): Buffer; 54 | new (array: any[]): Buffer; 55 | prototype: Buffer; 56 | isBuffer(obj: any): boolean; 57 | byteLength(string: string, encoding?: string): number; 58 | concat(list: Buffer[], totalLength?: number): Buffer; 59 | }; 60 | 61 | 62 | // Buffer class 63 | interface Buffer extends NodeBuffer {} 64 | declare var Buffer: { 65 | new (str: string, encoding?: string): Buffer; 66 | new (size: number): Buffer; 67 | new (size: Uint8Array): Buffer; 68 | new (array: any[]): Buffer; 69 | prototype: Buffer; 70 | isBuffer(obj: any): boolean; 71 | byteLength(string: string, encoding?: string): number; 72 | concat(list: Buffer[], totalLength?: number): Buffer; 73 | }; 74 | 75 | /************************************************ 76 | * * 77 | * GLOBAL INTERFACES * 78 | * * 79 | ************************************************/ 80 | declare module NodeJS { 81 | export interface ErrnoException extends Error { 82 | errno?: any; 83 | code?: string; 84 | path?: string; 85 | syscall?: string; 86 | } 87 | 88 | export interface EventEmitter { 89 | addListener(event: string, listener: Function): EventEmitter; 90 | on(event: string, listener: Function): EventEmitter; 91 | once(event: string, listener: Function): EventEmitter; 92 | removeListener(event: string, listener: Function): EventEmitter; 93 | removeAllListeners(event?: string): EventEmitter; 94 | setMaxListeners(n: number): void; 95 | listeners(event: string): Function[]; 96 | emit(event: string, ...args: any[]): boolean; 97 | } 98 | 99 | export interface ReadableStream extends EventEmitter { 100 | readable: boolean; 101 | read(size?: number): any; 102 | setEncoding(encoding: string): void; 103 | pause(): void; 104 | resume(): void; 105 | pipe(destination: T, options?: { end?: boolean; }): T; 106 | unpipe(destination?: T): void; 107 | unshift(chunk: string): void; 108 | unshift(chunk: Buffer): void; 109 | wrap(oldStream: ReadableStream): ReadableStream; 110 | } 111 | 112 | export interface WritableStream extends EventEmitter { 113 | writable: boolean; 114 | write(buffer: Buffer, cb?: Function): boolean; 115 | write(str: string, cb?: Function): boolean; 116 | write(str: string, encoding?: string, cb?: Function): boolean; 117 | end(): void; 118 | end(buffer: Buffer, cb?: Function): void; 119 | end(str: string, cb?: Function): void; 120 | end(str: string, encoding?: string, cb?: Function): void; 121 | } 122 | 123 | export interface ReadWriteStream extends ReadableStream, WritableStream {} 124 | 125 | export interface Process extends EventEmitter { 126 | stdout: WritableStream; 127 | stderr: WritableStream; 128 | stdin: ReadableStream; 129 | argv: string[]; 130 | execPath: string; 131 | abort(): void; 132 | chdir(directory: string): void; 133 | cwd(): string; 134 | env: any; 135 | exit(code?: number): void; 136 | getgid(): number; 137 | setgid(id: number): void; 138 | setgid(id: string): void; 139 | getuid(): number; 140 | setuid(id: number): void; 141 | setuid(id: string): void; 142 | version: string; 143 | versions: { 144 | http_parser: string; 145 | node: string; 146 | v8: string; 147 | ares: string; 148 | uv: string; 149 | zlib: string; 150 | openssl: string; 151 | }; 152 | config: { 153 | target_defaults: { 154 | cflags: any[]; 155 | default_configuration: string; 156 | defines: string[]; 157 | include_dirs: string[]; 158 | libraries: string[]; 159 | }; 160 | variables: { 161 | clang: number; 162 | host_arch: string; 163 | node_install_npm: boolean; 164 | node_install_waf: boolean; 165 | node_prefix: string; 166 | node_shared_openssl: boolean; 167 | node_shared_v8: boolean; 168 | node_shared_zlib: boolean; 169 | node_use_dtrace: boolean; 170 | node_use_etw: boolean; 171 | node_use_openssl: boolean; 172 | target_arch: string; 173 | v8_no_strict_aliasing: number; 174 | v8_use_snapshot: boolean; 175 | visibility: string; 176 | }; 177 | }; 178 | kill(pid: number, signal?: string): void; 179 | pid: number; 180 | title: string; 181 | arch: string; 182 | platform: string; 183 | memoryUsage(): { rss: number; heapTotal: number; heapUsed: number; }; 184 | nextTick(callback: Function): void; 185 | umask(mask?: number): number; 186 | uptime(): number; 187 | hrtime(time?:number[]): number[]; 188 | 189 | // Worker 190 | send?(message: any, sendHandle?: any): void; 191 | } 192 | 193 | export interface Timer { 194 | ref() : void; 195 | unref() : void; 196 | } 197 | } 198 | 199 | /** 200 | * @deprecated 201 | */ 202 | interface NodeBuffer { 203 | [index: number]: number; 204 | write(string: string, offset?: number, length?: number, encoding?: string): number; 205 | toString(encoding?: string, start?: number, end?: number): string; 206 | toJSON(): any; 207 | length: number; 208 | copy(targetBuffer: Buffer, targetStart?: number, sourceStart?: number, sourceEnd?: number): number; 209 | slice(start?: number, end?: number): Buffer; 210 | readUInt8(offset: number, noAsset?: boolean): number; 211 | readUInt16LE(offset: number, noAssert?: boolean): number; 212 | readUInt16BE(offset: number, noAssert?: boolean): number; 213 | readUInt32LE(offset: number, noAssert?: boolean): number; 214 | readUInt32BE(offset: number, noAssert?: boolean): number; 215 | readInt8(offset: number, noAssert?: boolean): number; 216 | readInt16LE(offset: number, noAssert?: boolean): number; 217 | readInt16BE(offset: number, noAssert?: boolean): number; 218 | readInt32LE(offset: number, noAssert?: boolean): number; 219 | readInt32BE(offset: number, noAssert?: boolean): number; 220 | readFloatLE(offset: number, noAssert?: boolean): number; 221 | readFloatBE(offset: number, noAssert?: boolean): number; 222 | readDoubleLE(offset: number, noAssert?: boolean): number; 223 | readDoubleBE(offset: number, noAssert?: boolean): number; 224 | writeUInt8(value: number, offset: number, noAssert?: boolean): void; 225 | writeUInt16LE(value: number, offset: number, noAssert?: boolean): void; 226 | writeUInt16BE(value: number, offset: number, noAssert?: boolean): void; 227 | writeUInt32LE(value: number, offset: number, noAssert?: boolean): void; 228 | writeUInt32BE(value: number, offset: number, noAssert?: boolean): void; 229 | writeInt8(value: number, offset: number, noAssert?: boolean): void; 230 | writeInt16LE(value: number, offset: number, noAssert?: boolean): void; 231 | writeInt16BE(value: number, offset: number, noAssert?: boolean): void; 232 | writeInt32LE(value: number, offset: number, noAssert?: boolean): void; 233 | writeInt32BE(value: number, offset: number, noAssert?: boolean): void; 234 | writeFloatLE(value: number, offset: number, noAssert?: boolean): void; 235 | writeFloatBE(value: number, offset: number, noAssert?: boolean): void; 236 | writeDoubleLE(value: number, offset: number, noAssert?: boolean): void; 237 | writeDoubleBE(value: number, offset: number, noAssert?: boolean): void; 238 | fill(value: any, offset?: number, end?: number): void; 239 | } 240 | 241 | /************************************************ 242 | * * 243 | * MODULES * 244 | * * 245 | ************************************************/ 246 | declare module "buffer" { 247 | export var INSPECT_MAX_BYTES: number; 248 | } 249 | 250 | declare module "querystring" { 251 | export function stringify(obj: any, sep?: string, eq?: string): string; 252 | export function parse(str: string, sep?: string, eq?: string, options?: { maxKeys?: number; }): any; 253 | export function escape(): any; 254 | export function unescape(): any; 255 | } 256 | 257 | declare module "events" { 258 | export class EventEmitter implements NodeJS.EventEmitter { 259 | static listenerCount(emitter: EventEmitter, event: string): number; 260 | 261 | addListener(event: string, listener: Function): EventEmitter; 262 | on(event: string, listener: Function): EventEmitter; 263 | once(event: string, listener: Function): EventEmitter; 264 | removeListener(event: string, listener: Function): EventEmitter; 265 | removeAllListeners(event?: string): EventEmitter; 266 | setMaxListeners(n: number): void; 267 | listeners(event: string): Function[]; 268 | emit(event: string, ...args: any[]): boolean; 269 | } 270 | } 271 | 272 | declare module "http" { 273 | import events = require("events"); 274 | import net = require("net"); 275 | import stream = require("stream"); 276 | 277 | export interface Server extends events.EventEmitter { 278 | listen(port: number, hostname?: string, backlog?: number, callback?: Function): Server; 279 | listen(path: string, callback?: Function): Server; 280 | listen(handle: any, listeningListener?: Function): Server; 281 | close(cb?: any): Server; 282 | address(): { port: number; family: string; address: string; }; 283 | maxHeadersCount: number; 284 | } 285 | export interface ServerRequest extends events.EventEmitter, stream.Readable { 286 | method: string; 287 | url: string; 288 | headers: any; 289 | trailers: string; 290 | httpVersion: string; 291 | setEncoding(encoding?: string): void; 292 | pause(): void; 293 | resume(): void; 294 | connection: net.Socket; 295 | } 296 | export interface ServerResponse extends events.EventEmitter, stream.Writable { 297 | // Extended base methods 298 | write(buffer: Buffer): boolean; 299 | write(buffer: Buffer, cb?: Function): boolean; 300 | write(str: string, cb?: Function): boolean; 301 | write(str: string, encoding?: string, cb?: Function): boolean; 302 | write(str: string, encoding?: string, fd?: string): boolean; 303 | 304 | writeContinue(): void; 305 | writeHead(statusCode: number, reasonPhrase?: string, headers?: any): void; 306 | writeHead(statusCode: number, headers?: any): void; 307 | statusCode: number; 308 | setHeader(name: string, value: string): void; 309 | sendDate: boolean; 310 | getHeader(name: string): string; 311 | removeHeader(name: string): void; 312 | write(chunk: any, encoding?: string): any; 313 | addTrailers(headers: any): void; 314 | 315 | // Extended base methods 316 | end(): void; 317 | end(buffer: Buffer, cb?: Function): void; 318 | end(str: string, cb?: Function): void; 319 | end(str: string, encoding?: string, cb?: Function): void; 320 | end(data?: any, encoding?: string): void; 321 | } 322 | export interface ClientRequest extends events.EventEmitter, stream.Writable { 323 | // Extended base methods 324 | write(buffer: Buffer): boolean; 325 | write(buffer: Buffer, cb?: Function): boolean; 326 | write(str: string, cb?: Function): boolean; 327 | write(str: string, encoding?: string, cb?: Function): boolean; 328 | write(str: string, encoding?: string, fd?: string): boolean; 329 | 330 | write(chunk: any, encoding?: string): void; 331 | abort(): void; 332 | setTimeout(timeout: number, callback?: Function): void; 333 | setNoDelay(noDelay?: boolean): void; 334 | setSocketKeepAlive(enable?: boolean, initialDelay?: number): void; 335 | 336 | // Extended base methods 337 | end(): void; 338 | end(buffer: Buffer, cb?: Function): void; 339 | end(str: string, cb?: Function): void; 340 | end(str: string, encoding?: string, cb?: Function): void; 341 | end(data?: any, encoding?: string): void; 342 | } 343 | export interface ClientResponse extends events.EventEmitter, stream.Readable { 344 | statusCode: number; 345 | httpVersion: string; 346 | headers: any; 347 | trailers: any; 348 | setEncoding(encoding?: string): void; 349 | pause(): void; 350 | resume(): void; 351 | } 352 | export interface Agent { maxSockets: number; sockets: any; requests: any; } 353 | 354 | export var STATUS_CODES: { 355 | [errorCode: number]: string; 356 | [errorCode: string]: string; 357 | }; 358 | export function createServer(requestListener?: (request: ServerRequest, response: ServerResponse) =>void ): Server; 359 | export function createClient(port?: number, host?: string): any; 360 | export function request(options: any, callback?: Function): ClientRequest; 361 | export function get(options: any, callback?: Function): ClientRequest; 362 | export var globalAgent: Agent; 363 | } 364 | 365 | declare module "cluster" { 366 | import child = require("child_process"); 367 | import events = require("events"); 368 | 369 | export interface ClusterSettings { 370 | exec?: string; 371 | args?: string[]; 372 | silent?: boolean; 373 | } 374 | 375 | export class Worker extends events.EventEmitter { 376 | id: string; 377 | process: child.ChildProcess; 378 | suicide: boolean; 379 | send(message: any, sendHandle?: any): void; 380 | kill(signal?: string): void; 381 | destroy(signal?: string): void; 382 | disconnect(): void; 383 | } 384 | 385 | export var settings: ClusterSettings; 386 | export var isMaster: boolean; 387 | export var isWorker: boolean; 388 | export function setupMaster(settings?: ClusterSettings): void; 389 | export function fork(env?: any): Worker; 390 | export function disconnect(callback?: Function): void; 391 | export var worker: Worker; 392 | export var workers: Worker[]; 393 | 394 | // Event emitter 395 | export function addListener(event: string, listener: Function): void; 396 | export function on(event: string, listener: Function): any; 397 | export function once(event: string, listener: Function): void; 398 | export function removeListener(event: string, listener: Function): void; 399 | export function removeAllListeners(event?: string): void; 400 | export function setMaxListeners(n: number): void; 401 | export function listeners(event: string): Function[]; 402 | export function emit(event: string, ...args: any[]): boolean; 403 | } 404 | 405 | declare module "zlib" { 406 | import stream = require("stream"); 407 | export interface ZlibOptions { chunkSize?: number; windowBits?: number; level?: number; memLevel?: number; strategy?: number; dictionary?: any; } 408 | 409 | export interface Gzip extends stream.Transform { } 410 | export interface Gunzip extends stream.Transform { } 411 | export interface Deflate extends stream.Transform { } 412 | export interface Inflate extends stream.Transform { } 413 | export interface DeflateRaw extends stream.Transform { } 414 | export interface InflateRaw extends stream.Transform { } 415 | export interface Unzip extends stream.Transform { } 416 | 417 | export function createGzip(options?: ZlibOptions): Gzip; 418 | export function createGunzip(options?: ZlibOptions): Gunzip; 419 | export function createDeflate(options?: ZlibOptions): Deflate; 420 | export function createInflate(options?: ZlibOptions): Inflate; 421 | export function createDeflateRaw(options?: ZlibOptions): DeflateRaw; 422 | export function createInflateRaw(options?: ZlibOptions): InflateRaw; 423 | export function createUnzip(options?: ZlibOptions): Unzip; 424 | 425 | export function deflate(buf: Buffer, callback: (error: Error, result: any) =>void ): void; 426 | export function deflateRaw(buf: Buffer, callback: (error: Error, result: any) =>void ): void; 427 | export function gzip(buf: Buffer, callback: (error: Error, result: any) =>void ): void; 428 | export function gunzip(buf: Buffer, callback: (error: Error, result: any) =>void ): void; 429 | export function inflate(buf: Buffer, callback: (error: Error, result: any) =>void ): void; 430 | export function inflateRaw(buf: Buffer, callback: (error: Error, result: any) =>void ): void; 431 | export function unzip(buf: Buffer, callback: (error: Error, result: any) =>void ): void; 432 | 433 | // Constants 434 | export var Z_NO_FLUSH: number; 435 | export var Z_PARTIAL_FLUSH: number; 436 | export var Z_SYNC_FLUSH: number; 437 | export var Z_FULL_FLUSH: number; 438 | export var Z_FINISH: number; 439 | export var Z_BLOCK: number; 440 | export var Z_TREES: number; 441 | export var Z_OK: number; 442 | export var Z_STREAM_END: number; 443 | export var Z_NEED_DICT: number; 444 | export var Z_ERRNO: number; 445 | export var Z_STREAM_ERROR: number; 446 | export var Z_DATA_ERROR: number; 447 | export var Z_MEM_ERROR: number; 448 | export var Z_BUF_ERROR: number; 449 | export var Z_VERSION_ERROR: number; 450 | export var Z_NO_COMPRESSION: number; 451 | export var Z_BEST_SPEED: number; 452 | export var Z_BEST_COMPRESSION: number; 453 | export var Z_DEFAULT_COMPRESSION: number; 454 | export var Z_FILTERED: number; 455 | export var Z_HUFFMAN_ONLY: number; 456 | export var Z_RLE: number; 457 | export var Z_FIXED: number; 458 | export var Z_DEFAULT_STRATEGY: number; 459 | export var Z_BINARY: number; 460 | export var Z_TEXT: number; 461 | export var Z_ASCII: number; 462 | export var Z_UNKNOWN: number; 463 | export var Z_DEFLATED: number; 464 | export var Z_NULL: number; 465 | } 466 | 467 | declare module "os" { 468 | export function tmpDir(): string; 469 | export function hostname(): string; 470 | export function type(): string; 471 | export function platform(): string; 472 | export function arch(): string; 473 | export function release(): string; 474 | export function uptime(): number; 475 | export function loadavg(): number[]; 476 | export function totalmem(): number; 477 | export function freemem(): number; 478 | export function cpus(): { model: string; speed: number; times: { user: number; nice: number; sys: number; idle: number; irq: number; }; }[]; 479 | export function networkInterfaces(): any; 480 | export var EOL: string; 481 | } 482 | 483 | declare module "https" { 484 | import tls = require("tls"); 485 | import events = require("events"); 486 | import http = require("http"); 487 | 488 | export interface ServerOptions { 489 | pfx?: any; 490 | key?: any; 491 | passphrase?: string; 492 | cert?: any; 493 | ca?: any; 494 | crl?: any; 495 | ciphers?: string; 496 | honorCipherOrder?: boolean; 497 | requestCert?: boolean; 498 | rejectUnauthorized?: boolean; 499 | NPNProtocols?: any; 500 | SNICallback?: (servername: string) => any; 501 | } 502 | 503 | export interface RequestOptions { 504 | host?: string; 505 | hostname?: string; 506 | port?: number; 507 | path?: string; 508 | method?: string; 509 | headers?: any; 510 | auth?: string; 511 | agent?: any; 512 | pfx?: any; 513 | key?: any; 514 | passphrase?: string; 515 | cert?: any; 516 | ca?: any; 517 | ciphers?: string; 518 | rejectUnauthorized?: boolean; 519 | } 520 | 521 | export interface Agent { 522 | maxSockets: number; 523 | sockets: any; 524 | requests: any; 525 | } 526 | export var Agent: { 527 | new (options?: RequestOptions): Agent; 528 | }; 529 | export interface Server extends tls.Server { } 530 | export function createServer(options: ServerOptions, requestListener?: Function): Server; 531 | export function request(options: RequestOptions, callback?: (res: events.EventEmitter) =>void ): http.ClientRequest; 532 | export function get(options: RequestOptions, callback?: (res: events.EventEmitter) =>void ): http.ClientRequest; 533 | export var globalAgent: Agent; 534 | } 535 | 536 | declare module "punycode" { 537 | export function decode(string: string): string; 538 | export function encode(string: string): string; 539 | export function toUnicode(domain: string): string; 540 | export function toASCII(domain: string): string; 541 | export var ucs2: ucs2; 542 | interface ucs2 { 543 | decode(string: string): string; 544 | encode(codePoints: number[]): string; 545 | } 546 | export var version: any; 547 | } 548 | 549 | declare module "repl" { 550 | import stream = require("stream"); 551 | import events = require("events"); 552 | 553 | export interface ReplOptions { 554 | prompt?: string; 555 | input?: NodeJS.ReadableStream; 556 | output?: NodeJS.WritableStream; 557 | terminal?: boolean; 558 | eval?: Function; 559 | useColors?: boolean; 560 | useGlobal?: boolean; 561 | ignoreUndefined?: boolean; 562 | writer?: Function; 563 | } 564 | export function start(options: ReplOptions): events.EventEmitter; 565 | } 566 | 567 | declare module "readline" { 568 | import events = require("events"); 569 | import stream = require("stream"); 570 | 571 | export interface ReadLine extends events.EventEmitter { 572 | setPrompt(prompt: string, length: number): void; 573 | prompt(preserveCursor?: boolean): void; 574 | question(query: string, callback: Function): void; 575 | pause(): void; 576 | resume(): void; 577 | close(): void; 578 | write(data: any, key?: any): void; 579 | } 580 | export interface ReadLineOptions { 581 | input: NodeJS.ReadableStream; 582 | output: NodeJS.WritableStream; 583 | completer?: Function; 584 | terminal?: boolean; 585 | } 586 | export function createInterface(options: ReadLineOptions): ReadLine; 587 | } 588 | 589 | declare module "vm" { 590 | export interface Context { } 591 | export interface Script { 592 | runInThisContext(): void; 593 | runInNewContext(sandbox?: Context): void; 594 | } 595 | export function runInThisContext(code: string, filename?: string): void; 596 | export function runInNewContext(code: string, sandbox?: Context, filename?: string): void; 597 | export function runInContext(code: string, context: Context, filename?: string): void; 598 | export function createContext(initSandbox?: Context): Context; 599 | export function createScript(code: string, filename?: string): Script; 600 | } 601 | 602 | declare module "child_process" { 603 | import events = require("events"); 604 | import stream = require("stream"); 605 | 606 | export interface ChildProcess extends events.EventEmitter { 607 | stdin: stream.Writable; 608 | stdout: stream.Readable; 609 | stderr: stream.Readable; 610 | pid: number; 611 | kill(signal?: string): void; 612 | send(message: any, sendHandle: any): void; 613 | disconnect(): void; 614 | } 615 | 616 | export function spawn(command: string, args?: string[], options?: { 617 | cwd?: string; 618 | stdio?: any; 619 | custom?: any; 620 | env?: any; 621 | detached?: boolean; 622 | }): ChildProcess; 623 | export function exec(command: string, options: { 624 | cwd?: string; 625 | stdio?: any; 626 | customFds?: any; 627 | env?: any; 628 | encoding?: string; 629 | timeout?: number; 630 | maxBuffer?: number; 631 | killSignal?: string; 632 | }, callback: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; 633 | export function exec(command: string, callback: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; 634 | export function execFile(file: string, args: string[], options: { 635 | cwd?: string; 636 | stdio?: any; 637 | customFds?: any; 638 | env?: any; 639 | encoding?: string; 640 | timeout?: number; 641 | maxBuffer?: string; 642 | killSignal?: string; 643 | }, callback: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; 644 | export function fork(modulePath: string, args?: string[], options?: { 645 | cwd?: string; 646 | env?: any; 647 | encoding?: string; 648 | }): ChildProcess; 649 | } 650 | 651 | declare module "url" { 652 | export interface Url { 653 | href: string; 654 | protocol: string; 655 | auth: string; 656 | hostname: string; 657 | port: string; 658 | host: string; 659 | pathname: string; 660 | search: string; 661 | query: any; // string | Object 662 | slashes: boolean; 663 | hash?: string; 664 | path?: string; 665 | } 666 | 667 | export interface UrlOptions { 668 | protocol?: string; 669 | auth?: string; 670 | hostname?: string; 671 | port?: string; 672 | host?: string; 673 | pathname?: string; 674 | search?: string; 675 | query?: any; 676 | hash?: string; 677 | path?: string; 678 | } 679 | 680 | export function parse(urlStr: string, parseQueryString?: boolean , slashesDenoteHost?: boolean ): Url; 681 | export function format(url: UrlOptions): string; 682 | export function resolve(from: string, to: string): string; 683 | } 684 | 685 | declare module "dns" { 686 | export function lookup(domain: string, family: number, callback: (err: Error, address: string, family: number) =>void ): string; 687 | export function lookup(domain: string, callback: (err: Error, address: string, family: number) =>void ): string; 688 | export function resolve(domain: string, rrtype: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 689 | export function resolve(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 690 | export function resolve4(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 691 | export function resolve6(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 692 | export function resolveMx(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 693 | export function resolveTxt(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 694 | export function resolveSrv(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 695 | export function resolveNs(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 696 | export function resolveCname(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 697 | export function reverse(ip: string, callback: (err: Error, domains: string[]) =>void ): string[]; 698 | } 699 | 700 | declare module "net" { 701 | import stream = require("stream"); 702 | 703 | export interface Socket extends stream.Duplex { 704 | // Extended base methods 705 | write(buffer: Buffer): boolean; 706 | write(buffer: Buffer, cb?: Function): boolean; 707 | write(str: string, cb?: Function): boolean; 708 | write(str: string, encoding?: string, cb?: Function): boolean; 709 | write(str: string, encoding?: string, fd?: string): boolean; 710 | 711 | connect(port: number, host?: string, connectionListener?: Function): void; 712 | connect(path: string, connectionListener?: Function): void; 713 | bufferSize: number; 714 | setEncoding(encoding?: string): void; 715 | write(data: any, encoding?: string, callback?: Function): void; 716 | destroy(): void; 717 | pause(): void; 718 | resume(): void; 719 | setTimeout(timeout: number, callback?: Function): void; 720 | setNoDelay(noDelay?: boolean): void; 721 | setKeepAlive(enable?: boolean, initialDelay?: number): void; 722 | address(): { port: number; family: string; address: string; }; 723 | unref(): void; 724 | ref(): void; 725 | 726 | remoteAddress: string; 727 | remotePort: number; 728 | bytesRead: number; 729 | bytesWritten: number; 730 | 731 | // Extended base methods 732 | end(): void; 733 | end(buffer: Buffer, cb?: Function): void; 734 | end(str: string, cb?: Function): void; 735 | end(str: string, encoding?: string, cb?: Function): void; 736 | end(data?: any, encoding?: string): void; 737 | } 738 | 739 | export var Socket: { 740 | new (options?: { fd?: string; type?: string; allowHalfOpen?: boolean; }): Socket; 741 | }; 742 | 743 | export interface Server extends Socket { 744 | listen(port: number, host?: string, backlog?: number, listeningListener?: Function): Server; 745 | listen(path: string, listeningListener?: Function): Server; 746 | listen(handle: any, listeningListener?: Function): Server; 747 | close(callback?: Function): Server; 748 | address(): { port: number; family: string; address: string; }; 749 | maxConnections: number; 750 | connections: number; 751 | } 752 | export function createServer(connectionListener?: (socket: Socket) =>void ): Server; 753 | export function createServer(options?: { allowHalfOpen?: boolean; }, connectionListener?: (socket: Socket) =>void ): Server; 754 | export function connect(options: { allowHalfOpen?: boolean; }, connectionListener?: Function): Socket; 755 | export function connect(port: number, host?: string, connectionListener?: Function): Socket; 756 | export function connect(path: string, connectionListener?: Function): Socket; 757 | export function createConnection(options: { allowHalfOpen?: boolean; }, connectionListener?: Function): Socket; 758 | export function createConnection(port: number, host?: string, connectionListener?: Function): Socket; 759 | export function createConnection(path: string, connectionListener?: Function): Socket; 760 | export function isIP(input: string): number; 761 | export function isIPv4(input: string): boolean; 762 | export function isIPv6(input: string): boolean; 763 | } 764 | 765 | declare module "dgram" { 766 | import events = require("events"); 767 | 768 | interface RemoteInfo { 769 | address: string; 770 | port: number; 771 | size: number; 772 | } 773 | 774 | interface AddressInfo { 775 | address: string; 776 | family: string; 777 | port: number; 778 | } 779 | 780 | export function createSocket(type: string, callback?: (msg: Buffer, rinfo: RemoteInfo) => void): Socket; 781 | 782 | interface Socket extends events.EventEmitter { 783 | send(buf: Buffer, offset: number, length: number, port: number, address: string, callback?: (error: Error, bytes: number) => void): void; 784 | bind(port: number, address?: string, callback?: () => void): void; 785 | close(): void; 786 | address(): AddressInfo; 787 | setBroadcast(flag: boolean): void; 788 | setMulticastTTL(ttl: number): void; 789 | setMulticastLoopback(flag: boolean): void; 790 | addMembership(multicastAddress: string, multicastInterface?: string): void; 791 | dropMembership(multicastAddress: string, multicastInterface?: string): void; 792 | } 793 | } 794 | 795 | declare module "fs" { 796 | import stream = require("stream"); 797 | import events = require("events"); 798 | 799 | interface Stats { 800 | isFile(): boolean; 801 | isDirectory(): boolean; 802 | isBlockDevice(): boolean; 803 | isCharacterDevice(): boolean; 804 | isSymbolicLink(): boolean; 805 | isFIFO(): boolean; 806 | isSocket(): boolean; 807 | dev: number; 808 | ino: number; 809 | mode: number; 810 | nlink: number; 811 | uid: number; 812 | gid: number; 813 | rdev: number; 814 | size: number; 815 | blksize: number; 816 | blocks: number; 817 | atime: Date; 818 | mtime: Date; 819 | ctime: Date; 820 | } 821 | 822 | interface FSWatcher extends events.EventEmitter { 823 | close(): void; 824 | } 825 | 826 | export interface ReadStream extends stream.Readable {} 827 | export interface WriteStream extends stream.Writable {} 828 | 829 | export function rename(oldPath: string, newPath: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 830 | export function renameSync(oldPath: string, newPath: string): void; 831 | export function truncate(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 832 | export function truncate(path: string, len: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 833 | export function truncateSync(path: string, len?: number): void; 834 | export function ftruncate(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 835 | export function ftruncate(fd: number, len: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 836 | export function ftruncateSync(fd: number, len?: number): void; 837 | export function chown(path: string, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 838 | export function chownSync(path: string, uid: number, gid: number): void; 839 | export function fchown(fd: number, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 840 | export function fchownSync(fd: number, uid: number, gid: number): void; 841 | export function lchown(path: string, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 842 | export function lchownSync(path: string, uid: number, gid: number): void; 843 | export function chmod(path: string, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 844 | export function chmod(path: string, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 845 | export function chmodSync(path: string, mode: number): void; 846 | export function chmodSync(path: string, mode: string): void; 847 | export function fchmod(fd: number, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 848 | export function fchmod(fd: number, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 849 | export function fchmodSync(fd: number, mode: number): void; 850 | export function fchmodSync(fd: number, mode: string): void; 851 | export function lchmod(path: string, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 852 | export function lchmod(path: string, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 853 | export function lchmodSync(path: string, mode: number): void; 854 | export function lchmodSync(path: string, mode: string): void; 855 | export function stat(path: string, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void; 856 | export function lstat(path: string, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void; 857 | export function fstat(fd: number, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void; 858 | export function statSync(path: string): Stats; 859 | export function lstatSync(path: string): Stats; 860 | export function fstatSync(fd: number): Stats; 861 | export function link(srcpath: string, dstpath: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 862 | export function linkSync(srcpath: string, dstpath: string): void; 863 | export function symlink(srcpath: string, dstpath: string, type?: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 864 | export function symlinkSync(srcpath: string, dstpath: string, type?: string): void; 865 | export function readlink(path: string, callback?: (err: NodeJS.ErrnoException, linkString: string) => any): void; 866 | export function readlinkSync(path: string): string; 867 | export function realpath(path: string, callback?: (err: NodeJS.ErrnoException, resolvedPath: string) => any): void; 868 | export function realpath(path: string, cache: {[path: string]: string}, callback: (err: NodeJS.ErrnoException, resolvedPath: string) =>any): void; 869 | export function realpathSync(path: string, cache?: {[path: string]: string}): string; 870 | export function unlink(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 871 | export function unlinkSync(path: string): void; 872 | export function rmdir(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 873 | export function rmdirSync(path: string): void; 874 | export function mkdir(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 875 | export function mkdir(path: string, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 876 | export function mkdir(path: string, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 877 | export function mkdirSync(path: string, mode?: number): void; 878 | export function mkdirSync(path: string, mode?: string): void; 879 | export function readdir(path: string, callback?: (err: NodeJS.ErrnoException, files: string[]) => void): void; 880 | export function readdirSync(path: string): string[]; 881 | export function close(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 882 | export function closeSync(fd: number): void; 883 | export function open(path: string, flags: string, callback?: (err: NodeJS.ErrnoException, fd: number) => any): void; 884 | export function open(path: string, flags: string, mode: number, callback?: (err: NodeJS.ErrnoException, fd: number) => any): void; 885 | export function open(path: string, flags: string, mode: string, callback?: (err: NodeJS.ErrnoException, fd: number) => any): void; 886 | export function openSync(path: string, flags: string, mode?: number): number; 887 | export function openSync(path: string, flags: string, mode?: string): number; 888 | export function utimes(path: string, atime: number, mtime: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 889 | export function utimes(path: string, atime: Date, mtime: Date, callback?: (err?: NodeJS.ErrnoException) => void): void; 890 | export function utimesSync(path: string, atime: number, mtime: number): void; 891 | export function utimesSync(path: string, atime: Date, mtime: Date): void; 892 | export function futimes(fd: number, atime: number, mtime: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 893 | export function futimes(fd: number, atime: Date, mtime: Date, callback?: (err?: NodeJS.ErrnoException) => void): void; 894 | export function futimesSync(fd: number, atime: number, mtime: number): void; 895 | export function futimesSync(fd: number, atime: Date, mtime: Date): void; 896 | export function fsync(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 897 | export function fsyncSync(fd: number): void; 898 | export function write(fd: number, buffer: Buffer, offset: number, length: number, position: number, callback?: (err: NodeJS.ErrnoException, written: number, buffer: Buffer) => void): void; 899 | export function writeSync(fd: number, buffer: Buffer, offset: number, length: number, position: number): number; 900 | export function read(fd: number, buffer: Buffer, offset: number, length: number, position: number, callback?: (err: NodeJS.ErrnoException, bytesRead: number, buffer: Buffer) => void): void; 901 | export function readSync(fd: number, buffer: Buffer, offset: number, length: number, position: number): number; 902 | export function readFile(filename: string, encoding: string, callback: (err: NodeJS.ErrnoException, data: string) => void): void; 903 | export function readFile(filename: string, options: { encoding: string; flag?: string; }, callback: (err: NodeJS.ErrnoException, data: string) => void): void; 904 | export function readFile(filename: string, options: { flag?: string; }, callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void; 905 | export function readFile(filename: string, callback: (err: NodeJS.ErrnoException, data: Buffer) => void ): void; 906 | export function readFileSync(filename: string, encoding: string): string; 907 | export function readFileSync(filename: string, options: { encoding: string; flag?: string; }): string; 908 | export function readFileSync(filename: string, options?: { flag?: string; }): Buffer; 909 | export function writeFile(filename: string, data: any, callback?: (err: NodeJS.ErrnoException) => void): void; 910 | export function writeFile(filename: string, data: any, options: { encoding?: string; mode?: number; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; 911 | export function writeFile(filename: string, data: any, options: { encoding?: string; mode?: string; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; 912 | export function writeFileSync(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; }): void; 913 | export function writeFileSync(filename: string, data: any, options?: { encoding?: string; mode?: string; flag?: string; }): void; 914 | export function appendFile(filename: string, data: any, options: { encoding?: string; mode?: number; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; 915 | export function appendFile(filename: string, data: any, options: { encoding?: string; mode?: string; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; 916 | export function appendFile(filename: string, data: any, callback?: (err: NodeJS.ErrnoException) => void): void; 917 | export function appendFileSync(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; }): void; 918 | export function appendFileSync(filename: string, data: any, options?: { encoding?: string; mode?: string; flag?: string; }): void; 919 | export function watchFile(filename: string, listener: (curr: Stats, prev: Stats) => void): void; 920 | export function watchFile(filename: string, options: { persistent?: boolean; interval?: number; }, listener: (curr: Stats, prev: Stats) => void): void; 921 | export function unwatchFile(filename: string, listener?: (curr: Stats, prev: Stats) => void): void; 922 | export function watch(filename: string, listener?: (event: string, filename: string) => any): FSWatcher; 923 | export function watch(filename: string, options: { persistent?: boolean; }, listener?: (event: string, filename: string) => any): FSWatcher; 924 | export function exists(path: string, callback?: (exists: boolean) => void): void; 925 | export function existsSync(path: string): boolean; 926 | export function createReadStream(path: string, options?: { 927 | flags?: string; 928 | encoding?: string; 929 | fd?: string; 930 | mode?: number; 931 | bufferSize?: number; 932 | }): ReadStream; 933 | export function createReadStream(path: string, options?: { 934 | flags?: string; 935 | encoding?: string; 936 | fd?: string; 937 | mode?: string; 938 | bufferSize?: number; 939 | }): ReadStream; 940 | export function createWriteStream(path: string, options?: { 941 | flags?: string; 942 | encoding?: string; 943 | string?: string; 944 | }): WriteStream; 945 | } 946 | 947 | declare module "path" { 948 | export function normalize(p: string): string; 949 | export function join(...paths: any[]): string; 950 | export function resolve(...pathSegments: any[]): string; 951 | export function relative(from: string, to: string): string; 952 | export function dirname(p: string): string; 953 | export function basename(p: string, ext?: string): string; 954 | export function extname(p: string): string; 955 | export var sep: string; 956 | } 957 | 958 | declare module "string_decoder" { 959 | export interface NodeStringDecoder { 960 | write(buffer: Buffer): string; 961 | detectIncompleteChar(buffer: Buffer): number; 962 | } 963 | export var StringDecoder: { 964 | new (encoding: string): NodeStringDecoder; 965 | }; 966 | } 967 | 968 | declare module "tls" { 969 | import crypto = require("crypto"); 970 | import net = require("net"); 971 | import stream = require("stream"); 972 | 973 | var CLIENT_RENEG_LIMIT: number; 974 | var CLIENT_RENEG_WINDOW: number; 975 | 976 | export interface TlsOptions { 977 | pfx?: any; //string or buffer 978 | key?: any; //string or buffer 979 | passphrase?: string; 980 | cert?: any; 981 | ca?: any; //string or buffer 982 | crl?: any; //string or string array 983 | ciphers?: string; 984 | honorCipherOrder?: any; 985 | requestCert?: boolean; 986 | rejectUnauthorized?: boolean; 987 | NPNProtocols?: any; //array or Buffer; 988 | SNICallback?: (servername: string) => any; 989 | } 990 | 991 | export interface ConnectionOptions { 992 | host?: string; 993 | port?: number; 994 | socket?: net.Socket; 995 | pfx?: any; //string | Buffer 996 | key?: any; //string | Buffer 997 | passphrase?: string; 998 | cert?: any; //string | Buffer 999 | ca?: any; //Array of string | Buffer 1000 | rejectUnauthorized?: boolean; 1001 | NPNProtocols?: any; //Array of string | Buffer 1002 | servername?: string; 1003 | } 1004 | 1005 | export interface Server extends net.Server { 1006 | // Extended base methods 1007 | listen(port: number, host?: string, backlog?: number, listeningListener?: Function): Server; 1008 | listen(path: string, listeningListener?: Function): Server; 1009 | listen(handle: any, listeningListener?: Function): Server; 1010 | 1011 | listen(port: number, host?: string, callback?: Function): Server; 1012 | close(): Server; 1013 | address(): { port: number; family: string; address: string; }; 1014 | addContext(hostName: string, credentials: { 1015 | key: string; 1016 | cert: string; 1017 | ca: string; 1018 | }): void; 1019 | maxConnections: number; 1020 | connections: number; 1021 | } 1022 | 1023 | export interface ClearTextStream extends stream.Duplex { 1024 | authorized: boolean; 1025 | authorizationError: Error; 1026 | getPeerCertificate(): any; 1027 | getCipher: { 1028 | name: string; 1029 | version: string; 1030 | }; 1031 | address: { 1032 | port: number; 1033 | family: string; 1034 | address: string; 1035 | }; 1036 | remoteAddress: string; 1037 | remotePort: number; 1038 | } 1039 | 1040 | export interface SecurePair { 1041 | encrypted: any; 1042 | cleartext: any; 1043 | } 1044 | 1045 | export function createServer(options: TlsOptions, secureConnectionListener?: (cleartextStream: ClearTextStream) =>void ): Server; 1046 | export function connect(options: TlsOptions, secureConnectionListener?: () =>void ): ClearTextStream; 1047 | export function connect(port: number, host?: string, options?: ConnectionOptions, secureConnectListener?: () =>void ): ClearTextStream; 1048 | export function connect(port: number, options?: ConnectionOptions, secureConnectListener?: () =>void ): ClearTextStream; 1049 | export function createSecurePair(credentials?: crypto.Credentials, isServer?: boolean, requestCert?: boolean, rejectUnauthorized?: boolean): SecurePair; 1050 | } 1051 | 1052 | declare module "crypto" { 1053 | export interface CredentialDetails { 1054 | pfx: string; 1055 | key: string; 1056 | passphrase: string; 1057 | cert: string; 1058 | ca: any; //string | string array 1059 | crl: any; //string | string array 1060 | ciphers: string; 1061 | } 1062 | export interface Credentials { context?: any; } 1063 | export function createCredentials(details: CredentialDetails): Credentials; 1064 | export function createHash(algorithm: string): Hash; 1065 | export function createHmac(algorithm: string, key: string): Hmac; 1066 | export function createHmac(algorithm: string, key: Buffer): Hmac; 1067 | interface Hash { 1068 | update(data: any, input_encoding?: string): Hash; 1069 | digest(encoding: 'buffer'): Buffer; 1070 | digest(encoding: string): any; 1071 | digest(): Buffer; 1072 | } 1073 | interface Hmac { 1074 | update(data: any, input_encoding?: string): Hmac; 1075 | digest(encoding: 'buffer'): Buffer; 1076 | digest(encoding: string): any; 1077 | digest(): Buffer; 1078 | } 1079 | export function createCipher(algorithm: string, password: any): Cipher; 1080 | export function createCipheriv(algorithm: string, key: any, iv: any): Cipher; 1081 | interface Cipher { 1082 | update(data: Buffer): Buffer; 1083 | update(data: string, input_encoding?: string, output_encoding?: string): string; 1084 | final(): Buffer; 1085 | final(output_encoding: string): string; 1086 | setAutoPadding(auto_padding: boolean): void; 1087 | } 1088 | export function createDecipher(algorithm: string, password: any): Decipher; 1089 | export function createDecipheriv(algorithm: string, key: any, iv: any): Decipher; 1090 | interface Decipher { 1091 | update(data: Buffer): Buffer; 1092 | update(data: string, input_encoding?: string, output_encoding?: string): string; 1093 | final(): Buffer; 1094 | final(output_encoding: string): string; 1095 | setAutoPadding(auto_padding: boolean): void; 1096 | } 1097 | export function createSign(algorithm: string): Signer; 1098 | interface Signer { 1099 | update(data: any): void; 1100 | sign(private_key: string, output_format: string): string; 1101 | } 1102 | export function createVerify(algorith: string): Verify; 1103 | interface Verify { 1104 | update(data: any): void; 1105 | verify(object: string, signature: string, signature_format?: string): boolean; 1106 | } 1107 | export function createDiffieHellman(prime_length: number): DiffieHellman; 1108 | export function createDiffieHellman(prime: number, encoding?: string): DiffieHellman; 1109 | interface DiffieHellman { 1110 | generateKeys(encoding?: string): string; 1111 | computeSecret(other_public_key: string, input_encoding?: string, output_encoding?: string): string; 1112 | getPrime(encoding?: string): string; 1113 | getGenerator(encoding: string): string; 1114 | getPublicKey(encoding?: string): string; 1115 | getPrivateKey(encoding?: string): string; 1116 | setPublicKey(public_key: string, encoding?: string): void; 1117 | setPrivateKey(public_key: string, encoding?: string): void; 1118 | } 1119 | export function getDiffieHellman(group_name: string): DiffieHellman; 1120 | export function pbkdf2(password: string, salt: string, iterations: number, keylen: number, callback: (err: Error, derivedKey: Buffer) => any): void; 1121 | export function pbkdf2Sync(password: string, salt: string, iterations: number, keylen: number) : Buffer; 1122 | export function randomBytes(size: number): Buffer; 1123 | export function randomBytes(size: number, callback: (err: Error, buf: Buffer) =>void ): void; 1124 | export function pseudoRandomBytes(size: number): Buffer; 1125 | export function pseudoRandomBytes(size: number, callback: (err: Error, buf: Buffer) =>void ): void; 1126 | } 1127 | 1128 | declare module "stream" { 1129 | import events = require("events"); 1130 | 1131 | export interface Stream extends events.EventEmitter { 1132 | pipe(destination: T, options?: { end?: boolean; }): T; 1133 | } 1134 | 1135 | export interface ReadableOptions { 1136 | highWaterMark?: number; 1137 | encoding?: string; 1138 | objectMode?: boolean; 1139 | } 1140 | 1141 | export class Readable extends events.EventEmitter implements NodeJS.ReadableStream { 1142 | readable: boolean; 1143 | constructor(opts?: ReadableOptions); 1144 | _read(size: number): void; 1145 | read(size?: number): any; 1146 | setEncoding(encoding: string): void; 1147 | pause(): void; 1148 | resume(): void; 1149 | pipe(destination: T, options?: { end?: boolean; }): T; 1150 | unpipe(destination?: T): void; 1151 | unshift(chunk: string): void; 1152 | unshift(chunk: Buffer): void; 1153 | wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream; 1154 | push(chunk: any, encoding?: string): boolean; 1155 | } 1156 | 1157 | export interface WritableOptions { 1158 | highWaterMark?: number; 1159 | decodeStrings?: boolean; 1160 | } 1161 | 1162 | export class Writable extends events.EventEmitter implements NodeJS.WritableStream { 1163 | writable: boolean; 1164 | constructor(opts?: WritableOptions); 1165 | _write(data: Buffer, encoding: string, callback: Function): void; 1166 | _write(data: string, encoding: string, callback: Function): void; 1167 | write(buffer: Buffer, cb?: Function): boolean; 1168 | write(str: string, cb?: Function): boolean; 1169 | write(str: string, encoding?: string, cb?: Function): boolean; 1170 | end(): void; 1171 | end(buffer: Buffer, cb?: Function): void; 1172 | end(str: string, cb?: Function): void; 1173 | end(str: string, encoding?: string, cb?: Function): void; 1174 | } 1175 | 1176 | export interface DuplexOptions extends ReadableOptions, WritableOptions { 1177 | allowHalfOpen?: boolean; 1178 | } 1179 | 1180 | // Note: Duplex extends both Readable and Writable. 1181 | export class Duplex extends Readable implements NodeJS.ReadWriteStream { 1182 | writable: boolean; 1183 | constructor(opts?: DuplexOptions); 1184 | _write(data: Buffer, encoding: string, callback: Function): void; 1185 | _write(data: string, encoding: string, callback: Function): void; 1186 | write(buffer: Buffer, cb?: Function): boolean; 1187 | write(str: string, cb?: Function): boolean; 1188 | write(str: string, encoding?: string, cb?: Function): boolean; 1189 | end(): void; 1190 | end(buffer: Buffer, cb?: Function): void; 1191 | end(str: string, cb?: Function): void; 1192 | end(str: string, encoding?: string, cb?: Function): void; 1193 | } 1194 | 1195 | export interface TransformOptions extends ReadableOptions, WritableOptions {} 1196 | 1197 | // Note: Transform lacks the _read and _write methods of Readable/Writable. 1198 | export class Transform extends events.EventEmitter implements NodeJS.ReadWriteStream { 1199 | readable: boolean; 1200 | writable: boolean; 1201 | constructor(opts?: TransformOptions); 1202 | _transform(chunk: Buffer, encoding: string, callback: Function): void; 1203 | _transform(chunk: string, encoding: string, callback: Function): void; 1204 | _flush(callback: Function): void; 1205 | read(size?: number): any; 1206 | setEncoding(encoding: string): void; 1207 | pause(): void; 1208 | resume(): void; 1209 | pipe(destination: T, options?: { end?: boolean; }): T; 1210 | unpipe(destination?: T): void; 1211 | unshift(chunk: string): void; 1212 | unshift(chunk: Buffer): void; 1213 | wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream; 1214 | push(chunk: any, encoding?: string): boolean; 1215 | write(buffer: Buffer, cb?: Function): boolean; 1216 | write(str: string, cb?: Function): boolean; 1217 | write(str: string, encoding?: string, cb?: Function): boolean; 1218 | end(): void; 1219 | end(buffer: Buffer, cb?: Function): void; 1220 | end(str: string, cb?: Function): void; 1221 | end(str: string, encoding?: string, cb?: Function): void; 1222 | } 1223 | 1224 | export class PassThrough extends Transform {} 1225 | } 1226 | 1227 | declare module "util" { 1228 | export interface InspectOptions { 1229 | showHidden?: boolean; 1230 | depth?: number; 1231 | colors?: boolean; 1232 | customInspect?: boolean; 1233 | } 1234 | 1235 | export function format(format: any, ...param: any[]): string; 1236 | export function debug(string: string): void; 1237 | export function error(...param: any[]): void; 1238 | export function puts(...param: any[]): void; 1239 | export function print(...param: any[]): void; 1240 | export function log(string: string): void; 1241 | export function inspect(object: any, showHidden?: boolean, depth?: number, color?: boolean): string; 1242 | export function inspect(object: any, options: InspectOptions): string; 1243 | export function isArray(object: any): boolean; 1244 | export function isRegExp(object: any): boolean; 1245 | export function isDate(object: any): boolean; 1246 | export function isError(object: any): boolean; 1247 | export function inherits(constructor: any, superConstructor: any): void; 1248 | } 1249 | 1250 | declare module "assert" { 1251 | function internal (value: any, message?: string): void; 1252 | module internal { 1253 | export class AssertionError implements Error { 1254 | name: string; 1255 | message: string; 1256 | actual: any; 1257 | expected: any; 1258 | operator: string; 1259 | generatedMessage: boolean; 1260 | 1261 | constructor(options?: {message?: string; actual?: any; expected?: any; 1262 | operator?: string; stackStartFunction?: Function}); 1263 | } 1264 | 1265 | export function fail(actual?: any, expected?: any, message?: string, operator?: string): void; 1266 | export function ok(value: any, message?: string): void; 1267 | export function equal(actual: any, expected: any, message?: string): void; 1268 | export function notEqual(actual: any, expected: any, message?: string): void; 1269 | export function deepEqual(actual: any, expected: any, message?: string): void; 1270 | export function notDeepEqual(acutal: any, expected: any, message?: string): void; 1271 | export function strictEqual(actual: any, expected: any, message?: string): void; 1272 | export function notStrictEqual(actual: any, expected: any, message?: string): void; 1273 | export var throws: { 1274 | (block: Function, message?: string): void; 1275 | (block: Function, error: Function, message?: string): void; 1276 | (block: Function, error: RegExp, message?: string): void; 1277 | (block: Function, error: (err: any) => boolean, message?: string): void; 1278 | }; 1279 | 1280 | export var doesNotThrow: { 1281 | (block: Function, message?: string): void; 1282 | (block: Function, error: Function, message?: string): void; 1283 | (block: Function, error: RegExp, message?: string): void; 1284 | (block: Function, error: (err: any) => boolean, message?: string): void; 1285 | }; 1286 | 1287 | export function ifError(value: any): void; 1288 | } 1289 | 1290 | export = internal; 1291 | } 1292 | 1293 | declare module "tty" { 1294 | import net = require("net"); 1295 | 1296 | export function isatty(fd: number): boolean; 1297 | export interface ReadStream extends net.Socket { 1298 | isRaw: boolean; 1299 | setRawMode(mode: boolean): void; 1300 | } 1301 | export interface WriteStream extends net.Socket { 1302 | columns: number; 1303 | rows: number; 1304 | } 1305 | } 1306 | 1307 | declare module "domain" { 1308 | import events = require("events"); 1309 | 1310 | export class Domain extends events.EventEmitter { 1311 | run(fn: Function): void; 1312 | add(emitter: events.EventEmitter): void; 1313 | remove(emitter: events.EventEmitter): void; 1314 | bind(cb: (err: Error, data: any) => any): any; 1315 | intercept(cb: (data: any) => any): any; 1316 | dispose(): void; 1317 | 1318 | addListener(event: string, listener: Function): Domain; 1319 | on(event: string, listener: Function): Domain; 1320 | once(event: string, listener: Function): Domain; 1321 | removeListener(event: string, listener: Function): Domain; 1322 | removeAllListeners(event?: string): Domain; 1323 | } 1324 | 1325 | export function create(): Domain; 1326 | } 1327 | -------------------------------------------------------------------------------- /typings/tsd.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | --------------------------------------------------------------------------------