├── .babelrc ├── .flowconfig ├── .gitignore ├── CNAME ├── LICENSE ├── README.md ├── examples ├── 1.js ├── 2.js ├── 3.js ├── 4.js ├── 5.js ├── 6.js ├── 7.js ├── node │ ├── 01-node-core-apis.js │ ├── 02-async.js │ ├── 03-sequelize.js │ └── 04-parse.js └── react │ ├── 01-react-propTypes.js │ └── 02-modern-react.js ├── favicon.png ├── index.html ├── js ├── flow.js ├── flow.map ├── flow.min.js ├── flowlib │ ├── bom.js │ ├── core.js │ ├── cssom.js │ ├── dom.js │ ├── indexeddb.js │ ├── node.js │ └── react.js └── worker.js └── package.json /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "stage": 0 3 | } 4 | -------------------------------------------------------------------------------- /.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | .*/js/flow.js 3 | .*/js/flow.min.js 4 | [include] 5 | [libs] 6 | [options] 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | config 11 | 12 | # Directory for instrumented libs generated by jscoverage/JSCover 13 | lib-cov 14 | 15 | # Coverage directory used by tools like istanbul 16 | coverage 17 | 18 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 19 | .grunt 20 | 21 | # Compiled binary addons (http://nodejs.org/api/addons.html) 22 | build/Release 23 | 24 | # Dependency directory 25 | # Commenting this out is preferred by some people, see 26 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- 27 | node_modules 28 | 29 | # Users Environment Variables 30 | .lock-wscript 31 | dist/scripts/app.js.map 32 | dist 33 | app/server.compiled 34 | -------------------------------------------------------------------------------- /CNAME: -------------------------------------------------------------------------------- 1 | tryflow.org 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Dmitry 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 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This project is no longer needed. There is an officially maintained better version: [flow.org/try](https://flow.org/try/). 2 | 3 | ## What is Flow 4 | 5 | Flow is a [static type checker for Javascript](http://flowtype.org/) written in Ocaml by Facebook team. See [http://flow.org/](http://flow.org/). 6 | -------------------------------------------------------------------------------- /examples/1.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | const CONVERSION_TABLE = { 3 | m: { 4 | km: (m) => m / 1000, 5 | mi: (m) => m * 0.000621371, 6 | }, 7 | }; 8 | 9 | // Converts a value from one unit to another 10 | // by using our internal totally awesome conversion 11 | // table. Returns a new UnitValue object. 12 | function convertUnit(from, to, value) { 13 | const transform = CONVERSION_TABLE[from][to]; 14 | 15 | return transform(value); 16 | } 17 | 18 | // Will return 1 19 | convertUnit('m', 'km', 1000); 20 | 21 | // Will return ? 22 | convertUnit('cm', 'm', 100); 23 | -------------------------------------------------------------------------------- /examples/2.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | const METER = 'm'; 3 | const KILOMETER = 'km'; 4 | const MILE = 'mi'; 5 | 6 | const CONVERSION_TABLE = { 7 | [METER]: { 8 | [KILOMETER]: (m) => m / 1000, 9 | [MILE]: (m) => m * 0.000621371, 10 | }, 11 | }; 12 | 13 | // Converts a value from one unit to another 14 | // by using our internal totally awesome conversion 15 | // table. Returns a new UnitValue object. 16 | function convertUnit(from, to, value) { 17 | const transform = CONVERSION_TABLE[from][to]; 18 | 19 | return transform(value); 20 | } 21 | 22 | // So now we are using constants, which might be safer with ESlint 23 | convertUnit(METER, KILOMETER, 1000) 24 | 25 | // But this doesn't protect us from misuse and will throw an 'undefined' error 26 | convertUnit('cm', 'm', 100); 27 | -------------------------------------------------------------------------------- /examples/3.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | const CONVERSION_TABLE = { 4 | m: { 5 | km: (m) => m / 1000, 6 | mi: (m) => m * 0.000621371, 7 | } 8 | }; 9 | 10 | function convertUnit(from: string, to: string, value: number): number { 11 | const transform = CONVERSION_TABLE[from][to]; 12 | 13 | return transform(value); 14 | } 15 | 16 | // Will return 1 17 | convertUnit('m', 'km', 1000); 18 | 19 | // This error goes unnoticed during development... 20 | // Especially hard to debug if you use variables for 'from' & 'to' 21 | convertUnit('cm', 'm', 100); 22 | -------------------------------------------------------------------------------- /examples/4.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | const assert = require('assert'); 4 | 5 | type Unit = 'm' | 'km' | 'mi'; 6 | 7 | // We create a type which almost properly types our 8 | // Conversion-Table... but the transform function still 9 | // is defined as `Function` type, which is a very loose 10 | // definition 11 | type ConversionTable = { 12 | [from: Unit]: { 13 | [to: Unit]: Function, 14 | }, 15 | }; 16 | 17 | // We got rid of the any keyword... 18 | // Now we cannot assign a non-Unit value as from / to 19 | const CONVERSION_TABLE: ConversionTable = { 20 | m: { 21 | km: (m) => m / 1000, 22 | mi: (m) => m * 0.000621371, 23 | }, 24 | // But we can secretly violate our transform interface... that's not good 25 | km: { 26 | m: (km) => (km * 1000).toString(), 27 | }, 28 | }; 29 | 30 | function convertUnit(from: Unit, to: Unit, value: number): number { 31 | const transform = CONVERSION_TABLE[from][to]; 32 | 33 | return transform(value); 34 | } 35 | 36 | // 1 km => 1000 m 37 | const value = convertUnit('km', 'm', 1); 38 | assert.equal(value, 1000); 39 | -------------------------------------------------------------------------------- /examples/5.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | type Unit = 'm' | 'km' | 'mi'; 4 | 5 | // We introduce a type for our transform function 6 | type ConvertFn = (value: number) => number; 7 | 8 | type ConversionTable = { 9 | [from: Unit]: { 10 | [to: Unit]: ConvertFn, // Now we make sure we only use the proper interface 11 | }, 12 | }; 13 | 14 | const CONVERSION_TABLE: ConversionTable = { 15 | m: { 16 | km: (m) => m / 1000, 17 | mi: (m) => m * 0.000621371, 18 | }, 19 | km: { 20 | // This does not work anymore... we get a warning 21 | m: (km) => (km * 1000)/*.toString()*/, 22 | } 23 | }; 24 | 25 | function convertUnit(from: Unit, to: Unit, value: number): number { 26 | const transform = CONVERSION_TABLE[from][to]; 27 | 28 | return transform(value); 29 | } 30 | 31 | // Should return 1000 32 | convertUnit('km', 'm', 1); 33 | -------------------------------------------------------------------------------- /examples/6.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | /** 3 | * The `type` keyword indicates that this is a 4 | * flow specific declaration. These declarations 5 | * are not part of the distributed code! 6 | */ 7 | 8 | // Enum / Union Type 9 | type Unit = 'm' | 'km'; 10 | 11 | // Function type 12 | type ConvertFn = (value: number) => number; 13 | 14 | // Applied generic types 15 | type VariadicFn = (...args: Array) => Object; 16 | 17 | // Object structure 18 | type UnitValue = { 19 | unit: Unit, 20 | value: number, 21 | } 22 | 23 | // Object structure with dynamic keys 24 | type ConversionTable = { 25 | [from: Unit]: { 26 | [to: Unit]: ConvertFn, 27 | }, 28 | }; 29 | 30 | // Actual function with typed parameters 31 | function createMeterValue(value): UnitValue { 32 | return { 33 | unit: 'm', 34 | value, 35 | }; 36 | } 37 | 38 | // Because flow knows about it's return type 39 | // UnitValue, it knows that value needs to 40 | // be a number 41 | function guessParamType(value): UnitValue { 42 | return { 43 | unit: 'km', 44 | value, 45 | }; 46 | } 47 | 48 | guessParamType(100); 49 | 50 | // $FlowExpectedError: A string is not valid for UnitValue#value 51 | guessParamType('100'); 52 | -------------------------------------------------------------------------------- /examples/7.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | import assert from 'assert'; 3 | 4 | type Unit = 'm' | 'km' | 'mi'; 5 | type ConvertFn = (value: number) => number; 6 | type UnitValue = { 7 | unit: Unit, 8 | value: number, 9 | }; 10 | type ConversionTable = { 11 | [from: Unit]: { 12 | [to: Unit]: ConvertFn, 13 | }, 14 | }; 15 | 16 | // Real code will be exported as usual 17 | const CONVERSION_TABLE: ConversionTable = { 18 | m: { 19 | km: (m) => m / 1000, 20 | mi: (m) => m * 0.000621371, 21 | }, 22 | km: { 23 | // This does not work anymore... we get a warning 24 | m: (km) => (km * 1000)/*.toString()*/, 25 | } 26 | }; 27 | 28 | // We didn't cover any edge cases yet, so let's do this now 29 | function convertUnit(from: Unit, to: Unit, value: number): ?number { 30 | if (from === to) { 31 | return value; 32 | } 33 | 34 | // If there is no conversion possible, return null 35 | // Note how we are using '== null' instead of '=== null' 36 | // because the first notation will cover both cases, 'null' 37 | // and 'undefined', which spares us a lot of extra code. 38 | // You will need to set eslint's 'eqeqeq' rule to '[2, "smart"]' 39 | if (CONVERSION_TABLE[from] == null || CONVERSION_TABLE[from][to] == null) { 40 | return null; 41 | } 42 | 43 | const transform = CONVERSION_TABLE[from][to]; 44 | 45 | return transform(value); 46 | } 47 | 48 | // Intersection Type for assuming unit to be 'm' 49 | // unit cannot be anything but a `Unit`, so we even 50 | // prevent errors on definition 51 | type MeterUnitValue = { 52 | unit: 'm' 53 | } & UnitValue; 54 | 55 | // Convert whole UnitValues instead of single values 56 | function convertToKm(unitValue: MeterUnitValue): ?UnitValue { 57 | const { unit, value } = unitValue; 58 | const converted = convertUnit(unit, 'km', value); 59 | 60 | if (converted == null) { 61 | return null; 62 | } 63 | 64 | return { 65 | unit: 'km', 66 | value: converted, 67 | } 68 | } 69 | 70 | const value = convertToKm({ unit: 'm', value: 1500 }); 71 | 72 | assert.deepEqual(value, { unit: 'km', value: 1.5 }); 73 | -------------------------------------------------------------------------------- /examples/node/01-node-core-apis.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | const a = parseInt("100", "10") 3 | setTimeout(() => {}, "100") 4 | 5 | const date = new Date() 6 | const str = date + "string" 7 | 8 | const watman = Array(16).join(1) + 'Batman!' 9 | 10 | import fs from 'fs' 11 | const filename = 1 12 | fs.readFileSync(filename) 13 | 14 | import { resolve4 } from 'dns' 15 | resolve4('139.130.4.5', (err, resolved) => { 16 | console.log(resolved[0]) 17 | }) 18 | -------------------------------------------------------------------------------- /examples/node/02-async.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | type Callback = (err: ?Error, results?: any) => void; 3 | type Waterfall = (tasks: Function[], callback?: Callback) => void; 4 | 5 | // import { rest } from lodash 6 | function rest(func) { 7 | if (typeof func != 'function') { 8 | throw new TypeError('LODASH_FUNC_ERROR_TEXT'); 9 | } 10 | const start = Math.max(func.length - 1, 0); 11 | return function() { 12 | var args = arguments, 13 | index = -1, 14 | length = Math.max(args.length - start, 0), 15 | array = Array(length); 16 | 17 | while (++index < length) { 18 | array[index] = args[start + index]; 19 | } 20 | switch (start) { 21 | case 0: return func.call(this, array); 22 | case 1: return func.call(this, args[0], array); 23 | case 2: return func.call(this, args[0], args[1], array); 24 | } 25 | var otherArgs = Array(start + 1); 26 | index = -1; 27 | while (++index < start) { 28 | otherArgs[index] = args[index]; 29 | } 30 | otherArgs[start] = array; 31 | return func.apply(this, otherArgs); 32 | }; 33 | } 34 | 35 | // import { waterfall } from async 36 | function waterfall(tasks: Function[], callback?: Callback): void { 37 | if (!Array.isArray(tasks) && callback) 38 | return callback(new Error('First argument to waterfall must be an array of functions')); 39 | if (!tasks.length && callback) return callback(null); 40 | var taskIndex = 0; 41 | 42 | function nextTask(args) { 43 | if (taskIndex === tasks.length && callback) { 44 | return callback.apply(null, [null].concat(args)); 45 | } 46 | 47 | var taskCallback = rest(function(err: ?Error, args: Array) { 48 | if (err && callback) { 49 | return callback.apply(null, [err].concat(args)); 50 | } 51 | nextTask(args); 52 | }); 53 | 54 | args.push(taskCallback); 55 | 56 | var task = tasks[taskIndex++]; 57 | task.apply(null, args); 58 | } 59 | 60 | nextTask([]); 61 | } 62 | 63 | waterfall([ 64 | function(callback) { 65 | callback(null, 'one', 'two'); 66 | }, 67 | function(arg1, arg2, callback) { 68 | // arg1 now equals 'one' and arg2 now equals 'two' 69 | callback(null, 'three'); 70 | }, 71 | function(arg1, callback) { 72 | // arg1 now equals 'three' 73 | callback(null, 'done'); 74 | } 75 | ], function (err, result) { 76 | // result now equals 'done' 77 | }); 78 | -------------------------------------------------------------------------------- /examples/node/03-sequelize.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | class Sequelize { 4 | define() { 5 | return { 6 | findAll: () => { } 7 | } 8 | } 9 | } 10 | 11 | const SequelizeSchema = { 12 | STRING: 'STRING', 13 | DATE: 'DATE', 14 | } 15 | 16 | const sequelize = new Sequelize('database', 'username', 'password'); 17 | 18 | // FIRST TIME 19 | const User = sequelize.define('user', { 20 | username: SequelizeSchema.STRING, 21 | birthday: SequelizeSchema.DATE 22 | }); 23 | 24 | // SECOND TIME 25 | type UserT = { 26 | username: string; 27 | birthday: Date; 28 | } 29 | 30 | async function getUsersFromDB() { 31 | const users: ?Array = await User.findAll(); 32 | const userLogin = users[0].login; 33 | } 34 | -------------------------------------------------------------------------------- /examples/node/04-parse.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | async function fetchHtml() { 4 | return fetch('http://localhost:3000').then(res => res.text()) 5 | } 6 | 7 | // click to see inferred 8 | function parseHtmlOptimistic(html) { 9 | // let's use something like cheerio to 10 | // parse text into complicated structure 11 | return { 12 | body: { 13 | nav: { 14 | ul: [ 15 | { 16 | li: { 17 | span: 'text 1' 18 | }, 19 | }, 20 | { 21 | li: { 22 | span: 'text 2' 23 | }, 24 | }, 25 | { 26 | li: { 27 | span: 'text 3' 28 | }, 29 | } 30 | ] 31 | } 32 | } 33 | } 34 | } 35 | 36 | // what if we need to describe that type 37 | type SimpleHtmlElement = { 38 | ul?: Array; 39 | [key: string]: SimpleHtmlElement | string; 40 | } 41 | type Html = { 42 | body?: SimpleHtmlElement 43 | } 44 | 45 | function parseHtmlRealistic(html: string): Html { 46 | return { 47 | body: { 48 | nav: { 49 | ul: [ 50 | { 51 | li: { 52 | span: 'text 1' 53 | }, 54 | }, 55 | { 56 | li: { 57 | span: 'text 2' 58 | }, 59 | }, 60 | { 61 | li: { 62 | span: 'text 3' 63 | }, 64 | } 65 | ] 66 | } 67 | } 68 | } 69 | } 70 | 71 | async function scrape() { 72 | const html = await fetchHtml() 73 | const wrongPathToSpan = parseHtmlOptimistic(html).body.nav.span; 74 | const rightPathToSpan = parseHtmlOptimistic(html).body.nav.ul[0].li.span; 75 | const withoutChecks = parseHtmlRealistic(html).body.nav.ul[0].li.span; 76 | const withChecks = parseHtmlRealistic(html) 77 | if (withChecks.body && withChecks.body.nav && withChecks.body.nav.ul) { 78 | withChecks.body.nav.ul.forEach(item => { 79 | if (item.li && item.li.span) { 80 | const span = item.li.span // safe according to our type 81 | } 82 | }) 83 | 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /examples/react/01-react-propTypes.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | var React = require('react') 3 | var ReactDOM = require('react-dom') 4 | 5 | var Comment = React.createClass({ 6 | render: function() { 7 | return ( 8 |
9 |

10 | {this.props.author} 11 |

12 | {this.props.children} 13 |
14 | ); 15 | } 16 | }); 17 | 18 | var CommentList = React.createClass({ 19 | render: function() { 20 | var commentNodes = this.props.data.map(function(comment) { 21 | return ( 22 | 23 | {comment.text} 24 | 25 | ); 26 | }); 27 | return ( 28 |
29 | {commentNodes} 30 |
31 | ); 32 | } 33 | }); 34 | 35 | var CommentForm = React.createClass({ 36 | getInitialState: function() { 37 | return {author: '', text: ''}; 38 | }, 39 | handleAuthorChange: function(e) { 40 | this.setState({author: e.target.value}); 41 | }, 42 | handleTextChange: function(e) { 43 | this.setState({text: e.target.value}); 44 | }, 45 | handleSubmit: function(e) { 46 | e.preventDefault(); 47 | var author = this.state.author.trim(); 48 | var text = this.state.text.trim(); 49 | if (!text || !author) { 50 | return; 51 | } 52 | this.props.onCommentSubmit({author: author, text: text}); 53 | this.setState({author: '', text: ''}); 54 | }, 55 | render: function() { 56 | return ( 57 |
58 | 64 | 70 | 71 |
72 | ); 73 | } 74 | }); 75 | 76 | var CommentBox = React.createClass({ 77 | loadCommentsFromServer: function() { 78 | fetch(this.props.url) 79 | .then(res => res.json()) 80 | .then(json => this.setState({data: json})) 81 | .catch(err => console.error(err)) 82 | }, 83 | getInitialState: function() { 84 | return {data: []}; 85 | }, 86 | componentDidMount: function() { 87 | this.loadCommentsFromServer(); 88 | setInterval(this.loadCommentsFromServer, this.props.pollInterval); 89 | }, 90 | handleCommentSubmit: function(comment) { 91 | // TODO: submit to the server and refresh the list 92 | }, 93 | render: function() { 94 | return ( 95 |
96 |

Comments

97 | 98 | 99 |
100 | ); 101 | } 102 | }); 103 | 104 | ReactDOM.render( 105 | , 106 | document.getElementById('content') 107 | ); 108 | -------------------------------------------------------------------------------- /examples/react/02-modern-react.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | import React from 'react' 3 | import ReactDOM from 'react-dom' 4 | 5 | /************* 6 | * types.js 7 | *************/ 8 | /*:: // The example of Flow comments 9 | 10 | type CommentBoxState = { 11 | author1: ?string; // TYPO 12 | text: string; 13 | data: Array; 14 | } 15 | 16 | type ActionCreator = Function; 17 | type Action = { 18 | type: string; 19 | author?: string; 20 | text?: string; 21 | data1?: Array; // TYPO 22 | } 23 | 24 | type Actions = { 25 | handleAuthorChange: ActionCreator; 26 | handleTextChange: ActionCreator; 27 | // FORGOT ABOUT handleSubmit 28 | } 29 | */ 30 | 31 | /*************** 32 | * actions.js 33 | ***************/ 34 | 35 | function fetchComments() { 36 | return dispatch => { 37 | dispatch({ type: 'LOAD_COMMENTS' }) 38 | fetch('/some/url') 39 | .then(res => res.json()) 40 | .then(json => dispatch({ type: 'LOAD_COMMENTS_FINISHED', data: json })) 41 | .catch(err => dispatch({ type: 'LOAD_COMMENTS_ERROR', err })) 42 | } 43 | } 44 | 45 | const authorChange = (author) => ({ type: 'AUTHOR_CHANGED', author }) 46 | const textChange = (text) => ({ type: 'TEXT_CHANGED', text }) 47 | 48 | /*************** 49 | * reducer.js 50 | ***************/ 51 | 52 | const INITIAL_STATE = { 53 | author: '', 54 | text: '', 55 | data: [], 56 | } 57 | 58 | const commentReducer = (state = INITIAL_STATE, action: Action): CommentBoxState => { 59 | switch (action.type) { 60 | case 'LOAD_COMMENTS_FINISHED': 61 | return { 62 | ...state, 63 | data: action.data, 64 | }; 65 | case 'AUTHOR_CHANGED': 66 | return { 67 | ...state, 68 | author: action.author, 69 | } 70 | case 'TEXT_CHANGED': 71 | return { 72 | ...state, 73 | text: action.text, 74 | } 75 | default: 76 | return state; 77 | } 78 | } 79 | 80 | /*************** 81 | * Comment.js 82 | ***************/ 83 | const Comment = ({ author, children }) => ( 84 |
85 |

86 | {author} 87 |

88 | {children} 89 |
90 | ) 91 | 92 | /*************** 93 | * CommentList.js 94 | ***************/ 95 | const CommentList = ({ data }) => ( 96 |
97 | {data.map(comment => 98 | 99 | {comment.text} 100 | 101 | )} 102 |
103 | ) 104 | 105 | /*************** 106 | * CommentForm.js 107 | ***************/ 108 | const CommentFrom = ({ 109 | author, 110 | text, 111 | handleAuthorChange, 112 | handleTextChange, 113 | handleSubmit 114 | }: (Actions & CommentBoxState)) => ( 115 |
116 | 122 | 128 | 129 |
130 | ) 131 | 132 | /*************** 133 | * CommentBox.js 134 | ***************/ 135 | const CommentBox = (props: Actions & CommentBoxState) => ( 136 |
137 |

Comments

138 | 139 | 140 |
141 | ) 142 | 143 | // from redux 144 | const bindActionCreators = () => {} 145 | const connect = (mapStateToProps, mapDispatchToProps) => 146 | (ReactComponent) => 147 | () => 148 | 149 | 150 | const commandAction = { 151 | authorChange, 152 | textChange, 153 | fetchComments, 154 | } 155 | /*************** 156 | * CommentBoxContainer.js 157 | ***************/ 158 | const CommentBoxContainer = connect( 159 | state => state, 160 | dispatch => bindActionCreators(commandAction, dispatch) 161 | )(CommentBox) 162 | 163 | ReactDOM.render( 164 | , 165 | document.getElementById('content') 166 | ); 167 | -------------------------------------------------------------------------------- /favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ptmt/tryflow/9a5f1d9aab69acb9c7c1ecd1e0e3bb6ac157bcc1/favicon.png -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Try Flow: Learn and share JavaScript snippets using type annotations 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 144 | 145 | 146 | 147 | 148 |

