├── .gitignore ├── .vscode └── settings.json ├── LICENSE ├── README.md ├── core.ts ├── gulpfile.js ├── package.json ├── src ├── Errors.ts ├── Positioning.ts ├── X12Diagnostic.ts ├── X12Element.ts ├── X12FunctionalGroup.ts ├── X12Interchange.ts ├── X12Parser.ts ├── X12QueryEngine.ts ├── X12Segment.ts ├── X12SerializationOptions.ts └── X12Transaction.ts ├── tests ├── FormattingSuite.ts ├── ParserSuite.ts ├── QuerySuite.ts └── test-data │ ├── 850.edi │ ├── 850_2.edi │ ├── 850_3.edi │ └── 856.edi ├── tsconfig.json └── typings ├── mocha └── mocha.d.ts └── node └── node.d.ts /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 18 | .grunt 19 | 20 | # node-waf configuration 21 | .lock-wscript 22 | 23 | # Compiled binary addons (http://nodejs.org/api/addons.html) 24 | build/Release 25 | 26 | # Dependency directory 27 | node_modules 28 | 29 | # Optional npm cache directory 30 | .npm 31 | 32 | # Optional REPL history 33 | .node_repl_history 34 | 35 | # compiled typescript 36 | src/**/*.js 37 | tests/**/*.js 38 | core.js -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | // Place your settings in this file to overwrite default and user settings. 2 | { 3 | "files.exclude": { 4 | "**/.git": true, 5 | "**/.DS_Store": true, 6 | "**/*.js": { 7 | "when": "$(basename).ts" 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 TrueCommerce 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, 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, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | :exclamation: **NOTE: This project is no longer being maintained!** :exclamation: 2 | 3 | # X12 4 | A simple ASC X12 parser for NodeJS. Created originally for the [TC Toolbox](https://github.com/TrueCommerce/vscode-tctoolbox) project. 5 | 6 | ## Usage 7 | ```typescript 8 | 'use strict'; 9 | 10 | import { X12Parser, X12QueryEngine } from 'x12/core'; 11 | 12 | // parse (deserialize) X12 EDI 13 | let parser = new X12Parser(true); 14 | let interchange = parser.parseX12('...raw X12 data...'); 15 | 16 | // OR use the query engine to query a document 17 | // Syntax Documentation: https://github.com/TrueCommerce/node-x12/wiki/x12queryengine-api#element-reference-syntax 18 | let engine = new X12QueryEngine(parser); 19 | let results = engine.query('REF02:REF01["IA"]'); 20 | 21 | results.forEach((result) => { 22 | // do something with each result 23 | 24 | // result.interchange 25 | // result.functionalGroup 26 | // result.transaction 27 | // result.segment 28 | // result.element(.value) 29 | }); 30 | ``` 31 | -------------------------------------------------------------------------------- /core.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | export * from './src/X12Element'; 4 | export * from './src/X12FunctionalGroup'; 5 | export * from './src/X12Interchange'; 6 | export * from './src/X12Parser'; 7 | export * from './src/X12Segment'; 8 | export * from './src/X12Transaction'; 9 | export * from './src/X12QueryEngine'; 10 | export * from './src/X12SerializationOptions'; -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'); 2 | var shell = require('gulp-shell'); 3 | var mocha = require('gulp-mocha'); 4 | 5 | gulp.task('compile', shell.task([ 6 | 'tsc' 7 | ])); 8 | 9 | gulp.task('test', ['compile'], function () { 10 | gulp.src('tests/*.js', { read: false }).pipe(mocha()); 11 | }); -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "x12", 3 | 4 | "version": "1.0.4", 5 | 6 | "description": "A simple ASC X12 parser for NodeJS.", 7 | 8 | "keywords": [ 9 | "x12", 10 | "edi", 11 | "ansi", 12 | "asc" 13 | ], 14 | 15 | "homepage": "https://github.com/TrueCommerce/node-x12", 16 | 17 | "bugs": { 18 | "url": "https://github.com/TrueCommerce/node-x12/wiki" 19 | }, 20 | 21 | "license": "MIT", 22 | 23 | "author": { 24 | "name": "TrueCommerce PSG Engineering Team", 25 | "url": "http://www.truecommerce.com" 26 | }, 27 | 28 | "repository": { 29 | "type": "git", 30 | "url": "https://github.com/TrueCommerce/node-x12.git" 31 | }, 32 | 33 | "scripts": { 34 | }, 35 | 36 | "dependencies": { 37 | 38 | }, 39 | 40 | "devDependencies": { 41 | "gulp": "^3.9.1", 42 | "gulp-mocha": "^2.2.0", 43 | "gulp-shell": "^0.5.2", 44 | "mocha": "^2.4.5", 45 | "typescript": "^1.8.7" 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Errors.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | export class ArgumentNullError implements Error { 4 | constructor(argumentName: string) { 5 | this.name = 'ArgumentNullError'; 6 | this.message = `The argument, '${argumentName}', cannot be null.`; 7 | } 8 | 9 | name: string; 10 | message: string; 11 | } 12 | 13 | export class ParserError implements Error { 14 | constructor(message?: string) { 15 | this.name = 'ParserError'; 16 | this.message = message; 17 | } 18 | 19 | name: string; 20 | message: string; 21 | } 22 | 23 | export class QuerySyntaxError implements Error { 24 | constructor(message?: string) { 25 | this.name = 'QuerySyntaxError'; 26 | this.message = message; 27 | } 28 | 29 | name: string; 30 | message: string; 31 | } -------------------------------------------------------------------------------- /src/Positioning.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | export class Position { 4 | constructor(line?: number, character?: number) { 5 | if (typeof line === 'number' && typeof character === 'number') { 6 | this.line = line; 7 | this.character = character; 8 | } 9 | } 10 | 11 | line: number; 12 | character: number; 13 | } 14 | 15 | export class Range { 16 | constructor(startLine?: number, startChar?: number, endLine?: number, endChar?: number) { 17 | if (typeof startLine === 'number' && typeof startChar === 'number' && typeof endLine === 'number' && typeof endChar === 'number') { 18 | this.start = new Position(startLine, startChar); 19 | this.end = new Position(endLine, endChar); 20 | } 21 | } 22 | 23 | start: Position; 24 | end: Position; 25 | } -------------------------------------------------------------------------------- /src/X12Diagnostic.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import { Range } from './Positioning'; 4 | 5 | export class X12Diagnostic { 6 | constructor(level?: X12DiagnosticLevel, message?: string, range?: Range) { 7 | this.level = level || X12DiagnosticLevel.Error; 8 | this.message = message || ''; 9 | this.range = range; 10 | } 11 | 12 | level: X12DiagnosticLevel; 13 | message: string; 14 | range: Range; 15 | } 16 | 17 | export enum X12DiagnosticLevel { 18 | Info = 0, 19 | Warning = 1, 20 | Error = 2 21 | } -------------------------------------------------------------------------------- /src/X12Element.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import { Range } from './Positioning'; 4 | import { X12Segment } from './X12Segment'; 5 | 6 | export class X12Element { 7 | constructor() { 8 | this.range = new Range(); 9 | this.value = ''; 10 | } 11 | 12 | range: Range; 13 | value: string; 14 | } -------------------------------------------------------------------------------- /src/X12FunctionalGroup.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import { Range } from './Positioning'; 4 | import { X12Interchange } from './X12Interchange'; 5 | import { X12Segment } from './X12Segment'; 6 | import { X12Transaction } from './X12Transaction'; 7 | import { defaultSerializationOptions, X12SerializationOptions } from './X12SerializationOptions'; 8 | 9 | export class X12FunctionalGroup { 10 | constructor() { 11 | this.transactions = new Array(); 12 | } 13 | 14 | header: X12Segment; 15 | trailer: X12Segment; 16 | 17 | transactions: X12Transaction[]; 18 | 19 | toString(options?: X12SerializationOptions): string { 20 | options = defaultSerializationOptions(options); 21 | 22 | let edi = this.header.toString(options); 23 | 24 | if (options.format) { 25 | edi += options.endOfLine; 26 | } 27 | 28 | for (let i = 0; i < this.transactions.length; i++) { 29 | edi += this.transactions[i].toString(options); 30 | 31 | if (options.format) { 32 | edi += options.endOfLine; 33 | } 34 | } 35 | 36 | edi += this.trailer.toString(options); 37 | 38 | return edi; 39 | } 40 | } -------------------------------------------------------------------------------- /src/X12Interchange.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import { Range } from './Positioning'; 4 | import { X12FunctionalGroup } from './X12FunctionalGroup'; 5 | import { X12Segment } from './X12Segment'; 6 | import { defaultSerializationOptions, X12SerializationOptions } from './X12SerializationOptions'; 7 | 8 | export class X12Interchange { 9 | constructor(segmentTerminator: string, elementDelimiter: string) { 10 | this.functionalGroups = new Array(); 11 | this.segmentTerminator = segmentTerminator; 12 | this.elementDelimiter = elementDelimiter; 13 | } 14 | 15 | header: X12Segment; 16 | trailer: X12Segment; 17 | 18 | functionalGroups: X12FunctionalGroup[]; 19 | 20 | segmentTerminator: string; 21 | elementDelimiter: string; 22 | 23 | toString(options?: X12SerializationOptions): string { 24 | options = defaultSerializationOptions(options); 25 | 26 | let edi = this.header.toString(options); 27 | 28 | if (options.format) { 29 | edi += options.endOfLine; 30 | } 31 | 32 | for (let i = 0; i < this.functionalGroups.length; i++) { 33 | edi += this.functionalGroups[i].toString(options); 34 | 35 | if (options.format) { 36 | edi += options.endOfLine; 37 | } 38 | } 39 | 40 | edi += this.trailer.toString(options); 41 | 42 | return edi; 43 | } 44 | 45 | private _padRight(input: string, width: number): string { 46 | while (input.length < width) { 47 | input += ' '; 48 | } 49 | 50 | return input.substr(0, width); 51 | } 52 | } -------------------------------------------------------------------------------- /src/X12Parser.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import { ArgumentNullError, ParserError } from './Errors'; 4 | import { Range, Position } from './Positioning'; 5 | import { X12Diagnostic, X12DiagnosticLevel } from './X12Diagnostic'; 6 | import { X12Interchange } from './X12Interchange'; 7 | import { X12FunctionalGroup } from './X12FunctionalGroup'; 8 | import { X12Transaction } from './X12Transaction'; 9 | import { X12Segment } from './X12Segment'; 10 | import { X12Element } from './X12Element'; 11 | 12 | const DOCUMENT_MIN_LENGTH: number = 113; // ISA = 106, IEA > 7 13 | const SEGMENT_TERMINATOR_POS: number = 105; 14 | const ELEMENT_DELIMITER_POS: number = 3; 15 | const INTERCHANGE_CACHE_SIZE: number = 10; 16 | 17 | export class X12Parser { 18 | constructor(private _strict: boolean) { 19 | this.diagnostics = new Array(); 20 | } 21 | 22 | diagnostics: X12Diagnostic[]; 23 | 24 | parseX12(edi: string): X12Interchange { 25 | if (!edi) { 26 | throw new ArgumentNullError('edi'); 27 | } 28 | 29 | this.diagnostics.splice(0); 30 | 31 | if (edi.length < DOCUMENT_MIN_LENGTH) { 32 | let errorMessage = `X12 Standard: Document is too short. Document must be at least ${DOCUMENT_MIN_LENGTH} characters long to be well-formed X12.`; 33 | 34 | if (this._strict) { 35 | throw new ParserError(errorMessage); 36 | } 37 | 38 | this.diagnostics.push(new X12Diagnostic(X12DiagnosticLevel.Error, errorMessage, new Range(0, 0, 0, edi.length - 1))); 39 | } 40 | 41 | let segmentTerminator = edi.charAt(SEGMENT_TERMINATOR_POS); 42 | let elementDelimiter = edi.charAt(ELEMENT_DELIMITER_POS); 43 | 44 | if (edi.charAt(103) !== elementDelimiter) { 45 | let errorMessage = 'X12 Standard: The ISA segment is not the correct length (106 characters, including segment terminator).'; 46 | 47 | if (this._strict) { 48 | throw new ParserError(errorMessage); 49 | } 50 | 51 | this.diagnostics.push(new X12Diagnostic(X12DiagnosticLevel.Error, errorMessage, new Range(0, 0, 0, 2))); 52 | } 53 | 54 | let interchange = new X12Interchange(segmentTerminator, elementDelimiter); 55 | let group: X12FunctionalGroup; 56 | let transaction: X12Transaction; 57 | 58 | let segments = this._parseSegments(edi, segmentTerminator, elementDelimiter); 59 | 60 | segments.forEach((seg) => { 61 | if (seg.tag == 'ISA') { 62 | this._processISA(interchange, seg); 63 | } 64 | 65 | else if (seg.tag == 'IEA') { 66 | this._processIEA(interchange, seg); 67 | } 68 | 69 | else if (seg.tag == 'GS') { 70 | group = new X12FunctionalGroup(); 71 | 72 | this._processGS(group, seg); 73 | interchange.functionalGroups.push(group); 74 | } 75 | 76 | else if (seg.tag == 'GE') { 77 | if (!group) { 78 | let errorMessage = 'X12 Standard: Missing GS segment!'; 79 | 80 | if (this._strict) { 81 | throw new ParserError(errorMessage); 82 | } 83 | 84 | this.diagnostics.push(new X12Diagnostic(X12DiagnosticLevel.Error, errorMessage, seg.range)); 85 | } 86 | 87 | this._processGE(group, seg); 88 | group = null; 89 | } 90 | 91 | else if (seg.tag == 'ST') { 92 | if (!group) { 93 | let errorMessage = `X12 Standard: ${seg.tag} segment cannot appear outside of a functional group.`; 94 | 95 | if (this._strict) { 96 | throw new ParserError(errorMessage); 97 | } 98 | 99 | this.diagnostics.push(new X12Diagnostic(X12DiagnosticLevel.Error, errorMessage, seg.range)); 100 | } 101 | 102 | transaction = new X12Transaction(); 103 | 104 | this._processST(transaction, seg); 105 | group.transactions.push(transaction); 106 | } 107 | 108 | else if (seg.tag == 'SE') { 109 | if (!group) { 110 | let errorMessage = `X12 Standard: ${seg.tag} segment cannot appear outside of a functional group.`; 111 | 112 | if (this._strict) { 113 | throw new ParserError(errorMessage); 114 | } 115 | 116 | this.diagnostics.push(new X12Diagnostic(X12DiagnosticLevel.Error, errorMessage, seg.range)); 117 | } 118 | 119 | if (!transaction) { 120 | let errorMessage = 'X12 Standard: Missing ST segment!'; 121 | 122 | if (this._strict) { 123 | throw new ParserError(errorMessage); 124 | } 125 | 126 | this.diagnostics.push(new X12Diagnostic(X12DiagnosticLevel.Error, errorMessage, seg.range)); 127 | } 128 | 129 | this._processSE(transaction, seg); 130 | transaction = null; 131 | } 132 | 133 | else { 134 | if (!group) { 135 | let errorMessage = `X12 Standard: ${seg.tag} segment cannot appear outside of a functional group.`; 136 | 137 | if (this._strict) { 138 | throw new ParserError(errorMessage); 139 | } 140 | 141 | this.diagnostics.push(new X12Diagnostic(X12DiagnosticLevel.Error, errorMessage, seg.range)); 142 | } 143 | 144 | if (!transaction) { 145 | let errorMessage = `X12 Standard: ${seg.tag} segment cannot appear outside of a transaction.`; 146 | 147 | if (this._strict) { 148 | throw new ParserError(errorMessage); 149 | } 150 | 151 | this.diagnostics.push(new X12Diagnostic(X12DiagnosticLevel.Error, errorMessage, seg.range)); 152 | } 153 | 154 | else { 155 | transaction.segments.push(seg); 156 | } 157 | } 158 | }); 159 | 160 | return interchange; 161 | } 162 | 163 | private _parseSegments(edi: string, segmentTerminator: string, elementDelimiter: string): X12Segment[] { 164 | let segments = new Array(); 165 | 166 | let tagged = false; 167 | let currentSegment: X12Segment; 168 | let currentElement: X12Element; 169 | 170 | currentSegment = new X12Segment(); 171 | 172 | for (let i = 0, l = 0, c = 0; i < edi.length; i++) { 173 | // segment not yet named and not whitespace or delimiter - begin naming segment 174 | if (!tagged && (edi[i].search(/\s/) == -1) && (edi[i] !== elementDelimiter) && (edi[i] !== segmentTerminator)) { 175 | currentSegment.tag += edi[i]; 176 | 177 | if (!currentSegment.range.start) { 178 | currentSegment.range.start = new Position(l, c); 179 | } 180 | } 181 | 182 | // trailing line breaks - consume them and increment line number 183 | else if (!tagged && (edi[i].search(/\s/) > -1)) { 184 | if (edi[i] == '\n') { 185 | l++; 186 | c = -1; 187 | } 188 | } 189 | 190 | // segment tag/name is completed - mark as tagged 191 | else if (!tagged && (edi[i] == elementDelimiter)) { 192 | tagged = true; 193 | 194 | currentElement = new X12Element(); 195 | currentElement.range.start = new Position(l, c); 196 | } 197 | 198 | // segment terminator 199 | else if (edi[i] == segmentTerminator) { 200 | currentElement.range.end = new Position(l, (c - 1)); 201 | currentSegment.elements.push(currentElement); 202 | currentSegment.range.end = new Position(l, c); 203 | 204 | segments.push(currentSegment); 205 | 206 | currentSegment = new X12Segment(); 207 | tagged = false; 208 | 209 | if (segmentTerminator === '\n') { 210 | l++; 211 | c = -1; 212 | } 213 | } 214 | 215 | // element delimiter 216 | else if (tagged && (edi[i] == elementDelimiter)) { 217 | currentElement.range.end = new Position(l, (c - 1)); 218 | currentSegment.elements.push(currentElement); 219 | 220 | currentElement = new X12Element(); 221 | currentElement.range.start = new Position(l, c + 1); 222 | } 223 | 224 | // element data 225 | else { 226 | currentElement.value += edi[i]; 227 | } 228 | 229 | c++; 230 | } 231 | 232 | return segments; 233 | } 234 | 235 | private _processISA(interchange: X12Interchange, segment: X12Segment): void { 236 | interchange.header = segment; 237 | } 238 | 239 | private _processIEA(interchange: X12Interchange, segment: X12Segment): void { 240 | interchange.trailer = segment; 241 | 242 | if (parseInt(segment.valueOf(1)) !== interchange.functionalGroups.length) { 243 | let errorMessage = `X12 Standard: The value in IEA01 (${segment.valueOf(1)}) does not match the number of GS segments in the interchange (${interchange.functionalGroups.length}).`; 244 | 245 | if (this._strict) { 246 | throw new ParserError(errorMessage); 247 | } 248 | 249 | this.diagnostics.push(new X12Diagnostic(X12DiagnosticLevel.Error, errorMessage, segment.elements[0].range)); 250 | } 251 | 252 | if (segment.valueOf(2) !== interchange.header.valueOf(13)) { 253 | let errorMessage = `X12 Standard: The value in IEA02 (${segment.valueOf(2)}) does not match the value in ISA13 (${interchange.header.valueOf(13)}).`; 254 | 255 | if (this._strict) { 256 | throw new ParserError(errorMessage); 257 | } 258 | 259 | this.diagnostics.push(new X12Diagnostic(X12DiagnosticLevel.Error, errorMessage, segment.elements[1].range)); 260 | } 261 | } 262 | 263 | private _processGS(group: X12FunctionalGroup, segment: X12Segment): void { 264 | group.header = segment; 265 | } 266 | 267 | private _processGE(group: X12FunctionalGroup, segment: X12Segment): void { 268 | group.trailer = segment; 269 | 270 | if (parseInt(segment.valueOf(1)) !== group.transactions.length) { 271 | let errorMessage = `X12 Standard: The value in GE01 (${segment.valueOf(1)}) does not match the number of ST segments in the functional group (${group.transactions.length}).`; 272 | 273 | if (this._strict) { 274 | throw new ParserError(errorMessage); 275 | } 276 | 277 | this.diagnostics.push(new X12Diagnostic(X12DiagnosticLevel.Error, errorMessage, segment.elements[0].range)); 278 | } 279 | 280 | if (segment.valueOf(2) !== group.header.valueOf(6)) { 281 | let errorMessage = `X12 Standard: The value in GE02 (${segment.valueOf(2)}) does not match the value in GS06 (${group.header.valueOf(6)}).`; 282 | 283 | if (this._strict) { 284 | throw new ParserError(errorMessage); 285 | } 286 | 287 | this.diagnostics.push(new X12Diagnostic(X12DiagnosticLevel.Error, errorMessage, segment.elements[1].range)); 288 | } 289 | } 290 | 291 | private _processST(transaction: X12Transaction, segment: X12Segment): void { 292 | transaction.header = segment; 293 | } 294 | 295 | private _processSE(transaction: X12Transaction, segment: X12Segment): void { 296 | transaction.trailer = segment; 297 | 298 | let expectedNumberOfSegments = (transaction.segments.length + 2); 299 | 300 | if (parseInt(segment.valueOf(1)) !== expectedNumberOfSegments) { 301 | let errorMessage = `X12 Standard: The value in SE01 (${segment.valueOf(1)}) does not match the number of segments in the transaction (${expectedNumberOfSegments}).`; 302 | 303 | if (this._strict) { 304 | throw new ParserError(errorMessage); 305 | } 306 | 307 | this.diagnostics.push(new X12Diagnostic(X12DiagnosticLevel.Error, errorMessage, segment.elements[0].range)); 308 | } 309 | 310 | if (segment.valueOf(2) !== transaction.header.valueOf(2)) { 311 | let errorMessage = `X12 Standard: The value in SE02 (${segment.valueOf(2)}) does not match the value in ST02 (${transaction.header.valueOf(2)}).`; 312 | 313 | if (this._strict) { 314 | throw new ParserError(errorMessage); 315 | } 316 | 317 | this.diagnostics.push(new X12Diagnostic(X12DiagnosticLevel.Error, errorMessage, segment.elements[1].range)); 318 | } 319 | } 320 | } -------------------------------------------------------------------------------- /src/X12QueryEngine.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import { QuerySyntaxError } from './Errors'; 4 | import { X12Parser } from './X12Parser'; 5 | import { X12Interchange } from './X12Interchange'; 6 | import { X12FunctionalGroup } from './X12FunctionalGroup'; 7 | import { X12Transaction } from './X12Transaction'; 8 | import { X12Segment } from './X12Segment'; 9 | import { X12Element } from './X12Element'; 10 | 11 | export class X12QueryEngine { 12 | constructor(private _parser: X12Parser) { } 13 | 14 | query(rawEdi: string, reference: string): X12QueryResult[] { 15 | let interchange = this._parser.parseX12(rawEdi); 16 | 17 | let hlPathMatch = reference.match(/HL\+(\w\+?)+[\+-]/g); // ex. HL+O+P+I 18 | let segPathMatch = reference.match(/([A-Z0-9]{2,3}-)+/g); // ex. PO1-N9- 19 | let elmRefMatch = reference.match(/[A-Z0-9]{2,3}[0-9]{2}[^\[]?/g); // ex. REF02; need to remove trailing ":" if exists 20 | let qualMatch = reference.match(/:[A-Za-z]{2,3}[0-9]{2,}\[\"[^\[\]\"\"]+\"\]/g); // ex. :REF01["PO"] 21 | 22 | let results = new Array(); 23 | 24 | for (let i = 0; i < interchange.functionalGroups.length; i++) { 25 | let group = interchange.functionalGroups[i]; 26 | 27 | for (let j = 0; j < group.transactions.length; j++) { 28 | let txn = group.transactions[j]; 29 | let segments = txn.segments; 30 | 31 | if (hlPathMatch) { 32 | segments = this._evaluateHLQueryPart(txn, hlPathMatch[0]); 33 | } 34 | 35 | if (segPathMatch) { 36 | segments = this._evaluateSegmentPathQueryPart(segments, segPathMatch[0]); 37 | } 38 | 39 | if (!elmRefMatch) { 40 | throw new QuerySyntaxError('Element reference queries must contain an element reference!'); 41 | } 42 | 43 | let txnResults = this._evaluateElementReferenceQueryPart(interchange, group, txn, [].concat(segments, [interchange.header, group.header, txn.header, txn.trailer, group.trailer, interchange.trailer]), elmRefMatch[0], qualMatch); 44 | 45 | txnResults.forEach((res) => { 46 | results.push(res); 47 | }); 48 | } 49 | } 50 | 51 | return results; 52 | } 53 | 54 | querySingle(rawEdi: string, reference: string): X12QueryResult { 55 | let results = this.query(rawEdi, reference); 56 | return (results.length == 0) ? null : results[0]; 57 | } 58 | 59 | private _evaluateHLQueryPart(transaction: X12Transaction, hlPath: string): X12Segment[] { 60 | let qualified = false; 61 | let pathParts = hlPath.replace('-', '').split('+').filter((value, index, array) => { return (value !== 'HL' && value !== '' && value !== null); }) 62 | let matches = new Array(); 63 | 64 | let lastParentIndex = -1; 65 | 66 | for (let i = 0, j = 0; i < transaction.segments.length; i++) { 67 | let segment = transaction.segments[i]; 68 | 69 | if (qualified && segment.tag === 'HL') { 70 | let parentIndex = parseInt(segment.valueOf(2, '-1')); 71 | 72 | if (parentIndex !== lastParentIndex) { 73 | j = 0; 74 | qualified = false; 75 | } 76 | } 77 | 78 | if (!qualified && transaction.segments[i].tag === 'HL' && transaction.segments[i].valueOf(3) == pathParts[j]) { 79 | lastParentIndex = parseInt(segment.valueOf(2, '-1')); 80 | j++; 81 | 82 | if (j == pathParts.length) { 83 | qualified = true; 84 | } 85 | } 86 | 87 | if (qualified) { 88 | matches.push(transaction.segments[i]); 89 | } 90 | } 91 | 92 | return matches; 93 | } 94 | 95 | private _evaluateSegmentPathQueryPart(segments: X12Segment[], segmentPath: string): X12Segment[] { 96 | let qualified = false; 97 | let pathParts = segmentPath.split('-').filter((value, index, array) => { return !!value; }); 98 | let matches = new Array(); 99 | 100 | for (let i = 0, j = 0; i < segments.length; i++) { 101 | if (qualified && (segments[i].tag == 'HL' || pathParts.indexOf(segments[i].tag) > -1)) { 102 | j = 0; 103 | qualified = false; 104 | } 105 | 106 | if (!qualified && segments[i].tag == pathParts[j]) { 107 | j++; 108 | 109 | if (j == pathParts.length) { 110 | qualified = true; 111 | } 112 | } 113 | 114 | if (qualified) { 115 | matches.push(segments[i]); 116 | } 117 | } 118 | 119 | return matches; 120 | } 121 | 122 | private _evaluateElementReferenceQueryPart(interchange: X12Interchange, functionalGroup: X12FunctionalGroup, transaction: X12Transaction, segments: X12Segment[], elementReference: string, qualifiers: string[]): X12QueryResult[] { 123 | let reference = elementReference.replace(':', ''); 124 | let tag = reference.substr(0, reference.length - 2); 125 | let pos = reference.substr(reference.length - 2, 2); 126 | let posint = parseInt(pos); 127 | 128 | let results = new Array(); 129 | 130 | for (let i = 0; i < segments.length; i++) { 131 | let segment = segments[i]; 132 | 133 | if (!segment) { 134 | continue; 135 | } 136 | 137 | if (segment.tag !== tag) { 138 | continue; 139 | } 140 | 141 | let value = segment.valueOf(posint, null); 142 | 143 | if (value && this._testQualifiers(transaction, segment, qualifiers)) { 144 | results.push(new X12QueryResult(interchange, functionalGroup, transaction, segment, segment.elements[posint - 1])); 145 | } 146 | } 147 | 148 | return results; 149 | } 150 | 151 | private _testQualifiers(transaction: X12Transaction, segment: X12Segment, qualifiers: string[]): boolean { 152 | if (!qualifiers) { 153 | return true; 154 | } 155 | 156 | for (let i = 0 ; i < qualifiers.length; i++) { 157 | let qualifier = qualifiers[i].substr(1); 158 | let elementReference = qualifier.substring(0, qualifier.indexOf('[')); 159 | let elementValue = qualifier.substring(qualifier.indexOf('[') + 2, qualifier.lastIndexOf(']') - 1); 160 | let tag = elementReference.substr(0, elementReference.length - 2); 161 | let pos = elementReference.substr(elementReference.length - 2, 2); 162 | let posint = parseInt(pos); 163 | 164 | for (let j = transaction.segments.indexOf(segment); j > -1; j--) { 165 | let seg = transaction.segments[j]; 166 | let value = seg.valueOf(posint); 167 | 168 | if (seg.tag === tag && seg.tag === segment.tag && value !== elementValue) { 169 | return false; 170 | } 171 | 172 | else if (seg.tag === tag && value === elementValue) { 173 | break; 174 | } 175 | 176 | if (j == 0) { 177 | return false; 178 | } 179 | } 180 | } 181 | 182 | return true; 183 | } 184 | } 185 | 186 | export class X12QueryResult { 187 | constructor(interchange?: X12Interchange, functionalGroup?: X12FunctionalGroup, transaction?: X12Transaction, segment?: X12Segment, element?: X12Element) { 188 | this.interchange = interchange; 189 | this.functionalGroup = functionalGroup; 190 | this.transaction = transaction; 191 | this.segment = segment; 192 | this.element = element; 193 | } 194 | 195 | interchange: X12Interchange; 196 | functionalGroup: X12FunctionalGroup; 197 | transaction: X12Transaction; 198 | segment: X12Segment; 199 | element: X12Element; 200 | } -------------------------------------------------------------------------------- /src/X12Segment.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import { Range } from './Positioning'; 4 | import { X12Transaction } from './X12Transaction'; 5 | import { X12Element } from './X12Element'; 6 | import { defaultSerializationOptions, X12SerializationOptions } from './X12SerializationOptions'; 7 | 8 | export class X12Segment { 9 | constructor() { 10 | this.tag = ''; 11 | this.elements = new Array(); 12 | this.range = new Range(); 13 | } 14 | 15 | tag: string; 16 | elements: X12Element[]; 17 | range: Range; 18 | 19 | toString(options?: X12SerializationOptions): string { 20 | options = defaultSerializationOptions(options); 21 | 22 | let edi = this.tag; 23 | 24 | for (let i = 0; i < this.elements.length; i++) { 25 | edi += options.elementDelimiter; 26 | edi += this.elements[i].value; 27 | } 28 | 29 | edi += options.segmentTerminator; 30 | 31 | return edi; 32 | } 33 | 34 | valueOf(segmentPosition: number, defaultValue?: string): string { 35 | let index = segmentPosition - 1; 36 | 37 | if (this.elements.length <= index) { 38 | return defaultValue || null; 39 | } 40 | 41 | return this.elements[index].value || defaultValue || null; 42 | } 43 | } -------------------------------------------------------------------------------- /src/X12SerializationOptions.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | export interface X12SerializationOptions { 4 | elementDelimiter?: string; 5 | endOfLine?: string; 6 | format?: boolean; 7 | segmentTerminator?: string; 8 | } 9 | 10 | export function defaultSerializationOptions(options?: X12SerializationOptions): X12SerializationOptions { 11 | options = options || {}; 12 | 13 | options.elementDelimiter = options.elementDelimiter || '*'; 14 | options.endOfLine = options.endOfLine || '\n'; 15 | options.format = options.format || false; 16 | options.segmentTerminator = options.segmentTerminator || '~'; 17 | 18 | if (options.segmentTerminator === '\n') { 19 | options.endOfLine = ''; 20 | } 21 | 22 | return options; 23 | } -------------------------------------------------------------------------------- /src/X12Transaction.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import { Range } from './Positioning'; 4 | import { X12FunctionalGroup } from './X12FunctionalGroup'; 5 | import { X12Segment } from './X12Segment'; 6 | import { defaultSerializationOptions, X12SerializationOptions } from './X12SerializationOptions'; 7 | 8 | export class X12Transaction { 9 | constructor() { 10 | this.segments = new Array(); 11 | } 12 | 13 | header: X12Segment; 14 | trailer: X12Segment; 15 | 16 | segments: X12Segment[]; 17 | 18 | toString(options?: X12SerializationOptions): string { 19 | options = defaultSerializationOptions(options); 20 | 21 | let edi = this.header.toString(options); 22 | 23 | if (options.format) { 24 | edi += options.endOfLine; 25 | } 26 | 27 | for (let i = 0; i < this.segments.length; i++) { 28 | edi += this.segments[i].toString(options); 29 | 30 | if (options.format) { 31 | edi += options.endOfLine; 32 | } 33 | } 34 | 35 | edi += this.trailer.toString(options); 36 | 37 | return edi; 38 | } 39 | } -------------------------------------------------------------------------------- /tests/FormattingSuite.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import * as mocha from 'mocha'; 4 | import { X12Parser, X12Interchange, X12SerializationOptions } from '../core'; 5 | 6 | let fs = require('fs'); 7 | 8 | describe('X12Formatting', () => { 9 | 10 | it('should replicate the source data unless changes are made', () => { 11 | let edi = fs.readFileSync('tests/test-data/850.edi', 'utf8'); 12 | let parser = new X12Parser(true); 13 | let interchange = parser.parseX12(edi); 14 | 15 | let options: X12SerializationOptions = { 16 | format: true, 17 | endOfLine: '\r\n' 18 | }; 19 | 20 | let edi2 = interchange.toString(options); 21 | 22 | if (edi !== edi2) { 23 | throw new Error(`Formatted EDI does not match source. Found ${edi2}, expected ${edi}.`); 24 | } 25 | }); 26 | 27 | }); -------------------------------------------------------------------------------- /tests/ParserSuite.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import * as mocha from 'mocha'; 4 | import { X12Parser, X12Interchange, X12Segment } from '../core'; 5 | 6 | let fs = require('fs'); 7 | 8 | describe('X12Parser', () => { 9 | 10 | it('should parse a valid X12 document without throwing an error', () => { 11 | let edi = fs.readFileSync('tests/test-data/850.edi', 'utf8'); 12 | let parser = new X12Parser(true); 13 | parser.parseX12(edi); 14 | }); 15 | 16 | it('should produce accurate line numbers for files with line breaks', () => { 17 | let edi = fs.readFileSync('tests/test-data/850_3.edi', 'utf8'); 18 | let parser = new X12Parser(true); 19 | let interchange = parser.parseX12(edi); 20 | 21 | let segments = [].concat( 22 | [interchange.header, interchange.functionalGroups[0].header, interchange.functionalGroups[0].transactions[0].header], 23 | interchange.functionalGroups[0].transactions[0].segments, 24 | [interchange.functionalGroups[0].transactions[0].trailer, interchange.functionalGroups[0].trailer, interchange.trailer] 25 | ); 26 | 27 | for (let i = 0; i < segments.length; i++) { 28 | let segment: X12Segment = segments[i]; 29 | 30 | if (i !== segment.range.start.line) { 31 | throw new Error(`Segment line number incorrect. Expected ${i}, found ${segment.range.start.line}.`); 32 | } 33 | } 34 | }); 35 | 36 | }); -------------------------------------------------------------------------------- /tests/QuerySuite.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import * as mocha from 'mocha'; 4 | import { X12Parser, X12QueryEngine, X12Interchange } from '../core'; 5 | 6 | let fs = require('fs'); 7 | 8 | describe('X12QueryEngine', () => { 9 | 10 | it('should handle basic element references', () => { 11 | let edi = fs.readFileSync('tests/test-data/850.edi', 'utf8'); 12 | let parser = new X12Parser(true); 13 | let engine = new X12QueryEngine(parser); 14 | let results = engine.query(edi, 'REF02'); 15 | 16 | if (results.length !== 2) { 17 | throw new Error('Expected two matching elements for REF02.'); 18 | } 19 | }); 20 | 21 | it('should handle qualified element references', () => { 22 | let edi = fs.readFileSync('tests/test-data/850.edi', 'utf8'); 23 | let parser = new X12Parser(true); 24 | let engine = new X12QueryEngine(parser); 25 | let results = engine.query(edi, 'REF02:REF01["DP"]'); 26 | 27 | if (results.length !== 1) { 28 | throw new Error('Expected one matching element for REF02:REF01["DP"].'); 29 | } 30 | 31 | else if (results[0].element.value !== '038') { 32 | throw new Error('Expected REF02 to be "038".') 33 | } 34 | }); 35 | 36 | 37 | it('should handle segment path element references', () => { 38 | let edi = fs.readFileSync('tests/test-data/850.edi', 'utf8'); 39 | let parser = new X12Parser(true); 40 | let engine = new X12QueryEngine(parser); 41 | let results = engine.query(edi, 'PO1-PID05:PID01["F"]'); 42 | 43 | if (results.length !== 6) { 44 | throw new Error('Expected six matching elements for PO1-PID05:PID01["F"].'); 45 | } 46 | }); 47 | 48 | it('should handle HL path element references', () => { 49 | let edi = fs.readFileSync('tests/test-data/856.edi', 'utf8'); 50 | let parser = new X12Parser(true); 51 | let engine = new X12QueryEngine(parser); 52 | let results = engine.query(edi, 'HL+S+O+I-LIN03'); 53 | 54 | if (results.length !== 2) { 55 | throw new Error('Expected two matching elements for HL+S+O+I-LIN03.'); 56 | } 57 | }); 58 | 59 | it('should return valid range information for segments and elements', () => { 60 | let edi = fs.readFileSync('tests/test-data/850.edi', 'utf8'); 61 | let parser = new X12Parser(true); 62 | let engine = new X12QueryEngine(parser); 63 | let result = engine.querySingle(edi, 'BEG03'); 64 | 65 | if (result.segment.range.start.line !== 3) { 66 | throw new Error(`Start line for segment is incorrect; found ${result.segment.range.start.line}, expected 3.`); 67 | } 68 | 69 | if (result.segment.range.start.character !== 0) { 70 | throw new Error(`Start char for segment is incorrect; found ${result.segment.range.start.character}, expected 0.`); 71 | } 72 | 73 | if (result.element.range.start.line !== 3) { 74 | throw new Error(`Start line for element is incorrect; found ${result.element.range.start.line}, expected 3.`); 75 | } 76 | 77 | if (result.element.range.start.character !== 10) { 78 | throw new Error(`Start char for element is incorrect; found ${result.element.range.start.character}, expected 10.`); 79 | } 80 | 81 | if (result.segment.range.end.line !== 3) { 82 | throw new Error(`End line for segment is incorrect; found ${result.segment.range.end.line}, expected 3.`); 83 | } 84 | 85 | if (result.segment.range.end.character !== 41) { 86 | throw new Error(`End char for segment is incorrect; found ${result.segment.range.end.character}, expected 41.`); 87 | } 88 | 89 | if (result.element.range.end.line !== 3) { 90 | throw new Error(`End line for element is incorrect; found ${result.element.range.end.line}, expected 3.`); 91 | } 92 | 93 | if (result.element.range.end.character !== 20) { 94 | throw new Error(`End char for element is incorrect; found ${result.element.range.end.character}, expected 20.`); 95 | } 96 | }); 97 | 98 | it('should handle envelope queries', () => { 99 | let edi = fs.readFileSync('tests/test-data/850.edi', 'utf8'); 100 | let parser = new X12Parser(true); 101 | let engine = new X12QueryEngine(parser); 102 | let results = engine.query(edi, 'ISA06'); 103 | 104 | if (results.length === 1) { 105 | if (results[0].element.value.trim() !== '4405197800') { 106 | throw new Error(`Expected 4405197800, found ${results[0].element.value}.`); 107 | } 108 | } 109 | 110 | else { 111 | throw new Error(`Expected exactly one result. Found ${results.length}.`); 112 | } 113 | }); 114 | 115 | it('should handle queries for files with line feed segment terminators', () => { 116 | let edi = fs.readFileSync('tests/test-data/850_2.edi', 'utf8'); 117 | let parser = new X12Parser(true); 118 | let engine = new X12QueryEngine(parser); 119 | let results = engine.query(edi, 'REF02:REF01["DP"]'); 120 | 121 | if (results.length === 1) { 122 | if (results[0].element.value.trim() !== '038') { 123 | throw new Error(`Expected 038, found ${results[0].element.value}.`); 124 | } 125 | } 126 | 127 | else { 128 | throw new Error(`Expected exactly one result. Found ${results.length}.`); 129 | } 130 | }); 131 | 132 | it('should handle chained qualifiers', () => { 133 | let edi = fs.readFileSync('tests/test-data/850.edi', 'utf8'); 134 | let parser = new X12Parser(true); 135 | let engine = new X12QueryEngine(parser); 136 | let results = engine.query(edi, 'REF02:REF01["DP"]:BEG02["SA"]'); 137 | 138 | if (results.length === 1) { 139 | if (results[0].element.value.trim() !== '038') { 140 | throw new Error(`Expected 038, found ${results[0].element.value}.`); 141 | } 142 | } 143 | 144 | else { 145 | throw new Error(`Expected exactly one result. Found ${results.length}.`); 146 | } 147 | }); 148 | }); -------------------------------------------------------------------------------- /tests/test-data/850.edi: -------------------------------------------------------------------------------- 1 | ISA*01*0000000000*01*ABCCO *12*4405197800 *01*999999999 *101127*1719*U*00400*000003438*0*P*>~ 2 | GS*PO*4405197800*999999999*20101127*1719*1421*X*004010VICS~ 3 | ST*850*000000010~ 4 | BEG*00*SA*08292233294**20101127*610385385~ 5 | REF*DP*038~ 6 | REF*PS*R~ 7 | ITD*14*3*2**45**46~ 8 | DTM*002*20101214~ 9 | PKG*F*68***PALLETIZE SHIPMENT~ 10 | PKG*F*66***REGULAR~ 11 | TD5*A*92*P3**SEE XYZ RETAIL ROUTING GUIDE~ 12 | N1*ST*XYZ RETAIL*9*0003947268292~ 13 | N3*31875 SOLON RD~ 14 | N4*SOLON*OH*44139~ 15 | PO1*1*120*EA*9.25*TE*CB*065322-117*PR*RO*VN*AB3542~ 16 | PID*F****SMALL WIDGET~ 17 | PO4*4*4*EA*PLT94**3*LR*15*CT~ 18 | PO1*2*220*EA*13.79*TE*CB*066850-116*PR*RO*VN*RD5322~ 19 | PID*F****MEDIUM WIDGET~ 20 | PO4*2*2*EA~ 21 | PO1*3*126*EA*10.99*TE*CB*060733-110*PR*RO*VN*XY5266~ 22 | PID*F****LARGE WIDGET~ 23 | PO4*6*1*EA*PLT94**3*LR*12*CT~ 24 | PO1*4*76*EA*4.35*TE*CB*065308-116*PR*RO*VN*VX2332~ 25 | PID*F****NANO WIDGET~ 26 | PO4*4*4*EA*PLT94**6*LR*19*CT~ 27 | PO1*5*72*EA*7.5*TE*CB*065374-118*PR*RO*VN*RV0524~ 28 | PID*F****BLUE WIDGET~ 29 | PO4*4*4*EA~ 30 | PO1*6*696*EA*9.55*TE*CB*067504-118*PR*RO*VN*DX1875~ 31 | PID*F****ORANGE WIDGET~ 32 | PO4*6*6*EA*PLT94**3*LR*10*CT~ 33 | CTT*6~ 34 | AMT*1*13045.94~ 35 | SE*33*000000010~ 36 | GE*1*1421~ 37 | IEA*1*000003438~ -------------------------------------------------------------------------------- /tests/test-data/850_2.edi: -------------------------------------------------------------------------------- 1 | ISA*01*0000000000*01*ABCCO *12*4405197800 *01*999999999 *101127*1719*U*00400*000003438*0*P*> 2 | GS*PO*4405197800*999999999*20101127*1719*1421*X*004010VICS 3 | ST*850*000000010 4 | BEG*00*SA*08292233294**20101127*610385385 5 | REF*DP*038 6 | REF*PS*R 7 | ITD*14*3*2**45**46 8 | DTM*002*20101214 9 | PKG*F*68***PALLETIZE SHIPMENT 10 | PKG*F*66***REGULAR 11 | TD5*A*92*P3**SEE XYZ RETAIL ROUTING GUIDE 12 | N1*ST*XYZ RETAIL*9*0003947268292 13 | N3*31875 SOLON RD 14 | N4*SOLON*OH*44139 15 | PO1*1*120*EA*9.25*TE*CB*065322-117*PR*RO*VN*AB3542 16 | PID*F****SMALL WIDGET 17 | PO4*4*4*EA*PLT94**3*LR*15*CT 18 | PO1*2*220*EA*13.79*TE*CB*066850-116*PR*RO*VN*RD5322 19 | PID*F****MEDIUM WIDGET 20 | PO4*2*2*EA 21 | PO1*3*126*EA*10.99*TE*CB*060733-110*PR*RO*VN*XY5266 22 | PID*F****LARGE WIDGET 23 | PO4*6*1*EA*PLT94**3*LR*12*CT 24 | PO1*4*76*EA*4.35*TE*CB*065308-116*PR*RO*VN*VX2332 25 | PID*F****NANO WIDGET 26 | PO4*4*4*EA*PLT94**6*LR*19*CT 27 | PO1*5*72*EA*7.5*TE*CB*065374-118*PR*RO*VN*RV0524 28 | PID*F****BLUE WIDGET 29 | PO4*4*4*EA 30 | PO1*6*696*EA*9.55*TE*CB*067504-118*PR*RO*VN*DX1875 31 | PID*F****ORANGE WIDGET 32 | PO4*6*6*EA*PLT94**3*LR*10*CT 33 | CTT*6 34 | AMT*1*13045.94 35 | SE*33*000000010 36 | GE*1*1421 37 | IEA*1*000003438 38 | -------------------------------------------------------------------------------- /tests/test-data/850_3.edi: -------------------------------------------------------------------------------- 1 | ISA*00* *00* *12*0000000000 *12*0000000000 *160426*1301*U*00401*010001398*0*P*> 2 | GS*PO*0000000000*0000000000*20160426*1301*10000774*X*004010 3 | ST*850*8830 4 | BEG*00*NE*----------**20160426 5 | DTM*106*20160502 6 | N9*ZZ*0 7 | MSG*000000000001010700 BUYER --------- ------ SHIP TO: 000 -------- ----- --. SAN ANTONIO, TX 78245 ATTN. --------- ------ 8 | N1*VN*----- ------ --------- ---*ZZ*----- 9 | N3*----- ------ -- 10 | N4*HUNTINGTON BEACH*CA*92647 11 | N1*ST*PETCO - CORPORATE*92*100 12 | N3*9125 REHCO RD 13 | N4*SAN DIEGO*CA*92121 14 | PO1**1*KI*225**VN*UNKNOWN*PD*SU - SPARK - AQ FREEZER PUSHER*SK*000000000001010700 15 | CTT*000001**0000000.00*01 16 | SE*14*8830 17 | GE*1*10000774 18 | IEA*1*010001398 19 | -------------------------------------------------------------------------------- /tests/test-data/856.edi: -------------------------------------------------------------------------------- 1 | ISA*01*0000000000*01*ABCCO *12*4405197800 *01*999999999 *111206*1719*-*00406*000000049*0*P*>~ 2 | GS*SH*4405197800*999999999*20111206*1045*49*X*004060~ 3 | ST*856*0008~ 4 | BSN*14*829716*20111206*142428*0002~ 5 | HL*1**S~ 6 | TD1*PCS*2****A3*60.310*LB~ 7 | TD5**2*XXXX**XXXX~ 8 | REF*BM*999999-001~ 9 | REF*CN*5787970539~ 10 | DTM*011*20111206~ 11 | N1*SH*1 EDI SOURCE~ 12 | N3*31875 SOLON RD~ 13 | N4*SOLON*OH*44139~ 14 | N1*OB*XYZ RETAIL~ 15 | N3*P O BOX 9999999~ 16 | N4*ATLANTA*GA*31139-0020**SN*9999~ 17 | N1*SF*1 EDI SOURCE~ 18 | N3*31875 SOLON ROAD~ 19 | N4*SOLON*OH*44139~ 20 | HL*2*1*O~ 21 | PRF*99999817***20111205~ 22 | HL*3*2*I~ 23 | LIN*1*VP*87787D*UP*999999310145~ 24 | SN1*1*24*EA~ 25 | PO4*1*24*EA~ 26 | PID*F****BLUE WIDGET~ 27 | HL*4*2*I~ 28 | LIN*2*VP*99887D*UP*999999311746~ 29 | SN1*2*6*EA~ 30 | PO4*1*6*EA~ 31 | PID*F****RED WIDGET~ 32 | CTT*4*30~ 33 | SE*31*0008~ 34 | GE*1*49~ 35 | IEA*1*000000049~ -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "moduleResolution": "node", 5 | "noImplicitAny": true, 6 | "removeComments": true, 7 | "target": "es6", 8 | "experimentalDecorators": true 9 | }, 10 | 11 | "exclude": [ 12 | "node_modules" 13 | ] 14 | } -------------------------------------------------------------------------------- /typings/mocha/mocha.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for mocha 2.2.5 2 | // Project: http://mochajs.org/ 3 | // Definitions by: Kazi Manzur Rashid , otiai10 , jt000 , Vadim Macagon 4 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped 5 | 6 | interface MochaSetupOptions { 7 | //milliseconds to wait before considering a test slow 8 | slow?: number; 9 | 10 | // timeout in milliseconds 11 | timeout?: number; 12 | 13 | // ui name "bdd", "tdd", "exports" etc 14 | ui?: string; 15 | 16 | //array of accepted globals 17 | globals?: any[]; 18 | 19 | // reporter instance (function or string), defaults to `mocha.reporters.Spec` 20 | reporter?: any; 21 | 22 | // bail on the first test failure 23 | bail?: boolean; 24 | 25 | // ignore global leaks 26 | ignoreLeaks?: boolean; 27 | 28 | // grep string or regexp to filter tests with 29 | grep?: any; 30 | } 31 | 32 | interface MochaDone { 33 | (error?: Error): void; 34 | } 35 | 36 | declare var mocha: Mocha; 37 | declare var describe: Mocha.IContextDefinition; 38 | declare var xdescribe: Mocha.IContextDefinition; 39 | // alias for `describe` 40 | declare var context: Mocha.IContextDefinition; 41 | // alias for `describe` 42 | declare var suite: Mocha.IContextDefinition; 43 | declare var it: Mocha.ITestDefinition; 44 | declare var xit: Mocha.ITestDefinition; 45 | // alias for `it` 46 | declare var test: Mocha.ITestDefinition; 47 | 48 | declare function before(action: () => void): void; 49 | 50 | declare function before(action: (done: MochaDone) => void): void; 51 | 52 | declare function before(description: string, action: () => void): void; 53 | 54 | declare function before(description: string, action: (done: MochaDone) => void): void; 55 | 56 | declare function setup(action: () => void): void; 57 | 58 | declare function setup(action: (done: MochaDone) => void): void; 59 | 60 | declare function after(action: () => void): void; 61 | 62 | declare function after(action: (done: MochaDone) => void): void; 63 | 64 | declare function after(description: string, action: () => void): void; 65 | 66 | declare function after(description: string, action: (done: MochaDone) => void): void; 67 | 68 | declare function teardown(action: () => void): void; 69 | 70 | declare function teardown(action: (done: MochaDone) => void): void; 71 | 72 | declare function beforeEach(action: () => void): void; 73 | 74 | declare function beforeEach(action: (done: MochaDone) => void): void; 75 | 76 | declare function beforeEach(description: string, action: () => void): void; 77 | 78 | declare function beforeEach(description: string, action: (done: MochaDone) => void): void; 79 | 80 | declare function suiteSetup(action: () => void): void; 81 | 82 | declare function suiteSetup(action: (done: MochaDone) => void): void; 83 | 84 | declare function afterEach(action: () => void): void; 85 | 86 | declare function afterEach(action: (done: MochaDone) => void): void; 87 | 88 | declare function afterEach(description: string, action: () => void): void; 89 | 90 | declare function afterEach(description: string, action: (done: MochaDone) => void): void; 91 | 92 | declare function suiteTeardown(action: () => void): void; 93 | 94 | declare function suiteTeardown(action: (done: MochaDone) => void): void; 95 | 96 | declare class Mocha { 97 | constructor(options?: { 98 | grep?: RegExp; 99 | ui?: string; 100 | reporter?: string; 101 | timeout?: number; 102 | bail?: boolean; 103 | }); 104 | 105 | /** Setup mocha with the given options. */ 106 | setup(options: MochaSetupOptions): Mocha; 107 | bail(value?: boolean): Mocha; 108 | addFile(file: string): Mocha; 109 | /** Sets reporter by name, defaults to "spec". */ 110 | reporter(name: string): Mocha; 111 | /** Sets reporter constructor, defaults to mocha.reporters.Spec. */ 112 | reporter(reporter: (runner: Mocha.IRunner, options: any) => any): Mocha; 113 | ui(value: string): Mocha; 114 | grep(value: string): Mocha; 115 | grep(value: RegExp): Mocha; 116 | invert(): Mocha; 117 | ignoreLeaks(value: boolean): Mocha; 118 | checkLeaks(): Mocha; 119 | /** 120 | * Function to allow assertion libraries to throw errors directly into mocha. 121 | * This is useful when running tests in a browser because window.onerror will 122 | * only receive the 'message' attribute of the Error. 123 | */ 124 | throwError(error: Error): void; 125 | /** Enables growl support. */ 126 | growl(): Mocha; 127 | globals(value: string): Mocha; 128 | globals(values: string[]): Mocha; 129 | useColors(value: boolean): Mocha; 130 | useInlineDiffs(value: boolean): Mocha; 131 | timeout(value: number): Mocha; 132 | slow(value: number): Mocha; 133 | enableTimeouts(value: boolean): Mocha; 134 | asyncOnly(value: boolean): Mocha; 135 | noHighlighting(value: boolean): Mocha; 136 | /** Runs tests and invokes `onComplete()` when finished. */ 137 | run(onComplete?: (failures: number) => void): Mocha.IRunner; 138 | } 139 | 140 | // merge the Mocha class declaration with a module 141 | declare namespace Mocha { 142 | /** Partial interface for Mocha's `Runnable` class. */ 143 | interface IRunnable { 144 | title: string; 145 | fn: Function; 146 | async: boolean; 147 | sync: boolean; 148 | timedOut: boolean; 149 | } 150 | 151 | /** Partial interface for Mocha's `Suite` class. */ 152 | interface ISuite { 153 | parent: ISuite; 154 | title: string; 155 | 156 | fullTitle(): string; 157 | } 158 | 159 | /** Partial interface for Mocha's `Test` class. */ 160 | interface ITest extends IRunnable { 161 | parent: ISuite; 162 | pending: boolean; 163 | 164 | fullTitle(): string; 165 | } 166 | 167 | /** Partial interface for Mocha's `Runner` class. */ 168 | interface IRunner {} 169 | 170 | interface IContextDefinition { 171 | (description: string, spec: () => void): ISuite; 172 | only(description: string, spec: () => void): ISuite; 173 | skip(description: string, spec: () => void): void; 174 | timeout(ms: number): void; 175 | } 176 | 177 | interface ITestDefinition { 178 | (expectation: string, assertion?: () => void): ITest; 179 | (expectation: string, assertion?: (done: MochaDone) => void): ITest; 180 | only(expectation: string, assertion?: () => void): ITest; 181 | only(expectation: string, assertion?: (done: MochaDone) => void): ITest; 182 | skip(expectation: string, assertion?: () => void): void; 183 | skip(expectation: string, assertion?: (done: MochaDone) => void): void; 184 | timeout(ms: number): void; 185 | } 186 | 187 | export module reporters { 188 | export class Base { 189 | stats: { 190 | suites: number; 191 | tests: number; 192 | passes: number; 193 | pending: number; 194 | failures: number; 195 | }; 196 | 197 | constructor(runner: IRunner); 198 | } 199 | 200 | export class Doc extends Base {} 201 | export class Dot extends Base {} 202 | export class HTML extends Base {} 203 | export class HTMLCov extends Base {} 204 | export class JSON extends Base {} 205 | export class JSONCov extends Base {} 206 | export class JSONStream extends Base {} 207 | export class Landing extends Base {} 208 | export class List extends Base {} 209 | export class Markdown extends Base {} 210 | export class Min extends Base {} 211 | export class Nyan extends Base {} 212 | export class Progress extends Base { 213 | /** 214 | * @param options.open String used to indicate the start of the progress bar. 215 | * @param options.complete String used to indicate a complete test on the progress bar. 216 | * @param options.incomplete String used to indicate an incomplete test on the progress bar. 217 | * @param options.close String used to indicate the end of the progress bar. 218 | */ 219 | constructor(runner: IRunner, options?: { 220 | open?: string; 221 | complete?: string; 222 | incomplete?: string; 223 | close?: string; 224 | }); 225 | } 226 | export class Spec extends Base {} 227 | export class TAP extends Base {} 228 | export class XUnit extends Base { 229 | constructor(runner: IRunner, options?: any); 230 | } 231 | } 232 | } 233 | 234 | declare module "mocha" { 235 | export = Mocha; 236 | } -------------------------------------------------------------------------------- /typings/node/node.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for Node.js v4.x 2 | // Project: http://nodejs.org/ 3 | // Definitions by: Microsoft TypeScript , DefinitelyTyped 4 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped 5 | 6 | /************************************************ 7 | * * 8 | * Node.js v4.x API * 9 | * * 10 | ************************************************/ 11 | 12 | interface Error { 13 | stack?: string; 14 | } 15 | 16 | 17 | // compat for TypeScript 1.8 18 | // if you use with --target es3 or --target es5 and use below definitions, 19 | // use the lib.es6.d.ts that is bundled with TypeScript 1.8. 20 | interface MapConstructor {} 21 | interface WeakMapConstructor {} 22 | interface SetConstructor {} 23 | interface WeakSetConstructor {} 24 | 25 | /************************************************ 26 | * * 27 | * GLOBAL * 28 | * * 29 | ************************************************/ 30 | declare var process: NodeJS.Process; 31 | declare var global: NodeJS.Global; 32 | 33 | declare var __filename: string; 34 | declare var __dirname: string; 35 | 36 | declare function setTimeout(callback: (...args: any[]) => void, ms: number, ...args: any[]): NodeJS.Timer; 37 | declare function clearTimeout(timeoutId: NodeJS.Timer): void; 38 | declare function setInterval(callback: (...args: any[]) => void, ms: number, ...args: any[]): NodeJS.Timer; 39 | declare function clearInterval(intervalId: NodeJS.Timer): void; 40 | declare function setImmediate(callback: (...args: any[]) => void, ...args: any[]): any; 41 | declare function clearImmediate(immediateId: any): void; 42 | 43 | interface NodeRequireFunction { 44 | (id: string): any; 45 | } 46 | 47 | interface NodeRequire extends NodeRequireFunction { 48 | resolve(id:string): string; 49 | cache: any; 50 | extensions: any; 51 | main: any; 52 | } 53 | 54 | declare var require: NodeRequire; 55 | 56 | interface NodeModule { 57 | exports: any; 58 | require: NodeRequireFunction; 59 | id: string; 60 | filename: string; 61 | loaded: boolean; 62 | parent: any; 63 | children: any[]; 64 | } 65 | 66 | declare var module: NodeModule; 67 | 68 | // Same as module.exports 69 | declare var exports: any; 70 | declare var SlowBuffer: { 71 | new (str: string, encoding?: string): Buffer; 72 | new (size: number): Buffer; 73 | new (size: Uint8Array): Buffer; 74 | new (array: any[]): Buffer; 75 | prototype: Buffer; 76 | isBuffer(obj: any): boolean; 77 | byteLength(string: string, encoding?: string): number; 78 | concat(list: Buffer[], totalLength?: number): Buffer; 79 | }; 80 | 81 | 82 | // Buffer class 83 | type BufferEncoding = "ascii" | "utf8" | "utf16le" | "ucs2" | "binary" | "hex"; 84 | interface Buffer extends NodeBuffer {} 85 | 86 | /** 87 | * Raw data is stored in instances of the Buffer class. 88 | * A Buffer is similar to an array of integers but corresponds to a raw memory allocation outside the V8 heap. A Buffer cannot be resized. 89 | * Valid string encodings: 'ascii'|'utf8'|'utf16le'|'ucs2'(alias of 'utf16le')|'base64'|'binary'(deprecated)|'hex' 90 | */ 91 | declare var Buffer: { 92 | /** 93 | * Allocates a new buffer containing the given {str}. 94 | * 95 | * @param str String to store in buffer. 96 | * @param encoding encoding to use, optional. Default is 'utf8' 97 | */ 98 | new (str: string, encoding?: string): Buffer; 99 | /** 100 | * Allocates a new buffer of {size} octets. 101 | * 102 | * @param size count of octets to allocate. 103 | */ 104 | new (size: number): Buffer; 105 | /** 106 | * Allocates a new buffer containing the given {array} of octets. 107 | * 108 | * @param array The octets to store. 109 | */ 110 | new (array: Uint8Array): Buffer; 111 | /** 112 | * Allocates a new buffer containing the given {array} of octets. 113 | * 114 | * @param array The octets to store. 115 | */ 116 | new (array: any[]): Buffer; 117 | /** 118 | * Copies the passed {buffer} data onto a new {Buffer} instance. 119 | * 120 | * @param buffer The buffer to copy. 121 | */ 122 | new (buffer: Buffer): Buffer; 123 | prototype: Buffer; 124 | /** 125 | * Returns true if {obj} is a Buffer 126 | * 127 | * @param obj object to test. 128 | */ 129 | isBuffer(obj: any): obj is Buffer; 130 | /** 131 | * Returns true if {encoding} is a valid encoding argument. 132 | * Valid string encodings in Node 0.12: 'ascii'|'utf8'|'utf16le'|'ucs2'(alias of 'utf16le')|'base64'|'binary'(deprecated)|'hex' 133 | * 134 | * @param encoding string to test. 135 | */ 136 | isEncoding(encoding: string): boolean; 137 | /** 138 | * Gives the actual byte length of a string. encoding defaults to 'utf8'. 139 | * This is not the same as String.prototype.length since that returns the number of characters in a string. 140 | * 141 | * @param string string to test. 142 | * @param encoding encoding used to evaluate (defaults to 'utf8') 143 | */ 144 | byteLength(string: string, encoding?: string): number; 145 | /** 146 | * Returns a buffer which is the result of concatenating all the buffers in the list together. 147 | * 148 | * If the list has no items, or if the totalLength is 0, then it returns a zero-length buffer. 149 | * If the list has exactly one item, then the first item of the list is returned. 150 | * If the list has more than one item, then a new Buffer is created. 151 | * 152 | * @param list An array of Buffer objects to concatenate 153 | * @param totalLength Total length of the buffers when concatenated. 154 | * If totalLength is not provided, it is read from the buffers in the list. However, this adds an additional loop to the function, so it is faster to provide the length explicitly. 155 | */ 156 | concat(list: Buffer[], totalLength?: number): Buffer; 157 | /** 158 | * The same as buf1.compare(buf2). 159 | */ 160 | compare(buf1: Buffer, buf2: Buffer): number; 161 | }; 162 | 163 | /************************************************ 164 | * * 165 | * GLOBAL INTERFACES * 166 | * * 167 | ************************************************/ 168 | declare namespace NodeJS { 169 | export interface ErrnoException extends Error { 170 | errno?: number; 171 | code?: string; 172 | path?: string; 173 | syscall?: string; 174 | stack?: string; 175 | } 176 | 177 | export interface EventEmitter { 178 | addListener(event: string, listener: Function): this; 179 | on(event: string, listener: Function): this; 180 | once(event: string, listener: Function): this; 181 | removeListener(event: string, listener: Function): this; 182 | removeAllListeners(event?: string): this; 183 | setMaxListeners(n: number): this; 184 | getMaxListeners(): number; 185 | listeners(event: string): Function[]; 186 | emit(event: string, ...args: any[]): boolean; 187 | listenerCount(type: string): number; 188 | } 189 | 190 | export interface ReadableStream extends EventEmitter { 191 | readable: boolean; 192 | read(size?: number): string|Buffer; 193 | setEncoding(encoding: string): void; 194 | pause(): void; 195 | resume(): void; 196 | pipe(destination: T, options?: { end?: boolean; }): T; 197 | unpipe(destination?: T): void; 198 | unshift(chunk: string): void; 199 | unshift(chunk: Buffer): void; 200 | wrap(oldStream: ReadableStream): ReadableStream; 201 | } 202 | 203 | export interface WritableStream extends EventEmitter { 204 | writable: boolean; 205 | write(buffer: Buffer|string, cb?: Function): boolean; 206 | write(str: string, encoding?: string, cb?: Function): boolean; 207 | end(): void; 208 | end(buffer: Buffer, cb?: Function): void; 209 | end(str: string, cb?: Function): void; 210 | end(str: string, encoding?: string, cb?: Function): void; 211 | } 212 | 213 | export interface ReadWriteStream extends ReadableStream, WritableStream {} 214 | 215 | export interface Events extends EventEmitter { } 216 | 217 | export interface Domain extends Events { 218 | run(fn: Function): void; 219 | add(emitter: Events): void; 220 | remove(emitter: Events): void; 221 | bind(cb: (err: Error, data: any) => any): any; 222 | intercept(cb: (data: any) => any): any; 223 | dispose(): void; 224 | 225 | addListener(event: string, listener: Function): this; 226 | on(event: string, listener: Function): this; 227 | once(event: string, listener: Function): this; 228 | removeListener(event: string, listener: Function): this; 229 | removeAllListeners(event?: string): this; 230 | } 231 | 232 | export interface MemoryUsage { 233 | rss: number; 234 | heapTotal: number; 235 | heapUsed: number; 236 | } 237 | 238 | export interface Process extends EventEmitter { 239 | stdout: WritableStream; 240 | stderr: WritableStream; 241 | stdin: ReadableStream; 242 | argv: string[]; 243 | execArgv: string[]; 244 | execPath: string; 245 | abort(): void; 246 | chdir(directory: string): void; 247 | cwd(): string; 248 | env: any; 249 | exit(code?: number): void; 250 | getgid(): number; 251 | setgid(id: number): void; 252 | setgid(id: string): void; 253 | getuid(): number; 254 | setuid(id: number): void; 255 | setuid(id: string): void; 256 | version: string; 257 | versions: { 258 | http_parser: string; 259 | node: string; 260 | v8: string; 261 | ares: string; 262 | uv: string; 263 | zlib: string; 264 | openssl: string; 265 | }; 266 | config: { 267 | target_defaults: { 268 | cflags: any[]; 269 | default_configuration: string; 270 | defines: string[]; 271 | include_dirs: string[]; 272 | libraries: string[]; 273 | }; 274 | variables: { 275 | clang: number; 276 | host_arch: string; 277 | node_install_npm: boolean; 278 | node_install_waf: boolean; 279 | node_prefix: string; 280 | node_shared_openssl: boolean; 281 | node_shared_v8: boolean; 282 | node_shared_zlib: boolean; 283 | node_use_dtrace: boolean; 284 | node_use_etw: boolean; 285 | node_use_openssl: boolean; 286 | target_arch: string; 287 | v8_no_strict_aliasing: number; 288 | v8_use_snapshot: boolean; 289 | visibility: string; 290 | }; 291 | }; 292 | kill(pid:number, signal?: string|number): void; 293 | pid: number; 294 | title: string; 295 | arch: string; 296 | platform: string; 297 | memoryUsage(): MemoryUsage; 298 | nextTick(callback: Function): void; 299 | umask(mask?: number): number; 300 | uptime(): number; 301 | hrtime(time?:number[]): number[]; 302 | domain: Domain; 303 | 304 | // Worker 305 | send?(message: any, sendHandle?: any): void; 306 | disconnect(): void; 307 | connected: boolean; 308 | } 309 | 310 | export interface Global { 311 | Array: typeof Array; 312 | ArrayBuffer: typeof ArrayBuffer; 313 | Boolean: typeof Boolean; 314 | Buffer: typeof Buffer; 315 | DataView: typeof DataView; 316 | Date: typeof Date; 317 | Error: typeof Error; 318 | EvalError: typeof EvalError; 319 | Float32Array: typeof Float32Array; 320 | Float64Array: typeof Float64Array; 321 | Function: typeof Function; 322 | GLOBAL: Global; 323 | Infinity: typeof Infinity; 324 | Int16Array: typeof Int16Array; 325 | Int32Array: typeof Int32Array; 326 | Int8Array: typeof Int8Array; 327 | Intl: typeof Intl; 328 | JSON: typeof JSON; 329 | Map: MapConstructor; 330 | Math: typeof Math; 331 | NaN: typeof NaN; 332 | Number: typeof Number; 333 | Object: typeof Object; 334 | Promise: Function; 335 | RangeError: typeof RangeError; 336 | ReferenceError: typeof ReferenceError; 337 | RegExp: typeof RegExp; 338 | Set: SetConstructor; 339 | String: typeof String; 340 | Symbol: Function; 341 | SyntaxError: typeof SyntaxError; 342 | TypeError: typeof TypeError; 343 | URIError: typeof URIError; 344 | Uint16Array: typeof Uint16Array; 345 | Uint32Array: typeof Uint32Array; 346 | Uint8Array: typeof Uint8Array; 347 | Uint8ClampedArray: Function; 348 | WeakMap: WeakMapConstructor; 349 | WeakSet: WeakSetConstructor; 350 | clearImmediate: (immediateId: any) => void; 351 | clearInterval: (intervalId: NodeJS.Timer) => void; 352 | clearTimeout: (timeoutId: NodeJS.Timer) => void; 353 | console: typeof console; 354 | decodeURI: typeof decodeURI; 355 | decodeURIComponent: typeof decodeURIComponent; 356 | encodeURI: typeof encodeURI; 357 | encodeURIComponent: typeof encodeURIComponent; 358 | escape: (str: string) => string; 359 | eval: typeof eval; 360 | global: Global; 361 | isFinite: typeof isFinite; 362 | isNaN: typeof isNaN; 363 | parseFloat: typeof parseFloat; 364 | parseInt: typeof parseInt; 365 | process: Process; 366 | root: Global; 367 | setImmediate: (callback: (...args: any[]) => void, ...args: any[]) => any; 368 | setInterval: (callback: (...args: any[]) => void, ms: number, ...args: any[]) => NodeJS.Timer; 369 | setTimeout: (callback: (...args: any[]) => void, ms: number, ...args: any[]) => NodeJS.Timer; 370 | undefined: typeof undefined; 371 | unescape: (str: string) => string; 372 | gc: () => void; 373 | v8debug?: any; 374 | } 375 | 376 | export interface Timer { 377 | ref() : void; 378 | unref() : void; 379 | } 380 | } 381 | 382 | /** 383 | * @deprecated 384 | */ 385 | interface NodeBuffer { 386 | [index: number]: number; 387 | write(string: string, offset?: number, length?: number, encoding?: string): number; 388 | toString(encoding?: string, start?: number, end?: number): string; 389 | toJSON(): any; 390 | length: number; 391 | equals(otherBuffer: Buffer): boolean; 392 | compare(otherBuffer: Buffer): number; 393 | copy(targetBuffer: Buffer, targetStart?: number, sourceStart?: number, sourceEnd?: number): number; 394 | slice(start?: number, end?: number): Buffer; 395 | writeUIntLE(value: number, offset: number, byteLength: number, noAssert?: boolean): number; 396 | writeUIntBE(value: number, offset: number, byteLength: number, noAssert?: boolean): number; 397 | writeIntLE(value: number, offset: number, byteLength: number, noAssert?: boolean): number; 398 | writeIntBE(value: number, offset: number, byteLength: number, noAssert?: boolean): number; 399 | readUIntLE(offset: number, byteLength: number, noAssert?: boolean): number; 400 | readUIntBE(offset: number, byteLength: number, noAssert?: boolean): number; 401 | readIntLE(offset: number, byteLength: number, noAssert?: boolean): number; 402 | readIntBE(offset: number, byteLength: number, noAssert?: boolean): number; 403 | readUInt8(offset: number, noAssert?: boolean): number; 404 | readUInt16LE(offset: number, noAssert?: boolean): number; 405 | readUInt16BE(offset: number, noAssert?: boolean): number; 406 | readUInt32LE(offset: number, noAssert?: boolean): number; 407 | readUInt32BE(offset: number, noAssert?: boolean): number; 408 | readInt8(offset: number, noAssert?: boolean): number; 409 | readInt16LE(offset: number, noAssert?: boolean): number; 410 | readInt16BE(offset: number, noAssert?: boolean): number; 411 | readInt32LE(offset: number, noAssert?: boolean): number; 412 | readInt32BE(offset: number, noAssert?: boolean): number; 413 | readFloatLE(offset: number, noAssert?: boolean): number; 414 | readFloatBE(offset: number, noAssert?: boolean): number; 415 | readDoubleLE(offset: number, noAssert?: boolean): number; 416 | readDoubleBE(offset: number, noAssert?: boolean): number; 417 | writeUInt8(value: number, offset: number, noAssert?: boolean): number; 418 | writeUInt16LE(value: number, offset: number, noAssert?: boolean): number; 419 | writeUInt16BE(value: number, offset: number, noAssert?: boolean): number; 420 | writeUInt32LE(value: number, offset: number, noAssert?: boolean): number; 421 | writeUInt32BE(value: number, offset: number, noAssert?: boolean): number; 422 | writeInt8(value: number, offset: number, noAssert?: boolean): number; 423 | writeInt16LE(value: number, offset: number, noAssert?: boolean): number; 424 | writeInt16BE(value: number, offset: number, noAssert?: boolean): number; 425 | writeInt32LE(value: number, offset: number, noAssert?: boolean): number; 426 | writeInt32BE(value: number, offset: number, noAssert?: boolean): number; 427 | writeFloatLE(value: number, offset: number, noAssert?: boolean): number; 428 | writeFloatBE(value: number, offset: number, noAssert?: boolean): number; 429 | writeDoubleLE(value: number, offset: number, noAssert?: boolean): number; 430 | writeDoubleBE(value: number, offset: number, noAssert?: boolean): number; 431 | fill(value: any, offset?: number, end?: number): Buffer; 432 | indexOf(value: string | number | Buffer, byteOffset?: number): number; 433 | } 434 | 435 | /************************************************ 436 | * * 437 | * MODULES * 438 | * * 439 | ************************************************/ 440 | declare module "buffer" { 441 | export var INSPECT_MAX_BYTES: number; 442 | var BuffType: typeof Buffer; 443 | var SlowBuffType: typeof SlowBuffer; 444 | export { BuffType as Buffer, SlowBuffType as SlowBuffer }; 445 | } 446 | 447 | declare module "querystring" { 448 | export interface StringifyOptions { 449 | encodeURIComponent?: Function; 450 | } 451 | 452 | export interface ParseOptions { 453 | maxKeys?: number; 454 | decodeURIComponent?: Function; 455 | } 456 | 457 | export function stringify(obj: T, sep?: string, eq?: string, options?: StringifyOptions): string; 458 | export function parse(str: string, sep?: string, eq?: string, options?: ParseOptions): any; 459 | export function parse(str: string, sep?: string, eq?: string, options?: ParseOptions): T; 460 | export function escape(str: string): string; 461 | export function unescape(str: string): string; 462 | } 463 | 464 | declare module "events" { 465 | export class EventEmitter implements NodeJS.EventEmitter { 466 | static EventEmitter: EventEmitter; 467 | static listenerCount(emitter: EventEmitter, event: string): number; // deprecated 468 | static defaultMaxListeners: number; 469 | 470 | addListener(event: string, listener: Function): this; 471 | on(event: string, listener: Function): this; 472 | once(event: string, listener: Function): this; 473 | removeListener(event: string, listener: Function): this; 474 | removeAllListeners(event?: string): this; 475 | setMaxListeners(n: number): this; 476 | getMaxListeners(): number; 477 | listeners(event: string): Function[]; 478 | emit(event: string, ...args: any[]): boolean; 479 | listenerCount(type: string): number; 480 | } 481 | } 482 | 483 | declare module "http" { 484 | import * as events from "events"; 485 | import * as net from "net"; 486 | import * as stream from "stream"; 487 | 488 | export interface RequestOptions { 489 | protocol?: string; 490 | host?: string; 491 | hostname?: string; 492 | family?: number; 493 | port?: number; 494 | localAddress?: string; 495 | socketPath?: string; 496 | method?: string; 497 | path?: string; 498 | headers?: { [key: string]: any }; 499 | auth?: string; 500 | agent?: Agent|boolean; 501 | } 502 | 503 | export interface Server extends events.EventEmitter, net.Server { 504 | setTimeout(msecs: number, callback: Function): void; 505 | maxHeadersCount: number; 506 | timeout: number; 507 | } 508 | /** 509 | * @deprecated Use IncomingMessage 510 | */ 511 | export interface ServerRequest extends IncomingMessage { 512 | connection: net.Socket; 513 | } 514 | export interface ServerResponse extends events.EventEmitter, stream.Writable { 515 | // Extended base methods 516 | write(buffer: Buffer): boolean; 517 | write(buffer: Buffer, cb?: Function): boolean; 518 | write(str: string, cb?: Function): boolean; 519 | write(str: string, encoding?: string, cb?: Function): boolean; 520 | write(str: string, encoding?: string, fd?: string): boolean; 521 | 522 | writeContinue(): void; 523 | writeHead(statusCode: number, reasonPhrase?: string, headers?: any): void; 524 | writeHead(statusCode: number, headers?: any): void; 525 | statusCode: number; 526 | statusMessage: string; 527 | headersSent: boolean; 528 | setHeader(name: string, value: string | string[]): void; 529 | sendDate: boolean; 530 | getHeader(name: string): string; 531 | removeHeader(name: string): void; 532 | write(chunk: any, encoding?: string): any; 533 | addTrailers(headers: any): void; 534 | 535 | // Extended base methods 536 | end(): void; 537 | end(buffer: Buffer, cb?: Function): void; 538 | end(str: string, cb?: Function): void; 539 | end(str: string, encoding?: string, cb?: Function): void; 540 | end(data?: any, encoding?: string): void; 541 | } 542 | export interface ClientRequest extends events.EventEmitter, stream.Writable { 543 | // Extended base methods 544 | write(buffer: Buffer): boolean; 545 | write(buffer: Buffer, cb?: Function): boolean; 546 | write(str: string, cb?: Function): boolean; 547 | write(str: string, encoding?: string, cb?: Function): boolean; 548 | write(str: string, encoding?: string, fd?: string): boolean; 549 | 550 | write(chunk: any, encoding?: string): void; 551 | abort(): void; 552 | setTimeout(timeout: number, callback?: Function): void; 553 | setNoDelay(noDelay?: boolean): void; 554 | setSocketKeepAlive(enable?: boolean, initialDelay?: number): void; 555 | 556 | setHeader(name: string, value: string | string[]): void; 557 | getHeader(name: string): string; 558 | removeHeader(name: string): void; 559 | addTrailers(headers: any): void; 560 | 561 | // Extended base methods 562 | end(): void; 563 | end(buffer: Buffer, cb?: Function): void; 564 | end(str: string, cb?: Function): void; 565 | end(str: string, encoding?: string, cb?: Function): void; 566 | end(data?: any, encoding?: string): void; 567 | } 568 | export interface IncomingMessage extends events.EventEmitter, stream.Readable { 569 | httpVersion: string; 570 | headers: any; 571 | rawHeaders: string[]; 572 | trailers: any; 573 | rawTrailers: any; 574 | setTimeout(msecs: number, callback: Function): NodeJS.Timer; 575 | /** 576 | * Only valid for request obtained from http.Server. 577 | */ 578 | method?: string; 579 | /** 580 | * Only valid for request obtained from http.Server. 581 | */ 582 | url?: string; 583 | /** 584 | * Only valid for response obtained from http.ClientRequest. 585 | */ 586 | statusCode?: number; 587 | /** 588 | * Only valid for response obtained from http.ClientRequest. 589 | */ 590 | statusMessage?: string; 591 | socket: net.Socket; 592 | } 593 | /** 594 | * @deprecated Use IncomingMessage 595 | */ 596 | export interface ClientResponse extends IncomingMessage { } 597 | 598 | export interface AgentOptions { 599 | /** 600 | * Keep sockets around in a pool to be used by other requests in the future. Default = false 601 | */ 602 | keepAlive?: boolean; 603 | /** 604 | * When using HTTP KeepAlive, how often to send TCP KeepAlive packets over sockets being kept alive. Default = 1000. 605 | * Only relevant if keepAlive is set to true. 606 | */ 607 | keepAliveMsecs?: number; 608 | /** 609 | * Maximum number of sockets to allow per host. Default for Node 0.10 is 5, default for Node 0.12 is Infinity 610 | */ 611 | maxSockets?: number; 612 | /** 613 | * Maximum number of sockets to leave open in a free state. Only relevant if keepAlive is set to true. Default = 256. 614 | */ 615 | maxFreeSockets?: number; 616 | } 617 | 618 | export class Agent { 619 | maxSockets: number; 620 | sockets: any; 621 | requests: any; 622 | 623 | constructor(opts?: AgentOptions); 624 | 625 | /** 626 | * Destroy any sockets that are currently in use by the agent. 627 | * It is usually not necessary to do this. However, if you are using an agent with KeepAlive enabled, 628 | * then it is best to explicitly shut down the agent when you know that it will no longer be used. Otherwise, 629 | * sockets may hang open for quite a long time before the server terminates them. 630 | */ 631 | destroy(): void; 632 | } 633 | 634 | export var METHODS: string[]; 635 | 636 | export var STATUS_CODES: { 637 | [errorCode: number]: string; 638 | [errorCode: string]: string; 639 | }; 640 | export function createServer(requestListener?: (request: IncomingMessage, response: ServerResponse) =>void ): Server; 641 | export function createClient(port?: number, host?: string): any; 642 | export function request(options: RequestOptions, callback?: (res: IncomingMessage) => void): ClientRequest; 643 | export function get(options: any, callback?: (res: IncomingMessage) => void): ClientRequest; 644 | export var globalAgent: Agent; 645 | } 646 | 647 | declare module "cluster" { 648 | import * as child from "child_process"; 649 | import * as events from "events"; 650 | 651 | export interface ClusterSettings { 652 | exec?: string; 653 | args?: string[]; 654 | silent?: boolean; 655 | } 656 | 657 | export interface Address { 658 | address: string; 659 | port: number; 660 | addressType: string; 661 | } 662 | 663 | export class Worker extends events.EventEmitter { 664 | id: string; 665 | process: child.ChildProcess; 666 | suicide: boolean; 667 | send(message: any, sendHandle?: any): void; 668 | kill(signal?: string): void; 669 | destroy(signal?: string): void; 670 | disconnect(): void; 671 | } 672 | 673 | export var settings: ClusterSettings; 674 | export var isMaster: boolean; 675 | export var isWorker: boolean; 676 | export function setupMaster(settings?: ClusterSettings): void; 677 | export function fork(env?: any): Worker; 678 | export function disconnect(callback?: Function): void; 679 | export var worker: Worker; 680 | export var workers: Worker[]; 681 | 682 | // Event emitter 683 | export function addListener(event: string, listener: Function): void; 684 | export function on(event: "disconnect", listener: (worker: Worker) => void): void; 685 | export function on(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): void; 686 | export function on(event: "fork", listener: (worker: Worker) => void): void; 687 | export function on(event: "listening", listener: (worker: Worker, address: any) => void): void; 688 | export function on(event: "message", listener: (worker: Worker, message: any) => void): void; 689 | export function on(event: "online", listener: (worker: Worker) => void): void; 690 | export function on(event: "setup", listener: (settings: any) => void): void; 691 | export function on(event: string, listener: Function): any; 692 | export function once(event: string, listener: Function): void; 693 | export function removeListener(event: string, listener: Function): void; 694 | export function removeAllListeners(event?: string): void; 695 | export function setMaxListeners(n: number): void; 696 | export function listeners(event: string): Function[]; 697 | export function emit(event: string, ...args: any[]): boolean; 698 | } 699 | 700 | declare module "zlib" { 701 | import * as stream from "stream"; 702 | export interface ZlibOptions { chunkSize?: number; windowBits?: number; level?: number; memLevel?: number; strategy?: number; dictionary?: any; } 703 | 704 | export interface Gzip extends stream.Transform { } 705 | export interface Gunzip extends stream.Transform { } 706 | export interface Deflate extends stream.Transform { } 707 | export interface Inflate extends stream.Transform { } 708 | export interface DeflateRaw extends stream.Transform { } 709 | export interface InflateRaw extends stream.Transform { } 710 | export interface Unzip extends stream.Transform { } 711 | 712 | export function createGzip(options?: ZlibOptions): Gzip; 713 | export function createGunzip(options?: ZlibOptions): Gunzip; 714 | export function createDeflate(options?: ZlibOptions): Deflate; 715 | export function createInflate(options?: ZlibOptions): Inflate; 716 | export function createDeflateRaw(options?: ZlibOptions): DeflateRaw; 717 | export function createInflateRaw(options?: ZlibOptions): InflateRaw; 718 | export function createUnzip(options?: ZlibOptions): Unzip; 719 | 720 | export function deflate(buf: Buffer, callback: (error: Error, result: any) =>void ): void; 721 | export function deflateSync(buf: Buffer, options?: ZlibOptions): any; 722 | export function deflateRaw(buf: Buffer, callback: (error: Error, result: any) =>void ): void; 723 | export function deflateRawSync(buf: Buffer, options?: ZlibOptions): any; 724 | export function gzip(buf: Buffer, callback: (error: Error, result: any) =>void ): void; 725 | export function gzipSync(buf: Buffer, options?: ZlibOptions): any; 726 | export function gunzip(buf: Buffer, callback: (error: Error, result: any) =>void ): void; 727 | export function gunzipSync(buf: Buffer, options?: ZlibOptions): any; 728 | export function inflate(buf: Buffer, callback: (error: Error, result: any) =>void ): void; 729 | export function inflateSync(buf: Buffer, options?: ZlibOptions): any; 730 | export function inflateRaw(buf: Buffer, callback: (error: Error, result: any) =>void ): void; 731 | export function inflateRawSync(buf: Buffer, options?: ZlibOptions): any; 732 | export function unzip(buf: Buffer, callback: (error: Error, result: any) =>void ): void; 733 | export function unzipSync(buf: Buffer, options?: ZlibOptions): any; 734 | 735 | // Constants 736 | export var Z_NO_FLUSH: number; 737 | export var Z_PARTIAL_FLUSH: number; 738 | export var Z_SYNC_FLUSH: number; 739 | export var Z_FULL_FLUSH: number; 740 | export var Z_FINISH: number; 741 | export var Z_BLOCK: number; 742 | export var Z_TREES: number; 743 | export var Z_OK: number; 744 | export var Z_STREAM_END: number; 745 | export var Z_NEED_DICT: number; 746 | export var Z_ERRNO: number; 747 | export var Z_STREAM_ERROR: number; 748 | export var Z_DATA_ERROR: number; 749 | export var Z_MEM_ERROR: number; 750 | export var Z_BUF_ERROR: number; 751 | export var Z_VERSION_ERROR: number; 752 | export var Z_NO_COMPRESSION: number; 753 | export var Z_BEST_SPEED: number; 754 | export var Z_BEST_COMPRESSION: number; 755 | export var Z_DEFAULT_COMPRESSION: number; 756 | export var Z_FILTERED: number; 757 | export var Z_HUFFMAN_ONLY: number; 758 | export var Z_RLE: number; 759 | export var Z_FIXED: number; 760 | export var Z_DEFAULT_STRATEGY: number; 761 | export var Z_BINARY: number; 762 | export var Z_TEXT: number; 763 | export var Z_ASCII: number; 764 | export var Z_UNKNOWN: number; 765 | export var Z_DEFLATED: number; 766 | export var Z_NULL: number; 767 | } 768 | 769 | declare module "os" { 770 | export interface CpuInfo { 771 | model: string; 772 | speed: number; 773 | times: { 774 | user: number; 775 | nice: number; 776 | sys: number; 777 | idle: number; 778 | irq: number; 779 | }; 780 | } 781 | 782 | export interface NetworkInterfaceInfo { 783 | address: string; 784 | netmask: string; 785 | family: string; 786 | mac: string; 787 | internal: boolean; 788 | } 789 | 790 | export function tmpdir(): string; 791 | export function homedir(): string; 792 | export function endianness(): string; 793 | export function hostname(): string; 794 | export function type(): string; 795 | export function platform(): string; 796 | export function arch(): string; 797 | export function release(): string; 798 | export function uptime(): number; 799 | export function loadavg(): number[]; 800 | export function totalmem(): number; 801 | export function freemem(): number; 802 | export function cpus(): CpuInfo[]; 803 | export function networkInterfaces(): {[index: string]: NetworkInterfaceInfo[]}; 804 | export var EOL: string; 805 | } 806 | 807 | declare module "https" { 808 | import * as tls from "tls"; 809 | import * as events from "events"; 810 | import * as http from "http"; 811 | 812 | export interface ServerOptions { 813 | pfx?: any; 814 | key?: any; 815 | passphrase?: string; 816 | cert?: any; 817 | ca?: any; 818 | crl?: any; 819 | ciphers?: string; 820 | honorCipherOrder?: boolean; 821 | requestCert?: boolean; 822 | rejectUnauthorized?: boolean; 823 | NPNProtocols?: any; 824 | SNICallback?: (servername: string) => any; 825 | } 826 | 827 | export interface RequestOptions extends http.RequestOptions{ 828 | pfx?: any; 829 | key?: any; 830 | passphrase?: string; 831 | cert?: any; 832 | ca?: any; 833 | ciphers?: string; 834 | rejectUnauthorized?: boolean; 835 | secureProtocol?: string; 836 | } 837 | 838 | export interface Agent { 839 | maxSockets: number; 840 | sockets: any; 841 | requests: any; 842 | } 843 | export var Agent: { 844 | new (options?: RequestOptions): Agent; 845 | }; 846 | export interface Server extends tls.Server { } 847 | export function createServer(options: ServerOptions, requestListener?: Function): Server; 848 | export function request(options: RequestOptions, callback?: (res: http.IncomingMessage) =>void ): http.ClientRequest; 849 | export function get(options: RequestOptions, callback?: (res: http.IncomingMessage) =>void ): http.ClientRequest; 850 | export var globalAgent: Agent; 851 | } 852 | 853 | declare module "punycode" { 854 | export function decode(string: string): string; 855 | export function encode(string: string): string; 856 | export function toUnicode(domain: string): string; 857 | export function toASCII(domain: string): string; 858 | export var ucs2: ucs2; 859 | interface ucs2 { 860 | decode(string: string): number[]; 861 | encode(codePoints: number[]): string; 862 | } 863 | export var version: any; 864 | } 865 | 866 | declare module "repl" { 867 | import * as stream from "stream"; 868 | import * as events from "events"; 869 | 870 | export interface ReplOptions { 871 | prompt?: string; 872 | input?: NodeJS.ReadableStream; 873 | output?: NodeJS.WritableStream; 874 | terminal?: boolean; 875 | eval?: Function; 876 | useColors?: boolean; 877 | useGlobal?: boolean; 878 | ignoreUndefined?: boolean; 879 | writer?: Function; 880 | } 881 | export function start(options: ReplOptions): events.EventEmitter; 882 | } 883 | 884 | declare module "readline" { 885 | import * as events from "events"; 886 | import * as stream from "stream"; 887 | 888 | export interface Key { 889 | sequence?: string; 890 | name?: string; 891 | ctrl?: boolean; 892 | meta?: boolean; 893 | shift?: boolean; 894 | } 895 | 896 | export interface ReadLine extends events.EventEmitter { 897 | setPrompt(prompt: string): void; 898 | prompt(preserveCursor?: boolean): void; 899 | question(query: string, callback: (answer: string) => void): void; 900 | pause(): ReadLine; 901 | resume(): ReadLine; 902 | close(): void; 903 | write(data: string|Buffer, key?: Key): void; 904 | } 905 | 906 | export interface Completer { 907 | (line: string): CompleterResult; 908 | (line: string, callback: (err: any, result: CompleterResult) => void): any; 909 | } 910 | 911 | export interface CompleterResult { 912 | completions: string[]; 913 | line: string; 914 | } 915 | 916 | export interface ReadLineOptions { 917 | input: NodeJS.ReadableStream; 918 | output?: NodeJS.WritableStream; 919 | completer?: Completer; 920 | terminal?: boolean; 921 | historySize?: number; 922 | } 923 | 924 | export function createInterface(input: NodeJS.ReadableStream, output?: NodeJS.WritableStream, completer?: Completer, terminal?: boolean): ReadLine; 925 | export function createInterface(options: ReadLineOptions): ReadLine; 926 | 927 | export function cursorTo(stream: NodeJS.WritableStream, x: number, y: number): void; 928 | export function moveCursor(stream: NodeJS.WritableStream, dx: number|string, dy: number|string): void; 929 | export function clearLine(stream: NodeJS.WritableStream, dir: number): void; 930 | export function clearScreenDown(stream: NodeJS.WritableStream): void; 931 | } 932 | 933 | declare module "vm" { 934 | export interface Context { } 935 | export interface Script { 936 | runInThisContext(): void; 937 | runInNewContext(sandbox?: Context): void; 938 | } 939 | export function runInThisContext(code: string, filename?: string): void; 940 | export function runInNewContext(code: string, sandbox?: Context, filename?: string): void; 941 | export function runInContext(code: string, context: Context, filename?: string): void; 942 | export function createContext(initSandbox?: Context): Context; 943 | export function createScript(code: string, filename?: string): Script; 944 | } 945 | 946 | declare module "child_process" { 947 | import * as events from "events"; 948 | import * as stream from "stream"; 949 | 950 | export interface ChildProcess extends events.EventEmitter { 951 | stdin: stream.Writable; 952 | stdout: stream.Readable; 953 | stderr: stream.Readable; 954 | stdio: [stream.Writable, stream.Readable, stream.Readable]; 955 | pid: number; 956 | kill(signal?: string): void; 957 | send(message: any, sendHandle?: any): void; 958 | disconnect(): void; 959 | unref(): void; 960 | } 961 | 962 | export interface SpawnOptions { 963 | cwd?: string; 964 | env?: any; 965 | stdio?: any; 966 | detached?: boolean; 967 | uid?: number; 968 | gid?: number; 969 | shell?: boolean | string; 970 | } 971 | export function spawn(command: string, args?: string[], options?: SpawnOptions): ChildProcess; 972 | 973 | export interface ExecOptions { 974 | cwd?: string; 975 | env?: any; 976 | shell?: string; 977 | timeout?: number; 978 | maxBuffer?: number; 979 | killSignal?: string; 980 | uid?: number; 981 | gid?: number; 982 | } 983 | export interface ExecOptionsWithStringEncoding extends ExecOptions { 984 | encoding: BufferEncoding; 985 | } 986 | export interface ExecOptionsWithBufferEncoding extends ExecOptions { 987 | encoding: string; // specify `null`. 988 | } 989 | export function exec(command: string, callback?: (error: Error, stdout: string, stderr: string) =>void ): ChildProcess; 990 | export function exec(command: string, options: ExecOptionsWithStringEncoding, callback?: (error: Error, stdout: string, stderr: string) =>void ): ChildProcess; 991 | // usage. child_process.exec("tsc", {encoding: null as string}, (err, stdout, stderr) => {}); 992 | export function exec(command: string, options: ExecOptionsWithBufferEncoding, callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; 993 | export function exec(command: string, options: ExecOptions, callback?: (error: Error, stdout: string, stderr: string) =>void ): ChildProcess; 994 | 995 | export interface ExecFileOptions { 996 | cwd?: string; 997 | env?: any; 998 | timeout?: number; 999 | maxBuffer?: number; 1000 | killSignal?: string; 1001 | uid?: number; 1002 | gid?: number; 1003 | } 1004 | export interface ExecFileOptionsWithStringEncoding extends ExecFileOptions { 1005 | encoding: BufferEncoding; 1006 | } 1007 | export interface ExecFileOptionsWithBufferEncoding extends ExecFileOptions { 1008 | encoding: string; // specify `null`. 1009 | } 1010 | export function execFile(file: string, callback?: (error: Error, stdout: string, stderr: string) =>void ): ChildProcess; 1011 | export function execFile(file: string, options?: ExecFileOptionsWithStringEncoding, callback?: (error: Error, stdout: string, stderr: string) =>void ): ChildProcess; 1012 | // usage. child_process.execFile("file.sh", {encoding: null as string}, (err, stdout, stderr) => {}); 1013 | export function execFile(file: string, options?: ExecFileOptionsWithBufferEncoding, callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; 1014 | export function execFile(file: string, options?: ExecFileOptions, callback?: (error: Error, stdout: string, stderr: string) =>void ): ChildProcess; 1015 | export function execFile(file: string, args?: string[], callback?: (error: Error, stdout: string, stderr: string) =>void ): ChildProcess; 1016 | export function execFile(file: string, args?: string[], options?: ExecFileOptionsWithStringEncoding, callback?: (error: Error, stdout: string, stderr: string) =>void ): ChildProcess; 1017 | // usage. child_process.execFile("file.sh", ["foo"], {encoding: null as string}, (err, stdout, stderr) => {}); 1018 | export function execFile(file: string, args?: string[], options?: ExecFileOptionsWithBufferEncoding, callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; 1019 | export function execFile(file: string, args?: string[], options?: ExecFileOptions, callback?: (error: Error, stdout: string, stderr: string) =>void ): ChildProcess; 1020 | 1021 | export interface ForkOptions { 1022 | cwd?: string; 1023 | env?: any; 1024 | execPath?: string; 1025 | execArgv?: string[]; 1026 | silent?: boolean; 1027 | uid?: number; 1028 | gid?: number; 1029 | } 1030 | export function fork(modulePath: string, args?: string[], options?: ForkOptions): ChildProcess; 1031 | 1032 | export interface SpawnSyncOptions { 1033 | cwd?: string; 1034 | input?: string | Buffer; 1035 | stdio?: any; 1036 | env?: any; 1037 | uid?: number; 1038 | gid?: number; 1039 | timeout?: number; 1040 | killSignal?: string; 1041 | maxBuffer?: number; 1042 | encoding?: string; 1043 | shell?: boolean | string; 1044 | } 1045 | export interface SpawnSyncOptionsWithStringEncoding extends SpawnSyncOptions { 1046 | encoding: BufferEncoding; 1047 | } 1048 | export interface SpawnSyncOptionsWithBufferEncoding extends SpawnSyncOptions { 1049 | encoding: string; // specify `null`. 1050 | } 1051 | export interface SpawnSyncReturns { 1052 | pid: number; 1053 | output: string[]; 1054 | stdout: T; 1055 | stderr: T; 1056 | status: number; 1057 | signal: string; 1058 | error: Error; 1059 | } 1060 | export function spawnSync(command: string): SpawnSyncReturns; 1061 | export function spawnSync(command: string, options?: SpawnSyncOptionsWithStringEncoding): SpawnSyncReturns; 1062 | export function spawnSync(command: string, options?: SpawnSyncOptionsWithBufferEncoding): SpawnSyncReturns; 1063 | export function spawnSync(command: string, options?: SpawnSyncOptions): SpawnSyncReturns; 1064 | export function spawnSync(command: string, args?: string[], options?: SpawnSyncOptionsWithStringEncoding): SpawnSyncReturns; 1065 | export function spawnSync(command: string, args?: string[], options?: SpawnSyncOptionsWithBufferEncoding): SpawnSyncReturns; 1066 | export function spawnSync(command: string, args?: string[], options?: SpawnSyncOptions): SpawnSyncReturns; 1067 | 1068 | export interface ExecSyncOptions { 1069 | cwd?: string; 1070 | input?: string | Buffer; 1071 | stdio?: any; 1072 | env?: any; 1073 | shell?: string; 1074 | uid?: number; 1075 | gid?: number; 1076 | timeout?: number; 1077 | killSignal?: string; 1078 | maxBuffer?: number; 1079 | encoding?: string; 1080 | } 1081 | export interface ExecSyncOptionsWithStringEncoding extends ExecSyncOptions { 1082 | encoding: BufferEncoding; 1083 | } 1084 | export interface ExecSyncOptionsWithBufferEncoding extends ExecSyncOptions { 1085 | encoding: string; // specify `null`. 1086 | } 1087 | export function execSync(command: string): Buffer; 1088 | export function execSync(command: string, options?: ExecSyncOptionsWithStringEncoding): string; 1089 | export function execSync(command: string, options?: ExecSyncOptionsWithBufferEncoding): Buffer; 1090 | export function execSync(command: string, options?: ExecSyncOptions): Buffer; 1091 | 1092 | export interface ExecFileSyncOptions { 1093 | cwd?: string; 1094 | input?: string | Buffer; 1095 | stdio?: any; 1096 | env?: any; 1097 | uid?: number; 1098 | gid?: number; 1099 | timeout?: number; 1100 | killSignal?: string; 1101 | maxBuffer?: number; 1102 | encoding?: string; 1103 | } 1104 | export interface ExecFileSyncOptionsWithStringEncoding extends ExecFileSyncOptions { 1105 | encoding: BufferEncoding; 1106 | } 1107 | export interface ExecFileSyncOptionsWithBufferEncoding extends ExecFileSyncOptions { 1108 | encoding: string; // specify `null`. 1109 | } 1110 | export function execFileSync(command: string): Buffer; 1111 | export function execFileSync(command: string, options?: ExecFileSyncOptionsWithStringEncoding): string; 1112 | export function execFileSync(command: string, options?: ExecFileSyncOptionsWithBufferEncoding): Buffer; 1113 | export function execFileSync(command: string, options?: ExecFileSyncOptions): Buffer; 1114 | export function execFileSync(command: string, args?: string[], options?: ExecFileSyncOptionsWithStringEncoding): string; 1115 | export function execFileSync(command: string, args?: string[], options?: ExecFileSyncOptionsWithBufferEncoding): Buffer; 1116 | export function execFileSync(command: string, args?: string[], options?: ExecFileSyncOptions): Buffer; 1117 | } 1118 | 1119 | declare module "url" { 1120 | export interface Url { 1121 | href?: string; 1122 | protocol?: string; 1123 | auth?: string; 1124 | hostname?: string; 1125 | port?: string; 1126 | host?: string; 1127 | pathname?: string; 1128 | search?: string; 1129 | query?: any; // string | Object 1130 | slashes?: boolean; 1131 | hash?: string; 1132 | path?: string; 1133 | } 1134 | 1135 | export function parse(urlStr: string, parseQueryString?: boolean , slashesDenoteHost?: boolean ): Url; 1136 | export function format(url: Url): string; 1137 | export function resolve(from: string, to: string): string; 1138 | } 1139 | 1140 | declare module "dns" { 1141 | export function lookup(domain: string, family: number, callback: (err: Error, address: string, family: number) =>void ): string; 1142 | export function lookup(domain: string, callback: (err: Error, address: string, family: number) =>void ): string; 1143 | export function resolve(domain: string, rrtype: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 1144 | export function resolve(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 1145 | export function resolve4(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 1146 | export function resolve6(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 1147 | export function resolveMx(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 1148 | export function resolveTxt(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 1149 | export function resolveSrv(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 1150 | export function resolveNs(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 1151 | export function resolveCname(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 1152 | export function reverse(ip: string, callback: (err: Error, domains: string[]) =>void ): string[]; 1153 | } 1154 | 1155 | declare module "net" { 1156 | import * as stream from "stream"; 1157 | 1158 | export interface Socket extends stream.Duplex { 1159 | // Extended base methods 1160 | write(buffer: Buffer): boolean; 1161 | write(buffer: Buffer, cb?: Function): boolean; 1162 | write(str: string, cb?: Function): boolean; 1163 | write(str: string, encoding?: string, cb?: Function): boolean; 1164 | write(str: string, encoding?: string, fd?: string): boolean; 1165 | 1166 | connect(port: number, host?: string, connectionListener?: Function): void; 1167 | connect(path: string, connectionListener?: Function): void; 1168 | bufferSize: number; 1169 | setEncoding(encoding?: string): void; 1170 | write(data: any, encoding?: string, callback?: Function): void; 1171 | destroy(): void; 1172 | pause(): void; 1173 | resume(): void; 1174 | setTimeout(timeout: number, callback?: Function): void; 1175 | setNoDelay(noDelay?: boolean): void; 1176 | setKeepAlive(enable?: boolean, initialDelay?: number): void; 1177 | address(): { port: number; family: string; address: string; }; 1178 | unref(): void; 1179 | ref(): void; 1180 | 1181 | remoteAddress: string; 1182 | remoteFamily: string; 1183 | remotePort: number; 1184 | localAddress: string; 1185 | localPort: number; 1186 | bytesRead: number; 1187 | bytesWritten: number; 1188 | 1189 | // Extended base methods 1190 | end(): void; 1191 | end(buffer: Buffer, cb?: Function): void; 1192 | end(str: string, cb?: Function): void; 1193 | end(str: string, encoding?: string, cb?: Function): void; 1194 | end(data?: any, encoding?: string): void; 1195 | } 1196 | 1197 | export var Socket: { 1198 | new (options?: { fd?: string; type?: string; allowHalfOpen?: boolean; }): Socket; 1199 | }; 1200 | 1201 | export interface ListenOptions { 1202 | port?: number; 1203 | host?: string; 1204 | backlog?: number; 1205 | path?: string; 1206 | exclusive?: boolean; 1207 | } 1208 | 1209 | export interface Server extends Socket { 1210 | listen(port: number, hostname?: string, backlog?: number, listeningListener?: Function): Server; 1211 | listen(port: number, hostname?: string, listeningListener?: Function): Server; 1212 | listen(port: number, backlog?: number, listeningListener?: Function): Server; 1213 | listen(port: number, listeningListener?: Function): Server; 1214 | listen(path: string, backlog?: number, listeningListener?: Function): Server; 1215 | listen(path: string, listeningListener?: Function): Server; 1216 | listen(handle: any, backlog?: number, listeningListener?: Function): Server; 1217 | listen(handle: any, listeningListener?: Function): Server; 1218 | listen(options: ListenOptions, listeningListener?: Function): Server; 1219 | close(callback?: Function): Server; 1220 | address(): { port: number; family: string; address: string; }; 1221 | getConnections(cb: (error: Error, count: number) => void): void; 1222 | ref(): Server; 1223 | unref(): Server; 1224 | maxConnections: number; 1225 | connections: number; 1226 | } 1227 | export function createServer(connectionListener?: (socket: Socket) =>void ): Server; 1228 | export function createServer(options?: { allowHalfOpen?: boolean; }, connectionListener?: (socket: Socket) =>void ): Server; 1229 | export function connect(options: { port: number, host?: string, localAddress? : string, localPort? : string, family? : number, allowHalfOpen?: boolean; }, connectionListener?: Function): Socket; 1230 | export function connect(port: number, host?: string, connectionListener?: Function): Socket; 1231 | export function connect(path: string, connectionListener?: Function): Socket; 1232 | export function createConnection(options: { port: number, host?: string, localAddress? : string, localPort? : string, family? : number, allowHalfOpen?: boolean; }, connectionListener?: Function): Socket; 1233 | export function createConnection(port: number, host?: string, connectionListener?: Function): Socket; 1234 | export function createConnection(path: string, connectionListener?: Function): Socket; 1235 | export function isIP(input: string): number; 1236 | export function isIPv4(input: string): boolean; 1237 | export function isIPv6(input: string): boolean; 1238 | } 1239 | 1240 | declare module "dgram" { 1241 | import * as events from "events"; 1242 | 1243 | interface RemoteInfo { 1244 | address: string; 1245 | port: number; 1246 | size: number; 1247 | } 1248 | 1249 | interface AddressInfo { 1250 | address: string; 1251 | family: string; 1252 | port: number; 1253 | } 1254 | 1255 | export function createSocket(type: string, callback?: (msg: Buffer, rinfo: RemoteInfo) => void): Socket; 1256 | 1257 | interface Socket extends events.EventEmitter { 1258 | send(buf: Buffer, offset: number, length: number, port: number, address: string, callback?: (error: Error, bytes: number) => void): void; 1259 | bind(port: number, address?: string, callback?: () => void): void; 1260 | close(): void; 1261 | address(): AddressInfo; 1262 | setBroadcast(flag: boolean): void; 1263 | setMulticastTTL(ttl: number): void; 1264 | setMulticastLoopback(flag: boolean): void; 1265 | addMembership(multicastAddress: string, multicastInterface?: string): void; 1266 | dropMembership(multicastAddress: string, multicastInterface?: string): void; 1267 | } 1268 | } 1269 | 1270 | declare module "fs" { 1271 | import * as stream from "stream"; 1272 | import * as events from "events"; 1273 | 1274 | interface Stats { 1275 | isFile(): boolean; 1276 | isDirectory(): boolean; 1277 | isBlockDevice(): boolean; 1278 | isCharacterDevice(): boolean; 1279 | isSymbolicLink(): boolean; 1280 | isFIFO(): boolean; 1281 | isSocket(): boolean; 1282 | dev: number; 1283 | ino: number; 1284 | mode: number; 1285 | nlink: number; 1286 | uid: number; 1287 | gid: number; 1288 | rdev: number; 1289 | size: number; 1290 | blksize: number; 1291 | blocks: number; 1292 | atime: Date; 1293 | mtime: Date; 1294 | ctime: Date; 1295 | birthtime: Date; 1296 | } 1297 | 1298 | interface FSWatcher extends events.EventEmitter { 1299 | close(): void; 1300 | } 1301 | 1302 | export interface ReadStream extends stream.Readable { 1303 | close(): void; 1304 | } 1305 | export interface WriteStream extends stream.Writable { 1306 | close(): void; 1307 | bytesWritten: number; 1308 | } 1309 | 1310 | /** 1311 | * Asynchronous rename. 1312 | * @param oldPath 1313 | * @param newPath 1314 | * @param callback No arguments other than a possible exception are given to the completion callback. 1315 | */ 1316 | export function rename(oldPath: string, newPath: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1317 | /** 1318 | * Synchronous rename 1319 | * @param oldPath 1320 | * @param newPath 1321 | */ 1322 | export function renameSync(oldPath: string, newPath: string): void; 1323 | export function truncate(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1324 | export function truncate(path: string, len: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1325 | export function truncateSync(path: string, len?: number): void; 1326 | export function ftruncate(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1327 | export function ftruncate(fd: number, len: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1328 | export function ftruncateSync(fd: number, len?: number): void; 1329 | export function chown(path: string, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1330 | export function chownSync(path: string, uid: number, gid: number): void; 1331 | export function fchown(fd: number, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1332 | export function fchownSync(fd: number, uid: number, gid: number): void; 1333 | export function lchown(path: string, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1334 | export function lchownSync(path: string, uid: number, gid: number): void; 1335 | export function chmod(path: string, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1336 | export function chmod(path: string, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1337 | export function chmodSync(path: string, mode: number): void; 1338 | export function chmodSync(path: string, mode: string): void; 1339 | export function fchmod(fd: number, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1340 | export function fchmod(fd: number, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1341 | export function fchmodSync(fd: number, mode: number): void; 1342 | export function fchmodSync(fd: number, mode: string): void; 1343 | export function lchmod(path: string, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1344 | export function lchmod(path: string, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1345 | export function lchmodSync(path: string, mode: number): void; 1346 | export function lchmodSync(path: string, mode: string): void; 1347 | export function stat(path: string, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void; 1348 | export function lstat(path: string, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void; 1349 | export function fstat(fd: number, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void; 1350 | export function statSync(path: string): Stats; 1351 | export function lstatSync(path: string): Stats; 1352 | export function fstatSync(fd: number): Stats; 1353 | export function link(srcpath: string, dstpath: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1354 | export function linkSync(srcpath: string, dstpath: string): void; 1355 | export function symlink(srcpath: string, dstpath: string, type?: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1356 | export function symlinkSync(srcpath: string, dstpath: string, type?: string): void; 1357 | export function readlink(path: string, callback?: (err: NodeJS.ErrnoException, linkString: string) => any): void; 1358 | export function readlinkSync(path: string): string; 1359 | export function realpath(path: string, callback?: (err: NodeJS.ErrnoException, resolvedPath: string) => any): void; 1360 | export function realpath(path: string, cache: {[path: string]: string}, callback: (err: NodeJS.ErrnoException, resolvedPath: string) =>any): void; 1361 | export function realpathSync(path: string, cache?: { [path: string]: string }): string; 1362 | /* 1363 | * Asynchronous unlink - deletes the file specified in {path} 1364 | * 1365 | * @param path 1366 | * @param callback No arguments other than a possible exception are given to the completion callback. 1367 | */ 1368 | export function unlink(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1369 | /* 1370 | * Synchronous unlink - deletes the file specified in {path} 1371 | * 1372 | * @param path 1373 | */ 1374 | export function unlinkSync(path: string): void; 1375 | /* 1376 | * Asynchronous rmdir - removes the directory specified in {path} 1377 | * 1378 | * @param path 1379 | * @param callback No arguments other than a possible exception are given to the completion callback. 1380 | */ 1381 | export function rmdir(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1382 | /* 1383 | * Synchronous rmdir - removes the directory specified in {path} 1384 | * 1385 | * @param path 1386 | */ 1387 | export function rmdirSync(path: string): void; 1388 | /* 1389 | * Asynchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777. 1390 | * 1391 | * @param path 1392 | * @param callback No arguments other than a possible exception are given to the completion callback. 1393 | */ 1394 | export function mkdir(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1395 | /* 1396 | * Asynchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777. 1397 | * 1398 | * @param path 1399 | * @param mode 1400 | * @param callback No arguments other than a possible exception are given to the completion callback. 1401 | */ 1402 | export function mkdir(path: string, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1403 | /* 1404 | * Asynchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777. 1405 | * 1406 | * @param path 1407 | * @param mode 1408 | * @param callback No arguments other than a possible exception are given to the completion callback. 1409 | */ 1410 | export function mkdir(path: string, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1411 | /* 1412 | * Synchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777. 1413 | * 1414 | * @param path 1415 | * @param mode 1416 | * @param callback No arguments other than a possible exception are given to the completion callback. 1417 | */ 1418 | export function mkdirSync(path: string, mode?: number): void; 1419 | /* 1420 | * Synchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777. 1421 | * 1422 | * @param path 1423 | * @param mode 1424 | * @param callback No arguments other than a possible exception are given to the completion callback. 1425 | */ 1426 | export function mkdirSync(path: string, mode?: string): void; 1427 | export function readdir(path: string, callback?: (err: NodeJS.ErrnoException, files: string[]) => void): void; 1428 | export function readdirSync(path: string): string[]; 1429 | export function close(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1430 | export function closeSync(fd: number): void; 1431 | export function open(path: string, flags: string, callback?: (err: NodeJS.ErrnoException, fd: number) => any): void; 1432 | export function open(path: string, flags: string, mode: number, callback?: (err: NodeJS.ErrnoException, fd: number) => any): void; 1433 | export function open(path: string, flags: string, mode: string, callback?: (err: NodeJS.ErrnoException, fd: number) => any): void; 1434 | export function openSync(path: string, flags: string, mode?: number): number; 1435 | export function openSync(path: string, flags: string, mode?: string): number; 1436 | export function utimes(path: string, atime: number, mtime: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1437 | export function utimes(path: string, atime: Date, mtime: Date, callback?: (err?: NodeJS.ErrnoException) => void): void; 1438 | export function utimesSync(path: string, atime: number, mtime: number): void; 1439 | export function utimesSync(path: string, atime: Date, mtime: Date): void; 1440 | export function futimes(fd: number, atime: number, mtime: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1441 | export function futimes(fd: number, atime: Date, mtime: Date, callback?: (err?: NodeJS.ErrnoException) => void): void; 1442 | export function futimesSync(fd: number, atime: number, mtime: number): void; 1443 | export function futimesSync(fd: number, atime: Date, mtime: Date): void; 1444 | export function fsync(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1445 | export function fsyncSync(fd: number): void; 1446 | export function write(fd: number, buffer: Buffer, offset: number, length: number, position: number, callback?: (err: NodeJS.ErrnoException, written: number, buffer: Buffer) => void): void; 1447 | export function write(fd: number, buffer: Buffer, offset: number, length: number, callback?: (err: NodeJS.ErrnoException, written: number, buffer: Buffer) => void): void; 1448 | export function write(fd: number, data: any, callback?: (err: NodeJS.ErrnoException, written: number, str: string) => void): void; 1449 | export function write(fd: number, data: any, offset: number, callback?: (err: NodeJS.ErrnoException, written: number, str: string) => void): void; 1450 | export function write(fd: number, data: any, offset: number, encoding: string, callback?: (err: NodeJS.ErrnoException, written: number, str: string) => void): void; 1451 | export function writeSync(fd: number, buffer: Buffer, offset: number, length: number, position?: number): number; 1452 | export function writeSync(fd: number, data: any, position?: number, enconding?: string): number; 1453 | export function read(fd: number, buffer: Buffer, offset: number, length: number, position: number, callback?: (err: NodeJS.ErrnoException, bytesRead: number, buffer: Buffer) => void): void; 1454 | export function readSync(fd: number, buffer: Buffer, offset: number, length: number, position: number): number; 1455 | /* 1456 | * Asynchronous readFile - Asynchronously reads the entire contents of a file. 1457 | * 1458 | * @param fileName 1459 | * @param encoding 1460 | * @param callback - The callback is passed two arguments (err, data), where data is the contents of the file. 1461 | */ 1462 | export function readFile(filename: string, encoding: string, callback: (err: NodeJS.ErrnoException, data: string) => void): void; 1463 | /* 1464 | * Asynchronous readFile - Asynchronously reads the entire contents of a file. 1465 | * 1466 | * @param fileName 1467 | * @param options An object with optional {encoding} and {flag} properties. If {encoding} is specified, readFile returns a string; otherwise it returns a Buffer. 1468 | * @param callback - The callback is passed two arguments (err, data), where data is the contents of the file. 1469 | */ 1470 | export function readFile(filename: string, options: { encoding: string; flag?: string; }, callback: (err: NodeJS.ErrnoException, data: string) => void): void; 1471 | /* 1472 | * Asynchronous readFile - Asynchronously reads the entire contents of a file. 1473 | * 1474 | * @param fileName 1475 | * @param options An object with optional {encoding} and {flag} properties. If {encoding} is specified, readFile returns a string; otherwise it returns a Buffer. 1476 | * @param callback - The callback is passed two arguments (err, data), where data is the contents of the file. 1477 | */ 1478 | export function readFile(filename: string, options: { flag?: string; }, callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void; 1479 | /* 1480 | * Asynchronous readFile - Asynchronously reads the entire contents of a file. 1481 | * 1482 | * @param fileName 1483 | * @param callback - The callback is passed two arguments (err, data), where data is the contents of the file. 1484 | */ 1485 | export function readFile(filename: string, callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void; 1486 | /* 1487 | * Synchronous readFile - Synchronously reads the entire contents of a file. 1488 | * 1489 | * @param fileName 1490 | * @param encoding 1491 | */ 1492 | export function readFileSync(filename: string, encoding: string): string; 1493 | /* 1494 | * Synchronous readFile - Synchronously reads the entire contents of a file. 1495 | * 1496 | * @param fileName 1497 | * @param options An object with optional {encoding} and {flag} properties. If {encoding} is specified, readFileSync returns a string; otherwise it returns a Buffer. 1498 | */ 1499 | export function readFileSync(filename: string, options: { encoding: string; flag?: string; }): string; 1500 | /* 1501 | * Synchronous readFile - Synchronously reads the entire contents of a file. 1502 | * 1503 | * @param fileName 1504 | * @param options An object with optional {encoding} and {flag} properties. If {encoding} is specified, readFileSync returns a string; otherwise it returns a Buffer. 1505 | */ 1506 | export function readFileSync(filename: string, options?: { flag?: string; }): Buffer; 1507 | export function writeFile(filename: string, data: any, callback?: (err: NodeJS.ErrnoException) => void): void; 1508 | export function writeFile(filename: string, data: any, options: { encoding?: string; mode?: number; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; 1509 | export function writeFile(filename: string, data: any, options: { encoding?: string; mode?: string; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; 1510 | export function writeFileSync(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; }): void; 1511 | export function writeFileSync(filename: string, data: any, options?: { encoding?: string; mode?: string; flag?: string; }): void; 1512 | export function appendFile(filename: string, data: any, options: { encoding?: string; mode?: number; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; 1513 | export function appendFile(filename: string, data: any, options: { encoding?: string; mode?: string; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; 1514 | export function appendFile(filename: string, data: any, callback?: (err: NodeJS.ErrnoException) => void): void; 1515 | export function appendFileSync(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; }): void; 1516 | export function appendFileSync(filename: string, data: any, options?: { encoding?: string; mode?: string; flag?: string; }): void; 1517 | export function watchFile(filename: string, listener: (curr: Stats, prev: Stats) => void): void; 1518 | export function watchFile(filename: string, options: { persistent?: boolean; interval?: number; }, listener: (curr: Stats, prev: Stats) => void): void; 1519 | export function unwatchFile(filename: string, listener?: (curr: Stats, prev: Stats) => void): void; 1520 | export function watch(filename: string, listener?: (event: string, filename: string) => any): FSWatcher; 1521 | export function watch(filename: string, options: { persistent?: boolean; }, listener?: (event: string, filename: string) => any): FSWatcher; 1522 | export function exists(path: string, callback?: (exists: boolean) => void): void; 1523 | export function existsSync(path: string): boolean; 1524 | /** Constant for fs.access(). File is visible to the calling process. */ 1525 | export var F_OK: number; 1526 | /** Constant for fs.access(). File can be read by the calling process. */ 1527 | export var R_OK: number; 1528 | /** Constant for fs.access(). File can be written by the calling process. */ 1529 | export var W_OK: number; 1530 | /** Constant for fs.access(). File can be executed by the calling process. */ 1531 | export var X_OK: number; 1532 | /** Tests a user's permissions for the file specified by path. */ 1533 | export function access(path: string, callback: (err: NodeJS.ErrnoException) => void): void; 1534 | export function access(path: string, mode: number, callback: (err: NodeJS.ErrnoException) => void): void; 1535 | /** Synchronous version of fs.access. This throws if any accessibility checks fail, and does nothing otherwise. */ 1536 | export function accessSync(path: string, mode ?: number): void; 1537 | export function createReadStream(path: string, options?: { 1538 | flags?: string; 1539 | encoding?: string; 1540 | fd?: number; 1541 | mode?: number; 1542 | autoClose?: boolean; 1543 | }): ReadStream; 1544 | export function createWriteStream(path: string, options?: { 1545 | flags?: string; 1546 | encoding?: string; 1547 | fd?: number; 1548 | mode?: number; 1549 | }): WriteStream; 1550 | } 1551 | 1552 | declare module "path" { 1553 | 1554 | /** 1555 | * A parsed path object generated by path.parse() or consumed by path.format(). 1556 | */ 1557 | export interface ParsedPath { 1558 | /** 1559 | * The root of the path such as '/' or 'c:\' 1560 | */ 1561 | root: string; 1562 | /** 1563 | * The full directory path such as '/home/user/dir' or 'c:\path\dir' 1564 | */ 1565 | dir: string; 1566 | /** 1567 | * The file name including extension (if any) such as 'index.html' 1568 | */ 1569 | base: string; 1570 | /** 1571 | * The file extension (if any) such as '.html' 1572 | */ 1573 | ext: string; 1574 | /** 1575 | * The file name without extension (if any) such as 'index' 1576 | */ 1577 | name: string; 1578 | } 1579 | 1580 | /** 1581 | * Normalize a string path, reducing '..' and '.' parts. 1582 | * When multiple slashes are found, they're replaced by a single one; when the path contains a trailing slash, it is preserved. On Windows backslashes are used. 1583 | * 1584 | * @param p string path to normalize. 1585 | */ 1586 | export function normalize(p: string): string; 1587 | /** 1588 | * Join all arguments together and normalize the resulting path. 1589 | * Arguments must be strings. In v0.8, non-string arguments were silently ignored. In v0.10 and up, an exception is thrown. 1590 | * 1591 | * @param paths string paths to join. 1592 | */ 1593 | export function join(...paths: any[]): string; 1594 | /** 1595 | * Join all arguments together and normalize the resulting path. 1596 | * Arguments must be strings. In v0.8, non-string arguments were silently ignored. In v0.10 and up, an exception is thrown. 1597 | * 1598 | * @param paths string paths to join. 1599 | */ 1600 | export function join(...paths: string[]): string; 1601 | /** 1602 | * The right-most parameter is considered {to}. Other parameters are considered an array of {from}. 1603 | * 1604 | * Starting from leftmost {from} paramter, resolves {to} to an absolute path. 1605 | * 1606 | * If {to} isn't already absolute, {from} arguments are prepended in right to left order, until an absolute path is found. If after using all {from} paths still no absolute path is found, the current working directory is used as well. The resulting path is normalized, and trailing slashes are removed unless the path gets resolved to the root directory. 1607 | * 1608 | * @param pathSegments string paths to join. Non-string arguments are ignored. 1609 | */ 1610 | export function resolve(...pathSegments: any[]): string; 1611 | /** 1612 | * Determines whether {path} is an absolute path. An absolute path will always resolve to the same location, regardless of the working directory. 1613 | * 1614 | * @param path path to test. 1615 | */ 1616 | export function isAbsolute(path: string): boolean; 1617 | /** 1618 | * Solve the relative path from {from} to {to}. 1619 | * At times we have two absolute paths, and we need to derive the relative path from one to the other. This is actually the reverse transform of path.resolve. 1620 | * 1621 | * @param from 1622 | * @param to 1623 | */ 1624 | export function relative(from: string, to: string): string; 1625 | /** 1626 | * Return the directory name of a path. Similar to the Unix dirname command. 1627 | * 1628 | * @param p the path to evaluate. 1629 | */ 1630 | export function dirname(p: string): string; 1631 | /** 1632 | * Return the last portion of a path. Similar to the Unix basename command. 1633 | * Often used to extract the file name from a fully qualified path. 1634 | * 1635 | * @param p the path to evaluate. 1636 | * @param ext optionally, an extension to remove from the result. 1637 | */ 1638 | export function basename(p: string, ext?: string): string; 1639 | /** 1640 | * Return the extension of the path, from the last '.' to end of string in the last portion of the path. 1641 | * If there is no '.' in the last portion of the path or the first character of it is '.', then it returns an empty string 1642 | * 1643 | * @param p the path to evaluate. 1644 | */ 1645 | export function extname(p: string): string; 1646 | /** 1647 | * The platform-specific file separator. '\\' or '/'. 1648 | */ 1649 | export var sep: string; 1650 | /** 1651 | * The platform-specific file delimiter. ';' or ':'. 1652 | */ 1653 | export var delimiter: string; 1654 | /** 1655 | * Returns an object from a path string - the opposite of format(). 1656 | * 1657 | * @param pathString path to evaluate. 1658 | */ 1659 | export function parse(pathString: string): ParsedPath; 1660 | /** 1661 | * Returns a path string from an object - the opposite of parse(). 1662 | * 1663 | * @param pathString path to evaluate. 1664 | */ 1665 | export function format(pathObject: ParsedPath): string; 1666 | 1667 | export module posix { 1668 | export function normalize(p: string): string; 1669 | export function join(...paths: any[]): string; 1670 | export function resolve(...pathSegments: any[]): string; 1671 | export function isAbsolute(p: string): boolean; 1672 | export function relative(from: string, to: string): string; 1673 | export function dirname(p: string): string; 1674 | export function basename(p: string, ext?: string): string; 1675 | export function extname(p: string): string; 1676 | export var sep: string; 1677 | export var delimiter: string; 1678 | export function parse(p: string): ParsedPath; 1679 | export function format(pP: ParsedPath): string; 1680 | } 1681 | 1682 | export module win32 { 1683 | export function normalize(p: string): string; 1684 | export function join(...paths: any[]): string; 1685 | export function resolve(...pathSegments: any[]): string; 1686 | export function isAbsolute(p: string): boolean; 1687 | export function relative(from: string, to: string): string; 1688 | export function dirname(p: string): string; 1689 | export function basename(p: string, ext?: string): string; 1690 | export function extname(p: string): string; 1691 | export var sep: string; 1692 | export var delimiter: string; 1693 | export function parse(p: string): ParsedPath; 1694 | export function format(pP: ParsedPath): string; 1695 | } 1696 | } 1697 | 1698 | declare module "string_decoder" { 1699 | export interface NodeStringDecoder { 1700 | write(buffer: Buffer): string; 1701 | detectIncompleteChar(buffer: Buffer): number; 1702 | } 1703 | export var StringDecoder: { 1704 | new (encoding: string): NodeStringDecoder; 1705 | }; 1706 | } 1707 | 1708 | declare module "tls" { 1709 | import * as crypto from "crypto"; 1710 | import * as net from "net"; 1711 | import * as stream from "stream"; 1712 | 1713 | var CLIENT_RENEG_LIMIT: number; 1714 | var CLIENT_RENEG_WINDOW: number; 1715 | 1716 | export interface TlsOptions { 1717 | host?: string; 1718 | port?: number; 1719 | pfx?: any; //string or buffer 1720 | key?: any; //string or buffer 1721 | passphrase?: string; 1722 | cert?: any; 1723 | ca?: any; //string or buffer 1724 | crl?: any; //string or string array 1725 | ciphers?: string; 1726 | honorCipherOrder?: any; 1727 | requestCert?: boolean; 1728 | rejectUnauthorized?: boolean; 1729 | NPNProtocols?: any; //array or Buffer; 1730 | SNICallback?: (servername: string) => any; 1731 | } 1732 | 1733 | export interface ConnectionOptions { 1734 | host?: string; 1735 | port?: number; 1736 | socket?: net.Socket; 1737 | pfx?: any; //string | Buffer 1738 | key?: any; //string | Buffer 1739 | passphrase?: string; 1740 | cert?: any; //string | Buffer 1741 | ca?: any; //Array of string | Buffer 1742 | rejectUnauthorized?: boolean; 1743 | NPNProtocols?: any; //Array of string | Buffer 1744 | servername?: string; 1745 | } 1746 | 1747 | export interface Server extends net.Server { 1748 | close(): Server; 1749 | address(): { port: number; family: string; address: string; }; 1750 | addContext(hostName: string, credentials: { 1751 | key: string; 1752 | cert: string; 1753 | ca: string; 1754 | }): void; 1755 | maxConnections: number; 1756 | connections: number; 1757 | } 1758 | 1759 | export interface ClearTextStream extends stream.Duplex { 1760 | authorized: boolean; 1761 | authorizationError: Error; 1762 | getPeerCertificate(): any; 1763 | getCipher: { 1764 | name: string; 1765 | version: string; 1766 | }; 1767 | address: { 1768 | port: number; 1769 | family: string; 1770 | address: string; 1771 | }; 1772 | remoteAddress: string; 1773 | remotePort: number; 1774 | } 1775 | 1776 | export interface SecurePair { 1777 | encrypted: any; 1778 | cleartext: any; 1779 | } 1780 | 1781 | export interface SecureContextOptions { 1782 | pfx?: any; //string | buffer 1783 | key?: any; //string | buffer 1784 | passphrase?: string; 1785 | cert?: any; // string | buffer 1786 | ca?: any; // string | buffer 1787 | crl?: any; // string | string[] 1788 | ciphers?: string; 1789 | honorCipherOrder?: boolean; 1790 | } 1791 | 1792 | export interface SecureContext { 1793 | context: any; 1794 | } 1795 | 1796 | export function createServer(options: TlsOptions, secureConnectionListener?: (cleartextStream: ClearTextStream) =>void ): Server; 1797 | export function connect(options: TlsOptions, secureConnectionListener?: () =>void ): ClearTextStream; 1798 | export function connect(port: number, host?: string, options?: ConnectionOptions, secureConnectListener?: () =>void ): ClearTextStream; 1799 | export function connect(port: number, options?: ConnectionOptions, secureConnectListener?: () =>void ): ClearTextStream; 1800 | export function createSecurePair(credentials?: crypto.Credentials, isServer?: boolean, requestCert?: boolean, rejectUnauthorized?: boolean): SecurePair; 1801 | export function createSecureContext(details: SecureContextOptions): SecureContext; 1802 | } 1803 | 1804 | declare module "crypto" { 1805 | export interface CredentialDetails { 1806 | pfx: string; 1807 | key: string; 1808 | passphrase: string; 1809 | cert: string; 1810 | ca: any; //string | string array 1811 | crl: any; //string | string array 1812 | ciphers: string; 1813 | } 1814 | export interface Credentials { context?: any; } 1815 | export function createCredentials(details: CredentialDetails): Credentials; 1816 | export function createHash(algorithm: string): Hash; 1817 | export function createHmac(algorithm: string, key: string): Hmac; 1818 | export function createHmac(algorithm: string, key: Buffer): Hmac; 1819 | export interface Hash { 1820 | update(data: any, input_encoding?: string): Hash; 1821 | digest(encoding: 'buffer'): Buffer; 1822 | digest(encoding: string): any; 1823 | digest(): Buffer; 1824 | } 1825 | export interface Hmac extends NodeJS.ReadWriteStream { 1826 | update(data: any, input_encoding?: string): Hmac; 1827 | digest(encoding: 'buffer'): Buffer; 1828 | digest(encoding: string): any; 1829 | digest(): Buffer; 1830 | } 1831 | export function createCipher(algorithm: string, password: any): Cipher; 1832 | export function createCipheriv(algorithm: string, key: any, iv: any): Cipher; 1833 | export interface Cipher extends NodeJS.ReadWriteStream { 1834 | update(data: Buffer): Buffer; 1835 | update(data: string, input_encoding: "utf8"|"ascii"|"binary"): Buffer; 1836 | update(data: Buffer, input_encoding: any, output_encoding: "binary"|"base64"|"hex"): string; 1837 | update(data: string, input_encoding: "utf8"|"ascii"|"binary", output_encoding: "binary"|"base64"|"hex"): string; 1838 | final(): Buffer; 1839 | final(output_encoding: string): string; 1840 | setAutoPadding(auto_padding: boolean): void; 1841 | getAuthTag(): Buffer; 1842 | } 1843 | export function createDecipher(algorithm: string, password: any): Decipher; 1844 | export function createDecipheriv(algorithm: string, key: any, iv: any): Decipher; 1845 | export interface Decipher extends NodeJS.ReadWriteStream { 1846 | update(data: Buffer): Buffer; 1847 | update(data: string, input_encoding: "binary"|"base64"|"hex"): Buffer; 1848 | update(data: Buffer, input_encoding: any, output_encoding: "utf8"|"ascii"|"binary"): string; 1849 | update(data: string, input_encoding: "binary"|"base64"|"hex", output_encoding: "utf8"|"ascii"|"binary"): string; 1850 | final(): Buffer; 1851 | final(output_encoding: string): string; 1852 | setAutoPadding(auto_padding: boolean): void; 1853 | setAuthTag(tag: Buffer): void; 1854 | } 1855 | export function createSign(algorithm: string): Signer; 1856 | export interface Signer extends NodeJS.WritableStream { 1857 | update(data: any): void; 1858 | sign(private_key: string, output_format: string): string; 1859 | } 1860 | export function createVerify(algorith: string): Verify; 1861 | export interface Verify extends NodeJS.WritableStream { 1862 | update(data: any): void; 1863 | verify(object: string, signature: string, signature_format?: string): boolean; 1864 | } 1865 | export function createDiffieHellman(prime_length: number): DiffieHellman; 1866 | export function createDiffieHellman(prime: number, encoding?: string): DiffieHellman; 1867 | export interface DiffieHellman { 1868 | generateKeys(encoding?: string): string; 1869 | computeSecret(other_public_key: string, input_encoding?: string, output_encoding?: string): string; 1870 | getPrime(encoding?: string): string; 1871 | getGenerator(encoding: string): string; 1872 | getPublicKey(encoding?: string): string; 1873 | getPrivateKey(encoding?: string): string; 1874 | setPublicKey(public_key: string, encoding?: string): void; 1875 | setPrivateKey(public_key: string, encoding?: string): void; 1876 | } 1877 | export function getDiffieHellman(group_name: string): DiffieHellman; 1878 | export function pbkdf2(password: string|Buffer, salt: string|Buffer, iterations: number, keylen: number, callback: (err: Error, derivedKey: Buffer) => any): void; 1879 | export function pbkdf2(password: string|Buffer, salt: string|Buffer, iterations: number, keylen: number, digest: string, callback: (err: Error, derivedKey: Buffer) => any): void; 1880 | export function pbkdf2Sync(password: string|Buffer, salt: string|Buffer, iterations: number, keylen: number) : Buffer; 1881 | export function pbkdf2Sync(password: string|Buffer, salt: string|Buffer, iterations: number, keylen: number, digest: string) : Buffer; 1882 | export function randomBytes(size: number): Buffer; 1883 | export function randomBytes(size: number, callback: (err: Error, buf: Buffer) =>void ): void; 1884 | export function pseudoRandomBytes(size: number): Buffer; 1885 | export function pseudoRandomBytes(size: number, callback: (err: Error, buf: Buffer) =>void ): void; 1886 | export interface RsaPublicKey { 1887 | key: string; 1888 | padding?: any; 1889 | } 1890 | export interface RsaPrivateKey { 1891 | key: string; 1892 | passphrase?: string, 1893 | padding?: any; 1894 | } 1895 | export function publicEncrypt(public_key: string|RsaPublicKey, buffer: Buffer): Buffer 1896 | export function privateDecrypt(private_key: string|RsaPrivateKey, buffer: Buffer): Buffer 1897 | } 1898 | 1899 | declare module "stream" { 1900 | import * as events from "events"; 1901 | 1902 | export class Stream extends events.EventEmitter { 1903 | pipe(destination: T, options?: { end?: boolean; }): T; 1904 | } 1905 | 1906 | export interface ReadableOptions { 1907 | highWaterMark?: number; 1908 | encoding?: string; 1909 | objectMode?: boolean; 1910 | } 1911 | 1912 | export class Readable extends events.EventEmitter implements NodeJS.ReadableStream { 1913 | readable: boolean; 1914 | constructor(opts?: ReadableOptions); 1915 | _read(size: number): void; 1916 | read(size?: number): any; 1917 | setEncoding(encoding: string): void; 1918 | pause(): void; 1919 | resume(): void; 1920 | pipe(destination: T, options?: { end?: boolean; }): T; 1921 | unpipe(destination?: T): void; 1922 | unshift(chunk: any): void; 1923 | wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream; 1924 | push(chunk: any, encoding?: string): boolean; 1925 | } 1926 | 1927 | export interface WritableOptions { 1928 | highWaterMark?: number; 1929 | decodeStrings?: boolean; 1930 | objectMode?: boolean; 1931 | } 1932 | 1933 | export class Writable extends events.EventEmitter implements NodeJS.WritableStream { 1934 | writable: boolean; 1935 | constructor(opts?: WritableOptions); 1936 | _write(chunk: any, encoding: string, callback: Function): void; 1937 | write(chunk: any, cb?: Function): boolean; 1938 | write(chunk: any, encoding?: string, cb?: Function): boolean; 1939 | end(): void; 1940 | end(chunk: any, cb?: Function): void; 1941 | end(chunk: any, encoding?: string, cb?: Function): void; 1942 | } 1943 | 1944 | export interface DuplexOptions extends ReadableOptions, WritableOptions { 1945 | allowHalfOpen?: boolean; 1946 | } 1947 | 1948 | // Note: Duplex extends both Readable and Writable. 1949 | export class Duplex extends Readable implements NodeJS.ReadWriteStream { 1950 | writable: boolean; 1951 | constructor(opts?: DuplexOptions); 1952 | _write(chunk: any, encoding: string, callback: Function): void; 1953 | write(chunk: any, cb?: Function): boolean; 1954 | write(chunk: any, encoding?: string, cb?: Function): boolean; 1955 | end(): void; 1956 | end(chunk: any, cb?: Function): void; 1957 | end(chunk: any, encoding?: string, cb?: Function): void; 1958 | } 1959 | 1960 | export interface TransformOptions extends ReadableOptions, WritableOptions {} 1961 | 1962 | // Note: Transform lacks the _read and _write methods of Readable/Writable. 1963 | export class Transform extends events.EventEmitter implements NodeJS.ReadWriteStream { 1964 | readable: boolean; 1965 | writable: boolean; 1966 | constructor(opts?: TransformOptions); 1967 | _transform(chunk: any, encoding: string, callback: Function): void; 1968 | _flush(callback: Function): void; 1969 | read(size?: number): any; 1970 | setEncoding(encoding: string): void; 1971 | pause(): void; 1972 | resume(): void; 1973 | pipe(destination: T, options?: { end?: boolean; }): T; 1974 | unpipe(destination?: T): void; 1975 | unshift(chunk: any): void; 1976 | wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream; 1977 | push(chunk: any, encoding?: string): boolean; 1978 | write(chunk: any, cb?: Function): boolean; 1979 | write(chunk: any, encoding?: string, cb?: Function): boolean; 1980 | end(): void; 1981 | end(chunk: any, cb?: Function): void; 1982 | end(chunk: any, encoding?: string, cb?: Function): void; 1983 | } 1984 | 1985 | export class PassThrough extends Transform {} 1986 | } 1987 | 1988 | declare module "util" { 1989 | export interface InspectOptions { 1990 | showHidden?: boolean; 1991 | depth?: number; 1992 | colors?: boolean; 1993 | customInspect?: boolean; 1994 | } 1995 | 1996 | export function format(format: any, ...param: any[]): string; 1997 | export function debug(string: string): void; 1998 | export function error(...param: any[]): void; 1999 | export function puts(...param: any[]): void; 2000 | export function print(...param: any[]): void; 2001 | export function log(string: string): void; 2002 | export function inspect(object: any, showHidden?: boolean, depth?: number, color?: boolean): string; 2003 | export function inspect(object: any, options: InspectOptions): string; 2004 | export function isArray(object: any): boolean; 2005 | export function isRegExp(object: any): boolean; 2006 | export function isDate(object: any): boolean; 2007 | export function isError(object: any): boolean; 2008 | export function inherits(constructor: any, superConstructor: any): void; 2009 | export function debuglog(key:string): (msg:string,...param: any[])=>void; 2010 | } 2011 | 2012 | declare module "assert" { 2013 | function internal (value: any, message?: string): void; 2014 | namespace internal { 2015 | export class AssertionError implements Error { 2016 | name: string; 2017 | message: string; 2018 | actual: any; 2019 | expected: any; 2020 | operator: string; 2021 | generatedMessage: boolean; 2022 | 2023 | constructor(options?: {message?: string; actual?: any; expected?: any; 2024 | operator?: string; stackStartFunction?: Function}); 2025 | } 2026 | 2027 | export function fail(actual?: any, expected?: any, message?: string, operator?: string): void; 2028 | export function ok(value: any, message?: string): void; 2029 | export function equal(actual: any, expected: any, message?: string): void; 2030 | export function notEqual(actual: any, expected: any, message?: string): void; 2031 | export function deepEqual(actual: any, expected: any, message?: string): void; 2032 | export function notDeepEqual(acutal: any, expected: any, message?: string): void; 2033 | export function strictEqual(actual: any, expected: any, message?: string): void; 2034 | export function notStrictEqual(actual: any, expected: any, message?: string): void; 2035 | export function deepStrictEqual(actual: any, expected: any, message?: string): void; 2036 | export function notDeepStrictEqual(actual: any, expected: any, message?: string): void; 2037 | export var throws: { 2038 | (block: Function, message?: string): void; 2039 | (block: Function, error: Function, message?: string): void; 2040 | (block: Function, error: RegExp, message?: string): void; 2041 | (block: Function, error: (err: any) => boolean, message?: string): void; 2042 | }; 2043 | 2044 | export var doesNotThrow: { 2045 | (block: Function, message?: string): void; 2046 | (block: Function, error: Function, message?: string): void; 2047 | (block: Function, error: RegExp, message?: string): void; 2048 | (block: Function, error: (err: any) => boolean, message?: string): void; 2049 | }; 2050 | 2051 | export function ifError(value: any): void; 2052 | } 2053 | 2054 | export = internal; 2055 | } 2056 | 2057 | declare module "tty" { 2058 | import * as net from "net"; 2059 | 2060 | export function isatty(fd: number): boolean; 2061 | export interface ReadStream extends net.Socket { 2062 | isRaw: boolean; 2063 | setRawMode(mode: boolean): void; 2064 | isTTY: boolean; 2065 | } 2066 | export interface WriteStream extends net.Socket { 2067 | columns: number; 2068 | rows: number; 2069 | isTTY: boolean; 2070 | } 2071 | } 2072 | 2073 | declare module "domain" { 2074 | import * as events from "events"; 2075 | 2076 | export class Domain extends events.EventEmitter implements NodeJS.Domain { 2077 | run(fn: Function): void; 2078 | add(emitter: events.EventEmitter): void; 2079 | remove(emitter: events.EventEmitter): void; 2080 | bind(cb: (err: Error, data: any) => any): any; 2081 | intercept(cb: (data: any) => any): any; 2082 | dispose(): void; 2083 | } 2084 | 2085 | export function create(): Domain; 2086 | } 2087 | 2088 | declare module "constants" { 2089 | export var E2BIG: number; 2090 | export var EACCES: number; 2091 | export var EADDRINUSE: number; 2092 | export var EADDRNOTAVAIL: number; 2093 | export var EAFNOSUPPORT: number; 2094 | export var EAGAIN: number; 2095 | export var EALREADY: number; 2096 | export var EBADF: number; 2097 | export var EBADMSG: number; 2098 | export var EBUSY: number; 2099 | export var ECANCELED: number; 2100 | export var ECHILD: number; 2101 | export var ECONNABORTED: number; 2102 | export var ECONNREFUSED: number; 2103 | export var ECONNRESET: number; 2104 | export var EDEADLK: number; 2105 | export var EDESTADDRREQ: number; 2106 | export var EDOM: number; 2107 | export var EEXIST: number; 2108 | export var EFAULT: number; 2109 | export var EFBIG: number; 2110 | export var EHOSTUNREACH: number; 2111 | export var EIDRM: number; 2112 | export var EILSEQ: number; 2113 | export var EINPROGRESS: number; 2114 | export var EINTR: number; 2115 | export var EINVAL: number; 2116 | export var EIO: number; 2117 | export var EISCONN: number; 2118 | export var EISDIR: number; 2119 | export var ELOOP: number; 2120 | export var EMFILE: number; 2121 | export var EMLINK: number; 2122 | export var EMSGSIZE: number; 2123 | export var ENAMETOOLONG: number; 2124 | export var ENETDOWN: number; 2125 | export var ENETRESET: number; 2126 | export var ENETUNREACH: number; 2127 | export var ENFILE: number; 2128 | export var ENOBUFS: number; 2129 | export var ENODATA: number; 2130 | export var ENODEV: number; 2131 | export var ENOENT: number; 2132 | export var ENOEXEC: number; 2133 | export var ENOLCK: number; 2134 | export var ENOLINK: number; 2135 | export var ENOMEM: number; 2136 | export var ENOMSG: number; 2137 | export var ENOPROTOOPT: number; 2138 | export var ENOSPC: number; 2139 | export var ENOSR: number; 2140 | export var ENOSTR: number; 2141 | export var ENOSYS: number; 2142 | export var ENOTCONN: number; 2143 | export var ENOTDIR: number; 2144 | export var ENOTEMPTY: number; 2145 | export var ENOTSOCK: number; 2146 | export var ENOTSUP: number; 2147 | export var ENOTTY: number; 2148 | export var ENXIO: number; 2149 | export var EOPNOTSUPP: number; 2150 | export var EOVERFLOW: number; 2151 | export var EPERM: number; 2152 | export var EPIPE: number; 2153 | export var EPROTO: number; 2154 | export var EPROTONOSUPPORT: number; 2155 | export var EPROTOTYPE: number; 2156 | export var ERANGE: number; 2157 | export var EROFS: number; 2158 | export var ESPIPE: number; 2159 | export var ESRCH: number; 2160 | export var ETIME: number; 2161 | export var ETIMEDOUT: number; 2162 | export var ETXTBSY: number; 2163 | export var EWOULDBLOCK: number; 2164 | export var EXDEV: number; 2165 | export var WSAEINTR: number; 2166 | export var WSAEBADF: number; 2167 | export var WSAEACCES: number; 2168 | export var WSAEFAULT: number; 2169 | export var WSAEINVAL: number; 2170 | export var WSAEMFILE: number; 2171 | export var WSAEWOULDBLOCK: number; 2172 | export var WSAEINPROGRESS: number; 2173 | export var WSAEALREADY: number; 2174 | export var WSAENOTSOCK: number; 2175 | export var WSAEDESTADDRREQ: number; 2176 | export var WSAEMSGSIZE: number; 2177 | export var WSAEPROTOTYPE: number; 2178 | export var WSAENOPROTOOPT: number; 2179 | export var WSAEPROTONOSUPPORT: number; 2180 | export var WSAESOCKTNOSUPPORT: number; 2181 | export var WSAEOPNOTSUPP: number; 2182 | export var WSAEPFNOSUPPORT: number; 2183 | export var WSAEAFNOSUPPORT: number; 2184 | export var WSAEADDRINUSE: number; 2185 | export var WSAEADDRNOTAVAIL: number; 2186 | export var WSAENETDOWN: number; 2187 | export var WSAENETUNREACH: number; 2188 | export var WSAENETRESET: number; 2189 | export var WSAECONNABORTED: number; 2190 | export var WSAECONNRESET: number; 2191 | export var WSAENOBUFS: number; 2192 | export var WSAEISCONN: number; 2193 | export var WSAENOTCONN: number; 2194 | export var WSAESHUTDOWN: number; 2195 | export var WSAETOOMANYREFS: number; 2196 | export var WSAETIMEDOUT: number; 2197 | export var WSAECONNREFUSED: number; 2198 | export var WSAELOOP: number; 2199 | export var WSAENAMETOOLONG: number; 2200 | export var WSAEHOSTDOWN: number; 2201 | export var WSAEHOSTUNREACH: number; 2202 | export var WSAENOTEMPTY: number; 2203 | export var WSAEPROCLIM: number; 2204 | export var WSAEUSERS: number; 2205 | export var WSAEDQUOT: number; 2206 | export var WSAESTALE: number; 2207 | export var WSAEREMOTE: number; 2208 | export var WSASYSNOTREADY: number; 2209 | export var WSAVERNOTSUPPORTED: number; 2210 | export var WSANOTINITIALISED: number; 2211 | export var WSAEDISCON: number; 2212 | export var WSAENOMORE: number; 2213 | export var WSAECANCELLED: number; 2214 | export var WSAEINVALIDPROCTABLE: number; 2215 | export var WSAEINVALIDPROVIDER: number; 2216 | export var WSAEPROVIDERFAILEDINIT: number; 2217 | export var WSASYSCALLFAILURE: number; 2218 | export var WSASERVICE_NOT_FOUND: number; 2219 | export var WSATYPE_NOT_FOUND: number; 2220 | export var WSA_E_NO_MORE: number; 2221 | export var WSA_E_CANCELLED: number; 2222 | export var WSAEREFUSED: number; 2223 | export var SIGHUP: number; 2224 | export var SIGINT: number; 2225 | export var SIGILL: number; 2226 | export var SIGABRT: number; 2227 | export var SIGFPE: number; 2228 | export var SIGKILL: number; 2229 | export var SIGSEGV: number; 2230 | export var SIGTERM: number; 2231 | export var SIGBREAK: number; 2232 | export var SIGWINCH: number; 2233 | export var SSL_OP_ALL: number; 2234 | export var SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION: number; 2235 | export var SSL_OP_CIPHER_SERVER_PREFERENCE: number; 2236 | export var SSL_OP_CISCO_ANYCONNECT: number; 2237 | export var SSL_OP_COOKIE_EXCHANGE: number; 2238 | export var SSL_OP_CRYPTOPRO_TLSEXT_BUG: number; 2239 | export var SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS: number; 2240 | export var SSL_OP_EPHEMERAL_RSA: number; 2241 | export var SSL_OP_LEGACY_SERVER_CONNECT: number; 2242 | export var SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER: number; 2243 | export var SSL_OP_MICROSOFT_SESS_ID_BUG: number; 2244 | export var SSL_OP_MSIE_SSLV2_RSA_PADDING: number; 2245 | export var SSL_OP_NETSCAPE_CA_DN_BUG: number; 2246 | export var SSL_OP_NETSCAPE_CHALLENGE_BUG: number; 2247 | export var SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG: number; 2248 | export var SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG: number; 2249 | export var SSL_OP_NO_COMPRESSION: number; 2250 | export var SSL_OP_NO_QUERY_MTU: number; 2251 | export var SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION: number; 2252 | export var SSL_OP_NO_SSLv2: number; 2253 | export var SSL_OP_NO_SSLv3: number; 2254 | export var SSL_OP_NO_TICKET: number; 2255 | export var SSL_OP_NO_TLSv1: number; 2256 | export var SSL_OP_NO_TLSv1_1: number; 2257 | export var SSL_OP_NO_TLSv1_2: number; 2258 | export var SSL_OP_PKCS1_CHECK_1: number; 2259 | export var SSL_OP_PKCS1_CHECK_2: number; 2260 | export var SSL_OP_SINGLE_DH_USE: number; 2261 | export var SSL_OP_SINGLE_ECDH_USE: number; 2262 | export var SSL_OP_SSLEAY_080_CLIENT_DH_BUG: number; 2263 | export var SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG: number; 2264 | export var SSL_OP_TLS_BLOCK_PADDING_BUG: number; 2265 | export var SSL_OP_TLS_D5_BUG: number; 2266 | export var SSL_OP_TLS_ROLLBACK_BUG: number; 2267 | export var ENGINE_METHOD_DSA: number; 2268 | export var ENGINE_METHOD_DH: number; 2269 | export var ENGINE_METHOD_RAND: number; 2270 | export var ENGINE_METHOD_ECDH: number; 2271 | export var ENGINE_METHOD_ECDSA: number; 2272 | export var ENGINE_METHOD_CIPHERS: number; 2273 | export var ENGINE_METHOD_DIGESTS: number; 2274 | export var ENGINE_METHOD_STORE: number; 2275 | export var ENGINE_METHOD_PKEY_METHS: number; 2276 | export var ENGINE_METHOD_PKEY_ASN1_METHS: number; 2277 | export var ENGINE_METHOD_ALL: number; 2278 | export var ENGINE_METHOD_NONE: number; 2279 | export var DH_CHECK_P_NOT_SAFE_PRIME: number; 2280 | export var DH_CHECK_P_NOT_PRIME: number; 2281 | export var DH_UNABLE_TO_CHECK_GENERATOR: number; 2282 | export var DH_NOT_SUITABLE_GENERATOR: number; 2283 | export var NPN_ENABLED: number; 2284 | export var RSA_PKCS1_PADDING: number; 2285 | export var RSA_SSLV23_PADDING: number; 2286 | export var RSA_NO_PADDING: number; 2287 | export var RSA_PKCS1_OAEP_PADDING: number; 2288 | export var RSA_X931_PADDING: number; 2289 | export var RSA_PKCS1_PSS_PADDING: number; 2290 | export var POINT_CONVERSION_COMPRESSED: number; 2291 | export var POINT_CONVERSION_UNCOMPRESSED: number; 2292 | export var POINT_CONVERSION_HYBRID: number; 2293 | export var O_RDONLY: number; 2294 | export var O_WRONLY: number; 2295 | export var O_RDWR: number; 2296 | export var S_IFMT: number; 2297 | export var S_IFREG: number; 2298 | export var S_IFDIR: number; 2299 | export var S_IFCHR: number; 2300 | export var S_IFLNK: number; 2301 | export var O_CREAT: number; 2302 | export var O_EXCL: number; 2303 | export var O_TRUNC: number; 2304 | export var O_APPEND: number; 2305 | export var F_OK: number; 2306 | export var R_OK: number; 2307 | export var W_OK: number; 2308 | export var X_OK: number; 2309 | export var UV_UDP_REUSEADDR: number; 2310 | } --------------------------------------------------------------------------------