Please, consider an officially maintained flowtype.org/try

161 | 162 |
163 |
164 | 165 | 196 | 197 |
198 | Loading core libs... 199 | 200 | 201 | © Flow tryflow.org 202 | 203 |
204 | 205 | 206 | 207 | 208 | 209 | 210 | 328 | 329 | 330 | -------------------------------------------------------------------------------- /js/flowlib/bom.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2013-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the "flow" directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | */ 10 | /* BOM */ 11 | 12 | declare class Screen { 13 | availHeight: number; 14 | availLeft: number; 15 | availTop: number; 16 | availWidth: number; 17 | colorDepth: number; 18 | height: number; 19 | left: number; 20 | mozOrientation?: string; 21 | onmozorientationchange?: any; 22 | orientation?: { 23 | lock(): Promise; 24 | unlock(): void; 25 | angle: number; 26 | onchange: () => mixed; 27 | type: 'portrait-primary' | 'portrait-secondary' | 'landscape-primary' | 'landscape-secondary'; 28 | }; 29 | pixelDepth: number; 30 | top: number; 31 | width: number; 32 | mozLockOrientation?: Function; 33 | mozUnlockOrientation?: Function; 34 | mozOrientation?: string; 35 | onmozorientationchange?: Function; 36 | } 37 | 38 | declare var screen: Screen; 39 | declare var window: any; 40 | 41 | type GamepadButton = { 42 | pressed: bool; 43 | value: number; 44 | } 45 | type Gamepad = { 46 | axes: number[]; 47 | buttons: GamepadButton[]; 48 | connected: bool; 49 | id: string; 50 | index: number; 51 | mapping: string; 52 | timestamp: number; 53 | } 54 | declare class Navigator { 55 | appCodeName: 'Mozilla'; 56 | appName: 'Netscape'; 57 | appVersion: string; 58 | buildID: string; 59 | cookieEnabled: boolean; 60 | doNotTrack?: any; 61 | geolocation: Geolocation; 62 | mediaDevices?: Object; 63 | hardwareConcurrency: number; 64 | javaEnabled: Function; 65 | language: string; 66 | languages: Array; 67 | maxTouchPoints: number; 68 | mediaDevices: Object; 69 | mimeTypes: MimeTypeArray; 70 | onLine: boolean; 71 | oscpu: string; 72 | permissions: any; 73 | platform: string; 74 | plugins: PluginArray; 75 | product: 'Gecko'; 76 | productSub: '20030107' | '20100101'; 77 | serviceWorker?: Object; 78 | userAgent: string; 79 | vendor: '' | 'Google Inc.' | 'Apple Computer, Inc'; 80 | vendorSub: ''; 81 | getBattery?: () => Promise; 82 | getGamepads?: () => Object[]; 83 | webkitGetGamepads?: Function; 84 | mozGetGamepads?: Function; 85 | mozGamepads?: any; 86 | gamepads?: any; 87 | webkitGamepads?: any; 88 | requestMIDIAccess?: Function; 89 | registerContentHandler(mimeType: string, uri: string, title: string): void; 90 | registerProtocolHandler(protocol: string, uri: string, title: string): void; 91 | requestMediaKeySystemAccess?: (keySystem: string, supportedConfigurations: any[]) => Promise; 92 | sendBeacon?: Function; 93 | getUserMedia?: Function; 94 | webkitGetUserMedia?: Function; 95 | mozGetUserMedia?: Function; 96 | msGetUserMedia?: Function; 97 | taintEnabled?: Function; 98 | vibrate?: (pattern: number|number[]) => bool; 99 | 100 | } 101 | 102 | declare var navigator: Navigator; 103 | 104 | declare class MimeType { 105 | type: string; 106 | description: string; 107 | suffixes: string; 108 | enabledPlugin: Plugin; 109 | } 110 | 111 | declare class MimeTypeArray { 112 | length: number; 113 | item(index: number): MimeType; 114 | namedItem(name: string): MimeType; 115 | [key: number | string]: MimeType; 116 | } 117 | 118 | declare class Plugin { 119 | description: string; 120 | filename: string; 121 | name: string; 122 | version?: string; // Gecko only 123 | length: number; 124 | item(index: number): MimeType; 125 | namedItem(name: string): MimeType; 126 | [key: number | string]: MimeType; 127 | } 128 | 129 | declare class PluginArray { 130 | length: number; 131 | item(index: number): Plugin; 132 | namedItem(name: string): Plugin; 133 | refresh(): void; 134 | [key: number | string]: Plugin; 135 | } 136 | 137 | declare class History { 138 | length: number; 139 | scrollRestoration: 'auto' | 'manual'; 140 | state: any; 141 | back(): void; 142 | forward(): void; 143 | go(delta?: any): void; 144 | pushState(statedata: any, title: string, url?: string): void; 145 | replaceState(statedata: any, title: string, url?: string): void; 146 | } 147 | 148 | declare var history: History; 149 | 150 | declare class Location { 151 | ancestorOrigins: string[]; 152 | hash: string; 153 | host: string; 154 | hostname: string; 155 | href: string; 156 | origin: string; 157 | pathname: string; 158 | port: string; 159 | protocol: string; 160 | search: string; 161 | assign(url: string): void; 162 | reload(flag?: boolean): void; 163 | replace(url: string): void; 164 | toString(): string; 165 | } 166 | 167 | declare var location: Location; 168 | 169 | /////////////////////////////////////////////////////////////////////////////// 170 | 171 | declare class DOMParser { 172 | parseFromString(source: string, mimeType: string): Document; 173 | } 174 | 175 | declare class FormData { 176 | append(name: any, value: any, blobName?: string): void; 177 | } 178 | 179 | declare class MutationRecord { 180 | oldValue: string; 181 | previousSibling: Node; 182 | addedNodes: NodeList; 183 | attributeName: string; 184 | removedNodes: NodeList; 185 | target: Node; 186 | nextSibling: Node; 187 | attributeNamespace: string; 188 | type: string; 189 | } 190 | 191 | declare class MutationObserver { 192 | constructor(callback: (arr: Array, observer: MutationObserver)=>any): void; 193 | observe(target: Node, options: { 194 | childList?: boolean; 195 | attributes?: boolean; 196 | characterData?: boolean; 197 | subtree?: boolean; 198 | attributeOldValue?: boolean; 199 | characterDataOldValue?: boolean; 200 | attributeFilter?: Array; 201 | }): void; 202 | takeRecords(): Array; 203 | disconnect(): void; 204 | } 205 | 206 | declare var NodeFilter: { 207 | acceptNode(n: Node): number; 208 | SHOW_ENTITY_REFERENCE: number; 209 | SHOW_NOTATION: number; 210 | SHOW_ENTITY: number; 211 | SHOW_DOCUMENT: number; 212 | SHOW_PROCESSING_INSTRUCTION: number; 213 | FILTER_REJECT: number; 214 | SHOW_CDATA_SECTION: number; 215 | FILTER_ACCEPT: number; 216 | SHOW_ALL: number; 217 | SHOW_DOCUMENT_TYPE: number; 218 | SHOW_TEXT: number; 219 | SHOW_ELEMENT: number; 220 | SHOW_COMMENT: number; 221 | FILTER_SKIP: number; 222 | SHOW_ATTRIBUTE: number; 223 | SHOW_DOCUMENT_FRAGMENT: number; 224 | }; 225 | 226 | declare class CloseEvent extends Event { 227 | code: number; 228 | reason: string; 229 | wasClean: boolean; 230 | } 231 | 232 | declare class WebSocket extends EventTarget { 233 | static CONNECTING: 0; 234 | static OPEN: 1; 235 | static CLOSING: 2; 236 | static CLOSED: 3; 237 | constructor(url: string, protocols?: string | Array): void; 238 | protocol: string; 239 | readyState: number; 240 | bufferedAmount: number; 241 | onopen: (ev: Event) => any; 242 | extensions: string; 243 | onmessage: (ev: MessageEvent) => any; 244 | onclose: (ev: CloseEvent) => any; 245 | onerror: (ev: Event) => any; 246 | binaryType: string; 247 | url: string; 248 | close(code?: number, reason?: string): void; 249 | send(data: any): void; 250 | CONNECTING: 0; 251 | OPEN: 1; 252 | CLOSING: 2; 253 | CLOSED: 3; 254 | } 255 | 256 | declare class Worker extends EventTarget { 257 | constructor(stringUrl: string): void; 258 | onerror: (ev: Event) => any; 259 | onmessage: (ev: MessageEvent) => any; 260 | postMessage(message: any, ports?: any): void; 261 | terminate(): void; 262 | } 263 | 264 | declare class XDomainRequest { 265 | timeout: number; 266 | onerror: (ev: Event) => any; 267 | onload: (ev: Event) => any; 268 | onprogress: (ev: Event) => any; 269 | ontimeout: (ev: Event) => any; 270 | responseText: string; 271 | contentType: string; 272 | open(method: string, url: string): void; 273 | abort(): void; 274 | send(data?: any): void; 275 | addEventListener(type: string, listener: (evt: any) => void, useCapture?: boolean): void; 276 | 277 | statics: { 278 | create(): XDomainRequest; 279 | } 280 | } 281 | 282 | declare class XMLHttpRequest extends EventTarget { 283 | responseBody: any; 284 | status: number; 285 | readyState: number; 286 | responseText: string; 287 | responseXML: any; 288 | ontimeout: (ev: ProgressEvent) => any; 289 | statusText: string; 290 | onreadystatechange: (ev: Event) => any; 291 | timeout: number; 292 | onload: (ev: ProgressEvent) => any; 293 | response: any; 294 | withCredentials: boolean; 295 | onprogress: (ev: ProgressEvent) => any; 296 | onabort: (ev: ProgressEvent) => any; 297 | responseType: string; 298 | onloadend: (ev: ProgressEvent) => any; 299 | upload: XMLHttpRequestEventTarget; 300 | onerror: (ev: ProgressEvent) => any; 301 | onloadstart: (ev: ProgressEvent) => any; 302 | msCaching: string; 303 | open(method: string, url: string, async?: boolean, user?: string, password?: string): void; 304 | send(data?: any): void; 305 | abort(): void; 306 | getAllResponseHeaders(): string; 307 | setRequestHeader(header: string, value: string): void; 308 | getResponseHeader(header: string): string; 309 | msCachingEnabled(): boolean; 310 | overrideMimeType(mime: string): void; 311 | LOADING: number; 312 | DONE: number; 313 | UNSENT: number; 314 | OPENED: number; 315 | HEADERS_RECEIVED: number; 316 | 317 | statics: { 318 | create(): XMLHttpRequest; 319 | } 320 | } 321 | 322 | declare class XMLHttpRequestEventTarget extends EventTarget { 323 | onprogress: (ev: ProgressEvent) => any; 324 | onerror: (ev: Event) => any; 325 | onload: (ev: Event) => any; 326 | ontimeout: (ev: Event) => any; 327 | onabort: (ev: Event) => any; 328 | onloadstart: (ev: Event) => any; 329 | onloadend: (ev: Event) => any; 330 | } 331 | 332 | declare class XMLSerializer { 333 | serializeToString(target: Node): string; 334 | } 335 | 336 | declare class Geolocation { 337 | getCurrentPosition: ( 338 | success: (position: Position) => any, 339 | error?: (error: PositionError) => any, 340 | options?: PositionOptions 341 | ) => any; 342 | watchPosition: ( 343 | success: (position: Position) => any, 344 | error?: (error: PositionError) => any, 345 | options?: PositionOptions 346 | ) => any; 347 | clearWatch: any; 348 | } 349 | 350 | declare class Position { 351 | coords: Coordinates; 352 | timestamp: number; 353 | } 354 | 355 | declare class Coordinates { 356 | latitude: number; 357 | longitude: number; 358 | altitude?: number; 359 | accuracy: number; 360 | altitudeAccuracy?: number; 361 | heading?: number; 362 | } 363 | 364 | declare class PositionError { 365 | code: number; 366 | message: string; 367 | PERMISSION_DENIED: number; 368 | POSITION_UNAVAILABLE: number; 369 | TIMEOUT: number; 370 | } 371 | 372 | type PositionOptions = { 373 | enableHighAccuracy: boolean; 374 | timeout: number; 375 | maximumAge: number; 376 | } 377 | 378 | declare class AudioContext { 379 | currentTime: number; 380 | destination: AudioDestinationNode; 381 | listener: AudioListener; 382 | sampleRate: number; 383 | state: any; 384 | onstatechange: (ev: any) => any; 385 | close(): void; 386 | createBuffer(numOfChannels: number, length: number, sampleRate: number): AudioBuffer; 387 | createBufferSource(myMediaElement?: HTMLMediaElement): AudioBufferSourceNode; 388 | createMediaElementSource(stream?: MediaStream): MediaElementAudioSourceNode; 389 | createMediaStreamSource(): MediaStreamAudioSourceNode; 390 | createMediaStreamDestination(): MediaStream; 391 | createScriptProcessor(bufferSize: number, numberOfInputChannels: number, numberOfOutputChannels: number): ScriptProcessorNode; 392 | createAnalyser(): AnalyserNode; 393 | createBiquadFilter(): BiquadFilterNode; 394 | createChannelMerger(numberOfInputs?: number): ChannelMergerNode; 395 | createChannelSplitter(numberOfInputs?: number): ChannelSplitterNode; 396 | createConvolver(): ConvolverNode; 397 | createDelay(maxDelayTime?: number): DelayNode; 398 | createDynamicCompressor(): DynamicsCompressorNode; 399 | createGain(): GainNode; 400 | createOscillator(): OscillatorNode; 401 | createPanner(): PannerNode; 402 | createPeriodicWave(real: Float32Array, img: Float32Array, options?: { 403 | disableNormalization: bool, 404 | }): PeriodicWave; 405 | createWaveShaper(): WaveShaperNode; 406 | decodeAudioData(arrayBuffer: ArrayBuffer, decodeSuccessCallback: Function, decodeErrorCallback: Function): void; 407 | decodeAudioData(arrayBuffer: ArrayBuffer): Promise; 408 | resume(): Promise; 409 | suspend(): Promise; 410 | } 411 | 412 | declare class AudioNode { 413 | context: AudioContext; 414 | numberOfInputs: number; 415 | numberOfOutputs: number; 416 | channelCount: number; 417 | channelCoundMode: any; 418 | channelInterpretation: 'speakers'|'discrete'; 419 | connect(audioNode: AudioNode, output?: number, input?: number): AudioNode; 420 | connect(destination: AudioParam, output?: number): void; 421 | disconnect(destination?: AudioNode, output?: number, input?: number): void; 422 | } 423 | 424 | declare class AudioParam extends AudioNode { 425 | value: number; 426 | defaultValue: number; 427 | setValueAtTime(value: number, startTime: number): this; 428 | linearRampToValueAtTime(value: number, endTime: number): this; 429 | exponentialRampToValueAtTime(value: number, endTime: number): this; 430 | setTargetAtTime(target: number, startTime: number, timeConstant: number): this; 431 | setValueCurveAtTime(values: Float32Array, startTime: number, duration: number): this; 432 | cancelScheduledValues(startTime: number): this; 433 | } 434 | 435 | declare class AudioDestinationNode extends AudioNode { 436 | maxChannelCount: number; 437 | } 438 | 439 | declare class AudioListener extends AudioNode { 440 | setOrientation(x: number, y: number, z: number, xUp: number, yUp: number, zUp: number): void; 441 | } 442 | 443 | declare class AudioBuffer { 444 | sampleRate: number; 445 | length: number; 446 | duration: number; 447 | numberOfChannels: number; 448 | getChannelData(channel: number): Float32Array; 449 | copyFromChannel(destination: Float32Array, channelNumber: number, startInChannel?: number): void; 450 | copyToChannel(source: Float32Array, channelNumber: number, startInChannel?: number): void; 451 | } 452 | 453 | declare class AudioBufferSourceNode extends AudioNode { 454 | buffer: AudioBuffer; 455 | detune: AudioParam; 456 | loop: bool; 457 | loopStart: number; 458 | loopEnd: number; 459 | playbackRate: AudioParam; 460 | onended: (ev: any) => any; 461 | start(when?: number, offset?: number, duration?: number): void; 462 | stop(when?: number): void; 463 | } 464 | 465 | declare class MediaStream extends EventTarget { 466 | active: bool; 467 | ended: bool; 468 | id: string; 469 | onactive: (ev: any) => any; 470 | onaddtrack: (ev: any) => any; 471 | onended: (ev: any) => any; 472 | oninactive: (ev: any) => any; 473 | onremovetrack: (ev: any) => any; 474 | addTrack(track: MediaStreamTrack): void; 475 | clone(): MediaStream; 476 | getAudioTracks(): MediaStreamTrack[]; 477 | getTrackById(trackid?: string): ?MediaStreamTrack; 478 | getTracks(): MediaStreamTrack[]; 479 | getVideoTracks(): MediaStreamTrack[]; 480 | removeTrack(track: MediaStreamTrack): void; 481 | } 482 | 483 | declare class MediaStreamTrack { 484 | enabled: bool; 485 | id: string; 486 | kind: string; 487 | label: string; 488 | muted: bool; 489 | readonly: bool; 490 | readyState: 'live'|'ended'; 491 | remote: bool; 492 | onstarted: (ev: any) => any; 493 | onmute: (ev: any) => any; 494 | onunmute: (ev: any) => any; 495 | onoverconstrained: (ev: any) => any; 496 | onended: (ev: any) => any; 497 | getConstraints(): any; 498 | applyConstraints(): any; 499 | getSettings(): any; 500 | getCapabilities(): any; 501 | clone(): MediaStreamTrack; 502 | stop(): void; 503 | } 504 | 505 | declare class MediaElementAudioSourceNode extends AudioNode {} 506 | declare class MediaStreamAudioSourceNode extends AudioNode {} 507 | 508 | declare class ScriptProcessorNode extends AudioNode { 509 | bufferSize: number; 510 | onaudioprocess: (ev: any) => any; 511 | } 512 | 513 | declare class AnalyserNode extends AudioNode { 514 | fftSize: number; 515 | frequencyBinCount: number; 516 | minDecibels: number; 517 | maxDecibels: number; 518 | smoothingTimeConstant: number; 519 | getFloatFrequencyData(array: Float32Array): Float32Array; 520 | getByteFrequencyData(array: Uint8Array): Uint8Array; 521 | getFloatTimeDomainData(array: Float32Array): Float32Array; 522 | getByteTimeDomainData(array: Uint8Array): Uint8Array; 523 | } 524 | 525 | declare class BiquadFilterNode extends AudioNode { 526 | frequency: AudioParam; 527 | detune: AudioParam; 528 | Q: AudioParam; 529 | gain: AudioParam; 530 | type: 'lowpass'|'highpass'|'bandpass'|'lowshelf'|'highshelf'|'peaking'|'notch'|'allpass'; 531 | getFrequencyResponse(frequencyHz: Float32Array, magResponse: Float32Array, phaseResponse: Float32Array): BiquadFilterNode; 532 | } 533 | 534 | declare class ChannelMergerNode extends AudioNode {} 535 | declare class ChannelSplitterNode extends AudioNode {} 536 | declare class ConvolverNode extends AudioNode { 537 | buffer: AudioBuffer; 538 | normalize: bool; 539 | } 540 | 541 | declare class DelayNode extends AudioNode { 542 | delayTime: number; 543 | } 544 | 545 | declare class DynamicsCompressorNode extends AudioNode { 546 | threshold: AudioParam; 547 | knee: AudioParam; 548 | ratio: AudioParam; 549 | reduction: AudioParam; 550 | attack: AudioParam; 551 | release: AudioParam; 552 | } 553 | 554 | declare class GainNode extends AudioNode { 555 | gain: AudioParam; 556 | } 557 | 558 | declare class OscillatorNode extends AudioNode { 559 | frequency: AudioParam; 560 | detune: AudioParam; 561 | type: AudioParam; 562 | start(when?: number): void; 563 | stop(when?: number): void; 564 | setPeriodicWave(periodicWave: PeriodicWave): void; 565 | } 566 | 567 | declare class PannerNode extends AudioNode { 568 | panningModel: 'equalpower'|'HRTF'; 569 | distanceModel: 'linear'|'inverse'|'exponential'; 570 | refDistance: number; 571 | maxDistance: number; 572 | rollofFactor: number; 573 | coneInnerAngle: number; 574 | coneOuterAngle: number; 575 | coneOuterGain: number; 576 | setPosition(x: number, y: number, z: number): void; 577 | setOrientation(x: number, y: number, z: number): void; 578 | } 579 | 580 | declare class PeriodicWave extends AudioNode {} 581 | declare class WaveShaperNode extends AudioNode { 582 | curve: Float32Array; 583 | oversample: 'none'|'2x'|'4x'; 584 | } 585 | 586 | declare var AudioContext: AudioContext; 587 | 588 | 589 | // this part of spec is not finished yet, apparently 590 | // https://stackoverflow.com/questions/35296664/can-fetch-get-object-as-headers 591 | type HeadersInit = Headers | {[key: string]: string}; 592 | 593 | 594 | // TODO Heades and URLSearchParams are almost the same thing. 595 | // Could it somehow be abstracted away? 596 | declare class Headers { 597 | @@iterator(): Iterator<[string, string]>; 598 | constructor(init?: HeadersInit): void; 599 | append(name: string, value: string): void; 600 | delete(name: string): void; 601 | entries(): Iterator<[string, string]>; 602 | get(name: string): string; 603 | getAll(name: string): Array; 604 | has(name: string): boolean; 605 | keys(): Iterator; 606 | set(name: string, value: string): void; 607 | values(): Iterator; 608 | } 609 | 610 | declare class URLSearchParams { 611 | @@iterator(): Iterator<[string, string]>; 612 | constructor(query?: string | URLSearchParams): void; 613 | append(name: string, value: string): void; 614 | delete(name: string): void; 615 | entries(): Iterator<[string, string]>; 616 | get(name: string): string; 617 | getAll(name: string): Array; 618 | has(name: string): boolean; 619 | keys(): Iterator; 620 | set(name: string, value: string): void; 621 | values(): Iterator; 622 | } 623 | 624 | type CacheType = 'default' | 'no-store' | 'reload' | 'no-cache' | 'force-cache' | 'only-if-cached'; 625 | type CredentialsType = 'omit' | 'same-origin' | 'include'; 626 | type ModeType = 'cors' | 'no-cors' | 'same-origin'; 627 | type RedirectType = 'follow' | 'error' | 'manual'; 628 | type MethodType = 'GET' | 'POST' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'PUT' | 'PATCH' ; 629 | type ReferrerPolicyType = 630 | '' | 'no-referrer' | 'no-referrer-when-downgrade' | 'origin-only' | 631 | 'origin-when-cross-origin' | 'unsafe-url'; 632 | type ResponseType = 'basic' | 'cors' | 'default' | 'error' | 'opaque' | 'opaqueredirect' ; 633 | 634 | type RequestOptions = { 635 | body?: ?(Blob | FormData | URLSearchParams | string); 636 | 637 | cache?: ?CacheType; 638 | credentials?: ?CredentialsType; 639 | headers?: ?HeadersInit; 640 | integrity?: ?string; 641 | method?: ?MethodType; 642 | mode?: ?ModeType; 643 | redirect?: ?RedirectType; 644 | referrer?: ?string; 645 | referrerPolicy?: ?ReferrerPolicyType; 646 | } 647 | 648 | type ResponseOptions = { 649 | status?: ?number; 650 | statusText?: ?string; 651 | headers?: ?HeadersInit 652 | } 653 | 654 | declare class Response { 655 | constructor(input?: string | URLSearchParams | FormData | Blob, init?: ResponseOptions): void; 656 | clone(): Response; 657 | static error(): Response; 658 | static redirect(url: string, status: number): Response; 659 | 660 | type: ResponseType; 661 | url: string; 662 | useFinalURL: boolean; 663 | ok: boolean; 664 | status: number; 665 | statusText: string; 666 | headers: Headers; 667 | 668 | // Body methods and attributes 669 | bodyUsed: boolean; 670 | 671 | arrayBuffer(): Promise; 672 | blob(): Promise; 673 | formData(): Promise; 674 | json(): Promise; 675 | text(): Promise; 676 | } 677 | 678 | declare class Request { 679 | constructor(input: string | Request, init?: RequestOptions): void; 680 | clone(): Request; 681 | 682 | url: string; 683 | 684 | cache: CacheType; 685 | credentials: CredentialsType; 686 | headers: Headers; 687 | integrity: string; 688 | method: MethodType; 689 | mode: ModeType; 690 | redirect: RedirectType; 691 | referrer: string; 692 | referrerPolicy: ReferrerPolicyType; 693 | 694 | // Body methods and attributes 695 | bodyUsed: boolean; 696 | 697 | arrayBuffer(): Promise; 698 | blob(): Promise; 699 | formData(): Promise; 700 | json(): Promise; 701 | text(): Promise; 702 | } 703 | 704 | declare function fetch(input: string | Request, init?: RequestOptions): Promise; 705 | -------------------------------------------------------------------------------- /js/flowlib/core.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2013-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the "flow" directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | */ 10 | /* JS primitives 11 | cf. http://typescript.codeplex.com/sourcecontrol/latest#typings/lib.d.ts 12 | */ 13 | 14 | declare var NaN: number; 15 | declare var Infinity: number; 16 | 17 | declare function parseInt(string: mixed, radix?: number): number; 18 | declare function parseFloat(string: mixed): number; 19 | declare function isNaN(number: mixed): boolean; 20 | declare function isFinite(number: mixed): boolean; 21 | declare function decodeURI(encodedURI: string): string; 22 | declare function decodeURIComponent(encodedURIComponent: string): string; 23 | declare function encodeURI(uri: string): string; 24 | declare function encodeURIComponent(uriComponent: string): string; 25 | 26 | // TODO: instance 27 | declare class Object { 28 | static (o: ?void): {[key: any]: any}; 29 | static (o: boolean): Boolean; 30 | static (o: number): Number; 31 | static (o: string): String; 32 | static (o: T): T; 33 | static assign: Object$Assign; 34 | static create(o: any, properties?: any): any; // compiler magic 35 | static defineProperties(o: any, properties: any): any; 36 | static defineProperty(o: any, p: any, attributes: any): any; 37 | static entries(object: any): Array<[string, mixed]>; 38 | static freeze(o: T): T; 39 | static getOwnPropertyDescriptor(o: any, p: any): any; 40 | static getOwnPropertyNames(o: any): Array; 41 | static getOwnPropertySymbols(o: any): Symbol[]; 42 | static getPrototypeOf: Object$GetPrototypeOf; 43 | static is(a: any, b: any): boolean; 44 | static isExtensible(o: any): boolean; 45 | static isFrozen(o: any): boolean; 46 | static isSealed(o: any): boolean; 47 | static keys(o: any): Array; 48 | static preventExtensions(o: any): any; 49 | static seal(o: any): any; 50 | static setPrototypeOf(o: any, proto: ?Object): bool; 51 | static values(object: any): Array; 52 | hasOwnProperty(prop: any): boolean; 53 | propertyIsEnumerable(prop: any): boolean; 54 | toLocaleString(): string; 55 | toString(): string; 56 | valueOf(): Object; 57 | [key:any]: any; 58 | } 59 | 60 | // Well known Symbols. 61 | declare class $SymbolHasInstance mixins Symbol {} 62 | declare class $SymboIsConcatSpreadable mixins Symbol {} 63 | declare class $SymbolIterator mixins Symbol {} 64 | declare class $SymbolMatch mixins Symbol {} 65 | declare class $SymbolReplace mixins Symbol {} 66 | declare class $SymbolSearch mixins Symbol {} 67 | declare class $SymbolSpecies mixins Symbol {} 68 | declare class $SymbolSplit mixins Symbol {} 69 | declare class $SymbolToPrimitive mixins Symbol {} 70 | declare class $SymbolToStringTag mixins Symbol {} 71 | declare class $SymbolUnscopables mixins Symbol {} 72 | 73 | declare class Symbol { 74 | static (value?:any): Symbol; 75 | static for(key: string): Symbol; 76 | static hasInstance: $SymbolHasInstance; 77 | static isConcatSpreadable: $SymboIsConcatSpreadable; 78 | static iterator: string; // polyfill '@@iterator' 79 | static keyFor(sym: Symbol): ?string; 80 | static length: 0; 81 | static match: $SymbolMatch; 82 | static replace: $SymbolReplace; 83 | static search: $SymbolSearch; 84 | static species: $SymbolSpecies; 85 | static split: $SymbolSplit; 86 | static toPrimitive: $SymbolToPrimitive; 87 | static toStringTag: $SymbolToStringTag; 88 | static unscopables: $SymbolUnscopables; 89 | toString(): string; 90 | valueOf(): ?Symbol; 91 | } 92 | 93 | // TODO: instance, static 94 | declare class Function { 95 | apply: Function$Prototype$Apply; // (thisArg: any, argArray?: any) => any 96 | bind: Function$Prototype$Bind; // (thisArg: any, ...argArray: Array) => any; 97 | call: Function$Prototype$Call; // (thisArg: any, ...argArray: Array) => any 98 | arguments: any; 99 | caller: Function | null; 100 | length: number; 101 | name: string; 102 | } 103 | 104 | declare class Boolean { 105 | static (value:any):boolean; 106 | valueOf(): boolean; 107 | } 108 | 109 | declare class Number { 110 | static EPSILON: number; 111 | static MAX_SAFE_INTEGER: number; 112 | static MAX_VALUE: number; 113 | static MIN_SAFE_INTEGER: number; 114 | static MIN_VALUE: number; 115 | static NaN: number; 116 | static NEGATIVE_INFINITY: number; 117 | static POSITIVE_INFINITY: number; 118 | static (value:any):number; 119 | static isFinite(value: any): boolean; 120 | static isInteger(value: any): boolean; 121 | static isNaN(value: any): boolean; 122 | static isSafeInteger(value: any): boolean; 123 | static parseFloat(value: string): number; 124 | static parseInt(value: string): number; 125 | toExponential(fractionDigits?: number): string; 126 | toFixed(fractionDigits?: number): string; 127 | toPrecision(precision?: number): string; 128 | toString(radix?: number): string; 129 | valueOf(): number; 130 | } 131 | 132 | declare var Math: { 133 | E: number; 134 | LN10: number; 135 | LN2: number; 136 | LOG10E: number; 137 | LOG2E: number; 138 | PI: number; 139 | SQRT1_2: number; 140 | SQRT2: number; 141 | abs(x: number): number; 142 | acos(x: number): number; 143 | acosh(x: number): number; 144 | asin(x: number): number; 145 | asinh(x: number): number; 146 | atan(x: number): number; 147 | atan2(y: number, x: number): number; 148 | atanh(x: number): number; 149 | cbrt(x: number): number; 150 | ceil(x: number): number; 151 | clz32(x: number): number; 152 | cos(x: number): number; 153 | cosh(x: number): number; 154 | exp(x: number): number; 155 | expm1(x: number): number; 156 | floor(x: number): number; 157 | fround(x: number): number; 158 | hypot(...values: Array): number; 159 | imul(y: number, x: number): number; 160 | log(x: number): number; 161 | log10(x: number): number; 162 | log1p(x: number): number; 163 | log2(x: number): number; 164 | max(...values: Array): number; 165 | min(...values: Array): number; 166 | pow(x: number, y: number): number; 167 | random(): number; 168 | round(x: number): number; 169 | sign(x: number): number; 170 | sin(x: number): number; 171 | sinh(x: number): number; 172 | sqrt(x: number): number; 173 | tan(x: number): number; 174 | tanh(x: number): number; 175 | trunc(x: number): number; 176 | }; 177 | 178 | declare class Array { 179 | @@iterator(): Iterator; 180 | toLocaleString(): string; 181 | // concat creates a new array 182 | concat | S>(...items: Array): Array; 183 | copyWithin(target: number, start: number, end?: number): T[]; 184 | entries(): Iterator<[number, T]>; 185 | every(callbackfn: (value: T, index: number, array: Array) => any, thisArg?: any): boolean; 186 | fill(value: T, begin?: number, end?: number): Array; 187 | filter(callbackfn: (value: T, index: number, array: Array) => any, thisArg?: any): Array; 188 | find(callbackfn: (value: T, index: number, array: Array) => any, thisArg?: any): T; 189 | findIndex(callbackfn: (value: T, index: number, array: Array) => any, thisArg?: any): number; 190 | forEach(callbackfn: (value: T, index: number, array: Array) => any, thisArg?: any): void; 191 | includes(searchElement: T, fromIndex?: number): boolean; 192 | indexOf(searchElement: T, fromIndex?: number): number; 193 | join(separator?: string): string; 194 | keys(): Iterator; 195 | lastIndexOf(searchElement: T, fromIndex?: number): number; 196 | map(callbackfn: (value: T, index: number, array: Array) => U, thisArg?: any): Array; 197 | pop(): T; 198 | push(...items: Array): number; 199 | reduce( 200 | callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: Array) => U, 201 | initialValue: U 202 | ): U; 203 | reduce( 204 | callbackfn: (previousValue: T|U, currentValue: T, currentIndex: number, array: Array) => U 205 | ): U; 206 | reduceRight( 207 | callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: Array) => U, 208 | initialValue: U 209 | ): U; 210 | reduceRight( 211 | callbackfn: (previousValue: T|U, currentValue: T, currentIndex: number, array: Array) => U 212 | ): U; 213 | reverse(): Array; 214 | shift(): T; 215 | slice(start?: number, end?: number): Array; 216 | some(callbackfn: (value: T, index: number, array: Array) => any, thisArg?: any): boolean; 217 | sort(compareFn?: (a: T, b: T) => number): Array; 218 | splice(start: number, deleteCount?: number, ...items: Array): Array; 219 | unshift(...items: Array): number; 220 | values(): Iterator; 221 | length: number; 222 | static (...values:Array): Array; 223 | static isArray(obj: any): bool; 224 | static from(iter: Iterable, mapFn: (elem: A, index: number) => B, thisArg?: any): Array; 225 | static from(iter: Iterable, mapFn: void): Array; 226 | static from(iter: Iterator, mapFn: (elem: A, index: number) => B, thisArg?: any): Array; 227 | static from(iter: Iterator, mapFn: void): Array; 228 | static from(arrayLike: {length: number}, mapFn: (elem: void, index: number) => A, thisArg?: any): Array; 229 | static from(arrayLike: {length: number}, mapFn: void): Array; 230 | static of(...values: any[]): any[]; 231 | } 232 | 233 | declare class String { 234 | @@iterator(): Iterator; 235 | anchor(name: string): string; 236 | charAt(pos: number): string; 237 | charCodeAt(index: number): number; 238 | codePointAt(index: number): number; 239 | concat(...strings: Array): string; 240 | endsWith(searchString: string, position?: number): boolean; 241 | includes(searchString: string, position?: number): boolean; 242 | indexOf(searchString: string, position?: number): number; 243 | lastIndexOf(searchString: string, position?: number): number; 244 | link(href: string): string; 245 | localeCompare(that: string): number; 246 | match(regexp: string | RegExp): ?Array; 247 | normalize(format?: string): string; 248 | repeat(count: number): string; 249 | replace(searchValue: string | RegExp, replaceValue: string | (substring: string, ...args: Array) => string): string; 250 | search(regexp: string | RegExp): number; 251 | slice(start?: number, end?: number): string; 252 | split(separator: string | RegExp, limit?: number): Array; 253 | startsWith(searchString: string, position?: number): boolean; 254 | substr(from: number, length?: number): string; 255 | substring(start: number, end?: number): string; 256 | toLocaleLowerCase(): string; 257 | toLocaleUpperCase(): string; 258 | toLowerCase(): string; 259 | toUpperCase(): string; 260 | trim(): string; 261 | trimLeft(): string; 262 | trimRight(): string; 263 | valueOf(): string; 264 | length: number; 265 | static (value:any):string; 266 | static fromCharCode(...codes: Array): string; 267 | static fromCodePoint(...codes: Array): string; 268 | static raw(templateString: string): string; 269 | static raw(callSite: $Shape<{raw: string}>, ...substitutions: any[]): string; 270 | } 271 | 272 | type RegExp$flags = 273 | 'i' | 'g' | 'm' | 'y' | 'ig' | 'im' | 'iy' | 'gi' | 'gm' | 'gy' | 'mi' | 'mg' | 'my' | 'yg' | 'ym' | 'yi' | 274 | 'igm' | 'igy' | 'img' | 'imy' | 'iym' | 'iyg' | 'gim' | 'gym' | 'gmi' | 'gmy' | 'gyi' | 'giy' | 275 | 'mig' | 'mgi' | 'myg' | 'mgy' | 'miy' | 'myi' | 'igmy' | 'igym' | 'imgy' | 'imyg' | 'iygm' | 276 | 'iymg' | 'giym' | 'gimy' | 'gmyi' | 'gmiy' | 'gymi' | 'gyim' | 'migy' | 'miyg' | 'mgiy' | 277 | 'mgyi' | 'myig' | 'mygi' | 'yimg' | 'yigm' | 'ygmi' | 'ygim' | 'ymgi' | 'ymig'; 278 | 279 | declare class RegExp { 280 | static (pattern: string | RegExp, flags?: RegExp$flags): RegExp; 281 | compile(): RegExp; 282 | constructor(pattern: string | RegExp, flags?: RegExp$flags): RegExp; 283 | exec(string: string): any; 284 | flags: string; 285 | global: boolean; 286 | ignoreCase: boolean; 287 | lastIndex: number; 288 | multiline: boolean; 289 | source: string; 290 | sticky: bool; 291 | unicode: bool; 292 | test(string: string): boolean; 293 | toString(): string; 294 | } 295 | 296 | declare class Date { 297 | // new Date(); 298 | // new Date(timestamp); 299 | // new Date(dateString); 300 | // new Date(year, month[, day[, hour[, minute[, second[, millisecond]]]]]); 301 | // TODO: This should specify an overloaded constructor once they're 302 | // supported, instead of a union type for the first argument. 303 | constructor(value?: number | string, month?: number, day?: number, hour?: number, minute?: number, second?: number, millisecond?: number): void; 304 | getDate(): number; 305 | getDay(): number; 306 | getFullYear(): number; 307 | getHours(): number; 308 | getMilliseconds(): number; 309 | getMinutes(): number; 310 | getMonth(): number; 311 | getSeconds(): number; 312 | getTime(): number; 313 | getTimezoneOffset(): number; 314 | getUTCDate(): number; 315 | getUTCDay(): number; 316 | getUTCFullYear(): number; 317 | getUTCHours(): number; 318 | getUTCMilliseconds(): number; 319 | getUTCMinutes(): number; 320 | getUTCMonth(): number; 321 | getUTCSeconds(): number; 322 | setDate(date: number): number; 323 | setFullYear(year: number, month?: number, date?: number): number; 324 | setHours(hours: number, min?: number, sec?: number, ms?: number): number; 325 | setMilliseconds(ms: number): number; 326 | setMinutes(min: number, sec?: number, ms?: number): number; 327 | setMonth(month: number, date?: number): number; 328 | setSeconds(sec: number, ms?: number): number; 329 | setTime(time: number): number; 330 | setUTCDate(date: number): number; 331 | setUTCFullYear(year: number, month?: number, date?: number): number; 332 | setUTCHours(hours: number, min?: number, sec?: number, ms?: number): number; 333 | setUTCMilliseconds(ms: number): number; 334 | setUTCMinutes(min: number, sec?: number, ms?: number): number; 335 | setUTCMonth(month: number, date?: number): number; 336 | setUTCSeconds(sec: number, ms?: number): number; 337 | toDateString(): string; 338 | toISOString(): string; 339 | toJSON(key?: any): string; 340 | toLocaleDateString(): string; 341 | toLocaleString(): string; 342 | toLocaleTimeString(): string; 343 | toTimeString(): string; 344 | toUTCString(): string; 345 | valueOf(): number; 346 | 347 | static ():string; 348 | static now(): number; 349 | static parse(s: string): number; 350 | static UTC(year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): number; 351 | // multiple indexers not yet supported 352 | [key: $SymbolToPrimitive]: (hint: 'string' | 'default' | 'number') => string | number; 353 | } 354 | 355 | declare class Error { 356 | static (message?:string):Error; 357 | name: string; 358 | message: string; 359 | stack: string; 360 | 361 | // note: v8 only (node/chrome) 362 | static captureStackTrace(target: Object, constructor?: Function): void; 363 | } 364 | 365 | declare class EvalError extends Error { 366 | } 367 | 368 | declare class RangeError extends Error { 369 | } 370 | 371 | declare class ReferenceError extends Error { 372 | } 373 | 374 | declare class SyntaxError extends Error { 375 | } 376 | 377 | declare class TypeError extends Error { 378 | } 379 | 380 | declare class URIError extends Error { 381 | } 382 | 383 | declare class JSON { 384 | static parse(text: string, reviver?: (key: any, value: any) => any): any; 385 | static stringify( 386 | value: any, 387 | replacer?: ?((key: string, value: any) => any) | Array, 388 | space?: string | number 389 | ): string; 390 | } 391 | 392 | /* Iterators */ 393 | type IteratorResult = { 394 | done: true, 395 | value?: Return, 396 | } | { 397 | done: false, 398 | value: Yield, 399 | }; 400 | 401 | interface $Iterator { 402 | @@iterator(): $Iterator; 403 | next(value?: Next): IteratorResult; 404 | } 405 | type Iterator = $Iterator; 406 | 407 | interface $Iterable { 408 | @@iterator(): $Iterator; 409 | } 410 | type Iterable = $Iterable; 411 | 412 | /* Generators */ 413 | interface Generator<+Yield,+Return,-Next> { 414 | @@iterator(): $Iterator; 415 | next(value?: Next): IteratorResult; 416 | return(value: R): { done: true, value: R }; 417 | throw(error?: any): IteratorResult; 418 | } 419 | 420 | /* Maps and Sets */ 421 | 422 | declare class Map { 423 | @@iterator(): Iterator<[K, V]>; 424 | constructor(_: void): Map; 425 | constructor(_: null): Map; 426 | constructor(iterable: Array<[Key, Value]>): Map; 427 | constructor(iterable: Iterable<[Key, Value]>): Map; 428 | clear(): void; 429 | delete(key: K): boolean; 430 | entries(): Iterator<[K, V]>; 431 | forEach(callbackfn: (value: V, index: K, map: Map) => mixed, thisArg?: any): void; 432 | get(key: K): V | void; 433 | has(key: K): boolean; 434 | keys(): Iterator; 435 | set(key: K, value: V): Map; 436 | size: number; 437 | values(): Iterator; 438 | // Multiple Indexers not yet supported 439 | [key: $SymbolToStringTag | $SymbolSpecies]: Function; 440 | } 441 | 442 | declare class WeakMap { 443 | clear(): void; 444 | delete(key: K): boolean; 445 | get(key: K): V; 446 | has(key: K): boolean; 447 | set(key: K, value: V): WeakMap; 448 | } 449 | 450 | declare class Set { 451 | @@iterator(): Iterator; 452 | add(value: T): Set; 453 | clear(): void; 454 | delete(value: T): boolean; 455 | entries(): Iterator<[T, T]>; 456 | forEach(callbackfn: (value: T, index: T, set: Set) => mixed, thisArg?: any): void; 457 | has(value: T): boolean; 458 | keys(): Iterator; 459 | size: number; 460 | values(): Iterator; 461 | [key: $SymbolSpecies]: Function; // This would the Set constructor, can't think of a way to correctly type this 462 | } 463 | 464 | declare class WeakSet { 465 | constructor(_: void): WeakSet; 466 | constructor(iterable: Array): WeakSet; 467 | constructor(iterable: Iterable): WeakSet; 468 | add(value: T): WeakSet; 469 | delete(value: T): boolean; 470 | has(value: T): boolean; 471 | } 472 | 473 | /* Promises 474 | cf. https://github.com/borisyankov/DefinitelyTyped/blob/master/es6-promises/es6-promises.d.ts 475 | */ 476 | 477 | declare class Promise<+R> { 478 | constructor(callback: ( 479 | resolve: (result: Promise | R) => void, 480 | reject: (error: any) => void 481 | ) => mixed): void; 482 | 483 | then( 484 | onFulfill?: (value: R) => Promise | U, 485 | onReject?: (error: any) => Promise | U 486 | ): Promise; 487 | 488 | catch( 489 | onReject?: (error: any) => ?Promise | U 490 | ): Promise; 491 | 492 | static resolve(object?: Promise | T): Promise; 493 | static reject(error?: any): Promise; 494 | static all: Promise$All; 495 | static race | T>(promises: Array): Promise; 496 | } 497 | 498 | // we use this signature when typing await expressions 499 | declare function $await(p: Promise | T): T; 500 | 501 | /* Binary data */ 502 | 503 | declare class ArrayBuffer { 504 | static isView(arg: mixed): boolean; 505 | constructor(byteLength: number): void; 506 | byteLength: number; 507 | slice(begin: number, end?: number): this; 508 | [key: $SymbolSpecies]: Function; // This would be the constructor, can't think of a way to correctly type this 509 | } 510 | 511 | // This is a helper type to simplify the specification, it isn't an interface 512 | // and there are no objects implementing it. 513 | // https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView 514 | type $ArrayBufferView = $TypedArray | DataView; 515 | 516 | // The TypedArray intrinsic object is a constructor function, but does not have 517 | // a global name or appear as a property of the global object. 518 | // http://www.ecma-international.org/ecma-262/6.0/#sec-%typedarray%-intrinsic-object 519 | declare class $TypedArray { 520 | static BYTES_PER_ELEMENT: number; 521 | static from(iterable: Iterable): this; 522 | static of(...values: number[]): this; 523 | 524 | constructor(length: number): void; 525 | constructor(typedArray: $TypedArray): void; 526 | constructor(iterable: Iterable): void; 527 | constructor(buffer: ArrayBuffer, byteOffset?: number, length?: number): void; 528 | 529 | [index: number]: number; 530 | 531 | @@iterator(): Iterator; 532 | 533 | buffer: ArrayBuffer; 534 | byteLength: number; 535 | byteOffset: number; 536 | length: number; 537 | 538 | copyWithin(target: number, start: number, end?: number): void; 539 | entries(): Iterator; 540 | every(callback: (value: number, index: number, array: this) => mixed, thisArg?: any): boolean; 541 | fill(value: number, start?: number, end?: number): void; 542 | filter(callback: (value: number, index: number, array: this) => mixed, thisArg?: any): this; 543 | find(callback: (value: number, index: number, array: this) => mixed, thisArg?: any): number | void; 544 | findIndex(callback: (value: number, index: number, array: this) => mixed, thisArg?: any): number | void; 545 | forEach(callback: (value: number, index: number, array: this) => mixed, thisArg?: any): void; 546 | includes(searchElement: number, fromIndex?: number): boolean; 547 | indexOf(searchElement: number, fromIndex?: number): number; // -1 if not present 548 | join(separator?: string): string; 549 | keys(): Array; 550 | lastIndexOf(searchElement: number, fromIndex?: number): number; // -1 if not present 551 | map(callback: (currentValue: number, index: number, array: this) => number, thisArg?: any): this; 552 | reduce( 553 | callback: (previousValue: U, currentValue: number, index: number, array: this) => U, 554 | initialValue: U 555 | ): U; 556 | reduce( 557 | callback: (previousValue: number|U, currentValue: number, index: number, array: this) => U, 558 | initialValue: void 559 | ): U; 560 | reduceRight( 561 | callback: (previousValue: U, currentValue: number, index: number, array: this) => U, 562 | initialValue: U 563 | ): U; 564 | reduceRight( 565 | callback: (previousValue: number|U, currentValue: number, index: number, array: this) => U, 566 | initialValue: void 567 | ): U; 568 | reverse(): this; 569 | set(array: Array | $TypedArray, offset?: number): void; 570 | slice(begin?: number, end?: number): this; 571 | some(callback: (value: number, index: number, array: this) => mixed, thisArg?: any): boolean; 572 | sort(compare?: (a: number, b: number) => number): void; 573 | subarray(begin?: number, end?: number): this; 574 | values(): Iterator; 575 | } 576 | 577 | declare class Int8Array extends $TypedArray {} 578 | declare class Uint8Array extends $TypedArray {} 579 | declare class Uint8ClampedArray extends $TypedArray {} 580 | declare class Int16Array extends $TypedArray {} 581 | declare class Uint16Array extends $TypedArray {} 582 | declare class Int32Array extends $TypedArray {} 583 | declare class Uint32Array extends $TypedArray {} 584 | declare class Float32Array extends $TypedArray {} 585 | declare class Float64Array extends $TypedArray {} 586 | 587 | declare class DataView { 588 | constructor(buffer: ArrayBuffer, byteOffset?: number, length?: number): void; 589 | buffer: ArrayBuffer; 590 | byteLength: number; 591 | byteOffset: number; 592 | getInt8(byteOffset: number): number; 593 | getUint8(byteOffset: number): number; 594 | getInt16(byteOffset: number, littleEndian?: boolean): number; 595 | getUint16(byteOffset: number, littleEndian?: boolean): number; 596 | getInt32(byteOffset: number, littleEndian?: boolean): number; 597 | getUint32(byteOffset: number, littleEndian?: boolean): number; 598 | getFloat32(byteOffset: number, littleEndian?: boolean): number; 599 | getFloat64(byteOffset: number, littleEndian?: boolean): number; 600 | setInt8(byteOffset: number, value: number): void; 601 | setUint8(byteOffset: number, value: number): void; 602 | setInt16(byteOffset: number, value: number, littleEndian?: boolean): void; 603 | setUint16(byteOffset: number, value: number, littleEndian?: boolean): void; 604 | setInt32(byteOffset: number, value: number, littleEndian?: boolean): void; 605 | setUint32(byteOffset: number, value: number, littleEndian?: boolean): void; 606 | setFloat32(byteOffset: number, value: number, littleEndian?: boolean): void; 607 | setFloat64(byteOffset: number, value: number, littleEndian?: boolean): void; 608 | } 609 | 610 | declare function btoa(rawString: string): string; 611 | declare function atob(encodedString: string): string; 612 | 613 | declare function clearInterval(intervalId?: number): void; 614 | declare function clearTimeout(timeoutId?: any): void; 615 | declare function setTimeout(callback: any, ms?: number, ...args: Array): number; 616 | declare function setInterval(callback: any, ms?: number, ...args: Array): number; 617 | 618 | /* Reflect API */ 619 | 620 | declare class Reflect { 621 | static apply(target: Function, thisArg?: any, argumentsList?: Array): any; 622 | static construct(target: Function, argumentsList?: Array, newTarget?: Function): any; 623 | static defineProperty(o: any, p: any, attributes: any): boolean; 624 | static deleteProperty(o: any, p: any): boolean; 625 | static get(o: any, p: any, receiver?: any): any; 626 | static getOwnPropertyDescriptor(o: any, p: any): any; 627 | static getPrototypeOf(o: any): any; 628 | static has(o: any, p: any): boolean; 629 | static isExtensible(o: any): boolean; 630 | static ownKeys(o: any): Array; 631 | static preventExtensions(o: any): boolean; 632 | static set(o: any, p: any, value: any, receiver?: any): boolean; 633 | static setPrototypeOf(o: any, prototype: any): boolean; 634 | } 635 | 636 | /* CommonJS */ 637 | 638 | declare var global: any; 639 | 640 | declare var module: { 641 | exports: any; 642 | require(id: string): any; 643 | id: string; 644 | filename: string; 645 | loaded: boolean; 646 | parent: any; 647 | children: Array; 648 | }; 649 | declare function require(id: string): any; 650 | declare var exports: any; 651 | 652 | /* Commonly available, shared between node and dom */ 653 | declare var console: any; 654 | -------------------------------------------------------------------------------- /js/flowlib/cssom.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2013-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the "flow" directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | */ 10 | 11 | declare class StyleSheet { 12 | disabled: boolean; 13 | href: string; 14 | media: MediaList; 15 | ownerNode: Node; 16 | parentStyleSheet: ?StyleSheet; 17 | title: string; 18 | type: string; 19 | } 20 | 21 | declare class StyleSheetList { 22 | length: number; 23 | [index: number]: StyleSheet; 24 | } 25 | 26 | declare class MediaList { 27 | mediaText: string; 28 | length: number; 29 | item(index: number): ?string; 30 | deleteMedium(oldMedium: string): void; 31 | appendMedium(newMedium: string): void; 32 | [index: number]: string; 33 | } 34 | 35 | declare class CSSStyleSheet extends StyleSheet { 36 | cssRules: CSSRuleList; 37 | ownerRule: ?CSSRule; 38 | deleteRule(index: number): void; 39 | insertRule(rule: string, index: number): void; 40 | } 41 | 42 | declare class CSSRule { 43 | cssText: string; 44 | parentRule: ?CSSRule; 45 | parentStyleSheet: ?CSSStyleSheet; 46 | type: number; 47 | static STYLE_RULE: number; 48 | static MEDIA_RULE: number; 49 | static FONT_FACE_RULE: number; 50 | static PAGE_RULE: number; 51 | static IMPORT_RULE: number; 52 | static CHARSET_RULE: number; 53 | static UNKNOWN_RULE: number; 54 | static KEYFRAMES_RULE: number; 55 | static KEYFRAME_RULE: number; 56 | static NAMESPACE_RULE: number; 57 | static COUNTER_STYLE_RULE: number; 58 | static SUPPORTS_RULE: number; 59 | static DOCUMENT_RULE: number; 60 | static FONT_FEATURE_VALUES_RULE: number; 61 | static VIEWPORT_RULE: number; 62 | static REGION_STYLE_RULE: number; 63 | } 64 | 65 | declare class CSSRuleList { 66 | length: number; 67 | item(index: number): ?CSSRule; 68 | } 69 | 70 | declare class CSSStyleDeclaration { 71 | /* DOM CSS Properties */ 72 | alignContent: string; 73 | alignItems: string; 74 | alignSelf: string; 75 | all: string; 76 | animation: string; 77 | animationDelay: string; 78 | animationDirection: string; 79 | animationDuration: string; 80 | animationFillMode: string; 81 | animationIterationCount: string; 82 | animationName: string; 83 | animationPlayState: string; 84 | animationTimingFunction: string; 85 | backfaceVisibility: string; 86 | background: string; 87 | backgroundAttachment: string; 88 | backgroundBlendMode: string; 89 | backgroundClip: string; 90 | backgroundColor: string; 91 | backgroundImage: string; 92 | backgroundOrigin: string; 93 | backgroundPosition: string; 94 | backgroundRepeat: string; 95 | backgroundSize: string; 96 | blockSize: string; 97 | border: string; 98 | borderBlockEnd: string; 99 | borderBlockEndColor: string; 100 | borderBlockEndStyle: string; 101 | borderBlockEndWidth: string; 102 | borderBlockStart: string; 103 | borderBlockStartColor: string; 104 | borderBlockStartStyle: string; 105 | borderBlockStartWidth: string; 106 | borderBottom: string; 107 | borderBottomColor: string; 108 | borderBottomLeftRadius: string; 109 | borderBottomRightRadius: string; 110 | borderBottomStyle: string; 111 | borderBottomWidth: string; 112 | borderCollapse: string; 113 | borderColor: string; 114 | borderImage: string; 115 | borderImageOutset: string; 116 | borderImageRepeat: string; 117 | borderImageSlice: string; 118 | borderImageSource: string; 119 | borderImageWidth: string; 120 | borderInlineEnd: string; 121 | borderInlineEndColor: string; 122 | borderInlineEndStyle: string; 123 | borderInlineEndWidth: string; 124 | borderInlineStart: string; 125 | borderInlineStartColor: string; 126 | borderInlineStartStyle: string; 127 | borderInlineStartWidth: string; 128 | borderLeft: string; 129 | borderLeftColor: string; 130 | borderLeftStyle: string; 131 | borderLeftWidth: string; 132 | borderRadius: string; 133 | borderRight: string; 134 | borderRightColor: string; 135 | borderRightStyle: string; 136 | borderRightWidth: string; 137 | borderSpacing: string; 138 | borderStyle: string; 139 | borderTop: string; 140 | borderTopColor: string; 141 | borderTopLeftRadius: string; 142 | borderTopRightRadius: string; 143 | borderTopStyle: string; 144 | borderTopWidth: string; 145 | borderWidth: string; 146 | bottom: string; 147 | boxDecorationBreak: string; 148 | boxShadow: string; 149 | boxSizing: string; 150 | breakAfter: string; 151 | breakBefore: string; 152 | breakInside: string; 153 | captionSide: string; 154 | clear: string; 155 | clip: string; 156 | clipPath: string; 157 | color: string; 158 | columns: string; 159 | columnCount: string; 160 | columnFill: string; 161 | columnGap: string; 162 | columnRule: string; 163 | columnRuleColor: string; 164 | columnRuleStyle: string; 165 | columnRuleWidth: string; 166 | columnSpan: string; 167 | columnWidth: string; 168 | content: string; 169 | counterIncrement: string; 170 | counterReset: string; 171 | cursor: string; 172 | direction: string; 173 | display: string; 174 | emptyCells: string; 175 | filter: string; 176 | flex: string; 177 | flexBasis: string; 178 | flexDirection: string; 179 | flexFlow: string; 180 | flexGrow: string; 181 | flexShrink: string; 182 | flexWrap: string; 183 | float: string; 184 | font: string; 185 | fontFamily: string; 186 | fontFeatureSettings: string; 187 | fontKerning: string; 188 | fontLanguageOverride: string; 189 | fontSize: string; 190 | fontSizeAdjust: string; 191 | fontStretch: string; 192 | fontStyle: string; 193 | fontSynthesis: string; 194 | fontVariant: string; 195 | fontVariantAlternates: string; 196 | fontVariantCaps: string; 197 | fontVariantEastAsian: string; 198 | fontVariantLigatures: string; 199 | fontVariantNumeric: string; 200 | fontVariantPosition: string; 201 | fontWeight: string; 202 | grad: string; 203 | grid: string; 204 | gridArea: string; 205 | gridAutoColumns: string; 206 | gridAutoFlow: string; 207 | gridAutoPosition: string; 208 | gridAutoRows: string; 209 | gridColumn: string; 210 | gridColumnStart: string; 211 | gridColumnEnd: string; 212 | gridRow: string; 213 | gridRowStart: string; 214 | gridRowEnd: string; 215 | gridTemplate: string; 216 | gridTemplateAreas: string; 217 | gridTemplateRows: string; 218 | gridTemplateColumns: string; 219 | height: string; 220 | hyphens: string; 221 | imageRendering: string; 222 | imageResolution: string; 223 | imageOrientation: string; 224 | imeMode: string; 225 | inherit: string; 226 | initial: string; 227 | inlineSize: string; 228 | isolation: string; 229 | justifyContent: string; 230 | left: string; 231 | letterSpacing: string; 232 | lineBreak: string; 233 | lineHeight: string; 234 | listStyle: string; 235 | listStyleImage: string; 236 | listStylePosition: string; 237 | listStyleType: string; 238 | margin: string; 239 | marginBlockEnd: string; 240 | marginBlockStart: string; 241 | marginBottom: string; 242 | marginInlineEnd: string; 243 | marginInlineStart: string; 244 | marginLeft: string; 245 | marginRight: string; 246 | marginTop: string; 247 | marks: string; 248 | mask: string; 249 | maskType: string; 250 | maxBlockSize: string; 251 | maxHeight: string; 252 | maxInlineSize: string; 253 | maxWidth: string; 254 | minBlockSize: string; 255 | minHeight: string; 256 | minInlineSize: string; 257 | minWidth: string; 258 | mixBlendMode: string; 259 | objectFit: string; 260 | objectPosition: string; 261 | offsetBlockEnd: string; 262 | offsetBlockStart: string; 263 | offsetInlineEnd: string; 264 | offsetInlineStart: string; 265 | opacity: string; 266 | order: string; 267 | orphans: string; 268 | outline: string; 269 | outlineColor: string; 270 | outlineOffset: string; 271 | outlineStyle: string; 272 | outlineWidth: string; 273 | overflow: string; 274 | overflowWrap: string; 275 | overflowX: string; 276 | overflowY: string; 277 | padding: string; 278 | paddingBlockEnd: string; 279 | paddingBlockStart: string; 280 | paddingBottom: string; 281 | paddingInlineEnd: string; 282 | paddingInlineStart: string; 283 | paddingLeft: string; 284 | paddingRight: string; 285 | paddingTop: string; 286 | pageBreakAfter: string; 287 | pageBreakBefore: string; 288 | pageBreakInside: string; 289 | perspective: string; 290 | perspectiveOrigin: string; 291 | pointerEvents: string; 292 | position: string; 293 | quotes: string; 294 | rad: string; 295 | resize: string; 296 | right: string; 297 | rubyAlign: string; 298 | rubyMerge: string; 299 | rubyPosition: string; 300 | scrollBehavior: string; 301 | scrollSnapCoordinate: string; 302 | scrollSnapDestination: string; 303 | scrollSnapPointsX: string; 304 | scrollSnapPointsY: string; 305 | scrollSnapType: string; 306 | shapeImageThreshold: string; 307 | shapeMargin: string; 308 | shapeOutside: string; 309 | tableLayout: string; 310 | tabSize: string; 311 | textAlign: string; 312 | textAlignLast: string; 313 | textCombineUpright: string; 314 | textDecoration: string; 315 | textDecorationColor: string; 316 | textDecorationLine: string; 317 | textDecorationStyle: string; 318 | textIndent: string; 319 | textOrientation: string; 320 | textOverflow: string; 321 | textRendering: string; 322 | textShadow: string; 323 | textTransform: string; 324 | textUnderlinePosition: string; 325 | top: string; 326 | touchAction: string; 327 | transform: string; 328 | transformOrigin: string; 329 | transformStyle: string; 330 | transition: string; 331 | transitionDelay: string; 332 | transitionDuration: string; 333 | transitionProperty: string; 334 | transitionTimingFunction: string; 335 | turn: string; 336 | unicodeBidi: string; 337 | unicodeRange: string; 338 | verticalAlign: string; 339 | visibility: string; 340 | whiteSpace: string; 341 | widows: string; 342 | width: string; 343 | willChange: string; 344 | wordBreak: string; 345 | wordSpacing: string; 346 | wordWrap: string; 347 | writingMode: string; 348 | zIndex: string; 349 | 350 | cssFloat: string; 351 | cssText: string; 352 | getPropertyPriority(property: string): string; 353 | getPropertyValue(property:string): string; 354 | item(index: number): string; 355 | length: number; 356 | parentRule: CSSRule; 357 | removeProperty(property: string): string; 358 | setProperty(property: string, value: ?string, priority: ?string): void; 359 | setPropertyPriority(property: string, priority: string): void; 360 | } 361 | 362 | declare class TransitionEvent extends Event { 363 | elapsedTime: number; // readonly 364 | pseudoElement: string; // readonly 365 | propertyName: string; // readonly 366 | } 367 | -------------------------------------------------------------------------------- /js/flowlib/indexeddb.js: -------------------------------------------------------------------------------- 1 | // Implemented by window & worker 2 | declare interface IDBEnvironment { 3 | indexedDB: IDBFactory; 4 | } 5 | 6 | type IDBDirection = 'next' | 'nextunique' | 'prev' | 'prevunique'; 7 | 8 | // Implemented by window.indexedDB & worker.indexedDB 9 | declare interface IDBFactory { 10 | open(name: string, version?: number): IDBOpenDBRequest; 11 | deleteDatabase(name: string): IDBOpenDBRequest; 12 | cmp(a: any, b: any): -1|0|1; 13 | } 14 | 15 | declare interface IDBRequest extends EventTarget { 16 | result: IDBObjectStore; 17 | error: Error; 18 | source: ?(IDBIndex | IDBObjectStore | IDBCursor); 19 | transaction: IDBTransaction; 20 | readyState: 'pending'|'done'; 21 | onerror: (err: any) => mixed; 22 | onsuccess: (e: any) => mixed; 23 | } 24 | 25 | declare interface IDBOpenDBRequest extends IDBRequest { 26 | onblocked: (e: any) => mixed; 27 | onupgradeneeded: (e: any) => mixed; 28 | } 29 | 30 | declare interface IDBDatabase extends EventTarget { 31 | close(): void; 32 | createObjectStore(name: string, options?: { 33 | keyPath?: ?(string|string[]), 34 | autoIncrement?: bool 35 | }): IDBObjectStore; 36 | deleteObjectStore(name: string): void; 37 | transaction(storeNames: string|string[], mode?: 'readonly'|'readwrite'|'versionchange'): IDBTransaction; 38 | name: string; 39 | version: number; 40 | objectStoreNames: string[]; 41 | onabort: (e: any) => mixed; 42 | onerror: (e: any) => mixed; 43 | onversionchange: (e: any) => mixed; 44 | } 45 | 46 | declare interface IDBTransaction extends EventTarget { 47 | abort(): void; 48 | db: IDBDatabase; 49 | error: Error; 50 | mode: 'readonly'|'readwrite'|'versionchange'; 51 | name: string; 52 | objectStore(name: string): IDBObjectStore; 53 | onabort: (e: any) => mixed; 54 | oncomplete: (e: any) => mixed; 55 | onerror: (e: any) => mixed; 56 | } 57 | 58 | declare interface IDBObjectStore { 59 | add(value: any, key?: any): IDBRequest; 60 | autoIncrement: bool; 61 | clear(): IDBRequest; 62 | createIndex(indexName: string, keyPath: string|string[], optionalParameter?: { 63 | unique?: bool, 64 | multiEntry?: bool, 65 | }): IDBIndex; 66 | count(keyRange?: any|IDBKeyRange): IDBRequest; 67 | delete(key: any): IDBRequest; 68 | deleteIndex(indexName: string): void; 69 | get(key: any): IDBRequest; 70 | index(indexName: string): IDBIndex; 71 | indexNames: string[]; 72 | name: string; 73 | keyPath: any; 74 | openCursor(range?: any|IDBKeyRange, direction?: IDBDirection): IDBRequest; 75 | openKeyCursor(range?: any|IDBKeyRange, direction?: IDBDirection): IDBRequest; 76 | put(value: any, key?: any): IDBRequest; 77 | transaction : IDBTransaction; 78 | } 79 | 80 | declare interface IDBIndex extends EventTarget { 81 | count(key?: any|IDBKeyRange): IDBRequest; 82 | get(key: any|IDBKeyRange): IDBRequest; 83 | getKey(key: any|IDBKeyRange): IDBRequest; 84 | openCursor(range?: any|IDBKeyRange, direction?: IDBDirection): IDBRequest; 85 | openKeyCursor(range?: any|IDBKeyRange, direction?: IDBDirection): IDBRequest; 86 | name: string; 87 | objectStore: IDBObjectStore; 88 | keyPath: any; 89 | multiEntry: bool; 90 | unique: bool; 91 | } 92 | 93 | declare interface IDBKeyRange { 94 | bound(lower: any, upper: any, lowerOpen?: bool, upperOpen?: bool): IDBKeyRange; 95 | only(value: any): IDBKeyRange; 96 | lowerBound(bound: any, open?: bool): IDBKeyRange; 97 | upperBound(bound: any, open?: bool): IDBKeyRange; 98 | lower: any; 99 | upper: any; 100 | lowerOpen: bool; 101 | upperOpen: bool; 102 | } 103 | 104 | declare interface IDBCursor { 105 | advance(count: number): void; 106 | continue(key?: any): void; 107 | delete(): IDBRequest; 108 | update(newValue: any): IDBRequest; 109 | source: IDBObjectStore|IDBIndex; 110 | direction: IDBDirection; 111 | key: any; 112 | primaryKey: any; 113 | } 114 | 115 | declare interface IDBCursorWithValue extends IDBCursor { 116 | value: any; 117 | } 118 | -------------------------------------------------------------------------------- /js/flowlib/node.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2013-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the "flow" directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * @flow 9 | */ 10 | 11 | type buffer$NonBufferEncoding = 12 | 'hex' | 'HEX' | 13 | 'utf8' | 'UTF8' | 'utf-8' | 'UTF-8' | 14 | 'ascii' | 'ASCII' | 15 | 'binary' | 'BINARY' | 16 | 'base64' | 'BASE64' | 17 | 'ucs2' | 'UCS2' | 'ucs-2' | 'UCS-2' | 18 | 'utf16le' | 'UTF16LE' | 'utf-16le' | 'UTF-16LE'; 19 | type buffer$Encoding = buffer$NonBufferEncoding | 'buffer' 20 | 21 | declare class Buffer { 22 | constructor( 23 | value: Array | number | string | Buffer, 24 | encoding?: buffer$Encoding 25 | ): void; 26 | [i: number]: number; 27 | length: number; 28 | write( 29 | string: string, 30 | offset?: number, 31 | length?: number, 32 | encoding?: buffer$Encoding 33 | ): void; 34 | copy(targetBuffer: Buffer, targetStart?: number, sourceStart?: number, sourceEnd?: number): number; 35 | equals(otherBuffer: Buffer): boolean; 36 | compare(otherBuffer: Buffer): number; 37 | slice(start?: number, end?: number): Buffer; 38 | fill(value: string | number, offset?: number, end?: number): void; 39 | inspect(): string; 40 | toString(encoding?: buffer$Encoding, start?: number, end?: number): string; 41 | toJSON(): Array; 42 | 43 | readUInt8(offset: number, noAssert?: boolean): number; 44 | readUInt16LE(offset: number, noAssert?: boolean): number; 45 | readUInt16BE(offset: number, noAssert?: boolean): number; 46 | readUInt32LE(offset: number, noAssert?: boolean): number; 47 | readUInt32BE(offset: number, noAssert?: boolean): number; 48 | readUIntLE(offset: number, byteLength: number, noAssert?: boolean): number; 49 | readUIntBE(offset: number, byteLength: number, noAssert?: boolean): number; 50 | readInt8(offset: number, noAssert?: boolean): number; 51 | readInt16LE(offset: number, noAssert?: boolean): number; 52 | readInt16BE(offset: number, noAssert?: boolean): number; 53 | readInt32LE(offset: number, noAssert?: boolean): number; 54 | readInt32BE(offset: number, noAssert?: boolean): number; 55 | readIntLE(offset: number, byteLength: number, noAssert?: boolean): number; 56 | readIntBE(offset: number, byteLength: number, noAssert?: boolean): number; 57 | readFloatLE(offset: number, noAssert?: boolean): number; 58 | readFloatBE(offset: number, noAssert?: boolean): number; 59 | readDoubleLE(offset: number, noAssert?: boolean): number; 60 | readDoubleBE(offset: number, noAssert?: boolean): number; 61 | writeUInt8(value: number, offset: number, noAssert?: boolean): number; 62 | writeUInt16LE(value: number, offset: number, noAssert?: boolean): number; 63 | writeUInt16BE(value: number, offset: number, noAssert?: boolean): number; 64 | writeUInt32LE(value: number, offset: number, noAssert?: boolean): number; 65 | writeUInt32BE(value: number, offset: number, noAssert?: boolean): number; 66 | writeUIntLE(value: number, offset: number, byteLength: number, noAssert?: boolean): number; 67 | writeUIntBE(value: number, offset: number, byteLength: number, noAssert?: boolean): number; 68 | writeInt8(value: number, offset: number, noAssert?: boolean): number; 69 | writeInt16LE(value: number, offset: number, noAssert?: boolean): number; 70 | writeInt16BE(value: number, offset: number, noAssert?: boolean): number; 71 | writeInt32LE(value: number, offset: number, noAssert?: boolean): number; 72 | writeInt32BE(value: number, offset: number, noAssert?: boolean): number; 73 | writeIntLE(value: number, offset: number, byteLength: number, noAssert?: boolean): number; 74 | writeIntBE(value: number, offset: number, byteLength: number, noAssert?: boolean): number; 75 | writeFloatLE(value: number, offset: number, noAssert?: boolean): number; 76 | writeFloatBE(value: number, offset: number, noAssert?: boolean): number; 77 | writeDoubleLE(value: number, offset: number, noAssert?: boolean): number; 78 | writeDoubleBE(value: number, offset: number, noAssert?: boolean): number; 79 | 80 | static alloc(size: number, fill?: string | number, encoding?: buffer$Encoding): Buffer; 81 | static isEncoding(encoding: string): boolean; 82 | static isBuffer(obj: any): boolean; 83 | static byteLength(string: string, encoding?: buffer$Encoding): number; 84 | static concat(list: Array, totalLength?: number): Buffer; 85 | static compare(buf1: Buffer, buf2: Buffer): number; 86 | } 87 | 88 | declare module "buffer" { 89 | declare var INSPECT_MAX_BYTES: number; 90 | } 91 | 92 | type child_process$execOpts = { 93 | cwd?: string; 94 | env?: Object; 95 | encoding?: string; 96 | shell?: string; 97 | timeout?: number; 98 | maxBuffer?: number; 99 | killSignal?: string; 100 | uid?: number; 101 | gid?: number; 102 | }; 103 | 104 | type child_process$execCallback = (error: ?Error, stdout: Buffer, stderr: Buffer) => void; 105 | 106 | type child_process$execSyncOpts = { 107 | cwd?: string; 108 | input?: string | Buffer; 109 | stdio?: Array; 110 | env?: Object; 111 | uid?: number; 112 | gid?: number; 113 | timeout?: number; 114 | killSignal?: string; 115 | maxBuffer?: number; 116 | encoding?: string; 117 | }; 118 | 119 | type child_process$execFileOpts = { 120 | cwd?: string; 121 | env?: Object; 122 | encoding?: string; 123 | timeout?: number; 124 | maxBuffer?: number; 125 | killSignal?: string; 126 | uid?: number; 127 | gid?: number; 128 | }; 129 | 130 | type child_process$execFileCallback = (error: ?Error, stdout: Buffer, stderr: Buffer) => void; 131 | 132 | type child_process$forkOpts = { 133 | cwd?: string; 134 | env?: Object; 135 | execPath?: string; 136 | execArgv?: Array; 137 | silent?: boolean; 138 | uid?: number; 139 | gid?: number; 140 | }; 141 | 142 | type child_process$Handle = any; // TODO 143 | 144 | type child_process$spawnOpts = { 145 | cwd?: string; 146 | env?: Object; 147 | stdio?: string | Array; 148 | detached?: boolean; 149 | uid?: number; 150 | gid?: number; 151 | }; 152 | 153 | type child_process$spawnRet = { 154 | pid: number; 155 | output: Array; 156 | stdout: Buffer | string; 157 | stderr: Buffer | string; 158 | status: number; 159 | signal: string; 160 | error: Error; 161 | }; 162 | 163 | declare class child_process$ChildProcess extends events$EventEmitter { 164 | stdin: stream$Writable; 165 | stdout: stream$Readable; 166 | stderr: stream$Readable; 167 | pid: number; 168 | connected: boolean; 169 | 170 | disconnect(): void; 171 | kill(signal?: string): void; 172 | send(message: Object, sendHandle?: child_process$Handle): void; 173 | } 174 | 175 | declare module "child_process" { 176 | declare var ChildProcess: typeof child_process$ChildProcess; 177 | 178 | declare function exec( 179 | command: string, 180 | optionsOrCallback?: child_process$execOpts | child_process$execCallback, 181 | callback?: child_process$execCallback 182 | ): child_process$ChildProcess; 183 | 184 | declare function execSync( 185 | command: string, 186 | options: {encoding: buffer$NonBufferEncoding} & child_process$execSyncOpts 187 | ): string; 188 | 189 | declare function execSync( 190 | command: string, 191 | options?: child_process$execSyncOpts 192 | ): Buffer; 193 | 194 | declare function execFile( 195 | file: string, 196 | argsOrOptionsOrCallback?: 197 | Array | child_process$execFileOpts | child_process$execFileCallback, 198 | optionsOrCallback?: child_process$execFileOpts | child_process$execFileCallback, 199 | callback?: child_process$execFileCallback 200 | ): child_process$ChildProcess; 201 | 202 | declare function execFileSync( 203 | command: string, 204 | argsOrOptions?: Array | child_process$execFileOpts, 205 | options?: child_process$execFileOpts 206 | ): Buffer | string; 207 | 208 | declare function fork( 209 | modulePath: string, 210 | argsOrOptions?: Array | child_process$forkOpts, 211 | options?: child_process$forkOpts 212 | ): child_process$ChildProcess; 213 | 214 | declare function spawn( 215 | command: string, 216 | argsOrOptions?: Array | child_process$spawnOpts, 217 | options?: child_process$spawnOpts 218 | ): child_process$ChildProcess; 219 | 220 | declare function spawnSync( 221 | command: string, 222 | argsOrOptions?: Array | child_process$spawnOpts, 223 | options?: child_process$spawnOpts 224 | ): child_process$spawnRet; 225 | } 226 | 227 | type cluster$Worker = { 228 | id: string; 229 | process: child_process$ChildProcess; 230 | suicide: boolean; 231 | 232 | disconnect(): void; 233 | kill(signal?: string): void; 234 | send(message: Object, sendHandle?: child_process$Handle): void; 235 | } 236 | 237 | declare module "cluster" { 238 | declare var isMaster: boolean; 239 | declare var isWorker: boolean; 240 | declare var settings: { 241 | args: Array; 242 | exec: string; 243 | execArgv: Array; 244 | silent: boolean; 245 | }; 246 | declare var worker: cluster$Worker; 247 | declare var workers: Object; 248 | 249 | declare function disconnect(callback?: () => void): void; 250 | declare function fork(env?: Object): cluster$Worker; 251 | declare function setupMaster(settings?: Object): void; 252 | } 253 | 254 | type crypto$createCredentialsDetails = any; // TODO 255 | 256 | type crypto$Cipher = { 257 | final(output_encoding?: string): any; 258 | setAutoPadding(auto_padding?: boolean): void; 259 | update(data: any, input_encoding?: string, output_encoding?: string): any; 260 | getAuthTag(): Buffer; 261 | } 262 | 263 | type crypto$Credentials = { 264 | // TODO 265 | } 266 | 267 | type crypto$DiffieHellman = { 268 | computeSecret( 269 | other_public_key: string, 270 | input_encoding?: string, 271 | output_encoding?: string 272 | ): any; 273 | generateKeys(encoding?: string): any; 274 | getGenerator(encoding?: string): any; 275 | getPrime(encoding?: string): any; 276 | getPrivateKey(encoding?: string): any; 277 | getPublicKey(encoding?: string): any; 278 | setPrivateKey(private_key: any, encoding?: string): void; 279 | setPublicKey(public_key: any, encoding?: string): void; 280 | } 281 | 282 | type crypto$Decipher = { 283 | update(data: any, input_encoding?: string, output_encoding?: string): any; 284 | final(output_encoding?: string): any; 285 | setAutoPadding(auto_padding?: boolean): void; 286 | setAuthTag(tag: Buffer): void; 287 | } 288 | 289 | type crypto$Hash = { 290 | update(data: any, input_encoding?: string): crypto$Hash; 291 | digest(encoding?: string): any; 292 | } 293 | 294 | type crypto$Hmac = { 295 | update(data: any): void; 296 | digest(encoding?: string): any; 297 | } 298 | 299 | type crypto$Sign = { 300 | sign(private_key: string, output_format?: string): any; 301 | update(data: any): void; 302 | } 303 | 304 | type crypto$Verify = { 305 | update(data: any): void; 306 | verify(object: Object, signature: crypto$Sign, signature_format?: string): boolean; 307 | } 308 | 309 | declare module "crypto" { 310 | declare var DEFAULT_ENCODING: string; 311 | 312 | declare function createCipher(algorithm: string, password: string | Buffer): crypto$Cipher; 313 | declare function createCipheriv( 314 | algorithm: string, 315 | key: string | Buffer, 316 | iv: string | Buffer 317 | ): crypto$Cipher; 318 | declare function createCredentials( 319 | details?: crypto$createCredentialsDetails 320 | ): crypto$Credentials 321 | declare function createDecipher(algorithm: string, password: string | Buffer): crypto$Decipher; 322 | declare function createDecipheriv( 323 | algorithm: string, 324 | key: string | Buffer, 325 | iv: string | Buffer 326 | ): crypto$Decipher; 327 | declare function createDiffieHellman(prime_length: number): crypto$DiffieHellman; 328 | declare function createDiffieHellman(prime: number, encoding?: string): crypto$DiffieHellman; 329 | declare function createHash(algorithm: string): crypto$Hash; 330 | declare function createHmac(algorithm: string, key: string | Buffer): crypto$Hmac; 331 | declare function creatSign(algorithm: string): crypto$Sign; 332 | declare function createVerify(algorithm: string): crypto$Verify; 333 | declare function getCiphers(): Array; 334 | declare function getDiffieHellman(group_name: string): crypto$DiffieHellman; 335 | declare function getHashes(): Array; 336 | declare function pbkdf2( 337 | password: string | Buffer, 338 | salt: string | Buffer, 339 | iterations: number, 340 | keylen: number, 341 | digestOrCallback: string | ((err: ?Error, derivedKey: Buffer) => void), 342 | callback?: (err: ?Error, derivedKey: Buffer) => void 343 | ): void; 344 | declare function pbkdf2Sync( 345 | password: string | Buffer, 346 | salt: string | Buffer, 347 | iterations: number, 348 | keylen: number, 349 | digest?: string 350 | ): Buffer; 351 | // `UNUSED` argument strictly enforces arity to enable overloading this 352 | // function with 1-arg and 2-arg variants. 353 | declare function pseudoRandomBytes(size: number, UNUSED: void): Buffer; 354 | declare function pseudoRandomBytes( 355 | size: number, 356 | callback: (err: ?Error, buffer: Buffer) => void 357 | ): void; 358 | // `UNUSED` argument strictly enforces arity to enable overloading this 359 | // function with 1-arg and 2-arg variants. 360 | declare function randomBytes(size: number, UNUSED: void): Buffer; 361 | declare function randomBytes( 362 | size: number, 363 | callback: (err: ?Error, buffer: Buffer) => void 364 | ): void; 365 | } 366 | 367 | type net$Socket$address = {address: string; family: string; port: number}; 368 | 369 | type dgram$Socket = { 370 | addMembership(multicastAddress: string, multicastInterface?: string): void; 371 | address(): net$Socket$address; 372 | bind(port: number, address?: string, callback?: () => void): void; 373 | close(): void; 374 | dropMembership(multicastAddress: string, multicastInterface?: string): void; 375 | ref(): void; 376 | send( 377 | buf: Buffer, 378 | offset: number, 379 | length: number, 380 | port: number, 381 | address: string, 382 | callback?: (err: ?Error, bytes: any) => void 383 | ): void; 384 | setBroadcast(flag: boolean): void; 385 | setMulticastLoopback(flag: boolean): void; 386 | setMulticastTTL(ttl: number): void; 387 | setTTL(ttl: number): void; 388 | unref(): void; 389 | }; 390 | 391 | declare module "dgram" { 392 | declare function createSocket(type: string, callback?: () => void): dgram$Socket; 393 | } 394 | 395 | declare module "dns" { 396 | declare var ADDRGETNETWORKPARAMS: string; 397 | declare var BADFAMILY: string; 398 | declare var BADFLAGS: string; 399 | declare var BADHINTS: string; 400 | declare var BADQUERY: string; 401 | declare var BADNAME: string; 402 | declare var BADRESP: string; 403 | declare var BADSTR: string; 404 | declare var CANCELLED: string; 405 | declare var CONNREFUSED: string; 406 | declare var DESTRUCTION: string; 407 | declare var EOF: string; 408 | declare var FILE: string; 409 | declare var FORMER: string; 410 | declare var LOADIPHLPAPI: string; 411 | declare var NODATA: string; 412 | declare var NOMEM: string; 413 | declare var NONAME: string; 414 | declare var NOTFOUND: string; 415 | declare var NOTIMP: string; 416 | declare var NOTINITIALIZED: string; 417 | declare var REFUSED: string; 418 | declare var SERVFAIL: string; 419 | declare var TIMEOUT: string; 420 | 421 | declare function lookup( 422 | domain: string, 423 | family?: ?number, 424 | callback?: (err: ?Error, address: string, family: number) => void 425 | ): void; 426 | 427 | declare function resolve( 428 | domain: string, 429 | rrtype?: string, 430 | callback?: (err: ?Error, addresses: Array) => void 431 | ): void; 432 | 433 | declare function resolve4( 434 | domain: string, 435 | callback: (err: ?Error, addresses: Array) => void 436 | ): void; 437 | 438 | declare function resolve6( 439 | domain: string, 440 | callback: (err: ?Error, addresses: Array) => void 441 | ): void; 442 | 443 | declare function resolveCname( 444 | domain: string, 445 | callback: (err: ?Error, addresses: Array) => void 446 | ): void; 447 | 448 | declare function resolveMx( 449 | domain: string, 450 | callback: (err: ?Error, addresses: Array) => void 451 | ): void; 452 | 453 | declare function resolveNs( 454 | domain: string, 455 | callback: (err: ?Error, addresses: Array) => void 456 | ): void; 457 | 458 | declare function resolveSrv( 459 | domain: string, 460 | callback: (err: ?Error, addresses: Array) => void 461 | ): void; 462 | 463 | declare function resolveTxt( 464 | domain: string, 465 | callback: (err: ?Error, addresses: Array) => void 466 | ): void; 467 | 468 | declare function reverse( 469 | ip: string, 470 | callback: (err: ?Error, domains: Array) => void 471 | ): void; 472 | } 473 | 474 | // TODO: This is copypasta of the EventEmitter class signature exported from the 475 | // `events` module. The only reason this exists is because other module 476 | // interface definitions need to reference this type structure -- but 477 | // referencing type structures defined in other modules isn't possible at 478 | // the time of this writing. 479 | declare class events$EventEmitter { 480 | // deprecated 481 | static listenerCount(emitter: events$EventEmitter, event: string): number; 482 | 483 | addListener(event: string, listener: Function): events$EventEmitter; 484 | emit(event: string, ...args:Array): boolean; 485 | listeners(event: string): Array; 486 | listenerCount(event: string): number; 487 | on(event: string, listener: Function): events$EventEmitter; 488 | once(event: string, listener: Function): events$EventEmitter; 489 | removeAllListeners(event?: string): events$EventEmitter; 490 | removeListener(event: string, listener: Function): events$EventEmitter; 491 | setMaxListeners(n: number): void; 492 | } 493 | 494 | 495 | declare module "events" { 496 | // TODO: See the comment above the events$EventEmitter declaration 497 | declare var EventEmitter: typeof events$EventEmitter; 498 | } 499 | 500 | declare class domain$Domain extends events$EventEmitter { 501 | members: Array; 502 | 503 | add(emitter: events$EventEmitter): void; 504 | bind(callback: Function): Function; 505 | dispose(): void; 506 | enter(): void; 507 | exit(): void; 508 | intercept(callback: Function): Function; 509 | remove(emitter: events$EventEmitter): void; 510 | run(fn: Function): void; 511 | } 512 | 513 | declare module "domain" { 514 | declare function create(): domain$Domain; 515 | } 516 | 517 | declare module "fs" { 518 | declare class Stats { 519 | dev: number; 520 | ino: number; 521 | mode: number; 522 | nlink: number; 523 | uid: number; 524 | gid: number; 525 | rdev: number; 526 | size: number; 527 | blksize: number; 528 | blocks: number; 529 | atime: Date; 530 | mtime: Date; 531 | ctime: Date; 532 | 533 | isFile(): boolean; 534 | isDirectory(): boolean; 535 | isBlockDevice(): boolean; 536 | isCharacterDevice(): boolean; 537 | isSymbolicLink(): boolean; 538 | isFIFO(): boolean; 539 | isSocket(): boolean; 540 | } 541 | 542 | declare class FSWatcher extends events$EventEmitter { 543 | close(): void 544 | } 545 | 546 | declare class ReadStream extends stream$Readable { 547 | close(): void 548 | } 549 | 550 | declare class WriteStream extends stream$Writable { 551 | close(): void 552 | } 553 | 554 | declare function rename(oldPath: string, newPath: string, callback?: (err: ?Error) => void): void; 555 | declare function renameSync(oldPath: string, newPath: string): void; 556 | declare function ftruncate(fd: number, len: number, callback?: (err: ?Error) => void): void; 557 | declare function ftruncateSync(fd: number, len: number): void; 558 | declare function truncate(path: string, len: number, callback?: (err: ?Error) => void): void; 559 | declare function truncateSync(path: string, len: number): void; 560 | declare function chown(path: string, uid: number, gid: number, callback?: (err: ?Error) => void): void; 561 | declare function chownSync(path: string, uid: number, gid: number): void; 562 | declare function fchown(fd: number, uid: number, gid: number, callback?: (err: ?Error) => void): void; 563 | declare function fchownSync(fd: number, uid: number, gid: number): void; 564 | declare function lchown(path: string, uid: number, gid: number, callback?: (err: ?Error) => void): void; 565 | declare function lchownSync(path: string, uid: number, gid: number): void; 566 | declare function chmod(path: string, mode: number | string, callback?: (err: ?Error) => void): void; 567 | declare function chmodSync(path: string, mode: number | string): void; 568 | declare function fchmod(fd: number, mode: number | string, callback?: (err: ?Error) => void): void; 569 | declare function fchmodSync(fd: number, mode: number | string): void; 570 | declare function lchmod(path: string, mode: number | string, callback?: (err: ?Error) => void): void; 571 | declare function lchmodSync(path: string, mode: number | string): void; 572 | declare function stat(path: string, callback?: (err: ?Error, stats: Stats) => any): void; 573 | declare function statSync(path: string): Stats; 574 | declare function fstat(fd: number, callback?: (err: ?Error, stats: Stats) => any): void; 575 | declare function fstatSync(fd: number): Stats; 576 | declare function lstat(path: string, callback?: (err: ?Error, stats: Stats) => any): void; 577 | declare function lstatSync(path: string): Stats; 578 | declare function link(srcpath: string, dstpath: string, callback?: (err: ?Error) => void): void; 579 | declare function linkSync(srcpath: string, dstpath: string): void; 580 | declare function symlink(srcpath: string, dtspath: string, type?: string, callback?: (err: ?Error) => void): void; 581 | declare function symlinkSync(srcpath: string, dstpath: string, type: string): void; 582 | declare function readlink(path: string, callback: (err: ?Error, linkString: string) => void): void; 583 | declare function readlinkSync(path: string): string; 584 | declare function realpath(path: string, cache?: Object, callback?: (err: ?Error, resolvedPath: string) => void): void; 585 | declare function realpathSync(path: string, cache?: Object): string; 586 | declare function unlink(path: string, callback?: (err: ?Error) => void): void; 587 | declare function unlinkSync(path: string): void; 588 | declare function rmdir(path: string, callback?: (err: ?Error) => void): void; 589 | declare function rmdirSync(path: string): void; 590 | declare function mkdir(path: string, mode?: number, callback?: (err: ?Error) => void): void; 591 | declare function mkdirSync(path: string, mode?: number): void; 592 | declare function readdir(path: string, callback?: (err: ?Error, files: Array) => void): void; 593 | declare function readdirSync(path: string): Array; 594 | declare function close(fd: number, callback?: (err: ?Error) => void): void; 595 | declare function closeSync(fd: number): void; 596 | declare function open(path: string, flags: string, mode?: number, callback?: (err: ?Error, fd: number) => void): void; 597 | declare function openSync(path: string, flags: string, mode?: number): number; 598 | declare function utimes(path: string, atime: number, mtime: number, callback?: (err: ?Error) => void): void; 599 | declare function utimesSync(path: string, atime: number, mtime: number): void; 600 | declare function futimes(fd: number, atime: number, mtime: number, callback?: (err: ?Error) => void): void; 601 | declare function futimesSync(fd: number, atime: number, mtime: number): void; 602 | declare function fsync(fd: number, callback?: (err: ?Error) => void): void; 603 | declare function fsyncSync(fd: number): void; 604 | declare var write: (fd: number, buffer: Buffer, offset: number, length: number, position?: mixed, callback?: (err: ?Error, write: number, str: string) => void) => void 605 | | (fd: number, data: mixed, position?: mixed, encoding?: string, callback?: (err: ?Error, write: number, str: string) => void) => void; 606 | declare var writeSync: (fd: number, buffer: Buffer, offset: number, length: number, position?: number) => number 607 | | (fd: number, data: mixed, position?: mixed, encoding?: string) => number; 608 | declare function read( 609 | fd: number, 610 | buffer: Buffer, 611 | offset: number, 612 | length: number, 613 | position: ?number, 614 | callback?: (err: ?Error, bytesRead: number, buffer: Buffer) => void 615 | ): void; 616 | declare function readSync( 617 | fd: number, 618 | buffer: Buffer, 619 | offset: number, 620 | length: number, 621 | position: number 622 | ): number; 623 | declare function readFile( 624 | filename: string, 625 | callback: (err: ?Error, data: Buffer) => void 626 | ): void; 627 | declare function readFile( 628 | filename: string, 629 | encoding: string, 630 | callback: (err: ?Error, data: string) => void 631 | ): void; 632 | declare function readFile( 633 | filename: string, 634 | options: { encoding: string; flag?: string }, 635 | callback: (err: ?Error, data: string) => void 636 | ): void; 637 | declare function readFile( 638 | filename: string, 639 | options: { flag?: string }, 640 | callback: (err: ?Error, data: Buffer) => void 641 | ): void; 642 | declare function readFileSync(filename: string): Buffer; 643 | declare function readFileSync(filename: string, encoding: string): string; 644 | declare function readFileSync(filename: string, options: { encoding: string, flag?: string }): string; 645 | declare function readFileSync(filename: string, options: { flag?: string }): Buffer; 646 | declare function writeFile( 647 | filename: string, 648 | data: Buffer | string, 649 | options?: Object | string, 650 | callback?: (err: ?Error) => void 651 | ): void; 652 | declare function writeFileSync( 653 | filename: string, 654 | data: Buffer | string, 655 | options?: Object | string 656 | ): void; 657 | declare function appendFile(filename: string, data: string | Buffer, options?: Object, callback?: (err: ?Error) => void): void; 658 | declare function appendFileSync(filename: string, data: string | Buffer, options?: Object): void; 659 | declare function watchFile(filename: string, options?: Object, listener?: (curr: Stats, prev: Stats) => void): void; 660 | declare function unwatchFile(filename: string, listener?: (curr: Stats, prev: Stats) => void): void; 661 | declare function watch(filename: string, options?: Object, listener?: (event: string, filename: string) => void): FSWatcher; 662 | declare function exists(path: string, callback?: (exists: boolean) => void): void; 663 | declare function existsSync(path: string): boolean; 664 | declare function access(path: string, mode?: any, callback?: (err: ?Error) => void): void; 665 | declare function accessSync(path: string, mode?: any): void; 666 | declare function createReadStream(path: string, options?: Object): ReadStream; 667 | declare function createWriteStream(path: string, options?: Object): WriteStream; 668 | 669 | declare var F_OK: number; 670 | declare var R_OK: number; 671 | declare var W_OK: number; 672 | declare var X_OK: number; 673 | } 674 | 675 | declare class http$IncomingMessage extends stream$Readable { 676 | headers: Object; 677 | httpVersion: string; 678 | method: string; 679 | trailers: Object; 680 | setTimeout(msecs: number, callback: Function): void; 681 | socket: net$Socket; 682 | statusCode: number; 683 | url: String; 684 | } 685 | 686 | declare class http$ClientRequest extends stream$Writable { 687 | flushHeaders(): void; 688 | abort(): void; 689 | setTimeout(msecs: number, callback?: Function): void; 690 | setNoDelay(noDelay?: boolean): void; 691 | setSocketKeepAlive(enable?: boolean, initialDelay?: number): void; 692 | } 693 | 694 | declare module "http" { 695 | declare class Server extends net$Server { 696 | listen(port: number, hostname?: string, backlog?: number, callback?: Function): Server; 697 | listen(path: string, callback?: Function): Server; 698 | listen(handle: Object, callback?: Function): Server; 699 | close(callback?: Function): Server; 700 | maxHeadersCount: number; 701 | setTimeout(msecs: number, callback: Function): Server; 702 | timeout: number; 703 | } 704 | 705 | declare class ClientRequest extends http$ClientRequest {} 706 | declare class IncomingMessage extends http$IncomingMessage {} 707 | 708 | declare function createServer(listener?: Function): Server; 709 | declare function request( 710 | options: Object | string, 711 | callback?: (response: IncomingMessage) => void 712 | ): ClientRequest; 713 | declare function get( 714 | options: Object | string, 715 | callback?: (response: IncomingMessage) => void 716 | ): ClientRequest; 717 | } 718 | 719 | declare module "https" { 720 | declare class Server extends tls$Server { 721 | listen(port: number, hostname?: string, backlog?: number, callback?: Function): Server; 722 | listen(path: string, callback?: Function): Server; 723 | listen(handle: Object, callback?: Function): Server; 724 | close(callback?: Function): Server; 725 | setTimeout(msecs: number, callback: Function): Server; 726 | timeout: number; 727 | } 728 | 729 | declare class ClientRequest extends http$ClientRequest {} 730 | declare class IncomingMessage extends http$IncomingMessage {} 731 | 732 | declare function createServer(options: Object, secureConnectionListener?: function): Server; 733 | declare function request( 734 | options: Object | string, 735 | callback?: (response: IncomingMessage) => void 736 | ): ClientRequest; 737 | declare function get( 738 | options: Object | string, 739 | callback?: (response: IncomingMessage) => void 740 | ): ClientRequest; 741 | 742 | } 743 | 744 | declare class net$Socket extends stream$Duplex { 745 | constructor(options?: Object): void; 746 | address(): net$Socket$address; 747 | bufferSize: number; 748 | bytesRead: number; 749 | bytesWritten: number; 750 | connect(options: Object, connectListener?: function): void; 751 | destroy(): void; 752 | end( 753 | chunk?: string | Buffer, 754 | encodingOrCallback?: string | (data: any) => void, 755 | callback?: (data: any) => void 756 | ): void; 757 | localAddress: string; 758 | localPort: number; 759 | pause(): stream$Readable; 760 | ref(): net$Socket; 761 | remoteAddress: string | void; 762 | remoteFamily: string; 763 | remotePort: number; 764 | resume(): stream$Readable; 765 | setEncoding(encoding?: string): stream$Readable; 766 | setKeepAlive(enable?: boolean, initialDelay?: number): net$Socket; 767 | setNoDelay(noDelay?: boolean): net$Socket; 768 | setTimeout(timeout: number, callback?: function): net$Socket; 769 | unref(): net$Socket; 770 | write( 771 | chunk?: string | Buffer, 772 | encodingOrCallback?: string | (data: any) => void, 773 | callback?: (data: any) => void 774 | ): boolean; 775 | } 776 | 777 | declare class net$Server extends events$EventEmitter { 778 | listen(port: number, hostname?: string, backlog?: number, callback?: Function): net$Server; 779 | listen(path: string, callback?: Function): net$Server; 780 | listen(handle: Object, callback?: Function): net$Server; 781 | close(callback?: Function): net$Server; 782 | address(): net$Socket$address; 783 | connections: number; 784 | maxConnections: number; 785 | getConnections(callback: Function): void; 786 | ref(): net$Server; 787 | unref(): net$Server; 788 | } 789 | 790 | declare module "net" { 791 | 792 | 793 | declare class Server extends net$Server {} 794 | declare class Socket extends net$Socket {} 795 | 796 | declare function isIP(input: string): number; 797 | declare function isIPv4(input: string): boolean; 798 | declare function isIPv6(input: string): boolean; 799 | 800 | 801 | declare type connectionListener = (socket: Socket) => any; 802 | declare function createServer( 803 | options?: { 804 | allowHalfOpen?: boolean, 805 | pauseOnConnect?: boolean, 806 | } | connectionListener, 807 | connectionListener?: connectionListener, 808 | ): Server; 809 | 810 | declare type connectListener = () => any; 811 | declare function connect( 812 | options?: { 813 | port?: number, 814 | host?: string, 815 | localAddress?: string, 816 | localPort?: number, 817 | family?: number, 818 | lookup?: string, 819 | path?: string, 820 | } | connectListener, 821 | connectListener?: connectListener, 822 | ) : Socket; 823 | } 824 | 825 | type os$CPU = { 826 | model: string, 827 | speed: number, 828 | times: { 829 | idle: number, 830 | irq: number, 831 | nice: number, 832 | sys: number, 833 | user: number, 834 | } 835 | }; 836 | 837 | type os$NetIFAddr = { 838 | address: string, 839 | family: string, 840 | internal: boolean, 841 | mac: string, 842 | netmask: string 843 | }; 844 | 845 | declare module "os" { 846 | declare function arch(): "x64"|"arm"|"ia32"; 847 | declare function cpus(): Array; 848 | declare function endianness(): "BE"|"LE"; 849 | declare function freemem(): number; 850 | declare function homedir(): string; 851 | declare function hostname(): string; 852 | declare function loadavg(): [number, number, number]; 853 | declare function networkInterfaces(): {[ifName: string]: Array}; 854 | declare function platform(): string; 855 | declare function release(): string; 856 | declare function tmpdir(): string; 857 | declare function totalmem(): number; 858 | declare function type(): string; 859 | declare function uptime(): number; 860 | declare var EOL: string; 861 | } 862 | 863 | declare module "path" { 864 | declare function normalize(path: string): string; 865 | declare function join(...parts: Array): string; 866 | declare function resolve(...parts: Array): string; 867 | declare function isAbsolute(path: string): boolean; 868 | declare function relative(from: string, to: string): string; 869 | declare function dirname(path: string): string; 870 | declare function basename(path: string, ext?: string): string; 871 | declare function extname(path: string): string; 872 | declare var sep: string; 873 | declare var delimiter: string; 874 | declare function parse(pathString: string): { 875 | root: string; 876 | dir: string; 877 | base: string; 878 | ext: string; 879 | name: string; 880 | }; 881 | declare function format(pathObject: { 882 | root?: string; 883 | dir?: string; 884 | base?: string; 885 | ext?: string; 886 | name?: string; 887 | }): string; 888 | declare var posix: any; 889 | declare var win32: any; 890 | } 891 | 892 | declare module "punycode" { 893 | declare function decode(string: string): string; 894 | declare function encode(string: string): string; 895 | declare function toASCII(domain: string): string; 896 | declare function toUnicode(domain: string): string; 897 | declare var ucs2: { 898 | decode: (str: string) => Array, 899 | encode: (codePoints: Array) => string 900 | }; 901 | declare var version : string; 902 | } 903 | 904 | declare module "querystring" { 905 | declare function stringify( 906 | obj: Object, 907 | separator?: string, 908 | equal?: string, 909 | options?: { 910 | encodeURIComponent?: (str: string) => string; 911 | } 912 | ): string; 913 | declare function parse( 914 | str: string, 915 | separator: ?string, 916 | equal: ?string, 917 | options?: { 918 | decodeURIComponent?: (str: string) => string; 919 | maxKeys?: number; 920 | } 921 | ): any; 922 | declare function escape(str: string): string; 923 | declare function unescape(str: string, decodeSpaces?: boolean): string; 924 | } 925 | 926 | declare class readline$Interface extends events$EventEmitter { 927 | close(): void; 928 | pause(): void; 929 | prompt(preserveCursor?: boolean): void; 930 | question(query: string, callback: (answer: string) => void): void; 931 | resume(): void; 932 | setPrompt(prompt: string): void; 933 | write(val: string | void | null, key?: { 934 | name: string, 935 | ctrl?: boolean, 936 | shift?: boolean, 937 | meta?: boolean 938 | }): void; 939 | } 940 | 941 | declare module "readline" { 942 | declare var Interface : typeof readline$Interface; 943 | declare function clearLine(stream: stream$Stream, dir: -1 | 1 | 0): void; 944 | declare function clearScreenDown(stream: stream$Stream): void; 945 | declare function createInterface(opts: { 946 | input: stream$Readable, 947 | output?: stream$Stream, 948 | completer?: (completions: Array, matchedString: string) => void, 949 | terminal?: boolean, 950 | historySize?: number 951 | }): readline$Interface; 952 | declare function cursorTo(stream: stream$Stream, x?: number, y?: number): void; 953 | declare function moveCursor(stream: stream$Stream, dx: number, dy: number): void; 954 | } 955 | 956 | declare class stream$Stream extends events$EventEmitter {} 957 | 958 | type readableStreamOptions = { highWaterMark? : number, encoding? : ?string, objectMode? : boolean }; 959 | declare class stream$Readable extends stream$Stream { 960 | constructor(options?: readableStreamOptions): void; 961 | setEncoding(encoding : string): stream$Readable; 962 | isPaused(): boolean; 963 | pause(): stream$Readable; 964 | pipe(dest: stream$Duplex, options?: { end? : boolean }): stream$Duplex; 965 | pipe(dest: stream$Writable, options?: { end? : boolean }): stream$Writable; 966 | read(size?: number): ?(string | Buffer); 967 | resume(): stream$Readable; 968 | unpipe(dest?: (stream$Writable | stream$Duplex)): void; 969 | unshift(chunk: Buffer | string): void; 970 | push(chunk: ?(Buffer | string), encoding? : string): boolean; 971 | wrap(oldReadable: any): stream$Readable; 972 | } 973 | 974 | type writableStreamOptions = { highWaterMark? : number, decodeString? : boolean, objectMode? : boolean }; 975 | declare class stream$Writable extends stream$Stream { 976 | constructor(options?: writableStreamOptions): void; 977 | cork(): void; 978 | end( 979 | chunkOrEncodingOrCallback?: Buffer | string | Function, 980 | encodingOrCallback?: string | Function, 981 | callback?: Function 982 | ): void; 983 | setDefaultEncoding(encoding: string): boolean; 984 | uncork() : void; 985 | write( 986 | chunk: Buffer | string, 987 | encodingOrCallback?: string | Function, 988 | callback?: Function 989 | ): boolean; 990 | _write( 991 | chunk: Buffer | string, 992 | encoding: string, 993 | callback: (error: ?Error, data?: Buffer | string) => void 994 | ): boolean; 995 | } 996 | 997 | //According to the NodeJS docs: 998 | //"Since JavaScript doesn't have multiple prototypal inheritance, this class 999 | //prototypally inherits from Readable, and then parasitically from Writable." 1000 | //Source: void 1025 | ): boolean; 1026 | } 1027 | declare class stream$Transform extends stream$Duplex { 1028 | _transform( 1029 | chunk: Buffer | string, 1030 | encoding: string, 1031 | callback: (error: ?Error, data?: Buffer | string) => void 1032 | ): void; 1033 | _flush( 1034 | callback: (error: ?Error) => void 1035 | ): void; 1036 | } 1037 | declare class stream$PassThrough extends stream$Transform {} 1038 | 1039 | declare module "stream" { 1040 | declare var Readable : typeof stream$Readable 1041 | declare var Writable : typeof stream$Writable 1042 | declare var Duplex : typeof stream$Duplex 1043 | declare var Transform : typeof stream$Transform 1044 | declare var PassThrough : typeof stream$PassThrough 1045 | } 1046 | 1047 | declare class tty$ReadStream extends net$Socket { 1048 | isRaw : boolean; 1049 | setRawMode(mode : boolean) : void; 1050 | isTTY : true 1051 | } 1052 | declare class tty$WriteStream extends net$Socket { 1053 | columns : number; 1054 | rows : number; 1055 | isTTY : true 1056 | } 1057 | 1058 | declare module "tty" { 1059 | declare function isatty(fd : number) : boolean; 1060 | declare function setRawMode(mode : boolean) : void; 1061 | declare var ReadStream : typeof tty$ReadStream 1062 | declare var WriteStream : typeof tty$WriteStream 1063 | } 1064 | 1065 | declare class string_decoder$StringDecoder { 1066 | constructor(encoding?: 'utf8' | 'ucs2' | 'utf16le' | 'base64'): void; 1067 | end(): void; 1068 | write(buffer: Buffer): string; 1069 | } 1070 | 1071 | declare module "string_decoder" { 1072 | declare var StringDecoder : typeof string_decoder$StringDecoder; 1073 | } 1074 | 1075 | declare class tls$TLSSocket extends net$Socket { 1076 | constructor(socket: net$Socket, options?: Object): void; 1077 | authorized: boolean; 1078 | authorizationError: string | null; 1079 | encrypted: true; 1080 | getCipher(): { name: string, version: string } | null; 1081 | getEphemeralKeyInfo(): { type: 'DH', size: number } | { type: 'EDHC', name: string, size: number } | null; 1082 | getPeerCertificate(detailed?: boolean): Object | null; 1083 | getSession(): ?Buffer; 1084 | getTLSTicket(): Buffer | void; 1085 | renegotiate(options: Object, callback: Function): boolean | void; 1086 | setMaxSendFragment(size: number): boolean; 1087 | } 1088 | 1089 | declare class tls$Server extends net$Server { 1090 | listen(port: number, hostname?: string, backlog?: number, callback?: Function): tls$Server; 1091 | listen(path: string, callback?: Function): tls$Server; 1092 | listen(handle: Object, callback?: Function): tls$Server; 1093 | close(callback?: Function): tls$Server; 1094 | addContext(hostname: string, context: Object): void; 1095 | getTicketKeys(): Buffer; 1096 | setTicketKeys(keys: Buffer): void; 1097 | } 1098 | 1099 | declare module "tls" { 1100 | declare var CLIENT_RENEG_LIMIT: number; 1101 | declare var CLIENT_RENEG_WINDOW: number; 1102 | declare var SLAB_BUFFER_SIZE: number; 1103 | declare var DEFAULT_CIPHERS: string; 1104 | declare var DEFAULT_ECDH_CURVE: string; 1105 | declare function getCiphers(): Array; 1106 | declare function convertNPNProtocols(NPNProtocols: Array, out: Object): void; 1107 | declare function checkServerIdentity(servername: string, cert: string): Error | void; 1108 | declare function parseCertString(s: string): Object; 1109 | declare function createSecureContext(details: Object): Object; 1110 | declare var SecureContext: Object; 1111 | declare var TLSSocket: typeof tls$TLSSocket; 1112 | declare var Server: typeof tls$Server; 1113 | declare function createServer(options: Object, secureConnectionListener?: function): typeof tls$Server; 1114 | declare function connect(options: Object, callback?: function): typeof tls$TLSSocket; 1115 | declare function connect(port: number, host?: string, options?: Object, callback?: function): typeof tls$TLSSocket; 1116 | declare function createSecurePair(context?: Object, isServer?: boolean, requestCert?: boolean, rejectUnauthorized?: boolean, options?: Object): Object; 1117 | } 1118 | 1119 | declare module "url" { 1120 | declare function parse( 1121 | urlStr: string, 1122 | parseQueryString?: boolean, 1123 | slashesDenoteHost?: boolean 1124 | ): { 1125 | protocol?: string; 1126 | slashes?: boolean; 1127 | auth?: string; 1128 | host?: string; 1129 | port?: string; 1130 | hostname?: string; 1131 | hash?: string; 1132 | search?: string; 1133 | query?: any; // null | string | Object 1134 | pathname?: string; 1135 | path?: string; 1136 | href: string; 1137 | }; 1138 | declare function format(urlObj: { 1139 | href?: string; 1140 | protocol?: string; 1141 | slashes?: boolean; 1142 | auth?: string; 1143 | hostname?: string; 1144 | port?: string | number; 1145 | host?: string; 1146 | pathname?: string; 1147 | search?: string; 1148 | query?: Object; 1149 | hash?: string; 1150 | }): string; 1151 | declare function resolve(from: string, to: string): string; 1152 | } 1153 | 1154 | declare module "util" { 1155 | declare function debuglog(section: string): (data: any, ...args: any) => void; 1156 | declare function format(format: string, ...placeholders: any): string; 1157 | declare function log(string: string): void; 1158 | declare function inspect(object: any, options?: { 1159 | showHidden?: boolean; 1160 | depth?: ?number; 1161 | colors?: boolean; 1162 | customInspect?: boolean; 1163 | }): string; 1164 | declare function isArray(object: any): boolean; 1165 | declare function isRegExp(object: any): boolean; 1166 | declare function isDate(object: any): boolean; 1167 | declare function isError(object: any): boolean; 1168 | declare function inherits(constructor: Function, superConstructor: Function): void; 1169 | declare function deprecate(f: Function, string: string): Function; 1170 | } 1171 | 1172 | type vm$ScriptOptions = { 1173 | filename?: string, 1174 | lineOffset?: number, 1175 | columnOffset?: number, 1176 | displayErrors?: boolean, 1177 | timeout?: number 1178 | }; 1179 | 1180 | declare class vm$Script { 1181 | constructor(code: string, options: Object): void; 1182 | runInContext(contextifiedSandbox: vm$Context, options?: vm$ScriptOptions): any; 1183 | runInNewContext(sandbox?: Object, options?: vm$ScriptOptions): any; 1184 | runInThisContext(options?: vm$ScriptOptions): any; 1185 | } 1186 | 1187 | declare class vm$Context {} 1188 | 1189 | declare module "vm" { 1190 | declare var Script : typeof vm$Script 1191 | declare function createContext(sandbox?: Object): vm$Context; 1192 | declare function isContext(sandbox: any): boolean; 1193 | declare function runInContext(code: string, contextifiedSandbox: vm$Context, options?: vm$ScriptOptions): any; 1194 | declare function runInDebugContext(code: string): any; 1195 | declare function runInNewContext(code: string, sandbox?: Object, options?: vm$ScriptOptions): any; 1196 | declare function runInThisContext(code: string, options?: vm$ScriptOptions): any; 1197 | } 1198 | 1199 | type zlib$options = { 1200 | flush?: number; 1201 | chunkSize?: number; 1202 | windowBits?: number; 1203 | level?: number; 1204 | memLevel?: number; 1205 | strategy?: number; 1206 | dictionary?: Buffer; 1207 | }; 1208 | 1209 | type zlib$syncFn = ( 1210 | buffer: string | Buffer, 1211 | options?: zlib$options 1212 | ) => Buffer; 1213 | 1214 | type zlib$asyncFn = ( 1215 | buffer: string | Buffer, 1216 | options?: zlib$options, 1217 | callback?: ((error: ?Error, result: any) => void) 1218 | ) => void; 1219 | 1220 | declare module "zlib" { 1221 | declare var Z_NO_FLUSH: number; 1222 | declare var Z_PARTIAL_FLUSH: number; 1223 | declare var Z_SYNC_FLUSH: number; 1224 | declare var Z_FULL_FLUSH: number; 1225 | declare var Z_FINISH: number; 1226 | declare var Z_BLOCK: number; 1227 | declare var Z_TREES: number; 1228 | declare var Z_OK: number; 1229 | declare var Z_STREAM_END: number; 1230 | declare var Z_NEED_DICT: number; 1231 | declare var Z_ERRNO: number; 1232 | declare var Z_STREAM_ERROR: number; 1233 | declare var Z_DATA_ERROR: number; 1234 | declare var Z_MEM_ERROR: number; 1235 | declare var Z_BUF_ERROR: number; 1236 | declare var Z_VERSION_ERROR: number; 1237 | declare var Z_NO_COMPRESSION: number; 1238 | declare var Z_BEST_SPEED: number; 1239 | declare var Z_BEST_COMPRESSION: number; 1240 | declare var Z_DEFAULT_COMPRESSION: number; 1241 | declare var Z_FILTERED: number; 1242 | declare var Z_HUFFMAN_ONLY: number; 1243 | declare var Z_RLE: number; 1244 | declare var Z_FIXED: number; 1245 | declare var Z_DEFAULT_STRATEGY: number; 1246 | declare var Z_BINARY: number; 1247 | declare var Z_TEXT: number; 1248 | declare var Z_ASCII: number; 1249 | declare var Z_UNKNOWN: number; 1250 | declare var Z_DEFLATED: number; 1251 | declare var Z_NULL: number; 1252 | declare var Z_DEFAULT_CHUNK: number; 1253 | declare var Z_DEFAULT_LEVEL: number; 1254 | declare var Z_DEFAULT_MEMLEVEL: number; 1255 | declare var Z_DEFAULT_WINDOWBITS: number; 1256 | declare var Z_MAX_CHUNK: number; 1257 | declare var Z_MAX_LEVEL: number; 1258 | declare var Z_MAX_MEMLEVEL: number; 1259 | declare var Z_MAX_WINDOWBITS: number; 1260 | declare var Z_MIN_CHUNK: number; 1261 | declare var Z_MIN_LEVEL: number; 1262 | declare var Z_MIN_MEMLEVEL: number; 1263 | declare var Z_MIN_WINDOWBITS: number; 1264 | declare var codes: { 1265 | Z_OK: number, 1266 | Z_STREAM_END: number, 1267 | Z_NEED_DICT: number, 1268 | Z_ERRNO: number, 1269 | Z_STREAM_ERROR: number, 1270 | Z_DATA_ERROR: number, 1271 | Z_MEM_ERROR: number, 1272 | Z_BUF_ERROR: number, 1273 | Z_VERSION_ERROR: number 1274 | }; 1275 | declare class Zlib extends stream$Duplex { 1276 | // TODO 1277 | } 1278 | declare class Deflate extends Zlib {} 1279 | declare class Inflate extends Zlib {} 1280 | declare class Gzip extends Zlib {} 1281 | declare class Gunzip extends Zlib {} 1282 | declare class DeflateRaw extends Zlib {} 1283 | declare class InflateRaw extends Zlib {} 1284 | declare class Unzip extends Zlib {} 1285 | declare function createDeflate(options?: zlib$options): Deflate; 1286 | declare function createInflate(options?: zlib$options): Inflate; 1287 | declare function createDeflateRaw(options?: zlib$options): DeflateRaw; 1288 | declare function createInflateRaw(options?: zlib$options): InflateRaw; 1289 | declare function createGzip(options?: zlib$options): Gzip; 1290 | declare function createGunzip(options?: zlib$options): Gunzip; 1291 | declare function createUnzip(options?: zlib$options): Unzip; 1292 | declare var deflate: zlib$asyncFn; 1293 | declare var deflateSync: zlib$syncFn; 1294 | declare var gzip: zlib$asyncFn; 1295 | declare var gzipSync: zlib$syncFn; 1296 | declare var deflateRaw: zlib$asyncFn; 1297 | declare var deflateRawSync: zlib$syncFn; 1298 | declare var unzip: zlib$asyncFn; 1299 | declare var unzipSync: zlib$syncFn; 1300 | declare var inflate: zlib$asyncFn; 1301 | declare var inflateSync: zlib$syncFn; 1302 | declare var gunzip: zlib$asyncFn; 1303 | declare var gunzipSync: zlib$syncFn; 1304 | declare var inflateRaw: zlib$asyncFn; 1305 | declare var inflateRawSync: zlib$syncFn; 1306 | } 1307 | 1308 | declare module "assert" { 1309 | declare var exports: { 1310 | (value: any, message?: string): void; 1311 | ok(value: any, message?: string): void; 1312 | fail(actual: any, expected: any, message: string, operator: string): void; 1313 | equal(actual: any, expected: any, message?: string): void; 1314 | notEqual(actual: any, expected: any, message?: string): void; 1315 | deepEqual(actual: any, expected: any, message?: string): void; 1316 | notDeepEqual(actual: any, expected: any, message?: string): void; 1317 | strictEqual(actual: any, expected: any, message?: string): void; 1318 | notStrictEqual(actual: any, expected: any, message?: string): void; 1319 | throws( 1320 | block: Function, 1321 | error?: Function | RegExp | (err: any) => boolean, 1322 | message?: string 1323 | ): void; 1324 | doesNotThrow(block: Function, message?: string): void; 1325 | ifError(value: any): void; 1326 | } 1327 | } 1328 | 1329 | /* globals: https://nodejs.org/api/globals.html */ 1330 | 1331 | declare class Process extends events$EventEmitter { 1332 | abort() : void; 1333 | arch : string; 1334 | argv : Array; 1335 | chdir(directory : string) : void; 1336 | config : Object; 1337 | connected : boolean; 1338 | cwd() : string; 1339 | disconnect? : () => void; 1340 | env : { [key: string] : ?string }; 1341 | execArgv : Array; 1342 | execPath : string; 1343 | exit(code? : number) : void; 1344 | getegid? : () => number; 1345 | geteuid? : () => number; 1346 | getgid? : () => number; 1347 | getgroups? : () => Array; 1348 | getuid? : () => number; 1349 | hrtime() : [ number, number ]; 1350 | initgroups? : (user : number | string, extra_group : number | string) => void; 1351 | kill(pid : number, signal? : string | number) : void; 1352 | mainModule : Object; 1353 | memoryUsage() : { 1354 | rss : number; 1355 | heapTotal : number; 1356 | heapUsed : number; 1357 | }; 1358 | nextTick(cb : Function) : void; 1359 | pid : number; 1360 | platform : string; 1361 | release : { 1362 | name : string; 1363 | lts? : string; 1364 | sourceUrl : string; 1365 | headersUrl : string; 1366 | libUrl : string; 1367 | }; 1368 | send? : (message : any, 1369 | sendHandleOrCallback? : net$Socket | net$Server | Function, 1370 | callback? : Function) => void; 1371 | setegid? : (id : number | string) => void; 1372 | seteuid? : (id : number | string) => void; 1373 | setgid? : (id : number | string) => void; 1374 | setgroups? : (groups : Array) => void; 1375 | setuid? : (id : number | string) => void; 1376 | stderr : stream$Writable | tty$WriteStream; 1377 | stdin : stream$Readable | tty$ReadStream; 1378 | stdout : stream$Writable | tty$WriteStream; 1379 | title : string; 1380 | umask(mask : number) : number; 1381 | uptime() : number; 1382 | version : string; 1383 | versions : { [key: string] : ?string }; 1384 | } 1385 | declare var process: Process; 1386 | 1387 | declare var __filename: string; 1388 | declare var __dirname: string; 1389 | 1390 | declare function setImmediate(callback: ((...args: Array) => mixed), ...args: Array): Object; 1391 | declare function clearImmediate(immediateObject: any): Object; 1392 | -------------------------------------------------------------------------------- /js/flowlib/react.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2013-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the "flow" directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | * 9 | */ 10 | /* React */ 11 | 12 | /** 13 | * Base class of ES6 React classes, modeled as a polymorphic class whose type 14 | * parameters are DefaultProps, Props, State. 15 | */ 16 | declare class React$Component { 17 | // fields 18 | 19 | static defaultProps: $Abstract; 20 | props: Props; 21 | state: $Abstract; 22 | 23 | // action methods 24 | 25 | // TODO: partialState could be a function as well 26 | setState(partialState: $Shape, callback?: () => void): void; 27 | 28 | forceUpdate(callback?: () => void): void; 29 | 30 | // lifecycle methods 31 | 32 | render(): ?React$Element; 33 | componentWillMount(): void; 34 | componentDidMount(component?: any): void; 35 | componentWillReceiveProps(nextProps: Props, nextContext?: any): void; 36 | shouldComponentUpdate(nextProps: Props, nextState: State, nextContext: any): boolean; 37 | componentWillUpdate(nextProps: Props, nextState: State, nextContext: any): void; 38 | componentDidUpdate(nextProps: Props, nextState: State, nextContext: any, component: any): void; 39 | componentWillUnmount(): void; 40 | 41 | // long tail of other stuff not modeled very well 42 | 43 | refs: any; 44 | context: any; 45 | getChildContext(): any; 46 | static displayName: string; 47 | static childContextTypes: any; 48 | static contextTypes: any; 49 | static propTypes: $Subtype<{[_: $Keys]: any}>; //object whose keys are in PropTypes 50 | } 51 | 52 | /** 53 | * Base class of legacy React classes, which extends the base class of ES6 React 54 | * classes and supports additional methods. 55 | */ 56 | declare class LegacyReactComponent extends React$Component { 57 | // additional methods 58 | 59 | getDefaultProps(): DefaultProps; 60 | getInitialState(): State; 61 | 62 | replaceState(state: State, callback?: () => void): void; 63 | 64 | isMounted(): bool; 65 | 66 | // TODO: Due to bugs in Flow's handling of React.createClass, some fields 67 | // already declared in the base class need to be redeclared below. Ideally 68 | // they should simply be inherited. 69 | 70 | static defaultProps: DefaultProps; 71 | props: Props; 72 | state: State; 73 | 74 | static propTypes: $Subtype<{[_: $Keys]: any}>; //object whose keys are in PropTypes 75 | static contextTypes: any; 76 | static childContextTypes: any; 77 | static displayName: string; 78 | } 79 | 80 | /** 81 | * Type of a React class (not to be confused with the type of instances of a 82 | * React class, which is the React class itself). A React class is any subclass 83 | * of React$Component. We make the type of a React class parametric over Config, 84 | * which is derived from some of the type parameters (DefaultProps, Props) of 85 | * React$Component, abstracting away others (State); whereas a React$Component 86 | * type is useful for checking the definition of a React class, a ReactClass 87 | * type (and the corresponding React$Element type, see below) is useful for 88 | * checking the uses of a React class. The required constraints are set up using 89 | * a "helper" type alias, that takes an additional type parameter C representing 90 | * the React class, which is then abstracted with an existential type (*). The * 91 | * can be thought of as an "auto" instruction to the typechecker, telling it to 92 | * fill in the type from context. 93 | */ 94 | type ReactClass = _ReactClass<*, *, Config, *>; 95 | type _ReactClass, C: React$Component> = Class; 96 | 97 | // TODO: DefaultProps and Props are needed to type some introspection APIs 98 | // below, but in general, Config does not carry enough information to recover 99 | // them faithfully. For now, we trade off that additional precision for overall 100 | // simplicity of the model. In the future, we may provide more powerful 101 | // introspection features in types, at which point Config would carry enough 102 | // information to faithfully recover DefaultProps and Props. 103 | type $PropsOf = any 104 | type $DefaultPropsOf = any 105 | 106 | /** 107 | * Type of a React element. React elements are commonly created using JSX 108 | * literals, which desugar to React.createElement calls (see below). The type 109 | * parameterization of React$Element mimics that of ReactClass (see above). 110 | */ 111 | declare class React$Element { 112 | type: ReactClass; 113 | props: $PropsOf; 114 | key: ?string; 115 | ref: any; 116 | } 117 | 118 | type ReactPropsCheckType = ( 119 | props: any, 120 | propName: string, 121 | componentName: string, 122 | href?: string) => ?Error; 123 | 124 | type ReactPropsChainableTypeChecker = { 125 | isRequired: ReactPropsCheckType; 126 | (props: any, propName: string, componentName: string, href?: string): ?Error; 127 | }; 128 | 129 | type ReactPropTypes = { 130 | array: ReactPropsChainableTypeChecker; 131 | bool: ReactPropsChainableTypeChecker; 132 | func: ReactPropsChainableTypeChecker; 133 | number: ReactPropsChainableTypeChecker; 134 | object: ReactPropsChainableTypeChecker; 135 | string: ReactPropsChainableTypeChecker; 136 | 137 | any: ReactPropsChainableTypeChecker; 138 | arrayOf: (typeChecker: ReactPropsCheckType) => ReactPropsChainableTypeChecker; 139 | element: ReactPropsChainableTypeChecker; 140 | instanceOf: (expectedClass: any) => ReactPropsChainableTypeChecker; 141 | node: ReactPropsChainableTypeChecker; 142 | objectOf: (typeChecker: ReactPropsCheckType) => ReactPropsChainableTypeChecker; 143 | oneOf: (expectedValues: Array) => ReactPropsChainableTypeChecker; 144 | oneOfType: (arrayOfTypeCheckers: Array) => ReactPropsChainableTypeChecker; 145 | shape: (shapeTypes: { [key: string]: ReactPropsCheckType }) => ReactPropsChainableTypeChecker; 146 | } 147 | 148 | declare module react { 149 | declare var Children: any; 150 | declare var DOM: any; 151 | declare var PropTypes: ReactPropTypes; 152 | declare var version: string; 153 | 154 | declare function initializeTouchEvents(shouldUseTouch: boolean): void; 155 | 156 | // compiler magic 157 | declare function createClass(spec: any): ReactClass; 158 | 159 | declare function cloneElement ( 160 | element: React$Element, 161 | attributes: $Shape, 162 | children?: any 163 | ): React$Element; 164 | 165 | /** 166 | * Methods that take an `config` argument of type Config, describing objects 167 | * whose properties must cover (at least) the difference between the 168 | * properties in Props and the properties in DefaultProps. This is intended 169 | * to model what happens at run time: the config are merged with the default 170 | * props to obtain the props of a React$Element / React$Component instance. 171 | */ 172 | declare var createElement: React$CreateElement 173 | 174 | // TODO: React DOM elements 175 | declare function createFactory( 176 | name: ReactClass 177 | ): (config: Config, children?: any) => React$Element; 178 | 179 | // TODO: React DOM elements 180 | declare function constructAndRenderComponent( 181 | name: ReactClass, 182 | config: Config, 183 | container: any 184 | ): React$Component<$DefaultPropsOf, $PropsOf, any>; 185 | 186 | // TODO: React DOM elements 187 | declare function constructAndRenderComponentByID( 188 | name: ReactClass, 189 | config: Config, 190 | id: string 191 | ): React$Component<$DefaultPropsOf, $PropsOf, any>; 192 | 193 | declare function findDOMNode( 194 | object: React$Component | HTMLElement 195 | ): any; 196 | 197 | declare function render( 198 | element: React$Element, 199 | container: any 200 | ): React$Component<$DefaultPropsOf, $PropsOf, any>; 201 | 202 | declare function renderToString( 203 | element: React$Element 204 | ): string; 205 | declare function renderToStaticMarkup( 206 | element: React$Element 207 | ): string; 208 | 209 | declare function unmountComponentAtNode(container: any): boolean; 210 | 211 | declare function isValidElement(element: any): boolean; 212 | declare function withContext(context: any, callback: () => void): any; 213 | 214 | declare var Component: typeof React$Component; 215 | declare var Element: typeof React$Element; 216 | } 217 | 218 | // TODO Delete this once https://github.com/facebook/react/pull/3031 lands 219 | // and "react" becomes the standard name for this module 220 | declare module React { 221 | declare var exports: $Exports<'react'>; 222 | } 223 | 224 | // TODO: Delete the corresponding method defs from the 'react' module once React 225 | // 0.15 comes out and removes them. 226 | declare module 'react-dom' { 227 | declare function findDOMNode( 228 | object: React$Component | HTMLElement 229 | ): any; 230 | 231 | declare function render( 232 | element: React$Element, 233 | container: any 234 | ): React$Component<$DefaultPropsOf, $PropsOf, any>; 235 | 236 | declare function unmountComponentAtNode(container: any): boolean; 237 | declare var version: string; 238 | 239 | declare function unstable_batchedUpdates( 240 | callback: (a: A, b: B, c: C, d: D, e: E) => mixed, 241 | a: A, 242 | b: B, 243 | c: C, 244 | d: D, 245 | e: E 246 | ): void; 247 | declare function unstable_renderSubtreeIntoContainer( 248 | parentComponent: React$Component, 249 | nextElement: React$Element, 250 | container: any, 251 | callback?: () => void 252 | ): React$Component<$DefaultPropsOf, $PropsOf, any>; 253 | } 254 | 255 | // TODO: Delete the corresponding method defs from the 'react' module once React 256 | // 0.15 comes out and removes them. 257 | declare module 'react-dom/server' { 258 | declare function renderToString( 259 | element: React$Element 260 | ): string; 261 | declare function renderToStaticMarkup( 262 | element: React$Element 263 | ): string; 264 | } 265 | 266 | declare class SyntheticEvent { 267 | bubbles: boolean; 268 | cancelable: boolean; 269 | currentTarget: EventTarget; 270 | defaultPrevented: boolean; 271 | eventPhase: number; 272 | isDefaultPrevented(): boolean; 273 | isPropagationStopped(): boolean; 274 | isTrusted: boolean; 275 | nativeEvent: Event; 276 | preventDefault(): void; 277 | stopPropagation(): void; 278 | target: EventTarget; 279 | timeStamp: number; 280 | type: string; 281 | persist(): void; 282 | } 283 | 284 | declare class SyntheticClipboardEvent extends SyntheticEvent { 285 | clipboardData: any; 286 | } 287 | 288 | declare class SyntheticCompositionEvent extends SyntheticEvent { 289 | data: any; 290 | } 291 | 292 | declare class SyntheticInputEvent extends SyntheticEvent { 293 | data: any; 294 | } 295 | 296 | declare class SyntheticUIEvent extends SyntheticEvent { 297 | detail: number; 298 | view: any; 299 | } 300 | 301 | declare class SyntheticFocusEvent extends SyntheticUIEvent { 302 | relatedTarget: EventTarget; 303 | } 304 | 305 | declare class SyntheticKeyboardEvent extends SyntheticUIEvent { 306 | altKey: boolean; 307 | charCode: number; 308 | ctrlKey: boolean; 309 | getModifierState: any; 310 | key: string; 311 | keyCode: number; 312 | locale: string; 313 | location: number; 314 | metaKey: boolean; 315 | repeat: boolean; 316 | shiftKey: boolean; 317 | which: number; 318 | } 319 | 320 | declare class SyntheticMouseEvent extends SyntheticUIEvent { 321 | altKey: boolean; 322 | button: number; 323 | buttons: number; 324 | clientX: number; 325 | clientY: number; 326 | ctrlKey: boolean; 327 | getModifierState: any; 328 | metaKey: boolean; 329 | pageX: number; 330 | pageY: number; 331 | relatedTarget: EventTarget; 332 | screenX: number; 333 | screenY: number; 334 | shiftKey: boolean; 335 | } 336 | 337 | declare class SyntheticDragEvent extends SyntheticMouseEvent { 338 | dataTransfer: any; 339 | } 340 | 341 | declare class SyntheticWheelEvent extends SyntheticMouseEvent { 342 | deltaMode: number; 343 | deltaX: number; 344 | deltaY: number; 345 | deltaZ: number; 346 | } 347 | 348 | declare class SyntheticTouchEvent extends SyntheticUIEvent { 349 | altKey: boolean; 350 | changedTouches: any; 351 | ctrlKey: boolean; 352 | getModifierState: any; 353 | metaKey: boolean; 354 | shiftKey: boolean; 355 | targetTouches: any; 356 | touches: any; 357 | } 358 | 359 | type $JSXIntrinsics = {[k:string]: ReactClass} 360 | -------------------------------------------------------------------------------- /js/worker.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | importScripts('flow.js'); 3 | postMessage({ flowVersion: flow.flowVersion }); 4 | 5 | function get(url) { 6 | return new Promise(function (resolve, reject) { 7 | var req = new XMLHttpRequest(); 8 | req.open('GET', url); 9 | req.onload = function () { 10 | if (req.status == 200) { 11 | resolve([url, req.response]); 12 | } else { 13 | reject(Error(req.statusText)); 14 | } 15 | }; 16 | req.onerror = function () { 17 | reject(Error("Network Error")); 18 | }; 19 | req.send(); 20 | }); 21 | } 22 | 23 | var libs = [ 24 | '/js/flowlib/core.js', 25 | '/js/flowlib/bom.js', 26 | '/js/flowlib/cssom.js', 27 | '/js/flowlib/dom.js', 28 | '/js/flowlib/node.js', 29 | '/js/flowlib/react.js' 30 | ]; 31 | 32 | Promise.all(libs.map(get)).then(function (contents) { 33 | contents.forEach(function (nameAndContent) { 34 | flow.registerFile(nameAndContent[0], nameAndContent[1]); 35 | }); 36 | return libs; 37 | }).then(function (libs) { 38 | flow.setLibs(libs); 39 | postMessage({ 40 | flowReady: true, 41 | }) 42 | }).catch(function(e) { 43 | console.log('Can\'t load libs', JSON.stringify(e[2])) 44 | }); 45 | 46 | function transformErrors(errors) { 47 | return errors.reduce(function(errors, error) { 48 | 49 | var description = error.message.length >= 5 ? 50 | error.message.slice(2, 5).map(function(e) { return e.descr}).join('\n') : 51 | error.message.map(function(e) { 52 | return e.path && e.path !== '/example.js' ? e.descr + ': ' + e.path + ':' + e.line + '\n' + e.context: e.descr; 53 | }).join('\n') 54 | 55 | var messages = error.message.map(function(message) { 56 | return { 57 | row: message.line - 1, 58 | column: message.start - 1, 59 | columnEnd: message.end - 1, 60 | text: description, 61 | type: 'error' 62 | } 63 | }); 64 | return errors.concat(messages) 65 | }, []); 66 | } 67 | 68 | onmessage = function(e) { 69 | if (e.data.inferTypeAt) { 70 | try { 71 | var line = parseInt(e.data.inferTypeAt.row, 10) + 1; 72 | var column = parseInt(e.data.inferTypeAt.column, 10) + 1; 73 | var res = flow.typeAtPos( 74 | '/example.js', 75 | e.data.text, 76 | line, 77 | column); 78 | postMessage({ 79 | inferredType: res[1].c 80 | }); 81 | } catch (e) { 82 | // can't infer 83 | postMessage({ 84 | inferredType: ' ' 85 | }); 86 | return null 87 | } 88 | } 89 | if (e.data.flowCheck) { 90 | try { 91 | var results = flow.checkContent('/example.js', e.data.text) 92 | var annotations = transformErrors(results) 93 | postMessage({ 94 | flowResults: annotations, 95 | flowCheck: true, 96 | }); 97 | } catch (e) { 98 | // don't care 99 | console.log(JSON.stringify(e)) 100 | return null 101 | } 102 | 103 | } 104 | 105 | } 106 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tryflow", 3 | "version": "2.0.0", 4 | "description": "Try Flow online", 5 | "main": "js/flow.js", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "scripts": { 10 | "start": "python -m SimpleHTTPServer", 11 | "copy": "cp ../flow/bin/flow* ./js" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/unknownexception/tryflow.git" 16 | }, 17 | "keywords": [ 18 | "flowtype" 19 | ], 20 | "author": "Dmitriy Loktev", 21 | "license": "MIT", 22 | "bugs": { 23 | "url": "https://github.com/unknownexception/tryflow/issues" 24 | }, 25 | "homepage": "https://tryflow.org", 26 | "dependencies": { 27 | }, 28 | "devDependencies": { 29 | }, 30 | "engines": { 31 | "node": "4.x.x", 32 | "npm": "3.x.x" 33 | } 34 | } 35 | --------------------------------------------------------------------------------