choi

fix dependencies

Showing 152 changed files with 26477 additions and 3 deletions
1 +#### 9.0.0
2 +* 27/05/2019
3 +* For compatibility with legacy browsers, remove `Symbol` references.
4 +
5 +#### 8.1.1
6 +* 24/02/2019
7 +* [BUGFIX] #222 Restore missing `var` to `export BigNumber`.
8 +* Allow any key in BigNumber.Instance in *bignumber.d.ts*.
9 +
10 +#### 8.1.0
11 +* 23/02/2019
12 +* [NEW FEATURE] #220 Create a BigNumber using `{s, e, c}`.
13 +* [NEW FEATURE] `isBigNumber`: if `BigNumber.DEBUG` is `true`, also check that the BigNumber instance is well-formed.
14 +* Remove `instanceof` checks; just use `_isBigNumber` to identify a BigNumber instance.
15 +* Add `_isBigNumber` to prototype in *bignumber.mjs*.
16 +* Add tests for BigNumber creation from object.
17 +* Update *API.html*.
18 +
19 +#### 8.0.2
20 +* 13/01/2019
21 +* #209 `toPrecision` without argument should follow `toString`.
22 +* Improve *Use* section of *README*.
23 +* Optimise `toString(10)`.
24 +* Add verson number to API doc.
25 +
26 +#### 8.0.1
27 +* 01/11/2018
28 +* Rest parameter must be array type in *bignumber.d.ts*.
29 +
30 +#### 8.0.0
31 +* 01/11/2018
32 +* [NEW FEATURE] Add `BigNumber.sum` method.
33 +* [NEW FEATURE]`toFormat`: add `prefix` and `suffix` options.
34 +* [NEW FEATURE] #178 Pass custom formatting to `toFormat`.
35 +* [BREAKING CHANGE] #184 `toFraction`: return array of BigNumbers not strings.
36 +* [NEW FEATURE] #185 Enable overwrite of `valueOf` to prevent accidental addition to string.
37 +* #183 Add Node.js `crypto` requirement to documentation.
38 +* [BREAKING CHANGE] #198 Disallow signs and whitespace in custom alphabet.
39 +* [NEW FEATURE] #188 Implement `util.inspect.custom` for Node.js REPL.
40 +* #170 Make `isBigNumber` a type guard in *bignumber.d.ts*.
41 +* [BREAKING CHANGE] `BigNumber.min` and `BigNumber.max`: don't accept an array.
42 +* Update *.travis.yml*.
43 +* Remove *bower.json*.
44 +
45 +#### 7.2.1
46 +* 24/05/2018
47 +* Add `browser` field to *package.json*.
48 +
49 +#### 7.2.0
50 +* 22/05/2018
51 +* #166 Correct *.mjs* file. Remove extension from `main` field in *package.json*.
52 +
53 +#### 7.1.0
54 +* 18/05/2018
55 +* Add `module` field to *package.json* for *bignumber.mjs*.
56 +
57 +#### 7.0.2
58 +* 17/05/2018
59 +* #165 Bugfix: upper-case letters for bases 11-36 in a custom alphabet.
60 +* Add note to *README* regarding creating BigNumbers from Number values.
61 +
62 +#### 7.0.1
63 +* 26/04/2018
64 +* #158 Fix global object variable name typo.
65 +
66 +#### 7.0.0
67 +* 26/04/2018
68 +* #143 Remove global BigNumber from typings.
69 +* #144 Enable compatibility with `Object.freeze(Object.prototype)`.
70 +* #148 #123 #11 Only throw on a number primitive with more than 15 significant digits if `BigNumber.DEBUG` is `true`.
71 +* Only throw on an invalid BigNumber value if `BigNumber.DEBUG` is `true`. Return BigNumber `NaN` instead.
72 +* #154 `exponentiatedBy`: allow BigNumber exponent.
73 +* #156 Prevent Content Security Policy *unsafe-eval* issue.
74 +* `toFraction`: allow `Infinity` maximum denominator.
75 +* Comment-out some excess tests to reduce test time.
76 +* Amend indentation and other spacing.
77 +
78 +#### 6.0.0
79 +* 26/01/2018
80 +* #137 Implement `APLHABET` configuration option.
81 +* Remove `ERRORS` configuration option.
82 +* Remove `toDigits` method; extend `precision` method accordingly.
83 +* Remove s`round` method; extend `decimalPlaces` method accordingly.
84 +* Remove methods: `ceil`, `floor`, and `truncated`.
85 +* Remove method aliases: `add`, `cmp`, `isInt`, `isNeg`, `trunc`, `mul`, `neg` and `sub`.
86 +* Rename methods: `shift` to `shiftedBy`, `another` to `clone`, `toPower` to `exponentiatedBy`, and `equals` to `isEqualTo`.
87 +* Rename methods: add `is` prefix to `greaterThan`, `greaterThanOrEqualTo`, `lessThan` and `lessThanOrEqualTo`.
88 +* Add methods: `multipliedBy`, `isBigNumber`, `isPositive`, `integerValue`, `maximum` and `minimum`.
89 +* Refactor test suite.
90 +* Add *CHANGELOG.md*.
91 +* Rewrite *bignumber.d.ts*.
92 +* Redo API image.
93 +
94 +#### 5.0.0
95 +* 27/11/2017
96 +* #81 Don't throw on constructor call without `new`.
97 +
98 +#### 4.1.0
99 +* 26/09/2017
100 +* Remove node 0.6 from *.travis.yml*.
101 +* Add *bignumber.mjs*.
102 +
103 +#### 4.0.4
104 +* 03/09/2017
105 +* Add missing aliases to *bignumber.d.ts*.
106 +
107 +#### 4.0.3
108 +* 30/08/2017
109 +* Add types: *bignumber.d.ts*.
110 +
111 +#### 4.0.2
112 +* 03/05/2017
113 +* #120 Workaround Safari/Webkit bug.
114 +
115 +#### 4.0.1
116 +* 05/04/2017
117 +* #121 BigNumber.default to BigNumber['default'].
118 +
119 +#### 4.0.0
120 +* 09/01/2017
121 +* Replace BigNumber.isBigNumber method with isBigNumber prototype property.
122 +
123 +#### 3.1.2
124 +* 08/01/2017
125 +* Minor documentation edit.
126 +
127 +#### 3.1.1
128 +* 08/01/2017
129 +* Uncomment `isBigNumber` tests.
130 +* Ignore dot files.
131 +
132 +#### 3.1.0
133 +* 08/01/2017
134 +* Add `isBigNumber` method.
135 +
136 +#### 3.0.2
137 +* 08/01/2017
138 +* Bugfix: Possible incorrect value of `ERRORS` after a `BigNumber.another` call (due to `parseNumeric` declaration in outer scope).
139 +
140 +#### 3.0.1
141 +* 23/11/2016
142 +* Apply fix for old ipads with `%` issue, see #57 and #102.
143 +* Correct error message.
144 +
145 +#### 3.0.0
146 +* 09/11/2016
147 +* Remove `require('crypto')` - leave it to the user.
148 +* Add `BigNumber.set` as `BigNumber.config` alias.
149 +* Default `POW_PRECISION` to `0`.
150 +
151 +#### 2.4.0
152 +* 14/07/2016
153 +* #97 Add exports to support ES6 imports.
154 +
155 +#### 2.3.0
156 +* 07/03/2016
157 +* #86 Add modulus parameter to `toPower`.
158 +
159 +#### 2.2.0
160 +* 03/03/2016
161 +* #91 Permit larger JS integers.
162 +
163 +#### 2.1.4
164 +* 15/12/2015
165 +* Correct UMD.
166 +
167 +#### 2.1.3
168 +* 13/12/2015
169 +* Refactor re global object and crypto availability when bundling.
170 +
171 +#### 2.1.2
172 +* 10/12/2015
173 +* Bugfix: `window.crypto` not assigned to `crypto`.
174 +
175 +#### 2.1.1
176 +* 09/12/2015
177 +* Prevent code bundler from adding `crypto` shim.
178 +
179 +#### 2.1.0
180 +* 26/10/2015
181 +* For `valueOf` and `toJSON`, include the minus sign with negative zero.
182 +
183 +#### 2.0.8
184 +* 2/10/2015
185 +* Internal round function bugfix.
186 +
187 +#### 2.0.6
188 +* 31/03/2015
189 +* Add bower.json. Tweak division after in-depth review.
190 +
191 +#### 2.0.5
192 +* 25/03/2015
193 +* Amend README. Remove bitcoin address.
194 +
195 +#### 2.0.4
196 +* 25/03/2015
197 +* Critical bugfix #58: division.
198 +
199 +#### 2.0.3
200 +* 18/02/2015
201 +* Amend README. Add source map.
202 +
203 +#### 2.0.2
204 +* 18/02/2015
205 +* Correct links.
206 +
207 +#### 2.0.1
208 +* 18/02/2015
209 +* Add `max`, `min`, `precision`, `random`, `shiftedBy`, `toDigits` and `truncated` methods.
210 +* Add the short-forms: `add`, `mul`, `sd`, `sub` and `trunc`.
211 +* Add an `another` method to enable multiple independent constructors to be created.
212 +* Add support for the base 2, 8 and 16 prefixes `0b`, `0o` and `0x`.
213 +* Enable a rounding mode to be specified as a second parameter to `toExponential`, `toFixed`, `toFormat` and `toPrecision`.
214 +* Add a `CRYPTO` configuration property so cryptographically-secure pseudo-random number generation can be specified.
215 +* Add a `MODULO_MODE` configuration property to enable the rounding mode used by the `modulo` operation to be specified.
216 +* Add a `POW_PRECISION` configuration property to enable the number of significant digits calculated by the power operation to be limited.
217 +* Improve code quality.
218 +* Improve documentation.
219 +
220 +#### 2.0.0
221 +* 29/12/2014
222 +* Add `dividedToIntegerBy`, `isInteger` and `toFormat` methods.
223 +* Remove the following short-forms: `isF`, `isZ`, `toE`, `toF`, `toFr`, `toN`, `toP`, `toS`.
224 +* Store a BigNumber's coefficient in base 1e14, rather than base 10.
225 +* Add fast path for integers to BigNumber constructor.
226 +* Incorporate the library into the online documentation.
227 +
228 +#### 1.5.0
229 +* 13/11/2014
230 +* Add `toJSON` and `decimalPlaces` methods.
231 +
232 +#### 1.4.1
233 +* 08/06/2014
234 +* Amend README.
235 +
236 +#### 1.4.0
237 +* 08/05/2014
238 +* Add `toNumber`.
239 +
240 +#### 1.3.0
241 +* 08/11/2013
242 +* Ensure correct rounding of `sqrt` in all, rather than almost all, cases.
243 +* Maximum radix to 64.
244 +
245 +#### 1.2.1
246 +* 17/10/2013
247 +* Sign of zero when x < 0 and x + (-x) = 0.
248 +
249 +#### 1.2.0
250 +* 19/9/2013
251 +* Throw Error objects for stack.
252 +
253 +#### 1.1.1
254 +* 22/8/2013
255 +* Show original value in constructor error message.
256 +
257 +#### 1.1.0
258 +* 1/8/2013
259 +* Allow numbers with trailing radix point.
260 +
261 +#### 1.0.1
262 +* Bugfix: error messages with incorrect method name
263 +
264 +#### 1.0.0
265 +* 8/11/2012
266 +* Initial release
1 +The MIT Licence.
2 +
3 +Copyright (c) 2019 Michael Mclaughlin
4 +
5 +Permission is hereby granted, free of charge, to any person obtaining
6 +a copy of this software and associated documentation files (the
7 +'Software'), to deal in the Software without restriction, including
8 +without limitation the rights to use, copy, modify, merge, publish,
9 +distribute, sublicense, and/or sell copies of the Software, and to
10 +permit persons to whom the Software is furnished to do so, subject to
11 +the following conditions:
12 +
13 +The above copyright notice and this permission notice shall be
14 +included in all copies or substantial portions of the Software.
15 +
16 +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17 +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 +
1 +![bignumber.js](https://raw.githubusercontent.com/MikeMcl/bignumber.js/gh-pages/bignumberjs.png)
2 +
3 +A JavaScript library for arbitrary-precision decimal and non-decimal arithmetic.
4 +
5 +[![Build Status](https://travis-ci.org/MikeMcl/bignumber.js.svg)](https://travis-ci.org/MikeMcl/bignumber.js)
6 +
7 +<br />
8 +
9 +## Features
10 +
11 + - Integers and decimals
12 + - Simple API but full-featured
13 + - Faster, smaller, and perhaps easier to use than JavaScript versions of Java's BigDecimal
14 + - 8 KB minified and gzipped
15 + - Replicates the `toExponential`, `toFixed`, `toPrecision` and `toString` methods of JavaScript's Number type
16 + - Includes a `toFraction` and a correctly-rounded `squareRoot` method
17 + - Supports cryptographically-secure pseudo-random number generation
18 + - No dependencies
19 + - Wide platform compatibility: uses JavaScript 1.5 (ECMAScript 3) features only
20 + - Comprehensive [documentation](http://mikemcl.github.io/bignumber.js/) and test set
21 +
22 +![API](https://raw.githubusercontent.com/MikeMcl/bignumber.js/gh-pages/API.png)
23 +
24 +If a smaller and simpler library is required see [big.js](https://github.com/MikeMcl/big.js/).
25 +It's less than half the size but only works with decimal numbers and only has half the methods.
26 +It also does not allow `NaN` or `Infinity`, or have the configuration options of this library.
27 +
28 +See also [decimal.js](https://github.com/MikeMcl/decimal.js/), which among other things adds support for non-integer powers, and performs all operations to a specified number of significant digits.
29 +
30 +## Load
31 +
32 +The library is the single JavaScript file *bignumber.js* (or minified, *bignumber.min.js*).
33 +
34 +Browser:
35 +
36 +```html
37 +<script src='path/to/bignumber.js'></script>
38 +```
39 +
40 +[Node.js](http://nodejs.org):
41 +
42 +```bash
43 +$ npm install bignumber.js
44 +```
45 +
46 +```javascript
47 +const BigNumber = require('bignumber.js');
48 +```
49 +
50 +ES6 module:
51 +
52 +```javascript
53 +import BigNumber from "./bignumber.mjs"
54 +```
55 +
56 +AMD loader libraries such as [requireJS](http://requirejs.org/):
57 +
58 +```javascript
59 +require(['bignumber'], function(BigNumber) {
60 + // Use BigNumber here in local scope. No global BigNumber.
61 +});
62 +```
63 +
64 +## Use
65 +
66 +The library exports a single constructor function, [`BigNumber`](http://mikemcl.github.io/bignumber.js/#bignumber), which accepts a value of type Number, String or BigNumber,
67 +
68 +```javascript
69 +let x = new BigNumber(123.4567);
70 +let y = BigNumber('123456.7e-3');
71 +let z = new BigNumber(x);
72 +x.isEqualTo(y) && y.isEqualTo(z) && x.isEqualTo(z); // true
73 +```
74 +
75 +To get the string value of a BigNumber use [`toString()`](http://mikemcl.github.io/bignumber.js/#toS) or [`toFixed()`](http://mikemcl.github.io/bignumber.js/#toFix). Using `toFixed()` prevents exponential notation being returned, no matter how large or small the value.
76 +
77 +```javascript
78 +let x = new BigNumber('1111222233334444555566');
79 +x.toString(); // "1.111222233334444555566e+21"
80 +x.toFixed(); // "1111222233334444555566"
81 +```
82 +
83 +If the limited precision of Number values is not well understood, it is recommended to create BigNumbers from String values rather than Number values to avoid a potential loss of precision.
84 +
85 +*In all further examples below, `let`, semicolons and `toString` calls are not shown. If a commented-out value is in quotes it means `toString` has been called on the preceding expression.*
86 +
87 +```javascript
88 +// Precision loss from using numeric literals with more than 15 significant digits.
89 +new BigNumber(1.0000000000000001) // '1'
90 +new BigNumber(88259496234518.57) // '88259496234518.56'
91 +new BigNumber(99999999999999999999) // '100000000000000000000'
92 +
93 +// Precision loss from using numeric literals outside the range of Number values.
94 +new BigNumber(2e+308) // 'Infinity'
95 +new BigNumber(1e-324) // '0'
96 +
97 +// Precision loss from the unexpected result of arithmetic with Number values.
98 +new BigNumber(0.7 + 0.1) // '0.7999999999999999'
99 +```
100 +
101 +When creating a BigNumber from a Number, note that a BigNumber is created from a Number's decimal `toString()` value not from its underlying binary value. If the latter is required, then pass the Number's `toString(2)` value and specify base 2.
102 +
103 +```javascript
104 +new BigNumber(Number.MAX_VALUE.toString(2), 2)
105 +```
106 +
107 +BigNumbers can be created from values in bases from 2 to 36. See [`ALPHABET`](http://mikemcl.github.io/bignumber.js/#alphabet) to extend this range.
108 +
109 +```javascript
110 +a = new BigNumber(1011, 2) // "11"
111 +b = new BigNumber('zz.9', 36) // "1295.25"
112 +c = a.plus(b) // "1306.25"
113 +```
114 +
115 +Performance is better if base 10 is NOT specified for decimal values. Only specify base 10 when it is desired that the number of decimal places of the input value be limited to the current [`DECIMAL_PLACES`](http://mikemcl.github.io/bignumber.js/#decimal-places) setting.
116 +
117 +A BigNumber is immutable in the sense that it is not changed by its methods.
118 +
119 +```javascript
120 +0.3 - 0.1 // 0.19999999999999998
121 +x = new BigNumber(0.3)
122 +x.minus(0.1) // "0.2"
123 +x // "0.3"
124 +```
125 +
126 +The methods that return a BigNumber can be chained.
127 +
128 +```javascript
129 +x.dividedBy(y).plus(z).times(9)
130 +x.times('1.23456780123456789e+9').plus(9876.5432321).dividedBy('4444562598.111772').integerValue()
131 +```
132 +
133 +Some of the longer method names have a shorter alias.
134 +
135 +```javascript
136 +x.squareRoot().dividedBy(y).exponentiatedBy(3).isEqualTo(x.sqrt().div(y).pow(3)) // true
137 +x.modulo(y).multipliedBy(z).eq(x.mod(y).times(z)) // true
138 +```
139 +
140 +As with JavaScript's Number type, there are [`toExponential`](http://mikemcl.github.io/bignumber.js/#toE), [`toFixed`](http://mikemcl.github.io/bignumber.js/#toFix) and [`toPrecision`](http://mikemcl.github.io/bignumber.js/#toP) methods.
141 +
142 +```javascript
143 +x = new BigNumber(255.5)
144 +x.toExponential(5) // "2.55500e+2"
145 +x.toFixed(5) // "255.50000"
146 +x.toPrecision(5) // "255.50"
147 +x.toNumber() // 255.5
148 +```
149 +
150 + A base can be specified for [`toString`](http://mikemcl.github.io/bignumber.js/#toS). Performance is better if base 10 is NOT specified, i.e. use `toString()` not `toString(10)`. Only specify base 10 when it is desired that the number of decimal places be limited to the current [`DECIMAL_PLACES`](http://mikemcl.github.io/bignumber.js/#decimal-places) setting.
151 +
152 + ```javascript
153 + x.toString(16) // "ff.8"
154 + ```
155 +
156 +There is a [`toFormat`](http://mikemcl.github.io/bignumber.js/#toFor) method which may be useful for internationalisation.
157 +
158 +```javascript
159 +y = new BigNumber('1234567.898765')
160 +y.toFormat(2) // "1,234,567.90"
161 +```
162 +
163 +The maximum number of decimal places of the result of an operation involving division (i.e. a division, square root, base conversion or negative power operation) is set using the `set` or `config` method of the `BigNumber` constructor.
164 +
165 +The other arithmetic operations always give the exact result.
166 +
167 +```javascript
168 +BigNumber.set({ DECIMAL_PLACES: 10, ROUNDING_MODE: 4 })
169 +
170 +x = new BigNumber(2)
171 +y = new BigNumber(3)
172 +z = x.dividedBy(y) // "0.6666666667"
173 +z.squareRoot() // "0.8164965809"
174 +z.exponentiatedBy(-3) // "3.3749999995"
175 +z.toString(2) // "0.1010101011"
176 +z.multipliedBy(z) // "0.44444444448888888889"
177 +z.multipliedBy(z).decimalPlaces(10) // "0.4444444445"
178 +```
179 +
180 +There is a [`toFraction`](http://mikemcl.github.io/bignumber.js/#toFr) method with an optional *maximum denominator* argument
181 +
182 +```javascript
183 +y = new BigNumber(355)
184 +pi = y.dividedBy(113) // "3.1415929204"
185 +pi.toFraction() // [ "7853982301", "2500000000" ]
186 +pi.toFraction(1000) // [ "355", "113" ]
187 +```
188 +
189 +and [`isNaN`](http://mikemcl.github.io/bignumber.js/#isNaN) and [`isFinite`](http://mikemcl.github.io/bignumber.js/#isF) methods, as `NaN` and `Infinity` are valid `BigNumber` values.
190 +
191 +```javascript
192 +x = new BigNumber(NaN) // "NaN"
193 +y = new BigNumber(Infinity) // "Infinity"
194 +x.isNaN() && !y.isNaN() && !x.isFinite() && !y.isFinite() // true
195 +```
196 +
197 +The value of a BigNumber is stored in a decimal floating point format in terms of a coefficient, exponent and sign.
198 +
199 +```javascript
200 +x = new BigNumber(-123.456);
201 +x.c // [ 123, 45600000000000 ] coefficient (i.e. significand)
202 +x.e // 2 exponent
203 +x.s // -1 sign
204 +```
205 +
206 +For advanced usage, multiple BigNumber constructors can be created, each with their own independent configuration.
207 +
208 +```javascript
209 +// Set DECIMAL_PLACES for the original BigNumber constructor
210 +BigNumber.set({ DECIMAL_PLACES: 10 })
211 +
212 +// Create another BigNumber constructor, optionally passing in a configuration object
213 +BN = BigNumber.clone({ DECIMAL_PLACES: 5 })
214 +
215 +x = new BigNumber(1)
216 +y = new BN(1)
217 +
218 +x.div(3) // '0.3333333333'
219 +y.div(3) // '0.33333'
220 +```
221 +
222 +For further information see the [API](http://mikemcl.github.io/bignumber.js/) reference in the *doc* directory.
223 +
224 +## Test
225 +
226 +The *test/modules* directory contains the test scripts for each method.
227 +
228 +The tests can be run with Node.js or a browser. For Node.js use
229 +
230 + $ npm test
231 +
232 +or
233 +
234 + $ node test/test
235 +
236 +To test a single method, use, for example
237 +
238 + $ node test/methods/toFraction
239 +
240 +For the browser, open *test/test.html*.
241 +
242 +## Build
243 +
244 +For Node, if [uglify-js](https://github.com/mishoo/UglifyJS2) is installed
245 +
246 + npm install uglify-js -g
247 +
248 +then
249 +
250 + npm run build
251 +
252 +will create *bignumber.min.js*.
253 +
254 +A source map will also be created in the root directory.
255 +
256 +## Feedback
257 +
258 +Open an issue, or email
259 +
260 +Michael
261 +
262 +<a href="mailto:M8ch88l@gmail.com">M8ch88l@gmail.com</a>
263 +
264 +## Licence
265 +
266 +The MIT Licence.
267 +
268 +See [LICENCE](https://github.com/MikeMcl/bignumber.js/blob/master/LICENCE).
1 +// Type definitions for bignumber.js >=8.1.0
2 +// Project: https://github.com/MikeMcl/bignumber.js
3 +// Definitions by: Michael Mclaughlin <https://github.com/MikeMcl>
4 +// Definitions: https://github.com/MikeMcl/bignumber.js
5 +
6 +// Documentation: http://mikemcl.github.io/bignumber.js/
7 +//
8 +// Exports:
9 +//
10 +// class BigNumber (default export)
11 +// type BigNumber.Constructor
12 +// type BigNumber.ModuloMode
13 +// type BigNumber.RoundingMOde
14 +// type BigNumber.Value
15 +// interface BigNumber.Config
16 +// interface BigNumber.Format
17 +// interface BigNumber.Instance
18 +//
19 +// Example:
20 +//
21 +// import {BigNumber} from "bignumber.js"
22 +// //import BigNumber from "bignumber.js"
23 +//
24 +// let rm: BigNumber.RoundingMode = BigNumber.ROUND_UP;
25 +// let f: BigNumber.Format = { decimalSeparator: ',' };
26 +// let c: BigNumber.Config = { DECIMAL_PLACES: 4, ROUNDING_MODE: rm, FORMAT: f };
27 +// BigNumber.config(c);
28 +//
29 +// let v: BigNumber.Value = '12345.6789';
30 +// let b: BigNumber = new BigNumber(v);
31 +//
32 +// The use of compiler option `--strictNullChecks` is recommended.
33 +
34 +export default BigNumber;
35 +
36 +export namespace BigNumber {
37 +
38 + /** See `BigNumber.config` (alias `BigNumber.set`) and `BigNumber.clone`. */
39 + interface Config {
40 +
41 + /**
42 + * An integer, 0 to 1e+9. Default value: 20.
43 + *
44 + * The maximum number of decimal places of the result of operations involving division, i.e.
45 + * division, square root and base conversion operations, and exponentiation when the exponent is
46 + * negative.
47 + *
48 + * ```ts
49 + * BigNumber.config({ DECIMAL_PLACES: 5 })
50 + * BigNumber.set({ DECIMAL_PLACES: 5 })
51 + * ```
52 + */
53 + DECIMAL_PLACES?: number;
54 +
55 + /**
56 + * An integer, 0 to 8. Default value: `BigNumber.ROUND_HALF_UP` (4).
57 + *
58 + * The rounding mode used in operations that involve division (see `DECIMAL_PLACES`) and the
59 + * default rounding mode of the `decimalPlaces`, `precision`, `toExponential`, `toFixed`,
60 + * `toFormat` and `toPrecision` methods.
61 + *
62 + * The modes are available as enumerated properties of the BigNumber constructor.
63 + *
64 + * ```ts
65 + * BigNumber.config({ ROUNDING_MODE: 0 })
66 + * BigNumber.set({ ROUNDING_MODE: BigNumber.ROUND_UP })
67 + * ```
68 + */
69 + ROUNDING_MODE?: BigNumber.RoundingMode;
70 +
71 + /**
72 + * An integer, 0 to 1e+9, or an array, [-1e+9 to 0, 0 to 1e+9].
73 + * Default value: `[-7, 20]`.
74 + *
75 + * The exponent value(s) at which `toString` returns exponential notation.
76 + *
77 + * If a single number is assigned, the value is the exponent magnitude.
78 + *
79 + * If an array of two numbers is assigned then the first number is the negative exponent value at
80 + * and beneath which exponential notation is used, and the second number is the positive exponent
81 + * value at and above which exponential notation is used.
82 + *
83 + * For example, to emulate JavaScript numbers in terms of the exponent values at which they begin
84 + * to use exponential notation, use `[-7, 20]`.
85 + *
86 + * ```ts
87 + * BigNumber.config({ EXPONENTIAL_AT: 2 })
88 + * new BigNumber(12.3) // '12.3' e is only 1
89 + * new BigNumber(123) // '1.23e+2'
90 + * new BigNumber(0.123) // '0.123' e is only -1
91 + * new BigNumber(0.0123) // '1.23e-2'
92 + *
93 + * BigNumber.config({ EXPONENTIAL_AT: [-7, 20] })
94 + * new BigNumber(123456789) // '123456789' e is only 8
95 + * new BigNumber(0.000000123) // '1.23e-7'
96 + *
97 + * // Almost never return exponential notation:
98 + * BigNumber.config({ EXPONENTIAL_AT: 1e+9 })
99 + *
100 + * // Always return exponential notation:
101 + * BigNumber.config({ EXPONENTIAL_AT: 0 })
102 + * ```
103 + *
104 + * Regardless of the value of `EXPONENTIAL_AT`, the `toFixed` method will always return a value in
105 + * normal notation and the `toExponential` method will always return a value in exponential form.
106 + * Calling `toString` with a base argument, e.g. `toString(10)`, will also always return normal
107 + * notation.
108 + */
109 + EXPONENTIAL_AT?: number | [number, number];
110 +
111 + /**
112 + * An integer, magnitude 1 to 1e+9, or an array, [-1e+9 to -1, 1 to 1e+9].
113 + * Default value: `[-1e+9, 1e+9]`.
114 + *
115 + * The exponent value(s) beyond which overflow to Infinity and underflow to zero occurs.
116 + *
117 + * If a single number is assigned, it is the maximum exponent magnitude: values wth a positive
118 + * exponent of greater magnitude become Infinity and those with a negative exponent of greater
119 + * magnitude become zero.
120 + *
121 + * If an array of two numbers is assigned then the first number is the negative exponent limit and
122 + * the second number is the positive exponent limit.
123 + *
124 + * For example, to emulate JavaScript numbers in terms of the exponent values at which they
125 + * become zero and Infinity, use [-324, 308].
126 + *
127 + * ```ts
128 + * BigNumber.config({ RANGE: 500 })
129 + * BigNumber.config().RANGE // [ -500, 500 ]
130 + * new BigNumber('9.999e499') // '9.999e+499'
131 + * new BigNumber('1e500') // 'Infinity'
132 + * new BigNumber('1e-499') // '1e-499'
133 + * new BigNumber('1e-500') // '0'
134 + *
135 + * BigNumber.config({ RANGE: [-3, 4] })
136 + * new BigNumber(99999) // '99999' e is only 4
137 + * new BigNumber(100000) // 'Infinity' e is 5
138 + * new BigNumber(0.001) // '0.01' e is only -3
139 + * new BigNumber(0.0001) // '0' e is -4
140 + * ```
141 + * The largest possible magnitude of a finite BigNumber is 9.999...e+1000000000.
142 + * The smallest possible magnitude of a non-zero BigNumber is 1e-1000000000.
143 + */
144 + RANGE?: number | [number, number];
145 +
146 + /**
147 + * A boolean: `true` or `false`. Default value: `false`.
148 + *
149 + * The value that determines whether cryptographically-secure pseudo-random number generation is
150 + * used. If `CRYPTO` is set to true then the random method will generate random digits using
151 + * `crypto.getRandomValues` in browsers that support it, or `crypto.randomBytes` if using a
152 + * version of Node.js that supports it.
153 + *
154 + * If neither function is supported by the host environment then attempting to set `CRYPTO` to
155 + * `true` will fail and an exception will be thrown.
156 + *
157 + * If `CRYPTO` is `false` then the source of randomness used will be `Math.random` (which is
158 + * assumed to generate at least 30 bits of randomness).
159 + *
160 + * See `BigNumber.random`.
161 + *
162 + * ```ts
163 + * // Node.js
164 + * global.crypto = require('crypto')
165 + *
166 + * BigNumber.config({ CRYPTO: true })
167 + * BigNumber.config().CRYPTO // true
168 + * BigNumber.random() // 0.54340758610486147524
169 + * ```
170 + */
171 + CRYPTO?: boolean;
172 +
173 + /**
174 + * An integer, 0, 1, 3, 6 or 9. Default value: `BigNumber.ROUND_DOWN` (1).
175 + *
176 + * The modulo mode used when calculating the modulus: `a mod n`.
177 + * The quotient, `q = a / n`, is calculated according to the `ROUNDING_MODE` that corresponds to
178 + * the chosen `MODULO_MODE`.
179 + * The remainder, `r`, is calculated as: `r = a - n * q`.
180 + *
181 + * The modes that are most commonly used for the modulus/remainder operation are shown in the
182 + * following table. Although the other rounding modes can be used, they may not give useful
183 + * results.
184 + *
185 + * Property | Value | Description
186 + * :------------------|:------|:------------------------------------------------------------------
187 + * `ROUND_UP` | 0 | The remainder is positive if the dividend is negative.
188 + * `ROUND_DOWN` | 1 | The remainder has the same sign as the dividend.
189 + * | | Uses 'truncating division' and matches JavaScript's `%` operator .
190 + * `ROUND_FLOOR` | 3 | The remainder has the same sign as the divisor.
191 + * | | This matches Python's `%` operator.
192 + * `ROUND_HALF_EVEN` | 6 | The IEEE 754 remainder function.
193 + * `EUCLID` | 9 | The remainder is always positive.
194 + * | | Euclidian division: `q = sign(n) * floor(a / abs(n))`
195 + *
196 + * The rounding/modulo modes are available as enumerated properties of the BigNumber constructor.
197 + *
198 + * See `modulo`.
199 + *
200 + * ```ts
201 + * BigNumber.config({ MODULO_MODE: BigNumber.EUCLID })
202 + * BigNumber.set({ MODULO_MODE: 9 }) // equivalent
203 + * ```
204 + */
205 + MODULO_MODE?: BigNumber.ModuloMode;
206 +
207 + /**
208 + * An integer, 0 to 1e+9. Default value: 0.
209 + *
210 + * The maximum precision, i.e. number of significant digits, of the result of the power operation
211 + * - unless a modulus is specified.
212 + *
213 + * If set to 0, the number of significant digits will not be limited.
214 + *
215 + * See `exponentiatedBy`.
216 + *
217 + * ```ts
218 + * BigNumber.config({ POW_PRECISION: 100 })
219 + * ```
220 + */
221 + POW_PRECISION?: number;
222 +
223 + /**
224 + * An object including any number of the properties shown below.
225 + *
226 + * The object configures the format of the string returned by the `toFormat` method.
227 + * The example below shows the properties of the object that are recognised, and
228 + * their default values.
229 + *
230 + * Unlike the other configuration properties, the values of the properties of the `FORMAT` object
231 + * will not be checked for validity - the existing object will simply be replaced by the object
232 + * that is passed in.
233 + *
234 + * See `toFormat`.
235 + *
236 + * ```ts
237 + * BigNumber.config({
238 + * FORMAT: {
239 + * // string to prepend
240 + * prefix: '',
241 + * // the decimal separator
242 + * decimalSeparator: '.',
243 + * // the grouping separator of the integer part
244 + * groupSeparator: ',',
245 + * // the primary grouping size of the integer part
246 + * groupSize: 3,
247 + * // the secondary grouping size of the integer part
248 + * secondaryGroupSize: 0,
249 + * // the grouping separator of the fraction part
250 + * fractionGroupSeparator: ' ',
251 + * // the grouping size of the fraction part
252 + * fractionGroupSize: 0,
253 + * // string to append
254 + * suffix: ''
255 + * }
256 + * })
257 + * ```
258 + */
259 + FORMAT?: BigNumber.Format;
260 +
261 + /**
262 + * The alphabet used for base conversion. The length of the alphabet corresponds to the maximum
263 + * value of the base argument that can be passed to the BigNumber constructor or `toString`.
264 + *
265 + * Default value: `'0123456789abcdefghijklmnopqrstuvwxyz'`.
266 + *
267 + * There is no maximum length for the alphabet, but it must be at least 2 characters long,
268 + * and it must not contain whitespace or a repeated character, or the sign indicators '+' and
269 + * '-', or the decimal separator '.'.
270 + *
271 + * ```ts
272 + * // duodecimal (base 12)
273 + * BigNumber.config({ ALPHABET: '0123456789TE' })
274 + * x = new BigNumber('T', 12)
275 + * x.toString() // '10'
276 + * x.toString(12) // 'T'
277 + * ```
278 + */
279 + ALPHABET?: string;
280 + }
281 +
282 + /** See `FORMAT` and `toFormat`. */
283 + interface Format {
284 +
285 + /** The string to prepend. */
286 + prefix?: string;
287 +
288 + /** The decimal separator. */
289 + decimalSeparator?: string;
290 +
291 + /** The grouping separator of the integer part. */
292 + groupSeparator?: string;
293 +
294 + /** The primary grouping size of the integer part. */
295 + groupSize?: number;
296 +
297 + /** The secondary grouping size of the integer part. */
298 + secondaryGroupSize?: number;
299 +
300 + /** The grouping separator of the fraction part. */
301 + fractionGroupSeparator?: string;
302 +
303 + /** The grouping size of the fraction part. */
304 + fractionGroupSize?: number;
305 +
306 + /** The string to append. */
307 + suffix?: string;
308 + }
309 +
310 + interface Instance {
311 +
312 + /** The coefficient of the value of this BigNumber, an array of base 1e14 integer numbers, or null. */
313 + readonly c: number[] | null;
314 +
315 + /** The exponent of the value of this BigNumber, an integer number, -1000000000 to 1000000000, or null. */
316 + readonly e: number | null;
317 +
318 + /** The sign of the value of this BigNumber, -1, 1, or null. */
319 + readonly s: number | null;
320 +
321 + [key: string]: any;
322 + }
323 +
324 + type Constructor = typeof BigNumber;
325 + type ModuloMode = 0 | 1 | 3 | 6 | 9;
326 + type RoundingMode = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
327 + type Value = string | number | Instance;
328 +}
329 +
330 +export declare class BigNumber implements BigNumber.Instance {
331 +
332 + /** Used internally to identify a BigNumber instance. */
333 + private readonly _isBigNumber: true;
334 +
335 + /** The coefficient of the value of this BigNumber, an array of base 1e14 integer numbers, or null. */
336 + readonly c: number[] | null;
337 +
338 + /** The exponent of the value of this BigNumber, an integer number, -1000000000 to 1000000000, or null. */
339 + readonly e: number | null;
340 +
341 + /** The sign of the value of this BigNumber, -1, 1, or null. */
342 + readonly s: number | null;
343 +
344 + /**
345 + * Returns a new instance of a BigNumber object with value `n`, where `n` is a numeric value in
346 + * the specified `base`, or base 10 if `base` is omitted or is `null` or `undefined`.
347 + *
348 + * ```ts
349 + * x = new BigNumber(123.4567) // '123.4567'
350 + * // 'new' is optional
351 + * y = BigNumber(x) // '123.4567'
352 + * ```
353 + *
354 + * If `n` is a base 10 value it can be in normal (fixed-point) or exponential notation.
355 + * Values in other bases must be in normal notation. Values in any base can have fraction digits,
356 + * i.e. digits after the decimal point.
357 + *
358 + * ```ts
359 + * new BigNumber(43210) // '43210'
360 + * new BigNumber('4.321e+4') // '43210'
361 + * new BigNumber('-735.0918e-430') // '-7.350918e-428'
362 + * new BigNumber('123412421.234324', 5) // '607236.557696'
363 + * ```
364 + *
365 + * Signed `0`, signed `Infinity` and `NaN` are supported.
366 + *
367 + * ```ts
368 + * new BigNumber('-Infinity') // '-Infinity'
369 + * new BigNumber(NaN) // 'NaN'
370 + * new BigNumber(-0) // '0'
371 + * new BigNumber('.5') // '0.5'
372 + * new BigNumber('+2') // '2'
373 + * ```
374 + *
375 + * String values in hexadecimal literal form, e.g. `'0xff'`, are valid, as are string values with
376 + * the octal and binary prefixs `'0o'` and `'0b'`. String values in octal literal form without the
377 + * prefix will be interpreted as decimals, e.g. `'011'` is interpreted as 11, not 9.
378 + *
379 + * ```ts
380 + * new BigNumber(-10110100.1, 2) // '-180.5'
381 + * new BigNumber('-0b10110100.1') // '-180.5'
382 + * new BigNumber('ff.8', 16) // '255.5'
383 + * new BigNumber('0xff.8') // '255.5'
384 + * ```
385 + *
386 + * If a base is specified, `n` is rounded according to the current `DECIMAL_PLACES` and
387 + * `ROUNDING_MODE` settings. This includes base 10, so don't include a `base` parameter for decimal
388 + * values unless this behaviour is desired.
389 + *
390 + * ```ts
391 + * BigNumber.config({ DECIMAL_PLACES: 5 })
392 + * new BigNumber(1.23456789) // '1.23456789'
393 + * new BigNumber(1.23456789, 10) // '1.23457'
394 + * ```
395 + *
396 + * An error is thrown if `base` is invalid.
397 + *
398 + * There is no limit to the number of digits of a value of type string (other than that of
399 + * JavaScript's maximum array size). See `RANGE` to set the maximum and minimum possible exponent
400 + * value of a BigNumber.
401 + *
402 + * ```ts
403 + * new BigNumber('5032485723458348569331745.33434346346912144534543')
404 + * new BigNumber('4.321e10000000')
405 + * ```
406 + *
407 + * BigNumber `NaN` is returned if `n` is invalid (unless `BigNumber.DEBUG` is `true`, see below).
408 + *
409 + * ```ts
410 + * new BigNumber('.1*') // 'NaN'
411 + * new BigNumber('blurgh') // 'NaN'
412 + * new BigNumber(9, 2) // 'NaN'
413 + * ```
414 + *
415 + * To aid in debugging, if `BigNumber.DEBUG` is `true` then an error will be thrown on an
416 + * invalid `n`. An error will also be thrown if `n` is of type number with more than 15
417 + * significant digits, as calling `toString` or `valueOf` on these numbers may not result in the
418 + * intended value.
419 + *
420 + * ```ts
421 + * console.log(823456789123456.3) // 823456789123456.2
422 + * new BigNumber(823456789123456.3) // '823456789123456.2'
423 + * BigNumber.DEBUG = true
424 + * // 'Error: Number has more than 15 significant digits'
425 + * new BigNumber(823456789123456.3)
426 + * // 'Error: Not a base 2 number'
427 + * new BigNumber(9, 2)
428 + * ```
429 + *
430 + * A BigNumber can also be created from an object literal.
431 + * Use `isBigNumber` to check that it is well-formed.
432 + *
433 + * ```ts
434 + * new BigNumber({ s: 1, e: 2, c: [ 777, 12300000000000 ], _isBigNumber: true }) // '777.123'
435 + * ```
436 + *
437 + * @param n A numeric value.
438 + * @param base The base of `n`, integer, 2 to 36 (or `ALPHABET.length`, see `ALPHABET`).
439 + */
440 + constructor(n: BigNumber.Value, base?: number);
441 +
442 + /**
443 + * Returns a BigNumber whose value is the absolute value, i.e. the magnitude, of the value of this
444 + * BigNumber.
445 + *
446 + * The return value is always exact and unrounded.
447 + *
448 + * ```ts
449 + * x = new BigNumber(-0.8)
450 + * x.absoluteValue() // '0.8'
451 + * ```
452 + */
453 + absoluteValue(): BigNumber;
454 +
455 + /**
456 + * Returns a BigNumber whose value is the absolute value, i.e. the magnitude, of the value of this
457 + * BigNumber.
458 + *
459 + * The return value is always exact and unrounded.
460 + *
461 + * ```ts
462 + * x = new BigNumber(-0.8)
463 + * x.abs() // '0.8'
464 + * ```
465 + */
466 + abs(): BigNumber;
467 +
468 + /**
469 + * Returns | |
470 + * :-------:|:--------------------------------------------------------------|
471 + * 1 | If the value of this BigNumber is greater than the value of `n`
472 + * -1 | If the value of this BigNumber is less than the value of `n`
473 + * 0 | If this BigNumber and `n` have the same value
474 + * `null` | If the value of either this BigNumber or `n` is `NaN`
475 + *
476 + * ```ts
477 + *
478 + * x = new BigNumber(Infinity)
479 + * y = new BigNumber(5)
480 + * x.comparedTo(y) // 1
481 + * x.comparedTo(x.minus(1)) // 0
482 + * y.comparedTo(NaN) // null
483 + * y.comparedTo('110', 2) // -1
484 + * ```
485 + * @param n A numeric value.
486 + * @param [base] The base of n.
487 + */
488 + comparedTo(n: BigNumber.Value, base?: number): number;
489 +
490 + /**
491 + * Returns a BigNumber whose value is the value of this BigNumber rounded by rounding mode
492 + * `roundingMode` to a maximum of `decimalPlaces` decimal places.
493 + *
494 + * If `decimalPlaces` is omitted, or is `null` or `undefined`, the return value is the number of
495 + * decimal places of the value of this BigNumber, or `null` if the value of this BigNumber is
496 + * ±`Infinity` or `NaN`.
497 + *
498 + * If `roundingMode` is omitted, or is `null` or `undefined`, `ROUNDING_MODE` is used.
499 + *
500 + * Throws if `decimalPlaces` or `roundingMode` is invalid.
501 + *
502 + * ```ts
503 + * x = new BigNumber(1234.56)
504 + * x.decimalPlaces() // 2
505 + * x.decimalPlaces(1) // '1234.6'
506 + * x.decimalPlaces(2) // '1234.56'
507 + * x.decimalPlaces(10) // '1234.56'
508 + * x.decimalPlaces(0, 1) // '1234'
509 + * x.decimalPlaces(0, 6) // '1235'
510 + * x.decimalPlaces(1, 1) // '1234.5'
511 + * x.decimalPlaces(1, BigNumber.ROUND_HALF_EVEN) // '1234.6'
512 + * x // '1234.56'
513 + * y = new BigNumber('9.9e-101')
514 + * y.decimalPlaces() // 102
515 + * ```
516 + *
517 + * @param [decimalPlaces] Decimal places, integer, 0 to 1e+9.
518 + * @param [roundingMode] Rounding mode, integer, 0 to 8.
519 + */
520 + decimalPlaces(): number;
521 + decimalPlaces(decimalPlaces: number, roundingMode?: BigNumber.RoundingMode): BigNumber;
522 +
523 + /**
524 + * Returns a BigNumber whose value is the value of this BigNumber rounded by rounding mode
525 + * `roundingMode` to a maximum of `decimalPlaces` decimal places.
526 + *
527 + * If `decimalPlaces` is omitted, or is `null` or `undefined`, the return value is the number of
528 + * decimal places of the value of this BigNumber, or `null` if the value of this BigNumber is
529 + * ±`Infinity` or `NaN`.
530 + *
531 + * If `roundingMode` is omitted, or is `null` or `undefined`, `ROUNDING_MODE` is used.
532 + *
533 + * Throws if `decimalPlaces` or `roundingMode` is invalid.
534 + *
535 + * ```ts
536 + * x = new BigNumber(1234.56)
537 + * x.dp() // 2
538 + * x.dp(1) // '1234.6'
539 + * x.dp(2) // '1234.56'
540 + * x.dp(10) // '1234.56'
541 + * x.dp(0, 1) // '1234'
542 + * x.dp(0, 6) // '1235'
543 + * x.dp(1, 1) // '1234.5'
544 + * x.dp(1, BigNumber.ROUND_HALF_EVEN) // '1234.6'
545 + * x // '1234.56'
546 + * y = new BigNumber('9.9e-101')
547 + * y.dp() // 102
548 + * ```
549 + *
550 + * @param [decimalPlaces] Decimal places, integer, 0 to 1e+9.
551 + * @param [roundingMode] Rounding mode, integer, 0 to 8.
552 + */
553 + dp(): number;
554 + dp(decimalPlaces: number, roundingMode?: BigNumber.RoundingMode): BigNumber;
555 +
556 + /**
557 + * Returns a BigNumber whose value is the value of this BigNumber divided by `n`, rounded
558 + * according to the current `DECIMAL_PLACES` and `ROUNDING_MODE` settings.
559 + *
560 + * ```ts
561 + * x = new BigNumber(355)
562 + * y = new BigNumber(113)
563 + * x.dividedBy(y) // '3.14159292035398230088'
564 + * x.dividedBy(5) // '71'
565 + * x.dividedBy(47, 16) // '5'
566 + * ```
567 + *
568 + * @param n A numeric value.
569 + * @param [base] The base of n.
570 + */
571 + dividedBy(n: BigNumber.Value, base?: number): BigNumber;
572 +
573 + /**
574 + * Returns a BigNumber whose value is the value of this BigNumber divided by `n`, rounded
575 + * according to the current `DECIMAL_PLACES` and `ROUNDING_MODE` settings.
576 + *
577 + * ```ts
578 + * x = new BigNumber(355)
579 + * y = new BigNumber(113)
580 + * x.div(y) // '3.14159292035398230088'
581 + * x.div(5) // '71'
582 + * x.div(47, 16) // '5'
583 + * ```
584 + *
585 + * @param n A numeric value.
586 + * @param [base] The base of n.
587 + */
588 + div(n: BigNumber.Value, base?: number): BigNumber;
589 +
590 + /**
591 + * Returns a BigNumber whose value is the integer part of dividing the value of this BigNumber by
592 + * `n`.
593 + *
594 + * ```ts
595 + * x = new BigNumber(5)
596 + * y = new BigNumber(3)
597 + * x.dividedToIntegerBy(y) // '1'
598 + * x.dividedToIntegerBy(0.7) // '7'
599 + * x.dividedToIntegerBy('0.f', 16) // '5'
600 + * ```
601 + *
602 + * @param n A numeric value.
603 + * @param [base] The base of n.
604 + */
605 + dividedToIntegerBy(n: BigNumber.Value, base?: number): BigNumber;
606 +
607 + /**
608 + * Returns a BigNumber whose value is the integer part of dividing the value of this BigNumber by
609 + * `n`.
610 + *
611 + * ```ts
612 + * x = new BigNumber(5)
613 + * y = new BigNumber(3)
614 + * x.idiv(y) // '1'
615 + * x.idiv(0.7) // '7'
616 + * x.idiv('0.f', 16) // '5'
617 + * ```
618 + *
619 + * @param n A numeric value.
620 + * @param [base] The base of n.
621 + */
622 + idiv(n: BigNumber.Value, base?: number): BigNumber;
623 +
624 + /**
625 + * Returns a BigNumber whose value is the value of this BigNumber exponentiated by `n`, i.e.
626 + * raised to the power `n`, and optionally modulo a modulus `m`.
627 + *
628 + * If `n` is negative the result is rounded according to the current `DECIMAL_PLACES` and
629 + * `ROUNDING_MODE` settings.
630 + *
631 + * As the number of digits of the result of the power operation can grow so large so quickly,
632 + * e.g. 123.456**10000 has over 50000 digits, the number of significant digits calculated is
633 + * limited to the value of the `POW_PRECISION` setting (unless a modulus `m` is specified).
634 + *
635 + * By default `POW_PRECISION` is set to 0. This means that an unlimited number of significant
636 + * digits will be calculated, and that the method's performance will decrease dramatically for
637 + * larger exponents.
638 + *
639 + * If `m` is specified and the value of `m`, `n` and this BigNumber are integers and `n` is
640 + * positive, then a fast modular exponentiation algorithm is used, otherwise the operation will
641 + * be performed as `x.exponentiatedBy(n).modulo(m)` with a `POW_PRECISION` of 0.
642 + *
643 + * Throws if `n` is not an integer.
644 + *
645 + * ```ts
646 + * Math.pow(0.7, 2) // 0.48999999999999994
647 + * x = new BigNumber(0.7)
648 + * x.exponentiatedBy(2) // '0.49'
649 + * BigNumber(3).exponentiatedBy(-2) // '0.11111111111111111111'
650 + * ```
651 + *
652 + * @param n The exponent, an integer.
653 + * @param [m] The modulus.
654 + */
655 + exponentiatedBy(n: BigNumber.Value, m?: BigNumber.Value): BigNumber;
656 + exponentiatedBy(n: number, m?: BigNumber.Value): BigNumber;
657 +
658 + /**
659 + * Returns a BigNumber whose value is the value of this BigNumber exponentiated by `n`, i.e.
660 + * raised to the power `n`, and optionally modulo a modulus `m`.
661 + *
662 + * If `n` is negative the result is rounded according to the current `DECIMAL_PLACES` and
663 + * `ROUNDING_MODE` settings.
664 + *
665 + * As the number of digits of the result of the power operation can grow so large so quickly,
666 + * e.g. 123.456**10000 has over 50000 digits, the number of significant digits calculated is
667 + * limited to the value of the `POW_PRECISION` setting (unless a modulus `m` is specified).
668 + *
669 + * By default `POW_PRECISION` is set to 0. This means that an unlimited number of significant
670 + * digits will be calculated, and that the method's performance will decrease dramatically for
671 + * larger exponents.
672 + *
673 + * If `m` is specified and the value of `m`, `n` and this BigNumber are integers and `n` is
674 + * positive, then a fast modular exponentiation algorithm is used, otherwise the operation will
675 + * be performed as `x.pow(n).modulo(m)` with a `POW_PRECISION` of 0.
676 + *
677 + * Throws if `n` is not an integer.
678 + *
679 + * ```ts
680 + * Math.pow(0.7, 2) // 0.48999999999999994
681 + * x = new BigNumber(0.7)
682 + * x.pow(2) // '0.49'
683 + * BigNumber(3).pow(-2) // '0.11111111111111111111'
684 + * ```
685 + *
686 + * @param n The exponent, an integer.
687 + * @param [m] The modulus.
688 + */
689 + pow(n: BigNumber.Value, m?: BigNumber.Value): BigNumber;
690 + pow(n: number, m?: BigNumber.Value): BigNumber;
691 +
692 + /**
693 + * Returns a BigNumber whose value is the value of this BigNumber rounded to an integer using
694 + * rounding mode `rm`.
695 + *
696 + * If `rm` is omitted, or is `null` or `undefined`, `ROUNDING_MODE` is used.
697 + *
698 + * Throws if `rm` is invalid.
699 + *
700 + * ```ts
701 + * x = new BigNumber(123.456)
702 + * x.integerValue() // '123'
703 + * x.integerValue(BigNumber.ROUND_CEIL) // '124'
704 + * y = new BigNumber(-12.7)
705 + * y.integerValue() // '-13'
706 + * x.integerValue(BigNumber.ROUND_DOWN) // '-12'
707 + * ```
708 + *
709 + * @param {BigNumber.RoundingMode} [rm] The roundng mode, an integer, 0 to 8.
710 + */
711 + integerValue(rm?: BigNumber.RoundingMode): BigNumber;
712 +
713 + /**
714 + * Returns `true` if the value of this BigNumber is equal to the value of `n`, otherwise returns
715 + * `false`.
716 + *
717 + * As with JavaScript, `NaN` does not equal `NaN`.
718 + *
719 + * ```ts
720 + * 0 === 1e-324 // true
721 + * x = new BigNumber(0)
722 + * x.isEqualTo('1e-324') // false
723 + * BigNumber(-0).isEqualTo(x) // true ( -0 === 0 )
724 + * BigNumber(255).isEqualTo('ff', 16) // true
725 + *
726 + * y = new BigNumber(NaN)
727 + * y.isEqualTo(NaN) // false
728 + * ```
729 + *
730 + * @param n A numeric value.
731 + * @param [base] The base of n.
732 + */
733 + isEqualTo(n: BigNumber.Value, base?: number): boolean;
734 +
735 + /**
736 + * Returns `true` if the value of this BigNumber is equal to the value of `n`, otherwise returns
737 + * `false`.
738 + *
739 + * As with JavaScript, `NaN` does not equal `NaN`.
740 + *
741 + * ```ts
742 + * 0 === 1e-324 // true
743 + * x = new BigNumber(0)
744 + * x.eq('1e-324') // false
745 + * BigNumber(-0).eq(x) // true ( -0 === 0 )
746 + * BigNumber(255).eq('ff', 16) // true
747 + *
748 + * y = new BigNumber(NaN)
749 + * y.eq(NaN) // false
750 + * ```
751 + *
752 + * @param n A numeric value.
753 + * @param [base] The base of n.
754 + */
755 + eq(n: BigNumber.Value, base?: number): boolean;
756 +
757 + /**
758 + * Returns `true` if the value of this BigNumber is a finite number, otherwise returns `false`.
759 + *
760 + * The only possible non-finite values of a BigNumber are `NaN`, `Infinity` and `-Infinity`.
761 + *
762 + * ```ts
763 + * x = new BigNumber(1)
764 + * x.isFinite() // true
765 + * y = new BigNumber(Infinity)
766 + * y.isFinite() // false
767 + * ```
768 + */
769 + isFinite(): boolean;
770 +
771 + /**
772 + * Returns `true` if the value of this BigNumber is greater than the value of `n`, otherwise
773 + * returns `false`.
774 + *
775 + * ```ts
776 + * 0.1 > (0.3 - 0.2) // true
777 + * x = new BigNumber(0.1)
778 + * x.isGreaterThan(BigNumber(0.3).minus(0.2)) // false
779 + * BigNumber(0).isGreaterThan(x) // false
780 + * BigNumber(11, 3).isGreaterThan(11.1, 2) // true
781 + * ```
782 + *
783 + * @param n A numeric value.
784 + * @param [base] The base of n.
785 + */
786 + isGreaterThan(n: BigNumber.Value, base?: number): boolean;
787 +
788 + /**
789 + * Returns `true` if the value of this BigNumber is greater than the value of `n`, otherwise
790 + * returns `false`.
791 + *
792 + * ```ts
793 + * 0.1 > (0.3 - 0 // true
794 + * x = new BigNumber(0.1)
795 + * x.gt(BigNumber(0.3).minus(0.2)) // false
796 + * BigNumber(0).gt(x) // false
797 + * BigNumber(11, 3).gt(11.1, 2) // true
798 + * ```
799 + *
800 + * @param n A numeric value.
801 + * @param [base] The base of n.
802 + */
803 + gt(n: BigNumber.Value, base?: number): boolean;
804 +
805 + /**
806 + * Returns `true` if the value of this BigNumber is greater than or equal to the value of `n`,
807 + * otherwise returns `false`.
808 + *
809 + * ```ts
810 + * (0.3 - 0.2) >= 0.1 // false
811 + * x = new BigNumber(0.3).minus(0.2)
812 + * x.isGreaterThanOrEqualTo(0.1) // true
813 + * BigNumber(1).isGreaterThanOrEqualTo(x) // true
814 + * BigNumber(10, 18).isGreaterThanOrEqualTo('i', 36) // true
815 + * ```
816 + *
817 + * @param n A numeric value.
818 + * @param [base] The base of n.
819 + */
820 + isGreaterThanOrEqualTo(n: BigNumber.Value, base?: number): boolean;
821 +
822 + /**
823 + * Returns `true` if the value of this BigNumber is greater than or equal to the value of `n`,
824 + * otherwise returns `false`.
825 + *
826 + * ```ts
827 + * (0.3 - 0.2) >= 0.1 // false
828 + * x = new BigNumber(0.3).minus(0.2)
829 + * x.gte(0.1) // true
830 + * BigNumber(1).gte(x) // true
831 + * BigNumber(10, 18).gte('i', 36) // true
832 + * ```
833 + *
834 + * @param n A numeric value.
835 + * @param [base] The base of n.
836 + */
837 + gte(n: BigNumber.Value, base?: number): boolean;
838 +
839 + /**
840 + * Returns `true` if the value of this BigNumber is an integer, otherwise returns `false`.
841 + *
842 + * ```ts
843 + * x = new BigNumber(1)
844 + * x.isInteger() // true
845 + * y = new BigNumber(123.456)
846 + * y.isInteger() // false
847 + * ```
848 + */
849 + isInteger(): boolean;
850 +
851 + /**
852 + * Returns `true` if the value of this BigNumber is less than the value of `n`, otherwise returns
853 + * `false`.
854 + *
855 + * ```ts
856 + * (0.3 - 0.2) < 0.1 // true
857 + * x = new BigNumber(0.3).minus(0.2)
858 + * x.isLessThan(0.1) // false
859 + * BigNumber(0).isLessThan(x) // true
860 + * BigNumber(11.1, 2).isLessThan(11, 3) // true
861 + * ```
862 + *
863 + * @param n A numeric value.
864 + * @param [base] The base of n.
865 + */
866 + isLessThan(n: BigNumber.Value, base?: number): boolean;
867 +
868 + /**
869 + * Returns `true` if the value of this BigNumber is less than the value of `n`, otherwise returns
870 + * `false`.
871 + *
872 + * ```ts
873 + * (0.3 - 0.2) < 0.1 // true
874 + * x = new BigNumber(0.3).minus(0.2)
875 + * x.lt(0.1) // false
876 + * BigNumber(0).lt(x) // true
877 + * BigNumber(11.1, 2).lt(11, 3) // true
878 + * ```
879 + *
880 + * @param n A numeric value.
881 + * @param [base] The base of n.
882 + */
883 + lt(n: BigNumber.Value, base?: number): boolean;
884 +
885 + /**
886 + * Returns `true` if the value of this BigNumber is less than or equal to the value of `n`,
887 + * otherwise returns `false`.
888 + *
889 + * ```ts
890 + * 0.1 <= (0.3 - 0.2) // false
891 + * x = new BigNumber(0.1)
892 + * x.isLessThanOrEqualTo(BigNumber(0.3).minus(0.2)) // true
893 + * BigNumber(-1).isLessThanOrEqualTo(x) // true
894 + * BigNumber(10, 18).isLessThanOrEqualTo('i', 36) // true
895 + * ```
896 + *
897 + * @param n A numeric value.
898 + * @param [base] The base of n.
899 + */
900 + isLessThanOrEqualTo(n: BigNumber.Value, base?: number): boolean;
901 +
902 + /**
903 + * Returns `true` if the value of this BigNumber is less than or equal to the value of `n`,
904 + * otherwise returns `false`.
905 + *
906 + * ```ts
907 + * 0.1 <= (0.3 - 0.2) // false
908 + * x = new BigNumber(0.1)
909 + * x.lte(BigNumber(0.3).minus(0.2)) // true
910 + * BigNumber(-1).lte(x) // true
911 + * BigNumber(10, 18).lte('i', 36) // true
912 + * ```
913 + *
914 + * @param n A numeric value.
915 + * @param [base] The base of n.
916 + */
917 + lte(n: BigNumber.Value, base?: number): boolean;
918 +
919 + /**
920 + * Returns `true` if the value of this BigNumber is `NaN`, otherwise returns `false`.
921 + *
922 + * ```ts
923 + * x = new BigNumber(NaN)
924 + * x.isNaN() // true
925 + * y = new BigNumber('Infinity')
926 + * y.isNaN() // false
927 + * ```
928 + */
929 + isNaN(): boolean;
930 +
931 + /**
932 + * Returns `true` if the value of this BigNumber is negative, otherwise returns `false`.
933 + *
934 + * ```ts
935 + * x = new BigNumber(-0)
936 + * x.isNegative() // true
937 + * y = new BigNumber(2)
938 + * y.isNegative() // false
939 + * ```
940 + */
941 + isNegative(): boolean;
942 +
943 + /**
944 + * Returns `true` if the value of this BigNumber is positive, otherwise returns `false`.
945 + *
946 + * ```ts
947 + * x = new BigNumber(-0)
948 + * x.isPositive() // false
949 + * y = new BigNumber(2)
950 + * y.isPositive() // true
951 + * ```
952 + */
953 + isPositive(): boolean;
954 +
955 + /**
956 + * Returns `true` if the value of this BigNumber is zero or minus zero, otherwise returns `false`.
957 + *
958 + * ```ts
959 + * x = new BigNumber(-0)
960 + * x.isZero() // true
961 + * ```
962 + */
963 + isZero(): boolean;
964 +
965 + /**
966 + * Returns a BigNumber whose value is the value of this BigNumber minus `n`.
967 + *
968 + * The return value is always exact and unrounded.
969 + *
970 + * ```ts
971 + * 0.3 - 0.1 // 0.19999999999999998
972 + * x = new BigNumber(0.3)
973 + * x.minus(0.1) // '0.2'
974 + * x.minus(0.6, 20) // '0'
975 + * ```
976 + *
977 + * @param n A numeric value.
978 + * @param [base] The base of n.
979 + */
980 + minus(n: BigNumber.Value, base?: number): BigNumber;
981 +
982 + /**
983 + * Returns a BigNumber whose value is the value of this BigNumber modulo `n`, i.e. the integer
984 + * remainder of dividing this BigNumber by `n`.
985 + *
986 + * The value returned, and in particular its sign, is dependent on the value of the `MODULO_MODE`
987 + * setting of this BigNumber constructor. If it is 1 (default value), the result will have the
988 + * same sign as this BigNumber, and it will match that of Javascript's `%` operator (within the
989 + * limits of double precision) and BigDecimal's `remainder` method.
990 + *
991 + * The return value is always exact and unrounded.
992 + *
993 + * See `MODULO_MODE` for a description of the other modulo modes.
994 + *
995 + * ```ts
996 + * 1 % 0.9 // 0.09999999999999998
997 + * x = new BigNumber(1)
998 + * x.modulo(0.9) // '0.1'
999 + * y = new BigNumber(33)
1000 + * y.modulo('a', 33) // '3'
1001 + * ```
1002 + *
1003 + * @param n A numeric value.
1004 + * @param [base] The base of n.
1005 + */
1006 + modulo(n: BigNumber.Value, base?: number): BigNumber;
1007 +
1008 + /**
1009 + * Returns a BigNumber whose value is the value of this BigNumber modulo `n`, i.e. the integer
1010 + * remainder of dividing this BigNumber by `n`.
1011 + *
1012 + * The value returned, and in particular its sign, is dependent on the value of the `MODULO_MODE`
1013 + * setting of this BigNumber constructor. If it is 1 (default value), the result will have the
1014 + * same sign as this BigNumber, and it will match that of Javascript's `%` operator (within the
1015 + * limits of double precision) and BigDecimal's `remainder` method.
1016 + *
1017 + * The return value is always exact and unrounded.
1018 + *
1019 + * See `MODULO_MODE` for a description of the other modulo modes.
1020 + *
1021 + * ```ts
1022 + * 1 % 0.9 // 0.09999999999999998
1023 + * x = new BigNumber(1)
1024 + * x.mod(0.9) // '0.1'
1025 + * y = new BigNumber(33)
1026 + * y.mod('a', 33) // '3'
1027 + * ```
1028 + *
1029 + * @param n A numeric value.
1030 + * @param [base] The base of n.
1031 + */
1032 + mod(n: BigNumber.Value, base?: number): BigNumber;
1033 +
1034 + /**
1035 + * Returns a BigNumber whose value is the value of this BigNumber multiplied by `n`.
1036 + *
1037 + * The return value is always exact and unrounded.
1038 + *
1039 + * ```ts
1040 + * 0.6 * 3 // 1.7999999999999998
1041 + * x = new BigNumber(0.6)
1042 + * y = x.multipliedBy(3) // '1.8'
1043 + * BigNumber('7e+500').multipliedBy(y) // '1.26e+501'
1044 + * x.multipliedBy('-a', 16) // '-6'
1045 + * ```
1046 + *
1047 + * @param n A numeric value.
1048 + * @param [base] The base of n.
1049 + */
1050 + multipliedBy(n: BigNumber.Value, base?: number): BigNumber;
1051 +
1052 + /**
1053 + * Returns a BigNumber whose value is the value of this BigNumber multiplied by `n`.
1054 + *
1055 + * The return value is always exact and unrounded.
1056 + *
1057 + * ```ts
1058 + * 0.6 * 3 // 1.7999999999999998
1059 + * x = new BigNumber(0.6)
1060 + * y = x.times(3) // '1.8'
1061 + * BigNumber('7e+500').times(y) // '1.26e+501'
1062 + * x.times('-a', 16) // '-6'
1063 + * ```
1064 + *
1065 + * @param n A numeric value.
1066 + * @param [base] The base of n.
1067 + */
1068 + times(n: BigNumber.Value, base?: number): BigNumber;
1069 +
1070 + /**
1071 + * Returns a BigNumber whose value is the value of this BigNumber negated, i.e. multiplied by -1.
1072 + *
1073 + * ```ts
1074 + * x = new BigNumber(1.8)
1075 + * x.negated() // '-1.8'
1076 + * y = new BigNumber(-1.3)
1077 + * y.negated() // '1.3'
1078 + * ```
1079 + */
1080 + negated(): BigNumber;
1081 +
1082 + /**
1083 + * Returns a BigNumber whose value is the value of this BigNumber plus `n`.
1084 + *
1085 + * The return value is always exact and unrounded.
1086 + *
1087 + * ```ts
1088 + * 0.1 + 0.2 // 0.30000000000000004
1089 + * x = new BigNumber(0.1)
1090 + * y = x.plus(0.2) // '0.3'
1091 + * BigNumber(0.7).plus(x).plus(y) // '1'
1092 + * x.plus('0.1', 8) // '0.225'
1093 + * ```
1094 + *
1095 + * @param n A numeric value.
1096 + * @param [base] The base of n.
1097 + */
1098 + plus(n: BigNumber.Value, base?: number): BigNumber;
1099 +
1100 + /**
1101 + * Returns the number of significant digits of the value of this BigNumber, or `null` if the value
1102 + * of this BigNumber is ±`Infinity` or `NaN`.
1103 + *
1104 + * If `includeZeros` is true then any trailing zeros of the integer part of the value of this
1105 + * BigNumber are counted as significant digits, otherwise they are not.
1106 + *
1107 + * Throws if `includeZeros` is invalid.
1108 + *
1109 + * ```ts
1110 + * x = new BigNumber(9876.54321)
1111 + * x.precision() // 9
1112 + * y = new BigNumber(987000)
1113 + * y.precision(false) // 3
1114 + * y.precision(true) // 6
1115 + * ```
1116 + *
1117 + * @param [includeZeros] Whether to include integer trailing zeros in the significant digit count.
1118 + */
1119 + precision(includeZeros?: boolean): number;
1120 +
1121 + /**
1122 + * Returns a BigNumber whose value is the value of this BigNumber rounded to a precision of
1123 + * `significantDigits` significant digits using rounding mode `roundingMode`.
1124 + *
1125 + * If `roundingMode` is omitted or is `null` or `undefined`, `ROUNDING_MODE` will be used.
1126 + *
1127 + * Throws if `significantDigits` or `roundingMode` is invalid.
1128 + *
1129 + * ```ts
1130 + * x = new BigNumber(9876.54321)
1131 + * x.precision(6) // '9876.54'
1132 + * x.precision(6, BigNumber.ROUND_UP) // '9876.55'
1133 + * x.precision(2) // '9900'
1134 + * x.precision(2, 1) // '9800'
1135 + * x // '9876.54321'
1136 + * ```
1137 + *
1138 + * @param significantDigits Significant digits, integer, 1 to 1e+9.
1139 + * @param [roundingMode] Rounding mode, integer, 0 to 8.
1140 + */
1141 + precision(significantDigits: number, roundingMode?: BigNumber.RoundingMode): BigNumber;
1142 +
1143 + /**
1144 + * Returns the number of significant digits of the value of this BigNumber,
1145 + * or `null` if the value of this BigNumber is ±`Infinity` or `NaN`.
1146 + *
1147 + * If `includeZeros` is true then any trailing zeros of the integer part of
1148 + * the value of this BigNumber are counted as significant digits, otherwise
1149 + * they are not.
1150 + *
1151 + * Throws if `includeZeros` is invalid.
1152 + *
1153 + * ```ts
1154 + * x = new BigNumber(9876.54321)
1155 + * x.sd() // 9
1156 + * y = new BigNumber(987000)
1157 + * y.sd(false) // 3
1158 + * y.sd(true) // 6
1159 + * ```
1160 + *
1161 + * @param [includeZeros] Whether to include integer trailing zeros in the significant digit count.
1162 + */
1163 + sd(includeZeros?: boolean): number;
1164 +
1165 + /**
1166 + * Returns a BigNumber whose value is the value of this BigNumber rounded to a precision of
1167 + * `significantDigits` significant digits using rounding mode `roundingMode`.
1168 + *
1169 + * If `roundingMode` is omitted or is `null` or `undefined`, `ROUNDING_MODE` will be used.
1170 + *
1171 + * Throws if `significantDigits` or `roundingMode` is invalid.
1172 + *
1173 + * ```ts
1174 + * x = new BigNumber(9876.54321)
1175 + * x.sd(6) // '9876.54'
1176 + * x.sd(6, BigNumber.ROUND_UP) // '9876.55'
1177 + * x.sd(2) // '9900'
1178 + * x.sd(2, 1) // '9800'
1179 + * x // '9876.54321'
1180 + * ```
1181 + *
1182 + * @param significantDigits Significant digits, integer, 1 to 1e+9.
1183 + * @param [roundingMode] Rounding mode, integer, 0 to 8.
1184 + */
1185 + sd(significantDigits: number, roundingMode?: BigNumber.RoundingMode): BigNumber;
1186 +
1187 + /**
1188 + * Returns a BigNumber whose value is the value of this BigNumber shifted by `n` places.
1189 + *
1190 + * The shift is of the decimal point, i.e. of powers of ten, and is to the left if `n` is negative
1191 + * or to the right if `n` is positive.
1192 + *
1193 + * The return value is always exact and unrounded.
1194 + *
1195 + * Throws if `n` is invalid.
1196 + *
1197 + * ```ts
1198 + * x = new BigNumber(1.23)
1199 + * x.shiftedBy(3) // '1230'
1200 + * x.shiftedBy(-3) // '0.00123'
1201 + * ```
1202 + *
1203 + * @param n The shift value, integer, -9007199254740991 to 9007199254740991.
1204 + */
1205 + shiftedBy(n: number): BigNumber;
1206 +
1207 + /**
1208 + * Returns a BigNumber whose value is the square root of the value of this BigNumber, rounded
1209 + * according to the current `DECIMAL_PLACES` and `ROUNDING_MODE` settings.
1210 + *
1211 + * The return value will be correctly rounded, i.e. rounded as if the result was first calculated
1212 + * to an infinite number of correct digits before rounding.
1213 + *
1214 + * ```ts
1215 + * x = new BigNumber(16)
1216 + * x.squareRoot() // '4'
1217 + * y = new BigNumber(3)
1218 + * y.squareRoot() // '1.73205080756887729353'
1219 + * ```
1220 + */
1221 + squareRoot(): BigNumber;
1222 +
1223 + /**
1224 + * Returns a BigNumber whose value is the square root of the value of this BigNumber, rounded
1225 + * according to the current `DECIMAL_PLACES` and `ROUNDING_MODE` settings.
1226 + *
1227 + * The return value will be correctly rounded, i.e. rounded as if the result was first calculated
1228 + * to an infinite number of correct digits before rounding.
1229 + *
1230 + * ```ts
1231 + * x = new BigNumber(16)
1232 + * x.sqrt() // '4'
1233 + * y = new BigNumber(3)
1234 + * y.sqrt() // '1.73205080756887729353'
1235 + * ```
1236 + */
1237 + sqrt(): BigNumber;
1238 +
1239 + /**
1240 + * Returns a string representing the value of this BigNumber in exponential notation rounded using
1241 + * rounding mode `roundingMode` to `decimalPlaces` decimal places, i.e with one digit before the
1242 + * decimal point and `decimalPlaces` digits after it.
1243 + *
1244 + * If the value of this BigNumber in exponential notation has fewer than `decimalPlaces` fraction
1245 + * digits, the return value will be appended with zeros accordingly.
1246 + *
1247 + * If `decimalPlaces` is omitted, or is `null` or `undefined`, the number of digits after the
1248 + * decimal point defaults to the minimum number of digits necessary to represent the value
1249 + * exactly.
1250 + *
1251 + * If `roundingMode` is omitted or is `null` or `undefined`, `ROUNDING_MODE` is used.
1252 + *
1253 + * Throws if `decimalPlaces` or `roundingMode` is invalid.
1254 + *
1255 + * ```ts
1256 + * x = 45.6
1257 + * y = new BigNumber(x)
1258 + * x.toExponential() // '4.56e+1'
1259 + * y.toExponential() // '4.56e+1'
1260 + * x.toExponential(0) // '5e+1'
1261 + * y.toExponential(0) // '5e+1'
1262 + * x.toExponential(1) // '4.6e+1'
1263 + * y.toExponential(1) // '4.6e+1'
1264 + * y.toExponential(1, 1) // '4.5e+1' (ROUND_DOWN)
1265 + * x.toExponential(3) // '4.560e+1'
1266 + * y.toExponential(3) // '4.560e+1'
1267 + * ```
1268 + *
1269 + * @param [decimalPlaces] Decimal places, integer, 0 to 1e+9.
1270 + * @param [roundingMode] Rounding mode, integer, 0 to 8.
1271 + */
1272 + toExponential(decimalPlaces: number, roundingMode?: BigNumber.RoundingMode): string;
1273 + toExponential(): string;
1274 +
1275 + /**
1276 + * Returns a string representing the value of this BigNumber in normal (fixed-point) notation
1277 + * rounded to `decimalPlaces` decimal places using rounding mode `roundingMode`.
1278 + *
1279 + * If the value of this BigNumber in normal notation has fewer than `decimalPlaces` fraction
1280 + * digits, the return value will be appended with zeros accordingly.
1281 + *
1282 + * Unlike `Number.prototype.toFixed`, which returns exponential notation if a number is greater or
1283 + * equal to 10**21, this method will always return normal notation.
1284 + *
1285 + * If `decimalPlaces` is omitted or is `null` or `undefined`, the return value will be unrounded
1286 + * and in normal notation. This is also unlike `Number.prototype.toFixed`, which returns the value
1287 + * to zero decimal places. It is useful when normal notation is required and the current
1288 + * `EXPONENTIAL_AT` setting causes `toString` to return exponential notation.
1289 + *
1290 + * If `roundingMode` is omitted or is `null` or `undefined`, `ROUNDING_MODE` is used.
1291 + *
1292 + * Throws if `decimalPlaces` or `roundingMode` is invalid.
1293 + *
1294 + * ```ts
1295 + * x = 3.456
1296 + * y = new BigNumber(x)
1297 + * x.toFixed() // '3'
1298 + * y.toFixed() // '3.456'
1299 + * y.toFixed(0) // '3'
1300 + * x.toFixed(2) // '3.46'
1301 + * y.toFixed(2) // '3.46'
1302 + * y.toFixed(2, 1) // '3.45' (ROUND_DOWN)
1303 + * x.toFixed(5) // '3.45600'
1304 + * y.toFixed(5) // '3.45600'
1305 + * ```
1306 + *
1307 + * @param [decimalPlaces] Decimal places, integer, 0 to 1e+9.
1308 + * @param [roundingMode] Rounding mode, integer, 0 to 8.
1309 + */
1310 + toFixed(decimalPlaces: number, roundingMode?: BigNumber.RoundingMode): string;
1311 + toFixed(): string;
1312 +
1313 + /**
1314 + * Returns a string representing the value of this BigNumber in normal (fixed-point) notation
1315 + * rounded to `decimalPlaces` decimal places using rounding mode `roundingMode`, and formatted
1316 + * according to the properties of the `format` or `FORMAT` object.
1317 + *
1318 + * The formatting object may contain some or all of the properties shown in the examples below.
1319 + *
1320 + * If `decimalPlaces` is omitted or is `null` or `undefined`, then the return value is not
1321 + * rounded to a fixed number of decimal places.
1322 + *
1323 + * If `roundingMode` is omitted or is `null` or `undefined`, `ROUNDING_MODE` is used.
1324 + *
1325 + * If `format` is omitted or is `null` or `undefined`, `FORMAT` is used.
1326 + *
1327 + * Throws if `decimalPlaces`, `roundingMode`, or `format` is invalid.
1328 + *
1329 + * ```ts
1330 + * fmt = {
1331 + * decimalSeparator: '.',
1332 + * groupSeparator: ',',
1333 + * groupSize: 3,
1334 + * secondaryGroupSize: 0,
1335 + * fractionGroupSeparator: ' ',
1336 + * fractionGroupSize: 0
1337 + * }
1338 + *
1339 + * x = new BigNumber('123456789.123456789')
1340 + *
1341 + * // Set the global formatting options
1342 + * BigNumber.config({ FORMAT: fmt })
1343 + *
1344 + * x.toFormat() // '123,456,789.123456789'
1345 + * x.toFormat(3) // '123,456,789.123'
1346 + *
1347 + * // If a reference to the object assigned to FORMAT has been retained,
1348 + * // the format properties can be changed directly
1349 + * fmt.groupSeparator = ' '
1350 + * fmt.fractionGroupSize = 5
1351 + * x.toFormat() // '123 456 789.12345 6789'
1352 + *
1353 + * // Alternatively, pass the formatting options as an argument
1354 + * fmt = {
1355 + * decimalSeparator: ',',
1356 + * groupSeparator: '.',
1357 + * groupSize: 3,
1358 + * secondaryGroupSize: 2
1359 + * }
1360 + *
1361 + * x.toFormat() // '123 456 789.12345 6789'
1362 + * x.toFormat(fmt) // '12.34.56.789,123456789'
1363 + * x.toFormat(2, fmt) // '12.34.56.789,12'
1364 + * x.toFormat(3, BigNumber.ROUND_UP, fmt) // '12.34.56.789,124'
1365 + * ```
1366 + *
1367 + * @param [decimalPlaces] Decimal places, integer, 0 to 1e+9.
1368 + * @param [roundingMode] Rounding mode, integer, 0 to 8.
1369 + * @param [format] Formatting options object. See `BigNumber.Format`.
1370 + */
1371 + toFormat(decimalPlaces: number, roundingMode: BigNumber.RoundingMode, format?: BigNumber.Format): string;
1372 + toFormat(decimalPlaces: number, roundingMode?: BigNumber.RoundingMode): string;
1373 + toFormat(decimalPlaces?: number): string;
1374 + toFormat(decimalPlaces: number, format: BigNumber.Format): string;
1375 + toFormat(format: BigNumber.Format): string;
1376 +
1377 + /**
1378 + * Returns an array of two BigNumbers representing the value of this BigNumber as a simple
1379 + * fraction with an integer numerator and an integer denominator.
1380 + * The denominator will be a positive non-zero value less than or equal to `max_denominator`.
1381 + * If a maximum denominator, `max_denominator`, is not specified, or is `null` or `undefined`, the
1382 + * denominator will be the lowest value necessary to represent the number exactly.
1383 + *
1384 + * Throws if `max_denominator` is invalid.
1385 + *
1386 + * ```ts
1387 + * x = new BigNumber(1.75)
1388 + * x.toFraction() // '7, 4'
1389 + *
1390 + * pi = new BigNumber('3.14159265358')
1391 + * pi.toFraction() // '157079632679,50000000000'
1392 + * pi.toFraction(100000) // '312689, 99532'
1393 + * pi.toFraction(10000) // '355, 113'
1394 + * pi.toFraction(100) // '311, 99'
1395 + * pi.toFraction(10) // '22, 7'
1396 + * pi.toFraction(1) // '3, 1'
1397 + * ```
1398 + *
1399 + * @param [max_denominator] The maximum denominator, integer > 0, or Infinity.
1400 + */
1401 + toFraction(max_denominator?: BigNumber.Value): [BigNumber, BigNumber];
1402 +
1403 + /** As `valueOf`. */
1404 + toJSON(): string;
1405 +
1406 + /**
1407 + * Returns the value of this BigNumber as a JavaScript primitive number.
1408 + *
1409 + * Using the unary plus operator gives the same result.
1410 + *
1411 + * ```ts
1412 + * x = new BigNumber(456.789)
1413 + * x.toNumber() // 456.789
1414 + * +x // 456.789
1415 + *
1416 + * y = new BigNumber('45987349857634085409857349856430985')
1417 + * y.toNumber() // 4.598734985763409e+34
1418 + *
1419 + * z = new BigNumber(-0)
1420 + * 1 / z.toNumber() // -Infinity
1421 + * 1 / +z // -Infinity
1422 + * ```
1423 + */
1424 + toNumber(): number;
1425 +
1426 + /**
1427 + * Returns a string representing the value of this BigNumber rounded to `significantDigits`
1428 + * significant digits using rounding mode `roundingMode`.
1429 + *
1430 + * If `significantDigits` is less than the number of digits necessary to represent the integer
1431 + * part of the value in normal (fixed-point) notation, then exponential notation is used.
1432 + *
1433 + * If `significantDigits` is omitted, or is `null` or `undefined`, then the return value is the
1434 + * same as `n.toString()`.
1435 + *
1436 + * If `roundingMode` is omitted or is `null` or `undefined`, `ROUNDING_MODE` is used.
1437 + *
1438 + * Throws if `significantDigits` or `roundingMode` is invalid.
1439 + *
1440 + * ```ts
1441 + * x = 45.6
1442 + * y = new BigNumber(x)
1443 + * x.toPrecision() // '45.6'
1444 + * y.toPrecision() // '45.6'
1445 + * x.toPrecision(1) // '5e+1'
1446 + * y.toPrecision(1) // '5e+1'
1447 + * y.toPrecision(2, 0) // '4.6e+1' (ROUND_UP)
1448 + * y.toPrecision(2, 1) // '4.5e+1' (ROUND_DOWN)
1449 + * x.toPrecision(5) // '45.600'
1450 + * y.toPrecision(5) // '45.600'
1451 + * ```
1452 + *
1453 + * @param [significantDigits] Significant digits, integer, 1 to 1e+9.
1454 + * @param [roundingMode] Rounding mode, integer 0 to 8.
1455 + */
1456 + toPrecision(significantDigits: number, roundingMode?: BigNumber.RoundingMode): string;
1457 + toPrecision(): string;
1458 +
1459 + /**
1460 + * Returns a string representing the value of this BigNumber in base `base`, or base 10 if `base`
1461 + * is omitted or is `null` or `undefined`.
1462 + *
1463 + * For bases above 10, and using the default base conversion alphabet (see `ALPHABET`), values
1464 + * from 10 to 35 are represented by a-z (the same as `Number.prototype.toString`).
1465 + *
1466 + * If a base is specified the value is rounded according to the current `DECIMAL_PLACES` and
1467 + * `ROUNDING_MODE` settings, otherwise it is not.
1468 + *
1469 + * If a base is not specified, and this BigNumber has a positive exponent that is equal to or
1470 + * greater than the positive component of the current `EXPONENTIAL_AT` setting, or a negative
1471 + * exponent equal to or less than the negative component of the setting, then exponential notation
1472 + * is returned.
1473 + *
1474 + * If `base` is `null` or `undefined` it is ignored.
1475 + *
1476 + * Throws if `base` is invalid.
1477 + *
1478 + * ```ts
1479 + * x = new BigNumber(750000)
1480 + * x.toString() // '750000'
1481 + * BigNumber.config({ EXPONENTIAL_AT: 5 })
1482 + * x.toString() // '7.5e+5'
1483 + *
1484 + * y = new BigNumber(362.875)
1485 + * y.toString(2) // '101101010.111'
1486 + * y.toString(9) // '442.77777777777777777778'
1487 + * y.toString(32) // 'ba.s'
1488 + *
1489 + * BigNumber.config({ DECIMAL_PLACES: 4 });
1490 + * z = new BigNumber('1.23456789')
1491 + * z.toString() // '1.23456789'
1492 + * z.toString(10) // '1.2346'
1493 + * ```
1494 + *
1495 + * @param [base] The base, integer, 2 to 36 (or `ALPHABET.length`, see `ALPHABET`).
1496 + */
1497 + toString(base?: number): string;
1498 +
1499 + /**
1500 + * As `toString`, but does not accept a base argument and includes the minus sign for negative
1501 + * zero.
1502 + *
1503 + * ``ts
1504 + * x = new BigNumber('-0')
1505 + * x.toString() // '0'
1506 + * x.valueOf() // '-0'
1507 + * y = new BigNumber('1.777e+457')
1508 + * y.valueOf() // '1.777e+457'
1509 + * ```
1510 + */
1511 + valueOf(): string;
1512 +
1513 + /** Helps ES6 import. */
1514 + private static readonly default?: BigNumber.Constructor;
1515 +
1516 + /** Helps ES6 import. */
1517 + private static readonly BigNumber?: BigNumber.Constructor;
1518 +
1519 + /** Rounds away from zero. */
1520 + static readonly ROUND_UP: 0;
1521 +
1522 + /** Rounds towards zero. */
1523 + static readonly ROUND_DOWN: 1;
1524 +
1525 + /** Rounds towards Infinity. */
1526 + static readonly ROUND_CEIL: 2;
1527 +
1528 + /** Rounds towards -Infinity. */
1529 + static readonly ROUND_FLOOR: 3;
1530 +
1531 + /** Rounds towards nearest neighbour. If equidistant, rounds away from zero . */
1532 + static readonly ROUND_HALF_UP: 4;
1533 +
1534 + /** Rounds towards nearest neighbour. If equidistant, rounds towards zero. */
1535 + static readonly ROUND_HALF_DOWN: 5;
1536 +
1537 + /** Rounds towards nearest neighbour. If equidistant, rounds towards even neighbour. */
1538 + static readonly ROUND_HALF_EVEN: 6;
1539 +
1540 + /** Rounds towards nearest neighbour. If equidistant, rounds towards Infinity. */
1541 + static readonly ROUND_HALF_CEIL: 7;
1542 +
1543 + /** Rounds towards nearest neighbour. If equidistant, rounds towards -Infinity. */
1544 + static readonly ROUND_HALF_FLOOR: 8;
1545 +
1546 + /** See `MODULO_MODE`. */
1547 + static readonly EUCLID: 9;
1548 +
1549 + /**
1550 + * To aid in debugging, if a `BigNumber.DEBUG` property is `true` then an error will be thrown
1551 + * if the BigNumber constructor receives an invalid `BigNumber.Value`, or if `BigNumber.isBigNumber`
1552 + * receives a BigNumber instance that is malformed.
1553 + *
1554 + * ```ts
1555 + * // No error, and BigNumber NaN is returned.
1556 + * new BigNumber('blurgh') // 'NaN'
1557 + * new BigNumber(9, 2) // 'NaN'
1558 + * BigNumber.DEBUG = true
1559 + * new BigNumber('blurgh') // '[BigNumber Error] Not a number'
1560 + * new BigNumber(9, 2) // '[BigNumber Error] Not a base 2 number'
1561 + * ```
1562 + *
1563 + * An error will also be thrown if a `BigNumber.Value` is of type number with more than 15
1564 + * significant digits, as calling `toString` or `valueOf` on such numbers may not result
1565 + * in the intended value.
1566 + *
1567 + * ```ts
1568 + * console.log(823456789123456.3) // 823456789123456.2
1569 + * // No error, and the returned BigNumber does not have the same value as the number literal.
1570 + * new BigNumber(823456789123456.3) // '823456789123456.2'
1571 + * BigNumber.DEBUG = true
1572 + * new BigNumber(823456789123456.3)
1573 + * // '[BigNumber Error] Number primitive has more than 15 significant digits'
1574 + * ```
1575 + *
1576 + * Check that a BigNumber instance is well-formed:
1577 + *
1578 + * ```ts
1579 + * x = new BigNumber(10)
1580 + *
1581 + * BigNumber.DEBUG = false
1582 + * // Change x.c to an illegitimate value.
1583 + * x.c = NaN
1584 + * // No error, as BigNumber.DEBUG is false.
1585 + * BigNumber.isBigNumber(x) // true
1586 + *
1587 + * BigNumber.DEBUG = true
1588 + * BigNumber.isBigNumber(x) // '[BigNumber Error] Invalid BigNumber'
1589 + * ```
1590 + */
1591 + static DEBUG?: boolean;
1592 +
1593 + /**
1594 + * Returns a new independent BigNumber constructor with configuration as described by `object`, or
1595 + * with the default configuration if object is `null` or `undefined`.
1596 + *
1597 + * Throws if `object` is not an object.
1598 + *
1599 + * ```ts
1600 + * BigNumber.config({ DECIMAL_PLACES: 5 })
1601 + * BN = BigNumber.clone({ DECIMAL_PLACES: 9 })
1602 + *
1603 + * x = new BigNumber(1)
1604 + * y = new BN(1)
1605 + *
1606 + * x.div(3) // 0.33333
1607 + * y.div(3) // 0.333333333
1608 + *
1609 + * // BN = BigNumber.clone({ DECIMAL_PLACES: 9 }) is equivalent to:
1610 + * BN = BigNumber.clone()
1611 + * BN.config({ DECIMAL_PLACES: 9 })
1612 + * ```
1613 + *
1614 + * @param [object] The configuration object.
1615 + */
1616 + static clone(object?: BigNumber.Config): BigNumber.Constructor;
1617 +
1618 + /**
1619 + * Configures the settings that apply to this BigNumber constructor.
1620 + *
1621 + * The configuration object, `object`, contains any number of the properties shown in the example
1622 + * below.
1623 + *
1624 + * Returns an object with the above properties and their current values.
1625 + *
1626 + * Throws if `object` is not an object, or if an invalid value is assigned to one or more of the
1627 + * properties.
1628 + *
1629 + * ```ts
1630 + * BigNumber.config({
1631 + * DECIMAL_PLACES: 40,
1632 + * ROUNDING_MODE: BigNumber.ROUND_HALF_CEIL,
1633 + * EXPONENTIAL_AT: [-10, 20],
1634 + * RANGE: [-500, 500],
1635 + * CRYPTO: true,
1636 + * MODULO_MODE: BigNumber.ROUND_FLOOR,
1637 + * POW_PRECISION: 80,
1638 + * FORMAT: {
1639 + * groupSize: 3,
1640 + * groupSeparator: ' ',
1641 + * decimalSeparator: ','
1642 + * },
1643 + * ALPHABET: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_'
1644 + * });
1645 + *
1646 + * BigNumber.config().DECIMAL_PLACES // 40
1647 + * ```
1648 + *
1649 + * @param object The configuration object.
1650 + */
1651 + static config(object: BigNumber.Config): BigNumber.Config;
1652 +
1653 + /**
1654 + * Returns `true` if `value` is a BigNumber instance, otherwise returns `false`.
1655 + *
1656 + * If `BigNumber.DEBUG` is `true`, throws if a BigNumber instance is not well-formed.
1657 + *
1658 + * ```ts
1659 + * x = 42
1660 + * y = new BigNumber(x)
1661 + *
1662 + * BigNumber.isBigNumber(x) // false
1663 + * y instanceof BigNumber // true
1664 + * BigNumber.isBigNumber(y) // true
1665 + *
1666 + * BN = BigNumber.clone();
1667 + * z = new BN(x)
1668 + * z instanceof BigNumber // false
1669 + * BigNumber.isBigNumber(z) // true
1670 + * ```
1671 + *
1672 + * @param value The value to test.
1673 + */
1674 + static isBigNumber(value: any): value is BigNumber;
1675 +
1676 + /**
1677 + * Returns a BigNumber whose value is the maximum of the arguments.
1678 + *
1679 + * The return value is always exact and unrounded.
1680 + *
1681 + * ```ts
1682 + * x = new BigNumber('3257869345.0378653')
1683 + * BigNumber.maximum(4e9, x, '123456789.9') // '4000000000'
1684 + *
1685 + * arr = [12, '13', new BigNumber(14)]
1686 + * BigNumber.maximum.apply(null, arr) // '14'
1687 + * ```
1688 + *
1689 + * @param n A numeric value.
1690 + */
1691 + static maximum(...n: BigNumber.Value[]): BigNumber;
1692 +
1693 + /**
1694 + * Returns a BigNumber whose value is the maximum of the arguments.
1695 + *
1696 + * The return value is always exact and unrounded.
1697 + *
1698 + * ```ts
1699 + * x = new BigNumber('3257869345.0378653')
1700 + * BigNumber.max(4e9, x, '123456789.9') // '4000000000'
1701 + *
1702 + * arr = [12, '13', new BigNumber(14)]
1703 + * BigNumber.max.apply(null, arr) // '14'
1704 + * ```
1705 + *
1706 + * @param n A numeric value.
1707 + */
1708 + static max(...n: BigNumber.Value[]): BigNumber;
1709 +
1710 + /**
1711 + * Returns a BigNumber whose value is the minimum of the arguments.
1712 + *
1713 + * The return value is always exact and unrounded.
1714 + *
1715 + * ```ts
1716 + * x = new BigNumber('3257869345.0378653')
1717 + * BigNumber.minimum(4e9, x, '123456789.9') // '123456789.9'
1718 + *
1719 + * arr = [2, new BigNumber(-14), '-15.9999', -12]
1720 + * BigNumber.minimum.apply(null, arr) // '-15.9999'
1721 + * ```
1722 + *
1723 + * @param n A numeric value.
1724 + */
1725 + static minimum(...n: BigNumber.Value[]): BigNumber;
1726 +
1727 + /**
1728 + * Returns a BigNumber whose value is the minimum of the arguments.
1729 + *
1730 + * The return value is always exact and unrounded.
1731 + *
1732 + * ```ts
1733 + * x = new BigNumber('3257869345.0378653')
1734 + * BigNumber.min(4e9, x, '123456789.9') // '123456789.9'
1735 + *
1736 + * arr = [2, new BigNumber(-14), '-15.9999', -12]
1737 + * BigNumber.min.apply(null, arr) // '-15.9999'
1738 + * ```
1739 + *
1740 + * @param n A numeric value.
1741 + */
1742 + static min(...n: BigNumber.Value[]): BigNumber;
1743 +
1744 + /**
1745 + * Returns a new BigNumber with a pseudo-random value equal to or greater than 0 and less than 1.
1746 + *
1747 + * The return value will have `decimalPlaces` decimal places, or less if trailing zeros are
1748 + * produced. If `decimalPlaces` is omitted, the current `DECIMAL_PLACES` setting will be used.
1749 + *
1750 + * Depending on the value of this BigNumber constructor's `CRYPTO` setting and the support for the
1751 + * `crypto` object in the host environment, the random digits of the return value are generated by
1752 + * either `Math.random` (fastest), `crypto.getRandomValues` (Web Cryptography API in recent
1753 + * browsers) or `crypto.randomBytes` (Node.js).
1754 + *
1755 + * To be able to set `CRYPTO` to true when using Node.js, the `crypto` object must be available
1756 + * globally:
1757 + *
1758 + * ```ts
1759 + * global.crypto = require('crypto')
1760 + * ```
1761 + *
1762 + * If `CRYPTO` is true, i.e. one of the `crypto` methods is to be used, the value of a returned
1763 + * BigNumber should be cryptographically secure and statistically indistinguishable from a random
1764 + * value.
1765 + *
1766 + * Throws if `decimalPlaces` is invalid.
1767 + *
1768 + * ```ts
1769 + * BigNumber.config({ DECIMAL_PLACES: 10 })
1770 + * BigNumber.random() // '0.4117936847'
1771 + * BigNumber.random(20) // '0.78193327636914089009'
1772 + * ```
1773 + *
1774 + * @param [decimalPlaces] Decimal places, integer, 0 to 1e+9.
1775 + */
1776 + static random(decimalPlaces?: number): BigNumber;
1777 +
1778 + /**
1779 + * Returns a BigNumber whose value is the sum of the arguments.
1780 + *
1781 + * The return value is always exact and unrounded.
1782 + *
1783 + * ```ts
1784 + * x = new BigNumber('3257869345.0378653')
1785 + * BigNumber.sum(4e9, x, '123456789.9') // '7381326134.9378653'
1786 + *
1787 + * arr = [2, new BigNumber(14), '15.9999', 12]
1788 + * BigNumber.sum.apply(null, arr) // '43.9999'
1789 + * ```
1790 + *
1791 + * @param n A numeric value.
1792 + */
1793 + static sum(...n: BigNumber.Value[]): BigNumber;
1794 +
1795 + /**
1796 + * Configures the settings that apply to this BigNumber constructor.
1797 + *
1798 + * The configuration object, `object`, contains any number of the properties shown in the example
1799 + * below.
1800 + *
1801 + * Returns an object with the above properties and their current values.
1802 + *
1803 + * Throws if `object` is not an object, or if an invalid value is assigned to one or more of the
1804 + * properties.
1805 + *
1806 + * ```ts
1807 + * BigNumber.set({
1808 + * DECIMAL_PLACES: 40,
1809 + * ROUNDING_MODE: BigNumber.ROUND_HALF_CEIL,
1810 + * EXPONENTIAL_AT: [-10, 20],
1811 + * RANGE: [-500, 500],
1812 + * CRYPTO: true,
1813 + * MODULO_MODE: BigNumber.ROUND_FLOOR,
1814 + * POW_PRECISION: 80,
1815 + * FORMAT: {
1816 + * groupSize: 3,
1817 + * groupSeparator: ' ',
1818 + * decimalSeparator: ','
1819 + * },
1820 + * ALPHABET: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_'
1821 + * });
1822 + *
1823 + * BigNumber.set().DECIMAL_PLACES // 40
1824 + * ```
1825 + *
1826 + * @param object The configuration object.
1827 + */
1828 + static set(object: BigNumber.Config): BigNumber.Config;
1829 +}
1 +;(function (globalObject) {
2 + 'use strict';
3 +
4 +/*
5 + * bignumber.js v9.0.0
6 + * A JavaScript library for arbitrary-precision arithmetic.
7 + * https://github.com/MikeMcl/bignumber.js
8 + * Copyright (c) 2019 Michael Mclaughlin <M8ch88l@gmail.com>
9 + * MIT Licensed.
10 + *
11 + * BigNumber.prototype methods | BigNumber methods
12 + * |
13 + * absoluteValue abs | clone
14 + * comparedTo | config set
15 + * decimalPlaces dp | DECIMAL_PLACES
16 + * dividedBy div | ROUNDING_MODE
17 + * dividedToIntegerBy idiv | EXPONENTIAL_AT
18 + * exponentiatedBy pow | RANGE
19 + * integerValue | CRYPTO
20 + * isEqualTo eq | MODULO_MODE
21 + * isFinite | POW_PRECISION
22 + * isGreaterThan gt | FORMAT
23 + * isGreaterThanOrEqualTo gte | ALPHABET
24 + * isInteger | isBigNumber
25 + * isLessThan lt | maximum max
26 + * isLessThanOrEqualTo lte | minimum min
27 + * isNaN | random
28 + * isNegative | sum
29 + * isPositive |
30 + * isZero |
31 + * minus |
32 + * modulo mod |
33 + * multipliedBy times |
34 + * negated |
35 + * plus |
36 + * precision sd |
37 + * shiftedBy |
38 + * squareRoot sqrt |
39 + * toExponential |
40 + * toFixed |
41 + * toFormat |
42 + * toFraction |
43 + * toJSON |
44 + * toNumber |
45 + * toPrecision |
46 + * toString |
47 + * valueOf |
48 + *
49 + */
50 +
51 +
52 + var BigNumber,
53 + isNumeric = /^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,
54 + mathceil = Math.ceil,
55 + mathfloor = Math.floor,
56 +
57 + bignumberError = '[BigNumber Error] ',
58 + tooManyDigits = bignumberError + 'Number primitive has more than 15 significant digits: ',
59 +
60 + BASE = 1e14,
61 + LOG_BASE = 14,
62 + MAX_SAFE_INTEGER = 0x1fffffffffffff, // 2^53 - 1
63 + // MAX_INT32 = 0x7fffffff, // 2^31 - 1
64 + POWS_TEN = [1, 10, 100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13],
65 + SQRT_BASE = 1e7,
66 +
67 + // EDITABLE
68 + // The limit on the value of DECIMAL_PLACES, TO_EXP_NEG, TO_EXP_POS, MIN_EXP, MAX_EXP, and
69 + // the arguments to toExponential, toFixed, toFormat, and toPrecision.
70 + MAX = 1E9; // 0 to MAX_INT32
71 +
72 +
73 + /*
74 + * Create and return a BigNumber constructor.
75 + */
76 + function clone(configObject) {
77 + var div, convertBase, parseNumeric,
78 + P = BigNumber.prototype = { constructor: BigNumber, toString: null, valueOf: null },
79 + ONE = new BigNumber(1),
80 +
81 +
82 + //----------------------------- EDITABLE CONFIG DEFAULTS -------------------------------
83 +
84 +
85 + // The default values below must be integers within the inclusive ranges stated.
86 + // The values can also be changed at run-time using BigNumber.set.
87 +
88 + // The maximum number of decimal places for operations involving division.
89 + DECIMAL_PLACES = 20, // 0 to MAX
90 +
91 + // The rounding mode used when rounding to the above decimal places, and when using
92 + // toExponential, toFixed, toFormat and toPrecision, and round (default value).
93 + // UP 0 Away from zero.
94 + // DOWN 1 Towards zero.
95 + // CEIL 2 Towards +Infinity.
96 + // FLOOR 3 Towards -Infinity.
97 + // HALF_UP 4 Towards nearest neighbour. If equidistant, up.
98 + // HALF_DOWN 5 Towards nearest neighbour. If equidistant, down.
99 + // HALF_EVEN 6 Towards nearest neighbour. If equidistant, towards even neighbour.
100 + // HALF_CEIL 7 Towards nearest neighbour. If equidistant, towards +Infinity.
101 + // HALF_FLOOR 8 Towards nearest neighbour. If equidistant, towards -Infinity.
102 + ROUNDING_MODE = 4, // 0 to 8
103 +
104 + // EXPONENTIAL_AT : [TO_EXP_NEG , TO_EXP_POS]
105 +
106 + // The exponent value at and beneath which toString returns exponential notation.
107 + // Number type: -7
108 + TO_EXP_NEG = -7, // 0 to -MAX
109 +
110 + // The exponent value at and above which toString returns exponential notation.
111 + // Number type: 21
112 + TO_EXP_POS = 21, // 0 to MAX
113 +
114 + // RANGE : [MIN_EXP, MAX_EXP]
115 +
116 + // The minimum exponent value, beneath which underflow to zero occurs.
117 + // Number type: -324 (5e-324)
118 + MIN_EXP = -1e7, // -1 to -MAX
119 +
120 + // The maximum exponent value, above which overflow to Infinity occurs.
121 + // Number type: 308 (1.7976931348623157e+308)
122 + // For MAX_EXP > 1e7, e.g. new BigNumber('1e100000000').plus(1) may be slow.
123 + MAX_EXP = 1e7, // 1 to MAX
124 +
125 + // Whether to use cryptographically-secure random number generation, if available.
126 + CRYPTO = false, // true or false
127 +
128 + // The modulo mode used when calculating the modulus: a mod n.
129 + // The quotient (q = a / n) is calculated according to the corresponding rounding mode.
130 + // The remainder (r) is calculated as: r = a - n * q.
131 + //
132 + // UP 0 The remainder is positive if the dividend is negative, else is negative.
133 + // DOWN 1 The remainder has the same sign as the dividend.
134 + // This modulo mode is commonly known as 'truncated division' and is
135 + // equivalent to (a % n) in JavaScript.
136 + // FLOOR 3 The remainder has the same sign as the divisor (Python %).
137 + // HALF_EVEN 6 This modulo mode implements the IEEE 754 remainder function.
138 + // EUCLID 9 Euclidian division. q = sign(n) * floor(a / abs(n)).
139 + // The remainder is always positive.
140 + //
141 + // The truncated division, floored division, Euclidian division and IEEE 754 remainder
142 + // modes are commonly used for the modulus operation.
143 + // Although the other rounding modes can also be used, they may not give useful results.
144 + MODULO_MODE = 1, // 0 to 9
145 +
146 + // The maximum number of significant digits of the result of the exponentiatedBy operation.
147 + // If POW_PRECISION is 0, there will be unlimited significant digits.
148 + POW_PRECISION = 0, // 0 to MAX
149 +
150 + // The format specification used by the BigNumber.prototype.toFormat method.
151 + FORMAT = {
152 + prefix: '',
153 + groupSize: 3,
154 + secondaryGroupSize: 0,
155 + groupSeparator: ',',
156 + decimalSeparator: '.',
157 + fractionGroupSize: 0,
158 + fractionGroupSeparator: '\xA0', // non-breaking space
159 + suffix: ''
160 + },
161 +
162 + // The alphabet used for base conversion. It must be at least 2 characters long, with no '+',
163 + // '-', '.', whitespace, or repeated character.
164 + // '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_'
165 + ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyz';
166 +
167 +
168 + //------------------------------------------------------------------------------------------
169 +
170 +
171 + // CONSTRUCTOR
172 +
173 +
174 + /*
175 + * The BigNumber constructor and exported function.
176 + * Create and return a new instance of a BigNumber object.
177 + *
178 + * v {number|string|BigNumber} A numeric value.
179 + * [b] {number} The base of v. Integer, 2 to ALPHABET.length inclusive.
180 + */
181 + function BigNumber(v, b) {
182 + var alphabet, c, caseChanged, e, i, isNum, len, str,
183 + x = this;
184 +
185 + // Enable constructor call without `new`.
186 + if (!(x instanceof BigNumber)) return new BigNumber(v, b);
187 +
188 + if (b == null) {
189 +
190 + if (v && v._isBigNumber === true) {
191 + x.s = v.s;
192 +
193 + if (!v.c || v.e > MAX_EXP) {
194 + x.c = x.e = null;
195 + } else if (v.e < MIN_EXP) {
196 + x.c = [x.e = 0];
197 + } else {
198 + x.e = v.e;
199 + x.c = v.c.slice();
200 + }
201 +
202 + return;
203 + }
204 +
205 + if ((isNum = typeof v == 'number') && v * 0 == 0) {
206 +
207 + // Use `1 / n` to handle minus zero also.
208 + x.s = 1 / v < 0 ? (v = -v, -1) : 1;
209 +
210 + // Fast path for integers, where n < 2147483648 (2**31).
211 + if (v === ~~v) {
212 + for (e = 0, i = v; i >= 10; i /= 10, e++);
213 +
214 + if (e > MAX_EXP) {
215 + x.c = x.e = null;
216 + } else {
217 + x.e = e;
218 + x.c = [v];
219 + }
220 +
221 + return;
222 + }
223 +
224 + str = String(v);
225 + } else {
226 +
227 + if (!isNumeric.test(str = String(v))) return parseNumeric(x, str, isNum);
228 +
229 + x.s = str.charCodeAt(0) == 45 ? (str = str.slice(1), -1) : 1;
230 + }
231 +
232 + // Decimal point?
233 + if ((e = str.indexOf('.')) > -1) str = str.replace('.', '');
234 +
235 + // Exponential form?
236 + if ((i = str.search(/e/i)) > 0) {
237 +
238 + // Determine exponent.
239 + if (e < 0) e = i;
240 + e += +str.slice(i + 1);
241 + str = str.substring(0, i);
242 + } else if (e < 0) {
243 +
244 + // Integer.
245 + e = str.length;
246 + }
247 +
248 + } else {
249 +
250 + // '[BigNumber Error] Base {not a primitive number|not an integer|out of range}: {b}'
251 + intCheck(b, 2, ALPHABET.length, 'Base');
252 +
253 + // Allow exponential notation to be used with base 10 argument, while
254 + // also rounding to DECIMAL_PLACES as with other bases.
255 + if (b == 10) {
256 + x = new BigNumber(v);
257 + return round(x, DECIMAL_PLACES + x.e + 1, ROUNDING_MODE);
258 + }
259 +
260 + str = String(v);
261 +
262 + if (isNum = typeof v == 'number') {
263 +
264 + // Avoid potential interpretation of Infinity and NaN as base 44+ values.
265 + if (v * 0 != 0) return parseNumeric(x, str, isNum, b);
266 +
267 + x.s = 1 / v < 0 ? (str = str.slice(1), -1) : 1;
268 +
269 + // '[BigNumber Error] Number primitive has more than 15 significant digits: {n}'
270 + if (BigNumber.DEBUG && str.replace(/^0\.0*|\./, '').length > 15) {
271 + throw Error
272 + (tooManyDigits + v);
273 + }
274 + } else {
275 + x.s = str.charCodeAt(0) === 45 ? (str = str.slice(1), -1) : 1;
276 + }
277 +
278 + alphabet = ALPHABET.slice(0, b);
279 + e = i = 0;
280 +
281 + // Check that str is a valid base b number.
282 + // Don't use RegExp, so alphabet can contain special characters.
283 + for (len = str.length; i < len; i++) {
284 + if (alphabet.indexOf(c = str.charAt(i)) < 0) {
285 + if (c == '.') {
286 +
287 + // If '.' is not the first character and it has not be found before.
288 + if (i > e) {
289 + e = len;
290 + continue;
291 + }
292 + } else if (!caseChanged) {
293 +
294 + // Allow e.g. hexadecimal 'FF' as well as 'ff'.
295 + if (str == str.toUpperCase() && (str = str.toLowerCase()) ||
296 + str == str.toLowerCase() && (str = str.toUpperCase())) {
297 + caseChanged = true;
298 + i = -1;
299 + e = 0;
300 + continue;
301 + }
302 + }
303 +
304 + return parseNumeric(x, String(v), isNum, b);
305 + }
306 + }
307 +
308 + // Prevent later check for length on converted number.
309 + isNum = false;
310 + str = convertBase(str, b, 10, x.s);
311 +
312 + // Decimal point?
313 + if ((e = str.indexOf('.')) > -1) str = str.replace('.', '');
314 + else e = str.length;
315 + }
316 +
317 + // Determine leading zeros.
318 + for (i = 0; str.charCodeAt(i) === 48; i++);
319 +
320 + // Determine trailing zeros.
321 + for (len = str.length; str.charCodeAt(--len) === 48;);
322 +
323 + if (str = str.slice(i, ++len)) {
324 + len -= i;
325 +
326 + // '[BigNumber Error] Number primitive has more than 15 significant digits: {n}'
327 + if (isNum && BigNumber.DEBUG &&
328 + len > 15 && (v > MAX_SAFE_INTEGER || v !== mathfloor(v))) {
329 + throw Error
330 + (tooManyDigits + (x.s * v));
331 + }
332 +
333 + // Overflow?
334 + if ((e = e - i - 1) > MAX_EXP) {
335 +
336 + // Infinity.
337 + x.c = x.e = null;
338 +
339 + // Underflow?
340 + } else if (e < MIN_EXP) {
341 +
342 + // Zero.
343 + x.c = [x.e = 0];
344 + } else {
345 + x.e = e;
346 + x.c = [];
347 +
348 + // Transform base
349 +
350 + // e is the base 10 exponent.
351 + // i is where to slice str to get the first element of the coefficient array.
352 + i = (e + 1) % LOG_BASE;
353 + if (e < 0) i += LOG_BASE; // i < 1
354 +
355 + if (i < len) {
356 + if (i) x.c.push(+str.slice(0, i));
357 +
358 + for (len -= LOG_BASE; i < len;) {
359 + x.c.push(+str.slice(i, i += LOG_BASE));
360 + }
361 +
362 + i = LOG_BASE - (str = str.slice(i)).length;
363 + } else {
364 + i -= len;
365 + }
366 +
367 + for (; i--; str += '0');
368 + x.c.push(+str);
369 + }
370 + } else {
371 +
372 + // Zero.
373 + x.c = [x.e = 0];
374 + }
375 + }
376 +
377 +
378 + // CONSTRUCTOR PROPERTIES
379 +
380 +
381 + BigNumber.clone = clone;
382 +
383 + BigNumber.ROUND_UP = 0;
384 + BigNumber.ROUND_DOWN = 1;
385 + BigNumber.ROUND_CEIL = 2;
386 + BigNumber.ROUND_FLOOR = 3;
387 + BigNumber.ROUND_HALF_UP = 4;
388 + BigNumber.ROUND_HALF_DOWN = 5;
389 + BigNumber.ROUND_HALF_EVEN = 6;
390 + BigNumber.ROUND_HALF_CEIL = 7;
391 + BigNumber.ROUND_HALF_FLOOR = 8;
392 + BigNumber.EUCLID = 9;
393 +
394 +
395 + /*
396 + * Configure infrequently-changing library-wide settings.
397 + *
398 + * Accept an object with the following optional properties (if the value of a property is
399 + * a number, it must be an integer within the inclusive range stated):
400 + *
401 + * DECIMAL_PLACES {number} 0 to MAX
402 + * ROUNDING_MODE {number} 0 to 8
403 + * EXPONENTIAL_AT {number|number[]} -MAX to MAX or [-MAX to 0, 0 to MAX]
404 + * RANGE {number|number[]} -MAX to MAX (not zero) or [-MAX to -1, 1 to MAX]
405 + * CRYPTO {boolean} true or false
406 + * MODULO_MODE {number} 0 to 9
407 + * POW_PRECISION {number} 0 to MAX
408 + * ALPHABET {string} A string of two or more unique characters which does
409 + * not contain '.'.
410 + * FORMAT {object} An object with some of the following properties:
411 + * prefix {string}
412 + * groupSize {number}
413 + * secondaryGroupSize {number}
414 + * groupSeparator {string}
415 + * decimalSeparator {string}
416 + * fractionGroupSize {number}
417 + * fractionGroupSeparator {string}
418 + * suffix {string}
419 + *
420 + * (The values assigned to the above FORMAT object properties are not checked for validity.)
421 + *
422 + * E.g.
423 + * BigNumber.config({ DECIMAL_PLACES : 20, ROUNDING_MODE : 4 })
424 + *
425 + * Ignore properties/parameters set to null or undefined, except for ALPHABET.
426 + *
427 + * Return an object with the properties current values.
428 + */
429 + BigNumber.config = BigNumber.set = function (obj) {
430 + var p, v;
431 +
432 + if (obj != null) {
433 +
434 + if (typeof obj == 'object') {
435 +
436 + // DECIMAL_PLACES {number} Integer, 0 to MAX inclusive.
437 + // '[BigNumber Error] DECIMAL_PLACES {not a primitive number|not an integer|out of range}: {v}'
438 + if (obj.hasOwnProperty(p = 'DECIMAL_PLACES')) {
439 + v = obj[p];
440 + intCheck(v, 0, MAX, p);
441 + DECIMAL_PLACES = v;
442 + }
443 +
444 + // ROUNDING_MODE {number} Integer, 0 to 8 inclusive.
445 + // '[BigNumber Error] ROUNDING_MODE {not a primitive number|not an integer|out of range}: {v}'
446 + if (obj.hasOwnProperty(p = 'ROUNDING_MODE')) {
447 + v = obj[p];
448 + intCheck(v, 0, 8, p);
449 + ROUNDING_MODE = v;
450 + }
451 +
452 + // EXPONENTIAL_AT {number|number[]}
453 + // Integer, -MAX to MAX inclusive or
454 + // [integer -MAX to 0 inclusive, 0 to MAX inclusive].
455 + // '[BigNumber Error] EXPONENTIAL_AT {not a primitive number|not an integer|out of range}: {v}'
456 + if (obj.hasOwnProperty(p = 'EXPONENTIAL_AT')) {
457 + v = obj[p];
458 + if (v && v.pop) {
459 + intCheck(v[0], -MAX, 0, p);
460 + intCheck(v[1], 0, MAX, p);
461 + TO_EXP_NEG = v[0];
462 + TO_EXP_POS = v[1];
463 + } else {
464 + intCheck(v, -MAX, MAX, p);
465 + TO_EXP_NEG = -(TO_EXP_POS = v < 0 ? -v : v);
466 + }
467 + }
468 +
469 + // RANGE {number|number[]} Non-zero integer, -MAX to MAX inclusive or
470 + // [integer -MAX to -1 inclusive, integer 1 to MAX inclusive].
471 + // '[BigNumber Error] RANGE {not a primitive number|not an integer|out of range|cannot be zero}: {v}'
472 + if (obj.hasOwnProperty(p = 'RANGE')) {
473 + v = obj[p];
474 + if (v && v.pop) {
475 + intCheck(v[0], -MAX, -1, p);
476 + intCheck(v[1], 1, MAX, p);
477 + MIN_EXP = v[0];
478 + MAX_EXP = v[1];
479 + } else {
480 + intCheck(v, -MAX, MAX, p);
481 + if (v) {
482 + MIN_EXP = -(MAX_EXP = v < 0 ? -v : v);
483 + } else {
484 + throw Error
485 + (bignumberError + p + ' cannot be zero: ' + v);
486 + }
487 + }
488 + }
489 +
490 + // CRYPTO {boolean} true or false.
491 + // '[BigNumber Error] CRYPTO not true or false: {v}'
492 + // '[BigNumber Error] crypto unavailable'
493 + if (obj.hasOwnProperty(p = 'CRYPTO')) {
494 + v = obj[p];
495 + if (v === !!v) {
496 + if (v) {
497 + if (typeof crypto != 'undefined' && crypto &&
498 + (crypto.getRandomValues || crypto.randomBytes)) {
499 + CRYPTO = v;
500 + } else {
501 + CRYPTO = !v;
502 + throw Error
503 + (bignumberError + 'crypto unavailable');
504 + }
505 + } else {
506 + CRYPTO = v;
507 + }
508 + } else {
509 + throw Error
510 + (bignumberError + p + ' not true or false: ' + v);
511 + }
512 + }
513 +
514 + // MODULO_MODE {number} Integer, 0 to 9 inclusive.
515 + // '[BigNumber Error] MODULO_MODE {not a primitive number|not an integer|out of range}: {v}'
516 + if (obj.hasOwnProperty(p = 'MODULO_MODE')) {
517 + v = obj[p];
518 + intCheck(v, 0, 9, p);
519 + MODULO_MODE = v;
520 + }
521 +
522 + // POW_PRECISION {number} Integer, 0 to MAX inclusive.
523 + // '[BigNumber Error] POW_PRECISION {not a primitive number|not an integer|out of range}: {v}'
524 + if (obj.hasOwnProperty(p = 'POW_PRECISION')) {
525 + v = obj[p];
526 + intCheck(v, 0, MAX, p);
527 + POW_PRECISION = v;
528 + }
529 +
530 + // FORMAT {object}
531 + // '[BigNumber Error] FORMAT not an object: {v}'
532 + if (obj.hasOwnProperty(p = 'FORMAT')) {
533 + v = obj[p];
534 + if (typeof v == 'object') FORMAT = v;
535 + else throw Error
536 + (bignumberError + p + ' not an object: ' + v);
537 + }
538 +
539 + // ALPHABET {string}
540 + // '[BigNumber Error] ALPHABET invalid: {v}'
541 + if (obj.hasOwnProperty(p = 'ALPHABET')) {
542 + v = obj[p];
543 +
544 + // Disallow if only one character,
545 + // or if it contains '+', '-', '.', whitespace, or a repeated character.
546 + if (typeof v == 'string' && !/^.$|[+-.\s]|(.).*\1/.test(v)) {
547 + ALPHABET = v;
548 + } else {
549 + throw Error
550 + (bignumberError + p + ' invalid: ' + v);
551 + }
552 + }
553 +
554 + } else {
555 +
556 + // '[BigNumber Error] Object expected: {v}'
557 + throw Error
558 + (bignumberError + 'Object expected: ' + obj);
559 + }
560 + }
561 +
562 + return {
563 + DECIMAL_PLACES: DECIMAL_PLACES,
564 + ROUNDING_MODE: ROUNDING_MODE,
565 + EXPONENTIAL_AT: [TO_EXP_NEG, TO_EXP_POS],
566 + RANGE: [MIN_EXP, MAX_EXP],
567 + CRYPTO: CRYPTO,
568 + MODULO_MODE: MODULO_MODE,
569 + POW_PRECISION: POW_PRECISION,
570 + FORMAT: FORMAT,
571 + ALPHABET: ALPHABET
572 + };
573 + };
574 +
575 +
576 + /*
577 + * Return true if v is a BigNumber instance, otherwise return false.
578 + *
579 + * If BigNumber.DEBUG is true, throw if a BigNumber instance is not well-formed.
580 + *
581 + * v {any}
582 + *
583 + * '[BigNumber Error] Invalid BigNumber: {v}'
584 + */
585 + BigNumber.isBigNumber = function (v) {
586 + if (!v || v._isBigNumber !== true) return false;
587 + if (!BigNumber.DEBUG) return true;
588 +
589 + var i, n,
590 + c = v.c,
591 + e = v.e,
592 + s = v.s;
593 +
594 + out: if ({}.toString.call(c) == '[object Array]') {
595 +
596 + if ((s === 1 || s === -1) && e >= -MAX && e <= MAX && e === mathfloor(e)) {
597 +
598 + // If the first element is zero, the BigNumber value must be zero.
599 + if (c[0] === 0) {
600 + if (e === 0 && c.length === 1) return true;
601 + break out;
602 + }
603 +
604 + // Calculate number of digits that c[0] should have, based on the exponent.
605 + i = (e + 1) % LOG_BASE;
606 + if (i < 1) i += LOG_BASE;
607 +
608 + // Calculate number of digits of c[0].
609 + //if (Math.ceil(Math.log(c[0] + 1) / Math.LN10) == i) {
610 + if (String(c[0]).length == i) {
611 +
612 + for (i = 0; i < c.length; i++) {
613 + n = c[i];
614 + if (n < 0 || n >= BASE || n !== mathfloor(n)) break out;
615 + }
616 +
617 + // Last element cannot be zero, unless it is the only element.
618 + if (n !== 0) return true;
619 + }
620 + }
621 +
622 + // Infinity/NaN
623 + } else if (c === null && e === null && (s === null || s === 1 || s === -1)) {
624 + return true;
625 + }
626 +
627 + throw Error
628 + (bignumberError + 'Invalid BigNumber: ' + v);
629 + };
630 +
631 +
632 + /*
633 + * Return a new BigNumber whose value is the maximum of the arguments.
634 + *
635 + * arguments {number|string|BigNumber}
636 + */
637 + BigNumber.maximum = BigNumber.max = function () {
638 + return maxOrMin(arguments, P.lt);
639 + };
640 +
641 +
642 + /*
643 + * Return a new BigNumber whose value is the minimum of the arguments.
644 + *
645 + * arguments {number|string|BigNumber}
646 + */
647 + BigNumber.minimum = BigNumber.min = function () {
648 + return maxOrMin(arguments, P.gt);
649 + };
650 +
651 +
652 + /*
653 + * Return a new BigNumber with a random value equal to or greater than 0 and less than 1,
654 + * and with dp, or DECIMAL_PLACES if dp is omitted, decimal places (or less if trailing
655 + * zeros are produced).
656 + *
657 + * [dp] {number} Decimal places. Integer, 0 to MAX inclusive.
658 + *
659 + * '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {dp}'
660 + * '[BigNumber Error] crypto unavailable'
661 + */
662 + BigNumber.random = (function () {
663 + var pow2_53 = 0x20000000000000;
664 +
665 + // Return a 53 bit integer n, where 0 <= n < 9007199254740992.
666 + // Check if Math.random() produces more than 32 bits of randomness.
667 + // If it does, assume at least 53 bits are produced, otherwise assume at least 30 bits.
668 + // 0x40000000 is 2^30, 0x800000 is 2^23, 0x1fffff is 2^21 - 1.
669 + var random53bitInt = (Math.random() * pow2_53) & 0x1fffff
670 + ? function () { return mathfloor(Math.random() * pow2_53); }
671 + : function () { return ((Math.random() * 0x40000000 | 0) * 0x800000) +
672 + (Math.random() * 0x800000 | 0); };
673 +
674 + return function (dp) {
675 + var a, b, e, k, v,
676 + i = 0,
677 + c = [],
678 + rand = new BigNumber(ONE);
679 +
680 + if (dp == null) dp = DECIMAL_PLACES;
681 + else intCheck(dp, 0, MAX);
682 +
683 + k = mathceil(dp / LOG_BASE);
684 +
685 + if (CRYPTO) {
686 +
687 + // Browsers supporting crypto.getRandomValues.
688 + if (crypto.getRandomValues) {
689 +
690 + a = crypto.getRandomValues(new Uint32Array(k *= 2));
691 +
692 + for (; i < k;) {
693 +
694 + // 53 bits:
695 + // ((Math.pow(2, 32) - 1) * Math.pow(2, 21)).toString(2)
696 + // 11111 11111111 11111111 11111111 11100000 00000000 00000000
697 + // ((Math.pow(2, 32) - 1) >>> 11).toString(2)
698 + // 11111 11111111 11111111
699 + // 0x20000 is 2^21.
700 + v = a[i] * 0x20000 + (a[i + 1] >>> 11);
701 +
702 + // Rejection sampling:
703 + // 0 <= v < 9007199254740992
704 + // Probability that v >= 9e15, is
705 + // 7199254740992 / 9007199254740992 ~= 0.0008, i.e. 1 in 1251
706 + if (v >= 9e15) {
707 + b = crypto.getRandomValues(new Uint32Array(2));
708 + a[i] = b[0];
709 + a[i + 1] = b[1];
710 + } else {
711 +
712 + // 0 <= v <= 8999999999999999
713 + // 0 <= (v % 1e14) <= 99999999999999
714 + c.push(v % 1e14);
715 + i += 2;
716 + }
717 + }
718 + i = k / 2;
719 +
720 + // Node.js supporting crypto.randomBytes.
721 + } else if (crypto.randomBytes) {
722 +
723 + // buffer
724 + a = crypto.randomBytes(k *= 7);
725 +
726 + for (; i < k;) {
727 +
728 + // 0x1000000000000 is 2^48, 0x10000000000 is 2^40
729 + // 0x100000000 is 2^32, 0x1000000 is 2^24
730 + // 11111 11111111 11111111 11111111 11111111 11111111 11111111
731 + // 0 <= v < 9007199254740992
732 + v = ((a[i] & 31) * 0x1000000000000) + (a[i + 1] * 0x10000000000) +
733 + (a[i + 2] * 0x100000000) + (a[i + 3] * 0x1000000) +
734 + (a[i + 4] << 16) + (a[i + 5] << 8) + a[i + 6];
735 +
736 + if (v >= 9e15) {
737 + crypto.randomBytes(7).copy(a, i);
738 + } else {
739 +
740 + // 0 <= (v % 1e14) <= 99999999999999
741 + c.push(v % 1e14);
742 + i += 7;
743 + }
744 + }
745 + i = k / 7;
746 + } else {
747 + CRYPTO = false;
748 + throw Error
749 + (bignumberError + 'crypto unavailable');
750 + }
751 + }
752 +
753 + // Use Math.random.
754 + if (!CRYPTO) {
755 +
756 + for (; i < k;) {
757 + v = random53bitInt();
758 + if (v < 9e15) c[i++] = v % 1e14;
759 + }
760 + }
761 +
762 + k = c[--i];
763 + dp %= LOG_BASE;
764 +
765 + // Convert trailing digits to zeros according to dp.
766 + if (k && dp) {
767 + v = POWS_TEN[LOG_BASE - dp];
768 + c[i] = mathfloor(k / v) * v;
769 + }
770 +
771 + // Remove trailing elements which are zero.
772 + for (; c[i] === 0; c.pop(), i--);
773 +
774 + // Zero?
775 + if (i < 0) {
776 + c = [e = 0];
777 + } else {
778 +
779 + // Remove leading elements which are zero and adjust exponent accordingly.
780 + for (e = -1 ; c[0] === 0; c.splice(0, 1), e -= LOG_BASE);
781 +
782 + // Count the digits of the first element of c to determine leading zeros, and...
783 + for (i = 1, v = c[0]; v >= 10; v /= 10, i++);
784 +
785 + // adjust the exponent accordingly.
786 + if (i < LOG_BASE) e -= LOG_BASE - i;
787 + }
788 +
789 + rand.e = e;
790 + rand.c = c;
791 + return rand;
792 + };
793 + })();
794 +
795 +
796 + /*
797 + * Return a BigNumber whose value is the sum of the arguments.
798 + *
799 + * arguments {number|string|BigNumber}
800 + */
801 + BigNumber.sum = function () {
802 + var i = 1,
803 + args = arguments,
804 + sum = new BigNumber(args[0]);
805 + for (; i < args.length;) sum = sum.plus(args[i++]);
806 + return sum;
807 + };
808 +
809 +
810 + // PRIVATE FUNCTIONS
811 +
812 +
813 + // Called by BigNumber and BigNumber.prototype.toString.
814 + convertBase = (function () {
815 + var decimal = '0123456789';
816 +
817 + /*
818 + * Convert string of baseIn to an array of numbers of baseOut.
819 + * Eg. toBaseOut('255', 10, 16) returns [15, 15].
820 + * Eg. toBaseOut('ff', 16, 10) returns [2, 5, 5].
821 + */
822 + function toBaseOut(str, baseIn, baseOut, alphabet) {
823 + var j,
824 + arr = [0],
825 + arrL,
826 + i = 0,
827 + len = str.length;
828 +
829 + for (; i < len;) {
830 + for (arrL = arr.length; arrL--; arr[arrL] *= baseIn);
831 +
832 + arr[0] += alphabet.indexOf(str.charAt(i++));
833 +
834 + for (j = 0; j < arr.length; j++) {
835 +
836 + if (arr[j] > baseOut - 1) {
837 + if (arr[j + 1] == null) arr[j + 1] = 0;
838 + arr[j + 1] += arr[j] / baseOut | 0;
839 + arr[j] %= baseOut;
840 + }
841 + }
842 + }
843 +
844 + return arr.reverse();
845 + }
846 +
847 + // Convert a numeric string of baseIn to a numeric string of baseOut.
848 + // If the caller is toString, we are converting from base 10 to baseOut.
849 + // If the caller is BigNumber, we are converting from baseIn to base 10.
850 + return function (str, baseIn, baseOut, sign, callerIsToString) {
851 + var alphabet, d, e, k, r, x, xc, y,
852 + i = str.indexOf('.'),
853 + dp = DECIMAL_PLACES,
854 + rm = ROUNDING_MODE;
855 +
856 + // Non-integer.
857 + if (i >= 0) {
858 + k = POW_PRECISION;
859 +
860 + // Unlimited precision.
861 + POW_PRECISION = 0;
862 + str = str.replace('.', '');
863 + y = new BigNumber(baseIn);
864 + x = y.pow(str.length - i);
865 + POW_PRECISION = k;
866 +
867 + // Convert str as if an integer, then restore the fraction part by dividing the
868 + // result by its base raised to a power.
869 +
870 + y.c = toBaseOut(toFixedPoint(coeffToString(x.c), x.e, '0'),
871 + 10, baseOut, decimal);
872 + y.e = y.c.length;
873 + }
874 +
875 + // Convert the number as integer.
876 +
877 + xc = toBaseOut(str, baseIn, baseOut, callerIsToString
878 + ? (alphabet = ALPHABET, decimal)
879 + : (alphabet = decimal, ALPHABET));
880 +
881 + // xc now represents str as an integer and converted to baseOut. e is the exponent.
882 + e = k = xc.length;
883 +
884 + // Remove trailing zeros.
885 + for (; xc[--k] == 0; xc.pop());
886 +
887 + // Zero?
888 + if (!xc[0]) return alphabet.charAt(0);
889 +
890 + // Does str represent an integer? If so, no need for the division.
891 + if (i < 0) {
892 + --e;
893 + } else {
894 + x.c = xc;
895 + x.e = e;
896 +
897 + // The sign is needed for correct rounding.
898 + x.s = sign;
899 + x = div(x, y, dp, rm, baseOut);
900 + xc = x.c;
901 + r = x.r;
902 + e = x.e;
903 + }
904 +
905 + // xc now represents str converted to baseOut.
906 +
907 + // THe index of the rounding digit.
908 + d = e + dp + 1;
909 +
910 + // The rounding digit: the digit to the right of the digit that may be rounded up.
911 + i = xc[d];
912 +
913 + // Look at the rounding digits and mode to determine whether to round up.
914 +
915 + k = baseOut / 2;
916 + r = r || d < 0 || xc[d + 1] != null;
917 +
918 + r = rm < 4 ? (i != null || r) && (rm == 0 || rm == (x.s < 0 ? 3 : 2))
919 + : i > k || i == k &&(rm == 4 || r || rm == 6 && xc[d - 1] & 1 ||
920 + rm == (x.s < 0 ? 8 : 7));
921 +
922 + // If the index of the rounding digit is not greater than zero, or xc represents
923 + // zero, then the result of the base conversion is zero or, if rounding up, a value
924 + // such as 0.00001.
925 + if (d < 1 || !xc[0]) {
926 +
927 + // 1^-dp or 0
928 + str = r ? toFixedPoint(alphabet.charAt(1), -dp, alphabet.charAt(0)) : alphabet.charAt(0);
929 + } else {
930 +
931 + // Truncate xc to the required number of decimal places.
932 + xc.length = d;
933 +
934 + // Round up?
935 + if (r) {
936 +
937 + // Rounding up may mean the previous digit has to be rounded up and so on.
938 + for (--baseOut; ++xc[--d] > baseOut;) {
939 + xc[d] = 0;
940 +
941 + if (!d) {
942 + ++e;
943 + xc = [1].concat(xc);
944 + }
945 + }
946 + }
947 +
948 + // Determine trailing zeros.
949 + for (k = xc.length; !xc[--k];);
950 +
951 + // E.g. [4, 11, 15] becomes 4bf.
952 + for (i = 0, str = ''; i <= k; str += alphabet.charAt(xc[i++]));
953 +
954 + // Add leading zeros, decimal point and trailing zeros as required.
955 + str = toFixedPoint(str, e, alphabet.charAt(0));
956 + }
957 +
958 + // The caller will add the sign.
959 + return str;
960 + };
961 + })();
962 +
963 +
964 + // Perform division in the specified base. Called by div and convertBase.
965 + div = (function () {
966 +
967 + // Assume non-zero x and k.
968 + function multiply(x, k, base) {
969 + var m, temp, xlo, xhi,
970 + carry = 0,
971 + i = x.length,
972 + klo = k % SQRT_BASE,
973 + khi = k / SQRT_BASE | 0;
974 +
975 + for (x = x.slice(); i--;) {
976 + xlo = x[i] % SQRT_BASE;
977 + xhi = x[i] / SQRT_BASE | 0;
978 + m = khi * xlo + xhi * klo;
979 + temp = klo * xlo + ((m % SQRT_BASE) * SQRT_BASE) + carry;
980 + carry = (temp / base | 0) + (m / SQRT_BASE | 0) + khi * xhi;
981 + x[i] = temp % base;
982 + }
983 +
984 + if (carry) x = [carry].concat(x);
985 +
986 + return x;
987 + }
988 +
989 + function compare(a, b, aL, bL) {
990 + var i, cmp;
991 +
992 + if (aL != bL) {
993 + cmp = aL > bL ? 1 : -1;
994 + } else {
995 +
996 + for (i = cmp = 0; i < aL; i++) {
997 +
998 + if (a[i] != b[i]) {
999 + cmp = a[i] > b[i] ? 1 : -1;
1000 + break;
1001 + }
1002 + }
1003 + }
1004 +
1005 + return cmp;
1006 + }
1007 +
1008 + function subtract(a, b, aL, base) {
1009 + var i = 0;
1010 +
1011 + // Subtract b from a.
1012 + for (; aL--;) {
1013 + a[aL] -= i;
1014 + i = a[aL] < b[aL] ? 1 : 0;
1015 + a[aL] = i * base + a[aL] - b[aL];
1016 + }
1017 +
1018 + // Remove leading zeros.
1019 + for (; !a[0] && a.length > 1; a.splice(0, 1));
1020 + }
1021 +
1022 + // x: dividend, y: divisor.
1023 + return function (x, y, dp, rm, base) {
1024 + var cmp, e, i, more, n, prod, prodL, q, qc, rem, remL, rem0, xi, xL, yc0,
1025 + yL, yz,
1026 + s = x.s == y.s ? 1 : -1,
1027 + xc = x.c,
1028 + yc = y.c;
1029 +
1030 + // Either NaN, Infinity or 0?
1031 + if (!xc || !xc[0] || !yc || !yc[0]) {
1032 +
1033 + return new BigNumber(
1034 +
1035 + // Return NaN if either NaN, or both Infinity or 0.
1036 + !x.s || !y.s || (xc ? yc && xc[0] == yc[0] : !yc) ? NaN :
1037 +
1038 + // Return ±0 if x is ±0 or y is ±Infinity, or return ±Infinity as y is ±0.
1039 + xc && xc[0] == 0 || !yc ? s * 0 : s / 0
1040 + );
1041 + }
1042 +
1043 + q = new BigNumber(s);
1044 + qc = q.c = [];
1045 + e = x.e - y.e;
1046 + s = dp + e + 1;
1047 +
1048 + if (!base) {
1049 + base = BASE;
1050 + e = bitFloor(x.e / LOG_BASE) - bitFloor(y.e / LOG_BASE);
1051 + s = s / LOG_BASE | 0;
1052 + }
1053 +
1054 + // Result exponent may be one less then the current value of e.
1055 + // The coefficients of the BigNumbers from convertBase may have trailing zeros.
1056 + for (i = 0; yc[i] == (xc[i] || 0); i++);
1057 +
1058 + if (yc[i] > (xc[i] || 0)) e--;
1059 +
1060 + if (s < 0) {
1061 + qc.push(1);
1062 + more = true;
1063 + } else {
1064 + xL = xc.length;
1065 + yL = yc.length;
1066 + i = 0;
1067 + s += 2;
1068 +
1069 + // Normalise xc and yc so highest order digit of yc is >= base / 2.
1070 +
1071 + n = mathfloor(base / (yc[0] + 1));
1072 +
1073 + // Not necessary, but to handle odd bases where yc[0] == (base / 2) - 1.
1074 + // if (n > 1 || n++ == 1 && yc[0] < base / 2) {
1075 + if (n > 1) {
1076 + yc = multiply(yc, n, base);
1077 + xc = multiply(xc, n, base);
1078 + yL = yc.length;
1079 + xL = xc.length;
1080 + }
1081 +
1082 + xi = yL;
1083 + rem = xc.slice(0, yL);
1084 + remL = rem.length;
1085 +
1086 + // Add zeros to make remainder as long as divisor.
1087 + for (; remL < yL; rem[remL++] = 0);
1088 + yz = yc.slice();
1089 + yz = [0].concat(yz);
1090 + yc0 = yc[0];
1091 + if (yc[1] >= base / 2) yc0++;
1092 + // Not necessary, but to prevent trial digit n > base, when using base 3.
1093 + // else if (base == 3 && yc0 == 1) yc0 = 1 + 1e-15;
1094 +
1095 + do {
1096 + n = 0;
1097 +
1098 + // Compare divisor and remainder.
1099 + cmp = compare(yc, rem, yL, remL);
1100 +
1101 + // If divisor < remainder.
1102 + if (cmp < 0) {
1103 +
1104 + // Calculate trial digit, n.
1105 +
1106 + rem0 = rem[0];
1107 + if (yL != remL) rem0 = rem0 * base + (rem[1] || 0);
1108 +
1109 + // n is how many times the divisor goes into the current remainder.
1110 + n = mathfloor(rem0 / yc0);
1111 +
1112 + // Algorithm:
1113 + // product = divisor multiplied by trial digit (n).
1114 + // Compare product and remainder.
1115 + // If product is greater than remainder:
1116 + // Subtract divisor from product, decrement trial digit.
1117 + // Subtract product from remainder.
1118 + // If product was less than remainder at the last compare:
1119 + // Compare new remainder and divisor.
1120 + // If remainder is greater than divisor:
1121 + // Subtract divisor from remainder, increment trial digit.
1122 +
1123 + if (n > 1) {
1124 +
1125 + // n may be > base only when base is 3.
1126 + if (n >= base) n = base - 1;
1127 +
1128 + // product = divisor * trial digit.
1129 + prod = multiply(yc, n, base);
1130 + prodL = prod.length;
1131 + remL = rem.length;
1132 +
1133 + // Compare product and remainder.
1134 + // If product > remainder then trial digit n too high.
1135 + // n is 1 too high about 5% of the time, and is not known to have
1136 + // ever been more than 1 too high.
1137 + while (compare(prod, rem, prodL, remL) == 1) {
1138 + n--;
1139 +
1140 + // Subtract divisor from product.
1141 + subtract(prod, yL < prodL ? yz : yc, prodL, base);
1142 + prodL = prod.length;
1143 + cmp = 1;
1144 + }
1145 + } else {
1146 +
1147 + // n is 0 or 1, cmp is -1.
1148 + // If n is 0, there is no need to compare yc and rem again below,
1149 + // so change cmp to 1 to avoid it.
1150 + // If n is 1, leave cmp as -1, so yc and rem are compared again.
1151 + if (n == 0) {
1152 +
1153 + // divisor < remainder, so n must be at least 1.
1154 + cmp = n = 1;
1155 + }
1156 +
1157 + // product = divisor
1158 + prod = yc.slice();
1159 + prodL = prod.length;
1160 + }
1161 +
1162 + if (prodL < remL) prod = [0].concat(prod);
1163 +
1164 + // Subtract product from remainder.
1165 + subtract(rem, prod, remL, base);
1166 + remL = rem.length;
1167 +
1168 + // If product was < remainder.
1169 + if (cmp == -1) {
1170 +
1171 + // Compare divisor and new remainder.
1172 + // If divisor < new remainder, subtract divisor from remainder.
1173 + // Trial digit n too low.
1174 + // n is 1 too low about 5% of the time, and very rarely 2 too low.
1175 + while (compare(yc, rem, yL, remL) < 1) {
1176 + n++;
1177 +
1178 + // Subtract divisor from remainder.
1179 + subtract(rem, yL < remL ? yz : yc, remL, base);
1180 + remL = rem.length;
1181 + }
1182 + }
1183 + } else if (cmp === 0) {
1184 + n++;
1185 + rem = [0];
1186 + } // else cmp === 1 and n will be 0
1187 +
1188 + // Add the next digit, n, to the result array.
1189 + qc[i++] = n;
1190 +
1191 + // Update the remainder.
1192 + if (rem[0]) {
1193 + rem[remL++] = xc[xi] || 0;
1194 + } else {
1195 + rem = [xc[xi]];
1196 + remL = 1;
1197 + }
1198 + } while ((xi++ < xL || rem[0] != null) && s--);
1199 +
1200 + more = rem[0] != null;
1201 +
1202 + // Leading zero?
1203 + if (!qc[0]) qc.splice(0, 1);
1204 + }
1205 +
1206 + if (base == BASE) {
1207 +
1208 + // To calculate q.e, first get the number of digits of qc[0].
1209 + for (i = 1, s = qc[0]; s >= 10; s /= 10, i++);
1210 +
1211 + round(q, dp + (q.e = i + e * LOG_BASE - 1) + 1, rm, more);
1212 +
1213 + // Caller is convertBase.
1214 + } else {
1215 + q.e = e;
1216 + q.r = +more;
1217 + }
1218 +
1219 + return q;
1220 + };
1221 + })();
1222 +
1223 +
1224 + /*
1225 + * Return a string representing the value of BigNumber n in fixed-point or exponential
1226 + * notation rounded to the specified decimal places or significant digits.
1227 + *
1228 + * n: a BigNumber.
1229 + * i: the index of the last digit required (i.e. the digit that may be rounded up).
1230 + * rm: the rounding mode.
1231 + * id: 1 (toExponential) or 2 (toPrecision).
1232 + */
1233 + function format(n, i, rm, id) {
1234 + var c0, e, ne, len, str;
1235 +
1236 + if (rm == null) rm = ROUNDING_MODE;
1237 + else intCheck(rm, 0, 8);
1238 +
1239 + if (!n.c) return n.toString();
1240 +
1241 + c0 = n.c[0];
1242 + ne = n.e;
1243 +
1244 + if (i == null) {
1245 + str = coeffToString(n.c);
1246 + str = id == 1 || id == 2 && (ne <= TO_EXP_NEG || ne >= TO_EXP_POS)
1247 + ? toExponential(str, ne)
1248 + : toFixedPoint(str, ne, '0');
1249 + } else {
1250 + n = round(new BigNumber(n), i, rm);
1251 +
1252 + // n.e may have changed if the value was rounded up.
1253 + e = n.e;
1254 +
1255 + str = coeffToString(n.c);
1256 + len = str.length;
1257 +
1258 + // toPrecision returns exponential notation if the number of significant digits
1259 + // specified is less than the number of digits necessary to represent the integer
1260 + // part of the value in fixed-point notation.
1261 +
1262 + // Exponential notation.
1263 + if (id == 1 || id == 2 && (i <= e || e <= TO_EXP_NEG)) {
1264 +
1265 + // Append zeros?
1266 + for (; len < i; str += '0', len++);
1267 + str = toExponential(str, e);
1268 +
1269 + // Fixed-point notation.
1270 + } else {
1271 + i -= ne;
1272 + str = toFixedPoint(str, e, '0');
1273 +
1274 + // Append zeros?
1275 + if (e + 1 > len) {
1276 + if (--i > 0) for (str += '.'; i--; str += '0');
1277 + } else {
1278 + i += e - len;
1279 + if (i > 0) {
1280 + if (e + 1 == len) str += '.';
1281 + for (; i--; str += '0');
1282 + }
1283 + }
1284 + }
1285 + }
1286 +
1287 + return n.s < 0 && c0 ? '-' + str : str;
1288 + }
1289 +
1290 +
1291 + // Handle BigNumber.max and BigNumber.min.
1292 + function maxOrMin(args, method) {
1293 + var n,
1294 + i = 1,
1295 + m = new BigNumber(args[0]);
1296 +
1297 + for (; i < args.length; i++) {
1298 + n = new BigNumber(args[i]);
1299 +
1300 + // If any number is NaN, return NaN.
1301 + if (!n.s) {
1302 + m = n;
1303 + break;
1304 + } else if (method.call(m, n)) {
1305 + m = n;
1306 + }
1307 + }
1308 +
1309 + return m;
1310 + }
1311 +
1312 +
1313 + /*
1314 + * Strip trailing zeros, calculate base 10 exponent and check against MIN_EXP and MAX_EXP.
1315 + * Called by minus, plus and times.
1316 + */
1317 + function normalise(n, c, e) {
1318 + var i = 1,
1319 + j = c.length;
1320 +
1321 + // Remove trailing zeros.
1322 + for (; !c[--j]; c.pop());
1323 +
1324 + // Calculate the base 10 exponent. First get the number of digits of c[0].
1325 + for (j = c[0]; j >= 10; j /= 10, i++);
1326 +
1327 + // Overflow?
1328 + if ((e = i + e * LOG_BASE - 1) > MAX_EXP) {
1329 +
1330 + // Infinity.
1331 + n.c = n.e = null;
1332 +
1333 + // Underflow?
1334 + } else if (e < MIN_EXP) {
1335 +
1336 + // Zero.
1337 + n.c = [n.e = 0];
1338 + } else {
1339 + n.e = e;
1340 + n.c = c;
1341 + }
1342 +
1343 + return n;
1344 + }
1345 +
1346 +
1347 + // Handle values that fail the validity test in BigNumber.
1348 + parseNumeric = (function () {
1349 + var basePrefix = /^(-?)0([xbo])(?=\w[\w.]*$)/i,
1350 + dotAfter = /^([^.]+)\.$/,
1351 + dotBefore = /^\.([^.]+)$/,
1352 + isInfinityOrNaN = /^-?(Infinity|NaN)$/,
1353 + whitespaceOrPlus = /^\s*\+(?=[\w.])|^\s+|\s+$/g;
1354 +
1355 + return function (x, str, isNum, b) {
1356 + var base,
1357 + s = isNum ? str : str.replace(whitespaceOrPlus, '');
1358 +
1359 + // No exception on ±Infinity or NaN.
1360 + if (isInfinityOrNaN.test(s)) {
1361 + x.s = isNaN(s) ? null : s < 0 ? -1 : 1;
1362 + } else {
1363 + if (!isNum) {
1364 +
1365 + // basePrefix = /^(-?)0([xbo])(?=\w[\w.]*$)/i
1366 + s = s.replace(basePrefix, function (m, p1, p2) {
1367 + base = (p2 = p2.toLowerCase()) == 'x' ? 16 : p2 == 'b' ? 2 : 8;
1368 + return !b || b == base ? p1 : m;
1369 + });
1370 +
1371 + if (b) {
1372 + base = b;
1373 +
1374 + // E.g. '1.' to '1', '.1' to '0.1'
1375 + s = s.replace(dotAfter, '$1').replace(dotBefore, '0.$1');
1376 + }
1377 +
1378 + if (str != s) return new BigNumber(s, base);
1379 + }
1380 +
1381 + // '[BigNumber Error] Not a number: {n}'
1382 + // '[BigNumber Error] Not a base {b} number: {n}'
1383 + if (BigNumber.DEBUG) {
1384 + throw Error
1385 + (bignumberError + 'Not a' + (b ? ' base ' + b : '') + ' number: ' + str);
1386 + }
1387 +
1388 + // NaN
1389 + x.s = null;
1390 + }
1391 +
1392 + x.c = x.e = null;
1393 + }
1394 + })();
1395 +
1396 +
1397 + /*
1398 + * Round x to sd significant digits using rounding mode rm. Check for over/under-flow.
1399 + * If r is truthy, it is known that there are more digits after the rounding digit.
1400 + */
1401 + function round(x, sd, rm, r) {
1402 + var d, i, j, k, n, ni, rd,
1403 + xc = x.c,
1404 + pows10 = POWS_TEN;
1405 +
1406 + // if x is not Infinity or NaN...
1407 + if (xc) {
1408 +
1409 + // rd is the rounding digit, i.e. the digit after the digit that may be rounded up.
1410 + // n is a base 1e14 number, the value of the element of array x.c containing rd.
1411 + // ni is the index of n within x.c.
1412 + // d is the number of digits of n.
1413 + // i is the index of rd within n including leading zeros.
1414 + // j is the actual index of rd within n (if < 0, rd is a leading zero).
1415 + out: {
1416 +
1417 + // Get the number of digits of the first element of xc.
1418 + for (d = 1, k = xc[0]; k >= 10; k /= 10, d++);
1419 + i = sd - d;
1420 +
1421 + // If the rounding digit is in the first element of xc...
1422 + if (i < 0) {
1423 + i += LOG_BASE;
1424 + j = sd;
1425 + n = xc[ni = 0];
1426 +
1427 + // Get the rounding digit at index j of n.
1428 + rd = n / pows10[d - j - 1] % 10 | 0;
1429 + } else {
1430 + ni = mathceil((i + 1) / LOG_BASE);
1431 +
1432 + if (ni >= xc.length) {
1433 +
1434 + if (r) {
1435 +
1436 + // Needed by sqrt.
1437 + for (; xc.length <= ni; xc.push(0));
1438 + n = rd = 0;
1439 + d = 1;
1440 + i %= LOG_BASE;
1441 + j = i - LOG_BASE + 1;
1442 + } else {
1443 + break out;
1444 + }
1445 + } else {
1446 + n = k = xc[ni];
1447 +
1448 + // Get the number of digits of n.
1449 + for (d = 1; k >= 10; k /= 10, d++);
1450 +
1451 + // Get the index of rd within n.
1452 + i %= LOG_BASE;
1453 +
1454 + // Get the index of rd within n, adjusted for leading zeros.
1455 + // The number of leading zeros of n is given by LOG_BASE - d.
1456 + j = i - LOG_BASE + d;
1457 +
1458 + // Get the rounding digit at index j of n.
1459 + rd = j < 0 ? 0 : n / pows10[d - j - 1] % 10 | 0;
1460 + }
1461 + }
1462 +
1463 + r = r || sd < 0 ||
1464 +
1465 + // Are there any non-zero digits after the rounding digit?
1466 + // The expression n % pows10[d - j - 1] returns all digits of n to the right
1467 + // of the digit at j, e.g. if n is 908714 and j is 2, the expression gives 714.
1468 + xc[ni + 1] != null || (j < 0 ? n : n % pows10[d - j - 1]);
1469 +
1470 + r = rm < 4
1471 + ? (rd || r) && (rm == 0 || rm == (x.s < 0 ? 3 : 2))
1472 + : rd > 5 || rd == 5 && (rm == 4 || r || rm == 6 &&
1473 +
1474 + // Check whether the digit to the left of the rounding digit is odd.
1475 + ((i > 0 ? j > 0 ? n / pows10[d - j] : 0 : xc[ni - 1]) % 10) & 1 ||
1476 + rm == (x.s < 0 ? 8 : 7));
1477 +
1478 + if (sd < 1 || !xc[0]) {
1479 + xc.length = 0;
1480 +
1481 + if (r) {
1482 +
1483 + // Convert sd to decimal places.
1484 + sd -= x.e + 1;
1485 +
1486 + // 1, 0.1, 0.01, 0.001, 0.0001 etc.
1487 + xc[0] = pows10[(LOG_BASE - sd % LOG_BASE) % LOG_BASE];
1488 + x.e = -sd || 0;
1489 + } else {
1490 +
1491 + // Zero.
1492 + xc[0] = x.e = 0;
1493 + }
1494 +
1495 + return x;
1496 + }
1497 +
1498 + // Remove excess digits.
1499 + if (i == 0) {
1500 + xc.length = ni;
1501 + k = 1;
1502 + ni--;
1503 + } else {
1504 + xc.length = ni + 1;
1505 + k = pows10[LOG_BASE - i];
1506 +
1507 + // E.g. 56700 becomes 56000 if 7 is the rounding digit.
1508 + // j > 0 means i > number of leading zeros of n.
1509 + xc[ni] = j > 0 ? mathfloor(n / pows10[d - j] % pows10[j]) * k : 0;
1510 + }
1511 +
1512 + // Round up?
1513 + if (r) {
1514 +
1515 + for (; ;) {
1516 +
1517 + // If the digit to be rounded up is in the first element of xc...
1518 + if (ni == 0) {
1519 +
1520 + // i will be the length of xc[0] before k is added.
1521 + for (i = 1, j = xc[0]; j >= 10; j /= 10, i++);
1522 + j = xc[0] += k;
1523 + for (k = 1; j >= 10; j /= 10, k++);
1524 +
1525 + // if i != k the length has increased.
1526 + if (i != k) {
1527 + x.e++;
1528 + if (xc[0] == BASE) xc[0] = 1;
1529 + }
1530 +
1531 + break;
1532 + } else {
1533 + xc[ni] += k;
1534 + if (xc[ni] != BASE) break;
1535 + xc[ni--] = 0;
1536 + k = 1;
1537 + }
1538 + }
1539 + }
1540 +
1541 + // Remove trailing zeros.
1542 + for (i = xc.length; xc[--i] === 0; xc.pop());
1543 + }
1544 +
1545 + // Overflow? Infinity.
1546 + if (x.e > MAX_EXP) {
1547 + x.c = x.e = null;
1548 +
1549 + // Underflow? Zero.
1550 + } else if (x.e < MIN_EXP) {
1551 + x.c = [x.e = 0];
1552 + }
1553 + }
1554 +
1555 + return x;
1556 + }
1557 +
1558 +
1559 + function valueOf(n) {
1560 + var str,
1561 + e = n.e;
1562 +
1563 + if (e === null) return n.toString();
1564 +
1565 + str = coeffToString(n.c);
1566 +
1567 + str = e <= TO_EXP_NEG || e >= TO_EXP_POS
1568 + ? toExponential(str, e)
1569 + : toFixedPoint(str, e, '0');
1570 +
1571 + return n.s < 0 ? '-' + str : str;
1572 + }
1573 +
1574 +
1575 + // PROTOTYPE/INSTANCE METHODS
1576 +
1577 +
1578 + /*
1579 + * Return a new BigNumber whose value is the absolute value of this BigNumber.
1580 + */
1581 + P.absoluteValue = P.abs = function () {
1582 + var x = new BigNumber(this);
1583 + if (x.s < 0) x.s = 1;
1584 + return x;
1585 + };
1586 +
1587 +
1588 + /*
1589 + * Return
1590 + * 1 if the value of this BigNumber is greater than the value of BigNumber(y, b),
1591 + * -1 if the value of this BigNumber is less than the value of BigNumber(y, b),
1592 + * 0 if they have the same value,
1593 + * or null if the value of either is NaN.
1594 + */
1595 + P.comparedTo = function (y, b) {
1596 + return compare(this, new BigNumber(y, b));
1597 + };
1598 +
1599 +
1600 + /*
1601 + * If dp is undefined or null or true or false, return the number of decimal places of the
1602 + * value of this BigNumber, or null if the value of this BigNumber is ±Infinity or NaN.
1603 + *
1604 + * Otherwise, if dp is a number, return a new BigNumber whose value is the value of this
1605 + * BigNumber rounded to a maximum of dp decimal places using rounding mode rm, or
1606 + * ROUNDING_MODE if rm is omitted.
1607 + *
1608 + * [dp] {number} Decimal places: integer, 0 to MAX inclusive.
1609 + * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
1610 + *
1611 + * '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {dp|rm}'
1612 + */
1613 + P.decimalPlaces = P.dp = function (dp, rm) {
1614 + var c, n, v,
1615 + x = this;
1616 +
1617 + if (dp != null) {
1618 + intCheck(dp, 0, MAX);
1619 + if (rm == null) rm = ROUNDING_MODE;
1620 + else intCheck(rm, 0, 8);
1621 +
1622 + return round(new BigNumber(x), dp + x.e + 1, rm);
1623 + }
1624 +
1625 + if (!(c = x.c)) return null;
1626 + n = ((v = c.length - 1) - bitFloor(this.e / LOG_BASE)) * LOG_BASE;
1627 +
1628 + // Subtract the number of trailing zeros of the last number.
1629 + if (v = c[v]) for (; v % 10 == 0; v /= 10, n--);
1630 + if (n < 0) n = 0;
1631 +
1632 + return n;
1633 + };
1634 +
1635 +
1636 + /*
1637 + * n / 0 = I
1638 + * n / N = N
1639 + * n / I = 0
1640 + * 0 / n = 0
1641 + * 0 / 0 = N
1642 + * 0 / N = N
1643 + * 0 / I = 0
1644 + * N / n = N
1645 + * N / 0 = N
1646 + * N / N = N
1647 + * N / I = N
1648 + * I / n = I
1649 + * I / 0 = I
1650 + * I / N = N
1651 + * I / I = N
1652 + *
1653 + * Return a new BigNumber whose value is the value of this BigNumber divided by the value of
1654 + * BigNumber(y, b), rounded according to DECIMAL_PLACES and ROUNDING_MODE.
1655 + */
1656 + P.dividedBy = P.div = function (y, b) {
1657 + return div(this, new BigNumber(y, b), DECIMAL_PLACES, ROUNDING_MODE);
1658 + };
1659 +
1660 +
1661 + /*
1662 + * Return a new BigNumber whose value is the integer part of dividing the value of this
1663 + * BigNumber by the value of BigNumber(y, b).
1664 + */
1665 + P.dividedToIntegerBy = P.idiv = function (y, b) {
1666 + return div(this, new BigNumber(y, b), 0, 1);
1667 + };
1668 +
1669 +
1670 + /*
1671 + * Return a BigNumber whose value is the value of this BigNumber exponentiated by n.
1672 + *
1673 + * If m is present, return the result modulo m.
1674 + * If n is negative round according to DECIMAL_PLACES and ROUNDING_MODE.
1675 + * If POW_PRECISION is non-zero and m is not present, round to POW_PRECISION using ROUNDING_MODE.
1676 + *
1677 + * The modular power operation works efficiently when x, n, and m are integers, otherwise it
1678 + * is equivalent to calculating x.exponentiatedBy(n).modulo(m) with a POW_PRECISION of 0.
1679 + *
1680 + * n {number|string|BigNumber} The exponent. An integer.
1681 + * [m] {number|string|BigNumber} The modulus.
1682 + *
1683 + * '[BigNumber Error] Exponent not an integer: {n}'
1684 + */
1685 + P.exponentiatedBy = P.pow = function (n, m) {
1686 + var half, isModExp, i, k, more, nIsBig, nIsNeg, nIsOdd, y,
1687 + x = this;
1688 +
1689 + n = new BigNumber(n);
1690 +
1691 + // Allow NaN and ±Infinity, but not other non-integers.
1692 + if (n.c && !n.isInteger()) {
1693 + throw Error
1694 + (bignumberError + 'Exponent not an integer: ' + valueOf(n));
1695 + }
1696 +
1697 + if (m != null) m = new BigNumber(m);
1698 +
1699 + // Exponent of MAX_SAFE_INTEGER is 15.
1700 + nIsBig = n.e > 14;
1701 +
1702 + // If x is NaN, ±Infinity, ±0 or ±1, or n is ±Infinity, NaN or ±0.
1703 + if (!x.c || !x.c[0] || x.c[0] == 1 && !x.e && x.c.length == 1 || !n.c || !n.c[0]) {
1704 +
1705 + // The sign of the result of pow when x is negative depends on the evenness of n.
1706 + // If +n overflows to ±Infinity, the evenness of n would be not be known.
1707 + y = new BigNumber(Math.pow(+valueOf(x), nIsBig ? 2 - isOdd(n) : +valueOf(n)));
1708 + return m ? y.mod(m) : y;
1709 + }
1710 +
1711 + nIsNeg = n.s < 0;
1712 +
1713 + if (m) {
1714 +
1715 + // x % m returns NaN if abs(m) is zero, or m is NaN.
1716 + if (m.c ? !m.c[0] : !m.s) return new BigNumber(NaN);
1717 +
1718 + isModExp = !nIsNeg && x.isInteger() && m.isInteger();
1719 +
1720 + if (isModExp) x = x.mod(m);
1721 +
1722 + // Overflow to ±Infinity: >=2**1e10 or >=1.0000024**1e15.
1723 + // Underflow to ±0: <=0.79**1e10 or <=0.9999975**1e15.
1724 + } else if (n.e > 9 && (x.e > 0 || x.e < -1 || (x.e == 0
1725 + // [1, 240000000]
1726 + ? x.c[0] > 1 || nIsBig && x.c[1] >= 24e7
1727 + // [80000000000000] [99999750000000]
1728 + : x.c[0] < 8e13 || nIsBig && x.c[0] <= 9999975e7))) {
1729 +
1730 + // If x is negative and n is odd, k = -0, else k = 0.
1731 + k = x.s < 0 && isOdd(n) ? -0 : 0;
1732 +
1733 + // If x >= 1, k = ±Infinity.
1734 + if (x.e > -1) k = 1 / k;
1735 +
1736 + // If n is negative return ±0, else return ±Infinity.
1737 + return new BigNumber(nIsNeg ? 1 / k : k);
1738 +
1739 + } else if (POW_PRECISION) {
1740 +
1741 + // Truncating each coefficient array to a length of k after each multiplication
1742 + // equates to truncating significant digits to POW_PRECISION + [28, 41],
1743 + // i.e. there will be a minimum of 28 guard digits retained.
1744 + k = mathceil(POW_PRECISION / LOG_BASE + 2);
1745 + }
1746 +
1747 + if (nIsBig) {
1748 + half = new BigNumber(0.5);
1749 + if (nIsNeg) n.s = 1;
1750 + nIsOdd = isOdd(n);
1751 + } else {
1752 + i = Math.abs(+valueOf(n));
1753 + nIsOdd = i % 2;
1754 + }
1755 +
1756 + y = new BigNumber(ONE);
1757 +
1758 + // Performs 54 loop iterations for n of 9007199254740991.
1759 + for (; ;) {
1760 +
1761 + if (nIsOdd) {
1762 + y = y.times(x);
1763 + if (!y.c) break;
1764 +
1765 + if (k) {
1766 + if (y.c.length > k) y.c.length = k;
1767 + } else if (isModExp) {
1768 + y = y.mod(m); //y = y.minus(div(y, m, 0, MODULO_MODE).times(m));
1769 + }
1770 + }
1771 +
1772 + if (i) {
1773 + i = mathfloor(i / 2);
1774 + if (i === 0) break;
1775 + nIsOdd = i % 2;
1776 + } else {
1777 + n = n.times(half);
1778 + round(n, n.e + 1, 1);
1779 +
1780 + if (n.e > 14) {
1781 + nIsOdd = isOdd(n);
1782 + } else {
1783 + i = +valueOf(n);
1784 + if (i === 0) break;
1785 + nIsOdd = i % 2;
1786 + }
1787 + }
1788 +
1789 + x = x.times(x);
1790 +
1791 + if (k) {
1792 + if (x.c && x.c.length > k) x.c.length = k;
1793 + } else if (isModExp) {
1794 + x = x.mod(m); //x = x.minus(div(x, m, 0, MODULO_MODE).times(m));
1795 + }
1796 + }
1797 +
1798 + if (isModExp) return y;
1799 + if (nIsNeg) y = ONE.div(y);
1800 +
1801 + return m ? y.mod(m) : k ? round(y, POW_PRECISION, ROUNDING_MODE, more) : y;
1802 + };
1803 +
1804 +
1805 + /*
1806 + * Return a new BigNumber whose value is the value of this BigNumber rounded to an integer
1807 + * using rounding mode rm, or ROUNDING_MODE if rm is omitted.
1808 + *
1809 + * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
1810 + *
1811 + * '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {rm}'
1812 + */
1813 + P.integerValue = function (rm) {
1814 + var n = new BigNumber(this);
1815 + if (rm == null) rm = ROUNDING_MODE;
1816 + else intCheck(rm, 0, 8);
1817 + return round(n, n.e + 1, rm);
1818 + };
1819 +
1820 +
1821 + /*
1822 + * Return true if the value of this BigNumber is equal to the value of BigNumber(y, b),
1823 + * otherwise return false.
1824 + */
1825 + P.isEqualTo = P.eq = function (y, b) {
1826 + return compare(this, new BigNumber(y, b)) === 0;
1827 + };
1828 +
1829 +
1830 + /*
1831 + * Return true if the value of this BigNumber is a finite number, otherwise return false.
1832 + */
1833 + P.isFinite = function () {
1834 + return !!this.c;
1835 + };
1836 +
1837 +
1838 + /*
1839 + * Return true if the value of this BigNumber is greater than the value of BigNumber(y, b),
1840 + * otherwise return false.
1841 + */
1842 + P.isGreaterThan = P.gt = function (y, b) {
1843 + return compare(this, new BigNumber(y, b)) > 0;
1844 + };
1845 +
1846 +
1847 + /*
1848 + * Return true if the value of this BigNumber is greater than or equal to the value of
1849 + * BigNumber(y, b), otherwise return false.
1850 + */
1851 + P.isGreaterThanOrEqualTo = P.gte = function (y, b) {
1852 + return (b = compare(this, new BigNumber(y, b))) === 1 || b === 0;
1853 +
1854 + };
1855 +
1856 +
1857 + /*
1858 + * Return true if the value of this BigNumber is an integer, otherwise return false.
1859 + */
1860 + P.isInteger = function () {
1861 + return !!this.c && bitFloor(this.e / LOG_BASE) > this.c.length - 2;
1862 + };
1863 +
1864 +
1865 + /*
1866 + * Return true if the value of this BigNumber is less than the value of BigNumber(y, b),
1867 + * otherwise return false.
1868 + */
1869 + P.isLessThan = P.lt = function (y, b) {
1870 + return compare(this, new BigNumber(y, b)) < 0;
1871 + };
1872 +
1873 +
1874 + /*
1875 + * Return true if the value of this BigNumber is less than or equal to the value of
1876 + * BigNumber(y, b), otherwise return false.
1877 + */
1878 + P.isLessThanOrEqualTo = P.lte = function (y, b) {
1879 + return (b = compare(this, new BigNumber(y, b))) === -1 || b === 0;
1880 + };
1881 +
1882 +
1883 + /*
1884 + * Return true if the value of this BigNumber is NaN, otherwise return false.
1885 + */
1886 + P.isNaN = function () {
1887 + return !this.s;
1888 + };
1889 +
1890 +
1891 + /*
1892 + * Return true if the value of this BigNumber is negative, otherwise return false.
1893 + */
1894 + P.isNegative = function () {
1895 + return this.s < 0;
1896 + };
1897 +
1898 +
1899 + /*
1900 + * Return true if the value of this BigNumber is positive, otherwise return false.
1901 + */
1902 + P.isPositive = function () {
1903 + return this.s > 0;
1904 + };
1905 +
1906 +
1907 + /*
1908 + * Return true if the value of this BigNumber is 0 or -0, otherwise return false.
1909 + */
1910 + P.isZero = function () {
1911 + return !!this.c && this.c[0] == 0;
1912 + };
1913 +
1914 +
1915 + /*
1916 + * n - 0 = n
1917 + * n - N = N
1918 + * n - I = -I
1919 + * 0 - n = -n
1920 + * 0 - 0 = 0
1921 + * 0 - N = N
1922 + * 0 - I = -I
1923 + * N - n = N
1924 + * N - 0 = N
1925 + * N - N = N
1926 + * N - I = N
1927 + * I - n = I
1928 + * I - 0 = I
1929 + * I - N = N
1930 + * I - I = N
1931 + *
1932 + * Return a new BigNumber whose value is the value of this BigNumber minus the value of
1933 + * BigNumber(y, b).
1934 + */
1935 + P.minus = function (y, b) {
1936 + var i, j, t, xLTy,
1937 + x = this,
1938 + a = x.s;
1939 +
1940 + y = new BigNumber(y, b);
1941 + b = y.s;
1942 +
1943 + // Either NaN?
1944 + if (!a || !b) return new BigNumber(NaN);
1945 +
1946 + // Signs differ?
1947 + if (a != b) {
1948 + y.s = -b;
1949 + return x.plus(y);
1950 + }
1951 +
1952 + var xe = x.e / LOG_BASE,
1953 + ye = y.e / LOG_BASE,
1954 + xc = x.c,
1955 + yc = y.c;
1956 +
1957 + if (!xe || !ye) {
1958 +
1959 + // Either Infinity?
1960 + if (!xc || !yc) return xc ? (y.s = -b, y) : new BigNumber(yc ? x : NaN);
1961 +
1962 + // Either zero?
1963 + if (!xc[0] || !yc[0]) {
1964 +
1965 + // Return y if y is non-zero, x if x is non-zero, or zero if both are zero.
1966 + return yc[0] ? (y.s = -b, y) : new BigNumber(xc[0] ? x :
1967 +
1968 + // IEEE 754 (2008) 6.3: n - n = -0 when rounding to -Infinity
1969 + ROUNDING_MODE == 3 ? -0 : 0);
1970 + }
1971 + }
1972 +
1973 + xe = bitFloor(xe);
1974 + ye = bitFloor(ye);
1975 + xc = xc.slice();
1976 +
1977 + // Determine which is the bigger number.
1978 + if (a = xe - ye) {
1979 +
1980 + if (xLTy = a < 0) {
1981 + a = -a;
1982 + t = xc;
1983 + } else {
1984 + ye = xe;
1985 + t = yc;
1986 + }
1987 +
1988 + t.reverse();
1989 +
1990 + // Prepend zeros to equalise exponents.
1991 + for (b = a; b--; t.push(0));
1992 + t.reverse();
1993 + } else {
1994 +
1995 + // Exponents equal. Check digit by digit.
1996 + j = (xLTy = (a = xc.length) < (b = yc.length)) ? a : b;
1997 +
1998 + for (a = b = 0; b < j; b++) {
1999 +
2000 + if (xc[b] != yc[b]) {
2001 + xLTy = xc[b] < yc[b];
2002 + break;
2003 + }
2004 + }
2005 + }
2006 +
2007 + // x < y? Point xc to the array of the bigger number.
2008 + if (xLTy) t = xc, xc = yc, yc = t, y.s = -y.s;
2009 +
2010 + b = (j = yc.length) - (i = xc.length);
2011 +
2012 + // Append zeros to xc if shorter.
2013 + // No need to add zeros to yc if shorter as subtract only needs to start at yc.length.
2014 + if (b > 0) for (; b--; xc[i++] = 0);
2015 + b = BASE - 1;
2016 +
2017 + // Subtract yc from xc.
2018 + for (; j > a;) {
2019 +
2020 + if (xc[--j] < yc[j]) {
2021 + for (i = j; i && !xc[--i]; xc[i] = b);
2022 + --xc[i];
2023 + xc[j] += BASE;
2024 + }
2025 +
2026 + xc[j] -= yc[j];
2027 + }
2028 +
2029 + // Remove leading zeros and adjust exponent accordingly.
2030 + for (; xc[0] == 0; xc.splice(0, 1), --ye);
2031 +
2032 + // Zero?
2033 + if (!xc[0]) {
2034 +
2035 + // Following IEEE 754 (2008) 6.3,
2036 + // n - n = +0 but n - n = -0 when rounding towards -Infinity.
2037 + y.s = ROUNDING_MODE == 3 ? -1 : 1;
2038 + y.c = [y.e = 0];
2039 + return y;
2040 + }
2041 +
2042 + // No need to check for Infinity as +x - +y != Infinity && -x - -y != Infinity
2043 + // for finite x and y.
2044 + return normalise(y, xc, ye);
2045 + };
2046 +
2047 +
2048 + /*
2049 + * n % 0 = N
2050 + * n % N = N
2051 + * n % I = n
2052 + * 0 % n = 0
2053 + * -0 % n = -0
2054 + * 0 % 0 = N
2055 + * 0 % N = N
2056 + * 0 % I = 0
2057 + * N % n = N
2058 + * N % 0 = N
2059 + * N % N = N
2060 + * N % I = N
2061 + * I % n = N
2062 + * I % 0 = N
2063 + * I % N = N
2064 + * I % I = N
2065 + *
2066 + * Return a new BigNumber whose value is the value of this BigNumber modulo the value of
2067 + * BigNumber(y, b). The result depends on the value of MODULO_MODE.
2068 + */
2069 + P.modulo = P.mod = function (y, b) {
2070 + var q, s,
2071 + x = this;
2072 +
2073 + y = new BigNumber(y, b);
2074 +
2075 + // Return NaN if x is Infinity or NaN, or y is NaN or zero.
2076 + if (!x.c || !y.s || y.c && !y.c[0]) {
2077 + return new BigNumber(NaN);
2078 +
2079 + // Return x if y is Infinity or x is zero.
2080 + } else if (!y.c || x.c && !x.c[0]) {
2081 + return new BigNumber(x);
2082 + }
2083 +
2084 + if (MODULO_MODE == 9) {
2085 +
2086 + // Euclidian division: q = sign(y) * floor(x / abs(y))
2087 + // r = x - qy where 0 <= r < abs(y)
2088 + s = y.s;
2089 + y.s = 1;
2090 + q = div(x, y, 0, 3);
2091 + y.s = s;
2092 + q.s *= s;
2093 + } else {
2094 + q = div(x, y, 0, MODULO_MODE);
2095 + }
2096 +
2097 + y = x.minus(q.times(y));
2098 +
2099 + // To match JavaScript %, ensure sign of zero is sign of dividend.
2100 + if (!y.c[0] && MODULO_MODE == 1) y.s = x.s;
2101 +
2102 + return y;
2103 + };
2104 +
2105 +
2106 + /*
2107 + * n * 0 = 0
2108 + * n * N = N
2109 + * n * I = I
2110 + * 0 * n = 0
2111 + * 0 * 0 = 0
2112 + * 0 * N = N
2113 + * 0 * I = N
2114 + * N * n = N
2115 + * N * 0 = N
2116 + * N * N = N
2117 + * N * I = N
2118 + * I * n = I
2119 + * I * 0 = N
2120 + * I * N = N
2121 + * I * I = I
2122 + *
2123 + * Return a new BigNumber whose value is the value of this BigNumber multiplied by the value
2124 + * of BigNumber(y, b).
2125 + */
2126 + P.multipliedBy = P.times = function (y, b) {
2127 + var c, e, i, j, k, m, xcL, xlo, xhi, ycL, ylo, yhi, zc,
2128 + base, sqrtBase,
2129 + x = this,
2130 + xc = x.c,
2131 + yc = (y = new BigNumber(y, b)).c;
2132 +
2133 + // Either NaN, ±Infinity or ±0?
2134 + if (!xc || !yc || !xc[0] || !yc[0]) {
2135 +
2136 + // Return NaN if either is NaN, or one is 0 and the other is Infinity.
2137 + if (!x.s || !y.s || xc && !xc[0] && !yc || yc && !yc[0] && !xc) {
2138 + y.c = y.e = y.s = null;
2139 + } else {
2140 + y.s *= x.s;
2141 +
2142 + // Return ±Infinity if either is ±Infinity.
2143 + if (!xc || !yc) {
2144 + y.c = y.e = null;
2145 +
2146 + // Return ±0 if either is ±0.
2147 + } else {
2148 + y.c = [0];
2149 + y.e = 0;
2150 + }
2151 + }
2152 +
2153 + return y;
2154 + }
2155 +
2156 + e = bitFloor(x.e / LOG_BASE) + bitFloor(y.e / LOG_BASE);
2157 + y.s *= x.s;
2158 + xcL = xc.length;
2159 + ycL = yc.length;
2160 +
2161 + // Ensure xc points to longer array and xcL to its length.
2162 + if (xcL < ycL) zc = xc, xc = yc, yc = zc, i = xcL, xcL = ycL, ycL = i;
2163 +
2164 + // Initialise the result array with zeros.
2165 + for (i = xcL + ycL, zc = []; i--; zc.push(0));
2166 +
2167 + base = BASE;
2168 + sqrtBase = SQRT_BASE;
2169 +
2170 + for (i = ycL; --i >= 0;) {
2171 + c = 0;
2172 + ylo = yc[i] % sqrtBase;
2173 + yhi = yc[i] / sqrtBase | 0;
2174 +
2175 + for (k = xcL, j = i + k; j > i;) {
2176 + xlo = xc[--k] % sqrtBase;
2177 + xhi = xc[k] / sqrtBase | 0;
2178 + m = yhi * xlo + xhi * ylo;
2179 + xlo = ylo * xlo + ((m % sqrtBase) * sqrtBase) + zc[j] + c;
2180 + c = (xlo / base | 0) + (m / sqrtBase | 0) + yhi * xhi;
2181 + zc[j--] = xlo % base;
2182 + }
2183 +
2184 + zc[j] = c;
2185 + }
2186 +
2187 + if (c) {
2188 + ++e;
2189 + } else {
2190 + zc.splice(0, 1);
2191 + }
2192 +
2193 + return normalise(y, zc, e);
2194 + };
2195 +
2196 +
2197 + /*
2198 + * Return a new BigNumber whose value is the value of this BigNumber negated,
2199 + * i.e. multiplied by -1.
2200 + */
2201 + P.negated = function () {
2202 + var x = new BigNumber(this);
2203 + x.s = -x.s || null;
2204 + return x;
2205 + };
2206 +
2207 +
2208 + /*
2209 + * n + 0 = n
2210 + * n + N = N
2211 + * n + I = I
2212 + * 0 + n = n
2213 + * 0 + 0 = 0
2214 + * 0 + N = N
2215 + * 0 + I = I
2216 + * N + n = N
2217 + * N + 0 = N
2218 + * N + N = N
2219 + * N + I = N
2220 + * I + n = I
2221 + * I + 0 = I
2222 + * I + N = N
2223 + * I + I = I
2224 + *
2225 + * Return a new BigNumber whose value is the value of this BigNumber plus the value of
2226 + * BigNumber(y, b).
2227 + */
2228 + P.plus = function (y, b) {
2229 + var t,
2230 + x = this,
2231 + a = x.s;
2232 +
2233 + y = new BigNumber(y, b);
2234 + b = y.s;
2235 +
2236 + // Either NaN?
2237 + if (!a || !b) return new BigNumber(NaN);
2238 +
2239 + // Signs differ?
2240 + if (a != b) {
2241 + y.s = -b;
2242 + return x.minus(y);
2243 + }
2244 +
2245 + var xe = x.e / LOG_BASE,
2246 + ye = y.e / LOG_BASE,
2247 + xc = x.c,
2248 + yc = y.c;
2249 +
2250 + if (!xe || !ye) {
2251 +
2252 + // Return ±Infinity if either ±Infinity.
2253 + if (!xc || !yc) return new BigNumber(a / 0);
2254 +
2255 + // Either zero?
2256 + // Return y if y is non-zero, x if x is non-zero, or zero if both are zero.
2257 + if (!xc[0] || !yc[0]) return yc[0] ? y : new BigNumber(xc[0] ? x : a * 0);
2258 + }
2259 +
2260 + xe = bitFloor(xe);
2261 + ye = bitFloor(ye);
2262 + xc = xc.slice();
2263 +
2264 + // Prepend zeros to equalise exponents. Faster to use reverse then do unshifts.
2265 + if (a = xe - ye) {
2266 + if (a > 0) {
2267 + ye = xe;
2268 + t = yc;
2269 + } else {
2270 + a = -a;
2271 + t = xc;
2272 + }
2273 +
2274 + t.reverse();
2275 + for (; a--; t.push(0));
2276 + t.reverse();
2277 + }
2278 +
2279 + a = xc.length;
2280 + b = yc.length;
2281 +
2282 + // Point xc to the longer array, and b to the shorter length.
2283 + if (a - b < 0) t = yc, yc = xc, xc = t, b = a;
2284 +
2285 + // Only start adding at yc.length - 1 as the further digits of xc can be ignored.
2286 + for (a = 0; b;) {
2287 + a = (xc[--b] = xc[b] + yc[b] + a) / BASE | 0;
2288 + xc[b] = BASE === xc[b] ? 0 : xc[b] % BASE;
2289 + }
2290 +
2291 + if (a) {
2292 + xc = [a].concat(xc);
2293 + ++ye;
2294 + }
2295 +
2296 + // No need to check for zero, as +x + +y != 0 && -x + -y != 0
2297 + // ye = MAX_EXP + 1 possible
2298 + return normalise(y, xc, ye);
2299 + };
2300 +
2301 +
2302 + /*
2303 + * If sd is undefined or null or true or false, return the number of significant digits of
2304 + * the value of this BigNumber, or null if the value of this BigNumber is ±Infinity or NaN.
2305 + * If sd is true include integer-part trailing zeros in the count.
2306 + *
2307 + * Otherwise, if sd is a number, return a new BigNumber whose value is the value of this
2308 + * BigNumber rounded to a maximum of sd significant digits using rounding mode rm, or
2309 + * ROUNDING_MODE if rm is omitted.
2310 + *
2311 + * sd {number|boolean} number: significant digits: integer, 1 to MAX inclusive.
2312 + * boolean: whether to count integer-part trailing zeros: true or false.
2313 + * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
2314 + *
2315 + * '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {sd|rm}'
2316 + */
2317 + P.precision = P.sd = function (sd, rm) {
2318 + var c, n, v,
2319 + x = this;
2320 +
2321 + if (sd != null && sd !== !!sd) {
2322 + intCheck(sd, 1, MAX);
2323 + if (rm == null) rm = ROUNDING_MODE;
2324 + else intCheck(rm, 0, 8);
2325 +
2326 + return round(new BigNumber(x), sd, rm);
2327 + }
2328 +
2329 + if (!(c = x.c)) return null;
2330 + v = c.length - 1;
2331 + n = v * LOG_BASE + 1;
2332 +
2333 + if (v = c[v]) {
2334 +
2335 + // Subtract the number of trailing zeros of the last element.
2336 + for (; v % 10 == 0; v /= 10, n--);
2337 +
2338 + // Add the number of digits of the first element.
2339 + for (v = c[0]; v >= 10; v /= 10, n++);
2340 + }
2341 +
2342 + if (sd && x.e + 1 > n) n = x.e + 1;
2343 +
2344 + return n;
2345 + };
2346 +
2347 +
2348 + /*
2349 + * Return a new BigNumber whose value is the value of this BigNumber shifted by k places
2350 + * (powers of 10). Shift to the right if n > 0, and to the left if n < 0.
2351 + *
2352 + * k {number} Integer, -MAX_SAFE_INTEGER to MAX_SAFE_INTEGER inclusive.
2353 + *
2354 + * '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {k}'
2355 + */
2356 + P.shiftedBy = function (k) {
2357 + intCheck(k, -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
2358 + return this.times('1e' + k);
2359 + };
2360 +
2361 +
2362 + /*
2363 + * sqrt(-n) = N
2364 + * sqrt(N) = N
2365 + * sqrt(-I) = N
2366 + * sqrt(I) = I
2367 + * sqrt(0) = 0
2368 + * sqrt(-0) = -0
2369 + *
2370 + * Return a new BigNumber whose value is the square root of the value of this BigNumber,
2371 + * rounded according to DECIMAL_PLACES and ROUNDING_MODE.
2372 + */
2373 + P.squareRoot = P.sqrt = function () {
2374 + var m, n, r, rep, t,
2375 + x = this,
2376 + c = x.c,
2377 + s = x.s,
2378 + e = x.e,
2379 + dp = DECIMAL_PLACES + 4,
2380 + half = new BigNumber('0.5');
2381 +
2382 + // Negative/NaN/Infinity/zero?
2383 + if (s !== 1 || !c || !c[0]) {
2384 + return new BigNumber(!s || s < 0 && (!c || c[0]) ? NaN : c ? x : 1 / 0);
2385 + }
2386 +
2387 + // Initial estimate.
2388 + s = Math.sqrt(+valueOf(x));
2389 +
2390 + // Math.sqrt underflow/overflow?
2391 + // Pass x to Math.sqrt as integer, then adjust the exponent of the result.
2392 + if (s == 0 || s == 1 / 0) {
2393 + n = coeffToString(c);
2394 + if ((n.length + e) % 2 == 0) n += '0';
2395 + s = Math.sqrt(+n);
2396 + e = bitFloor((e + 1) / 2) - (e < 0 || e % 2);
2397 +
2398 + if (s == 1 / 0) {
2399 + n = '1e' + e;
2400 + } else {
2401 + n = s.toExponential();
2402 + n = n.slice(0, n.indexOf('e') + 1) + e;
2403 + }
2404 +
2405 + r = new BigNumber(n);
2406 + } else {
2407 + r = new BigNumber(s + '');
2408 + }
2409 +
2410 + // Check for zero.
2411 + // r could be zero if MIN_EXP is changed after the this value was created.
2412 + // This would cause a division by zero (x/t) and hence Infinity below, which would cause
2413 + // coeffToString to throw.
2414 + if (r.c[0]) {
2415 + e = r.e;
2416 + s = e + dp;
2417 + if (s < 3) s = 0;
2418 +
2419 + // Newton-Raphson iteration.
2420 + for (; ;) {
2421 + t = r;
2422 + r = half.times(t.plus(div(x, t, dp, 1)));
2423 +
2424 + if (coeffToString(t.c).slice(0, s) === (n = coeffToString(r.c)).slice(0, s)) {
2425 +
2426 + // The exponent of r may here be one less than the final result exponent,
2427 + // e.g 0.0009999 (e-4) --> 0.001 (e-3), so adjust s so the rounding digits
2428 + // are indexed correctly.
2429 + if (r.e < e) --s;
2430 + n = n.slice(s - 3, s + 1);
2431 +
2432 + // The 4th rounding digit may be in error by -1 so if the 4 rounding digits
2433 + // are 9999 or 4999 (i.e. approaching a rounding boundary) continue the
2434 + // iteration.
2435 + if (n == '9999' || !rep && n == '4999') {
2436 +
2437 + // On the first iteration only, check to see if rounding up gives the
2438 + // exact result as the nines may infinitely repeat.
2439 + if (!rep) {
2440 + round(t, t.e + DECIMAL_PLACES + 2, 0);
2441 +
2442 + if (t.times(t).eq(x)) {
2443 + r = t;
2444 + break;
2445 + }
2446 + }
2447 +
2448 + dp += 4;
2449 + s += 4;
2450 + rep = 1;
2451 + } else {
2452 +
2453 + // If rounding digits are null, 0{0,4} or 50{0,3}, check for exact
2454 + // result. If not, then there are further digits and m will be truthy.
2455 + if (!+n || !+n.slice(1) && n.charAt(0) == '5') {
2456 +
2457 + // Truncate to the first rounding digit.
2458 + round(r, r.e + DECIMAL_PLACES + 2, 1);
2459 + m = !r.times(r).eq(x);
2460 + }
2461 +
2462 + break;
2463 + }
2464 + }
2465 + }
2466 + }
2467 +
2468 + return round(r, r.e + DECIMAL_PLACES + 1, ROUNDING_MODE, m);
2469 + };
2470 +
2471 +
2472 + /*
2473 + * Return a string representing the value of this BigNumber in exponential notation and
2474 + * rounded using ROUNDING_MODE to dp fixed decimal places.
2475 + *
2476 + * [dp] {number} Decimal places. Integer, 0 to MAX inclusive.
2477 + * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
2478 + *
2479 + * '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {dp|rm}'
2480 + */
2481 + P.toExponential = function (dp, rm) {
2482 + if (dp != null) {
2483 + intCheck(dp, 0, MAX);
2484 + dp++;
2485 + }
2486 + return format(this, dp, rm, 1);
2487 + };
2488 +
2489 +
2490 + /*
2491 + * Return a string representing the value of this BigNumber in fixed-point notation rounding
2492 + * to dp fixed decimal places using rounding mode rm, or ROUNDING_MODE if rm is omitted.
2493 + *
2494 + * Note: as with JavaScript's number type, (-0).toFixed(0) is '0',
2495 + * but e.g. (-0.00001).toFixed(0) is '-0'.
2496 + *
2497 + * [dp] {number} Decimal places. Integer, 0 to MAX inclusive.
2498 + * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
2499 + *
2500 + * '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {dp|rm}'
2501 + */
2502 + P.toFixed = function (dp, rm) {
2503 + if (dp != null) {
2504 + intCheck(dp, 0, MAX);
2505 + dp = dp + this.e + 1;
2506 + }
2507 + return format(this, dp, rm);
2508 + };
2509 +
2510 +
2511 + /*
2512 + * Return a string representing the value of this BigNumber in fixed-point notation rounded
2513 + * using rm or ROUNDING_MODE to dp decimal places, and formatted according to the properties
2514 + * of the format or FORMAT object (see BigNumber.set).
2515 + *
2516 + * The formatting object may contain some or all of the properties shown below.
2517 + *
2518 + * FORMAT = {
2519 + * prefix: '',
2520 + * groupSize: 3,
2521 + * secondaryGroupSize: 0,
2522 + * groupSeparator: ',',
2523 + * decimalSeparator: '.',
2524 + * fractionGroupSize: 0,
2525 + * fractionGroupSeparator: '\xA0', // non-breaking space
2526 + * suffix: ''
2527 + * };
2528 + *
2529 + * [dp] {number} Decimal places. Integer, 0 to MAX inclusive.
2530 + * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
2531 + * [format] {object} Formatting options. See FORMAT pbject above.
2532 + *
2533 + * '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {dp|rm}'
2534 + * '[BigNumber Error] Argument not an object: {format}'
2535 + */
2536 + P.toFormat = function (dp, rm, format) {
2537 + var str,
2538 + x = this;
2539 +
2540 + if (format == null) {
2541 + if (dp != null && rm && typeof rm == 'object') {
2542 + format = rm;
2543 + rm = null;
2544 + } else if (dp && typeof dp == 'object') {
2545 + format = dp;
2546 + dp = rm = null;
2547 + } else {
2548 + format = FORMAT;
2549 + }
2550 + } else if (typeof format != 'object') {
2551 + throw Error
2552 + (bignumberError + 'Argument not an object: ' + format);
2553 + }
2554 +
2555 + str = x.toFixed(dp, rm);
2556 +
2557 + if (x.c) {
2558 + var i,
2559 + arr = str.split('.'),
2560 + g1 = +format.groupSize,
2561 + g2 = +format.secondaryGroupSize,
2562 + groupSeparator = format.groupSeparator || '',
2563 + intPart = arr[0],
2564 + fractionPart = arr[1],
2565 + isNeg = x.s < 0,
2566 + intDigits = isNeg ? intPart.slice(1) : intPart,
2567 + len = intDigits.length;
2568 +
2569 + if (g2) i = g1, g1 = g2, g2 = i, len -= i;
2570 +
2571 + if (g1 > 0 && len > 0) {
2572 + i = len % g1 || g1;
2573 + intPart = intDigits.substr(0, i);
2574 + for (; i < len; i += g1) intPart += groupSeparator + intDigits.substr(i, g1);
2575 + if (g2 > 0) intPart += groupSeparator + intDigits.slice(i);
2576 + if (isNeg) intPart = '-' + intPart;
2577 + }
2578 +
2579 + str = fractionPart
2580 + ? intPart + (format.decimalSeparator || '') + ((g2 = +format.fractionGroupSize)
2581 + ? fractionPart.replace(new RegExp('\\d{' + g2 + '}\\B', 'g'),
2582 + '$&' + (format.fractionGroupSeparator || ''))
2583 + : fractionPart)
2584 + : intPart;
2585 + }
2586 +
2587 + return (format.prefix || '') + str + (format.suffix || '');
2588 + };
2589 +
2590 +
2591 + /*
2592 + * Return an array of two BigNumbers representing the value of this BigNumber as a simple
2593 + * fraction with an integer numerator and an integer denominator.
2594 + * The denominator will be a positive non-zero value less than or equal to the specified
2595 + * maximum denominator. If a maximum denominator is not specified, the denominator will be
2596 + * the lowest value necessary to represent the number exactly.
2597 + *
2598 + * [md] {number|string|BigNumber} Integer >= 1, or Infinity. The maximum denominator.
2599 + *
2600 + * '[BigNumber Error] Argument {not an integer|out of range} : {md}'
2601 + */
2602 + P.toFraction = function (md) {
2603 + var d, d0, d1, d2, e, exp, n, n0, n1, q, r, s,
2604 + x = this,
2605 + xc = x.c;
2606 +
2607 + if (md != null) {
2608 + n = new BigNumber(md);
2609 +
2610 + // Throw if md is less than one or is not an integer, unless it is Infinity.
2611 + if (!n.isInteger() && (n.c || n.s !== 1) || n.lt(ONE)) {
2612 + throw Error
2613 + (bignumberError + 'Argument ' +
2614 + (n.isInteger() ? 'out of range: ' : 'not an integer: ') + valueOf(n));
2615 + }
2616 + }
2617 +
2618 + if (!xc) return new BigNumber(x);
2619 +
2620 + d = new BigNumber(ONE);
2621 + n1 = d0 = new BigNumber(ONE);
2622 + d1 = n0 = new BigNumber(ONE);
2623 + s = coeffToString(xc);
2624 +
2625 + // Determine initial denominator.
2626 + // d is a power of 10 and the minimum max denominator that specifies the value exactly.
2627 + e = d.e = s.length - x.e - 1;
2628 + d.c[0] = POWS_TEN[(exp = e % LOG_BASE) < 0 ? LOG_BASE + exp : exp];
2629 + md = !md || n.comparedTo(d) > 0 ? (e > 0 ? d : n1) : n;
2630 +
2631 + exp = MAX_EXP;
2632 + MAX_EXP = 1 / 0;
2633 + n = new BigNumber(s);
2634 +
2635 + // n0 = d1 = 0
2636 + n0.c[0] = 0;
2637 +
2638 + for (; ;) {
2639 + q = div(n, d, 0, 1);
2640 + d2 = d0.plus(q.times(d1));
2641 + if (d2.comparedTo(md) == 1) break;
2642 + d0 = d1;
2643 + d1 = d2;
2644 + n1 = n0.plus(q.times(d2 = n1));
2645 + n0 = d2;
2646 + d = n.minus(q.times(d2 = d));
2647 + n = d2;
2648 + }
2649 +
2650 + d2 = div(md.minus(d0), d1, 0, 1);
2651 + n0 = n0.plus(d2.times(n1));
2652 + d0 = d0.plus(d2.times(d1));
2653 + n0.s = n1.s = x.s;
2654 + e = e * 2;
2655 +
2656 + // Determine which fraction is closer to x, n0/d0 or n1/d1
2657 + r = div(n1, d1, e, ROUNDING_MODE).minus(x).abs().comparedTo(
2658 + div(n0, d0, e, ROUNDING_MODE).minus(x).abs()) < 1 ? [n1, d1] : [n0, d0];
2659 +
2660 + MAX_EXP = exp;
2661 +
2662 + return r;
2663 + };
2664 +
2665 +
2666 + /*
2667 + * Return the value of this BigNumber converted to a number primitive.
2668 + */
2669 + P.toNumber = function () {
2670 + return +valueOf(this);
2671 + };
2672 +
2673 +
2674 + /*
2675 + * Return a string representing the value of this BigNumber rounded to sd significant digits
2676 + * using rounding mode rm or ROUNDING_MODE. If sd is less than the number of digits
2677 + * necessary to represent the integer part of the value in fixed-point notation, then use
2678 + * exponential notation.
2679 + *
2680 + * [sd] {number} Significant digits. Integer, 1 to MAX inclusive.
2681 + * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
2682 + *
2683 + * '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {sd|rm}'
2684 + */
2685 + P.toPrecision = function (sd, rm) {
2686 + if (sd != null) intCheck(sd, 1, MAX);
2687 + return format(this, sd, rm, 2);
2688 + };
2689 +
2690 +
2691 + /*
2692 + * Return a string representing the value of this BigNumber in base b, or base 10 if b is
2693 + * omitted. If a base is specified, including base 10, round according to DECIMAL_PLACES and
2694 + * ROUNDING_MODE. If a base is not specified, and this BigNumber has a positive exponent
2695 + * that is equal to or greater than TO_EXP_POS, or a negative exponent equal to or less than
2696 + * TO_EXP_NEG, return exponential notation.
2697 + *
2698 + * [b] {number} Integer, 2 to ALPHABET.length inclusive.
2699 + *
2700 + * '[BigNumber Error] Base {not a primitive number|not an integer|out of range}: {b}'
2701 + */
2702 + P.toString = function (b) {
2703 + var str,
2704 + n = this,
2705 + s = n.s,
2706 + e = n.e;
2707 +
2708 + // Infinity or NaN?
2709 + if (e === null) {
2710 + if (s) {
2711 + str = 'Infinity';
2712 + if (s < 0) str = '-' + str;
2713 + } else {
2714 + str = 'NaN';
2715 + }
2716 + } else {
2717 + if (b == null) {
2718 + str = e <= TO_EXP_NEG || e >= TO_EXP_POS
2719 + ? toExponential(coeffToString(n.c), e)
2720 + : toFixedPoint(coeffToString(n.c), e, '0');
2721 + } else if (b === 10) {
2722 + n = round(new BigNumber(n), DECIMAL_PLACES + e + 1, ROUNDING_MODE);
2723 + str = toFixedPoint(coeffToString(n.c), n.e, '0');
2724 + } else {
2725 + intCheck(b, 2, ALPHABET.length, 'Base');
2726 + str = convertBase(toFixedPoint(coeffToString(n.c), e, '0'), 10, b, s, true);
2727 + }
2728 +
2729 + if (s < 0 && n.c[0]) str = '-' + str;
2730 + }
2731 +
2732 + return str;
2733 + };
2734 +
2735 +
2736 + /*
2737 + * Return as toString, but do not accept a base argument, and include the minus sign for
2738 + * negative zero.
2739 + */
2740 + P.valueOf = P.toJSON = function () {
2741 + return valueOf(this);
2742 + };
2743 +
2744 +
2745 + P._isBigNumber = true;
2746 +
2747 + if (configObject != null) BigNumber.set(configObject);
2748 +
2749 + return BigNumber;
2750 + }
2751 +
2752 +
2753 + // PRIVATE HELPER FUNCTIONS
2754 +
2755 + // These functions don't need access to variables,
2756 + // e.g. DECIMAL_PLACES, in the scope of the `clone` function above.
2757 +
2758 +
2759 + function bitFloor(n) {
2760 + var i = n | 0;
2761 + return n > 0 || n === i ? i : i - 1;
2762 + }
2763 +
2764 +
2765 + // Return a coefficient array as a string of base 10 digits.
2766 + function coeffToString(a) {
2767 + var s, z,
2768 + i = 1,
2769 + j = a.length,
2770 + r = a[0] + '';
2771 +
2772 + for (; i < j;) {
2773 + s = a[i++] + '';
2774 + z = LOG_BASE - s.length;
2775 + for (; z--; s = '0' + s);
2776 + r += s;
2777 + }
2778 +
2779 + // Determine trailing zeros.
2780 + for (j = r.length; r.charCodeAt(--j) === 48;);
2781 +
2782 + return r.slice(0, j + 1 || 1);
2783 + }
2784 +
2785 +
2786 + // Compare the value of BigNumbers x and y.
2787 + function compare(x, y) {
2788 + var a, b,
2789 + xc = x.c,
2790 + yc = y.c,
2791 + i = x.s,
2792 + j = y.s,
2793 + k = x.e,
2794 + l = y.e;
2795 +
2796 + // Either NaN?
2797 + if (!i || !j) return null;
2798 +
2799 + a = xc && !xc[0];
2800 + b = yc && !yc[0];
2801 +
2802 + // Either zero?
2803 + if (a || b) return a ? b ? 0 : -j : i;
2804 +
2805 + // Signs differ?
2806 + if (i != j) return i;
2807 +
2808 + a = i < 0;
2809 + b = k == l;
2810 +
2811 + // Either Infinity?
2812 + if (!xc || !yc) return b ? 0 : !xc ^ a ? 1 : -1;
2813 +
2814 + // Compare exponents.
2815 + if (!b) return k > l ^ a ? 1 : -1;
2816 +
2817 + j = (k = xc.length) < (l = yc.length) ? k : l;
2818 +
2819 + // Compare digit by digit.
2820 + for (i = 0; i < j; i++) if (xc[i] != yc[i]) return xc[i] > yc[i] ^ a ? 1 : -1;
2821 +
2822 + // Compare lengths.
2823 + return k == l ? 0 : k > l ^ a ? 1 : -1;
2824 + }
2825 +
2826 +
2827 + /*
2828 + * Check that n is a primitive number, an integer, and in range, otherwise throw.
2829 + */
2830 + function intCheck(n, min, max, name) {
2831 + if (n < min || n > max || n !== mathfloor(n)) {
2832 + throw Error
2833 + (bignumberError + (name || 'Argument') + (typeof n == 'number'
2834 + ? n < min || n > max ? ' out of range: ' : ' not an integer: '
2835 + : ' not a primitive number: ') + String(n));
2836 + }
2837 + }
2838 +
2839 +
2840 + // Assumes finite n.
2841 + function isOdd(n) {
2842 + var k = n.c.length - 1;
2843 + return bitFloor(n.e / LOG_BASE) == k && n.c[k] % 2 != 0;
2844 + }
2845 +
2846 +
2847 + function toExponential(str, e) {
2848 + return (str.length > 1 ? str.charAt(0) + '.' + str.slice(1) : str) +
2849 + (e < 0 ? 'e' : 'e+') + e;
2850 + }
2851 +
2852 +
2853 + function toFixedPoint(str, e, z) {
2854 + var len, zs;
2855 +
2856 + // Negative exponent?
2857 + if (e < 0) {
2858 +
2859 + // Prepend zeros.
2860 + for (zs = z + '.'; ++e; zs += z);
2861 + str = zs + str;
2862 +
2863 + // Positive exponent
2864 + } else {
2865 + len = str.length;
2866 +
2867 + // Append zeros.
2868 + if (++e > len) {
2869 + for (zs = z, e -= len; --e; zs += z);
2870 + str += zs;
2871 + } else if (e < len) {
2872 + str = str.slice(0, e) + '.' + str.slice(e);
2873 + }
2874 + }
2875 +
2876 + return str;
2877 + }
2878 +
2879 +
2880 + // EXPORT
2881 +
2882 +
2883 + BigNumber = clone();
2884 + BigNumber['default'] = BigNumber.BigNumber = BigNumber;
2885 +
2886 + // AMD.
2887 + if (typeof define == 'function' && define.amd) {
2888 + define(function () { return BigNumber; });
2889 +
2890 + // Node.js and other environments that support module.exports.
2891 + } else if (typeof module != 'undefined' && module.exports) {
2892 + module.exports = BigNumber;
2893 +
2894 + // Browser.
2895 + } else {
2896 + if (!globalObject) {
2897 + globalObject = typeof self != 'undefined' && self ? self : window;
2898 + }
2899 +
2900 + globalObject.BigNumber = BigNumber;
2901 + }
2902 +})(this);
1 +/* bignumber.js v9.0.0 https://github.com/MikeMcl/bignumber.js/LICENCE */!function(e){"use strict";var r,x=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,L=Math.ceil,U=Math.floor,I="[BigNumber Error] ",T=I+"Number primitive has more than 15 significant digits: ",C=1e14,M=14,G=9007199254740991,k=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],F=1e7,q=1e9;function j(e){var r=0|e;return 0<e||e===r?r:r-1}function $(e){for(var r,n,t=1,i=e.length,o=e[0]+"";t<i;){for(r=e[t++]+"",n=M-r.length;n--;r="0"+r);o+=r}for(i=o.length;48===o.charCodeAt(--i););return o.slice(0,i+1||1)}function z(e,r){var n,t,i=e.c,o=r.c,s=e.s,f=r.s,u=e.e,l=r.e;if(!s||!f)return null;if(n=i&&!i[0],t=o&&!o[0],n||t)return n?t?0:-f:s;if(s!=f)return s;if(n=s<0,t=u==l,!i||!o)return t?0:!i^n?1:-1;if(!t)return l<u^n?1:-1;for(f=(u=i.length)<(l=o.length)?u:l,s=0;s<f;s++)if(i[s]!=o[s])return i[s]>o[s]^n?1:-1;return u==l?0:l<u^n?1:-1}function H(e,r,n,t){if(e<r||n<e||e!==U(e))throw Error(I+(t||"Argument")+("number"==typeof e?e<r||n<e?" out of range: ":" not an integer: ":" not a primitive number: ")+String(e))}function V(e){var r=e.c.length-1;return j(e.e/M)==r&&e.c[r]%2!=0}function W(e,r){return(1<e.length?e.charAt(0)+"."+e.slice(1):e)+(r<0?"e":"e+")+r}function X(e,r,n){var t,i;if(r<0){for(i=n+".";++r;i+=n);e=i+e}else if(++r>(t=e.length)){for(i=n,r-=t;--r;i+=n);e+=i}else r<t&&(e=e.slice(0,r)+"."+e.slice(r));return e}(r=function e(r){var v,a,h,n,l,s,f,u,c,g,t=B.prototype={constructor:B,toString:null,valueOf:null},w=new B(1),N=20,O=4,p=-7,d=21,m=-1e7,y=1e7,b=!1,o=1,E=0,A={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:" ",suffix:""},S="0123456789abcdefghijklmnopqrstuvwxyz";function B(e,r){var n,t,i,o,s,f,u,l,c=this;if(!(c instanceof B))return new B(e,r);if(null==r){if(e&&!0===e._isBigNumber)return c.s=e.s,void(!e.c||e.e>y?c.c=c.e=null:e.e<m?c.c=[c.e=0]:(c.e=e.e,c.c=e.c.slice()));if((f="number"==typeof e)&&0*e==0){if(c.s=1/e<0?(e=-e,-1):1,e===~~e){for(o=0,s=e;10<=s;s/=10,o++);return void(c.c=y<o?c.e=null:(c.e=o,[e]))}l=String(e)}else{if(!x.test(l=String(e)))return h(c,l,f);c.s=45==l.charCodeAt(0)?(l=l.slice(1),-1):1}-1<(o=l.indexOf("."))&&(l=l.replace(".","")),0<(s=l.search(/e/i))?(o<0&&(o=s),o+=+l.slice(s+1),l=l.substring(0,s)):o<0&&(o=l.length)}else{if(H(r,2,S.length,"Base"),10==r)return D(c=new B(e),N+c.e+1,O);if(l=String(e),f="number"==typeof e){if(0*e!=0)return h(c,l,f,r);if(c.s=1/e<0?(l=l.slice(1),-1):1,B.DEBUG&&15<l.replace(/^0\.0*|\./,"").length)throw Error(T+e)}else c.s=45===l.charCodeAt(0)?(l=l.slice(1),-1):1;for(n=S.slice(0,r),o=s=0,u=l.length;s<u;s++)if(n.indexOf(t=l.charAt(s))<0){if("."==t){if(o<s){o=u;continue}}else if(!i&&(l==l.toUpperCase()&&(l=l.toLowerCase())||l==l.toLowerCase()&&(l=l.toUpperCase()))){i=!0,s=-1,o=0;continue}return h(c,String(e),f,r)}f=!1,-1<(o=(l=a(l,r,10,c.s)).indexOf("."))?l=l.replace(".",""):o=l.length}for(s=0;48===l.charCodeAt(s);s++);for(u=l.length;48===l.charCodeAt(--u););if(l=l.slice(s,++u)){if(u-=s,f&&B.DEBUG&&15<u&&(G<e||e!==U(e)))throw Error(T+c.s*e);if((o=o-s-1)>y)c.c=c.e=null;else if(o<m)c.c=[c.e=0];else{if(c.e=o,c.c=[],s=(o+1)%M,o<0&&(s+=M),s<u){for(s&&c.c.push(+l.slice(0,s)),u-=M;s<u;)c.c.push(+l.slice(s,s+=M));s=M-(l=l.slice(s)).length}else s-=u;for(;s--;l+="0");c.c.push(+l)}}else c.c=[c.e=0]}function i(e,r,n,t){var i,o,s,f,u;if(null==n?n=O:H(n,0,8),!e.c)return e.toString();if(i=e.c[0],s=e.e,null==r)u=$(e.c),u=1==t||2==t&&(s<=p||d<=s)?W(u,s):X(u,s,"0");else if(o=(e=D(new B(e),r,n)).e,f=(u=$(e.c)).length,1==t||2==t&&(r<=o||o<=p)){for(;f<r;u+="0",f++);u=W(u,o)}else if(r-=s,u=X(u,o,"0"),f<o+1){if(0<--r)for(u+=".";r--;u+="0");}else if(0<(r+=o-f))for(o+1==f&&(u+=".");r--;u+="0");return e.s<0&&i?"-"+u:u}function R(e,r){for(var n,t=1,i=new B(e[0]);t<e.length;t++){if(!(n=new B(e[t])).s){i=n;break}r.call(i,n)&&(i=n)}return i}function _(e,r,n){for(var t=1,i=r.length;!r[--i];r.pop());for(i=r[0];10<=i;i/=10,t++);return(n=t+n*M-1)>y?e.c=e.e=null:e.c=n<m?[e.e=0]:(e.e=n,r),e}function D(e,r,n,t){var i,o,s,f,u,l,c,a=e.c,h=k;if(a){e:{for(i=1,f=a[0];10<=f;f/=10,i++);if((o=r-i)<0)o+=M,s=r,c=(u=a[l=0])/h[i-s-1]%10|0;else if((l=L((o+1)/M))>=a.length){if(!t)break e;for(;a.length<=l;a.push(0));u=c=0,s=(o%=M)-M+(i=1)}else{for(u=f=a[l],i=1;10<=f;f/=10,i++);c=(s=(o%=M)-M+i)<0?0:u/h[i-s-1]%10|0}if(t=t||r<0||null!=a[l+1]||(s<0?u:u%h[i-s-1]),t=n<4?(c||t)&&(0==n||n==(e.s<0?3:2)):5<c||5==c&&(4==n||t||6==n&&(0<o?0<s?u/h[i-s]:0:a[l-1])%10&1||n==(e.s<0?8:7)),r<1||!a[0])return a.length=0,t?(r-=e.e+1,a[0]=h[(M-r%M)%M],e.e=-r||0):a[0]=e.e=0,e;if(0==o?(a.length=l,f=1,l--):(a.length=l+1,f=h[M-o],a[l]=0<s?U(u/h[i-s]%h[s])*f:0),t)for(;;){if(0==l){for(o=1,s=a[0];10<=s;s/=10,o++);for(s=a[0]+=f,f=1;10<=s;s/=10,f++);o!=f&&(e.e++,a[0]==C&&(a[0]=1));break}if(a[l]+=f,a[l]!=C)break;a[l--]=0,f=1}for(o=a.length;0===a[--o];a.pop());}e.e>y?e.c=e.e=null:e.e<m&&(e.c=[e.e=0])}return e}function P(e){var r,n=e.e;return null===n?e.toString():(r=$(e.c),r=n<=p||d<=n?W(r,n):X(r,n,"0"),e.s<0?"-"+r:r)}return B.clone=e,B.ROUND_UP=0,B.ROUND_DOWN=1,B.ROUND_CEIL=2,B.ROUND_FLOOR=3,B.ROUND_HALF_UP=4,B.ROUND_HALF_DOWN=5,B.ROUND_HALF_EVEN=6,B.ROUND_HALF_CEIL=7,B.ROUND_HALF_FLOOR=8,B.EUCLID=9,B.config=B.set=function(e){var r,n;if(null!=e){if("object"!=typeof e)throw Error(I+"Object expected: "+e);if(e.hasOwnProperty(r="DECIMAL_PLACES")&&(H(n=e[r],0,q,r),N=n),e.hasOwnProperty(r="ROUNDING_MODE")&&(H(n=e[r],0,8,r),O=n),e.hasOwnProperty(r="EXPONENTIAL_AT")&&((n=e[r])&&n.pop?(H(n[0],-q,0,r),H(n[1],0,q,r),p=n[0],d=n[1]):(H(n,-q,q,r),p=-(d=n<0?-n:n))),e.hasOwnProperty(r="RANGE"))if((n=e[r])&&n.pop)H(n[0],-q,-1,r),H(n[1],1,q,r),m=n[0],y=n[1];else{if(H(n,-q,q,r),!n)throw Error(I+r+" cannot be zero: "+n);m=-(y=n<0?-n:n)}if(e.hasOwnProperty(r="CRYPTO")){if((n=e[r])!==!!n)throw Error(I+r+" not true or false: "+n);if(n){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw b=!n,Error(I+"crypto unavailable");b=n}else b=n}if(e.hasOwnProperty(r="MODULO_MODE")&&(H(n=e[r],0,9,r),o=n),e.hasOwnProperty(r="POW_PRECISION")&&(H(n=e[r],0,q,r),E=n),e.hasOwnProperty(r="FORMAT")){if("object"!=typeof(n=e[r]))throw Error(I+r+" not an object: "+n);A=n}if(e.hasOwnProperty(r="ALPHABET")){if("string"!=typeof(n=e[r])||/^.$|[+-.\s]|(.).*\1/.test(n))throw Error(I+r+" invalid: "+n);S=n}}return{DECIMAL_PLACES:N,ROUNDING_MODE:O,EXPONENTIAL_AT:[p,d],RANGE:[m,y],CRYPTO:b,MODULO_MODE:o,POW_PRECISION:E,FORMAT:A,ALPHABET:S}},B.isBigNumber=function(e){if(!e||!0!==e._isBigNumber)return!1;if(!B.DEBUG)return!0;var r,n,t=e.c,i=e.e,o=e.s;e:if("[object Array]"=={}.toString.call(t)){if((1===o||-1===o)&&-q<=i&&i<=q&&i===U(i)){if(0===t[0]){if(0===i&&1===t.length)return!0;break e}if((r=(i+1)%M)<1&&(r+=M),String(t[0]).length==r){for(r=0;r<t.length;r++)if((n=t[r])<0||C<=n||n!==U(n))break e;if(0!==n)return!0}}}else if(null===t&&null===i&&(null===o||1===o||-1===o))return!0;throw Error(I+"Invalid BigNumber: "+e)},B.maximum=B.max=function(){return R(arguments,t.lt)},B.minimum=B.min=function(){return R(arguments,t.gt)},B.random=(n=9007199254740992,l=Math.random()*n&2097151?function(){return U(Math.random()*n)}:function(){return 8388608*(1073741824*Math.random()|0)+(8388608*Math.random()|0)},function(e){var r,n,t,i,o,s=0,f=[],u=new B(w);if(null==e?e=N:H(e,0,q),i=L(e/M),b)if(crypto.getRandomValues){for(r=crypto.getRandomValues(new Uint32Array(i*=2));s<i;)9e15<=(o=131072*r[s]+(r[s+1]>>>11))?(n=crypto.getRandomValues(new Uint32Array(2)),r[s]=n[0],r[s+1]=n[1]):(f.push(o%1e14),s+=2);s=i/2}else{if(!crypto.randomBytes)throw b=!1,Error(I+"crypto unavailable");for(r=crypto.randomBytes(i*=7);s<i;)9e15<=(o=281474976710656*(31&r[s])+1099511627776*r[s+1]+4294967296*r[s+2]+16777216*r[s+3]+(r[s+4]<<16)+(r[s+5]<<8)+r[s+6])?crypto.randomBytes(7).copy(r,s):(f.push(o%1e14),s+=7);s=i/7}if(!b)for(;s<i;)(o=l())<9e15&&(f[s++]=o%1e14);for(i=f[--s],e%=M,i&&e&&(o=k[M-e],f[s]=U(i/o)*o);0===f[s];f.pop(),s--);if(s<0)f=[t=0];else{for(t=-1;0===f[0];f.splice(0,1),t-=M);for(s=1,o=f[0];10<=o;o/=10,s++);s<M&&(t-=M-s)}return u.e=t,u.c=f,u}),B.sum=function(){for(var e=1,r=arguments,n=new B(r[0]);e<r.length;)n=n.plus(r[e++]);return n},a=function(){var d="0123456789";function m(e,r,n,t){for(var i,o,s=[0],f=0,u=e.length;f<u;){for(o=s.length;o--;s[o]*=r);for(s[0]+=t.indexOf(e.charAt(f++)),i=0;i<s.length;i++)s[i]>n-1&&(null==s[i+1]&&(s[i+1]=0),s[i+1]+=s[i]/n|0,s[i]%=n)}return s.reverse()}return function(e,r,n,t,i){var o,s,f,u,l,c,a,h,g=e.indexOf("."),p=N,w=O;for(0<=g&&(u=E,E=0,e=e.replace(".",""),c=(h=new B(r)).pow(e.length-g),E=u,h.c=m(X($(c.c),c.e,"0"),10,n,d),h.e=h.c.length),f=u=(a=m(e,r,n,i?(o=S,d):(o=d,S))).length;0==a[--u];a.pop());if(!a[0])return o.charAt(0);if(g<0?--f:(c.c=a,c.e=f,c.s=t,a=(c=v(c,h,p,w,n)).c,l=c.r,f=c.e),g=a[s=f+p+1],u=n/2,l=l||s<0||null!=a[s+1],l=w<4?(null!=g||l)&&(0==w||w==(c.s<0?3:2)):u<g||g==u&&(4==w||l||6==w&&1&a[s-1]||w==(c.s<0?8:7)),s<1||!a[0])e=l?X(o.charAt(1),-p,o.charAt(0)):o.charAt(0);else{if(a.length=s,l)for(--n;++a[--s]>n;)a[s]=0,s||(++f,a=[1].concat(a));for(u=a.length;!a[--u];);for(g=0,e="";g<=u;e+=o.charAt(a[g++]));e=X(e,f,o.charAt(0))}return e}}(),v=function(){function S(e,r,n){var t,i,o,s,f=0,u=e.length,l=r%F,c=r/F|0;for(e=e.slice();u--;)f=((i=l*(o=e[u]%F)+(t=c*o+(s=e[u]/F|0)*l)%F*F+f)/n|0)+(t/F|0)+c*s,e[u]=i%n;return f&&(e=[f].concat(e)),e}function R(e,r,n,t){var i,o;if(n!=t)o=t<n?1:-1;else for(i=o=0;i<n;i++)if(e[i]!=r[i]){o=e[i]>r[i]?1:-1;break}return o}function _(e,r,n,t){for(var i=0;n--;)e[n]-=i,i=e[n]<r[n]?1:0,e[n]=i*t+e[n]-r[n];for(;!e[0]&&1<e.length;e.splice(0,1));}return function(e,r,n,t,i){var o,s,f,u,l,c,a,h,g,p,w,d,m,v,N,O,y,b=e.s==r.s?1:-1,E=e.c,A=r.c;if(!(E&&E[0]&&A&&A[0]))return new B(e.s&&r.s&&(E?!A||E[0]!=A[0]:A)?E&&0==E[0]||!A?0*b:b/0:NaN);for(g=(h=new B(b)).c=[],b=n+(s=e.e-r.e)+1,i||(i=C,s=j(e.e/M)-j(r.e/M),b=b/M|0),f=0;A[f]==(E[f]||0);f++);if(A[f]>(E[f]||0)&&s--,b<0)g.push(1),u=!0;else{for(v=E.length,O=A.length,b+=2,1<(l=U(i/(A[f=0]+1)))&&(A=S(A,l,i),E=S(E,l,i),O=A.length,v=E.length),m=O,w=(p=E.slice(0,O)).length;w<O;p[w++]=0);y=A.slice(),y=[0].concat(y),N=A[0],A[1]>=i/2&&N++;do{if(l=0,(o=R(A,p,O,w))<0){if(d=p[0],O!=w&&(d=d*i+(p[1]||0)),1<(l=U(d/N)))for(i<=l&&(l=i-1),a=(c=S(A,l,i)).length,w=p.length;1==R(c,p,a,w);)l--,_(c,O<a?y:A,a,i),a=c.length,o=1;else 0==l&&(o=l=1),a=(c=A.slice()).length;if(a<w&&(c=[0].concat(c)),_(p,c,w,i),w=p.length,-1==o)for(;R(A,p,O,w)<1;)l++,_(p,O<w?y:A,w,i),w=p.length}else 0===o&&(l++,p=[0]);g[f++]=l,p[0]?p[w++]=E[m]||0:(p=[E[m]],w=1)}while((m++<v||null!=p[0])&&b--);u=null!=p[0],g[0]||g.splice(0,1)}if(i==C){for(f=1,b=g[0];10<=b;b/=10,f++);D(h,n+(h.e=f+s*M-1)+1,t,u)}else h.e=s,h.r=+u;return h}}(),s=/^(-?)0([xbo])(?=\w[\w.]*$)/i,f=/^([^.]+)\.$/,u=/^\.([^.]+)$/,c=/^-?(Infinity|NaN)$/,g=/^\s*\+(?=[\w.])|^\s+|\s+$/g,h=function(e,r,n,t){var i,o=n?r:r.replace(g,"");if(c.test(o))e.s=isNaN(o)?null:o<0?-1:1;else{if(!n&&(o=o.replace(s,function(e,r,n){return i="x"==(n=n.toLowerCase())?16:"b"==n?2:8,t&&t!=i?e:r}),t&&(i=t,o=o.replace(f,"$1").replace(u,"0.$1")),r!=o))return new B(o,i);if(B.DEBUG)throw Error(I+"Not a"+(t?" base "+t:"")+" number: "+r);e.s=null}e.c=e.e=null},t.absoluteValue=t.abs=function(){var e=new B(this);return e.s<0&&(e.s=1),e},t.comparedTo=function(e,r){return z(this,new B(e,r))},t.decimalPlaces=t.dp=function(e,r){var n,t,i;if(null!=e)return H(e,0,q),null==r?r=O:H(r,0,8),D(new B(this),e+this.e+1,r);if(!(n=this.c))return null;if(t=((i=n.length-1)-j(this.e/M))*M,i=n[i])for(;i%10==0;i/=10,t--);return t<0&&(t=0),t},t.dividedBy=t.div=function(e,r){return v(this,new B(e,r),N,O)},t.dividedToIntegerBy=t.idiv=function(e,r){return v(this,new B(e,r),0,1)},t.exponentiatedBy=t.pow=function(e,r){var n,t,i,o,s,f,u,l,c=this;if((e=new B(e)).c&&!e.isInteger())throw Error(I+"Exponent not an integer: "+P(e));if(null!=r&&(r=new B(r)),s=14<e.e,!c.c||!c.c[0]||1==c.c[0]&&!c.e&&1==c.c.length||!e.c||!e.c[0])return l=new B(Math.pow(+P(c),s?2-V(e):+P(e))),r?l.mod(r):l;if(f=e.s<0,r){if(r.c?!r.c[0]:!r.s)return new B(NaN);(t=!f&&c.isInteger()&&r.isInteger())&&(c=c.mod(r))}else{if(9<e.e&&(0<c.e||c.e<-1||(0==c.e?1<c.c[0]||s&&24e7<=c.c[1]:c.c[0]<8e13||s&&c.c[0]<=9999975e7)))return o=c.s<0&&V(e)?-0:0,-1<c.e&&(o=1/o),new B(f?1/o:o);E&&(o=L(E/M+2))}for(u=s?(n=new B(.5),f&&(e.s=1),V(e)):(i=Math.abs(+P(e)))%2,l=new B(w);;){if(u){if(!(l=l.times(c)).c)break;o?l.c.length>o&&(l.c.length=o):t&&(l=l.mod(r))}if(i){if(0===(i=U(i/2)))break;u=i%2}else if(D(e=e.times(n),e.e+1,1),14<e.e)u=V(e);else{if(0==(i=+P(e)))break;u=i%2}c=c.times(c),o?c.c&&c.c.length>o&&(c.c.length=o):t&&(c=c.mod(r))}return t?l:(f&&(l=w.div(l)),r?l.mod(r):o?D(l,E,O,void 0):l)},t.integerValue=function(e){var r=new B(this);return null==e?e=O:H(e,0,8),D(r,r.e+1,e)},t.isEqualTo=t.eq=function(e,r){return 0===z(this,new B(e,r))},t.isFinite=function(){return!!this.c},t.isGreaterThan=t.gt=function(e,r){return 0<z(this,new B(e,r))},t.isGreaterThanOrEqualTo=t.gte=function(e,r){return 1===(r=z(this,new B(e,r)))||0===r},t.isInteger=function(){return!!this.c&&j(this.e/M)>this.c.length-2},t.isLessThan=t.lt=function(e,r){return z(this,new B(e,r))<0},t.isLessThanOrEqualTo=t.lte=function(e,r){return-1===(r=z(this,new B(e,r)))||0===r},t.isNaN=function(){return!this.s},t.isNegative=function(){return this.s<0},t.isPositive=function(){return 0<this.s},t.isZero=function(){return!!this.c&&0==this.c[0]},t.minus=function(e,r){var n,t,i,o,s=this,f=s.s;if(r=(e=new B(e,r)).s,!f||!r)return new B(NaN);if(f!=r)return e.s=-r,s.plus(e);var u=s.e/M,l=e.e/M,c=s.c,a=e.c;if(!u||!l){if(!c||!a)return c?(e.s=-r,e):new B(a?s:NaN);if(!c[0]||!a[0])return a[0]?(e.s=-r,e):new B(c[0]?s:3==O?-0:0)}if(u=j(u),l=j(l),c=c.slice(),f=u-l){for((i=(o=f<0)?(f=-f,c):(l=u,a)).reverse(),r=f;r--;i.push(0));i.reverse()}else for(t=(o=(f=c.length)<(r=a.length))?f:r,f=r=0;r<t;r++)if(c[r]!=a[r]){o=c[r]<a[r];break}if(o&&(i=c,c=a,a=i,e.s=-e.s),0<(r=(t=a.length)-(n=c.length)))for(;r--;c[n++]=0);for(r=C-1;f<t;){if(c[--t]<a[t]){for(n=t;n&&!c[--n];c[n]=r);--c[n],c[t]+=C}c[t]-=a[t]}for(;0==c[0];c.splice(0,1),--l);return c[0]?_(e,c,l):(e.s=3==O?-1:1,e.c=[e.e=0],e)},t.modulo=t.mod=function(e,r){var n,t,i=this;return e=new B(e,r),!i.c||!e.s||e.c&&!e.c[0]?new B(NaN):!e.c||i.c&&!i.c[0]?new B(i):(9==o?(t=e.s,e.s=1,n=v(i,e,0,3),e.s=t,n.s*=t):n=v(i,e,0,o),(e=i.minus(n.times(e))).c[0]||1!=o||(e.s=i.s),e)},t.multipliedBy=t.times=function(e,r){var n,t,i,o,s,f,u,l,c,a,h,g,p,w,d,m=this,v=m.c,N=(e=new B(e,r)).c;if(!(v&&N&&v[0]&&N[0]))return!m.s||!e.s||v&&!v[0]&&!N||N&&!N[0]&&!v?e.c=e.e=e.s=null:(e.s*=m.s,v&&N?(e.c=[0],e.e=0):e.c=e.e=null),e;for(t=j(m.e/M)+j(e.e/M),e.s*=m.s,(u=v.length)<(a=N.length)&&(p=v,v=N,N=p,i=u,u=a,a=i),i=u+a,p=[];i--;p.push(0));for(w=C,d=F,i=a;0<=--i;){for(n=0,h=N[i]%d,g=N[i]/d|0,o=i+(s=u);i<o;)n=((l=h*(l=v[--s]%d)+(f=g*l+(c=v[s]/d|0)*h)%d*d+p[o]+n)/w|0)+(f/d|0)+g*c,p[o--]=l%w;p[o]=n}return n?++t:p.splice(0,1),_(e,p,t)},t.negated=function(){var e=new B(this);return e.s=-e.s||null,e},t.plus=function(e,r){var n,t=this,i=t.s;if(r=(e=new B(e,r)).s,!i||!r)return new B(NaN);if(i!=r)return e.s=-r,t.minus(e);var o=t.e/M,s=e.e/M,f=t.c,u=e.c;if(!o||!s){if(!f||!u)return new B(i/0);if(!f[0]||!u[0])return u[0]?e:new B(f[0]?t:0*i)}if(o=j(o),s=j(s),f=f.slice(),i=o-s){for((n=0<i?(s=o,u):(i=-i,f)).reverse();i--;n.push(0));n.reverse()}for((i=f.length)-(r=u.length)<0&&(n=u,u=f,f=n,r=i),i=0;r;)i=(f[--r]=f[r]+u[r]+i)/C|0,f[r]=C===f[r]?0:f[r]%C;return i&&(f=[i].concat(f),++s),_(e,f,s)},t.precision=t.sd=function(e,r){var n,t,i;if(null!=e&&e!==!!e)return H(e,1,q),null==r?r=O:H(r,0,8),D(new B(this),e,r);if(!(n=this.c))return null;if(t=(i=n.length-1)*M+1,i=n[i]){for(;i%10==0;i/=10,t--);for(i=n[0];10<=i;i/=10,t++);}return e&&this.e+1>t&&(t=this.e+1),t},t.shiftedBy=function(e){return H(e,-G,G),this.times("1e"+e)},t.squareRoot=t.sqrt=function(){var e,r,n,t,i,o=this,s=o.c,f=o.s,u=o.e,l=N+4,c=new B("0.5");if(1!==f||!s||!s[0])return new B(!f||f<0&&(!s||s[0])?NaN:s?o:1/0);if((n=0==(f=Math.sqrt(+P(o)))||f==1/0?(((r=$(s)).length+u)%2==0&&(r+="0"),f=Math.sqrt(+r),u=j((u+1)/2)-(u<0||u%2),new B(r=f==1/0?"1e"+u:(r=f.toExponential()).slice(0,r.indexOf("e")+1)+u)):new B(f+"")).c[0])for((f=(u=n.e)+l)<3&&(f=0);;)if(i=n,n=c.times(i.plus(v(o,i,l,1))),$(i.c).slice(0,f)===(r=$(n.c)).slice(0,f)){if(n.e<u&&--f,"9999"!=(r=r.slice(f-3,f+1))&&(t||"4999"!=r)){+r&&(+r.slice(1)||"5"!=r.charAt(0))||(D(n,n.e+N+2,1),e=!n.times(n).eq(o));break}if(!t&&(D(i,i.e+N+2,0),i.times(i).eq(o))){n=i;break}l+=4,f+=4,t=1}return D(n,n.e+N+1,O,e)},t.toExponential=function(e,r){return null!=e&&(H(e,0,q),e++),i(this,e,r,1)},t.toFixed=function(e,r){return null!=e&&(H(e,0,q),e=e+this.e+1),i(this,e,r)},t.toFormat=function(e,r,n){var t;if(null==n)null!=e&&r&&"object"==typeof r?(n=r,r=null):e&&"object"==typeof e?(n=e,e=r=null):n=A;else if("object"!=typeof n)throw Error(I+"Argument not an object: "+n);if(t=this.toFixed(e,r),this.c){var i,o=t.split("."),s=+n.groupSize,f=+n.secondaryGroupSize,u=n.groupSeparator||"",l=o[0],c=o[1],a=this.s<0,h=a?l.slice(1):l,g=h.length;if(f&&(i=s,s=f,g-=f=i),0<s&&0<g){for(i=g%s||s,l=h.substr(0,i);i<g;i+=s)l+=u+h.substr(i,s);0<f&&(l+=u+h.slice(i)),a&&(l="-"+l)}t=c?l+(n.decimalSeparator||"")+((f=+n.fractionGroupSize)?c.replace(new RegExp("\\d{"+f+"}\\B","g"),"$&"+(n.fractionGroupSeparator||"")):c):l}return(n.prefix||"")+t+(n.suffix||"")},t.toFraction=function(e){var r,n,t,i,o,s,f,u,l,c,a,h,g=this,p=g.c;if(null!=e&&(!(f=new B(e)).isInteger()&&(f.c||1!==f.s)||f.lt(w)))throw Error(I+"Argument "+(f.isInteger()?"out of range: ":"not an integer: ")+P(f));if(!p)return new B(g);for(r=new B(w),l=n=new B(w),t=u=new B(w),h=$(p),o=r.e=h.length-g.e-1,r.c[0]=k[(s=o%M)<0?M+s:s],e=!e||0<f.comparedTo(r)?0<o?r:l:f,s=y,y=1/0,f=new B(h),u.c[0]=0;c=v(f,r,0,1),1!=(i=n.plus(c.times(t))).comparedTo(e);)n=t,t=i,l=u.plus(c.times(i=l)),u=i,r=f.minus(c.times(i=r)),f=i;return i=v(e.minus(n),t,0,1),u=u.plus(i.times(l)),n=n.plus(i.times(t)),u.s=l.s=g.s,a=v(l,t,o*=2,O).minus(g).abs().comparedTo(v(u,n,o,O).minus(g).abs())<1?[l,t]:[u,n],y=s,a},t.toNumber=function(){return+P(this)},t.toPrecision=function(e,r){return null!=e&&H(e,1,q),i(this,e,r,2)},t.toString=function(e){var r,n=this,t=n.s,i=n.e;return null===i?t?(r="Infinity",t<0&&(r="-"+r)):r="NaN":(r=null==e?i<=p||d<=i?W($(n.c),i):X($(n.c),i,"0"):10===e?X($((n=D(new B(n),N+i+1,O)).c),n.e,"0"):(H(e,2,S.length,"Base"),a(X($(n.c),i,"0"),10,e,t,!0)),t<0&&n.c[0]&&(r="-"+r)),r},t.valueOf=t.toJSON=function(){return P(this)},t._isBigNumber=!0,null!=r&&B.set(r),B}()).default=r.BigNumber=r,"function"==typeof define&&define.amd?define(function(){return r}):"undefined"!=typeof module&&module.exports?module.exports=r:(e||(e="undefined"!=typeof self&&self?self:window),e.BigNumber=r)}(this);
...\ No newline at end of file ...\ No newline at end of file
1 +{"version":3,"sources":["bignumber.js"],"names":["globalObject","BigNumber","isNumeric","mathceil","Math","ceil","mathfloor","floor","bignumberError","tooManyDigits","BASE","LOG_BASE","MAX_SAFE_INTEGER","POWS_TEN","SQRT_BASE","MAX","bitFloor","n","i","coeffToString","a","s","z","j","length","r","charCodeAt","slice","compare","x","y","b","xc","c","yc","k","e","l","intCheck","min","max","name","Error","String","isOdd","toExponential","str","charAt","toFixedPoint","len","zs","clone","configObject","div","convertBase","parseNumeric","pow2_53","random53bitInt","basePrefix","dotAfter","dotBefore","isInfinityOrNaN","whitespaceOrPlus","P","prototype","constructor","toString","valueOf","ONE","DECIMAL_PLACES","ROUNDING_MODE","TO_EXP_NEG","TO_EXP_POS","MIN_EXP","MAX_EXP","CRYPTO","MODULO_MODE","POW_PRECISION","FORMAT","prefix","groupSize","secondaryGroupSize","groupSeparator","decimalSeparator","fractionGroupSize","fractionGroupSeparator","suffix","ALPHABET","v","alphabet","caseChanged","isNum","this","_isBigNumber","test","indexOf","replace","search","substring","round","DEBUG","toUpperCase","toLowerCase","push","format","rm","id","c0","ne","maxOrMin","args","method","m","call","normalise","pop","sd","d","ni","rd","pows10","out","ROUND_UP","ROUND_DOWN","ROUND_CEIL","ROUND_FLOOR","ROUND_HALF_UP","ROUND_HALF_DOWN","ROUND_HALF_EVEN","ROUND_HALF_CEIL","ROUND_HALF_FLOOR","EUCLID","config","set","obj","p","hasOwnProperty","crypto","getRandomValues","randomBytes","EXPONENTIAL_AT","RANGE","isBigNumber","maximum","arguments","lt","minimum","gt","random","dp","rand","Uint32Array","copy","splice","sum","plus","decimal","toBaseOut","baseIn","baseOut","arrL","arr","reverse","sign","callerIsToString","pow","concat","multiply","base","temp","xlo","xhi","carry","klo","khi","aL","bL","cmp","subtract","more","prod","prodL","q","qc","rem","remL","rem0","xi","xL","yc0","yL","yz","NaN","isNaN","p1","p2","absoluteValue","abs","comparedTo","decimalPlaces","dividedBy","dividedToIntegerBy","idiv","exponentiatedBy","half","isModExp","nIsBig","nIsNeg","nIsOdd","isInteger","mod","times","integerValue","isEqualTo","eq","isFinite","isGreaterThan","isGreaterThanOrEqualTo","gte","isLessThan","isLessThanOrEqualTo","lte","isNegative","isPositive","isZero","minus","t","xLTy","xe","ye","modulo","multipliedBy","xcL","ycL","ylo","yhi","zc","sqrtBase","negated","precision","shiftedBy","squareRoot","sqrt","rep","toFixed","toFormat","split","g1","g2","intPart","fractionPart","isNeg","intDigits","substr","RegExp","toFraction","md","d0","d1","d2","exp","n0","n1","toNumber","toPrecision","toJSON","define","amd","module","exports","self","window"],"mappings":"CAAC,SAAWA,GACV,aAkDA,IAAIC,EACFC,EAAY,6CACZC,EAAWC,KAAKC,KAChBC,EAAYF,KAAKG,MAEjBC,EAAiB,qBACjBC,EAAgBD,EAAiB,yDAEjCE,EAAO,KACPC,EAAW,GACXC,EAAmB,iBAEnBC,EAAW,CAAC,EAAG,GAAI,IAAK,IAAK,IAAK,IAAK,IAAK,IAAK,IAAK,IAAK,KAAM,KAAM,KAAM,MAC7EC,EAAY,IAKZC,EAAM,IAioFR,SAASC,EAASC,GAChB,IAAIC,EAAQ,EAAJD,EACR,OAAW,EAAJA,GAASA,IAAMC,EAAIA,EAAIA,EAAI,EAKpC,SAASC,EAAcC,GAMrB,IALA,IAAIC,EAAGC,EACLJ,EAAI,EACJK,EAAIH,EAAEI,OACNC,EAAIL,EAAE,GAAK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line at end of file ...\ No newline at end of file
1 +/*
2 + * bignumber.js v9.0.0
3 + * A JavaScript library for arbitrary-precision arithmetic.
4 + * https://github.com/MikeMcl/bignumber.js
5 + * Copyright (c) 2019 Michael Mclaughlin <M8ch88l@gmail.com>
6 + * MIT Licensed.
7 + *
8 + * BigNumber.prototype methods | BigNumber methods
9 + * |
10 + * absoluteValue abs | clone
11 + * comparedTo | config set
12 + * decimalPlaces dp | DECIMAL_PLACES
13 + * dividedBy div | ROUNDING_MODE
14 + * dividedToIntegerBy idiv | EXPONENTIAL_AT
15 + * exponentiatedBy pow | RANGE
16 + * integerValue | CRYPTO
17 + * isEqualTo eq | MODULO_MODE
18 + * isFinite | POW_PRECISION
19 + * isGreaterThan gt | FORMAT
20 + * isGreaterThanOrEqualTo gte | ALPHABET
21 + * isInteger | isBigNumber
22 + * isLessThan lt | maximum max
23 + * isLessThanOrEqualTo lte | minimum min
24 + * isNaN | random
25 + * isNegative | sum
26 + * isPositive |
27 + * isZero |
28 + * minus |
29 + * modulo mod |
30 + * multipliedBy times |
31 + * negated |
32 + * plus |
33 + * precision sd |
34 + * shiftedBy |
35 + * squareRoot sqrt |
36 + * toExponential |
37 + * toFixed |
38 + * toFormat |
39 + * toFraction |
40 + * toJSON |
41 + * toNumber |
42 + * toPrecision |
43 + * toString |
44 + * valueOf |
45 + *
46 + */
47 +
48 +
49 +var
50 + isNumeric = /^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,
51 +
52 + mathceil = Math.ceil,
53 + mathfloor = Math.floor,
54 +
55 + bignumberError = '[BigNumber Error] ',
56 + tooManyDigits = bignumberError + 'Number primitive has more than 15 significant digits: ',
57 +
58 + BASE = 1e14,
59 + LOG_BASE = 14,
60 + MAX_SAFE_INTEGER = 0x1fffffffffffff, // 2^53 - 1
61 + // MAX_INT32 = 0x7fffffff, // 2^31 - 1
62 + POWS_TEN = [1, 10, 100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13],
63 + SQRT_BASE = 1e7,
64 +
65 + // EDITABLE
66 + // The limit on the value of DECIMAL_PLACES, TO_EXP_NEG, TO_EXP_POS, MIN_EXP, MAX_EXP, and
67 + // the arguments to toExponential, toFixed, toFormat, and toPrecision.
68 + MAX = 1E9; // 0 to MAX_INT32
69 +
70 +
71 +/*
72 + * Create and return a BigNumber constructor.
73 + */
74 +function clone(configObject) {
75 + var div, convertBase, parseNumeric,
76 + P = BigNumber.prototype = { constructor: BigNumber, toString: null, valueOf: null },
77 + ONE = new BigNumber(1),
78 +
79 +
80 + //----------------------------- EDITABLE CONFIG DEFAULTS -------------------------------
81 +
82 +
83 + // The default values below must be integers within the inclusive ranges stated.
84 + // The values can also be changed at run-time using BigNumber.set.
85 +
86 + // The maximum number of decimal places for operations involving division.
87 + DECIMAL_PLACES = 20, // 0 to MAX
88 +
89 + // The rounding mode used when rounding to the above decimal places, and when using
90 + // toExponential, toFixed, toFormat and toPrecision, and round (default value).
91 + // UP 0 Away from zero.
92 + // DOWN 1 Towards zero.
93 + // CEIL 2 Towards +Infinity.
94 + // FLOOR 3 Towards -Infinity.
95 + // HALF_UP 4 Towards nearest neighbour. If equidistant, up.
96 + // HALF_DOWN 5 Towards nearest neighbour. If equidistant, down.
97 + // HALF_EVEN 6 Towards nearest neighbour. If equidistant, towards even neighbour.
98 + // HALF_CEIL 7 Towards nearest neighbour. If equidistant, towards +Infinity.
99 + // HALF_FLOOR 8 Towards nearest neighbour. If equidistant, towards -Infinity.
100 + ROUNDING_MODE = 4, // 0 to 8
101 +
102 + // EXPONENTIAL_AT : [TO_EXP_NEG , TO_EXP_POS]
103 +
104 + // The exponent value at and beneath which toString returns exponential notation.
105 + // Number type: -7
106 + TO_EXP_NEG = -7, // 0 to -MAX
107 +
108 + // The exponent value at and above which toString returns exponential notation.
109 + // Number type: 21
110 + TO_EXP_POS = 21, // 0 to MAX
111 +
112 + // RANGE : [MIN_EXP, MAX_EXP]
113 +
114 + // The minimum exponent value, beneath which underflow to zero occurs.
115 + // Number type: -324 (5e-324)
116 + MIN_EXP = -1e7, // -1 to -MAX
117 +
118 + // The maximum exponent value, above which overflow to Infinity occurs.
119 + // Number type: 308 (1.7976931348623157e+308)
120 + // For MAX_EXP > 1e7, e.g. new BigNumber('1e100000000').plus(1) may be slow.
121 + MAX_EXP = 1e7, // 1 to MAX
122 +
123 + // Whether to use cryptographically-secure random number generation, if available.
124 + CRYPTO = false, // true or false
125 +
126 + // The modulo mode used when calculating the modulus: a mod n.
127 + // The quotient (q = a / n) is calculated according to the corresponding rounding mode.
128 + // The remainder (r) is calculated as: r = a - n * q.
129 + //
130 + // UP 0 The remainder is positive if the dividend is negative, else is negative.
131 + // DOWN 1 The remainder has the same sign as the dividend.
132 + // This modulo mode is commonly known as 'truncated division' and is
133 + // equivalent to (a % n) in JavaScript.
134 + // FLOOR 3 The remainder has the same sign as the divisor (Python %).
135 + // HALF_EVEN 6 This modulo mode implements the IEEE 754 remainder function.
136 + // EUCLID 9 Euclidian division. q = sign(n) * floor(a / abs(n)).
137 + // The remainder is always positive.
138 + //
139 + // The truncated division, floored division, Euclidian division and IEEE 754 remainder
140 + // modes are commonly used for the modulus operation.
141 + // Although the other rounding modes can also be used, they may not give useful results.
142 + MODULO_MODE = 1, // 0 to 9
143 +
144 + // The maximum number of significant digits of the result of the exponentiatedBy operation.
145 + // If POW_PRECISION is 0, there will be unlimited significant digits.
146 + POW_PRECISION = 0, // 0 to MAX
147 +
148 + // The format specification used by the BigNumber.prototype.toFormat method.
149 + FORMAT = {
150 + prefix: '',
151 + groupSize: 3,
152 + secondaryGroupSize: 0,
153 + groupSeparator: ',',
154 + decimalSeparator: '.',
155 + fractionGroupSize: 0,
156 + fractionGroupSeparator: '\xA0', // non-breaking space
157 + suffix: ''
158 + },
159 +
160 + // The alphabet used for base conversion. It must be at least 2 characters long, with no '+',
161 + // '-', '.', whitespace, or repeated character.
162 + // '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_'
163 + ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyz';
164 +
165 +
166 + //------------------------------------------------------------------------------------------
167 +
168 +
169 + // CONSTRUCTOR
170 +
171 +
172 + /*
173 + * The BigNumber constructor and exported function.
174 + * Create and return a new instance of a BigNumber object.
175 + *
176 + * v {number|string|BigNumber} A numeric value.
177 + * [b] {number} The base of v. Integer, 2 to ALPHABET.length inclusive.
178 + */
179 + function BigNumber(v, b) {
180 + var alphabet, c, caseChanged, e, i, isNum, len, str,
181 + x = this;
182 +
183 + // Enable constructor call without `new`.
184 + if (!(x instanceof BigNumber)) return new BigNumber(v, b);
185 +
186 + if (b == null) {
187 +
188 + if (v && v._isBigNumber === true) {
189 + x.s = v.s;
190 +
191 + if (!v.c || v.e > MAX_EXP) {
192 + x.c = x.e = null;
193 + } else if (v.e < MIN_EXP) {
194 + x.c = [x.e = 0];
195 + } else {
196 + x.e = v.e;
197 + x.c = v.c.slice();
198 + }
199 +
200 + return;
201 + }
202 +
203 + if ((isNum = typeof v == 'number') && v * 0 == 0) {
204 +
205 + // Use `1 / n` to handle minus zero also.
206 + x.s = 1 / v < 0 ? (v = -v, -1) : 1;
207 +
208 + // Fast path for integers, where n < 2147483648 (2**31).
209 + if (v === ~~v) {
210 + for (e = 0, i = v; i >= 10; i /= 10, e++);
211 +
212 + if (e > MAX_EXP) {
213 + x.c = x.e = null;
214 + } else {
215 + x.e = e;
216 + x.c = [v];
217 + }
218 +
219 + return;
220 + }
221 +
222 + str = String(v);
223 + } else {
224 +
225 + if (!isNumeric.test(str = String(v))) return parseNumeric(x, str, isNum);
226 +
227 + x.s = str.charCodeAt(0) == 45 ? (str = str.slice(1), -1) : 1;
228 + }
229 +
230 + // Decimal point?
231 + if ((e = str.indexOf('.')) > -1) str = str.replace('.', '');
232 +
233 + // Exponential form?
234 + if ((i = str.search(/e/i)) > 0) {
235 +
236 + // Determine exponent.
237 + if (e < 0) e = i;
238 + e += +str.slice(i + 1);
239 + str = str.substring(0, i);
240 + } else if (e < 0) {
241 +
242 + // Integer.
243 + e = str.length;
244 + }
245 +
246 + } else {
247 +
248 + // '[BigNumber Error] Base {not a primitive number|not an integer|out of range}: {b}'
249 + intCheck(b, 2, ALPHABET.length, 'Base');
250 +
251 + // Allow exponential notation to be used with base 10 argument, while
252 + // also rounding to DECIMAL_PLACES as with other bases.
253 + if (b == 10) {
254 + x = new BigNumber(v);
255 + return round(x, DECIMAL_PLACES + x.e + 1, ROUNDING_MODE);
256 + }
257 +
258 + str = String(v);
259 +
260 + if (isNum = typeof v == 'number') {
261 +
262 + // Avoid potential interpretation of Infinity and NaN as base 44+ values.
263 + if (v * 0 != 0) return parseNumeric(x, str, isNum, b);
264 +
265 + x.s = 1 / v < 0 ? (str = str.slice(1), -1) : 1;
266 +
267 + // '[BigNumber Error] Number primitive has more than 15 significant digits: {n}'
268 + if (BigNumber.DEBUG && str.replace(/^0\.0*|\./, '').length > 15) {
269 + throw Error
270 + (tooManyDigits + v);
271 + }
272 + } else {
273 + x.s = str.charCodeAt(0) === 45 ? (str = str.slice(1), -1) : 1;
274 + }
275 +
276 + alphabet = ALPHABET.slice(0, b);
277 + e = i = 0;
278 +
279 + // Check that str is a valid base b number.
280 + // Don't use RegExp, so alphabet can contain special characters.
281 + for (len = str.length; i < len; i++) {
282 + if (alphabet.indexOf(c = str.charAt(i)) < 0) {
283 + if (c == '.') {
284 +
285 + // If '.' is not the first character and it has not be found before.
286 + if (i > e) {
287 + e = len;
288 + continue;
289 + }
290 + } else if (!caseChanged) {
291 +
292 + // Allow e.g. hexadecimal 'FF' as well as 'ff'.
293 + if (str == str.toUpperCase() && (str = str.toLowerCase()) ||
294 + str == str.toLowerCase() && (str = str.toUpperCase())) {
295 + caseChanged = true;
296 + i = -1;
297 + e = 0;
298 + continue;
299 + }
300 + }
301 +
302 + return parseNumeric(x, String(v), isNum, b);
303 + }
304 + }
305 +
306 + // Prevent later check for length on converted number.
307 + isNum = false;
308 + str = convertBase(str, b, 10, x.s);
309 +
310 + // Decimal point?
311 + if ((e = str.indexOf('.')) > -1) str = str.replace('.', '');
312 + else e = str.length;
313 + }
314 +
315 + // Determine leading zeros.
316 + for (i = 0; str.charCodeAt(i) === 48; i++);
317 +
318 + // Determine trailing zeros.
319 + for (len = str.length; str.charCodeAt(--len) === 48;);
320 +
321 + if (str = str.slice(i, ++len)) {
322 + len -= i;
323 +
324 + // '[BigNumber Error] Number primitive has more than 15 significant digits: {n}'
325 + if (isNum && BigNumber.DEBUG &&
326 + len > 15 && (v > MAX_SAFE_INTEGER || v !== mathfloor(v))) {
327 + throw Error
328 + (tooManyDigits + (x.s * v));
329 + }
330 +
331 + // Overflow?
332 + if ((e = e - i - 1) > MAX_EXP) {
333 +
334 + // Infinity.
335 + x.c = x.e = null;
336 +
337 + // Underflow?
338 + } else if (e < MIN_EXP) {
339 +
340 + // Zero.
341 + x.c = [x.e = 0];
342 + } else {
343 + x.e = e;
344 + x.c = [];
345 +
346 + // Transform base
347 +
348 + // e is the base 10 exponent.
349 + // i is where to slice str to get the first element of the coefficient array.
350 + i = (e + 1) % LOG_BASE;
351 + if (e < 0) i += LOG_BASE; // i < 1
352 +
353 + if (i < len) {
354 + if (i) x.c.push(+str.slice(0, i));
355 +
356 + for (len -= LOG_BASE; i < len;) {
357 + x.c.push(+str.slice(i, i += LOG_BASE));
358 + }
359 +
360 + i = LOG_BASE - (str = str.slice(i)).length;
361 + } else {
362 + i -= len;
363 + }
364 +
365 + for (; i--; str += '0');
366 + x.c.push(+str);
367 + }
368 + } else {
369 +
370 + // Zero.
371 + x.c = [x.e = 0];
372 + }
373 + }
374 +
375 +
376 + // CONSTRUCTOR PROPERTIES
377 +
378 +
379 + BigNumber.clone = clone;
380 +
381 + BigNumber.ROUND_UP = 0;
382 + BigNumber.ROUND_DOWN = 1;
383 + BigNumber.ROUND_CEIL = 2;
384 + BigNumber.ROUND_FLOOR = 3;
385 + BigNumber.ROUND_HALF_UP = 4;
386 + BigNumber.ROUND_HALF_DOWN = 5;
387 + BigNumber.ROUND_HALF_EVEN = 6;
388 + BigNumber.ROUND_HALF_CEIL = 7;
389 + BigNumber.ROUND_HALF_FLOOR = 8;
390 + BigNumber.EUCLID = 9;
391 +
392 +
393 + /*
394 + * Configure infrequently-changing library-wide settings.
395 + *
396 + * Accept an object with the following optional properties (if the value of a property is
397 + * a number, it must be an integer within the inclusive range stated):
398 + *
399 + * DECIMAL_PLACES {number} 0 to MAX
400 + * ROUNDING_MODE {number} 0 to 8
401 + * EXPONENTIAL_AT {number|number[]} -MAX to MAX or [-MAX to 0, 0 to MAX]
402 + * RANGE {number|number[]} -MAX to MAX (not zero) or [-MAX to -1, 1 to MAX]
403 + * CRYPTO {boolean} true or false
404 + * MODULO_MODE {number} 0 to 9
405 + * POW_PRECISION {number} 0 to MAX
406 + * ALPHABET {string} A string of two or more unique characters which does
407 + * not contain '.'.
408 + * FORMAT {object} An object with some of the following properties:
409 + * prefix {string}
410 + * groupSize {number}
411 + * secondaryGroupSize {number}
412 + * groupSeparator {string}
413 + * decimalSeparator {string}
414 + * fractionGroupSize {number}
415 + * fractionGroupSeparator {string}
416 + * suffix {string}
417 + *
418 + * (The values assigned to the above FORMAT object properties are not checked for validity.)
419 + *
420 + * E.g.
421 + * BigNumber.config({ DECIMAL_PLACES : 20, ROUNDING_MODE : 4 })
422 + *
423 + * Ignore properties/parameters set to null or undefined, except for ALPHABET.
424 + *
425 + * Return an object with the properties current values.
426 + */
427 + BigNumber.config = BigNumber.set = function (obj) {
428 + var p, v;
429 +
430 + if (obj != null) {
431 +
432 + if (typeof obj == 'object') {
433 +
434 + // DECIMAL_PLACES {number} Integer, 0 to MAX inclusive.
435 + // '[BigNumber Error] DECIMAL_PLACES {not a primitive number|not an integer|out of range}: {v}'
436 + if (obj.hasOwnProperty(p = 'DECIMAL_PLACES')) {
437 + v = obj[p];
438 + intCheck(v, 0, MAX, p);
439 + DECIMAL_PLACES = v;
440 + }
441 +
442 + // ROUNDING_MODE {number} Integer, 0 to 8 inclusive.
443 + // '[BigNumber Error] ROUNDING_MODE {not a primitive number|not an integer|out of range}: {v}'
444 + if (obj.hasOwnProperty(p = 'ROUNDING_MODE')) {
445 + v = obj[p];
446 + intCheck(v, 0, 8, p);
447 + ROUNDING_MODE = v;
448 + }
449 +
450 + // EXPONENTIAL_AT {number|number[]}
451 + // Integer, -MAX to MAX inclusive or
452 + // [integer -MAX to 0 inclusive, 0 to MAX inclusive].
453 + // '[BigNumber Error] EXPONENTIAL_AT {not a primitive number|not an integer|out of range}: {v}'
454 + if (obj.hasOwnProperty(p = 'EXPONENTIAL_AT')) {
455 + v = obj[p];
456 + if (v && v.pop) {
457 + intCheck(v[0], -MAX, 0, p);
458 + intCheck(v[1], 0, MAX, p);
459 + TO_EXP_NEG = v[0];
460 + TO_EXP_POS = v[1];
461 + } else {
462 + intCheck(v, -MAX, MAX, p);
463 + TO_EXP_NEG = -(TO_EXP_POS = v < 0 ? -v : v);
464 + }
465 + }
466 +
467 + // RANGE {number|number[]} Non-zero integer, -MAX to MAX inclusive or
468 + // [integer -MAX to -1 inclusive, integer 1 to MAX inclusive].
469 + // '[BigNumber Error] RANGE {not a primitive number|not an integer|out of range|cannot be zero}: {v}'
470 + if (obj.hasOwnProperty(p = 'RANGE')) {
471 + v = obj[p];
472 + if (v && v.pop) {
473 + intCheck(v[0], -MAX, -1, p);
474 + intCheck(v[1], 1, MAX, p);
475 + MIN_EXP = v[0];
476 + MAX_EXP = v[1];
477 + } else {
478 + intCheck(v, -MAX, MAX, p);
479 + if (v) {
480 + MIN_EXP = -(MAX_EXP = v < 0 ? -v : v);
481 + } else {
482 + throw Error
483 + (bignumberError + p + ' cannot be zero: ' + v);
484 + }
485 + }
486 + }
487 +
488 + // CRYPTO {boolean} true or false.
489 + // '[BigNumber Error] CRYPTO not true or false: {v}'
490 + // '[BigNumber Error] crypto unavailable'
491 + if (obj.hasOwnProperty(p = 'CRYPTO')) {
492 + v = obj[p];
493 + if (v === !!v) {
494 + if (v) {
495 + if (typeof crypto != 'undefined' && crypto &&
496 + (crypto.getRandomValues || crypto.randomBytes)) {
497 + CRYPTO = v;
498 + } else {
499 + CRYPTO = !v;
500 + throw Error
501 + (bignumberError + 'crypto unavailable');
502 + }
503 + } else {
504 + CRYPTO = v;
505 + }
506 + } else {
507 + throw Error
508 + (bignumberError + p + ' not true or false: ' + v);
509 + }
510 + }
511 +
512 + // MODULO_MODE {number} Integer, 0 to 9 inclusive.
513 + // '[BigNumber Error] MODULO_MODE {not a primitive number|not an integer|out of range}: {v}'
514 + if (obj.hasOwnProperty(p = 'MODULO_MODE')) {
515 + v = obj[p];
516 + intCheck(v, 0, 9, p);
517 + MODULO_MODE = v;
518 + }
519 +
520 + // POW_PRECISION {number} Integer, 0 to MAX inclusive.
521 + // '[BigNumber Error] POW_PRECISION {not a primitive number|not an integer|out of range}: {v}'
522 + if (obj.hasOwnProperty(p = 'POW_PRECISION')) {
523 + v = obj[p];
524 + intCheck(v, 0, MAX, p);
525 + POW_PRECISION = v;
526 + }
527 +
528 + // FORMAT {object}
529 + // '[BigNumber Error] FORMAT not an object: {v}'
530 + if (obj.hasOwnProperty(p = 'FORMAT')) {
531 + v = obj[p];
532 + if (typeof v == 'object') FORMAT = v;
533 + else throw Error
534 + (bignumberError + p + ' not an object: ' + v);
535 + }
536 +
537 + // ALPHABET {string}
538 + // '[BigNumber Error] ALPHABET invalid: {v}'
539 + if (obj.hasOwnProperty(p = 'ALPHABET')) {
540 + v = obj[p];
541 +
542 + // Disallow if only one character,
543 + // or if it contains '+', '-', '.', whitespace, or a repeated character.
544 + if (typeof v == 'string' && !/^.$|[+-.\s]|(.).*\1/.test(v)) {
545 + ALPHABET = v;
546 + } else {
547 + throw Error
548 + (bignumberError + p + ' invalid: ' + v);
549 + }
550 + }
551 +
552 + } else {
553 +
554 + // '[BigNumber Error] Object expected: {v}'
555 + throw Error
556 + (bignumberError + 'Object expected: ' + obj);
557 + }
558 + }
559 +
560 + return {
561 + DECIMAL_PLACES: DECIMAL_PLACES,
562 + ROUNDING_MODE: ROUNDING_MODE,
563 + EXPONENTIAL_AT: [TO_EXP_NEG, TO_EXP_POS],
564 + RANGE: [MIN_EXP, MAX_EXP],
565 + CRYPTO: CRYPTO,
566 + MODULO_MODE: MODULO_MODE,
567 + POW_PRECISION: POW_PRECISION,
568 + FORMAT: FORMAT,
569 + ALPHABET: ALPHABET
570 + };
571 + };
572 +
573 +
574 + /*
575 + * Return true if v is a BigNumber instance, otherwise return false.
576 + *
577 + * If BigNumber.DEBUG is true, throw if a BigNumber instance is not well-formed.
578 + *
579 + * v {any}
580 + *
581 + * '[BigNumber Error] Invalid BigNumber: {v}'
582 + */
583 + BigNumber.isBigNumber = function (v) {
584 + if (!v || v._isBigNumber !== true) return false;
585 + if (!BigNumber.DEBUG) return true;
586 +
587 + var i, n,
588 + c = v.c,
589 + e = v.e,
590 + s = v.s;
591 +
592 + out: if ({}.toString.call(c) == '[object Array]') {
593 +
594 + if ((s === 1 || s === -1) && e >= -MAX && e <= MAX && e === mathfloor(e)) {
595 +
596 + // If the first element is zero, the BigNumber value must be zero.
597 + if (c[0] === 0) {
598 + if (e === 0 && c.length === 1) return true;
599 + break out;
600 + }
601 +
602 + // Calculate number of digits that c[0] should have, based on the exponent.
603 + i = (e + 1) % LOG_BASE;
604 + if (i < 1) i += LOG_BASE;
605 +
606 + // Calculate number of digits of c[0].
607 + //if (Math.ceil(Math.log(c[0] + 1) / Math.LN10) == i) {
608 + if (String(c[0]).length == i) {
609 +
610 + for (i = 0; i < c.length; i++) {
611 + n = c[i];
612 + if (n < 0 || n >= BASE || n !== mathfloor(n)) break out;
613 + }
614 +
615 + // Last element cannot be zero, unless it is the only element.
616 + if (n !== 0) return true;
617 + }
618 + }
619 +
620 + // Infinity/NaN
621 + } else if (c === null && e === null && (s === null || s === 1 || s === -1)) {
622 + return true;
623 + }
624 +
625 + throw Error
626 + (bignumberError + 'Invalid BigNumber: ' + v);
627 + };
628 +
629 +
630 + /*
631 + * Return a new BigNumber whose value is the maximum of the arguments.
632 + *
633 + * arguments {number|string|BigNumber}
634 + */
635 + BigNumber.maximum = BigNumber.max = function () {
636 + return maxOrMin(arguments, P.lt);
637 + };
638 +
639 +
640 + /*
641 + * Return a new BigNumber whose value is the minimum of the arguments.
642 + *
643 + * arguments {number|string|BigNumber}
644 + */
645 + BigNumber.minimum = BigNumber.min = function () {
646 + return maxOrMin(arguments, P.gt);
647 + };
648 +
649 +
650 + /*
651 + * Return a new BigNumber with a random value equal to or greater than 0 and less than 1,
652 + * and with dp, or DECIMAL_PLACES if dp is omitted, decimal places (or less if trailing
653 + * zeros are produced).
654 + *
655 + * [dp] {number} Decimal places. Integer, 0 to MAX inclusive.
656 + *
657 + * '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {dp}'
658 + * '[BigNumber Error] crypto unavailable'
659 + */
660 + BigNumber.random = (function () {
661 + var pow2_53 = 0x20000000000000;
662 +
663 + // Return a 53 bit integer n, where 0 <= n < 9007199254740992.
664 + // Check if Math.random() produces more than 32 bits of randomness.
665 + // If it does, assume at least 53 bits are produced, otherwise assume at least 30 bits.
666 + // 0x40000000 is 2^30, 0x800000 is 2^23, 0x1fffff is 2^21 - 1.
667 + var random53bitInt = (Math.random() * pow2_53) & 0x1fffff
668 + ? function () { return mathfloor(Math.random() * pow2_53); }
669 + : function () { return ((Math.random() * 0x40000000 | 0) * 0x800000) +
670 + (Math.random() * 0x800000 | 0); };
671 +
672 + return function (dp) {
673 + var a, b, e, k, v,
674 + i = 0,
675 + c = [],
676 + rand = new BigNumber(ONE);
677 +
678 + if (dp == null) dp = DECIMAL_PLACES;
679 + else intCheck(dp, 0, MAX);
680 +
681 + k = mathceil(dp / LOG_BASE);
682 +
683 + if (CRYPTO) {
684 +
685 + // Browsers supporting crypto.getRandomValues.
686 + if (crypto.getRandomValues) {
687 +
688 + a = crypto.getRandomValues(new Uint32Array(k *= 2));
689 +
690 + for (; i < k;) {
691 +
692 + // 53 bits:
693 + // ((Math.pow(2, 32) - 1) * Math.pow(2, 21)).toString(2)
694 + // 11111 11111111 11111111 11111111 11100000 00000000 00000000
695 + // ((Math.pow(2, 32) - 1) >>> 11).toString(2)
696 + // 11111 11111111 11111111
697 + // 0x20000 is 2^21.
698 + v = a[i] * 0x20000 + (a[i + 1] >>> 11);
699 +
700 + // Rejection sampling:
701 + // 0 <= v < 9007199254740992
702 + // Probability that v >= 9e15, is
703 + // 7199254740992 / 9007199254740992 ~= 0.0008, i.e. 1 in 1251
704 + if (v >= 9e15) {
705 + b = crypto.getRandomValues(new Uint32Array(2));
706 + a[i] = b[0];
707 + a[i + 1] = b[1];
708 + } else {
709 +
710 + // 0 <= v <= 8999999999999999
711 + // 0 <= (v % 1e14) <= 99999999999999
712 + c.push(v % 1e14);
713 + i += 2;
714 + }
715 + }
716 + i = k / 2;
717 +
718 + // Node.js supporting crypto.randomBytes.
719 + } else if (crypto.randomBytes) {
720 +
721 + // buffer
722 + a = crypto.randomBytes(k *= 7);
723 +
724 + for (; i < k;) {
725 +
726 + // 0x1000000000000 is 2^48, 0x10000000000 is 2^40
727 + // 0x100000000 is 2^32, 0x1000000 is 2^24
728 + // 11111 11111111 11111111 11111111 11111111 11111111 11111111
729 + // 0 <= v < 9007199254740992
730 + v = ((a[i] & 31) * 0x1000000000000) + (a[i + 1] * 0x10000000000) +
731 + (a[i + 2] * 0x100000000) + (a[i + 3] * 0x1000000) +
732 + (a[i + 4] << 16) + (a[i + 5] << 8) + a[i + 6];
733 +
734 + if (v >= 9e15) {
735 + crypto.randomBytes(7).copy(a, i);
736 + } else {
737 +
738 + // 0 <= (v % 1e14) <= 99999999999999
739 + c.push(v % 1e14);
740 + i += 7;
741 + }
742 + }
743 + i = k / 7;
744 + } else {
745 + CRYPTO = false;
746 + throw Error
747 + (bignumberError + 'crypto unavailable');
748 + }
749 + }
750 +
751 + // Use Math.random.
752 + if (!CRYPTO) {
753 +
754 + for (; i < k;) {
755 + v = random53bitInt();
756 + if (v < 9e15) c[i++] = v % 1e14;
757 + }
758 + }
759 +
760 + k = c[--i];
761 + dp %= LOG_BASE;
762 +
763 + // Convert trailing digits to zeros according to dp.
764 + if (k && dp) {
765 + v = POWS_TEN[LOG_BASE - dp];
766 + c[i] = mathfloor(k / v) * v;
767 + }
768 +
769 + // Remove trailing elements which are zero.
770 + for (; c[i] === 0; c.pop(), i--);
771 +
772 + // Zero?
773 + if (i < 0) {
774 + c = [e = 0];
775 + } else {
776 +
777 + // Remove leading elements which are zero and adjust exponent accordingly.
778 + for (e = -1 ; c[0] === 0; c.splice(0, 1), e -= LOG_BASE);
779 +
780 + // Count the digits of the first element of c to determine leading zeros, and...
781 + for (i = 1, v = c[0]; v >= 10; v /= 10, i++);
782 +
783 + // adjust the exponent accordingly.
784 + if (i < LOG_BASE) e -= LOG_BASE - i;
785 + }
786 +
787 + rand.e = e;
788 + rand.c = c;
789 + return rand;
790 + };
791 + })();
792 +
793 +
794 + /*
795 + * Return a BigNumber whose value is the sum of the arguments.
796 + *
797 + * arguments {number|string|BigNumber}
798 + */
799 + BigNumber.sum = function () {
800 + var i = 1,
801 + args = arguments,
802 + sum = new BigNumber(args[0]);
803 + for (; i < args.length;) sum = sum.plus(args[i++]);
804 + return sum;
805 + };
806 +
807 +
808 + // PRIVATE FUNCTIONS
809 +
810 +
811 + // Called by BigNumber and BigNumber.prototype.toString.
812 + convertBase = (function () {
813 + var decimal = '0123456789';
814 +
815 + /*
816 + * Convert string of baseIn to an array of numbers of baseOut.
817 + * Eg. toBaseOut('255', 10, 16) returns [15, 15].
818 + * Eg. toBaseOut('ff', 16, 10) returns [2, 5, 5].
819 + */
820 + function toBaseOut(str, baseIn, baseOut, alphabet) {
821 + var j,
822 + arr = [0],
823 + arrL,
824 + i = 0,
825 + len = str.length;
826 +
827 + for (; i < len;) {
828 + for (arrL = arr.length; arrL--; arr[arrL] *= baseIn);
829 +
830 + arr[0] += alphabet.indexOf(str.charAt(i++));
831 +
832 + for (j = 0; j < arr.length; j++) {
833 +
834 + if (arr[j] > baseOut - 1) {
835 + if (arr[j + 1] == null) arr[j + 1] = 0;
836 + arr[j + 1] += arr[j] / baseOut | 0;
837 + arr[j] %= baseOut;
838 + }
839 + }
840 + }
841 +
842 + return arr.reverse();
843 + }
844 +
845 + // Convert a numeric string of baseIn to a numeric string of baseOut.
846 + // If the caller is toString, we are converting from base 10 to baseOut.
847 + // If the caller is BigNumber, we are converting from baseIn to base 10.
848 + return function (str, baseIn, baseOut, sign, callerIsToString) {
849 + var alphabet, d, e, k, r, x, xc, y,
850 + i = str.indexOf('.'),
851 + dp = DECIMAL_PLACES,
852 + rm = ROUNDING_MODE;
853 +
854 + // Non-integer.
855 + if (i >= 0) {
856 + k = POW_PRECISION;
857 +
858 + // Unlimited precision.
859 + POW_PRECISION = 0;
860 + str = str.replace('.', '');
861 + y = new BigNumber(baseIn);
862 + x = y.pow(str.length - i);
863 + POW_PRECISION = k;
864 +
865 + // Convert str as if an integer, then restore the fraction part by dividing the
866 + // result by its base raised to a power.
867 +
868 + y.c = toBaseOut(toFixedPoint(coeffToString(x.c), x.e, '0'),
869 + 10, baseOut, decimal);
870 + y.e = y.c.length;
871 + }
872 +
873 + // Convert the number as integer.
874 +
875 + xc = toBaseOut(str, baseIn, baseOut, callerIsToString
876 + ? (alphabet = ALPHABET, decimal)
877 + : (alphabet = decimal, ALPHABET));
878 +
879 + // xc now represents str as an integer and converted to baseOut. e is the exponent.
880 + e = k = xc.length;
881 +
882 + // Remove trailing zeros.
883 + for (; xc[--k] == 0; xc.pop());
884 +
885 + // Zero?
886 + if (!xc[0]) return alphabet.charAt(0);
887 +
888 + // Does str represent an integer? If so, no need for the division.
889 + if (i < 0) {
890 + --e;
891 + } else {
892 + x.c = xc;
893 + x.e = e;
894 +
895 + // The sign is needed for correct rounding.
896 + x.s = sign;
897 + x = div(x, y, dp, rm, baseOut);
898 + xc = x.c;
899 + r = x.r;
900 + e = x.e;
901 + }
902 +
903 + // xc now represents str converted to baseOut.
904 +
905 + // THe index of the rounding digit.
906 + d = e + dp + 1;
907 +
908 + // The rounding digit: the digit to the right of the digit that may be rounded up.
909 + i = xc[d];
910 +
911 + // Look at the rounding digits and mode to determine whether to round up.
912 +
913 + k = baseOut / 2;
914 + r = r || d < 0 || xc[d + 1] != null;
915 +
916 + r = rm < 4 ? (i != null || r) && (rm == 0 || rm == (x.s < 0 ? 3 : 2))
917 + : i > k || i == k &&(rm == 4 || r || rm == 6 && xc[d - 1] & 1 ||
918 + rm == (x.s < 0 ? 8 : 7));
919 +
920 + // If the index of the rounding digit is not greater than zero, or xc represents
921 + // zero, then the result of the base conversion is zero or, if rounding up, a value
922 + // such as 0.00001.
923 + if (d < 1 || !xc[0]) {
924 +
925 + // 1^-dp or 0
926 + str = r ? toFixedPoint(alphabet.charAt(1), -dp, alphabet.charAt(0)) : alphabet.charAt(0);
927 + } else {
928 +
929 + // Truncate xc to the required number of decimal places.
930 + xc.length = d;
931 +
932 + // Round up?
933 + if (r) {
934 +
935 + // Rounding up may mean the previous digit has to be rounded up and so on.
936 + for (--baseOut; ++xc[--d] > baseOut;) {
937 + xc[d] = 0;
938 +
939 + if (!d) {
940 + ++e;
941 + xc = [1].concat(xc);
942 + }
943 + }
944 + }
945 +
946 + // Determine trailing zeros.
947 + for (k = xc.length; !xc[--k];);
948 +
949 + // E.g. [4, 11, 15] becomes 4bf.
950 + for (i = 0, str = ''; i <= k; str += alphabet.charAt(xc[i++]));
951 +
952 + // Add leading zeros, decimal point and trailing zeros as required.
953 + str = toFixedPoint(str, e, alphabet.charAt(0));
954 + }
955 +
956 + // The caller will add the sign.
957 + return str;
958 + };
959 + })();
960 +
961 +
962 + // Perform division in the specified base. Called by div and convertBase.
963 + div = (function () {
964 +
965 + // Assume non-zero x and k.
966 + function multiply(x, k, base) {
967 + var m, temp, xlo, xhi,
968 + carry = 0,
969 + i = x.length,
970 + klo = k % SQRT_BASE,
971 + khi = k / SQRT_BASE | 0;
972 +
973 + for (x = x.slice(); i--;) {
974 + xlo = x[i] % SQRT_BASE;
975 + xhi = x[i] / SQRT_BASE | 0;
976 + m = khi * xlo + xhi * klo;
977 + temp = klo * xlo + ((m % SQRT_BASE) * SQRT_BASE) + carry;
978 + carry = (temp / base | 0) + (m / SQRT_BASE | 0) + khi * xhi;
979 + x[i] = temp % base;
980 + }
981 +
982 + if (carry) x = [carry].concat(x);
983 +
984 + return x;
985 + }
986 +
987 + function compare(a, b, aL, bL) {
988 + var i, cmp;
989 +
990 + if (aL != bL) {
991 + cmp = aL > bL ? 1 : -1;
992 + } else {
993 +
994 + for (i = cmp = 0; i < aL; i++) {
995 +
996 + if (a[i] != b[i]) {
997 + cmp = a[i] > b[i] ? 1 : -1;
998 + break;
999 + }
1000 + }
1001 + }
1002 +
1003 + return cmp;
1004 + }
1005 +
1006 + function subtract(a, b, aL, base) {
1007 + var i = 0;
1008 +
1009 + // Subtract b from a.
1010 + for (; aL--;) {
1011 + a[aL] -= i;
1012 + i = a[aL] < b[aL] ? 1 : 0;
1013 + a[aL] = i * base + a[aL] - b[aL];
1014 + }
1015 +
1016 + // Remove leading zeros.
1017 + for (; !a[0] && a.length > 1; a.splice(0, 1));
1018 + }
1019 +
1020 + // x: dividend, y: divisor.
1021 + return function (x, y, dp, rm, base) {
1022 + var cmp, e, i, more, n, prod, prodL, q, qc, rem, remL, rem0, xi, xL, yc0,
1023 + yL, yz,
1024 + s = x.s == y.s ? 1 : -1,
1025 + xc = x.c,
1026 + yc = y.c;
1027 +
1028 + // Either NaN, Infinity or 0?
1029 + if (!xc || !xc[0] || !yc || !yc[0]) {
1030 +
1031 + return new BigNumber(
1032 +
1033 + // Return NaN if either NaN, or both Infinity or 0.
1034 + !x.s || !y.s || (xc ? yc && xc[0] == yc[0] : !yc) ? NaN :
1035 +
1036 + // Return ±0 if x is ±0 or y is ±Infinity, or return ±Infinity as y is ±0.
1037 + xc && xc[0] == 0 || !yc ? s * 0 : s / 0
1038 + );
1039 + }
1040 +
1041 + q = new BigNumber(s);
1042 + qc = q.c = [];
1043 + e = x.e - y.e;
1044 + s = dp + e + 1;
1045 +
1046 + if (!base) {
1047 + base = BASE;
1048 + e = bitFloor(x.e / LOG_BASE) - bitFloor(y.e / LOG_BASE);
1049 + s = s / LOG_BASE | 0;
1050 + }
1051 +
1052 + // Result exponent may be one less then the current value of e.
1053 + // The coefficients of the BigNumbers from convertBase may have trailing zeros.
1054 + for (i = 0; yc[i] == (xc[i] || 0); i++);
1055 +
1056 + if (yc[i] > (xc[i] || 0)) e--;
1057 +
1058 + if (s < 0) {
1059 + qc.push(1);
1060 + more = true;
1061 + } else {
1062 + xL = xc.length;
1063 + yL = yc.length;
1064 + i = 0;
1065 + s += 2;
1066 +
1067 + // Normalise xc and yc so highest order digit of yc is >= base / 2.
1068 +
1069 + n = mathfloor(base / (yc[0] + 1));
1070 +
1071 + // Not necessary, but to handle odd bases where yc[0] == (base / 2) - 1.
1072 + // if (n > 1 || n++ == 1 && yc[0] < base / 2) {
1073 + if (n > 1) {
1074 + yc = multiply(yc, n, base);
1075 + xc = multiply(xc, n, base);
1076 + yL = yc.length;
1077 + xL = xc.length;
1078 + }
1079 +
1080 + xi = yL;
1081 + rem = xc.slice(0, yL);
1082 + remL = rem.length;
1083 +
1084 + // Add zeros to make remainder as long as divisor.
1085 + for (; remL < yL; rem[remL++] = 0);
1086 + yz = yc.slice();
1087 + yz = [0].concat(yz);
1088 + yc0 = yc[0];
1089 + if (yc[1] >= base / 2) yc0++;
1090 + // Not necessary, but to prevent trial digit n > base, when using base 3.
1091 + // else if (base == 3 && yc0 == 1) yc0 = 1 + 1e-15;
1092 +
1093 + do {
1094 + n = 0;
1095 +
1096 + // Compare divisor and remainder.
1097 + cmp = compare(yc, rem, yL, remL);
1098 +
1099 + // If divisor < remainder.
1100 + if (cmp < 0) {
1101 +
1102 + // Calculate trial digit, n.
1103 +
1104 + rem0 = rem[0];
1105 + if (yL != remL) rem0 = rem0 * base + (rem[1] || 0);
1106 +
1107 + // n is how many times the divisor goes into the current remainder.
1108 + n = mathfloor(rem0 / yc0);
1109 +
1110 + // Algorithm:
1111 + // product = divisor multiplied by trial digit (n).
1112 + // Compare product and remainder.
1113 + // If product is greater than remainder:
1114 + // Subtract divisor from product, decrement trial digit.
1115 + // Subtract product from remainder.
1116 + // If product was less than remainder at the last compare:
1117 + // Compare new remainder and divisor.
1118 + // If remainder is greater than divisor:
1119 + // Subtract divisor from remainder, increment trial digit.
1120 +
1121 + if (n > 1) {
1122 +
1123 + // n may be > base only when base is 3.
1124 + if (n >= base) n = base - 1;
1125 +
1126 + // product = divisor * trial digit.
1127 + prod = multiply(yc, n, base);
1128 + prodL = prod.length;
1129 + remL = rem.length;
1130 +
1131 + // Compare product and remainder.
1132 + // If product > remainder then trial digit n too high.
1133 + // n is 1 too high about 5% of the time, and is not known to have
1134 + // ever been more than 1 too high.
1135 + while (compare(prod, rem, prodL, remL) == 1) {
1136 + n--;
1137 +
1138 + // Subtract divisor from product.
1139 + subtract(prod, yL < prodL ? yz : yc, prodL, base);
1140 + prodL = prod.length;
1141 + cmp = 1;
1142 + }
1143 + } else {
1144 +
1145 + // n is 0 or 1, cmp is -1.
1146 + // If n is 0, there is no need to compare yc and rem again below,
1147 + // so change cmp to 1 to avoid it.
1148 + // If n is 1, leave cmp as -1, so yc and rem are compared again.
1149 + if (n == 0) {
1150 +
1151 + // divisor < remainder, so n must be at least 1.
1152 + cmp = n = 1;
1153 + }
1154 +
1155 + // product = divisor
1156 + prod = yc.slice();
1157 + prodL = prod.length;
1158 + }
1159 +
1160 + if (prodL < remL) prod = [0].concat(prod);
1161 +
1162 + // Subtract product from remainder.
1163 + subtract(rem, prod, remL, base);
1164 + remL = rem.length;
1165 +
1166 + // If product was < remainder.
1167 + if (cmp == -1) {
1168 +
1169 + // Compare divisor and new remainder.
1170 + // If divisor < new remainder, subtract divisor from remainder.
1171 + // Trial digit n too low.
1172 + // n is 1 too low about 5% of the time, and very rarely 2 too low.
1173 + while (compare(yc, rem, yL, remL) < 1) {
1174 + n++;
1175 +
1176 + // Subtract divisor from remainder.
1177 + subtract(rem, yL < remL ? yz : yc, remL, base);
1178 + remL = rem.length;
1179 + }
1180 + }
1181 + } else if (cmp === 0) {
1182 + n++;
1183 + rem = [0];
1184 + } // else cmp === 1 and n will be 0
1185 +
1186 + // Add the next digit, n, to the result array.
1187 + qc[i++] = n;
1188 +
1189 + // Update the remainder.
1190 + if (rem[0]) {
1191 + rem[remL++] = xc[xi] || 0;
1192 + } else {
1193 + rem = [xc[xi]];
1194 + remL = 1;
1195 + }
1196 + } while ((xi++ < xL || rem[0] != null) && s--);
1197 +
1198 + more = rem[0] != null;
1199 +
1200 + // Leading zero?
1201 + if (!qc[0]) qc.splice(0, 1);
1202 + }
1203 +
1204 + if (base == BASE) {
1205 +
1206 + // To calculate q.e, first get the number of digits of qc[0].
1207 + for (i = 1, s = qc[0]; s >= 10; s /= 10, i++);
1208 +
1209 + round(q, dp + (q.e = i + e * LOG_BASE - 1) + 1, rm, more);
1210 +
1211 + // Caller is convertBase.
1212 + } else {
1213 + q.e = e;
1214 + q.r = +more;
1215 + }
1216 +
1217 + return q;
1218 + };
1219 + })();
1220 +
1221 +
1222 + /*
1223 + * Return a string representing the value of BigNumber n in fixed-point or exponential
1224 + * notation rounded to the specified decimal places or significant digits.
1225 + *
1226 + * n: a BigNumber.
1227 + * i: the index of the last digit required (i.e. the digit that may be rounded up).
1228 + * rm: the rounding mode.
1229 + * id: 1 (toExponential) or 2 (toPrecision).
1230 + */
1231 + function format(n, i, rm, id) {
1232 + var c0, e, ne, len, str;
1233 +
1234 + if (rm == null) rm = ROUNDING_MODE;
1235 + else intCheck(rm, 0, 8);
1236 +
1237 + if (!n.c) return n.toString();
1238 +
1239 + c0 = n.c[0];
1240 + ne = n.e;
1241 +
1242 + if (i == null) {
1243 + str = coeffToString(n.c);
1244 + str = id == 1 || id == 2 && (ne <= TO_EXP_NEG || ne >= TO_EXP_POS)
1245 + ? toExponential(str, ne)
1246 + : toFixedPoint(str, ne, '0');
1247 + } else {
1248 + n = round(new BigNumber(n), i, rm);
1249 +
1250 + // n.e may have changed if the value was rounded up.
1251 + e = n.e;
1252 +
1253 + str = coeffToString(n.c);
1254 + len = str.length;
1255 +
1256 + // toPrecision returns exponential notation if the number of significant digits
1257 + // specified is less than the number of digits necessary to represent the integer
1258 + // part of the value in fixed-point notation.
1259 +
1260 + // Exponential notation.
1261 + if (id == 1 || id == 2 && (i <= e || e <= TO_EXP_NEG)) {
1262 +
1263 + // Append zeros?
1264 + for (; len < i; str += '0', len++);
1265 + str = toExponential(str, e);
1266 +
1267 + // Fixed-point notation.
1268 + } else {
1269 + i -= ne;
1270 + str = toFixedPoint(str, e, '0');
1271 +
1272 + // Append zeros?
1273 + if (e + 1 > len) {
1274 + if (--i > 0) for (str += '.'; i--; str += '0');
1275 + } else {
1276 + i += e - len;
1277 + if (i > 0) {
1278 + if (e + 1 == len) str += '.';
1279 + for (; i--; str += '0');
1280 + }
1281 + }
1282 + }
1283 + }
1284 +
1285 + return n.s < 0 && c0 ? '-' + str : str;
1286 + }
1287 +
1288 +
1289 + // Handle BigNumber.max and BigNumber.min.
1290 + function maxOrMin(args, method) {
1291 + var n,
1292 + i = 1,
1293 + m = new BigNumber(args[0]);
1294 +
1295 + for (; i < args.length; i++) {
1296 + n = new BigNumber(args[i]);
1297 +
1298 + // If any number is NaN, return NaN.
1299 + if (!n.s) {
1300 + m = n;
1301 + break;
1302 + } else if (method.call(m, n)) {
1303 + m = n;
1304 + }
1305 + }
1306 +
1307 + return m;
1308 + }
1309 +
1310 +
1311 + /*
1312 + * Strip trailing zeros, calculate base 10 exponent and check against MIN_EXP and MAX_EXP.
1313 + * Called by minus, plus and times.
1314 + */
1315 + function normalise(n, c, e) {
1316 + var i = 1,
1317 + j = c.length;
1318 +
1319 + // Remove trailing zeros.
1320 + for (; !c[--j]; c.pop());
1321 +
1322 + // Calculate the base 10 exponent. First get the number of digits of c[0].
1323 + for (j = c[0]; j >= 10; j /= 10, i++);
1324 +
1325 + // Overflow?
1326 + if ((e = i + e * LOG_BASE - 1) > MAX_EXP) {
1327 +
1328 + // Infinity.
1329 + n.c = n.e = null;
1330 +
1331 + // Underflow?
1332 + } else if (e < MIN_EXP) {
1333 +
1334 + // Zero.
1335 + n.c = [n.e = 0];
1336 + } else {
1337 + n.e = e;
1338 + n.c = c;
1339 + }
1340 +
1341 + return n;
1342 + }
1343 +
1344 +
1345 + // Handle values that fail the validity test in BigNumber.
1346 + parseNumeric = (function () {
1347 + var basePrefix = /^(-?)0([xbo])(?=\w[\w.]*$)/i,
1348 + dotAfter = /^([^.]+)\.$/,
1349 + dotBefore = /^\.([^.]+)$/,
1350 + isInfinityOrNaN = /^-?(Infinity|NaN)$/,
1351 + whitespaceOrPlus = /^\s*\+(?=[\w.])|^\s+|\s+$/g;
1352 +
1353 + return function (x, str, isNum, b) {
1354 + var base,
1355 + s = isNum ? str : str.replace(whitespaceOrPlus, '');
1356 +
1357 + // No exception on ±Infinity or NaN.
1358 + if (isInfinityOrNaN.test(s)) {
1359 + x.s = isNaN(s) ? null : s < 0 ? -1 : 1;
1360 + } else {
1361 + if (!isNum) {
1362 +
1363 + // basePrefix = /^(-?)0([xbo])(?=\w[\w.]*$)/i
1364 + s = s.replace(basePrefix, function (m, p1, p2) {
1365 + base = (p2 = p2.toLowerCase()) == 'x' ? 16 : p2 == 'b' ? 2 : 8;
1366 + return !b || b == base ? p1 : m;
1367 + });
1368 +
1369 + if (b) {
1370 + base = b;
1371 +
1372 + // E.g. '1.' to '1', '.1' to '0.1'
1373 + s = s.replace(dotAfter, '$1').replace(dotBefore, '0.$1');
1374 + }
1375 +
1376 + if (str != s) return new BigNumber(s, base);
1377 + }
1378 +
1379 + // '[BigNumber Error] Not a number: {n}'
1380 + // '[BigNumber Error] Not a base {b} number: {n}'
1381 + if (BigNumber.DEBUG) {
1382 + throw Error
1383 + (bignumberError + 'Not a' + (b ? ' base ' + b : '') + ' number: ' + str);
1384 + }
1385 +
1386 + // NaN
1387 + x.s = null;
1388 + }
1389 +
1390 + x.c = x.e = null;
1391 + }
1392 + })();
1393 +
1394 +
1395 + /*
1396 + * Round x to sd significant digits using rounding mode rm. Check for over/under-flow.
1397 + * If r is truthy, it is known that there are more digits after the rounding digit.
1398 + */
1399 + function round(x, sd, rm, r) {
1400 + var d, i, j, k, n, ni, rd,
1401 + xc = x.c,
1402 + pows10 = POWS_TEN;
1403 +
1404 + // if x is not Infinity or NaN...
1405 + if (xc) {
1406 +
1407 + // rd is the rounding digit, i.e. the digit after the digit that may be rounded up.
1408 + // n is a base 1e14 number, the value of the element of array x.c containing rd.
1409 + // ni is the index of n within x.c.
1410 + // d is the number of digits of n.
1411 + // i is the index of rd within n including leading zeros.
1412 + // j is the actual index of rd within n (if < 0, rd is a leading zero).
1413 + out: {
1414 +
1415 + // Get the number of digits of the first element of xc.
1416 + for (d = 1, k = xc[0]; k >= 10; k /= 10, d++);
1417 + i = sd - d;
1418 +
1419 + // If the rounding digit is in the first element of xc...
1420 + if (i < 0) {
1421 + i += LOG_BASE;
1422 + j = sd;
1423 + n = xc[ni = 0];
1424 +
1425 + // Get the rounding digit at index j of n.
1426 + rd = n / pows10[d - j - 1] % 10 | 0;
1427 + } else {
1428 + ni = mathceil((i + 1) / LOG_BASE);
1429 +
1430 + if (ni >= xc.length) {
1431 +
1432 + if (r) {
1433 +
1434 + // Needed by sqrt.
1435 + for (; xc.length <= ni; xc.push(0));
1436 + n = rd = 0;
1437 + d = 1;
1438 + i %= LOG_BASE;
1439 + j = i - LOG_BASE + 1;
1440 + } else {
1441 + break out;
1442 + }
1443 + } else {
1444 + n = k = xc[ni];
1445 +
1446 + // Get the number of digits of n.
1447 + for (d = 1; k >= 10; k /= 10, d++);
1448 +
1449 + // Get the index of rd within n.
1450 + i %= LOG_BASE;
1451 +
1452 + // Get the index of rd within n, adjusted for leading zeros.
1453 + // The number of leading zeros of n is given by LOG_BASE - d.
1454 + j = i - LOG_BASE + d;
1455 +
1456 + // Get the rounding digit at index j of n.
1457 + rd = j < 0 ? 0 : n / pows10[d - j - 1] % 10 | 0;
1458 + }
1459 + }
1460 +
1461 + r = r || sd < 0 ||
1462 +
1463 + // Are there any non-zero digits after the rounding digit?
1464 + // The expression n % pows10[d - j - 1] returns all digits of n to the right
1465 + // of the digit at j, e.g. if n is 908714 and j is 2, the expression gives 714.
1466 + xc[ni + 1] != null || (j < 0 ? n : n % pows10[d - j - 1]);
1467 +
1468 + r = rm < 4
1469 + ? (rd || r) && (rm == 0 || rm == (x.s < 0 ? 3 : 2))
1470 + : rd > 5 || rd == 5 && (rm == 4 || r || rm == 6 &&
1471 +
1472 + // Check whether the digit to the left of the rounding digit is odd.
1473 + ((i > 0 ? j > 0 ? n / pows10[d - j] : 0 : xc[ni - 1]) % 10) & 1 ||
1474 + rm == (x.s < 0 ? 8 : 7));
1475 +
1476 + if (sd < 1 || !xc[0]) {
1477 + xc.length = 0;
1478 +
1479 + if (r) {
1480 +
1481 + // Convert sd to decimal places.
1482 + sd -= x.e + 1;
1483 +
1484 + // 1, 0.1, 0.01, 0.001, 0.0001 etc.
1485 + xc[0] = pows10[(LOG_BASE - sd % LOG_BASE) % LOG_BASE];
1486 + x.e = -sd || 0;
1487 + } else {
1488 +
1489 + // Zero.
1490 + xc[0] = x.e = 0;
1491 + }
1492 +
1493 + return x;
1494 + }
1495 +
1496 + // Remove excess digits.
1497 + if (i == 0) {
1498 + xc.length = ni;
1499 + k = 1;
1500 + ni--;
1501 + } else {
1502 + xc.length = ni + 1;
1503 + k = pows10[LOG_BASE - i];
1504 +
1505 + // E.g. 56700 becomes 56000 if 7 is the rounding digit.
1506 + // j > 0 means i > number of leading zeros of n.
1507 + xc[ni] = j > 0 ? mathfloor(n / pows10[d - j] % pows10[j]) * k : 0;
1508 + }
1509 +
1510 + // Round up?
1511 + if (r) {
1512 +
1513 + for (; ;) {
1514 +
1515 + // If the digit to be rounded up is in the first element of xc...
1516 + if (ni == 0) {
1517 +
1518 + // i will be the length of xc[0] before k is added.
1519 + for (i = 1, j = xc[0]; j >= 10; j /= 10, i++);
1520 + j = xc[0] += k;
1521 + for (k = 1; j >= 10; j /= 10, k++);
1522 +
1523 + // if i != k the length has increased.
1524 + if (i != k) {
1525 + x.e++;
1526 + if (xc[0] == BASE) xc[0] = 1;
1527 + }
1528 +
1529 + break;
1530 + } else {
1531 + xc[ni] += k;
1532 + if (xc[ni] != BASE) break;
1533 + xc[ni--] = 0;
1534 + k = 1;
1535 + }
1536 + }
1537 + }
1538 +
1539 + // Remove trailing zeros.
1540 + for (i = xc.length; xc[--i] === 0; xc.pop());
1541 + }
1542 +
1543 + // Overflow? Infinity.
1544 + if (x.e > MAX_EXP) {
1545 + x.c = x.e = null;
1546 +
1547 + // Underflow? Zero.
1548 + } else if (x.e < MIN_EXP) {
1549 + x.c = [x.e = 0];
1550 + }
1551 + }
1552 +
1553 + return x;
1554 + }
1555 +
1556 +
1557 + function valueOf(n) {
1558 + var str,
1559 + e = n.e;
1560 +
1561 + if (e === null) return n.toString();
1562 +
1563 + str = coeffToString(n.c);
1564 +
1565 + str = e <= TO_EXP_NEG || e >= TO_EXP_POS
1566 + ? toExponential(str, e)
1567 + : toFixedPoint(str, e, '0');
1568 +
1569 + return n.s < 0 ? '-' + str : str;
1570 + }
1571 +
1572 +
1573 + // PROTOTYPE/INSTANCE METHODS
1574 +
1575 +
1576 + /*
1577 + * Return a new BigNumber whose value is the absolute value of this BigNumber.
1578 + */
1579 + P.absoluteValue = P.abs = function () {
1580 + var x = new BigNumber(this);
1581 + if (x.s < 0) x.s = 1;
1582 + return x;
1583 + };
1584 +
1585 +
1586 + /*
1587 + * Return
1588 + * 1 if the value of this BigNumber is greater than the value of BigNumber(y, b),
1589 + * -1 if the value of this BigNumber is less than the value of BigNumber(y, b),
1590 + * 0 if they have the same value,
1591 + * or null if the value of either is NaN.
1592 + */
1593 + P.comparedTo = function (y, b) {
1594 + return compare(this, new BigNumber(y, b));
1595 + };
1596 +
1597 +
1598 + /*
1599 + * If dp is undefined or null or true or false, return the number of decimal places of the
1600 + * value of this BigNumber, or null if the value of this BigNumber is ±Infinity or NaN.
1601 + *
1602 + * Otherwise, if dp is a number, return a new BigNumber whose value is the value of this
1603 + * BigNumber rounded to a maximum of dp decimal places using rounding mode rm, or
1604 + * ROUNDING_MODE if rm is omitted.
1605 + *
1606 + * [dp] {number} Decimal places: integer, 0 to MAX inclusive.
1607 + * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
1608 + *
1609 + * '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {dp|rm}'
1610 + */
1611 + P.decimalPlaces = P.dp = function (dp, rm) {
1612 + var c, n, v,
1613 + x = this;
1614 +
1615 + if (dp != null) {
1616 + intCheck(dp, 0, MAX);
1617 + if (rm == null) rm = ROUNDING_MODE;
1618 + else intCheck(rm, 0, 8);
1619 +
1620 + return round(new BigNumber(x), dp + x.e + 1, rm);
1621 + }
1622 +
1623 + if (!(c = x.c)) return null;
1624 + n = ((v = c.length - 1) - bitFloor(this.e / LOG_BASE)) * LOG_BASE;
1625 +
1626 + // Subtract the number of trailing zeros of the last number.
1627 + if (v = c[v]) for (; v % 10 == 0; v /= 10, n--);
1628 + if (n < 0) n = 0;
1629 +
1630 + return n;
1631 + };
1632 +
1633 +
1634 + /*
1635 + * n / 0 = I
1636 + * n / N = N
1637 + * n / I = 0
1638 + * 0 / n = 0
1639 + * 0 / 0 = N
1640 + * 0 / N = N
1641 + * 0 / I = 0
1642 + * N / n = N
1643 + * N / 0 = N
1644 + * N / N = N
1645 + * N / I = N
1646 + * I / n = I
1647 + * I / 0 = I
1648 + * I / N = N
1649 + * I / I = N
1650 + *
1651 + * Return a new BigNumber whose value is the value of this BigNumber divided by the value of
1652 + * BigNumber(y, b), rounded according to DECIMAL_PLACES and ROUNDING_MODE.
1653 + */
1654 + P.dividedBy = P.div = function (y, b) {
1655 + return div(this, new BigNumber(y, b), DECIMAL_PLACES, ROUNDING_MODE);
1656 + };
1657 +
1658 +
1659 + /*
1660 + * Return a new BigNumber whose value is the integer part of dividing the value of this
1661 + * BigNumber by the value of BigNumber(y, b).
1662 + */
1663 + P.dividedToIntegerBy = P.idiv = function (y, b) {
1664 + return div(this, new BigNumber(y, b), 0, 1);
1665 + };
1666 +
1667 +
1668 + /*
1669 + * Return a BigNumber whose value is the value of this BigNumber exponentiated by n.
1670 + *
1671 + * If m is present, return the result modulo m.
1672 + * If n is negative round according to DECIMAL_PLACES and ROUNDING_MODE.
1673 + * If POW_PRECISION is non-zero and m is not present, round to POW_PRECISION using ROUNDING_MODE.
1674 + *
1675 + * The modular power operation works efficiently when x, n, and m are integers, otherwise it
1676 + * is equivalent to calculating x.exponentiatedBy(n).modulo(m) with a POW_PRECISION of 0.
1677 + *
1678 + * n {number|string|BigNumber} The exponent. An integer.
1679 + * [m] {number|string|BigNumber} The modulus.
1680 + *
1681 + * '[BigNumber Error] Exponent not an integer: {n}'
1682 + */
1683 + P.exponentiatedBy = P.pow = function (n, m) {
1684 + var half, isModExp, i, k, more, nIsBig, nIsNeg, nIsOdd, y,
1685 + x = this;
1686 +
1687 + n = new BigNumber(n);
1688 +
1689 + // Allow NaN and ±Infinity, but not other non-integers.
1690 + if (n.c && !n.isInteger()) {
1691 + throw Error
1692 + (bignumberError + 'Exponent not an integer: ' + valueOf(n));
1693 + }
1694 +
1695 + if (m != null) m = new BigNumber(m);
1696 +
1697 + // Exponent of MAX_SAFE_INTEGER is 15.
1698 + nIsBig = n.e > 14;
1699 +
1700 + // If x is NaN, ±Infinity, ±0 or ±1, or n is ±Infinity, NaN or ±0.
1701 + if (!x.c || !x.c[0] || x.c[0] == 1 && !x.e && x.c.length == 1 || !n.c || !n.c[0]) {
1702 +
1703 + // The sign of the result of pow when x is negative depends on the evenness of n.
1704 + // If +n overflows to ±Infinity, the evenness of n would be not be known.
1705 + y = new BigNumber(Math.pow(+valueOf(x), nIsBig ? 2 - isOdd(n) : +valueOf(n)));
1706 + return m ? y.mod(m) : y;
1707 + }
1708 +
1709 + nIsNeg = n.s < 0;
1710 +
1711 + if (m) {
1712 +
1713 + // x % m returns NaN if abs(m) is zero, or m is NaN.
1714 + if (m.c ? !m.c[0] : !m.s) return new BigNumber(NaN);
1715 +
1716 + isModExp = !nIsNeg && x.isInteger() && m.isInteger();
1717 +
1718 + if (isModExp) x = x.mod(m);
1719 +
1720 + // Overflow to ±Infinity: >=2**1e10 or >=1.0000024**1e15.
1721 + // Underflow to ±0: <=0.79**1e10 or <=0.9999975**1e15.
1722 + } else if (n.e > 9 && (x.e > 0 || x.e < -1 || (x.e == 0
1723 + // [1, 240000000]
1724 + ? x.c[0] > 1 || nIsBig && x.c[1] >= 24e7
1725 + // [80000000000000] [99999750000000]
1726 + : x.c[0] < 8e13 || nIsBig && x.c[0] <= 9999975e7))) {
1727 +
1728 + // If x is negative and n is odd, k = -0, else k = 0.
1729 + k = x.s < 0 && isOdd(n) ? -0 : 0;
1730 +
1731 + // If x >= 1, k = ±Infinity.
1732 + if (x.e > -1) k = 1 / k;
1733 +
1734 + // If n is negative return ±0, else return ±Infinity.
1735 + return new BigNumber(nIsNeg ? 1 / k : k);
1736 +
1737 + } else if (POW_PRECISION) {
1738 +
1739 + // Truncating each coefficient array to a length of k after each multiplication
1740 + // equates to truncating significant digits to POW_PRECISION + [28, 41],
1741 + // i.e. there will be a minimum of 28 guard digits retained.
1742 + k = mathceil(POW_PRECISION / LOG_BASE + 2);
1743 + }
1744 +
1745 + if (nIsBig) {
1746 + half = new BigNumber(0.5);
1747 + if (nIsNeg) n.s = 1;
1748 + nIsOdd = isOdd(n);
1749 + } else {
1750 + i = Math.abs(+valueOf(n));
1751 + nIsOdd = i % 2;
1752 + }
1753 +
1754 + y = new BigNumber(ONE);
1755 +
1756 + // Performs 54 loop iterations for n of 9007199254740991.
1757 + for (; ;) {
1758 +
1759 + if (nIsOdd) {
1760 + y = y.times(x);
1761 + if (!y.c) break;
1762 +
1763 + if (k) {
1764 + if (y.c.length > k) y.c.length = k;
1765 + } else if (isModExp) {
1766 + y = y.mod(m); //y = y.minus(div(y, m, 0, MODULO_MODE).times(m));
1767 + }
1768 + }
1769 +
1770 + if (i) {
1771 + i = mathfloor(i / 2);
1772 + if (i === 0) break;
1773 + nIsOdd = i % 2;
1774 + } else {
1775 + n = n.times(half);
1776 + round(n, n.e + 1, 1);
1777 +
1778 + if (n.e > 14) {
1779 + nIsOdd = isOdd(n);
1780 + } else {
1781 + i = +valueOf(n);
1782 + if (i === 0) break;
1783 + nIsOdd = i % 2;
1784 + }
1785 + }
1786 +
1787 + x = x.times(x);
1788 +
1789 + if (k) {
1790 + if (x.c && x.c.length > k) x.c.length = k;
1791 + } else if (isModExp) {
1792 + x = x.mod(m); //x = x.minus(div(x, m, 0, MODULO_MODE).times(m));
1793 + }
1794 + }
1795 +
1796 + if (isModExp) return y;
1797 + if (nIsNeg) y = ONE.div(y);
1798 +
1799 + return m ? y.mod(m) : k ? round(y, POW_PRECISION, ROUNDING_MODE, more) : y;
1800 + };
1801 +
1802 +
1803 + /*
1804 + * Return a new BigNumber whose value is the value of this BigNumber rounded to an integer
1805 + * using rounding mode rm, or ROUNDING_MODE if rm is omitted.
1806 + *
1807 + * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
1808 + *
1809 + * '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {rm}'
1810 + */
1811 + P.integerValue = function (rm) {
1812 + var n = new BigNumber(this);
1813 + if (rm == null) rm = ROUNDING_MODE;
1814 + else intCheck(rm, 0, 8);
1815 + return round(n, n.e + 1, rm);
1816 + };
1817 +
1818 +
1819 + /*
1820 + * Return true if the value of this BigNumber is equal to the value of BigNumber(y, b),
1821 + * otherwise return false.
1822 + */
1823 + P.isEqualTo = P.eq = function (y, b) {
1824 + return compare(this, new BigNumber(y, b)) === 0;
1825 + };
1826 +
1827 +
1828 + /*
1829 + * Return true if the value of this BigNumber is a finite number, otherwise return false.
1830 + */
1831 + P.isFinite = function () {
1832 + return !!this.c;
1833 + };
1834 +
1835 +
1836 + /*
1837 + * Return true if the value of this BigNumber is greater than the value of BigNumber(y, b),
1838 + * otherwise return false.
1839 + */
1840 + P.isGreaterThan = P.gt = function (y, b) {
1841 + return compare(this, new BigNumber(y, b)) > 0;
1842 + };
1843 +
1844 +
1845 + /*
1846 + * Return true if the value of this BigNumber is greater than or equal to the value of
1847 + * BigNumber(y, b), otherwise return false.
1848 + */
1849 + P.isGreaterThanOrEqualTo = P.gte = function (y, b) {
1850 + return (b = compare(this, new BigNumber(y, b))) === 1 || b === 0;
1851 +
1852 + };
1853 +
1854 +
1855 + /*
1856 + * Return true if the value of this BigNumber is an integer, otherwise return false.
1857 + */
1858 + P.isInteger = function () {
1859 + return !!this.c && bitFloor(this.e / LOG_BASE) > this.c.length - 2;
1860 + };
1861 +
1862 +
1863 + /*
1864 + * Return true if the value of this BigNumber is less than the value of BigNumber(y, b),
1865 + * otherwise return false.
1866 + */
1867 + P.isLessThan = P.lt = function (y, b) {
1868 + return compare(this, new BigNumber(y, b)) < 0;
1869 + };
1870 +
1871 +
1872 + /*
1873 + * Return true if the value of this BigNumber is less than or equal to the value of
1874 + * BigNumber(y, b), otherwise return false.
1875 + */
1876 + P.isLessThanOrEqualTo = P.lte = function (y, b) {
1877 + return (b = compare(this, new BigNumber(y, b))) === -1 || b === 0;
1878 + };
1879 +
1880 +
1881 + /*
1882 + * Return true if the value of this BigNumber is NaN, otherwise return false.
1883 + */
1884 + P.isNaN = function () {
1885 + return !this.s;
1886 + };
1887 +
1888 +
1889 + /*
1890 + * Return true if the value of this BigNumber is negative, otherwise return false.
1891 + */
1892 + P.isNegative = function () {
1893 + return this.s < 0;
1894 + };
1895 +
1896 +
1897 + /*
1898 + * Return true if the value of this BigNumber is positive, otherwise return false.
1899 + */
1900 + P.isPositive = function () {
1901 + return this.s > 0;
1902 + };
1903 +
1904 +
1905 + /*
1906 + * Return true if the value of this BigNumber is 0 or -0, otherwise return false.
1907 + */
1908 + P.isZero = function () {
1909 + return !!this.c && this.c[0] == 0;
1910 + };
1911 +
1912 +
1913 + /*
1914 + * n - 0 = n
1915 + * n - N = N
1916 + * n - I = -I
1917 + * 0 - n = -n
1918 + * 0 - 0 = 0
1919 + * 0 - N = N
1920 + * 0 - I = -I
1921 + * N - n = N
1922 + * N - 0 = N
1923 + * N - N = N
1924 + * N - I = N
1925 + * I - n = I
1926 + * I - 0 = I
1927 + * I - N = N
1928 + * I - I = N
1929 + *
1930 + * Return a new BigNumber whose value is the value of this BigNumber minus the value of
1931 + * BigNumber(y, b).
1932 + */
1933 + P.minus = function (y, b) {
1934 + var i, j, t, xLTy,
1935 + x = this,
1936 + a = x.s;
1937 +
1938 + y = new BigNumber(y, b);
1939 + b = y.s;
1940 +
1941 + // Either NaN?
1942 + if (!a || !b) return new BigNumber(NaN);
1943 +
1944 + // Signs differ?
1945 + if (a != b) {
1946 + y.s = -b;
1947 + return x.plus(y);
1948 + }
1949 +
1950 + var xe = x.e / LOG_BASE,
1951 + ye = y.e / LOG_BASE,
1952 + xc = x.c,
1953 + yc = y.c;
1954 +
1955 + if (!xe || !ye) {
1956 +
1957 + // Either Infinity?
1958 + if (!xc || !yc) return xc ? (y.s = -b, y) : new BigNumber(yc ? x : NaN);
1959 +
1960 + // Either zero?
1961 + if (!xc[0] || !yc[0]) {
1962 +
1963 + // Return y if y is non-zero, x if x is non-zero, or zero if both are zero.
1964 + return yc[0] ? (y.s = -b, y) : new BigNumber(xc[0] ? x :
1965 +
1966 + // IEEE 754 (2008) 6.3: n - n = -0 when rounding to -Infinity
1967 + ROUNDING_MODE == 3 ? -0 : 0);
1968 + }
1969 + }
1970 +
1971 + xe = bitFloor(xe);
1972 + ye = bitFloor(ye);
1973 + xc = xc.slice();
1974 +
1975 + // Determine which is the bigger number.
1976 + if (a = xe - ye) {
1977 +
1978 + if (xLTy = a < 0) {
1979 + a = -a;
1980 + t = xc;
1981 + } else {
1982 + ye = xe;
1983 + t = yc;
1984 + }
1985 +
1986 + t.reverse();
1987 +
1988 + // Prepend zeros to equalise exponents.
1989 + for (b = a; b--; t.push(0));
1990 + t.reverse();
1991 + } else {
1992 +
1993 + // Exponents equal. Check digit by digit.
1994 + j = (xLTy = (a = xc.length) < (b = yc.length)) ? a : b;
1995 +
1996 + for (a = b = 0; b < j; b++) {
1997 +
1998 + if (xc[b] != yc[b]) {
1999 + xLTy = xc[b] < yc[b];
2000 + break;
2001 + }
2002 + }
2003 + }
2004 +
2005 + // x < y? Point xc to the array of the bigger number.
2006 + if (xLTy) t = xc, xc = yc, yc = t, y.s = -y.s;
2007 +
2008 + b = (j = yc.length) - (i = xc.length);
2009 +
2010 + // Append zeros to xc if shorter.
2011 + // No need to add zeros to yc if shorter as subtract only needs to start at yc.length.
2012 + if (b > 0) for (; b--; xc[i++] = 0);
2013 + b = BASE - 1;
2014 +
2015 + // Subtract yc from xc.
2016 + for (; j > a;) {
2017 +
2018 + if (xc[--j] < yc[j]) {
2019 + for (i = j; i && !xc[--i]; xc[i] = b);
2020 + --xc[i];
2021 + xc[j] += BASE;
2022 + }
2023 +
2024 + xc[j] -= yc[j];
2025 + }
2026 +
2027 + // Remove leading zeros and adjust exponent accordingly.
2028 + for (; xc[0] == 0; xc.splice(0, 1), --ye);
2029 +
2030 + // Zero?
2031 + if (!xc[0]) {
2032 +
2033 + // Following IEEE 754 (2008) 6.3,
2034 + // n - n = +0 but n - n = -0 when rounding towards -Infinity.
2035 + y.s = ROUNDING_MODE == 3 ? -1 : 1;
2036 + y.c = [y.e = 0];
2037 + return y;
2038 + }
2039 +
2040 + // No need to check for Infinity as +x - +y != Infinity && -x - -y != Infinity
2041 + // for finite x and y.
2042 + return normalise(y, xc, ye);
2043 + };
2044 +
2045 +
2046 + /*
2047 + * n % 0 = N
2048 + * n % N = N
2049 + * n % I = n
2050 + * 0 % n = 0
2051 + * -0 % n = -0
2052 + * 0 % 0 = N
2053 + * 0 % N = N
2054 + * 0 % I = 0
2055 + * N % n = N
2056 + * N % 0 = N
2057 + * N % N = N
2058 + * N % I = N
2059 + * I % n = N
2060 + * I % 0 = N
2061 + * I % N = N
2062 + * I % I = N
2063 + *
2064 + * Return a new BigNumber whose value is the value of this BigNumber modulo the value of
2065 + * BigNumber(y, b). The result depends on the value of MODULO_MODE.
2066 + */
2067 + P.modulo = P.mod = function (y, b) {
2068 + var q, s,
2069 + x = this;
2070 +
2071 + y = new BigNumber(y, b);
2072 +
2073 + // Return NaN if x is Infinity or NaN, or y is NaN or zero.
2074 + if (!x.c || !y.s || y.c && !y.c[0]) {
2075 + return new BigNumber(NaN);
2076 +
2077 + // Return x if y is Infinity or x is zero.
2078 + } else if (!y.c || x.c && !x.c[0]) {
2079 + return new BigNumber(x);
2080 + }
2081 +
2082 + if (MODULO_MODE == 9) {
2083 +
2084 + // Euclidian division: q = sign(y) * floor(x / abs(y))
2085 + // r = x - qy where 0 <= r < abs(y)
2086 + s = y.s;
2087 + y.s = 1;
2088 + q = div(x, y, 0, 3);
2089 + y.s = s;
2090 + q.s *= s;
2091 + } else {
2092 + q = div(x, y, 0, MODULO_MODE);
2093 + }
2094 +
2095 + y = x.minus(q.times(y));
2096 +
2097 + // To match JavaScript %, ensure sign of zero is sign of dividend.
2098 + if (!y.c[0] && MODULO_MODE == 1) y.s = x.s;
2099 +
2100 + return y;
2101 + };
2102 +
2103 +
2104 + /*
2105 + * n * 0 = 0
2106 + * n * N = N
2107 + * n * I = I
2108 + * 0 * n = 0
2109 + * 0 * 0 = 0
2110 + * 0 * N = N
2111 + * 0 * I = N
2112 + * N * n = N
2113 + * N * 0 = N
2114 + * N * N = N
2115 + * N * I = N
2116 + * I * n = I
2117 + * I * 0 = N
2118 + * I * N = N
2119 + * I * I = I
2120 + *
2121 + * Return a new BigNumber whose value is the value of this BigNumber multiplied by the value
2122 + * of BigNumber(y, b).
2123 + */
2124 + P.multipliedBy = P.times = function (y, b) {
2125 + var c, e, i, j, k, m, xcL, xlo, xhi, ycL, ylo, yhi, zc,
2126 + base, sqrtBase,
2127 + x = this,
2128 + xc = x.c,
2129 + yc = (y = new BigNumber(y, b)).c;
2130 +
2131 + // Either NaN, ±Infinity or ±0?
2132 + if (!xc || !yc || !xc[0] || !yc[0]) {
2133 +
2134 + // Return NaN if either is NaN, or one is 0 and the other is Infinity.
2135 + if (!x.s || !y.s || xc && !xc[0] && !yc || yc && !yc[0] && !xc) {
2136 + y.c = y.e = y.s = null;
2137 + } else {
2138 + y.s *= x.s;
2139 +
2140 + // Return ±Infinity if either is ±Infinity.
2141 + if (!xc || !yc) {
2142 + y.c = y.e = null;
2143 +
2144 + // Return ±0 if either is ±0.
2145 + } else {
2146 + y.c = [0];
2147 + y.e = 0;
2148 + }
2149 + }
2150 +
2151 + return y;
2152 + }
2153 +
2154 + e = bitFloor(x.e / LOG_BASE) + bitFloor(y.e / LOG_BASE);
2155 + y.s *= x.s;
2156 + xcL = xc.length;
2157 + ycL = yc.length;
2158 +
2159 + // Ensure xc points to longer array and xcL to its length.
2160 + if (xcL < ycL) zc = xc, xc = yc, yc = zc, i = xcL, xcL = ycL, ycL = i;
2161 +
2162 + // Initialise the result array with zeros.
2163 + for (i = xcL + ycL, zc = []; i--; zc.push(0));
2164 +
2165 + base = BASE;
2166 + sqrtBase = SQRT_BASE;
2167 +
2168 + for (i = ycL; --i >= 0;) {
2169 + c = 0;
2170 + ylo = yc[i] % sqrtBase;
2171 + yhi = yc[i] / sqrtBase | 0;
2172 +
2173 + for (k = xcL, j = i + k; j > i;) {
2174 + xlo = xc[--k] % sqrtBase;
2175 + xhi = xc[k] / sqrtBase | 0;
2176 + m = yhi * xlo + xhi * ylo;
2177 + xlo = ylo * xlo + ((m % sqrtBase) * sqrtBase) + zc[j] + c;
2178 + c = (xlo / base | 0) + (m / sqrtBase | 0) + yhi * xhi;
2179 + zc[j--] = xlo % base;
2180 + }
2181 +
2182 + zc[j] = c;
2183 + }
2184 +
2185 + if (c) {
2186 + ++e;
2187 + } else {
2188 + zc.splice(0, 1);
2189 + }
2190 +
2191 + return normalise(y, zc, e);
2192 + };
2193 +
2194 +
2195 + /*
2196 + * Return a new BigNumber whose value is the value of this BigNumber negated,
2197 + * i.e. multiplied by -1.
2198 + */
2199 + P.negated = function () {
2200 + var x = new BigNumber(this);
2201 + x.s = -x.s || null;
2202 + return x;
2203 + };
2204 +
2205 +
2206 + /*
2207 + * n + 0 = n
2208 + * n + N = N
2209 + * n + I = I
2210 + * 0 + n = n
2211 + * 0 + 0 = 0
2212 + * 0 + N = N
2213 + * 0 + I = I
2214 + * N + n = N
2215 + * N + 0 = N
2216 + * N + N = N
2217 + * N + I = N
2218 + * I + n = I
2219 + * I + 0 = I
2220 + * I + N = N
2221 + * I + I = I
2222 + *
2223 + * Return a new BigNumber whose value is the value of this BigNumber plus the value of
2224 + * BigNumber(y, b).
2225 + */
2226 + P.plus = function (y, b) {
2227 + var t,
2228 + x = this,
2229 + a = x.s;
2230 +
2231 + y = new BigNumber(y, b);
2232 + b = y.s;
2233 +
2234 + // Either NaN?
2235 + if (!a || !b) return new BigNumber(NaN);
2236 +
2237 + // Signs differ?
2238 + if (a != b) {
2239 + y.s = -b;
2240 + return x.minus(y);
2241 + }
2242 +
2243 + var xe = x.e / LOG_BASE,
2244 + ye = y.e / LOG_BASE,
2245 + xc = x.c,
2246 + yc = y.c;
2247 +
2248 + if (!xe || !ye) {
2249 +
2250 + // Return ±Infinity if either ±Infinity.
2251 + if (!xc || !yc) return new BigNumber(a / 0);
2252 +
2253 + // Either zero?
2254 + // Return y if y is non-zero, x if x is non-zero, or zero if both are zero.
2255 + if (!xc[0] || !yc[0]) return yc[0] ? y : new BigNumber(xc[0] ? x : a * 0);
2256 + }
2257 +
2258 + xe = bitFloor(xe);
2259 + ye = bitFloor(ye);
2260 + xc = xc.slice();
2261 +
2262 + // Prepend zeros to equalise exponents. Faster to use reverse then do unshifts.
2263 + if (a = xe - ye) {
2264 + if (a > 0) {
2265 + ye = xe;
2266 + t = yc;
2267 + } else {
2268 + a = -a;
2269 + t = xc;
2270 + }
2271 +
2272 + t.reverse();
2273 + for (; a--; t.push(0));
2274 + t.reverse();
2275 + }
2276 +
2277 + a = xc.length;
2278 + b = yc.length;
2279 +
2280 + // Point xc to the longer array, and b to the shorter length.
2281 + if (a - b < 0) t = yc, yc = xc, xc = t, b = a;
2282 +
2283 + // Only start adding at yc.length - 1 as the further digits of xc can be ignored.
2284 + for (a = 0; b;) {
2285 + a = (xc[--b] = xc[b] + yc[b] + a) / BASE | 0;
2286 + xc[b] = BASE === xc[b] ? 0 : xc[b] % BASE;
2287 + }
2288 +
2289 + if (a) {
2290 + xc = [a].concat(xc);
2291 + ++ye;
2292 + }
2293 +
2294 + // No need to check for zero, as +x + +y != 0 && -x + -y != 0
2295 + // ye = MAX_EXP + 1 possible
2296 + return normalise(y, xc, ye);
2297 + };
2298 +
2299 +
2300 + /*
2301 + * If sd is undefined or null or true or false, return the number of significant digits of
2302 + * the value of this BigNumber, or null if the value of this BigNumber is ±Infinity or NaN.
2303 + * If sd is true include integer-part trailing zeros in the count.
2304 + *
2305 + * Otherwise, if sd is a number, return a new BigNumber whose value is the value of this
2306 + * BigNumber rounded to a maximum of sd significant digits using rounding mode rm, or
2307 + * ROUNDING_MODE if rm is omitted.
2308 + *
2309 + * sd {number|boolean} number: significant digits: integer, 1 to MAX inclusive.
2310 + * boolean: whether to count integer-part trailing zeros: true or false.
2311 + * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
2312 + *
2313 + * '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {sd|rm}'
2314 + */
2315 + P.precision = P.sd = function (sd, rm) {
2316 + var c, n, v,
2317 + x = this;
2318 +
2319 + if (sd != null && sd !== !!sd) {
2320 + intCheck(sd, 1, MAX);
2321 + if (rm == null) rm = ROUNDING_MODE;
2322 + else intCheck(rm, 0, 8);
2323 +
2324 + return round(new BigNumber(x), sd, rm);
2325 + }
2326 +
2327 + if (!(c = x.c)) return null;
2328 + v = c.length - 1;
2329 + n = v * LOG_BASE + 1;
2330 +
2331 + if (v = c[v]) {
2332 +
2333 + // Subtract the number of trailing zeros of the last element.
2334 + for (; v % 10 == 0; v /= 10, n--);
2335 +
2336 + // Add the number of digits of the first element.
2337 + for (v = c[0]; v >= 10; v /= 10, n++);
2338 + }
2339 +
2340 + if (sd && x.e + 1 > n) n = x.e + 1;
2341 +
2342 + return n;
2343 + };
2344 +
2345 +
2346 + /*
2347 + * Return a new BigNumber whose value is the value of this BigNumber shifted by k places
2348 + * (powers of 10). Shift to the right if n > 0, and to the left if n < 0.
2349 + *
2350 + * k {number} Integer, -MAX_SAFE_INTEGER to MAX_SAFE_INTEGER inclusive.
2351 + *
2352 + * '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {k}'
2353 + */
2354 + P.shiftedBy = function (k) {
2355 + intCheck(k, -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
2356 + return this.times('1e' + k);
2357 + };
2358 +
2359 +
2360 + /*
2361 + * sqrt(-n) = N
2362 + * sqrt(N) = N
2363 + * sqrt(-I) = N
2364 + * sqrt(I) = I
2365 + * sqrt(0) = 0
2366 + * sqrt(-0) = -0
2367 + *
2368 + * Return a new BigNumber whose value is the square root of the value of this BigNumber,
2369 + * rounded according to DECIMAL_PLACES and ROUNDING_MODE.
2370 + */
2371 + P.squareRoot = P.sqrt = function () {
2372 + var m, n, r, rep, t,
2373 + x = this,
2374 + c = x.c,
2375 + s = x.s,
2376 + e = x.e,
2377 + dp = DECIMAL_PLACES + 4,
2378 + half = new BigNumber('0.5');
2379 +
2380 + // Negative/NaN/Infinity/zero?
2381 + if (s !== 1 || !c || !c[0]) {
2382 + return new BigNumber(!s || s < 0 && (!c || c[0]) ? NaN : c ? x : 1 / 0);
2383 + }
2384 +
2385 + // Initial estimate.
2386 + s = Math.sqrt(+valueOf(x));
2387 +
2388 + // Math.sqrt underflow/overflow?
2389 + // Pass x to Math.sqrt as integer, then adjust the exponent of the result.
2390 + if (s == 0 || s == 1 / 0) {
2391 + n = coeffToString(c);
2392 + if ((n.length + e) % 2 == 0) n += '0';
2393 + s = Math.sqrt(+n);
2394 + e = bitFloor((e + 1) / 2) - (e < 0 || e % 2);
2395 +
2396 + if (s == 1 / 0) {
2397 + n = '1e' + e;
2398 + } else {
2399 + n = s.toExponential();
2400 + n = n.slice(0, n.indexOf('e') + 1) + e;
2401 + }
2402 +
2403 + r = new BigNumber(n);
2404 + } else {
2405 + r = new BigNumber(s + '');
2406 + }
2407 +
2408 + // Check for zero.
2409 + // r could be zero if MIN_EXP is changed after the this value was created.
2410 + // This would cause a division by zero (x/t) and hence Infinity below, which would cause
2411 + // coeffToString to throw.
2412 + if (r.c[0]) {
2413 + e = r.e;
2414 + s = e + dp;
2415 + if (s < 3) s = 0;
2416 +
2417 + // Newton-Raphson iteration.
2418 + for (; ;) {
2419 + t = r;
2420 + r = half.times(t.plus(div(x, t, dp, 1)));
2421 +
2422 + if (coeffToString(t.c).slice(0, s) === (n = coeffToString(r.c)).slice(0, s)) {
2423 +
2424 + // The exponent of r may here be one less than the final result exponent,
2425 + // e.g 0.0009999 (e-4) --> 0.001 (e-3), so adjust s so the rounding digits
2426 + // are indexed correctly.
2427 + if (r.e < e) --s;
2428 + n = n.slice(s - 3, s + 1);
2429 +
2430 + // The 4th rounding digit may be in error by -1 so if the 4 rounding digits
2431 + // are 9999 or 4999 (i.e. approaching a rounding boundary) continue the
2432 + // iteration.
2433 + if (n == '9999' || !rep && n == '4999') {
2434 +
2435 + // On the first iteration only, check to see if rounding up gives the
2436 + // exact result as the nines may infinitely repeat.
2437 + if (!rep) {
2438 + round(t, t.e + DECIMAL_PLACES + 2, 0);
2439 +
2440 + if (t.times(t).eq(x)) {
2441 + r = t;
2442 + break;
2443 + }
2444 + }
2445 +
2446 + dp += 4;
2447 + s += 4;
2448 + rep = 1;
2449 + } else {
2450 +
2451 + // If rounding digits are null, 0{0,4} or 50{0,3}, check for exact
2452 + // result. If not, then there are further digits and m will be truthy.
2453 + if (!+n || !+n.slice(1) && n.charAt(0) == '5') {
2454 +
2455 + // Truncate to the first rounding digit.
2456 + round(r, r.e + DECIMAL_PLACES + 2, 1);
2457 + m = !r.times(r).eq(x);
2458 + }
2459 +
2460 + break;
2461 + }
2462 + }
2463 + }
2464 + }
2465 +
2466 + return round(r, r.e + DECIMAL_PLACES + 1, ROUNDING_MODE, m);
2467 + };
2468 +
2469 +
2470 + /*
2471 + * Return a string representing the value of this BigNumber in exponential notation and
2472 + * rounded using ROUNDING_MODE to dp fixed decimal places.
2473 + *
2474 + * [dp] {number} Decimal places. Integer, 0 to MAX inclusive.
2475 + * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
2476 + *
2477 + * '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {dp|rm}'
2478 + */
2479 + P.toExponential = function (dp, rm) {
2480 + if (dp != null) {
2481 + intCheck(dp, 0, MAX);
2482 + dp++;
2483 + }
2484 + return format(this, dp, rm, 1);
2485 + };
2486 +
2487 +
2488 + /*
2489 + * Return a string representing the value of this BigNumber in fixed-point notation rounding
2490 + * to dp fixed decimal places using rounding mode rm, or ROUNDING_MODE if rm is omitted.
2491 + *
2492 + * Note: as with JavaScript's number type, (-0).toFixed(0) is '0',
2493 + * but e.g. (-0.00001).toFixed(0) is '-0'.
2494 + *
2495 + * [dp] {number} Decimal places. Integer, 0 to MAX inclusive.
2496 + * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
2497 + *
2498 + * '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {dp|rm}'
2499 + */
2500 + P.toFixed = function (dp, rm) {
2501 + if (dp != null) {
2502 + intCheck(dp, 0, MAX);
2503 + dp = dp + this.e + 1;
2504 + }
2505 + return format(this, dp, rm);
2506 + };
2507 +
2508 +
2509 + /*
2510 + * Return a string representing the value of this BigNumber in fixed-point notation rounded
2511 + * using rm or ROUNDING_MODE to dp decimal places, and formatted according to the properties
2512 + * of the format or FORMAT object (see BigNumber.set).
2513 + *
2514 + * The formatting object may contain some or all of the properties shown below.
2515 + *
2516 + * FORMAT = {
2517 + * prefix: '',
2518 + * groupSize: 3,
2519 + * secondaryGroupSize: 0,
2520 + * groupSeparator: ',',
2521 + * decimalSeparator: '.',
2522 + * fractionGroupSize: 0,
2523 + * fractionGroupSeparator: '\xA0', // non-breaking space
2524 + * suffix: ''
2525 + * };
2526 + *
2527 + * [dp] {number} Decimal places. Integer, 0 to MAX inclusive.
2528 + * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
2529 + * [format] {object} Formatting options. See FORMAT pbject above.
2530 + *
2531 + * '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {dp|rm}'
2532 + * '[BigNumber Error] Argument not an object: {format}'
2533 + */
2534 + P.toFormat = function (dp, rm, format) {
2535 + var str,
2536 + x = this;
2537 +
2538 + if (format == null) {
2539 + if (dp != null && rm && typeof rm == 'object') {
2540 + format = rm;
2541 + rm = null;
2542 + } else if (dp && typeof dp == 'object') {
2543 + format = dp;
2544 + dp = rm = null;
2545 + } else {
2546 + format = FORMAT;
2547 + }
2548 + } else if (typeof format != 'object') {
2549 + throw Error
2550 + (bignumberError + 'Argument not an object: ' + format);
2551 + }
2552 +
2553 + str = x.toFixed(dp, rm);
2554 +
2555 + if (x.c) {
2556 + var i,
2557 + arr = str.split('.'),
2558 + g1 = +format.groupSize,
2559 + g2 = +format.secondaryGroupSize,
2560 + groupSeparator = format.groupSeparator || '',
2561 + intPart = arr[0],
2562 + fractionPart = arr[1],
2563 + isNeg = x.s < 0,
2564 + intDigits = isNeg ? intPart.slice(1) : intPart,
2565 + len = intDigits.length;
2566 +
2567 + if (g2) i = g1, g1 = g2, g2 = i, len -= i;
2568 +
2569 + if (g1 > 0 && len > 0) {
2570 + i = len % g1 || g1;
2571 + intPart = intDigits.substr(0, i);
2572 + for (; i < len; i += g1) intPart += groupSeparator + intDigits.substr(i, g1);
2573 + if (g2 > 0) intPart += groupSeparator + intDigits.slice(i);
2574 + if (isNeg) intPart = '-' + intPart;
2575 + }
2576 +
2577 + str = fractionPart
2578 + ? intPart + (format.decimalSeparator || '') + ((g2 = +format.fractionGroupSize)
2579 + ? fractionPart.replace(new RegExp('\\d{' + g2 + '}\\B', 'g'),
2580 + '$&' + (format.fractionGroupSeparator || ''))
2581 + : fractionPart)
2582 + : intPart;
2583 + }
2584 +
2585 + return (format.prefix || '') + str + (format.suffix || '');
2586 + };
2587 +
2588 +
2589 + /*
2590 + * Return an array of two BigNumbers representing the value of this BigNumber as a simple
2591 + * fraction with an integer numerator and an integer denominator.
2592 + * The denominator will be a positive non-zero value less than or equal to the specified
2593 + * maximum denominator. If a maximum denominator is not specified, the denominator will be
2594 + * the lowest value necessary to represent the number exactly.
2595 + *
2596 + * [md] {number|string|BigNumber} Integer >= 1, or Infinity. The maximum denominator.
2597 + *
2598 + * '[BigNumber Error] Argument {not an integer|out of range} : {md}'
2599 + */
2600 + P.toFraction = function (md) {
2601 + var d, d0, d1, d2, e, exp, n, n0, n1, q, r, s,
2602 + x = this,
2603 + xc = x.c;
2604 +
2605 + if (md != null) {
2606 + n = new BigNumber(md);
2607 +
2608 + // Throw if md is less than one or is not an integer, unless it is Infinity.
2609 + if (!n.isInteger() && (n.c || n.s !== 1) || n.lt(ONE)) {
2610 + throw Error
2611 + (bignumberError + 'Argument ' +
2612 + (n.isInteger() ? 'out of range: ' : 'not an integer: ') + valueOf(n));
2613 + }
2614 + }
2615 +
2616 + if (!xc) return new BigNumber(x);
2617 +
2618 + d = new BigNumber(ONE);
2619 + n1 = d0 = new BigNumber(ONE);
2620 + d1 = n0 = new BigNumber(ONE);
2621 + s = coeffToString(xc);
2622 +
2623 + // Determine initial denominator.
2624 + // d is a power of 10 and the minimum max denominator that specifies the value exactly.
2625 + e = d.e = s.length - x.e - 1;
2626 + d.c[0] = POWS_TEN[(exp = e % LOG_BASE) < 0 ? LOG_BASE + exp : exp];
2627 + md = !md || n.comparedTo(d) > 0 ? (e > 0 ? d : n1) : n;
2628 +
2629 + exp = MAX_EXP;
2630 + MAX_EXP = 1 / 0;
2631 + n = new BigNumber(s);
2632 +
2633 + // n0 = d1 = 0
2634 + n0.c[0] = 0;
2635 +
2636 + for (; ;) {
2637 + q = div(n, d, 0, 1);
2638 + d2 = d0.plus(q.times(d1));
2639 + if (d2.comparedTo(md) == 1) break;
2640 + d0 = d1;
2641 + d1 = d2;
2642 + n1 = n0.plus(q.times(d2 = n1));
2643 + n0 = d2;
2644 + d = n.minus(q.times(d2 = d));
2645 + n = d2;
2646 + }
2647 +
2648 + d2 = div(md.minus(d0), d1, 0, 1);
2649 + n0 = n0.plus(d2.times(n1));
2650 + d0 = d0.plus(d2.times(d1));
2651 + n0.s = n1.s = x.s;
2652 + e = e * 2;
2653 +
2654 + // Determine which fraction is closer to x, n0/d0 or n1/d1
2655 + r = div(n1, d1, e, ROUNDING_MODE).minus(x).abs().comparedTo(
2656 + div(n0, d0, e, ROUNDING_MODE).minus(x).abs()) < 1 ? [n1, d1] : [n0, d0];
2657 +
2658 + MAX_EXP = exp;
2659 +
2660 + return r;
2661 + };
2662 +
2663 +
2664 + /*
2665 + * Return the value of this BigNumber converted to a number primitive.
2666 + */
2667 + P.toNumber = function () {
2668 + return +valueOf(this);
2669 + };
2670 +
2671 +
2672 + /*
2673 + * Return a string representing the value of this BigNumber rounded to sd significant digits
2674 + * using rounding mode rm or ROUNDING_MODE. If sd is less than the number of digits
2675 + * necessary to represent the integer part of the value in fixed-point notation, then use
2676 + * exponential notation.
2677 + *
2678 + * [sd] {number} Significant digits. Integer, 1 to MAX inclusive.
2679 + * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
2680 + *
2681 + * '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {sd|rm}'
2682 + */
2683 + P.toPrecision = function (sd, rm) {
2684 + if (sd != null) intCheck(sd, 1, MAX);
2685 + return format(this, sd, rm, 2);
2686 + };
2687 +
2688 +
2689 + /*
2690 + * Return a string representing the value of this BigNumber in base b, or base 10 if b is
2691 + * omitted. If a base is specified, including base 10, round according to DECIMAL_PLACES and
2692 + * ROUNDING_MODE. If a base is not specified, and this BigNumber has a positive exponent
2693 + * that is equal to or greater than TO_EXP_POS, or a negative exponent equal to or less than
2694 + * TO_EXP_NEG, return exponential notation.
2695 + *
2696 + * [b] {number} Integer, 2 to ALPHABET.length inclusive.
2697 + *
2698 + * '[BigNumber Error] Base {not a primitive number|not an integer|out of range}: {b}'
2699 + */
2700 + P.toString = function (b) {
2701 + var str,
2702 + n = this,
2703 + s = n.s,
2704 + e = n.e;
2705 +
2706 + // Infinity or NaN?
2707 + if (e === null) {
2708 + if (s) {
2709 + str = 'Infinity';
2710 + if (s < 0) str = '-' + str;
2711 + } else {
2712 + str = 'NaN';
2713 + }
2714 + } else {
2715 + if (b == null) {
2716 + str = e <= TO_EXP_NEG || e >= TO_EXP_POS
2717 + ? toExponential(coeffToString(n.c), e)
2718 + : toFixedPoint(coeffToString(n.c), e, '0');
2719 + } else if (b === 10) {
2720 + n = round(new BigNumber(n), DECIMAL_PLACES + e + 1, ROUNDING_MODE);
2721 + str = toFixedPoint(coeffToString(n.c), n.e, '0');
2722 + } else {
2723 + intCheck(b, 2, ALPHABET.length, 'Base');
2724 + str = convertBase(toFixedPoint(coeffToString(n.c), e, '0'), 10, b, s, true);
2725 + }
2726 +
2727 + if (s < 0 && n.c[0]) str = '-' + str;
2728 + }
2729 +
2730 + return str;
2731 + };
2732 +
2733 +
2734 + /*
2735 + * Return as toString, but do not accept a base argument, and include the minus sign for
2736 + * negative zero.
2737 + */
2738 + P.valueOf = P.toJSON = function () {
2739 + return valueOf(this);
2740 + };
2741 +
2742 +
2743 + P._isBigNumber = true;
2744 +
2745 + P[Symbol.toStringTag] = 'BigNumber';
2746 +
2747 + // Node.js v10.12.0+
2748 + P[Symbol.for('nodejs.util.inspect.custom')] = P.valueOf;
2749 +
2750 + if (configObject != null) BigNumber.set(configObject);
2751 +
2752 + return BigNumber;
2753 +}
2754 +
2755 +
2756 +// PRIVATE HELPER FUNCTIONS
2757 +
2758 +// These functions don't need access to variables,
2759 +// e.g. DECIMAL_PLACES, in the scope of the `clone` function above.
2760 +
2761 +
2762 +function bitFloor(n) {
2763 + var i = n | 0;
2764 + return n > 0 || n === i ? i : i - 1;
2765 +}
2766 +
2767 +
2768 +// Return a coefficient array as a string of base 10 digits.
2769 +function coeffToString(a) {
2770 + var s, z,
2771 + i = 1,
2772 + j = a.length,
2773 + r = a[0] + '';
2774 +
2775 + for (; i < j;) {
2776 + s = a[i++] + '';
2777 + z = LOG_BASE - s.length;
2778 + for (; z--; s = '0' + s);
2779 + r += s;
2780 + }
2781 +
2782 + // Determine trailing zeros.
2783 + for (j = r.length; r.charCodeAt(--j) === 48;);
2784 +
2785 + return r.slice(0, j + 1 || 1);
2786 +}
2787 +
2788 +
2789 +// Compare the value of BigNumbers x and y.
2790 +function compare(x, y) {
2791 + var a, b,
2792 + xc = x.c,
2793 + yc = y.c,
2794 + i = x.s,
2795 + j = y.s,
2796 + k = x.e,
2797 + l = y.e;
2798 +
2799 + // Either NaN?
2800 + if (!i || !j) return null;
2801 +
2802 + a = xc && !xc[0];
2803 + b = yc && !yc[0];
2804 +
2805 + // Either zero?
2806 + if (a || b) return a ? b ? 0 : -j : i;
2807 +
2808 + // Signs differ?
2809 + if (i != j) return i;
2810 +
2811 + a = i < 0;
2812 + b = k == l;
2813 +
2814 + // Either Infinity?
2815 + if (!xc || !yc) return b ? 0 : !xc ^ a ? 1 : -1;
2816 +
2817 + // Compare exponents.
2818 + if (!b) return k > l ^ a ? 1 : -1;
2819 +
2820 + j = (k = xc.length) < (l = yc.length) ? k : l;
2821 +
2822 + // Compare digit by digit.
2823 + for (i = 0; i < j; i++) if (xc[i] != yc[i]) return xc[i] > yc[i] ^ a ? 1 : -1;
2824 +
2825 + // Compare lengths.
2826 + return k == l ? 0 : k > l ^ a ? 1 : -1;
2827 +}
2828 +
2829 +
2830 +/*
2831 + * Check that n is a primitive number, an integer, and in range, otherwise throw.
2832 + */
2833 +function intCheck(n, min, max, name) {
2834 + if (n < min || n > max || n !== mathfloor(n)) {
2835 + throw Error
2836 + (bignumberError + (name || 'Argument') + (typeof n == 'number'
2837 + ? n < min || n > max ? ' out of range: ' : ' not an integer: '
2838 + : ' not a primitive number: ') + String(n));
2839 + }
2840 +}
2841 +
2842 +
2843 +// Assumes finite n.
2844 +function isOdd(n) {
2845 + var k = n.c.length - 1;
2846 + return bitFloor(n.e / LOG_BASE) == k && n.c[k] % 2 != 0;
2847 +}
2848 +
2849 +
2850 +function toExponential(str, e) {
2851 + return (str.length > 1 ? str.charAt(0) + '.' + str.slice(1) : str) +
2852 + (e < 0 ? 'e' : 'e+') + e;
2853 +}
2854 +
2855 +
2856 +function toFixedPoint(str, e, z) {
2857 + var len, zs;
2858 +
2859 + // Negative exponent?
2860 + if (e < 0) {
2861 +
2862 + // Prepend zeros.
2863 + for (zs = z + '.'; ++e; zs += z);
2864 + str = zs + str;
2865 +
2866 + // Positive exponent
2867 + } else {
2868 + len = str.length;
2869 +
2870 + // Append zeros.
2871 + if (++e > len) {
2872 + for (zs = z, e -= len; --e; zs += z);
2873 + str += zs;
2874 + } else if (e < len) {
2875 + str = str.slice(0, e) + '.' + str.slice(e);
2876 + }
2877 + }
2878 +
2879 + return str;
2880 +}
2881 +
2882 +
2883 +// EXPORT
2884 +
2885 +
2886 +export var BigNumber = clone();
2887 +
2888 +export default BigNumber;
1 +<!DOCTYPE HTML>
2 +<html>
3 +<head>
4 +<meta charset="utf-8">
5 +<meta http-equiv="X-UA-Compatible" content="IE=edge">
6 +<meta name="Author" content="M Mclaughlin">
7 +<title>bignumber.js API</title>
8 +<style>
9 +html{font-size:100%}
10 +body{background:#fff;font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px;
11 + line-height:1.65em;min-height:100%;margin:0}
12 +body,i{color:#000}
13 +.nav{background:#fff;position:fixed;top:0;bottom:0;left:0;width:200px;overflow-y:auto;
14 + padding:15px 0 30px 15px}
15 +div.container{width:600px;margin:50px 0 50px 240px}
16 +p{margin:0 0 1em;width:600px}
17 +pre,ul{margin:1em 0}
18 +h1,h2,h3,h4,h5{margin:0;padding:1.5em 0 0}
19 +h1,h2{padding:.75em 0}
20 +h1{font:400 3em Verdana,sans-serif;color:#000;margin-bottom:1em}
21 +h2{font-size:2.25em;color:#ff2a00}
22 +h3{font-size:1.75em;color:#4dc71f}
23 +h4{font-size:1.75em;color:#ff2a00;padding-bottom:.75em}
24 +h5{font-size:1.2em;margin-bottom:.4em}
25 +h6{font-size:1.1em;margin-bottom:0.8em;padding:0.5em 0}
26 +dd{padding-top:.35em}
27 +dt{padding-top:.5em}
28 +b{font-weight:700}
29 +dt b{font-size:1.3em}
30 +a,a:visited{color:#ff2a00;text-decoration:none}
31 +a:active,a:hover{outline:0;text-decoration:underline}
32 +.nav a,.nav b,.nav a:visited{display:block;color:#ff2a00;font-weight:700; margin-top:15px}
33 +.nav b{color:#4dc71f;margin-top:20px;cursor:default;width:auto}
34 +ul{list-style-type:none;padding:0 0 0 20px}
35 +.nav ul{line-height:14px;padding-left:0;margin:5px 0 0}
36 +.nav ul a,.nav ul a:visited,span{display:inline;color:#000;font-family:Verdana,Geneva,sans-serif;
37 + font-size:11px;font-weight:400;margin:0}
38 +.inset,ul.inset{margin-left:20px}
39 +.inset{font-size:.9em}
40 +.nav li{width:auto;margin:0 0 3px}
41 +.alias{font-style:italic;margin-left:20px}
42 +table{border-collapse:collapse;border-spacing:0;border:2px solid #a7dbd8;margin:1.75em 0;padding:0}
43 +td,th{text-align:left;margin:0;padding:2px 5px;border:1px dotted #a7dbd8}
44 +th{border-top:2px solid #a7dbd8;border-bottom:2px solid #a7dbd8;color:#ff2a00}
45 +code,pre{font-family:Consolas, monaco, monospace;font-weight:400}
46 +pre{background:#f5f5f5;white-space:pre-wrap;word-wrap:break-word;border-left:5px solid #abef98;
47 + padding:1px 0 1px 15px;margin:1.2em 0}
48 +code,.nav-title{color:#ff2a00}
49 +.end{margin-bottom:25px}
50 +.centre{text-align:center}
51 +.error-table{font-size:13px;width:100%}
52 +#faq{margin:3em 0 0}
53 +li span{float:right;margin-right:10px;color:#c0c0c0}
54 +#js{font:inherit;color:#4dc71f}
55 +</style>
56 +</head>
57 +<body>
58 +
59 + <div class="nav">
60 +
61 + <b>v8.1.0</b>
62 +
63 + <a class='nav-title' href="#">API</a>
64 +
65 + <b> CONSTRUCTOR </b>
66 + <ul>
67 + <li><a href="#bignumber">BigNumber</a></li>
68 + </ul>
69 +
70 + <a href="#methods">Methods</a>
71 + <ul>
72 + <li><a href="#clone">clone</a></li>
73 + <li><a href="#config" >config</a><span>set</span></li>
74 + <li>
75 + <ul class="inset">
76 + <li><a href="#decimal-places">DECIMAL_PLACES</a></li>
77 + <li><a href="#rounding-mode" >ROUNDING_MODE</a></li>
78 + <li><a href="#exponential-at">EXPONENTIAL_AT</a></li>
79 + <li><a href="#range" >RANGE</a></li>
80 + <li><a href="#crypto" >CRYPTO</a></li>
81 + <li><a href="#modulo-mode" >MODULO_MODE</a></li>
82 + <li><a href="#pow-precision" >POW_PRECISION</a></li>
83 + <li><a href="#format" >FORMAT</a></li>
84 + <li><a href="#alphabet" >ALPHABET</a></li>
85 + </ul>
86 + </li>
87 + <li><a href="#isBigNumber">isBigNumber</a></li>
88 + <li><a href="#max" >maximum</a><span>max</span></li>
89 + <li><a href="#min" >minimum</a><span>min</span></li>
90 + <li><a href="#random" >random</a></li>
91 + <li><a href="#sum" >sum</a></li>
92 + </ul>
93 +
94 + <a href="#constructor-properties">Properties</a>
95 + <ul>
96 + <li><a href="#round-up" >ROUND_UP</a></li>
97 + <li><a href="#round-down" >ROUND_DOWN</a></li>
98 + <li><a href="#round-ceil" >ROUND_CEIL</a></li>
99 + <li><a href="#round-floor" >ROUND_FLOOR</a></li>
100 + <li><a href="#round-half-up" >ROUND_HALF_UP</a></li>
101 + <li><a href="#round-half-down" >ROUND_HALF_DOWN</a></li>
102 + <li><a href="#round-half-even" >ROUND_HALF_EVEN</a></li>
103 + <li><a href="#round-half-ceil" >ROUND_HALF_CEIL</a></li>
104 + <li><a href="#round-half-floor">ROUND_HALF_FLOOR</a></li>
105 + <li><a href="#debug" >DEBUG</a></li>
106 + </ul>
107 +
108 + <b> INSTANCE </b>
109 +
110 + <a href="#prototype-methods">Methods</a>
111 + <ul>
112 + <li><a href="#abs" >absoluteValue </a><span>abs</span> </li>
113 + <li><a href="#cmp" >comparedTo </a> </li>
114 + <li><a href="#dp" >decimalPlaces </a><span>dp</span> </li>
115 + <li><a href="#div" >dividedBy </a><span>div</span> </li>
116 + <li><a href="#divInt" >dividedToIntegerBy </a><span>idiv</span> </li>
117 + <li><a href="#pow" >exponentiatedBy </a><span>pow</span> </li>
118 + <li><a href="#int" >integerValue </a> </li>
119 + <li><a href="#eq" >isEqualTo </a><span>eq</span> </li>
120 + <li><a href="#isF" >isFinite </a> </li>
121 + <li><a href="#gt" >isGreaterThan </a><span>gt</span> </li>
122 + <li><a href="#gte" >isGreaterThanOrEqualTo</a><span>gte</span> </li>
123 + <li><a href="#isInt" >isInteger </a> </li>
124 + <li><a href="#lt" >isLessThan </a><span>lt</span> </li>
125 + <li><a href="#lte" >isLessThanOrEqualTo </a><span>lte</span> </li>
126 + <li><a href="#isNaN" >isNaN </a> </li>
127 + <li><a href="#isNeg" >isNegative </a> </li>
128 + <li><a href="#isPos" >isPositive </a> </li>
129 + <li><a href="#isZ" >isZero </a> </li>
130 + <li><a href="#minus" >minus </a> </li>
131 + <li><a href="#mod" >modulo </a><span>mod</span> </li>
132 + <li><a href="#times" >multipliedBy </a><span>times</span></li>
133 + <li><a href="#neg" >negated </a> </li>
134 + <li><a href="#plus" >plus </a> </li>
135 + <li><a href="#sd" >precision </a><span>sd</span> </li>
136 + <li><a href="#shift" >shiftedBy </a> </li>
137 + <li><a href="#sqrt" >squareRoot </a><span>sqrt</span> </li>
138 + <li><a href="#toE" >toExponential </a> </li>
139 + <li><a href="#toFix" >toFixed </a> </li>
140 + <li><a href="#toFor" >toFormat </a> </li>
141 + <li><a href="#toFr" >toFraction </a> </li>
142 + <li><a href="#toJSON" >toJSON </a> </li>
143 + <li><a href="#toN" >toNumber </a> </li>
144 + <li><a href="#toP" >toPrecision </a> </li>
145 + <li><a href="#toS" >toString </a> </li>
146 + <li><a href="#valueOf">valueOf </a> </li>
147 + </ul>
148 +
149 + <a href="#instance-properties">Properties</a>
150 + <ul>
151 + <li><a href="#coefficient">c: coefficient</a></li>
152 + <li><a href="#exponent" >e: exponent</a></li>
153 + <li><a href="#sign" >s: sign</a></li>
154 + </ul>
155 +
156 + <a href="#zero-nan-infinity">Zero, NaN &amp; Infinity</a>
157 + <a href="#Errors">Errors</a>
158 + <a href="#type-coercion">Type coercion</a>
159 + <a class='end' href="#faq">FAQ</a>
160 +
161 + </div>
162 +
163 + <div class="container">
164 +
165 + <h1>bignumber<span id='js'>.js</span></h1>
166 +
167 + <p>A JavaScript library for arbitrary-precision arithmetic.</p>
168 + <p><a href="https://github.com/MikeMcl/bignumber.js">Hosted on GitHub</a>. </p>
169 +
170 + <h2>API</h2>
171 +
172 + <p>
173 + See the <a href='https://github.com/MikeMcl/bignumber.js'>README</a> on GitHub for a
174 + quick-start introduction.
175 + </p>
176 + <p>
177 + In all examples below, <code>var</code> and semicolons are not shown, and if a commented-out
178 + value is in quotes it means <code>toString</code> has been called on the preceding expression.
179 + </p>
180 +
181 +
182 + <h3>CONSTRUCTOR</h3>
183 +
184 +
185 + <h5 id="bignumber">
186 + BigNumber<code class='inset'>BigNumber(n [, base]) <i>&rArr; BigNumber</i></code>
187 + </h5>
188 + <p>
189 + <code>n</code>: <i>number|string|BigNumber</i><br />
190 + <code>base</code>: <i>number</i>: integer, <code>2</code> to <code>36</code> inclusive. (See
191 + <a href='#alphabet'><code>ALPHABET</code></a> to extend this range).
192 + </p>
193 + <p>
194 + Returns a new instance of a BigNumber object with value <code>n</code>, where <code>n</code>
195 + is a numeric value in the specified <code>base</code>, or base <code>10</code> if
196 + <code>base</code> is omitted or is <code>null</code> or <code>undefined</code>.
197 + </p>
198 + <pre>
199 +x = new BigNumber(123.4567) // '123.4567'
200 +// 'new' is optional
201 +y = BigNumber(x) // '123.4567'</pre>
202 + <p>
203 + If <code>n</code> is a base <code>10</code> value it can be in normal (fixed-point) or
204 + exponential notation. Values in other bases must be in normal notation. Values in any base can
205 + have fraction digits, i.e. digits after the decimal point.
206 + </p>
207 + <pre>
208 +new BigNumber(43210) // '43210'
209 +new BigNumber('4.321e+4') // '43210'
210 +new BigNumber('-735.0918e-430') // '-7.350918e-428'
211 +new BigNumber('123412421.234324', 5) // '607236.557696'</pre>
212 + <p>
213 + Signed <code>0</code>, signed <code>Infinity</code> and <code>NaN</code> are supported.
214 + </p>
215 + <pre>
216 +new BigNumber('-Infinity') // '-Infinity'
217 +new BigNumber(NaN) // 'NaN'
218 +new BigNumber(-0) // '0'
219 +new BigNumber('.5') // '0.5'
220 +new BigNumber('+2') // '2'</pre>
221 + <p>
222 + String values in hexadecimal literal form, e.g. <code>'0xff'</code>, are valid, as are
223 + string values with the octal and binary prefixs <code>'0o'</code> and <code>'0b'</code>.
224 + String values in octal literal form without the prefix will be interpreted as
225 + decimals, e.g. <code>'011'</code> is interpreted as 11, not 9.
226 + </p>
227 + <pre>
228 +new BigNumber(-10110100.1, 2) // '-180.5'
229 +new BigNumber('-0b10110100.1') // '-180.5'
230 +new BigNumber('ff.8', 16) // '255.5'
231 +new BigNumber('0xff.8') // '255.5'</pre>
232 + <p>
233 + If a base is specified, <code>n</code> is rounded according to the current
234 + <a href='#decimal-places'><code>DECIMAL_PLACES</code></a> and
235 + <a href='#rounding-mode'><code>ROUNDING_MODE</code></a> settings. <em>This includes base
236 + <code>10</code> so don't include a <code>base</code> parameter for decimal values unless
237 + this behaviour is wanted.</em>
238 + </p>
239 + <pre>BigNumber.config({ DECIMAL_PLACES: 5 })
240 +new BigNumber(1.23456789) // '1.23456789'
241 +new BigNumber(1.23456789, 10) // '1.23457'</pre>
242 + <p>An error is thrown if <code>base</code> is invalid. See <a href='#Errors'>Errors</a>.</p>
243 + <p>
244 + There is no limit to the number of digits of a value of type <em>string</em> (other than
245 + that of JavaScript's maximum array size). See <a href='#range'><code>RANGE</code></a> to set
246 + the maximum and minimum possible exponent value of a BigNumber.
247 + </p>
248 + <pre>
249 +new BigNumber('5032485723458348569331745.33434346346912144534543')
250 +new BigNumber('4.321e10000000')</pre>
251 + <p>BigNumber <code>NaN</code> is returned if <code>n</code> is invalid
252 + (unless <code>BigNumber.DEBUG</code> is <code>true</code>, see below).</p>
253 + <pre>
254 +new BigNumber('.1*') // 'NaN'
255 +new BigNumber('blurgh') // 'NaN'
256 +new BigNumber(9, 2) // 'NaN'</pre>
257 + <p>
258 + To aid in debugging, if <code>BigNumber.DEBUG</code> is <code>true</code> then an error will
259 + be thrown on an invalid <code>n</code>. An error will also be thrown if <code>n</code> is of
260 + type <em>number</em> with more than <code>15</code> significant digits, as calling
261 + <code><a href='#toS'>toString</a></code> or <code><a href='#valueOf'>valueOf</a></code> on
262 + these numbers may not result in the intended value.
263 + </p>
264 + <pre>
265 +console.log(823456789123456.3) // 823456789123456.2
266 +new BigNumber(823456789123456.3) // '823456789123456.2'
267 +BigNumber.DEBUG = true
268 +// '[BigNumber Error] Number primitive has more than 15 significant digits'
269 +new BigNumber(823456789123456.3)
270 +// '[BigNumber Error] Not a base 2 number'
271 +new BigNumber(9, 2)</pre>
272 + <p>
273 + A BigNumber can also be created from an object literal.
274 + Use <code><a href='#isBigNumber'>isBigNumber</a></code> to check that it is well-formed.
275 + </p>
276 + <pre>new BigNumber({ s: 1, e: 2, c: [ 777, 12300000000000 ], _isBigNumber: true }) // '777.123'</pre>
277 +
278 +
279 +
280 +
281 + <h4 id="methods">Methods</h4>
282 + <p>The static methods of a BigNumber constructor.</p>
283 +
284 +
285 +
286 +
287 + <h5 id="clone">clone
288 + <code class='inset'>.clone([object]) <i>&rArr; BigNumber constructor</i></code>
289 + </h5>
290 + <p><code>object</code>: <i>object</i></p>
291 + <p>
292 + Returns a new independent BigNumber constructor with configuration as described by
293 + <code>object</code> (see <a href='#config'><code>config</code></a>), or with the default
294 + configuration if <code>object</code> is <code>null</code> or <code>undefined</code>.
295 + </p>
296 + <p>
297 + Throws if <code>object</code> is not an object. See <a href='#Errors'>Errors</a>.
298 + </p>
299 + <pre>BigNumber.config({ DECIMAL_PLACES: 5 })
300 +BN = BigNumber.clone({ DECIMAL_PLACES: 9 })
301 +
302 +x = new BigNumber(1)
303 +y = new BN(1)
304 +
305 +x.div(3) // 0.33333
306 +y.div(3) // 0.333333333
307 +
308 +// BN = BigNumber.clone({ DECIMAL_PLACES: 9 }) is equivalent to:
309 +BN = BigNumber.clone()
310 +BN.config({ DECIMAL_PLACES: 9 })</pre>
311 +
312 +
313 +
314 + <h5 id="config">config<code class='inset'>set([object]) <i>&rArr; object</i></code></h5>
315 + <p>
316 + <code>object</code>: <i>object</i>: an object that contains some or all of the following
317 + properties.
318 + </p>
319 + <p>Configures the settings for this particular BigNumber constructor.</p>
320 +
321 + <dl class='inset'>
322 + <dt id="decimal-places"><code><b>DECIMAL_PLACES</b></code></dt>
323 + <dd>
324 + <i>number</i>: integer, <code>0</code> to <code>1e+9</code> inclusive<br />
325 + Default value: <code>20</code>
326 + </dd>
327 + <dd>
328 + The <u>maximum</u> number of decimal places of the results of operations involving
329 + division, i.e. division, square root and base conversion operations, and power
330 + operations with negative exponents.<br />
331 + </dd>
332 + <dd>
333 + <pre>BigNumber.config({ DECIMAL_PLACES: 5 })
334 +BigNumber.set({ DECIMAL_PLACES: 5 }) // equivalent</pre>
335 + </dd>
336 +
337 +
338 +
339 + <dt id="rounding-mode"><code><b>ROUNDING_MODE</b></code></dt>
340 + <dd>
341 + <i>number</i>: integer, <code>0</code> to <code>8</code> inclusive<br />
342 + Default value: <code>4</code> <a href="#round-half-up">(<code>ROUND_HALF_UP</code>)</a>
343 + </dd>
344 + <dd>
345 + The rounding mode used in the above operations and the default rounding mode of
346 + <a href='#dp'><code>decimalPlaces</code></a>,
347 + <a href='#sd'><code>precision</code></a>,
348 + <a href='#toE'><code>toExponential</code></a>,
349 + <a href='#toFix'><code>toFixed</code></a>,
350 + <a href='#toFor'><code>toFormat</code></a> and
351 + <a href='#toP'><code>toPrecision</code></a>.
352 + </dd>
353 + <dd>The modes are available as enumerated properties of the BigNumber constructor.</dd>
354 + <dd>
355 + <pre>BigNumber.config({ ROUNDING_MODE: 0 })
356 +BigNumber.set({ ROUNDING_MODE: BigNumber.ROUND_UP }) // equivalent</pre>
357 + </dd>
358 +
359 +
360 +
361 + <dt id="exponential-at"><code><b>EXPONENTIAL_AT</b></code></dt>
362 + <dd>
363 + <i>number</i>: integer, magnitude <code>0</code> to <code>1e+9</code> inclusive, or
364 + <br />
365 + <i>number</i>[]: [ integer <code>-1e+9</code> to <code>0</code> inclusive, integer
366 + <code>0</code> to <code>1e+9</code> inclusive ]<br />
367 + Default value: <code>[-7, 20]</code>
368 + </dd>
369 + <dd>
370 + The exponent value(s) at which <code>toString</code> returns exponential notation.
371 + </dd>
372 + <dd>
373 + If a single number is assigned, the value is the exponent magnitude.<br />
374 + If an array of two numbers is assigned then the first number is the negative exponent
375 + value at and beneath which exponential notation is used, and the second number is the
376 + positive exponent value at and above which the same.
377 + </dd>
378 + <dd>
379 + For example, to emulate JavaScript numbers in terms of the exponent values at which they
380 + begin to use exponential notation, use <code>[-7, 20]</code>.
381 + </dd>
382 + <dd>
383 + <pre>BigNumber.config({ EXPONENTIAL_AT: 2 })
384 +new BigNumber(12.3) // '12.3' e is only 1
385 +new BigNumber(123) // '1.23e+2'
386 +new BigNumber(0.123) // '0.123' e is only -1
387 +new BigNumber(0.0123) // '1.23e-2'
388 +
389 +BigNumber.config({ EXPONENTIAL_AT: [-7, 20] })
390 +new BigNumber(123456789) // '123456789' e is only 8
391 +new BigNumber(0.000000123) // '1.23e-7'
392 +
393 +// Almost never return exponential notation:
394 +BigNumber.config({ EXPONENTIAL_AT: 1e+9 })
395 +
396 +// Always return exponential notation:
397 +BigNumber.config({ EXPONENTIAL_AT: 0 })</pre>
398 + </dd>
399 + <dd>
400 + Regardless of the value of <code>EXPONENTIAL_AT</code>, the <code>toFixed</code> method
401 + will always return a value in normal notation and the <code>toExponential</code> method
402 + will always return a value in exponential form.
403 + </dd>
404 + <dd>
405 + Calling <code>toString</code> with a base argument, e.g. <code>toString(10)</code>, will
406 + also always return normal notation.
407 + </dd>
408 +
409 +
410 +
411 + <dt id="range"><code><b>RANGE</b></code></dt>
412 + <dd>
413 + <i>number</i>: integer, magnitude <code>1</code> to <code>1e+9</code> inclusive, or
414 + <br />
415 + <i>number</i>[]: [ integer <code>-1e+9</code> to <code>-1</code> inclusive, integer
416 + <code>1</code> to <code>1e+9</code> inclusive ]<br />
417 + Default value: <code>[-1e+9, 1e+9]</code>
418 + </dd>
419 + <dd>
420 + The exponent value(s) beyond which overflow to <code>Infinity</code> and underflow to
421 + zero occurs.
422 + </dd>
423 + <dd>
424 + If a single number is assigned, it is the maximum exponent magnitude: values wth a
425 + positive exponent of greater magnitude become <code>Infinity</code> and those with a
426 + negative exponent of greater magnitude become zero.
427 + <dd>
428 + If an array of two numbers is assigned then the first number is the negative exponent
429 + limit and the second number is the positive exponent limit.
430 + </dd>
431 + <dd>
432 + For example, to emulate JavaScript numbers in terms of the exponent values at which they
433 + become zero and <code>Infinity</code>, use <code>[-324, 308]</code>.
434 + </dd>
435 + <dd>
436 + <pre>BigNumber.config({ RANGE: 500 })
437 +BigNumber.config().RANGE // [ -500, 500 ]
438 +new BigNumber('9.999e499') // '9.999e+499'
439 +new BigNumber('1e500') // 'Infinity'
440 +new BigNumber('1e-499') // '1e-499'
441 +new BigNumber('1e-500') // '0'
442 +
443 +BigNumber.config({ RANGE: [-3, 4] })
444 +new BigNumber(99999) // '99999' e is only 4
445 +new BigNumber(100000) // 'Infinity' e is 5
446 +new BigNumber(0.001) // '0.01' e is only -3
447 +new BigNumber(0.0001) // '0' e is -4</pre>
448 + </dd>
449 + <dd>
450 + The largest possible magnitude of a finite BigNumber is
451 + <code>9.999...e+1000000000</code>.<br />
452 + The smallest possible magnitude of a non-zero BigNumber is <code>1e-1000000000</code>.
453 + </dd>
454 +
455 +
456 +
457 + <dt id="crypto"><code><b>CRYPTO</b></code></dt>
458 + <dd>
459 + <i>boolean</i>: <code>true</code> or <code>false</code>.<br />
460 + Default value: <code>false</code>
461 + </dd>
462 + <dd>
463 + The value that determines whether cryptographically-secure pseudo-random number
464 + generation is used.
465 + </dd>
466 + <dd>
467 + If <code>CRYPTO</code> is set to <code>true</code> then the
468 + <a href='#random'><code>random</code></a> method will generate random digits using
469 + <code>crypto.getRandomValues</code> in browsers that support it, or
470 + <code>crypto.randomBytes</code> if using Node.js.
471 + </dd>
472 + <dd>
473 + If neither function is supported by the host environment then attempting to set
474 + <code>CRYPTO</code> to <code>true</code> will fail and an exception will be thrown.
475 + </dd>
476 + <dd>
477 + If <code>CRYPTO</code> is <code>false</code> then the source of randomness used will be
478 + <code>Math.random</code> (which is assumed to generate at least <code>30</code> bits of
479 + randomness).
480 + </dd>
481 + <dd>See <a href='#random'><code>random</code></a>.</dd>
482 + <dd>
483 + <pre>
484 +// Node.js
485 +global.crypto = require('crypto')
486 +
487 +BigNumber.config({ CRYPTO: true })
488 +BigNumber.config().CRYPTO // true
489 +BigNumber.random() // 0.54340758610486147524</pre>
490 + </dd>
491 +
492 +
493 +
494 + <dt id="modulo-mode"><code><b>MODULO_MODE</b></code></dt>
495 + <dd>
496 + <i>number</i>: integer, <code>0</code> to <code>9</code> inclusive<br />
497 + Default value: <code>1</code> (<a href="#round-down"><code>ROUND_DOWN</code></a>)
498 + </dd>
499 + <dd>The modulo mode used when calculating the modulus: <code>a mod n</code>.</dd>
500 + <dd>
501 + The quotient, <code>q = a / n</code>, is calculated according to the
502 + <a href='#rounding-mode'><code>ROUNDING_MODE</code></a> that corresponds to the chosen
503 + <code>MODULO_MODE</code>.
504 + </dd>
505 + <dd>The remainder, <code>r</code>, is calculated as: <code>r = a - n * q</code>.</dd>
506 + <dd>
507 + The modes that are most commonly used for the modulus/remainder operation are shown in
508 + the following table. Although the other rounding modes can be used, they may not give
509 + useful results.
510 + </dd>
511 + <dd>
512 + <table>
513 + <tr><th>Property</th><th>Value</th><th>Description</th></tr>
514 + <tr>
515 + <td><b>ROUND_UP</b></td><td class='centre'>0</td>
516 + <td>
517 + The remainder is positive if the dividend is negative, otherwise it is negative.
518 + </td>
519 + </tr>
520 + <tr>
521 + <td><b>ROUND_DOWN</b></td><td class='centre'>1</td>
522 + <td>
523 + The remainder has the same sign as the dividend.<br />
524 + This uses 'truncating division' and matches the behaviour of JavaScript's
525 + remainder operator <code>%</code>.
526 + </td>
527 + </tr>
528 + <tr>
529 + <td><b>ROUND_FLOOR</b></td><td class='centre'>3</td>
530 + <td>
531 + The remainder has the same sign as the divisor.<br />
532 + This matches Python's <code>%</code> operator.
533 + </td>
534 + </tr>
535 + <tr>
536 + <td><b>ROUND_HALF_EVEN</b></td><td class='centre'>6</td>
537 + <td>The <i>IEEE 754</i> remainder function.</td>
538 + </tr>
539 + <tr>
540 + <td><b>EUCLID</b></td><td class='centre'>9</td>
541 + <td>
542 + The remainder is always positive. Euclidian division: <br />
543 + <code>q = sign(n) * floor(a / abs(n))</code>
544 + </td>
545 + </tr>
546 + </table>
547 + </dd>
548 + <dd>
549 + The rounding/modulo modes are available as enumerated properties of the BigNumber
550 + constructor.
551 + </dd>
552 + <dd>See <a href='#mod'><code>modulo</code></a>.</dd>
553 + <dd>
554 + <pre>BigNumber.config({ MODULO_MODE: BigNumber.EUCLID })
555 +BigNumber.config({ MODULO_MODE: 9 }) // equivalent</pre>
556 + </dd>
557 +
558 +
559 +
560 + <dt id="pow-precision"><code><b>POW_PRECISION</b></code></dt>
561 + <dd>
562 + <i>number</i>: integer, <code>0</code> to <code>1e+9</code> inclusive.<br />
563 + Default value: <code>0</code>
564 + </dd>
565 + <dd>
566 + The <i>maximum</i> precision, i.e. number of significant digits, of the result of the power
567 + operation (unless a modulus is specified).
568 + </dd>
569 + <dd>If set to <code>0</code>, the number of significant digits will not be limited.</dd>
570 + <dd>See <a href='#pow'><code>exponentiatedBy</code></a>.</dd>
571 + <dd><pre>BigNumber.config({ POW_PRECISION: 100 })</pre></dd>
572 +
573 +
574 +
575 + <dt id="format"><code><b>FORMAT</b></code></dt>
576 + <dd><i>object</i></dd>
577 + <dd>
578 + The <code>FORMAT</code> object configures the format of the string returned by the
579 + <a href='#toFor'><code>toFormat</code></a> method.
580 + </dd>
581 + <dd>
582 + The example below shows the properties of the <code>FORMAT</code> object that are
583 + recognised, and their default values.
584 + </dd>
585 + <dd>
586 + Unlike the other configuration properties, the values of the properties of the
587 + <code>FORMAT</code> object will not be checked for validity. The existing
588 + <code>FORMAT</code> object will simply be replaced by the object that is passed in.
589 + The object can include any number of the properties shown below.
590 + </dd>
591 + <dd>See <a href='#toFor'><code>toFormat</code></a> for examples of usage.</dd>
592 + <dd>
593 + <pre>
594 +BigNumber.config({
595 + FORMAT: {
596 + // string to prepend
597 + prefix: '',
598 + // decimal separator
599 + decimalSeparator: '.',
600 + // grouping separator of the integer part
601 + groupSeparator: ',',
602 + // primary grouping size of the integer part
603 + groupSize: 3,
604 + // secondary grouping size of the integer part
605 + secondaryGroupSize: 0,
606 + // grouping separator of the fraction part
607 + fractionGroupSeparator: ' ',
608 + // grouping size of the fraction part
609 + fractionGroupSize: 0,
610 + // string to append
611 + suffix: ''
612 + }
613 +});</pre>
614 + </dd>
615 +
616 +
617 +
618 + <dt id="alphabet"><code><b>ALPHABET</b></code></dt>
619 + <dd>
620 + <i>string</i><br />
621 + Default value: <code>'0123456789abcdefghijklmnopqrstuvwxyz'</code>
622 + </dd>
623 + <dd>
624 + The alphabet used for base conversion. The length of the alphabet corresponds to the
625 + maximum value of the base argument that can be passed to the
626 + <a href='#bignumber'><code>BigNumber</code></a> constructor or
627 + <a href='#toS'><code>toString</code></a>.
628 + </dd>
629 + <dd>
630 + There is no maximum length for the alphabet, but it must be at least 2 characters long, and
631 + it must not contain whitespace or a repeated character, or the sign indicators
632 + <code>'+'</code> and <code>'-'</code>, or the decimal separator <code>'.'</code>.
633 + </dd>
634 + <dd>
635 + <pre>// duodecimal (base 12)
636 +BigNumber.config({ ALPHABET: '0123456789TE' })
637 +x = new BigNumber('T', 12)
638 +x.toString() // '10'
639 +x.toString(12) // 'T'</pre>
640 + </dd>
641 +
642 +
643 +
644 + </dl>
645 + <br /><br />
646 + <p>Returns an object with the above properties and their current values.</p>
647 + <p>
648 + Throws if <code>object</code> is not an object, or if an invalid value is assigned to
649 + one or more of the above properties. See <a href='#Errors'>Errors</a>.
650 + </p>
651 + <pre>
652 +BigNumber.config({
653 + DECIMAL_PLACES: 40,
654 + ROUNDING_MODE: BigNumber.ROUND_HALF_CEIL,
655 + EXPONENTIAL_AT: [-10, 20],
656 + RANGE: [-500, 500],
657 + CRYPTO: true,
658 + MODULO_MODE: BigNumber.ROUND_FLOOR,
659 + POW_PRECISION: 80,
660 + FORMAT: {
661 + groupSize: 3,
662 + groupSeparator: ' ',
663 + decimalSeparator: ','
664 + },
665 + ALPHABET: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_'
666 +});
667 +
668 +obj = BigNumber.config();
669 +obj.DECIMAL_PLACES // 40
670 +obj.RANGE // [-500, 500]</pre>
671 +
672 +
673 +
674 + <h5 id="isBigNumber">
675 + isBigNumber<code class='inset'>.isBigNumber(value) <i>&rArr; boolean</i></code>
676 + </h5>
677 + <p><code>value</code>: <i>any</i><br /></p>
678 + <p>
679 + Returns <code>true</code> if <code>value</code> is a BigNumber instance, otherwise returns
680 + <code>false</code>.
681 + </p>
682 + <pre>x = 42
683 +y = new BigNumber(x)
684 +
685 +BigNumber.isBigNumber(x) // false
686 +y instanceof BigNumber // true
687 +BigNumber.isBigNumber(y) // true
688 +
689 +BN = BigNumber.clone();
690 +z = new BN(x)
691 +z instanceof BigNumber // false
692 +BigNumber.isBigNumber(z) // true</pre>
693 + <p>
694 + If <code>value</code> is a BigNumber instance and <code>BigNumber.DEBUG</code> is <code>true</code>,
695 + then this method will also check if <code>value</code> is well-formed, and throw if it is not.
696 + See <a href='#Errors'>Errors</a>.
697 + </p>
698 + <p>
699 + The check can be useful if creating a BigNumber from an object literal.
700 + See <a href='#bignumber'>BigNumber</a>.
701 + </p>
702 + <pre>
703 +x = new BigNumber(10)
704 +
705 +// Change x.c to an illegitimate value.
706 +x.c = NaN
707 +
708 +BigNumber.DEBUG = false
709 +
710 +// No error.
711 +BigNumber.isBigNumber(x) // true
712 +
713 +BigNumber.DEBUG = true
714 +
715 +// Error.
716 +BigNumber.isBigNumber(x) // '[BigNumber Error] Invalid BigNumber'</pre>
717 +
718 +
719 +
720 + <h5 id="max">maximum<code class='inset'>.max(n...) <i>&rArr; BigNumber</i></code></h5>
721 + <p>
722 + <code>n</code>: <i>number|string|BigNumber</i><br />
723 + <i>See <code><a href="#bignumber">BigNumber</a></code> for further parameter details.</i>
724 + </p>
725 + <p>
726 + Returns a BigNumber whose value is the maximum of the arguments.
727 + </p>
728 + <p>The return value is always exact and unrounded.</p>
729 + <pre>x = new BigNumber('3257869345.0378653')
730 +BigNumber.maximum(4e9, x, '123456789.9') // '4000000000'
731 +
732 +arr = [12, '13', new BigNumber(14)]
733 +BigNumber.max.apply(null, arr) // '14'</pre>
734 +
735 +
736 +
737 + <h5 id="min">minimum<code class='inset'>.min(n...) <i>&rArr; BigNumber</i></code></h5>
738 + <p>
739 + <code>n</code>: <i>number|string|BigNumber</i><br />
740 + <i>See <code><a href="#bignumber">BigNumber</a></code> for further parameter details.</i>
741 + </p>
742 + <p>
743 + Returns a BigNumber whose value is the minimum of the arguments.
744 + </p>
745 + <p>The return value is always exact and unrounded.</p>
746 + <pre>x = new BigNumber('3257869345.0378653')
747 +BigNumber.minimum(4e9, x, '123456789.9') // '123456789.9'
748 +
749 +arr = [2, new BigNumber(-14), '-15.9999', -12]
750 +BigNumber.min.apply(null, arr) // '-15.9999'</pre>
751 +
752 +
753 +
754 + <h5 id="random">
755 + random<code class='inset'>.random([dp]) <i>&rArr; BigNumber</i></code>
756 + </h5>
757 + <p><code>dp</code>: <i>number</i>: integer, <code>0</code> to <code>1e+9</code> inclusive</p>
758 + <p>
759 + Returns a new BigNumber with a pseudo-random value equal to or greater than <code>0</code> and
760 + less than <code>1</code>.
761 + </p>
762 + <p>
763 + The return value will have <code>dp</code> decimal places (or less if trailing zeros are
764 + produced).<br />
765 + If <code>dp</code> is omitted then the number of decimal places will default to the current
766 + <a href='#decimal-places'><code>DECIMAL_PLACES</code></a> setting.
767 + </p>
768 + <p>
769 + Depending on the value of this BigNumber constructor's
770 + <a href='#crypto'><code>CRYPTO</code></a> setting and the support for the
771 + <code>crypto</code> object in the host environment, the random digits of the return value are
772 + generated by either <code>Math.random</code> (fastest), <code>crypto.getRandomValues</code>
773 + (Web Cryptography API in recent browsers) or <code>crypto.randomBytes</code> (Node.js).
774 + </p>
775 + <p>
776 + To be able to set <a href='#crypto'><code>CRYPTO</code></a> to <code>true</code> when using
777 + Node.js, the <code>crypto</code> object must be available globally:
778 + </p>
779 + <pre>global.crypto = require('crypto')</pre>
780 + <p>
781 + If <a href='#crypto'><code>CRYPTO</code></a> is <code>true</code>, i.e. one of the
782 + <code>crypto</code> methods is to be used, the value of a returned BigNumber should be
783 + cryptographically-secure and statistically indistinguishable from a random value.
784 + </p>
785 + <p>
786 + Throws if <code>dp</code> is invalid. See <a href='#Errors'>Errors</a>.
787 + </p>
788 + <pre>BigNumber.config({ DECIMAL_PLACES: 10 })
789 +BigNumber.random() // '0.4117936847'
790 +BigNumber.random(20) // '0.78193327636914089009'</pre>
791 +
792 +
793 +
794 + <h5 id="sum">sum<code class='inset'>.sum(n...) <i>&rArr; BigNumber</i></code></h5>
795 + <p>
796 + <code>n</code>: <i>number|string|BigNumber</i><br />
797 + <i>See <code><a href="#bignumber">BigNumber</a></code> for further parameter details.</i>
798 + </p>
799 + <p>Returns a BigNumber whose value is the sum of the arguments.</p>
800 + <p>The return value is always exact and unrounded.</p>
801 + <pre>x = new BigNumber('3257869345.0378653')
802 +BigNumber.sum(4e9, x, '123456789.9') // '7381326134.9378653'
803 +
804 +arr = [2, new BigNumber(14), '15.9999', 12]
805 +BigNumber.sum.apply(null, arr) // '43.9999'</pre>
806 +
807 +
808 +
809 + <h4 id="constructor-properties">Properties</h4>
810 + <p>
811 + The library's enumerated rounding modes are stored as properties of the constructor.<br />
812 + (They are not referenced internally by the library itself.)
813 + </p>
814 + <p>
815 + Rounding modes <code>0</code> to <code>6</code> (inclusive) are the same as those of Java's
816 + BigDecimal class.
817 + </p>
818 + <table>
819 + <tr>
820 + <th>Property</th>
821 + <th>Value</th>
822 + <th>Description</th>
823 + </tr>
824 + <tr>
825 + <td id="round-up"><b>ROUND_UP</b></td>
826 + <td class='centre'>0</td>
827 + <td>Rounds away from zero</td>
828 + </tr>
829 + <tr>
830 + <td id="round-down"><b>ROUND_DOWN</b></td>
831 + <td class='centre'>1</td>
832 + <td>Rounds towards zero</td>
833 + </tr>
834 + <tr>
835 + <td id="round-ceil"><b>ROUND_CEIL</b></td>
836 + <td class='centre'>2</td>
837 + <td>Rounds towards <code>Infinity</code></td>
838 + </tr>
839 + <tr>
840 + <td id="round-floor"><b>ROUND_FLOOR</b></td>
841 + <td class='centre'>3</td>
842 + <td>Rounds towards <code>-Infinity</code></td>
843 + </tr>
844 + <tr>
845 + <td id="round-half-up"><b>ROUND_HALF_UP</b></td>
846 + <td class='centre'>4</td>
847 + <td>
848 + Rounds towards nearest neighbour.<br />
849 + If equidistant, rounds away from zero
850 + </td>
851 + </tr>
852 + <tr>
853 + <td id="round-half-down"><b>ROUND_HALF_DOWN</b></td>
854 + <td class='centre'>5</td>
855 + <td>
856 + Rounds towards nearest neighbour.<br />
857 + If equidistant, rounds towards zero
858 + </td>
859 + </tr>
860 + <tr>
861 + <td id="round-half-even"><b>ROUND_HALF_EVEN</b></td>
862 + <td class='centre'>6</td>
863 + <td>
864 + Rounds towards nearest neighbour.<br />
865 + If equidistant, rounds towards even neighbour
866 + </td>
867 + </tr>
868 + <tr>
869 + <td id="round-half-ceil"><b>ROUND_HALF_CEIL</b></td>
870 + <td class='centre'>7</td>
871 + <td>
872 + Rounds towards nearest neighbour.<br />
873 + If equidistant, rounds towards <code>Infinity</code>
874 + </td>
875 + </tr>
876 + <tr>
877 + <td id="round-half-floor"><b>ROUND_HALF_FLOOR</b></td>
878 + <td class='centre'>8</td>
879 + <td>
880 + Rounds towards nearest neighbour.<br />
881 + If equidistant, rounds towards <code>-Infinity</code>
882 + </td>
883 + </tr>
884 + </table>
885 + <pre>
886 +BigNumber.config({ ROUNDING_MODE: BigNumber.ROUND_CEIL })
887 +BigNumber.config({ ROUNDING_MODE: 2 }) // equivalent</pre>
888 +
889 + <h5 id="debug">DEBUG</h5>
890 + <p><i>undefined|false|true</i></p>
891 + <p>
892 + If <code>BigNumber.DEBUG</code> is set <code>true</code> then an error will be thrown
893 + if this <a href='#bignumber'>BigNumber</a> constructor receives an invalid value, such as
894 + a value of type <em>number</em> with more than <code>15</code> significant digits.
895 + See <a href='#bignumber'>BigNumber</a>.
896 + </p>
897 + <p>
898 + An error will also be thrown if the <code><a href='#isBigNumber'>isBigNumber</a></code>
899 + method receives a BigNumber that is not well-formed.
900 + See <code><a href='#isBigNumber'>isBigNumber</a></code>.
901 + </p>
902 + <pre>BigNumber.DEBUG = true</pre>
903 +
904 +
905 + <h3>INSTANCE</h3>
906 +
907 +
908 + <h4 id="prototype-methods">Methods</h4>
909 + <p>The methods inherited by a BigNumber instance from its constructor's prototype object.</p>
910 + <p>A BigNumber is immutable in the sense that it is not changed by its methods. </p>
911 + <p>
912 + The treatment of &plusmn;<code>0</code>, &plusmn;<code>Infinity</code> and <code>NaN</code> is
913 + consistent with how JavaScript treats these values.
914 + </p>
915 + <p>Many method names have a shorter alias.</p>
916 +
917 +
918 +
919 + <h5 id="abs">absoluteValue<code class='inset'>.abs() <i>&rArr; BigNumber</i></code></h5>
920 + <p>
921 + Returns a BigNumber whose value is the absolute value, i.e. the magnitude, of the value of
922 + this BigNumber.
923 + </p>
924 + <p>The return value is always exact and unrounded.</p>
925 + <pre>
926 +x = new BigNumber(-0.8)
927 +y = x.absoluteValue() // '0.8'
928 +z = y.abs() // '0.8'</pre>
929 +
930 +
931 +
932 + <h5 id="cmp">
933 + comparedTo<code class='inset'>.comparedTo(n [, base]) <i>&rArr; number</i></code>
934 + </h5>
935 + <p>
936 + <code>n</code>: <i>number|string|BigNumber</i><br />
937 + <code>base</code>: <i>number</i><br />
938 + <i>See <a href="#bignumber">BigNumber</a> for further parameter details.</i>
939 + </p>
940 + <table>
941 + <tr><th>Returns</th><th>&nbsp;</th></tr>
942 + <tr>
943 + <td class='centre'><code>1</code></td>
944 + <td>If the value of this BigNumber is greater than the value of <code>n</code></td>
945 + </tr>
946 + <tr>
947 + <td class='centre'><code>-1</code></td>
948 + <td>If the value of this BigNumber is less than the value of <code>n</code></td>
949 + </tr>
950 + <tr>
951 + <td class='centre'><code>0</code></td>
952 + <td>If this BigNumber and <code>n</code> have the same value</td>
953 + </tr>
954 + <tr>
955 + <td class='centre'><code>null</code></td>
956 + <td>If the value of either this BigNumber or <code>n</code> is <code>NaN</code></td>
957 + </tr>
958 + </table>
959 + <pre>
960 +x = new BigNumber(Infinity)
961 +y = new BigNumber(5)
962 +x.comparedTo(y) // 1
963 +x.comparedTo(x.minus(1)) // 0
964 +y.comparedTo(NaN) // null
965 +y.comparedTo('110', 2) // -1</pre>
966 +
967 +
968 +
969 + <h5 id="dp">
970 + decimalPlaces<code class='inset'>.dp([dp [, rm]]) <i>&rArr; BigNumber|number</i></code>
971 + </h5>
972 + <p>
973 + <code>dp</code>: <i>number</i>: integer, <code>0</code> to <code>1e+9</code> inclusive<br />
974 + <code>rm</code>: <i>number</i>: integer, <code>0</code> to <code>8</code> inclusive
975 + </p>
976 + <p>
977 + If <code>dp</code> is a number, returns a BigNumber whose value is the value of this BigNumber
978 + rounded by rounding mode <code>rm</code> to a maximum of <code>dp</code> decimal places.
979 + </p>
980 + <p>
981 + If <code>dp</code> is omitted, or is <code>null</code> or <code>undefined</code>, the return
982 + value is the number of decimal places of the value of this BigNumber, or <code>null</code> if
983 + the value of this BigNumber is &plusmn;<code>Infinity</code> or <code>NaN</code>.
984 + </p>
985 + <p>
986 + If <code>rm</code> is omitted, or is <code>null</code> or <code>undefined</code>,
987 + <a href='#rounding-mode'><code>ROUNDING_MODE</code></a> is used.
988 + </p>
989 + <p>
990 + Throws if <code>dp</code> or <code>rm</code> is invalid. See <a href='#Errors'>Errors</a>.
991 + </p>
992 + <pre>
993 +x = new BigNumber(1234.56)
994 +x.decimalPlaces(1) // '1234.6'
995 +x.dp() // 2
996 +x.decimalPlaces(2) // '1234.56'
997 +x.dp(10) // '1234.56'
998 +x.decimalPlaces(0, 1) // '1234'
999 +x.dp(0, 6) // '1235'
1000 +x.decimalPlaces(1, 1) // '1234.5'
1001 +x.dp(1, BigNumber.ROUND_HALF_EVEN) // '1234.6'
1002 +x // '1234.56'
1003 +y = new BigNumber('9.9e-101')
1004 +y.dp() // 102</pre>
1005 +
1006 +
1007 +
1008 + <h5 id="div">dividedBy<code class='inset'>.div(n [, base]) <i>&rArr; BigNumber</i></code>
1009 + </h5>
1010 + <p>
1011 + <code>n</code>: <i>number|string|BigNumber</i><br />
1012 + <code>base</code>: <i>number</i><br />
1013 + <i>See <a href="#bignumber">BigNumber</a> for further parameter details.</i>
1014 + </p>
1015 + <p>
1016 + Returns a BigNumber whose value is the value of this BigNumber divided by
1017 + <code>n</code>, rounded according to the current
1018 + <a href='#decimal-places'><code>DECIMAL_PLACES</code></a> and
1019 + <a href='#rounding-mode'><code>ROUNDING_MODE</code></a> settings.
1020 + </p>
1021 + <pre>
1022 +x = new BigNumber(355)
1023 +y = new BigNumber(113)
1024 +x.dividedBy(y) // '3.14159292035398230088'
1025 +x.div(5) // '71'
1026 +x.div(47, 16) // '5'</pre>
1027 +
1028 +
1029 +
1030 + <h5 id="divInt">
1031 + dividedToIntegerBy<code class='inset'>.idiv(n [, base]) &rArr;
1032 + <i>BigNumber</i></code>
1033 + </h5>
1034 + <p>
1035 + <code>n</code>: <i>number|string|BigNumber</i><br />
1036 + <code>base</code>: <i>number</i><br />
1037 + <i>See <a href="#bignumber">BigNumber</a> for further parameter details.</i>
1038 + </p>
1039 + <p>
1040 + Returns a BigNumber whose value is the integer part of dividing the value of this BigNumber by
1041 + <code>n</code>.
1042 + </p>
1043 + <pre>
1044 +x = new BigNumber(5)
1045 +y = new BigNumber(3)
1046 +x.dividedToIntegerBy(y) // '1'
1047 +x.idiv(0.7) // '7'
1048 +x.idiv('0.f', 16) // '5'</pre>
1049 +
1050 +
1051 +
1052 + <h5 id="pow">
1053 + exponentiatedBy<code class='inset'>.pow(n [, m]) <i>&rArr; BigNumber</i></code>
1054 + </h5>
1055 + <p>
1056 + <code>n</code>: <i>number|string|BigNumber</i>: integer<br />
1057 + <code>m</code>: <i>number|string|BigNumber</i>
1058 + </p>
1059 + <p>
1060 + Returns a BigNumber whose value is the value of this BigNumber exponentiated by
1061 + <code>n</code>, i.e. raised to the power <code>n</code>, and optionally modulo a modulus
1062 + <code>m</code>.
1063 + </p>
1064 + <p>
1065 + Throws if <code>n</code> is not an integer. See <a href='#Errors'>Errors</a>.
1066 + </p>
1067 + <p>
1068 + If <code>n</code> is negative the result is rounded according to the current
1069 + <a href='#decimal-places'><code>DECIMAL_PLACES</code></a> and
1070 + <a href='#rounding-mode'><code>ROUNDING_MODE</code></a> settings.
1071 + </p>
1072 + <p>
1073 + As the number of digits of the result of the power operation can grow so large so quickly,
1074 + e.g. 123.456<sup>10000</sup> has over <code>50000</code> digits, the number of significant
1075 + digits calculated is limited to the value of the
1076 + <a href='#pow-precision'><code>POW_PRECISION</code></a> setting (unless a modulus
1077 + <code>m</code> is specified).
1078 + </p>
1079 + <p>
1080 + By default <a href='#pow-precision'><code>POW_PRECISION</code></a> is set to <code>0</code>.
1081 + This means that an unlimited number of significant digits will be calculated, and that the
1082 + method's performance will decrease dramatically for larger exponents.
1083 + </p>
1084 + <p>
1085 + If <code>m</code> is specified and the value of <code>m</code>, <code>n</code> and this
1086 + BigNumber are integers, and <code>n</code> is positive, then a fast modular exponentiation
1087 + algorithm is used, otherwise the operation will be performed as
1088 + <code>x.exponentiatedBy(n).modulo(m)</code> with a
1089 + <a href='#pow-precision'><code>POW_PRECISION</code></a> of <code>0</code>.
1090 + </p>
1091 + <pre>
1092 +Math.pow(0.7, 2) // 0.48999999999999994
1093 +x = new BigNumber(0.7)
1094 +x.exponentiatedBy(2) // '0.49'
1095 +BigNumber(3).pow(-2) // '0.11111111111111111111'</pre>
1096 +
1097 +
1098 +
1099 + <h5 id="int">
1100 + integerValue<code class='inset'>.integerValue([rm]) <i>&rArr; BigNumber</i></code>
1101 + </h5>
1102 + <p>
1103 + <code>rm</code>: <i>number</i>: integer, <code>0</code> to <code>8</code> inclusive
1104 + </p>
1105 + <p>
1106 + Returns a BigNumber whose value is the value of this BigNumber rounded to an integer using
1107 + rounding mode <code>rm</code>.
1108 + </p>
1109 + <p>
1110 + If <code>rm</code> is omitted, or is <code>null</code> or <code>undefined</code>,
1111 + <a href='#rounding-mode'><code>ROUNDING_MODE</code></a> is used.
1112 + </p>
1113 + <p>
1114 + Throws if <code>rm</code> is invalid. See <a href='#Errors'>Errors</a>.
1115 + </p>
1116 + <pre>
1117 +x = new BigNumber(123.456)
1118 +x.integerValue() // '123'
1119 +x.integerValue(BigNumber.ROUND_CEIL) // '124'
1120 +y = new BigNumber(-12.7)
1121 +y.integerValue() // '-13'
1122 +y.integerValue(BigNumber.ROUND_DOWN) // '-12'</pre>
1123 + <p>
1124 + The following is an example of how to add a prototype method that emulates JavaScript's
1125 + <code>Math.round</code> function. <code>Math.ceil</code>, <code>Math.floor</code> and
1126 + <code>Math.trunc</code> can be emulated in the same way with
1127 + <code>BigNumber.ROUND_CEIL</code>, <code>BigNumber.ROUND_FLOOR</code> and
1128 + <code> BigNumber.ROUND_DOWN</code> respectively.
1129 + </p>
1130 + <pre>
1131 +BigNumber.prototype.round = function (n) {
1132 + return n.integerValue(BigNumber.ROUND_HALF_CEIL);
1133 +};
1134 +x.round() // '123'</pre>
1135 +
1136 +
1137 +
1138 + <h5 id="eq">isEqualTo<code class='inset'>.eq(n [, base]) <i>&rArr; boolean</i></code></h5>
1139 + <p>
1140 + <code>n</code>: <i>number|string|BigNumber</i><br />
1141 + <code>base</code>: <i>number</i><br />
1142 + <i>See <a href="#bignumber">BigNumber</a> for further parameter details.</i>
1143 + </p>
1144 + <p>
1145 + Returns <code>true</code> if the value of this BigNumber is equal to the value of
1146 + <code>n</code>, otherwise returns <code>false</code>.<br />
1147 + As with JavaScript, <code>NaN</code> does not equal <code>NaN</code>.
1148 + </p>
1149 + <p>Note: This method uses the <a href='#cmp'><code>comparedTo</code></a> method internally.</p>
1150 + <pre>
1151 +0 === 1e-324 // true
1152 +x = new BigNumber(0)
1153 +x.isEqualTo('1e-324') // false
1154 +BigNumber(-0).eq(x) // true ( -0 === 0 )
1155 +BigNumber(255).eq('ff', 16) // true
1156 +
1157 +y = new BigNumber(NaN)
1158 +y.isEqualTo(NaN) // false</pre>
1159 +
1160 +
1161 +
1162 + <h5 id="isF">isFinite<code class='inset'>.isFinite() <i>&rArr; boolean</i></code></h5>
1163 + <p>
1164 + Returns <code>true</code> if the value of this BigNumber is a finite number, otherwise
1165 + returns <code>false</code>.
1166 + </p>
1167 + <p>
1168 + The only possible non-finite values of a BigNumber are <code>NaN</code>, <code>Infinity</code>
1169 + and <code>-Infinity</code>.
1170 + </p>
1171 + <pre>
1172 +x = new BigNumber(1)
1173 +x.isFinite() // true
1174 +y = new BigNumber(Infinity)
1175 +y.isFinite() // false</pre>
1176 + <p>
1177 + Note: The native method <code>isFinite()</code> can be used if
1178 + <code>n &lt;= Number.MAX_VALUE</code>.
1179 + </p>
1180 +
1181 +
1182 +
1183 + <h5 id="gt">isGreaterThan<code class='inset'>.gt(n [, base]) <i>&rArr; boolean</i></code></h5>
1184 + <p>
1185 + <code>n</code>: <i>number|string|BigNumber</i><br />
1186 + <code>base</code>: <i>number</i><br />
1187 + <i>See <a href="#bignumber">BigNumber</a> for further parameter details.</i>
1188 + </p>
1189 + <p>
1190 + Returns <code>true</code> if the value of this BigNumber is greater than the value of
1191 + <code>n</code>, otherwise returns <code>false</code>.
1192 + </p>
1193 + <p>Note: This method uses the <a href='#cmp'><code>comparedTo</code></a> method internally.</p>
1194 + <pre>
1195 +0.1 &gt; (0.3 - 0.2) // true
1196 +x = new BigNumber(0.1)
1197 +x.isGreaterThan(BigNumber(0.3).minus(0.2)) // false
1198 +BigNumber(0).gt(x) // false
1199 +BigNumber(11, 3).gt(11.1, 2) // true</pre>
1200 +
1201 +
1202 +
1203 + <h5 id="gte">
1204 + isGreaterThanOrEqualTo<code class='inset'>.gte(n [, base]) <i>&rArr; boolean</i></code>
1205 + </h5>
1206 + <p>
1207 + <code>n</code>: <i>number|string|BigNumber</i><br />
1208 + <code>base</code>: <i>number</i><br />
1209 + <i>See <a href="#bignumber">BigNumber</a> for further parameter details.</i>
1210 + </p>
1211 + <p>
1212 + Returns <code>true</code> if the value of this BigNumber is greater than or equal to the value
1213 + of <code>n</code>, otherwise returns <code>false</code>.
1214 + </p>
1215 + <p>Note: This method uses the <a href='#cmp'><code>comparedTo</code></a> method internally.</p>
1216 + <pre>
1217 +(0.3 - 0.2) &gt;= 0.1 // false
1218 +x = new BigNumber(0.3).minus(0.2)
1219 +x.isGreaterThanOrEqualTo(0.1) // true
1220 +BigNumber(1).gte(x) // true
1221 +BigNumber(10, 18).gte('i', 36) // true</pre>
1222 +
1223 +
1224 +
1225 + <h5 id="isInt">isInteger<code class='inset'>.isInteger() <i>&rArr; boolean</i></code></h5>
1226 + <p>
1227 + Returns <code>true</code> if the value of this BigNumber is an integer, otherwise returns
1228 + <code>false</code>.
1229 + </p>
1230 + <pre>
1231 +x = new BigNumber(1)
1232 +x.isInteger() // true
1233 +y = new BigNumber(123.456)
1234 +y.isInteger() // false</pre>
1235 +
1236 +
1237 +
1238 + <h5 id="lt">isLessThan<code class='inset'>.lt(n [, base]) <i>&rArr; boolean</i></code></h5>
1239 + <p>
1240 + <code>n</code>: <i>number|string|BigNumber</i><br />
1241 + <code>base</code>: <i>number</i><br />
1242 + <i>See <a href="#bignumber">BigNumber</a> for further parameter details.</i>
1243 + </p>
1244 + <p>
1245 + Returns <code>true</code> if the value of this BigNumber is less than the value of
1246 + <code>n</code>, otherwise returns <code>false</code>.
1247 + </p>
1248 + <p>Note: This method uses the <a href='#cmp'><code>comparedTo</code></a> method internally.</p>
1249 + <pre>
1250 +(0.3 - 0.2) &lt; 0.1 // true
1251 +x = new BigNumber(0.3).minus(0.2)
1252 +x.isLessThan(0.1) // false
1253 +BigNumber(0).lt(x) // true
1254 +BigNumber(11.1, 2).lt(11, 3) // true</pre>
1255 +
1256 +
1257 +
1258 + <h5 id="lte">
1259 + isLessThanOrEqualTo<code class='inset'>.lte(n [, base]) <i>&rArr; boolean</i></code>
1260 + </h5>
1261 + <p>
1262 + <code>n</code>: <i>number|string|BigNumber</i><br />
1263 + <code>base</code>: <i>number</i><br />
1264 + <i>See <a href="#bignumber">BigNumber</a> for further parameter details.</i>
1265 + </p>
1266 + <p>
1267 + Returns <code>true</code> if the value of this BigNumber is less than or equal to the value of
1268 + <code>n</code>, otherwise returns <code>false</code>.
1269 + </p>
1270 + <p>Note: This method uses the <a href='#cmp'><code>comparedTo</code></a> method internally.</p>
1271 + <pre>
1272 +0.1 &lt;= (0.3 - 0.2) // false
1273 +x = new BigNumber(0.1)
1274 +x.isLessThanOrEqualTo(BigNumber(0.3).minus(0.2)) // true
1275 +BigNumber(-1).lte(x) // true
1276 +BigNumber(10, 18).lte('i', 36) // true</pre>
1277 +
1278 +
1279 +
1280 + <h5 id="isNaN">isNaN<code class='inset'>.isNaN() <i>&rArr; boolean</i></code></h5>
1281 + <p>
1282 + Returns <code>true</code> if the value of this BigNumber is <code>NaN</code>, otherwise
1283 + returns <code>false</code>.
1284 + </p>
1285 + <pre>
1286 +x = new BigNumber(NaN)
1287 +x.isNaN() // true
1288 +y = new BigNumber('Infinity')
1289 +y.isNaN() // false</pre>
1290 + <p>Note: The native method <code>isNaN()</code> can also be used.</p>
1291 +
1292 +
1293 +
1294 + <h5 id="isNeg">isNegative<code class='inset'>.isNegative() <i>&rArr; boolean</i></code></h5>
1295 + <p>
1296 + Returns <code>true</code> if the sign of this BigNumber is negative, otherwise returns
1297 + <code>false</code>.
1298 + </p>
1299 + <pre>
1300 +x = new BigNumber(-0)
1301 +x.isNegative() // true
1302 +y = new BigNumber(2)
1303 +y.isNegative() // false</pre>
1304 + <p>Note: <code>n &lt; 0</code> can be used if <code>n &lt;= -Number.MIN_VALUE</code>.</p>
1305 +
1306 +
1307 +
1308 + <h5 id="isPos">isPositive<code class='inset'>.isPositive() <i>&rArr; boolean</i></code></h5>
1309 + <p>
1310 + Returns <code>true</code> if the sign of this BigNumber is positive, otherwise returns
1311 + <code>false</code>.
1312 + </p>
1313 + <pre>
1314 +x = new BigNumber(-0)
1315 +x.isPositive() // false
1316 +y = new BigNumber(2)
1317 +y.isPositive() // true</pre>
1318 +
1319 +
1320 +
1321 + <h5 id="isZ">isZero<code class='inset'>.isZero() <i>&rArr; boolean</i></code></h5>
1322 + <p>
1323 + Returns <code>true</code> if the value of this BigNumber is zero or minus zero, otherwise
1324 + returns <code>false</code>.
1325 + </p>
1326 + <pre>
1327 +x = new BigNumber(-0)
1328 +x.isZero() && x.isNegative() // true
1329 +y = new BigNumber(Infinity)
1330 +y.isZero() // false</pre>
1331 + <p>Note: <code>n == 0</code> can be used if <code>n &gt;= Number.MIN_VALUE</code>.</p>
1332 +
1333 +
1334 +
1335 + <h5 id="minus">
1336 + minus<code class='inset'>.minus(n [, base]) <i>&rArr; BigNumber</i></code>
1337 + </h5>
1338 + <p>
1339 + <code>n</code>: <i>number|string|BigNumber</i><br />
1340 + <code>base</code>: <i>number</i><br />
1341 + <i>See <a href="#bignumber">BigNumber</a> for further parameter details.</i>
1342 + </p>
1343 + <p>Returns a BigNumber whose value is the value of this BigNumber minus <code>n</code>.</p>
1344 + <p>The return value is always exact and unrounded.</p>
1345 + <pre>
1346 +0.3 - 0.1 // 0.19999999999999998
1347 +x = new BigNumber(0.3)
1348 +x.minus(0.1) // '0.2'
1349 +x.minus(0.6, 20) // '0'</pre>
1350 +
1351 +
1352 +
1353 + <h5 id="mod">modulo<code class='inset'>.mod(n [, base]) <i>&rArr; BigNumber</i></code></h5>
1354 + <p>
1355 + <code>n</code>: <i>number|string|BigNumber</i><br />
1356 + <code>base</code>: <i>number</i><br />
1357 + <i>See <a href="#bignumber">BigNumber</a> for further parameter details.</i>
1358 + </p>
1359 + <p>
1360 + Returns a BigNumber whose value is the value of this BigNumber modulo <code>n</code>, i.e.
1361 + the integer remainder of dividing this BigNumber by <code>n</code>.
1362 + </p>
1363 + <p>
1364 + The value returned, and in particular its sign, is dependent on the value of the
1365 + <a href='#modulo-mode'><code>MODULO_MODE</code></a> setting of this BigNumber constructor.
1366 + If it is <code>1</code> (default value), the result will have the same sign as this BigNumber,
1367 + and it will match that of Javascript's <code>%</code> operator (within the limits of double
1368 + precision) and BigDecimal's <code>remainder</code> method.
1369 + </p>
1370 + <p>The return value is always exact and unrounded.</p>
1371 + <p>
1372 + See <a href='#modulo-mode'><code>MODULO_MODE</code></a> for a description of the other
1373 + modulo modes.
1374 + </p>
1375 + <pre>
1376 +1 % 0.9 // 0.09999999999999998
1377 +x = new BigNumber(1)
1378 +x.modulo(0.9) // '0.1'
1379 +y = new BigNumber(33)
1380 +y.mod('a', 33) // '3'</pre>
1381 +
1382 +
1383 +
1384 + <h5 id="times">
1385 + multipliedBy<code class='inset'>.times(n [, base]) <i>&rArr; BigNumber</i></code>
1386 + </h5>
1387 + <p>
1388 + <code>n</code>: <i>number|string|BigNumber</i><br />
1389 + <code>base</code>: <i>number</i><br />
1390 + <i>See <a href="#bignumber">BigNumber</a> for further parameter details.</i>
1391 + </p>
1392 + <p>
1393 + Returns a BigNumber whose value is the value of this BigNumber multiplied by <code>n</code>.
1394 + </p>
1395 + <p>The return value is always exact and unrounded.</p>
1396 + <pre>
1397 +0.6 * 3 // 1.7999999999999998
1398 +x = new BigNumber(0.6)
1399 +y = x.multipliedBy(3) // '1.8'
1400 +BigNumber('7e+500').times(y) // '1.26e+501'
1401 +x.multipliedBy('-a', 16) // '-6'</pre>
1402 +
1403 +
1404 +
1405 + <h5 id="neg">negated<code class='inset'>.negated() <i>&rArr; BigNumber</i></code></h5>
1406 + <p>
1407 + Returns a BigNumber whose value is the value of this BigNumber negated, i.e. multiplied by
1408 + <code>-1</code>.
1409 + </p>
1410 + <pre>
1411 +x = new BigNumber(1.8)
1412 +x.negated() // '-1.8'
1413 +y = new BigNumber(-1.3)
1414 +y.negated() // '1.3'</pre>
1415 +
1416 +
1417 +
1418 + <h5 id="plus">plus<code class='inset'>.plus(n [, base]) <i>&rArr; BigNumber</i></code></h5>
1419 + <p>
1420 + <code>n</code>: <i>number|string|BigNumber</i><br />
1421 + <code>base</code>: <i>number</i><br />
1422 + <i>See <a href="#bignumber">BigNumber</a> for further parameter details.</i>
1423 + </p>
1424 + <p>Returns a BigNumber whose value is the value of this BigNumber plus <code>n</code>.</p>
1425 + <p>The return value is always exact and unrounded.</p>
1426 + <pre>
1427 +0.1 + 0.2 // 0.30000000000000004
1428 +x = new BigNumber(0.1)
1429 +y = x.plus(0.2) // '0.3'
1430 +BigNumber(0.7).plus(x).plus(y) // '1'
1431 +x.plus('0.1', 8) // '0.225'</pre>
1432 +
1433 +
1434 +
1435 + <h5 id="sd">
1436 + precision<code class='inset'>.sd([d [, rm]]) <i>&rArr; BigNumber|number</i></code>
1437 + </h5>
1438 + <p>
1439 + <code>d</code>: <i>number|boolean</i>: integer, <code>1</code> to <code>1e+9</code>
1440 + inclusive, or <code>true</code> or <code>false</code><br />
1441 + <code>rm</code>: <i>number</i>: integer, <code>0</code> to <code>8</code> inclusive.
1442 + </p>
1443 + <p>
1444 + If <code>d</code> is a number, returns a BigNumber whose value is the value of this BigNumber
1445 + rounded to a precision of <code>d</code> significant digits using rounding mode
1446 + <code>rm</code>.
1447 + </p>
1448 + <p>
1449 + If <code>d</code> is omitted or is <code>null</code> or <code>undefined</code>, the return
1450 + value is the number of significant digits of the value of this BigNumber, or <code>null</code>
1451 + if the value of this BigNumber is &plusmn;<code>Infinity</code> or <code>NaN</code>.</p>
1452 + </p>
1453 + <p>
1454 + If <code>d</code> is <code>true</code> then any trailing zeros of the integer
1455 + part of a number are counted as significant digits, otherwise they are not.
1456 + </p>
1457 + <p>
1458 + If <code>rm</code> is omitted or is <code>null</code> or <code>undefined</code>,
1459 + <a href='#rounding-mode'><code>ROUNDING_MODE</code></a> will be used.
1460 + </p>
1461 + <p>
1462 + Throws if <code>d</code> or <code>rm</code> is invalid. See <a href='#Errors'>Errors</a>.
1463 + </p>
1464 + <pre>
1465 +x = new BigNumber(9876.54321)
1466 +x.precision(6) // '9876.54'
1467 +x.sd() // 9
1468 +x.precision(6, BigNumber.ROUND_UP) // '9876.55'
1469 +x.sd(2) // '9900'
1470 +x.precision(2, 1) // '9800'
1471 +x // '9876.54321'
1472 +y = new BigNumber(987000)
1473 +y.precision() // 3
1474 +y.sd(true) // 6</pre>
1475 +
1476 +
1477 +
1478 +<h5 id="shift">shiftedBy<code class='inset'>.shiftedBy(n) <i>&rArr; BigNumber</i></code></h5>
1479 + <p>
1480 + <code>n</code>: <i>number</i>: integer,
1481 + <code>-9007199254740991</code> to <code>9007199254740991</code> inclusive
1482 + </p>
1483 + <p>
1484 + Returns a BigNumber whose value is the value of this BigNumber shifted by <code>n</code>
1485 + places.
1486 + <p>
1487 + The shift is of the decimal point, i.e. of powers of ten, and is to the left if <code>n</code>
1488 + is negative or to the right if <code>n</code> is positive.
1489 + </p>
1490 + <p>The return value is always exact and unrounded.</p>
1491 + <p>
1492 + Throws if <code>n</code> is invalid. See <a href='#Errors'>Errors</a>.
1493 + </p>
1494 + <pre>
1495 +x = new BigNumber(1.23)
1496 +x.shiftedBy(3) // '1230'
1497 +x.shiftedBy(-3) // '0.00123'</pre>
1498 +
1499 +
1500 +
1501 + <h5 id="sqrt">squareRoot<code class='inset'>.sqrt() <i>&rArr; BigNumber</i></code></h5>
1502 + <p>
1503 + Returns a BigNumber whose value is the square root of the value of this BigNumber,
1504 + rounded according to the current
1505 + <a href='#decimal-places'><code>DECIMAL_PLACES</code></a> and
1506 + <a href='#rounding-mode'><code>ROUNDING_MODE</code></a> settings.
1507 + </p>
1508 + <p>
1509 + The return value will be correctly rounded, i.e. rounded as if the result was first calculated
1510 + to an infinite number of correct digits before rounding.
1511 + </p>
1512 + <pre>
1513 +x = new BigNumber(16)
1514 +x.squareRoot() // '4'
1515 +y = new BigNumber(3)
1516 +y.sqrt() // '1.73205080756887729353'</pre>
1517 +
1518 +
1519 +
1520 + <h5 id="toE">
1521 + toExponential<code class='inset'>.toExponential([dp [, rm]]) <i>&rArr; string</i></code>
1522 + </h5>
1523 + <p>
1524 + <code>dp</code>: <i>number</i>: integer, <code>0</code> to <code>1e+9</code> inclusive<br />
1525 + <code>rm</code>: <i>number</i>: integer, <code>0</code> to <code>8</code> inclusive
1526 + </p>
1527 + <p>
1528 + Returns a string representing the value of this BigNumber in exponential notation rounded
1529 + using rounding mode <code>rm</code> to <code>dp</code> decimal places, i.e with one digit
1530 + before the decimal point and <code>dp</code> digits after it.
1531 + </p>
1532 + <p>
1533 + If the value of this BigNumber in exponential notation has fewer than <code>dp</code> fraction
1534 + digits, the return value will be appended with zeros accordingly.
1535 + </p>
1536 + <p>
1537 + If <code>dp</code> is omitted, or is <code>null</code> or <code>undefined</code>, the number
1538 + of digits after the decimal point defaults to the minimum number of digits necessary to
1539 + represent the value exactly.<br />
1540 + If <code>rm</code> is omitted or is <code>null</code> or <code>undefined</code>,
1541 + <a href='#rounding-mode'><code>ROUNDING_MODE</code></a> is used.
1542 + </p>
1543 + <p>
1544 + Throws if <code>dp</code> or <code>rm</code> is invalid. See <a href='#Errors'>Errors</a>.
1545 + </p>
1546 + <pre>
1547 +x = 45.6
1548 +y = new BigNumber(x)
1549 +x.toExponential() // '4.56e+1'
1550 +y.toExponential() // '4.56e+1'
1551 +x.toExponential(0) // '5e+1'
1552 +y.toExponential(0) // '5e+1'
1553 +x.toExponential(1) // '4.6e+1'
1554 +y.toExponential(1) // '4.6e+1'
1555 +y.toExponential(1, 1) // '4.5e+1' (ROUND_DOWN)
1556 +x.toExponential(3) // '4.560e+1'
1557 +y.toExponential(3) // '4.560e+1'</pre>
1558 +
1559 +
1560 +
1561 + <h5 id="toFix">
1562 + toFixed<code class='inset'>.toFixed([dp [, rm]]) <i>&rArr; string</i></code>
1563 + </h5>
1564 + <p>
1565 + <code>dp</code>: <i>number</i>: integer, <code>0</code> to <code>1e+9</code> inclusive<br />
1566 + <code>rm</code>: <i>number</i>: integer, <code>0</code> to <code>8</code> inclusive
1567 + </p>
1568 + <p>
1569 + Returns a string representing the value of this BigNumber in normal (fixed-point) notation
1570 + rounded to <code>dp</code> decimal places using rounding mode <code>rm</code>.
1571 + </p>
1572 + <p>
1573 + If the value of this BigNumber in normal notation has fewer than <code>dp</code> fraction
1574 + digits, the return value will be appended with zeros accordingly.
1575 + </p>
1576 + <p>
1577 + Unlike <code>Number.prototype.toFixed</code>, which returns exponential notation if a number
1578 + is greater or equal to <code>10<sup>21</sup></code>, this method will always return normal
1579 + notation.
1580 + </p>
1581 + <p>
1582 + If <code>dp</code> is omitted or is <code>null</code> or <code>undefined</code>, the return
1583 + value will be unrounded and in normal notation. This is also unlike
1584 + <code>Number.prototype.toFixed</code>, which returns the value to zero decimal places.<br />
1585 + It is useful when fixed-point notation is required and the current
1586 + <a href="#exponential-at"><code>EXPONENTIAL_AT</code></a> setting causes
1587 + <code><a href='#toS'>toString</a></code> to return exponential notation.<br />
1588 + If <code>rm</code> is omitted or is <code>null</code> or <code>undefined</code>,
1589 + <a href='#rounding-mode'><code>ROUNDING_MODE</code></a> is used.
1590 + </p>
1591 + <p>
1592 + Throws if <code>dp</code> or <code>rm</code> is invalid. See <a href='#Errors'>Errors</a>.
1593 + </p>
1594 + <pre>
1595 +x = 3.456
1596 +y = new BigNumber(x)
1597 +x.toFixed() // '3'
1598 +y.toFixed() // '3.456'
1599 +y.toFixed(0) // '3'
1600 +x.toFixed(2) // '3.46'
1601 +y.toFixed(2) // '3.46'
1602 +y.toFixed(2, 1) // '3.45' (ROUND_DOWN)
1603 +x.toFixed(5) // '3.45600'
1604 +y.toFixed(5) // '3.45600'</pre>
1605 +
1606 +
1607 +
1608 + <h5 id="toFor">
1609 + toFormat<code class='inset'>.toFormat([dp [, rm[, format]]]) <i>&rArr; string</i></code>
1610 + </h5>
1611 + <p>
1612 + <code>dp</code>: <i>number</i>: integer, <code>0</code> to <code>1e+9</code> inclusive<br />
1613 + <code>rm</code>: <i>number</i>: integer, <code>0</code> to <code>8</code> inclusive<br />
1614 + <code>format</code>: <i>object</i>: see <a href='#format'><code>FORMAT</code></a>
1615 + </p>
1616 + <p>
1617 + <p>
1618 + Returns a string representing the value of this BigNumber in normal (fixed-point) notation
1619 + rounded to <code>dp</code> decimal places using rounding mode <code>rm</code>, and formatted
1620 + according to the properties of the <code>format</code> object.
1621 + </p>
1622 + <p>
1623 + See <a href='#format'><code>FORMAT</code></a> and the examples below for the properties of the
1624 + <code>format</code> object, their types, and their usage. A formatting object may contain
1625 + some or all of the recognised properties.
1626 + </p>
1627 + <p>
1628 + If <code>dp</code> is omitted or is <code>null</code> or <code>undefined</code>, then the
1629 + return value is not rounded to a fixed number of decimal places.<br />
1630 + If <code>rm</code> is omitted or is <code>null</code> or <code>undefined</code>,
1631 + <a href='#rounding-mode'><code>ROUNDING_MODE</code></a> is used.<br />
1632 + If <code>format</code> is omitted or is <code>null</code> or <code>undefined</code>, the
1633 + <a href='#format'><code>FORMAT</code></a> object is used.
1634 + </p>
1635 + <p>
1636 + Throws if <code>dp</code>, <code>rm</code> or <code>format</code> is invalid. See
1637 + <a href='#Errors'>Errors</a>.
1638 + </p>
1639 + <pre>
1640 +fmt = {
1641 + prefix = '',
1642 + decimalSeparator: '.',
1643 + groupSeparator: ',',
1644 + groupSize: 3,
1645 + secondaryGroupSize: 0,
1646 + fractionGroupSeparator: ' ',
1647 + fractionGroupSize: 0,
1648 + suffix = ''
1649 +}
1650 +
1651 +x = new BigNumber('123456789.123456789')
1652 +
1653 +// Set the global formatting options
1654 +BigNumber.config({ FORMAT: fmt })
1655 +
1656 +x.toFormat() // '123,456,789.123456789'
1657 +x.toFormat(3) // '123,456,789.123'
1658 +
1659 +// If a reference to the object assigned to FORMAT has been retained,
1660 +// the format properties can be changed directly
1661 +fmt.groupSeparator = ' '
1662 +fmt.fractionGroupSize = 5
1663 +x.toFormat() // '123 456 789.12345 6789'
1664 +
1665 +// Alternatively, pass the formatting options as an argument
1666 +fmt = {
1667 + prefix: '=> ',
1668 + decimalSeparator: ',',
1669 + groupSeparator: '.',
1670 + groupSize: 3,
1671 + secondaryGroupSize: 2
1672 +}
1673 +
1674 +x.toFormat() // '123 456 789.12345 6789'
1675 +x.toFormat(fmt) // '=> 12.34.56.789,123456789'
1676 +x.toFormat(2, fmt) // '=> 12.34.56.789,12'
1677 +x.toFormat(3, BigNumber.ROUND_UP, fmt) // '=> 12.34.56.789,124'</pre>
1678 +
1679 +
1680 +
1681 + <h5 id="toFr">
1682 + toFraction<code class='inset'>.toFraction([maximum_denominator])
1683 + <i>&rArr; [BigNumber, BigNumber]</i></code>
1684 + </h5>
1685 + <p>
1686 + <code>maximum_denominator</code>:
1687 + <i>number|string|BigNumber</i>: integer &gt;= <code>1</code> and &lt;=
1688 + <code>Infinity</code>
1689 + </p>
1690 + <p>
1691 + Returns an array of two BigNumbers representing the value of this BigNumber as a simple
1692 + fraction with an integer numerator and an integer denominator. The denominator will be a
1693 + positive non-zero value less than or equal to <code>maximum_denominator</code>.
1694 + </p>
1695 + <p>
1696 + If a <code>maximum_denominator</code> is not specified, or is <code>null</code> or
1697 + <code>undefined</code>, the denominator will be the lowest value necessary to represent the
1698 + number exactly.
1699 + </p>
1700 + <p>
1701 + Throws if <code>maximum_denominator</code> is invalid. See <a href='#Errors'>Errors</a>.
1702 + </p>
1703 + <pre>
1704 +x = new BigNumber(1.75)
1705 +x.toFraction() // '7, 4'
1706 +
1707 +pi = new BigNumber('3.14159265358')
1708 +pi.toFraction() // '157079632679,50000000000'
1709 +pi.toFraction(100000) // '312689, 99532'
1710 +pi.toFraction(10000) // '355, 113'
1711 +pi.toFraction(100) // '311, 99'
1712 +pi.toFraction(10) // '22, 7'
1713 +pi.toFraction(1) // '3, 1'</pre>
1714 +
1715 +
1716 +
1717 + <h5 id="toJSON">toJSON<code class='inset'>.toJSON() <i>&rArr; string</i></code></h5>
1718 + <p>As <a href='#valueOf'><code>valueOf</code></a>.</p>
1719 + <pre>
1720 +x = new BigNumber('177.7e+457')
1721 +y = new BigNumber(235.4325)
1722 +z = new BigNumber('0.0098074')
1723 +
1724 +// Serialize an array of three BigNumbers
1725 +str = JSON.stringify( [x, y, z] )
1726 +// "["1.777e+459","235.4325","0.0098074"]"
1727 +
1728 +// Return an array of three BigNumbers
1729 +JSON.parse(str, function (key, val) {
1730 + return key === '' ? val : new BigNumber(val)
1731 +})</pre>
1732 +
1733 +
1734 +
1735 + <h5 id="toN">toNumber<code class='inset'>.toNumber() <i>&rArr; number</i></code></h5>
1736 + <p>Returns the value of this BigNumber as a JavaScript number primitive.</p>
1737 + <p>
1738 + This method is identical to using type coercion with the unary plus operator.
1739 + </p>
1740 + <pre>
1741 +x = new BigNumber(456.789)
1742 +x.toNumber() // 456.789
1743 ++x // 456.789
1744 +
1745 +y = new BigNumber('45987349857634085409857349856430985')
1746 +y.toNumber() // 4.598734985763409e+34
1747 +
1748 +z = new BigNumber(-0)
1749 +1 / z.toNumber() // -Infinity
1750 +1 / +z // -Infinity</pre>
1751 +
1752 +
1753 +
1754 + <h5 id="toP">
1755 + toPrecision<code class='inset'>.toPrecision([sd [, rm]]) <i>&rArr; string</i></code>
1756 + </h5>
1757 + <p>
1758 + <code>sd</code>: <i>number</i>: integer, <code>1</code> to <code>1e+9</code> inclusive<br />
1759 + <code>rm</code>: <i>number</i>: integer, <code>0</code> to <code>8</code> inclusive
1760 + </p>
1761 + <p>
1762 + Returns a string representing the value of this BigNumber rounded to <code>sd</code>
1763 + significant digits using rounding mode <code>rm</code>.
1764 + </p>
1765 + <p>
1766 + If <code>sd</code> is less than the number of digits necessary to represent the integer part
1767 + of the value in normal (fixed-point) notation, then exponential notation is used.
1768 + </p>
1769 + <p>
1770 + If <code>sd</code> is omitted, or is <code>null</code> or <code>undefined</code>, then the
1771 + return value is the same as <code>n.toString()</code>.<br />
1772 + If <code>rm</code> is omitted or is <code>null</code> or <code>undefined</code>,
1773 + <a href='#rounding-mode'><code>ROUNDING_MODE</code></a> is used.
1774 + </p>
1775 + <p>
1776 + Throws if <code>sd</code> or <code>rm</code> is invalid. See <a href='#Errors'>Errors</a>.
1777 + </p>
1778 + <pre>
1779 +x = 45.6
1780 +y = new BigNumber(x)
1781 +x.toPrecision() // '45.6'
1782 +y.toPrecision() // '45.6'
1783 +x.toPrecision(1) // '5e+1'
1784 +y.toPrecision(1) // '5e+1'
1785 +y.toPrecision(2, 0) // '4.6e+1' (ROUND_UP)
1786 +y.toPrecision(2, 1) // '4.5e+1' (ROUND_DOWN)
1787 +x.toPrecision(5) // '45.600'
1788 +y.toPrecision(5) // '45.600'</pre>
1789 +
1790 +
1791 +
1792 + <h5 id="toS">toString<code class='inset'>.toString([base]) <i>&rArr; string</i></code></h5>
1793 + <p>
1794 + <code>base</code>: <i>number</i>: integer, <code>2</code> to <code>ALPHABET.length</code>
1795 + inclusive (see <a href='#alphabet'><code>ALPHABET</code></a>).
1796 + </p>
1797 + <p>
1798 + Returns a string representing the value of this BigNumber in the specified base, or base
1799 + <code>10</code> if <code>base</code> is omitted or is <code>null</code> or
1800 + <code>undefined</code>.
1801 + </p>
1802 + <p>
1803 + For bases above <code>10</code>, and using the default base conversion alphabet
1804 + (see <a href='#alphabet'><code>ALPHABET</code></a>), values from <code>10</code> to
1805 + <code>35</code> are represented by <code>a-z</code>
1806 + (as with <code>Number.prototype.toString</code>).
1807 + </p>
1808 + <p>
1809 + If a base is specified the value is rounded according to the current
1810 + <a href='#decimal-places'><code>DECIMAL_PLACES</code></a>
1811 + and <a href='#rounding-mode'><code>ROUNDING_MODE</code></a> settings.
1812 + </p>
1813 + <p>
1814 + If a base is not specified, and this BigNumber has a positive
1815 + exponent that is equal to or greater than the positive component of the
1816 + current <a href="#exponential-at"><code>EXPONENTIAL_AT</code></a> setting,
1817 + or a negative exponent equal to or less than the negative component of the
1818 + setting, then exponential notation is returned.
1819 + </p>
1820 + <p>If <code>base</code> is <code>null</code> or <code>undefined</code> it is ignored.</p>
1821 + <p>
1822 + Throws if <code>base</code> is invalid. See <a href='#Errors'>Errors</a>.
1823 + </p>
1824 + <pre>
1825 +x = new BigNumber(750000)
1826 +x.toString() // '750000'
1827 +BigNumber.config({ EXPONENTIAL_AT: 5 })
1828 +x.toString() // '7.5e+5'
1829 +
1830 +y = new BigNumber(362.875)
1831 +y.toString(2) // '101101010.111'
1832 +y.toString(9) // '442.77777777777777777778'
1833 +y.toString(32) // 'ba.s'
1834 +
1835 +BigNumber.config({ DECIMAL_PLACES: 4 });
1836 +z = new BigNumber('1.23456789')
1837 +z.toString() // '1.23456789'
1838 +z.toString(10) // '1.2346'</pre>
1839 +
1840 +
1841 +
1842 + <h5 id="valueOf">valueOf<code class='inset'>.valueOf() <i>&rArr; string</i></code></h5>
1843 + <p>
1844 + As <a href='#toS'><code>toString</code></a>, but does not accept a base argument and includes
1845 + the minus sign for negative zero.
1846 + </p>
1847 + <pre>
1848 +x = new BigNumber('-0')
1849 +x.toString() // '0'
1850 +x.valueOf() // '-0'
1851 +y = new BigNumber('1.777e+457')
1852 +y.valueOf() // '1.777e+457'</pre>
1853 +
1854 +
1855 +
1856 + <h4 id="instance-properties">Properties</h4>
1857 + <p>The properties of a BigNumber instance:</p>
1858 + <table>
1859 + <tr>
1860 + <th>Property</th>
1861 + <th>Description</th>
1862 + <th>Type</th>
1863 + <th>Value</th>
1864 + </tr>
1865 + <tr>
1866 + <td class='centre' id='coefficient'><b>c</b></td>
1867 + <td>coefficient<sup>*</sup></td>
1868 + <td><i>number</i><code>[]</code></td>
1869 + <td> Array of base <code>1e14</code> numbers</td>
1870 + </tr>
1871 + <tr>
1872 + <td class='centre' id='exponent'><b>e</b></td>
1873 + <td>exponent</td>
1874 + <td><i>number</i></td>
1875 + <td>Integer, <code>-1000000000</code> to <code>1000000000</code> inclusive</td>
1876 + </tr>
1877 + <tr>
1878 + <td class='centre' id='sign'><b>s</b></td>
1879 + <td>sign</td>
1880 + <td><i>number</i></td>
1881 + <td><code>-1</code> or <code>1</code></td>
1882 + </tr>
1883 + </table>
1884 + <p><sup>*</sup>significand</p>
1885 + <p>
1886 + The value of any of the <code>c</code>, <code>e</code> and <code>s</code> properties may also
1887 + be <code>null</code>.
1888 + </p>
1889 + <p>
1890 + The above properties are best considered to be read-only. In early versions of this library it
1891 + was okay to change the exponent of a BigNumber by writing to its exponent property directly,
1892 + but this is no longer reliable as the value of the first element of the coefficient array is
1893 + now dependent on the exponent.
1894 + </p>
1895 + <p>
1896 + Note that, as with JavaScript numbers, the original exponent and fractional trailing zeros are
1897 + not necessarily preserved.
1898 + </p>
1899 + <pre>x = new BigNumber(0.123) // '0.123'
1900 +x.toExponential() // '1.23e-1'
1901 +x.c // '1,2,3'
1902 +x.e // -1
1903 +x.s // 1
1904 +
1905 +y = new Number(-123.4567000e+2) // '-12345.67'
1906 +y.toExponential() // '-1.234567e+4'
1907 +z = new BigNumber('-123.4567000e+2') // '-12345.67'
1908 +z.toExponential() // '-1.234567e+4'
1909 +z.c // '1,2,3,4,5,6,7'
1910 +z.e // 4
1911 +z.s // -1</pre>
1912 +
1913 +
1914 +
1915 + <h4 id="zero-nan-infinity">Zero, NaN and Infinity</h4>
1916 + <p>
1917 + The table below shows how &plusmn;<code>0</code>, <code>NaN</code> and
1918 + &plusmn;<code>Infinity</code> are stored.
1919 + </p>
1920 + <table>
1921 + <tr>
1922 + <th> </th>
1923 + <th class='centre'>c</th>
1924 + <th class='centre'>e</th>
1925 + <th class='centre'>s</th>
1926 + </tr>
1927 + <tr>
1928 + <td>&plusmn;0</td>
1929 + <td><code>[0]</code></td>
1930 + <td><code>0</code></td>
1931 + <td><code>&plusmn;1</code></td>
1932 + </tr>
1933 + <tr>
1934 + <td>NaN</td>
1935 + <td><code>null</code></td>
1936 + <td><code>null</code></td>
1937 + <td><code>null</code></td>
1938 + </tr>
1939 + <tr>
1940 + <td>&plusmn;Infinity</td>
1941 + <td><code>null</code></td>
1942 + <td><code>null</code></td>
1943 + <td><code>&plusmn;1</code></td>
1944 + </tr>
1945 + </table>
1946 + <pre>
1947 +x = new Number(-0) // 0
1948 +1 / x == -Infinity // true
1949 +
1950 +y = new BigNumber(-0) // '0'
1951 +y.c // '0' ( [0].toString() )
1952 +y.e // 0
1953 +y.s // -1</pre>
1954 +
1955 +
1956 +
1957 + <h4 id='Errors'>Errors</h4>
1958 + <p>The table below shows the errors that are thrown.</p>
1959 + <p>
1960 + The errors are generic <code>Error</code> objects whose message begins
1961 + <code>'[BigNumber Error]'</code>.
1962 + </p>
1963 + <table class='error-table'>
1964 + <tr>
1965 + <th>Method</th>
1966 + <th>Throws</th>
1967 + </tr>
1968 + <tr>
1969 + <td rowspan=6>
1970 + <code>BigNumber</code><br />
1971 + <code>comparedTo</code><br />
1972 + <code>dividedBy</code><br />
1973 + <code>dividedToIntegerBy</code><br />
1974 + <code>isEqualTo</code><br />
1975 + <code>isGreaterThan</code><br />
1976 + <code>isGreaterThanOrEqualTo</code><br />
1977 + <code>isLessThan</code><br />
1978 + <code>isLessThanOrEqualTo</code><br />
1979 + <code>minus</code><br />
1980 + <code>modulo</code><br />
1981 + <code>plus</code><br />
1982 + <code>multipliedBy</code>
1983 + </td>
1984 + <td>Base not a primitive number</td>
1985 + </tr>
1986 + <tr>
1987 + <td>Base not an integer</td>
1988 + </tr>
1989 + <tr>
1990 + <td>Base out of range</td>
1991 + </tr>
1992 + <tr>
1993 + <td>Number primitive has more than 15 significant digits<sup>*</sup></td>
1994 + </tr>
1995 + <tr>
1996 + <td>Not a base... number<sup>*</sup></td>
1997 + </tr>
1998 + <tr>
1999 + <td>Not a number<sup>*</sup></td>
2000 + </tr>
2001 + <tr>
2002 + <td><code>clone</code></td>
2003 + <td>Object expected</td>
2004 + </tr>
2005 + <tr>
2006 + <td rowspan=24><code>config</code></td>
2007 + <td>Object expected</td>
2008 + </tr>
2009 + <tr>
2010 + <td><code>DECIMAL_PLACES</code> not a primitive number</td>
2011 + </tr>
2012 + <tr>
2013 + <td><code>DECIMAL_PLACES</code> not an integer</td>
2014 + </tr>
2015 + <tr>
2016 + <td><code>DECIMAL_PLACES</code> out of range</td>
2017 + </tr>
2018 + <tr>
2019 + <td><code>ROUNDING_MODE</code> not a primitive number</td>
2020 + </tr>
2021 + <tr>
2022 + <td><code>ROUNDING_MODE</code> not an integer</td>
2023 + </tr>
2024 + <tr>
2025 + <td><code>ROUNDING_MODE</code> out of range</td>
2026 + </tr>
2027 + <tr>
2028 + <td><code>EXPONENTIAL_AT</code> not a primitive number</td>
2029 + </tr>
2030 + <tr>
2031 + <td><code>EXPONENTIAL_AT</code> not an integer</td>
2032 + </tr>
2033 + <tr>
2034 + <td><code>EXPONENTIAL_AT</code> out of range</td>
2035 + </tr>
2036 + <tr>
2037 + <td><code>RANGE</code> not a primitive number</td>
2038 + </tr>
2039 + <tr>
2040 + <td><code>RANGE</code> not an integer</td>
2041 + </tr>
2042 + <tr>
2043 + <td><code>RANGE</code> cannot be zero</td>
2044 + </tr>
2045 + <tr>
2046 + <td><code>RANGE</code> cannot be zero</td>
2047 + </tr>
2048 + <tr>
2049 + <td><code>CRYPTO</code> not true or false</td>
2050 + </tr>
2051 + <tr>
2052 + <td><code>crypto</code> unavailable</td>
2053 + </tr>
2054 + <tr>
2055 + <td><code>MODULO_MODE</code> not a primitive number</td>
2056 + </tr>
2057 + <tr>
2058 + <td><code>MODULO_MODE</code> not an integer</td>
2059 + </tr>
2060 + <tr>
2061 + <td><code>MODULO_MODE</code> out of range</td>
2062 + </tr>
2063 + <tr>
2064 + <td><code>POW_PRECISION</code> not a primitive number</td>
2065 + </tr>
2066 + <tr>
2067 + <td><code>POW_PRECISION</code> not an integer</td>
2068 + </tr>
2069 + <tr>
2070 + <td><code>POW_PRECISION</code> out of range</td>
2071 + </tr>
2072 + <tr>
2073 + <td><code>FORMAT</code> not an object</td>
2074 + </tr>
2075 + <tr>
2076 + <td><code>ALPHABET</code> invalid</td>
2077 + </tr>
2078 + <tr>
2079 + <td rowspan=3>
2080 + <code>decimalPlaces</code><br />
2081 + <code>precision</code><br />
2082 + <code>random</code><br />
2083 + <code>shiftedBy</code><br />
2084 + <code>toExponential</code><br />
2085 + <code>toFixed</code><br />
2086 + <code>toFormat</code><br />
2087 + <code>toPrecision</code>
2088 + </td>
2089 + <td>Argument not a primitive number</td>
2090 + </tr>
2091 + <tr>
2092 + <td>Argument not an integer</td>
2093 + </tr>
2094 + <tr>
2095 + <td>Argument out of range</td>
2096 + </tr>
2097 + <tr>
2098 + <td>
2099 + <code>decimalPlaces</code><br />
2100 + <code>precision</code>
2101 + </td>
2102 + <td>Argument not true or false</td>
2103 + </tr>
2104 + <tr>
2105 + <td><code>exponentiatedBy</code></td>
2106 + <td>Argument not an integer</td>
2107 + </tr>
2108 + <tr>
2109 + <td><code>isBigNumber</code></td>
2110 + <td>Invalid BigNumber<sup>*</sup></td>
2111 + </tr>
2112 + <tr>
2113 + <td>
2114 + <code>minimum</code><br />
2115 + <code>maximum</code>
2116 + </td>
2117 + <td>Not a number<sup>*</sup></td>
2118 + </tr>
2119 + <tr>
2120 + <td>
2121 + <code>random</code>
2122 + </td>
2123 + <td>crypto unavailable</td>
2124 + </tr>
2125 + <tr>
2126 + <td>
2127 + <code>toFormat</code>
2128 + </td>
2129 + <td>Argument not an object</td>
2130 + </tr>
2131 + <tr>
2132 + <td rowspan=2><code>toFraction</code></td>
2133 + <td>Argument not an integer</td>
2134 + </tr>
2135 + <tr>
2136 + <td>Argument out of range</td>
2137 + </tr>
2138 + <tr>
2139 + <td rowspan=3><code>toString</code></td>
2140 + <td>Base not a primitive number</td>
2141 + </tr>
2142 + <tr>
2143 + <td>Base not an integer</td>
2144 + </tr>
2145 + <tr>
2146 + <td>Base out of range</td>
2147 + </tr>
2148 + </table>
2149 + <p><sup>*</sup>Only thrown if <code>BigNumber.DEBUG</code> is <code>true</code>.</p>
2150 + <p>To determine if an exception is a BigNumber Error:</p>
2151 + <pre>
2152 +try {
2153 + // ...
2154 +} catch (e) {
2155 + if (e instanceof Error && e.message.indexOf('[BigNumber Error]') === 0) {
2156 + // ...
2157 + }
2158 +}</pre>
2159 +
2160 +
2161 +
2162 + <h4 id="type-coercion">Type coercion</h4>
2163 + <p>
2164 + To prevent the accidental use of a BigNumber in primitive number operations, or the
2165 + accidental addition of a BigNumber to a string, the <code>valueOf</code> method can be safely
2166 + overwritten as shown below.
2167 + </p>
2168 + <p>
2169 + The <a href='#valueOf'><code>valueOf</code></a> method is the same as the
2170 + <a href='#toJSON'><code>toJSON</code></a> method, and both are the same as the
2171 + <a href='#toS'><code>toString</code></a> method except they do not take a <code>base</code>
2172 + argument and they include the minus sign for negative zero.
2173 + </p>
2174 + <pre>
2175 +BigNumber.prototype.valueOf = function () {
2176 + throw Error('valueOf called!')
2177 +}
2178 +
2179 +x = new BigNumber(1)
2180 +x / 2 // '[BigNumber Error] valueOf called!'
2181 +x + 'abc' // '[BigNumber Error] valueOf called!'
2182 +</pre>
2183 +
2184 +
2185 +
2186 + <h4 id='faq'>FAQ</h4>
2187 +
2188 + <h6>Why are trailing fractional zeros removed from BigNumbers?</h6>
2189 + <p>
2190 + Some arbitrary-precision libraries retain trailing fractional zeros as they can indicate the
2191 + precision of a value. This can be useful but the results of arithmetic operations can be
2192 + misleading.
2193 + </p>
2194 + <pre>
2195 +x = new BigDecimal("1.0")
2196 +y = new BigDecimal("1.1000")
2197 +z = x.add(y) // 2.1000
2198 +
2199 +x = new BigDecimal("1.20")
2200 +y = new BigDecimal("3.45000")
2201 +z = x.multiply(y) // 4.1400000</pre>
2202 + <p>
2203 + To specify the precision of a value is to specify that the value lies
2204 + within a certain range.
2205 + </p>
2206 + <p>
2207 + In the first example, <code>x</code> has a value of <code>1.0</code>. The trailing zero shows
2208 + the precision of the value, implying that it is in the range <code>0.95</code> to
2209 + <code>1.05</code>. Similarly, the precision indicated by the trailing zeros of <code>y</code>
2210 + indicates that the value is in the range <code>1.09995</code> to <code>1.10005</code>.
2211 + </p>
2212 + <p>
2213 + If we add the two lowest values in the ranges we have, <code>0.95 + 1.09995 = 2.04995</code>,
2214 + and if we add the two highest values we have, <code>1.05 + 1.10005 = 2.15005</code>, so the
2215 + range of the result of the addition implied by the precision of its operands is
2216 + <code>2.04995</code> to <code>2.15005</code>.
2217 + </p>
2218 + <p>
2219 + The result given by BigDecimal of <code>2.1000</code> however, indicates that the value is in
2220 + the range <code>2.09995</code> to <code>2.10005</code> and therefore the precision implied by
2221 + its trailing zeros may be misleading.
2222 + </p>
2223 + <p>
2224 + In the second example, the true range is <code>4.122744</code> to <code>4.157256</code> yet
2225 + the BigDecimal answer of <code>4.1400000</code> indicates a range of <code>4.13999995</code>
2226 + to <code>4.14000005</code>. Again, the precision implied by the trailing zeros may be
2227 + misleading.
2228 + </p>
2229 + <p>
2230 + This library, like binary floating point and most calculators, does not retain trailing
2231 + fractional zeros. Instead, the <code>toExponential</code>, <code>toFixed</code> and
2232 + <code>toPrecision</code> methods enable trailing zeros to be added if and when required.<br />
2233 + </p>
2234 + </div>
2235 +
2236 +</body>
2237 +</html>
1 +{
2 + "_from": "bignumber.js@9.0.0",
3 + "_id": "bignumber.js@9.0.0",
4 + "_inBundle": false,
5 + "_integrity": "sha512-t/OYhhJ2SD+YGBQcjY8GzzDHEk9f3nerxjtfa6tlMXfe7frs/WozhvCNoGvpM0P3bNf3Gq5ZRMlGr5f3r4/N8A==",
6 + "_location": "/bignumber.js",
7 + "_phantomChildren": {},
8 + "_requested": {
9 + "type": "version",
10 + "registry": true,
11 + "raw": "bignumber.js@9.0.0",
12 + "name": "bignumber.js",
13 + "escapedName": "bignumber.js",
14 + "rawSpec": "9.0.0",
15 + "saveSpec": null,
16 + "fetchSpec": "9.0.0"
17 + },
18 + "_requiredBy": [
19 + "/mysql"
20 + ],
21 + "_resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.0.0.tgz",
22 + "_shasum": "805880f84a329b5eac6e7cb6f8274b6d82bdf075",
23 + "_spec": "bignumber.js@9.0.0",
24 + "_where": "C:\\Users\\user\\Desktop\\Singer-Composer\\node_modules\\mysql",
25 + "author": {
26 + "name": "Michael Mclaughlin",
27 + "email": "M8ch88l@gmail.com"
28 + },
29 + "browser": "bignumber.js",
30 + "bugs": {
31 + "url": "https://github.com/MikeMcl/bignumber.js/issues"
32 + },
33 + "bundleDependencies": false,
34 + "dependencies": {},
35 + "deprecated": false,
36 + "description": "A library for arbitrary-precision decimal and non-decimal arithmetic",
37 + "engines": {
38 + "node": "*"
39 + },
40 + "homepage": "https://github.com/MikeMcl/bignumber.js#readme",
41 + "keywords": [
42 + "arbitrary",
43 + "precision",
44 + "arithmetic",
45 + "big",
46 + "number",
47 + "decimal",
48 + "float",
49 + "biginteger",
50 + "bigdecimal",
51 + "bignumber",
52 + "bigint",
53 + "bignum"
54 + ],
55 + "license": "MIT",
56 + "main": "bignumber",
57 + "module": "bignumber.mjs",
58 + "name": "bignumber.js",
59 + "repository": {
60 + "type": "git",
61 + "url": "git+https://github.com/MikeMcl/bignumber.js.git"
62 + },
63 + "scripts": {
64 + "build": "uglifyjs bignumber.js --source-map -c -m -o bignumber.min.js",
65 + "test": "node test/test"
66 + },
67 + "types": "bignumber.d.ts",
68 + "version": "9.0.0"
69 +}
1 +language: node_js
2 +node_js:
3 + - "0.8"
4 + - "0.10"
1 +
2 +test:
3 + @node_modules/.bin/tape test.js
4 +
5 +.PHONY: test
6 +
1 +
2 +# isarray
3 +
4 +`Array#isArray` for older browsers.
5 +
6 +[![build status](https://secure.travis-ci.org/juliangruber/isarray.svg)](http://travis-ci.org/juliangruber/isarray)
7 +[![downloads](https://img.shields.io/npm/dm/isarray.svg)](https://www.npmjs.org/package/isarray)
8 +
9 +[![browser support](https://ci.testling.com/juliangruber/isarray.png)
10 +](https://ci.testling.com/juliangruber/isarray)
11 +
12 +## Usage
13 +
14 +```js
15 +var isArray = require('isarray');
16 +
17 +console.log(isArray([])); // => true
18 +console.log(isArray({})); // => false
19 +```
20 +
21 +## Installation
22 +
23 +With [npm](http://npmjs.org) do
24 +
25 +```bash
26 +$ npm install isarray
27 +```
28 +
29 +Then bundle for the browser with
30 +[browserify](https://github.com/substack/browserify).
31 +
32 +With [component](http://component.io) do
33 +
34 +```bash
35 +$ component install juliangruber/isarray
36 +```
37 +
38 +## License
39 +
40 +(MIT)
41 +
42 +Copyright (c) 2013 Julian Gruber &lt;julian@juliangruber.com&gt;
43 +
44 +Permission is hereby granted, free of charge, to any person obtaining a copy of
45 +this software and associated documentation files (the "Software"), to deal in
46 +the Software without restriction, including without limitation the rights to
47 +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
48 +of the Software, and to permit persons to whom the Software is furnished to do
49 +so, subject to the following conditions:
50 +
51 +The above copyright notice and this permission notice shall be included in all
52 +copies or substantial portions of the Software.
53 +
54 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
55 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
56 +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
57 +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
58 +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
59 +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
60 +SOFTWARE.
1 +{
2 + "name" : "isarray",
3 + "description" : "Array#isArray for older browsers",
4 + "version" : "0.0.1",
5 + "repository" : "juliangruber/isarray",
6 + "homepage": "https://github.com/juliangruber/isarray",
7 + "main" : "index.js",
8 + "scripts" : [
9 + "index.js"
10 + ],
11 + "dependencies" : {},
12 + "keywords": ["browser","isarray","array"],
13 + "author": {
14 + "name": "Julian Gruber",
15 + "email": "mail@juliangruber.com",
16 + "url": "http://juliangruber.com"
17 + },
18 + "license": "MIT"
19 +}
1 +var toString = {}.toString;
2 +
3 +module.exports = Array.isArray || function (arr) {
4 + return toString.call(arr) == '[object Array]';
5 +};
1 +{
2 + "_from": "isarray@~1.0.0",
3 + "_id": "isarray@1.0.0",
4 + "_inBundle": false,
5 + "_integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=",
6 + "_location": "/isarray",
7 + "_phantomChildren": {},
8 + "_requested": {
9 + "type": "range",
10 + "registry": true,
11 + "raw": "isarray@~1.0.0",
12 + "name": "isarray",
13 + "escapedName": "isarray",
14 + "rawSpec": "~1.0.0",
15 + "saveSpec": null,
16 + "fetchSpec": "~1.0.0"
17 + },
18 + "_requiredBy": [
19 + "/readable-stream"
20 + ],
21 + "_resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
22 + "_shasum": "bb935d48582cba168c06834957a54a3e07124f11",
23 + "_spec": "isarray@~1.0.0",
24 + "_where": "C:\\Users\\user\\Desktop\\Singer-Composer\\node_modules\\readable-stream",
25 + "author": {
26 + "name": "Julian Gruber",
27 + "email": "mail@juliangruber.com",
28 + "url": "http://juliangruber.com"
29 + },
30 + "bugs": {
31 + "url": "https://github.com/juliangruber/isarray/issues"
32 + },
33 + "bundleDependencies": false,
34 + "dependencies": {},
35 + "deprecated": false,
36 + "description": "Array#isArray for older browsers",
37 + "devDependencies": {
38 + "tape": "~2.13.4"
39 + },
40 + "homepage": "https://github.com/juliangruber/isarray",
41 + "keywords": [
42 + "browser",
43 + "isarray",
44 + "array"
45 + ],
46 + "license": "MIT",
47 + "main": "index.js",
48 + "name": "isarray",
49 + "repository": {
50 + "type": "git",
51 + "url": "git://github.com/juliangruber/isarray.git"
52 + },
53 + "scripts": {
54 + "test": "tape test.js"
55 + },
56 + "testling": {
57 + "files": "test.js",
58 + "browsers": [
59 + "ie/8..latest",
60 + "firefox/17..latest",
61 + "firefox/nightly",
62 + "chrome/22..latest",
63 + "chrome/canary",
64 + "opera/12..latest",
65 + "opera/next",
66 + "safari/5.1..latest",
67 + "ipad/6.0..latest",
68 + "iphone/6.0..latest",
69 + "android-browser/4.2..latest"
70 + ]
71 + },
72 + "version": "1.0.0"
73 +}
1 +var isArray = require('./');
2 +var test = require('tape');
3 +
4 +test('is array', function(t){
5 + t.ok(isArray([]));
6 + t.notOk(isArray({}));
7 + t.notOk(isArray(null));
8 + t.notOk(isArray(false));
9 +
10 + var obj = {};
11 + obj[0] = true;
12 + t.notOk(isArray(obj));
13 +
14 + var arr = [];
15 + arr.foo = 'bar';
16 + t.ok(isArray(arr));
17 +
18 + t.end();
19 +});
20 +
1 +language: node_js
2 +sudo: false
3 +script: npm run coverage
4 +node_js:
5 +- '6'
6 +- '7'
7 +cache:
8 + directories:
9 + - node_modules
1 +## [v2.0.0]
2 +> Jun 5, 2018
3 +
4 +See [Upgrading to v2.0.0](https://github.com/rstacruz/mocha-jsdom#upgrading-to-v200) for notes on how to update from an older version.
5 +
6 +* [#32] - `jsdom` is now a direct dependency of `mocha-jsdom` :tada:
7 +
8 +[#32]: https://github.com/rstacruz/mocha-jsdom/issues/32
9 +[v2.0.0]: https://github.com/rstacruz/mocha-jsdom/compare/v1.2.0...v2.0.0
10 +
11 +## [v1.2.0]
12 +> Jun 5, 2018
13 +
14 +* [#29] - Update Jsdom compatibility ([@RobLoach])
15 +* [#31] - Update all npm dependencies
16 +
17 +[#29]: https://github.com/rstacruz/mocha-jsdom/issues/29
18 +[#31]: https://github.com/rstacruz/mocha-jsdom/issues/31
19 +[@RobLoach]: https://github.com/robloach
20 +[v1.2.0]: https://github.com/rstacruz/mocha-jsdom/compare/v1.1.0...v1.2.0
21 +
22 +## [v1.1.0]
23 +> Feb 22, 2016
24 +
25 +* [#18] - Initialize global.window when it is undefined; fixes compatibility with [airbnb/enzyme][]. ([@moonboots])
26 +
27 +[v1.1.0]: https://github.com/rstacruz/mocha-jsdom/compare/v1.0.0...v1.1.0
28 +
29 +## [v1.0.0] - Jul 4, 2015
30 +
31 +* Add testling/browserify support.
32 +* Add more examples.
33 +
34 +[v1.0.0]: https://github.com/rstacruz/mocha-jsdom/compare/v0.5.0...v1.0.0
35 +
36 +## [v0.5.0] - Jun 26, 2015
37 +
38 +* Add `rerequire()` to help with using mocha-jsdom with `mocha --watch`.
39 +* Internal: change coding standard to feross/standard.
40 +
41 +## [v0.4.0] - May 25, 2015
42 +
43 +* [#5] - Add `useEach` option. ([@jasco], [#6])
44 +* [#7] - Add a `skipWindowCheck` option.
45 +
46 +## [v0.3.0] - Apr 3, 2015
47 +
48 +* [#3] - Bump `jsdom` dependency version. This fixes the "needs a context" error ([@nacyot], [#3])
49 +
50 +[#3]: https://github.com/rstacruz/mocha-jsdom/issues/3
51 +[#4]: https://github.com/rstacruz/mocha-jsdom/issues/4
52 +[@nacyot]: https://github.com/nacyot
53 +
54 +## [v0.2.1] - Feb 19, 2014
55 +
56 +* Add `LICENSE` file
57 +* Update documentation
58 +* No functionality changes
59 +
60 +## [v0.2.0] - November 5, 2014
61 +
62 +* Skip warnings. Add `JSDOM_VERBOSE=1` to your env to reenable them.
63 +
64 +## [v0.1.2] - September 27, 2014
65 +
66 +* Throw a useful error when invoked twice.
67 +
68 +## [v0.1.1] - September 27, 2014
69 +
70 +* Re-release with updated Readme.
71 +
72 +[airbnb/enzyme]: https://github.com/airbnb/enzyme
73 +
74 +## v0.1.0 - September 25, 2014
75 +
76 +* Initial version.
77 +
78 +[#5]: https://github.com/rstacruz/mocha-jsdom/issues/5
79 +[#6]: https://github.com/rstacruz/mocha-jsdom/issues/6
80 +[#7]: https://github.com/rstacruz/mocha-jsdom/issues/7
81 +[@jasco]: https://github.com/jasco
82 +[v0.5.0]: https://github.com/rstacruz/mocha-jsdom/compare/v0.4.0...v0.5.0
83 +[v0.4.0]: https://github.com/rstacruz/mocha-jsdom/compare/v0.3.0...v0.4.0
84 +[v0.3.0]: https://github.com/rstacruz/mocha-jsdom/compare/v0.2.1...v0.3.0
85 +[v0.2.1]: https://github.com/rstacruz/mocha-jsdom/compare/v0.2.0...v0.2.1
86 +[v0.2.0]: https://github.com/rstacruz/mocha-jsdom/compare/v0.1.2...v0.2.0
87 +[v0.1.2]: https://github.com/rstacruz/mocha-jsdom/compare/v0.1.1...v0.1.2
88 +[v0.1.1]: https://github.com/rstacruz/mocha-jsdom/compare/v0.1.0...v0.1.1
89 +[#18]: https://github.com/rstacruz/mocha-jsdom/issues/18
90 +[@moonboots]: https://github.com/moonboots
1 +Copyright © 2015 Rico Sta. Cruz
2 +
3 +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4 +
5 +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6 +
7 +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1 +> _Deprecation notice:_
2 +> Consider [jsdom-global](https://github.com/rstacruz/jsdom-global) instead, a simpler alternative that also works outside of Mocha. `mocha-jsdom` still works, but `jsdom-global` is better supported.
3 +
4 +---
5 +
6 +# mocha-jsdom
7 +
8 +> Test frontend libraries in the console using Node.js, [mocha] and [jsdom].
9 +
10 +[![Status](https://travis-ci.org/rstacruz/mocha-jsdom.svg?branch=master)](https://travis-ci.org/rstacruz/mocha-jsdom "See test builds")
11 +
12 +<br>
13 +
14 +## Usage
15 +
16 +```sh
17 +$ npm i --save-dev mocha-jsdom
18 +```
19 +
20 +[![npm version](http://img.shields.io/npm/v/mocha-jsdom.svg?style=flat)](https://npmjs.org/package/mocha-jsdom "View this project on npm")
21 +
22 +Use `jsdom()` inside your `describe(...)` block (or the global context). It will
23 +turn your Node.js environment into a mock browser environment supporting the
24 +full DOM and browser API. The variables `window`, `document`, `history` (and so
25 +on) will then be available for use.
26 +
27 +```js
28 +var jsdom = require('mocha-jsdom')
29 +var expect = require('chai').expect
30 +
31 +describe('mocha tests', function () {
32 +
33 + jsdom()
34 +
35 + it('has document', function () {
36 + var div = document.createElement('div')
37 + expect(div.nodeName).eql('DIV')
38 + })
39 +
40 +})
41 +```
42 +
43 +See [examples/basic](examples/basic) for an example of a basic setup.
44 +
45 +<br>
46 +
47 +## Upgrading to v2.0.0
48 +
49 +If you are coming from mocha-jsdom v1.x, remove `jsdom` if you're not using it before upgrading. `jsdom` is now a direct dependency of `mocha-jsdom`.
50 +
51 +```bash
52 +# using Yarn
53 +yarn remove jsdom
54 +yarn upgrade mocha-jsdom
55 +```
56 +
57 +```bash
58 +# using npm
59 +npm uninstall -S -D jsdom
60 +npm upgrade mocha-jsdom
61 +```
62 +
63 +<br>
64 +
65 +## Node and io.js information
66 +
67 +As of jsdom 4.0.0, [jsdom now requires io.js](https://github.com/tmpvar/jsdom/blob/master/Changelog.md#400) and will not work with Node.js 0.12 or below.
68 +
69 +<br>
70 +
71 +## How it works
72 +
73 +mocha-jsdom is a simple glue to integrate [jsdom] to mocha.
74 +
75 +Invoking `jsdom()` will inject `before` and `after` handlers to the current
76 +mocha suite which will setup and teardown jsdom. Here's what it does:
77 +
78 +* __Window__: `global.window` will be available as the jsdom.
79 +
80 +* __Globals__: global variables like `document` and `history` are propagated,
81 + and they're cleaned up after tests run.
82 +
83 +* __Error handling__: jsdom errors are sanitized so that their stack traces are
84 +shortened.
85 +
86 +__NB:__ Before you try this library, learn about jsdom first. In fact, you may be
87 +able to integrate jsdom into your tests *without* this library; this is mostly
88 +syntactic sugar and reasonable defaults.
89 +
90 +<br>
91 +
92 +## Using with a library
93 +
94 +Perfect for testing small DOM-consuming utilities in the console. See
95 +[test/jquery.js](test/jquery.js) for an example.
96 +
97 +```js
98 +describe('mocha tests', function () {
99 +
100 + var $
101 + jsdom()
102 +
103 + before(function () {
104 + $ = require('jquery')
105 + })
106 +
107 + it('works', function () {
108 + document.body.innerHTML = '<div>hola</div>'
109 + expect($("div").html()).eql('hola')
110 + })
111 +
112 +})
113 +```
114 +
115 +See [examples/basic](examples/basic) for an example of a basic setup.
116 +
117 +<br>
118 +
119 +## Using with a library, alternate
120 +
121 +You can also pass the source code via `src`:
122 +
123 +```js
124 +describe('mocha tests', function () {
125 + jsdom({
126 + src: fs.readFileSync('jquery.js', 'utf-8')
127 + })
128 +
129 + ...
130 +})
131 +```
132 +
133 +<br>
134 +
135 +## Configuration
136 +
137 +You can pass jsdom options:
138 +
139 +```js
140 +describe('mocha tests', function () {
141 + jsdom({
142 + parsingMode: 'xml'
143 + })
144 +
145 + ...
146 +})
147 +```
148 +
149 +<br>
150 +
151 +## Working with mocha --watch
152 +
153 +When using with `--watch`, you my encounter strange errors from 3rd-party
154 +libraries like jQuery not working properly.
155 +
156 +In these cases, use `require('mocha-jsdom').rerequire` instead of `require()`.
157 +This will ensure that the `require()` call will always happen.
158 +
159 +```js
160 +var $
161 +var jsdom = require('mocha-jsdom')
162 +var rerequire = jsdom.rerequire
163 +
164 +jsdom()
165 +
166 +before(function () {
167 + $ = rerequire('jquery')
168 +})
169 +```
170 +
171 +<br>
172 +
173 +## Special config
174 +
175 +Other mocha-jsdom specific options:
176 +
177 + * `globalize` - propagates to values in `window` to `global`. defaults to true.
178 +
179 + * `console` - allows you to use `console.log` inside a jsdom script. defaults
180 + to true.
181 +
182 + * `useEach` - bind to Mocha's `beforeEach`/`afterEach` rather than `before`/`after`.
183 + defaults to false.
184 +
185 + * `skipWindowCheck` - skips checking of `window` at startup. When false,
186 + mocha-jsdom will throw an error if `window` already exists. Defaults to false.
187 +
188 +[jsdom]: https://www.npmjs.org/package/jsdom
189 +[mocha]: https://www.npmjs.com/package/mocha
190 +
191 +<br>
192 +
193 +## Testling support
194 +
195 +Yes, fully compatible with testling. A test suite using jsdom should be able to use testling.
196 +
197 +See [examples/basic](examples/basic/) for a setup that allows for testing via iojs (jsdom), testling, and mocha via the browser.
198 +
199 +<br>
200 +
201 +## Thanks
202 +
203 +> **mocha-jsdom** © 2014-2018 Rico Sta. Cruz. Released under the [MIT] License.<br>
204 +> Authored and maintained by Rico Sta. Cruz with help from contributors ([list][contributors]).
205 +
206 +[![](https://img.shields.io/github/followers/rstacruz.svg?style=social&label=@rstacruz)](https://github.com/rstacruz)
207 +&nbsp;&nbsp;
208 +[![](https://img.shields.io/twitter/follow/rstacruz.svg?style=social&label=@rstacruz)](https://twitter.com/rstacruz)
209 +&nbsp;&nbsp;
210 +**[ricostacruz.com](http://ricostacruz.com)**
211 +
212 +[mit]: http://mit-license.org/
213 +[contributors]: http://github.com/rstacruz/mocha-jsdom/contributors
1 +/*
2 + * A noop version in case your tests are browserified (eg, when using
3 + * testling).
4 + */
5 +
6 +module.exports = function () {}
1 +This is a basic example of what you can put in your project's `test/` folder.
2 +It will allow you to run tests in both jsdom (iojs/node) and the browser.
1 +<!doctype html>
2 +<html>
3 +<head>
4 + <title>Mocha</title>
5 + <meta charset="utf-8">
6 + <meta name="viewport" content="width=device-width, initial-scale=1.0">
7 + <link href="https://cdn.rawgit.com/mochajs/mocha/2.2.5/mocha.css" rel="stylesheet" />
8 +</head>
9 +<body>
10 + <div id="mocha"></div>
11 + <script src="https://cdn.rawgit.com/mochajs/mocha/2.2.5/mocha.js"></script>
12 + <script src="https://cdn.rawgit.com/chaijs/chai/2.3.0/chai.js"></script>
13 + <script>mocha.setup('bdd')</script>
14 + <!-- thing to test -->
15 + <script src="../index.js"></script>
16 + <!-- your test files -->
17 + <script src="setup.js"></script>
18 + <script src="test.js"></script>
19 + <script>mocha.run()</script>
20 +</body>
21 +</html>
1 +if (typeof process === 'object') {
2 + // Initialize node environment
3 + global.expect = require('chai').expect
4 + require('mocha-jsdom')()
5 +} else {
6 + window.expect = window.chai.expect
7 + window.require = function () { /* noop */ }
8 +}
1 +/* global describe, it, before, expect */
2 +require('./setup')
3 +
4 +describe('my library', function () {
5 + var mylib
6 +
7 + before(function () {
8 + mylib = require('mylib') || window.mylib
9 + })
10 +
11 + it('works', function () {
12 + expect(mylib.greet()).to.eql('hola')
13 + })
14 +})
1 +These examples are here so you can see what failures look like.
2 +
3 +Run `mocha one.js` or `mocha two.js` to see.
1 +/* global it, expect, describe */
2 +/* jshint expr: true */
3 +
4 +var jsdom = require('../../index')
5 +
6 +describe('error', function () {
7 + jsdom({
8 + src: "(function () { throw new Error('ffff'); })()"
9 + })
10 +
11 + it('fails', function () {
12 + expect(global.document).be.undefined // eslint-disable-line no-unused-expressions
13 + })
14 +})
1 +/* global describe, it, expect */
2 +
3 +describe('src', function () {
4 + require('../../index')({
5 + src: '}}'
6 + })
7 +
8 + it('works', function () {
9 + expect(window.lol()).eql('DIV')
10 + })
11 +})
1 +var extend = Object.assign || require('util')._extend // eslint-disable-line node/no-deprecated-api
2 +var Path = require('path')
3 +
4 +/*
5 + * store original global keys
6 + */
7 +
8 +var blacklist = Object.keys(global)
9 +blacklist.push('constructor')
10 +
11 +/*
12 + * default config
13 + */
14 +
15 +var defaults = {
16 + globalize: true,
17 + console: true,
18 + useEach: false,
19 + skipWindowCheck: false,
20 + html:
21 + "<!doctype html><html><head><meta charset='utf-8'></head>" +
22 + '<body></body></html>'
23 +}
24 +
25 +/*
26 + * simple jsdom integration.
27 + * You can pass jsdom options in, too:
28 + *
29 + * require('./support/jsdom')({
30 + * src: [ jquery ]
31 + * })
32 + */
33 +
34 +module.exports = function (_options) {
35 + var options = extend(extend({}, defaults), _options)
36 +
37 + var keys = []
38 +
39 + var before = options.useEach ? global.beforeEach : global.before
40 + var after = options.useEach ? global.afterEach : global.after
41 +
42 + /*
43 + * register jsdom before the entire test suite
44 + */
45 +
46 + before(function (next) {
47 + if (global.window && !options.skipWindowCheck) {
48 + throw new Error(
49 + 'mocha-jsdom: already a browser environment, or mocha-jsdom invoked ' +
50 + "twice. use 'skipWindowCheck' to disable this check."
51 + )
52 + }
53 + require('jsdom/lib/old-api').env(
54 + extend(extend({}, options), { done: done })
55 + )
56 +
57 + function done (errors, window) {
58 + if (options.globalize) {
59 + propagateToGlobal(window)
60 + } else {
61 + global.window = window
62 + }
63 +
64 + if (options.console) {
65 + window.console = global.console
66 + }
67 +
68 + if (errors) {
69 + return next(getError(errors))
70 + }
71 +
72 + next(null)
73 + }
74 + })
75 +
76 + /*
77 + * undo keys from being propagated to global after the test suite
78 + */
79 +
80 + after(function () {
81 + if (options.globalize) {
82 + keys.forEach(function (key) {
83 + delete global[key]
84 + })
85 + } else {
86 + delete global.window
87 + }
88 + })
89 +
90 + /*
91 + * propagate keys from `window` to `global`
92 + */
93 +
94 + function propagateToGlobal (window) {
95 + for (var key in window) {
96 + if (!window.hasOwnProperty(key)) continue
97 + if (~blacklist.indexOf(key)) continue
98 + if (global[key]) {
99 + if (process.env.JSDOM_VERBOSE) {
100 + console.warn(
101 + "[jsdom] Warning: skipping cleanup of global['" + key + "']"
102 + )
103 + }
104 + continue
105 + }
106 +
107 + keys.push(key)
108 + global[key] = window[key]
109 + }
110 + }
111 +
112 + /*
113 + * re-throws jsdom errors
114 + */
115 +
116 + function getError (errors) {
117 + var data = errors[0].data
118 + var err = data.error
119 + err.message = err.message + ' [jsdom]'
120 +
121 + // clean up stack trace
122 + if (err.stack) {
123 + err.stack = err.stack
124 + .split('\n')
125 + .reduce(function (list, line) {
126 + if (line.match(/node_modules.+(jsdom|mocha)/)) {
127 + return list
128 + }
129 +
130 + line = line
131 + .replace(/file:\/\/.*<script>/g, '<script>')
132 + .replace(/:undefined:undefined/g, '')
133 + list.push(line)
134 + return list
135 + }, [])
136 + .join('\n')
137 + }
138 +
139 + return err
140 + }
141 +}
142 +
143 +module.exports.rerequire = rerequire
144 +
145 +/**
146 + * Requires a module via `require()`, but invalidates the cache so it may be
147 + * called again in the future. Useful for `mocha --watch`.
148 + *
149 + * var rerequire = require('mocha-jsdom').rerequire
150 + * var $ = rerequire('jquery')
151 + */
152 +
153 +function rerequire (module) {
154 + if (module[0] === '.') {
155 + module = Path.join(Path.dirname(getCaller()), module)
156 + }
157 +
158 + var oldkeys = Object.keys(require.cache)
159 + var result = require(module)
160 + var newkeys = Object.keys(require.cache)
161 + newkeys.forEach(function (newkey) {
162 + if (!~oldkeys.indexOf(newkey)) {
163 + delete require.cache[newkey]
164 + }
165 + })
166 + return result
167 +}
168 +
169 +/**
170 + * Internal: gets the filename of the caller function. The `offset` defines how
171 + * many hops away it's expected to be from in the stack trace.
172 + *
173 + * See: http://stackoverflow.com/questions/16697791/nodejs-get-filename-of-caller-function
174 + */
175 +
176 +function getCaller (offset) {
177 + /* eslint-disable handle-callback-err */
178 + if (typeof offset !== 'number') offset = 1
179 + var old = Error.prepareStackTrace
180 + var err = new Error()
181 + Error.prepareStackTrace = function (err, stack) {
182 + return stack
183 + }
184 + var fname = err.stack[1 + offset].getFileName()
185 + Error.prepareStackTrace = old
186 + return fname
187 +}
1 +{
2 + "_args": [
3 + [
4 + "mocha-jsdom@2.0.0",
5 + "C:\\Users\\user\\Desktop\\Singer-Composer"
6 + ]
7 + ],
8 + "_development": true,
9 + "_from": "mocha-jsdom@2.0.0",
10 + "_id": "mocha-jsdom@2.0.0",
11 + "_inBundle": false,
12 + "_integrity": "sha512-+3D++FPXHXEesbBD7Q/r4dkc3XzVFMPLJVIECaQ685dj9qKQYzliqX8IXyIUbUL4x1QfgD9h8Zao8cn03NKKEA==",
13 + "_location": "/mocha-jsdom",
14 + "_phantomChildren": {},
15 + "_requested": {
16 + "type": "version",
17 + "registry": true,
18 + "raw": "mocha-jsdom@2.0.0",
19 + "name": "mocha-jsdom",
20 + "escapedName": "mocha-jsdom",
21 + "rawSpec": "2.0.0",
22 + "saveSpec": null,
23 + "fetchSpec": "2.0.0"
24 + },
25 + "_requiredBy": [
26 + "#DEV:/"
27 + ],
28 + "_resolved": "https://registry.npmjs.org/mocha-jsdom/-/mocha-jsdom-2.0.0.tgz",
29 + "_spec": "2.0.0",
30 + "_where": "C:\\Users\\user\\Desktop\\Singer-Composer",
31 + "author": {
32 + "name": "Rico Sta. Cruz",
33 + "email": "rico@ricostacruz.com"
34 + },
35 + "browser": "browser.js",
36 + "bugs": {
37 + "url": "https://github.com/rstacruz/mocha-jsdom/issues"
38 + },
39 + "dependencies": {
40 + "jsdom": "^11.11.0"
41 + },
42 + "description": "Simple integration of jsdom into mocha tests",
43 + "devDependencies": {
44 + "chai": "4.1.2",
45 + "istanbul": "0.4.5",
46 + "jquery": "3.3.1",
47 + "mocha": "5.2.0",
48 + "mocha-standard": "1.0.0",
49 + "standard": "11.0.1"
50 + },
51 + "directories": {
52 + "test": "test"
53 + },
54 + "homepage": "https://github.com/rstacruz/mocha-jsdom#readme",
55 + "keywords": [
56 + "jsdom",
57 + "mocha"
58 + ],
59 + "license": "MIT",
60 + "main": "index.js",
61 + "name": "mocha-jsdom",
62 + "peerDependencies": {
63 + "mocha": "*"
64 + },
65 + "repository": {
66 + "type": "git",
67 + "url": "git+https://github.com/rstacruz/mocha-jsdom.git"
68 + },
69 + "scripts": {
70 + "coverage": "istanbul cover _mocha -- -R spec",
71 + "test": "mocha"
72 + },
73 + "version": "2.0.0"
74 +}
1 +/* this module will have side effects if it's ran more than once.
2 + * we're gonna test for that. */
3 +
4 +global._rerequirable_count++
1 +/* global describe, it, expect */
2 +/* jshint expr: true */
3 +
4 +var jsdom = require('../index')
5 +
6 +describe('globalize', function () {
7 + jsdom({ globalize: false })
8 +
9 + it('does not globalize', function () {
10 + expect(global.document).be.undefined // eslint-disable-line no-unused-expressions
11 + })
12 +})
1 +/* global describe, before, it, document, expect */
2 +
3 +var jsdom = require('../index')
4 +
5 +describe('jquery', function () {
6 + var $
7 + jsdom()
8 +
9 + before(function () {
10 + $ = require('jquery')
11 + })
12 +
13 + it('creating elements works', function () {
14 + var div = $('<div>hello <b>world</b></div>')
15 + expect(div.html()).to.eql('hello <b>world</b>')
16 + })
17 +
18 + it('lookup works', function () {
19 + document.body.innerHTML = '<div>hola</div>'
20 + expect($('div').html()).eql('hola')
21 + })
22 +})
1 +--require test/setup
2 +--timeout 5000
1 +/* global describe, it, beforeEach, expect */
2 +
3 +var rerequire = require('../index').rerequire
4 +
5 +describe('rerequire', function () {
6 + beforeEach(function () {
7 + global._rerequirable_count = 0
8 + })
9 +
10 + it('has a fixture that works', function () {
11 + rerequire('./fixtures/rerequirable')
12 + expect(global._rerequirable_count).eql(1)
13 + })
14 +
15 + // ensure that subsequent runs don't bother
16 + it('has a fixture that really works', function () {
17 + rerequire('./fixtures/rerequirable')
18 + expect(global._rerequirable_count).eql(1)
19 + })
20 +
21 + it('works 5x', function () {
22 + rerequire('./fixtures/rerequirable')
23 + rerequire('./fixtures/rerequirable')
24 + rerequire('./fixtures/rerequirable')
25 + rerequire('./fixtures/rerequirable')
26 + rerequire('./fixtures/rerequirable')
27 + expect(global._rerequirable_count).eql(5)
28 + })
29 +})
1 +/* global it, before, window, describe, expect */
2 +
3 +var jsdom = require('../index')
4 +
5 +describe('robust', function () {
6 + before(function () {
7 + // User or another test framework redefines global.window
8 + global.window = undefined
9 + })
10 +
11 + jsdom()
12 +
13 + it('has window', function () {
14 + expect(global.window).to.not.be.undefined // eslint-disable-line no-unused-expressions
15 + })
16 +})
1 +global.expect = require('chai').expect
1 +/* global it, history, describe, location, expect */
2 +
3 +var jsdom = require('../index')
4 +
5 +describe('simple', function () {
6 + jsdom()
7 +
8 + it('has document', function () {
9 + var div = document.createElement('div')
10 + expect(div.nodeName).eql('DIV')
11 + })
12 +
13 + it('has history', function () {
14 + history.pushState({}, 'abc', '#/a/b/c')
15 + expect(location.href).match(/\/a\/b\/c$/)
16 + })
17 +})
1 +/* global describe, it, before, after, expect */
2 +/* jshint expr: true */
3 +
4 +var jsdom = require('../index')
5 +
6 +describe('skipWindowCheck: true', function () {
7 + before(function () {
8 + global.window = {}
9 + })
10 +
11 + after(function () {
12 + delete global.window
13 + })
14 +
15 + jsdom({ skipWindowCheck: true })
16 +
17 + it('does not throw errors', function () {
18 + var div = document.createElement('div')
19 + expect(div.nodeName).eql('DIV')
20 + })
21 +})
1 +/* global describe, it */
2 +
3 +describe('standard', function () {
4 + it('is conformed to', require('mocha-standard'))
5 +})
1 +/* global describe, it, expect */
2 +/* jshint expr: true */
3 +
4 +var jsdom = require('../index')
5 +
6 +describe('check useEach false (default)', function () {
7 + var someContent = '<div>hola</div>'
8 + jsdom()
9 +
10 + it('check that html body is empty', function () {
11 + expect(document.body.innerHTML).to.be.empty // eslint-disable-line no-unused-expressions
12 + })
13 +
14 + it('accepts an html body', function () {
15 + document.body.innerHTML = someContent
16 + expect(document.body.innerHTML).eql(someContent)
17 + })
18 +
19 + it('has document persisting across tests', function () {
20 + expect(document.body.innerHTML).eql(someContent)
21 + })
22 +})
23 +
24 +describe('check useEach true', function () {
25 + var someContent = '<div>hola</div>'
26 + jsdom({ useEach: true })
27 +
28 + it('check that html body is empty', function () {
29 + expect(document.body.innerHTML).to.be.empty // eslint-disable-line no-unused-expressions
30 + })
31 +
32 + it('accepts an html body', function () {
33 + document.body.innerHTML = someContent
34 + expect(document.body.innerHTML).eql(someContent)
35 + })
36 +
37 + it('changes to the dom do not persist between tests', function () {
38 + expect(document.body.innerHTML).to.be.empty // eslint-disable-line no-unused-expressions
39 + })
40 +})
1 +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2 +# yarn lockfile v1
3 +
4 +
5 +abab@^1.0.4:
6 + version "1.0.4"
7 + resolved "https://registry.yarnpkg.com/abab/-/abab-1.0.4.tgz#5faad9c2c07f60dd76770f71cf025b62a63cfd4e"
8 +
9 +abbrev@1:
10 + version "1.1.1"
11 + resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.1.tgz#f8f2c887ad10bf67f634f005b6987fed3179aac8"
12 +
13 +abbrev@1.0.x:
14 + version "1.0.9"
15 + resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.0.9.tgz#91b4792588a7738c25f35dd6f63752a2f8776135"
16 +
17 +acorn-globals@^4.1.0:
18 + version "4.1.0"
19 + resolved "https://registry.yarnpkg.com/acorn-globals/-/acorn-globals-4.1.0.tgz#ab716025dbe17c54d3ef81d32ece2b2d99fe2538"
20 + dependencies:
21 + acorn "^5.0.0"
22 +
23 +acorn-jsx@^3.0.0:
24 + version "3.0.1"
25 + resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-3.0.1.tgz#afdf9488fb1ecefc8348f6fb22f464e32a58b36b"
26 + dependencies:
27 + acorn "^3.0.4"
28 +
29 +acorn@^3.0.4:
30 + version "3.3.0"
31 + resolved "https://registry.yarnpkg.com/acorn/-/acorn-3.3.0.tgz#45e37fb39e8da3f25baee3ff5369e2bb5f22017a"
32 +
33 +acorn@^5.0.0, acorn@^5.3.0, acorn@^5.5.0:
34 + version "5.6.1"
35 + resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.6.1.tgz#c9e50c3e3717cf897f1b071ceadbb543bbc0a8d4"
36 +
37 +ajv-keywords@^2.1.0:
38 + version "2.1.1"
39 + resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-2.1.1.tgz#617997fc5f60576894c435f940d819e135b80762"
40 +
41 +ajv@^5.1.0, ajv@^5.2.3, ajv@^5.3.0:
42 + version "5.5.2"
43 + resolved "https://registry.yarnpkg.com/ajv/-/ajv-5.5.2.tgz#73b5eeca3fab653e3d3f9422b341ad42205dc965"
44 + dependencies:
45 + co "^4.6.0"
46 + fast-deep-equal "^1.0.0"
47 + fast-json-stable-stringify "^2.0.0"
48 + json-schema-traverse "^0.3.0"
49 +
50 +align-text@^0.1.1, align-text@^0.1.3:
51 + version "0.1.4"
52 + resolved "https://registry.yarnpkg.com/align-text/-/align-text-0.1.4.tgz#0cd90a561093f35d0a99256c22b7069433fad117"
53 + dependencies:
54 + kind-of "^3.0.2"
55 + longest "^1.0.1"
56 + repeat-string "^1.5.2"
57 +
58 +amdefine@>=0.0.4:
59 + version "1.0.1"
60 + resolved "https://registry.yarnpkg.com/amdefine/-/amdefine-1.0.1.tgz#4a5282ac164729e93619bcfd3ad151f817ce91f5"
61 +
62 +ansi-escapes@^3.0.0:
63 + version "3.1.0"
64 + resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-3.1.0.tgz#f73207bb81207d75fd6c83f125af26eea378ca30"
65 +
66 +ansi-regex@^2.0.0:
67 + version "2.1.1"
68 + resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df"
69 +
70 +ansi-regex@^3.0.0:
71 + version "3.0.0"
72 + resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-3.0.0.tgz#ed0317c322064f79466c02966bddb605ab37d998"
73 +
74 +ansi-styles@^2.2.1:
75 + version "2.2.1"
76 + resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe"
77 +
78 +ansi-styles@^3.2.1:
79 + version "3.2.1"
80 + resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d"
81 + dependencies:
82 + color-convert "^1.9.0"
83 +
84 +argparse@^1.0.7:
85 + version "1.0.10"
86 + resolved "https://registry.yarnpkg.com/argparse/-/argparse-1.0.10.tgz#bcd6791ea5ae09725e17e5ad988134cd40b3d911"
87 + dependencies:
88 + sprintf-js "~1.0.2"
89 +
90 +array-equal@^1.0.0:
91 + version "1.0.0"
92 + resolved "https://registry.yarnpkg.com/array-equal/-/array-equal-1.0.0.tgz#8c2a5ef2472fd9ea742b04c77a75093ba2757c93"
93 +
94 +array-includes@^3.0.3:
95 + version "3.0.3"
96 + resolved "https://registry.yarnpkg.com/array-includes/-/array-includes-3.0.3.tgz#184b48f62d92d7452bb31b323165c7f8bd02266d"
97 + dependencies:
98 + define-properties "^1.1.2"
99 + es-abstract "^1.7.0"
100 +
101 +array-union@^1.0.1:
102 + version "1.0.2"
103 + resolved "https://registry.yarnpkg.com/array-union/-/array-union-1.0.2.tgz#9a34410e4f4e3da23dea375be5be70f24778ec39"
104 + dependencies:
105 + array-uniq "^1.0.1"
106 +
107 +array-uniq@^1.0.1:
108 + version "1.0.3"
109 + resolved "https://registry.yarnpkg.com/array-uniq/-/array-uniq-1.0.3.tgz#af6ac877a25cc7f74e058894753858dfdb24fdb6"
110 +
111 +arrify@^1.0.0:
112 + version "1.0.1"
113 + resolved "https://registry.yarnpkg.com/arrify/-/arrify-1.0.1.tgz#898508da2226f380df904728456849c1501a4b0d"
114 +
115 +asap@~2.0.3:
116 + version "2.0.6"
117 + resolved "https://registry.yarnpkg.com/asap/-/asap-2.0.6.tgz#e50347611d7e690943208bbdafebcbc2fb866d46"
118 +
119 +asn1@~0.2.3:
120 + version "0.2.3"
121 + resolved "https://registry.yarnpkg.com/asn1/-/asn1-0.2.3.tgz#dac8787713c9966849fc8180777ebe9c1ddf3b86"
122 +
123 +assert-plus@1.0.0, assert-plus@^1.0.0:
124 + version "1.0.0"
125 + resolved "https://registry.yarnpkg.com/assert-plus/-/assert-plus-1.0.0.tgz#f12e0f3c5d77b0b1cdd9146942e4e96c1e4dd525"
126 +
127 +assertion-error@^1.0.1:
128 + version "1.1.0"
129 + resolved "https://registry.yarnpkg.com/assertion-error/-/assertion-error-1.1.0.tgz#e60b6b0e8f301bd97e5375215bda406c85118c0b"
130 +
131 +async-limiter@~1.0.0:
132 + version "1.0.0"
133 + resolved "https://registry.yarnpkg.com/async-limiter/-/async-limiter-1.0.0.tgz#78faed8c3d074ab81f22b4e985d79e8738f720f8"
134 +
135 +async@1.x, async@^1.4.0:
136 + version "1.5.2"
137 + resolved "https://registry.yarnpkg.com/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a"
138 +
139 +asynckit@^0.4.0:
140 + version "0.4.0"
141 + resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
142 +
143 +aws-sign2@~0.7.0:
144 + version "0.7.0"
145 + resolved "https://registry.yarnpkg.com/aws-sign2/-/aws-sign2-0.7.0.tgz#b46e890934a9591f2d2f6f86d7e6a9f1b3fe76a8"
146 +
147 +aws4@^1.6.0:
148 + version "1.7.0"
149 + resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.7.0.tgz#d4d0e9b9dbfca77bf08eeb0a8a471550fe39e289"
150 +
151 +babel-code-frame@^6.22.0:
152 + version "6.26.0"
153 + resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.26.0.tgz#63fd43f7dc1e3bb7ce35947db8fe369a3f58c74b"
154 + dependencies:
155 + chalk "^1.1.3"
156 + esutils "^2.0.2"
157 + js-tokens "^3.0.2"
158 +
159 +balanced-match@^1.0.0:
160 + version "1.0.0"
161 + resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
162 +
163 +bcrypt-pbkdf@^1.0.0:
164 + version "1.0.1"
165 + resolved "https://registry.yarnpkg.com/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.1.tgz#63bc5dcb61331b92bc05fd528953c33462a06f8d"
166 + dependencies:
167 + tweetnacl "^0.14.3"
168 +
169 +brace-expansion@^1.1.7:
170 + version "1.1.11"
171 + resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"
172 + dependencies:
173 + balanced-match "^1.0.0"
174 + concat-map "0.0.1"
175 +
176 +browser-process-hrtime@^0.1.2:
177 + version "0.1.2"
178 + resolved "https://registry.yarnpkg.com/browser-process-hrtime/-/browser-process-hrtime-0.1.2.tgz#425d68a58d3447f02a04aa894187fce8af8b7b8e"
179 +
180 +browser-stdout@1.3.1:
181 + version "1.3.1"
182 + resolved "https://registry.yarnpkg.com/browser-stdout/-/browser-stdout-1.3.1.tgz#baa559ee14ced73452229bad7326467c61fabd60"
183 +
184 +buffer-from@^1.0.0:
185 + version "1.1.0"
186 + resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.0.tgz#87fcaa3a298358e0ade6e442cfce840740d1ad04"
187 +
188 +builtin-modules@^1.0.0, builtin-modules@^1.1.1:
189 + version "1.1.1"
190 + resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-1.1.1.tgz#270f076c5a72c02f5b65a47df94c5fe3a278892f"
191 +
192 +caller-path@^0.1.0:
193 + version "0.1.0"
194 + resolved "https://registry.yarnpkg.com/caller-path/-/caller-path-0.1.0.tgz#94085ef63581ecd3daa92444a8fe94e82577751f"
195 + dependencies:
196 + callsites "^0.2.0"
197 +
198 +callsites@^0.2.0:
199 + version "0.2.0"
200 + resolved "https://registry.yarnpkg.com/callsites/-/callsites-0.2.0.tgz#afab96262910a7f33c19a5775825c69f34e350ca"
201 +
202 +camelcase@^1.0.2:
203 + version "1.2.1"
204 + resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-1.2.1.tgz#9bb5304d2e0b56698b2c758b08a3eaa9daa58a39"
205 +
206 +caseless@~0.12.0:
207 + version "0.12.0"
208 + resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc"
209 +
210 +center-align@^0.1.1:
211 + version "0.1.3"
212 + resolved "https://registry.yarnpkg.com/center-align/-/center-align-0.1.3.tgz#aa0d32629b6ee972200411cbd4461c907bc2b7ad"
213 + dependencies:
214 + align-text "^0.1.3"
215 + lazy-cache "^1.0.3"
216 +
217 +chai@4.1.2:
218 + version "4.1.2"
219 + resolved "https://registry.yarnpkg.com/chai/-/chai-4.1.2.tgz#0f64584ba642f0f2ace2806279f4f06ca23ad73c"
220 + dependencies:
221 + assertion-error "^1.0.1"
222 + check-error "^1.0.1"
223 + deep-eql "^3.0.0"
224 + get-func-name "^2.0.0"
225 + pathval "^1.0.0"
226 + type-detect "^4.0.0"
227 +
228 +chalk@^1.1.3:
229 + version "1.1.3"
230 + resolved "https://registry.yarnpkg.com/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98"
231 + dependencies:
232 + ansi-styles "^2.2.1"
233 + escape-string-regexp "^1.0.2"
234 + has-ansi "^2.0.0"
235 + strip-ansi "^3.0.0"
236 + supports-color "^2.0.0"
237 +
238 +chalk@^2.0.0, chalk@^2.1.0:
239 + version "2.4.1"
240 + resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.1.tgz#18c49ab16a037b6eb0152cc83e3471338215b66e"
241 + dependencies:
242 + ansi-styles "^3.2.1"
243 + escape-string-regexp "^1.0.5"
244 + supports-color "^5.3.0"
245 +
246 +chardet@^0.4.0:
247 + version "0.4.2"
248 + resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.4.2.tgz#b5473b33dc97c424e5d98dc87d55d4d8a29c8bf2"
249 +
250 +check-error@^1.0.1:
251 + version "1.0.2"
252 + resolved "https://registry.yarnpkg.com/check-error/-/check-error-1.0.2.tgz#574d312edd88bb5dd8912e9286dd6c0aed4aac82"
253 +
254 +circular-json@^0.3.1:
255 + version "0.3.3"
256 + resolved "https://registry.yarnpkg.com/circular-json/-/circular-json-0.3.3.tgz#815c99ea84f6809529d2f45791bdf82711352d66"
257 +
258 +cli-cursor@^2.1.0:
259 + version "2.1.0"
260 + resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-2.1.0.tgz#b35dac376479facc3e94747d41d0d0f5238ffcb5"
261 + dependencies:
262 + restore-cursor "^2.0.0"
263 +
264 +cli-width@^2.0.0:
265 + version "2.2.0"
266 + resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-2.2.0.tgz#ff19ede8a9a5e579324147b0c11f0fbcbabed639"
267 +
268 +cliui@^2.1.0:
269 + version "2.1.0"
270 + resolved "https://registry.yarnpkg.com/cliui/-/cliui-2.1.0.tgz#4b475760ff80264c762c3a1719032e91c7fea0d1"
271 + dependencies:
272 + center-align "^0.1.1"
273 + right-align "^0.1.1"
274 + wordwrap "0.0.2"
275 +
276 +co@^4.6.0:
277 + version "4.6.0"
278 + resolved "https://registry.yarnpkg.com/co/-/co-4.6.0.tgz#6ea6bdf3d853ae54ccb8e47bfa0bf3f9031fb184"
279 +
280 +color-convert@^1.9.0:
281 + version "1.9.1"
282 + resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-1.9.1.tgz#c1261107aeb2f294ebffec9ed9ecad529a6097ed"
283 + dependencies:
284 + color-name "^1.1.1"
285 +
286 +color-name@^1.1.1:
287 + version "1.1.3"
288 + resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25"
289 +
290 +combined-stream@1.0.6, combined-stream@~1.0.5:
291 + version "1.0.6"
292 + resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.6.tgz#723e7df6e801ac5613113a7e445a9b69cb632818"
293 + dependencies:
294 + delayed-stream "~1.0.0"
295 +
296 +commander@2.15.1:
297 + version "2.15.1"
298 + resolved "https://registry.yarnpkg.com/commander/-/commander-2.15.1.tgz#df46e867d0fc2aec66a34662b406a9ccafff5b0f"
299 +
300 +concat-map@0.0.1:
301 + version "0.0.1"
302 + resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
303 +
304 +concat-stream@^1.6.0:
305 + version "1.6.2"
306 + resolved "https://registry.yarnpkg.com/concat-stream/-/concat-stream-1.6.2.tgz#904bdf194cd3122fc675c77fc4ac3d4ff0fd1a34"
307 + dependencies:
308 + buffer-from "^1.0.0"
309 + inherits "^2.0.3"
310 + readable-stream "^2.2.2"
311 + typedarray "^0.0.6"
312 +
313 +contains-path@^0.1.0:
314 + version "0.1.0"
315 + resolved "https://registry.yarnpkg.com/contains-path/-/contains-path-0.1.0.tgz#fe8cf184ff6670b6baef01a9d4861a5cbec4120a"
316 +
317 +core-js@^1.0.0:
318 + version "1.2.7"
319 + resolved "https://registry.yarnpkg.com/core-js/-/core-js-1.2.7.tgz#652294c14651db28fa93bd2d5ff2983a4f08c636"
320 +
321 +core-util-is@1.0.2, core-util-is@~1.0.0:
322 + version "1.0.2"
323 + resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
324 +
325 +cross-spawn@^5.1.0:
326 + version "5.1.0"
327 + resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-5.1.0.tgz#e8bd0efee58fcff6f8f94510a0a554bbfa235449"
328 + dependencies:
329 + lru-cache "^4.0.1"
330 + shebang-command "^1.2.0"
331 + which "^1.2.9"
332 +
333 +cssom@0.3.x, "cssom@>= 0.3.2 < 0.4.0":
334 + version "0.3.2"
335 + resolved "https://registry.yarnpkg.com/cssom/-/cssom-0.3.2.tgz#b8036170c79f07a90ff2f16e22284027a243848b"
336 +
337 +"cssstyle@>= 0.3.1 < 0.4.0":
338 + version "0.3.1"
339 + resolved "https://registry.yarnpkg.com/cssstyle/-/cssstyle-0.3.1.tgz#6da9b4cff1bc5d716e6e5fe8e04fcb1b50a49adf"
340 + dependencies:
341 + cssom "0.3.x"
342 +
343 +dashdash@^1.12.0:
344 + version "1.14.1"
345 + resolved "https://registry.yarnpkg.com/dashdash/-/dashdash-1.14.1.tgz#853cfa0f7cbe2fed5de20326b8dd581035f6e2f0"
346 + dependencies:
347 + assert-plus "^1.0.0"
348 +
349 +data-urls@^1.0.0:
350 + version "1.0.0"
351 + resolved "https://registry.yarnpkg.com/data-urls/-/data-urls-1.0.0.tgz#24802de4e81c298ea8a9388bb0d8e461c774684f"
352 + dependencies:
353 + abab "^1.0.4"
354 + whatwg-mimetype "^2.0.0"
355 + whatwg-url "^6.4.0"
356 +
357 +debug-log@^1.0.0:
358 + version "1.0.1"
359 + resolved "https://registry.yarnpkg.com/debug-log/-/debug-log-1.0.1.tgz#2307632d4c04382b8df8a32f70b895046d52745f"
360 +
361 +debug@3.1.0, debug@^3.1.0:
362 + version "3.1.0"
363 + resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261"
364 + dependencies:
365 + ms "2.0.0"
366 +
367 +debug@^2.6.8, debug@^2.6.9:
368 + version "2.6.9"
369 + resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
370 + dependencies:
371 + ms "2.0.0"
372 +
373 +decamelize@^1.0.0:
374 + version "1.2.0"
375 + resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290"
376 +
377 +deep-eql@^3.0.0:
378 + version "3.0.1"
379 + resolved "https://registry.yarnpkg.com/deep-eql/-/deep-eql-3.0.1.tgz#dfc9404400ad1c8fe023e7da1df1c147c4b444df"
380 + dependencies:
381 + type-detect "^4.0.0"
382 +
383 +deep-is@~0.1.3:
384 + version "0.1.3"
385 + resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34"
386 +
387 +define-properties@^1.1.2:
388 + version "1.1.2"
389 + resolved "https://registry.yarnpkg.com/define-properties/-/define-properties-1.1.2.tgz#83a73f2fea569898fb737193c8f873caf6d45c94"
390 + dependencies:
391 + foreach "^2.0.5"
392 + object-keys "^1.0.8"
393 +
394 +deglob@^2.1.0:
395 + version "2.1.0"
396 + resolved "https://registry.yarnpkg.com/deglob/-/deglob-2.1.0.tgz#4d44abe16ef32c779b4972bd141a80325029a14a"
397 + dependencies:
398 + find-root "^1.0.0"
399 + glob "^7.0.5"
400 + ignore "^3.0.9"
401 + pkg-config "^1.1.0"
402 + run-parallel "^1.1.2"
403 + uniq "^1.0.1"
404 +
405 +del@^2.0.2:
406 + version "2.2.2"
407 + resolved "https://registry.yarnpkg.com/del/-/del-2.2.2.tgz#c12c981d067846c84bcaf862cff930d907ffd1a8"
408 + dependencies:
409 + globby "^5.0.0"
410 + is-path-cwd "^1.0.0"
411 + is-path-in-cwd "^1.0.0"
412 + object-assign "^4.0.1"
413 + pify "^2.0.0"
414 + pinkie-promise "^2.0.0"
415 + rimraf "^2.2.8"
416 +
417 +delayed-stream@~1.0.0:
418 + version "1.0.0"
419 + resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
420 +
421 +diff@3.5.0:
422 + version "3.5.0"
423 + resolved "https://registry.yarnpkg.com/diff/-/diff-3.5.0.tgz#800c0dd1e0a8bfbc95835c202ad220fe317e5a12"
424 +
425 +doctrine@1.5.0:
426 + version "1.5.0"
427 + resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-1.5.0.tgz#379dce730f6166f76cefa4e6707a159b02c5a6fa"
428 + dependencies:
429 + esutils "^2.0.2"
430 + isarray "^1.0.0"
431 +
432 +doctrine@^2.0.2, doctrine@^2.1.0:
433 + version "2.1.0"
434 + resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-2.1.0.tgz#5cd01fc101621b42c4cd7f5d1a66243716d3f39d"
435 + dependencies:
436 + esutils "^2.0.2"
437 +
438 +domexception@^1.0.0:
439 + version "1.0.1"
440 + resolved "https://registry.yarnpkg.com/domexception/-/domexception-1.0.1.tgz#937442644ca6a31261ef36e3ec677fe805582c90"
441 + dependencies:
442 + webidl-conversions "^4.0.2"
443 +
444 +ecc-jsbn@~0.1.1:
445 + version "0.1.1"
446 + resolved "https://registry.yarnpkg.com/ecc-jsbn/-/ecc-jsbn-0.1.1.tgz#0fc73a9ed5f0d53c38193398523ef7e543777505"
447 + dependencies:
448 + jsbn "~0.1.0"
449 +
450 +encoding@^0.1.11:
451 + version "0.1.12"
452 + resolved "https://registry.yarnpkg.com/encoding/-/encoding-0.1.12.tgz#538b66f3ee62cd1ab51ec323829d1f9480c74beb"
453 + dependencies:
454 + iconv-lite "~0.4.13"
455 +
456 +error-ex@^1.2.0, error-ex@^1.3.1:
457 + version "1.3.1"
458 + resolved "https://registry.yarnpkg.com/error-ex/-/error-ex-1.3.1.tgz#f855a86ce61adc4e8621c3cda21e7a7612c3a8dc"
459 + dependencies:
460 + is-arrayish "^0.2.1"
461 +
462 +es-abstract@^1.7.0:
463 + version "1.12.0"
464 + resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.12.0.tgz#9dbbdd27c6856f0001421ca18782d786bf8a6165"
465 + dependencies:
466 + es-to-primitive "^1.1.1"
467 + function-bind "^1.1.1"
468 + has "^1.0.1"
469 + is-callable "^1.1.3"
470 + is-regex "^1.0.4"
471 +
472 +es-to-primitive@^1.1.1:
473 + version "1.1.1"
474 + resolved "https://registry.yarnpkg.com/es-to-primitive/-/es-to-primitive-1.1.1.tgz#45355248a88979034b6792e19bb81f2b7975dd0d"
475 + dependencies:
476 + is-callable "^1.1.1"
477 + is-date-object "^1.0.1"
478 + is-symbol "^1.0.1"
479 +
480 +escape-string-regexp@1.0.5, escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5:
481 + version "1.0.5"
482 + resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
483 +
484 +escodegen@1.8.x:
485 + version "1.8.1"
486 + resolved "https://registry.yarnpkg.com/escodegen/-/escodegen-1.8.1.tgz#5a5b53af4693110bebb0867aa3430dd3b70a1018"
487 + dependencies:
488 + esprima "^2.7.1"
489 + estraverse "^1.9.1"
490 + esutils "^2.0.2"
491 + optionator "^0.8.1"
492 + optionalDependencies:
493 + source-map "~0.2.0"
494 +
495 +escodegen@^1.9.0:
496 + version "1.9.1"
497 + resolved "https://registry.yarnpkg.com/escodegen/-/escodegen-1.9.1.tgz#dbae17ef96c8e4bedb1356f4504fa4cc2f7cb7e2"
498 + dependencies:
499 + esprima "^3.1.3"
500 + estraverse "^4.2.0"
501 + esutils "^2.0.2"
502 + optionator "^0.8.1"
503 + optionalDependencies:
504 + source-map "~0.6.1"
505 +
506 +eslint-config-standard-jsx@5.0.0:
507 + version "5.0.0"
508 + resolved "https://registry.yarnpkg.com/eslint-config-standard-jsx/-/eslint-config-standard-jsx-5.0.0.tgz#4abfac554f38668e0078c664569e7b2384e5d2aa"
509 +
510 +eslint-config-standard@11.0.0:
511 + version "11.0.0"
512 + resolved "https://registry.yarnpkg.com/eslint-config-standard/-/eslint-config-standard-11.0.0.tgz#87ee0d3c9d95382dc761958cbb23da9eea31e0ba"
513 +
514 +eslint-import-resolver-node@^0.3.1:
515 + version "0.3.2"
516 + resolved "https://registry.yarnpkg.com/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.2.tgz#58f15fb839b8d0576ca980413476aab2472db66a"
517 + dependencies:
518 + debug "^2.6.9"
519 + resolve "^1.5.0"
520 +
521 +eslint-module-utils@^2.1.1:
522 + version "2.2.0"
523 + resolved "https://registry.yarnpkg.com/eslint-module-utils/-/eslint-module-utils-2.2.0.tgz#b270362cd88b1a48ad308976ce7fa54e98411746"
524 + dependencies:
525 + debug "^2.6.8"
526 + pkg-dir "^1.0.0"
527 +
528 +eslint-plugin-import@~2.9.0:
529 + version "2.9.0"
530 + resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.9.0.tgz#26002efbfca5989b7288ac047508bd24f217b169"
531 + dependencies:
532 + builtin-modules "^1.1.1"
533 + contains-path "^0.1.0"
534 + debug "^2.6.8"
535 + doctrine "1.5.0"
536 + eslint-import-resolver-node "^0.3.1"
537 + eslint-module-utils "^2.1.1"
538 + has "^1.0.1"
539 + lodash "^4.17.4"
540 + minimatch "^3.0.3"
541 + read-pkg-up "^2.0.0"
542 +
543 +eslint-plugin-node@~6.0.0:
544 + version "6.0.1"
545 + resolved "https://registry.yarnpkg.com/eslint-plugin-node/-/eslint-plugin-node-6.0.1.tgz#bf19642298064379315d7a4b2a75937376fa05e4"
546 + dependencies:
547 + ignore "^3.3.6"
548 + minimatch "^3.0.4"
549 + resolve "^1.3.3"
550 + semver "^5.4.1"
551 +
552 +eslint-plugin-promise@~3.7.0:
553 + version "3.7.0"
554 + resolved "https://registry.yarnpkg.com/eslint-plugin-promise/-/eslint-plugin-promise-3.7.0.tgz#f4bde5c2c77cdd69557a8f69a24d1ad3cfc9e67e"
555 +
556 +eslint-plugin-react@~7.7.0:
557 + version "7.7.0"
558 + resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-7.7.0.tgz#f606c719dbd8a1a2b3d25c16299813878cca0160"
559 + dependencies:
560 + doctrine "^2.0.2"
561 + has "^1.0.1"
562 + jsx-ast-utils "^2.0.1"
563 + prop-types "^15.6.0"
564 +
565 +eslint-plugin-standard@~3.0.1:
566 + version "3.0.1"
567 + resolved "https://registry.yarnpkg.com/eslint-plugin-standard/-/eslint-plugin-standard-3.0.1.tgz#34d0c915b45edc6f010393c7eef3823b08565cf2"
568 +
569 +eslint-scope@^3.7.1:
570 + version "3.7.1"
571 + resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-3.7.1.tgz#3d63c3edfda02e06e01a452ad88caacc7cdcb6e8"
572 + dependencies:
573 + esrecurse "^4.1.0"
574 + estraverse "^4.1.1"
575 +
576 +eslint-visitor-keys@^1.0.0:
577 + version "1.0.0"
578 + resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz#3f3180fb2e291017716acb4c9d6d5b5c34a6a81d"
579 +
580 +eslint@~4.18.0:
581 + version "4.18.2"
582 + resolved "https://registry.yarnpkg.com/eslint/-/eslint-4.18.2.tgz#0f81267ad1012e7d2051e186a9004cc2267b8d45"
583 + dependencies:
584 + ajv "^5.3.0"
585 + babel-code-frame "^6.22.0"
586 + chalk "^2.1.0"
587 + concat-stream "^1.6.0"
588 + cross-spawn "^5.1.0"
589 + debug "^3.1.0"
590 + doctrine "^2.1.0"
591 + eslint-scope "^3.7.1"
592 + eslint-visitor-keys "^1.0.0"
593 + espree "^3.5.2"
594 + esquery "^1.0.0"
595 + esutils "^2.0.2"
596 + file-entry-cache "^2.0.0"
597 + functional-red-black-tree "^1.0.1"
598 + glob "^7.1.2"
599 + globals "^11.0.1"
600 + ignore "^3.3.3"
601 + imurmurhash "^0.1.4"
602 + inquirer "^3.0.6"
603 + is-resolvable "^1.0.0"
604 + js-yaml "^3.9.1"
605 + json-stable-stringify-without-jsonify "^1.0.1"
606 + levn "^0.3.0"
607 + lodash "^4.17.4"
608 + minimatch "^3.0.2"
609 + mkdirp "^0.5.1"
610 + natural-compare "^1.4.0"
611 + optionator "^0.8.2"
612 + path-is-inside "^1.0.2"
613 + pluralize "^7.0.0"
614 + progress "^2.0.0"
615 + require-uncached "^1.0.3"
616 + semver "^5.3.0"
617 + strip-ansi "^4.0.0"
618 + strip-json-comments "~2.0.1"
619 + table "4.0.2"
620 + text-table "~0.2.0"
621 +
622 +espree@^3.5.2:
623 + version "3.5.4"
624 + resolved "https://registry.yarnpkg.com/espree/-/espree-3.5.4.tgz#b0f447187c8a8bed944b815a660bddf5deb5d1a7"
625 + dependencies:
626 + acorn "^5.5.0"
627 + acorn-jsx "^3.0.0"
628 +
629 +esprima@2.7.x, esprima@^2.7.1:
630 + version "2.7.3"
631 + resolved "https://registry.yarnpkg.com/esprima/-/esprima-2.7.3.tgz#96e3b70d5779f6ad49cd032673d1c312767ba581"
632 +
633 +esprima@^3.1.3:
634 + version "3.1.3"
635 + resolved "https://registry.yarnpkg.com/esprima/-/esprima-3.1.3.tgz#fdca51cee6133895e3c88d535ce49dbff62a4633"
636 +
637 +esprima@^4.0.0:
638 + version "4.0.0"
639 + resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.0.tgz#4499eddcd1110e0b218bacf2fa7f7f59f55ca804"
640 +
641 +esquery@^1.0.0:
642 + version "1.0.1"
643 + resolved "https://registry.yarnpkg.com/esquery/-/esquery-1.0.1.tgz#406c51658b1f5991a5f9b62b1dc25b00e3e5c708"
644 + dependencies:
645 + estraverse "^4.0.0"
646 +
647 +esrecurse@^4.1.0:
648 + version "4.2.1"
649 + resolved "https://registry.yarnpkg.com/esrecurse/-/esrecurse-4.2.1.tgz#007a3b9fdbc2b3bb87e4879ea19c92fdbd3942cf"
650 + dependencies:
651 + estraverse "^4.1.0"
652 +
653 +estraverse@^1.9.1:
654 + version "1.9.3"
655 + resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-1.9.3.tgz#af67f2dc922582415950926091a4005d29c9bb44"
656 +
657 +estraverse@^4.0.0, estraverse@^4.1.0, estraverse@^4.1.1, estraverse@^4.2.0:
658 + version "4.2.0"
659 + resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-4.2.0.tgz#0dee3fed31fcd469618ce7342099fc1afa0bdb13"
660 +
661 +esutils@^2.0.2:
662 + version "2.0.2"
663 + resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.2.tgz#0abf4f1caa5bcb1f7a9d8acc6dea4faaa04bac9b"
664 +
665 +extend@~3.0.1:
666 + version "3.0.1"
667 + resolved "https://registry.yarnpkg.com/extend/-/extend-3.0.1.tgz#a755ea7bc1adfcc5a31ce7e762dbaadc5e636444"
668 +
669 +external-editor@^2.0.4:
670 + version "2.2.0"
671 + resolved "https://registry.yarnpkg.com/external-editor/-/external-editor-2.2.0.tgz#045511cfd8d133f3846673d1047c154e214ad3d5"
672 + dependencies:
673 + chardet "^0.4.0"
674 + iconv-lite "^0.4.17"
675 + tmp "^0.0.33"
676 +
677 +extsprintf@1.3.0:
678 + version "1.3.0"
679 + resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.3.0.tgz#96918440e3041a7a414f8c52e3c574eb3c3e1e05"
680 +
681 +extsprintf@^1.2.0:
682 + version "1.4.0"
683 + resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.4.0.tgz#e2689f8f356fad62cca65a3a91c5df5f9551692f"
684 +
685 +fast-deep-equal@^1.0.0:
686 + version "1.1.0"
687 + resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-1.1.0.tgz#c053477817c86b51daa853c81e059b733d023614"
688 +
689 +fast-json-stable-stringify@^2.0.0:
690 + version "2.0.0"
691 + resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz#d5142c0caee6b1189f87d3a76111064f86c8bbf2"
692 +
693 +fast-levenshtein@~2.0.4:
694 + version "2.0.6"
695 + resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917"
696 +
697 +fbjs@^0.8.16:
698 + version "0.8.16"
699 + resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-0.8.16.tgz#5e67432f550dc41b572bf55847b8aca64e5337db"
700 + dependencies:
701 + core-js "^1.0.0"
702 + isomorphic-fetch "^2.1.1"
703 + loose-envify "^1.0.0"
704 + object-assign "^4.1.0"
705 + promise "^7.1.1"
706 + setimmediate "^1.0.5"
707 + ua-parser-js "^0.7.9"
708 +
709 +figures@^2.0.0:
710 + version "2.0.0"
711 + resolved "https://registry.yarnpkg.com/figures/-/figures-2.0.0.tgz#3ab1a2d2a62c8bfb431a0c94cb797a2fce27c962"
712 + dependencies:
713 + escape-string-regexp "^1.0.5"
714 +
715 +file-entry-cache@^2.0.0:
716 + version "2.0.0"
717 + resolved "https://registry.yarnpkg.com/file-entry-cache/-/file-entry-cache-2.0.0.tgz#c392990c3e684783d838b8c84a45d8a048458361"
718 + dependencies:
719 + flat-cache "^1.2.1"
720 + object-assign "^4.0.1"
721 +
722 +find-root@^1.0.0:
723 + version "1.1.0"
724 + resolved "https://registry.yarnpkg.com/find-root/-/find-root-1.1.0.tgz#abcfc8ba76f708c42a97b3d685b7e9450bfb9ce4"
725 +
726 +find-up@^1.0.0:
727 + version "1.1.2"
728 + resolved "https://registry.yarnpkg.com/find-up/-/find-up-1.1.2.tgz#6b2e9822b1a2ce0a60ab64d610eccad53cb24d0f"
729 + dependencies:
730 + path-exists "^2.0.0"
731 + pinkie-promise "^2.0.0"
732 +
733 +find-up@^2.0.0:
734 + version "2.1.0"
735 + resolved "https://registry.yarnpkg.com/find-up/-/find-up-2.1.0.tgz#45d1b7e506c717ddd482775a2b77920a3c0c57a7"
736 + dependencies:
737 + locate-path "^2.0.0"
738 +
739 +flat-cache@^1.2.1:
740 + version "1.3.0"
741 + resolved "https://registry.yarnpkg.com/flat-cache/-/flat-cache-1.3.0.tgz#d3030b32b38154f4e3b7e9c709f490f7ef97c481"
742 + dependencies:
743 + circular-json "^0.3.1"
744 + del "^2.0.2"
745 + graceful-fs "^4.1.2"
746 + write "^0.2.1"
747 +
748 +foreach@^2.0.5:
749 + version "2.0.5"
750 + resolved "https://registry.yarnpkg.com/foreach/-/foreach-2.0.5.tgz#0bee005018aeb260d0a3af3ae658dd0136ec1b99"
751 +
752 +forever-agent@~0.6.1:
753 + version "0.6.1"
754 + resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91"
755 +
756 +form-data@~2.3.1:
757 + version "2.3.2"
758 + resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.3.2.tgz#4970498be604c20c005d4f5c23aecd21d6b49099"
759 + dependencies:
760 + asynckit "^0.4.0"
761 + combined-stream "1.0.6"
762 + mime-types "^2.1.12"
763 +
764 +fs.realpath@^1.0.0:
765 + version "1.0.0"
766 + resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
767 +
768 +function-bind@^1.1.1:
769 + version "1.1.1"
770 + resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d"
771 +
772 +functional-red-black-tree@^1.0.1:
773 + version "1.0.1"
774 + resolved "https://registry.yarnpkg.com/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz#1b0ab3bd553b2a0d6399d29c0e3ea0b252078327"
775 +
776 +get-func-name@^2.0.0:
777 + version "2.0.0"
778 + resolved "https://registry.yarnpkg.com/get-func-name/-/get-func-name-2.0.0.tgz#ead774abee72e20409433a066366023dd6887a41"
779 +
780 +get-stdin@^6.0.0:
781 + version "6.0.0"
782 + resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-6.0.0.tgz#9e09bf712b360ab9225e812048f71fde9c89657b"
783 +
784 +getpass@^0.1.1:
785 + version "0.1.7"
786 + resolved "https://registry.yarnpkg.com/getpass/-/getpass-0.1.7.tgz#5eff8e3e684d569ae4cb2b1282604e8ba62149fa"
787 + dependencies:
788 + assert-plus "^1.0.0"
789 +
790 +glob@7.1.2, glob@^7.0.3, glob@^7.0.5, glob@^7.1.2:
791 + version "7.1.2"
792 + resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15"
793 + dependencies:
794 + fs.realpath "^1.0.0"
795 + inflight "^1.0.4"
796 + inherits "2"
797 + minimatch "^3.0.4"
798 + once "^1.3.0"
799 + path-is-absolute "^1.0.0"
800 +
801 +glob@^5.0.15:
802 + version "5.0.15"
803 + resolved "https://registry.yarnpkg.com/glob/-/glob-5.0.15.tgz#1bc936b9e02f4a603fcc222ecf7633d30b8b93b1"
804 + dependencies:
805 + inflight "^1.0.4"
806 + inherits "2"
807 + minimatch "2 || 3"
808 + once "^1.3.0"
809 + path-is-absolute "^1.0.0"
810 +
811 +globals@^11.0.1:
812 + version "11.5.0"
813 + resolved "https://registry.yarnpkg.com/globals/-/globals-11.5.0.tgz#6bc840de6771173b191f13d3a9c94d441ee92642"
814 +
815 +globby@^5.0.0:
816 + version "5.0.0"
817 + resolved "https://registry.yarnpkg.com/globby/-/globby-5.0.0.tgz#ebd84667ca0dbb330b99bcfc68eac2bc54370e0d"
818 + dependencies:
819 + array-union "^1.0.1"
820 + arrify "^1.0.0"
821 + glob "^7.0.3"
822 + object-assign "^4.0.1"
823 + pify "^2.0.0"
824 + pinkie-promise "^2.0.0"
825 +
826 +graceful-fs@^4.1.2:
827 + version "4.1.11"
828 + resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658"
829 +
830 +growl@1.10.5:
831 + version "1.10.5"
832 + resolved "https://registry.yarnpkg.com/growl/-/growl-1.10.5.tgz#f2735dc2283674fa67478b10181059355c369e5e"
833 +
834 +handlebars@^4.0.1:
835 + version "4.0.11"
836 + resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.0.11.tgz#630a35dfe0294bc281edae6ffc5d329fc7982dcc"
837 + dependencies:
838 + async "^1.4.0"
839 + optimist "^0.6.1"
840 + source-map "^0.4.4"
841 + optionalDependencies:
842 + uglify-js "^2.6"
843 +
844 +har-schema@^2.0.0:
845 + version "2.0.0"
846 + resolved "https://registry.yarnpkg.com/har-schema/-/har-schema-2.0.0.tgz#a94c2224ebcac04782a0d9035521f24735b7ec92"
847 +
848 +har-validator@~5.0.3:
849 + version "5.0.3"
850 + resolved "https://registry.yarnpkg.com/har-validator/-/har-validator-5.0.3.tgz#ba402c266194f15956ef15e0fcf242993f6a7dfd"
851 + dependencies:
852 + ajv "^5.1.0"
853 + har-schema "^2.0.0"
854 +
855 +has-ansi@^2.0.0:
856 + version "2.0.0"
857 + resolved "https://registry.yarnpkg.com/has-ansi/-/has-ansi-2.0.0.tgz#34f5049ce1ecdf2b0649af3ef24e45ed35416d91"
858 + dependencies:
859 + ansi-regex "^2.0.0"
860 +
861 +has-flag@^1.0.0:
862 + version "1.0.0"
863 + resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-1.0.0.tgz#9d9e793165ce017a00f00418c43f942a7b1d11fa"
864 +
865 +has-flag@^3.0.0:
866 + version "3.0.0"
867 + resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd"
868 +
869 +has@^1.0.1:
870 + version "1.0.3"
871 + resolved "https://registry.yarnpkg.com/has/-/has-1.0.3.tgz#722d7cbfc1f6aa8241f16dd814e011e1f41e8796"
872 + dependencies:
873 + function-bind "^1.1.1"
874 +
875 +he@1.1.1:
876 + version "1.1.1"
877 + resolved "https://registry.yarnpkg.com/he/-/he-1.1.1.tgz#93410fd21b009735151f8868c2f271f3427e23fd"
878 +
879 +hosted-git-info@^2.1.4:
880 + version "2.6.0"
881 + resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.6.0.tgz#23235b29ab230c576aab0d4f13fc046b0b038222"
882 +
883 +html-encoding-sniffer@^1.0.2:
884 + version "1.0.2"
885 + resolved "https://registry.yarnpkg.com/html-encoding-sniffer/-/html-encoding-sniffer-1.0.2.tgz#e70d84b94da53aa375e11fe3a351be6642ca46f8"
886 + dependencies:
887 + whatwg-encoding "^1.0.1"
888 +
889 +http-signature@~1.2.0:
890 + version "1.2.0"
891 + resolved "https://registry.yarnpkg.com/http-signature/-/http-signature-1.2.0.tgz#9aecd925114772f3d95b65a60abb8f7c18fbace1"
892 + dependencies:
893 + assert-plus "^1.0.0"
894 + jsprim "^1.2.2"
895 + sshpk "^1.7.0"
896 +
897 +iconv-lite@0.4.19:
898 + version "0.4.19"
899 + resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.19.tgz#f7468f60135f5e5dad3399c0a81be9a1603a082b"
900 +
901 +iconv-lite@^0.4.17, iconv-lite@~0.4.13:
902 + version "0.4.23"
903 + resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.23.tgz#297871f63be507adcfbfca715d0cd0eed84e9a63"
904 + dependencies:
905 + safer-buffer ">= 2.1.2 < 3"
906 +
907 +ignore@^3.0.9, ignore@^3.3.3, ignore@^3.3.6:
908 + version "3.3.8"
909 + resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.3.8.tgz#3f8e9c35d38708a3a7e0e9abb6c73e7ee7707b2b"
910 +
911 +imurmurhash@^0.1.4:
912 + version "0.1.4"
913 + resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea"
914 +
915 +inflight@^1.0.4:
916 + version "1.0.6"
917 + resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9"
918 + dependencies:
919 + once "^1.3.0"
920 + wrappy "1"
921 +
922 +inherits@2, inherits@^2.0.3, inherits@~2.0.3:
923 + version "2.0.3"
924 + resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"
925 +
926 +inquirer@^3.0.6:
927 + version "3.3.0"
928 + resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-3.3.0.tgz#9dd2f2ad765dcab1ff0443b491442a20ba227dc9"
929 + dependencies:
930 + ansi-escapes "^3.0.0"
931 + chalk "^2.0.0"
932 + cli-cursor "^2.1.0"
933 + cli-width "^2.0.0"
934 + external-editor "^2.0.4"
935 + figures "^2.0.0"
936 + lodash "^4.3.0"
937 + mute-stream "0.0.7"
938 + run-async "^2.2.0"
939 + rx-lite "^4.0.8"
940 + rx-lite-aggregates "^4.0.8"
941 + string-width "^2.1.0"
942 + strip-ansi "^4.0.0"
943 + through "^2.3.6"
944 +
945 +is-arrayish@^0.2.1:
946 + version "0.2.1"
947 + resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.2.1.tgz#77c99840527aa8ecb1a8ba697b80645a7a926a9d"
948 +
949 +is-buffer@^1.1.5:
950 + version "1.1.6"
951 + resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be"
952 +
953 +is-builtin-module@^1.0.0:
954 + version "1.0.0"
955 + resolved "https://registry.yarnpkg.com/is-builtin-module/-/is-builtin-module-1.0.0.tgz#540572d34f7ac3119f8f76c30cbc1b1e037affbe"
956 + dependencies:
957 + builtin-modules "^1.0.0"
958 +
959 +is-callable@^1.1.1, is-callable@^1.1.3:
960 + version "1.1.3"
961 + resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.1.3.tgz#86eb75392805ddc33af71c92a0eedf74ee7604b2"
962 +
963 +is-date-object@^1.0.1:
964 + version "1.0.1"
965 + resolved "https://registry.yarnpkg.com/is-date-object/-/is-date-object-1.0.1.tgz#9aa20eb6aeebbff77fbd33e74ca01b33581d3a16"
966 +
967 +is-fullwidth-code-point@^2.0.0:
968 + version "2.0.0"
969 + resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz#a3b30a5c4f199183167aaab93beefae3ddfb654f"
970 +
971 +is-path-cwd@^1.0.0:
972 + version "1.0.0"
973 + resolved "https://registry.yarnpkg.com/is-path-cwd/-/is-path-cwd-1.0.0.tgz#d225ec23132e89edd38fda767472e62e65f1106d"
974 +
975 +is-path-in-cwd@^1.0.0:
976 + version "1.0.1"
977 + resolved "https://registry.yarnpkg.com/is-path-in-cwd/-/is-path-in-cwd-1.0.1.tgz#5ac48b345ef675339bd6c7a48a912110b241cf52"
978 + dependencies:
979 + is-path-inside "^1.0.0"
980 +
981 +is-path-inside@^1.0.0:
982 + version "1.0.1"
983 + resolved "https://registry.yarnpkg.com/is-path-inside/-/is-path-inside-1.0.1.tgz#8ef5b7de50437a3fdca6b4e865ef7aa55cb48036"
984 + dependencies:
985 + path-is-inside "^1.0.1"
986 +
987 +is-promise@^2.1.0:
988 + version "2.1.0"
989 + resolved "https://registry.yarnpkg.com/is-promise/-/is-promise-2.1.0.tgz#79a2a9ece7f096e80f36d2b2f3bc16c1ff4bf3fa"
990 +
991 +is-regex@^1.0.4:
992 + version "1.0.4"
993 + resolved "https://registry.yarnpkg.com/is-regex/-/is-regex-1.0.4.tgz#5517489b547091b0930e095654ced25ee97e9491"
994 + dependencies:
995 + has "^1.0.1"
996 +
997 +is-resolvable@^1.0.0:
998 + version "1.1.0"
999 + resolved "https://registry.yarnpkg.com/is-resolvable/-/is-resolvable-1.1.0.tgz#fb18f87ce1feb925169c9a407c19318a3206ed88"
1000 +
1001 +is-stream@^1.0.1:
1002 + version "1.1.0"
1003 + resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44"
1004 +
1005 +is-symbol@^1.0.1:
1006 + version "1.0.1"
1007 + resolved "https://registry.yarnpkg.com/is-symbol/-/is-symbol-1.0.1.tgz#3cc59f00025194b6ab2e38dbae6689256b660572"
1008 +
1009 +is-typedarray@~1.0.0:
1010 + version "1.0.0"
1011 + resolved "https://registry.yarnpkg.com/is-typedarray/-/is-typedarray-1.0.0.tgz#e479c80858df0c1b11ddda6940f96011fcda4a9a"
1012 +
1013 +isarray@^1.0.0, isarray@~1.0.0:
1014 + version "1.0.0"
1015 + resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11"
1016 +
1017 +isexe@^2.0.0:
1018 + version "2.0.0"
1019 + resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
1020 +
1021 +isomorphic-fetch@^2.1.1:
1022 + version "2.2.1"
1023 + resolved "https://registry.yarnpkg.com/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz#611ae1acf14f5e81f729507472819fe9733558a9"
1024 + dependencies:
1025 + node-fetch "^1.0.1"
1026 + whatwg-fetch ">=0.10.0"
1027 +
1028 +isstream@~0.1.2:
1029 + version "0.1.2"
1030 + resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a"
1031 +
1032 +istanbul@0.4.5:
1033 + version "0.4.5"
1034 + resolved "https://registry.yarnpkg.com/istanbul/-/istanbul-0.4.5.tgz#65c7d73d4c4da84d4f3ac310b918fb0b8033733b"
1035 + dependencies:
1036 + abbrev "1.0.x"
1037 + async "1.x"
1038 + escodegen "1.8.x"
1039 + esprima "2.7.x"
1040 + glob "^5.0.15"
1041 + handlebars "^4.0.1"
1042 + js-yaml "3.x"
1043 + mkdirp "0.5.x"
1044 + nopt "3.x"
1045 + once "1.x"
1046 + resolve "1.1.x"
1047 + supports-color "^3.1.0"
1048 + which "^1.1.1"
1049 + wordwrap "^1.0.0"
1050 +
1051 +jquery@3.3.1:
1052 + version "3.3.1"
1053 + resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.3.1.tgz#958ce29e81c9790f31be7792df5d4d95fc57fbca"
1054 +
1055 +js-tokens@^3.0.0, js-tokens@^3.0.2:
1056 + version "3.0.2"
1057 + resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b"
1058 +
1059 +js-yaml@3.x, js-yaml@^3.9.1:
1060 + version "3.12.0"
1061 + resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.12.0.tgz#eaed656ec8344f10f527c6bfa1b6e2244de167d1"
1062 + dependencies:
1063 + argparse "^1.0.7"
1064 + esprima "^4.0.0"
1065 +
1066 +jsbn@~0.1.0:
1067 + version "0.1.1"
1068 + resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.1.tgz#a5e654c2e5a2deb5f201d96cefbca80c0ef2f513"
1069 +
1070 +jsdom@^11.11.0:
1071 + version "11.11.0"
1072 + resolved "https://registry.yarnpkg.com/jsdom/-/jsdom-11.11.0.tgz#df486efad41aee96c59ad7a190e2449c7eb1110e"
1073 + dependencies:
1074 + abab "^1.0.4"
1075 + acorn "^5.3.0"
1076 + acorn-globals "^4.1.0"
1077 + array-equal "^1.0.0"
1078 + cssom ">= 0.3.2 < 0.4.0"
1079 + cssstyle ">= 0.3.1 < 0.4.0"
1080 + data-urls "^1.0.0"
1081 + domexception "^1.0.0"
1082 + escodegen "^1.9.0"
1083 + html-encoding-sniffer "^1.0.2"
1084 + left-pad "^1.2.0"
1085 + nwsapi "^2.0.0"
1086 + parse5 "4.0.0"
1087 + pn "^1.1.0"
1088 + request "^2.83.0"
1089 + request-promise-native "^1.0.5"
1090 + sax "^1.2.4"
1091 + symbol-tree "^3.2.2"
1092 + tough-cookie "^2.3.3"
1093 + w3c-hr-time "^1.0.1"
1094 + webidl-conversions "^4.0.2"
1095 + whatwg-encoding "^1.0.3"
1096 + whatwg-mimetype "^2.1.0"
1097 + whatwg-url "^6.4.1"
1098 + ws "^4.0.0"
1099 + xml-name-validator "^3.0.0"
1100 +
1101 +json-parse-better-errors@^1.0.1:
1102 + version "1.0.2"
1103 + resolved "https://registry.yarnpkg.com/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz#bb867cfb3450e69107c131d1c514bab3dc8bcaa9"
1104 +
1105 +json-schema-traverse@^0.3.0:
1106 + version "0.3.1"
1107 + resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-0.3.1.tgz#349a6d44c53a51de89b40805c5d5e59b417d3340"
1108 +
1109 +json-schema@0.2.3:
1110 + version "0.2.3"
1111 + resolved "https://registry.yarnpkg.com/json-schema/-/json-schema-0.2.3.tgz#b480c892e59a2f05954ce727bd3f2a4e882f9e13"
1112 +
1113 +json-stable-stringify-without-jsonify@^1.0.1:
1114 + version "1.0.1"
1115 + resolved "https://registry.yarnpkg.com/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz#9db7b59496ad3f3cfef30a75142d2d930ad72651"
1116 +
1117 +json-stringify-safe@~5.0.1:
1118 + version "5.0.1"
1119 + resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb"
1120 +
1121 +jsprim@^1.2.2:
1122 + version "1.4.1"
1123 + resolved "https://registry.yarnpkg.com/jsprim/-/jsprim-1.4.1.tgz#313e66bc1e5cc06e438bc1b7499c2e5c56acb6a2"
1124 + dependencies:
1125 + assert-plus "1.0.0"
1126 + extsprintf "1.3.0"
1127 + json-schema "0.2.3"
1128 + verror "1.10.0"
1129 +
1130 +jsx-ast-utils@^2.0.1:
1131 + version "2.0.1"
1132 + resolved "https://registry.yarnpkg.com/jsx-ast-utils/-/jsx-ast-utils-2.0.1.tgz#e801b1b39985e20fffc87b40e3748080e2dcac7f"
1133 + dependencies:
1134 + array-includes "^3.0.3"
1135 +
1136 +kind-of@^3.0.2:
1137 + version "3.2.2"
1138 + resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-3.2.2.tgz#31ea21a734bab9bbb0f32466d893aea51e4a3c64"
1139 + dependencies:
1140 + is-buffer "^1.1.5"
1141 +
1142 +lazy-cache@^1.0.3:
1143 + version "1.0.4"
1144 + resolved "https://registry.yarnpkg.com/lazy-cache/-/lazy-cache-1.0.4.tgz#a1d78fc3a50474cb80845d3b3b6e1da49a446e8e"
1145 +
1146 +left-pad@^1.2.0:
1147 + version "1.3.0"
1148 + resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.3.0.tgz#5b8a3a7765dfe001261dde915589e782f8c94d1e"
1149 +
1150 +levn@^0.3.0, levn@~0.3.0:
1151 + version "0.3.0"
1152 + resolved "https://registry.yarnpkg.com/levn/-/levn-0.3.0.tgz#3b09924edf9f083c0490fdd4c0bc4421e04764ee"
1153 + dependencies:
1154 + prelude-ls "~1.1.2"
1155 + type-check "~0.3.2"
1156 +
1157 +load-json-file@^2.0.0:
1158 + version "2.0.0"
1159 + resolved "https://registry.yarnpkg.com/load-json-file/-/load-json-file-2.0.0.tgz#7947e42149af80d696cbf797bcaabcfe1fe29ca8"
1160 + dependencies:
1161 + graceful-fs "^4.1.2"
1162 + parse-json "^2.2.0"
1163 + pify "^2.0.0"
1164 + strip-bom "^3.0.0"
1165 +
1166 +load-json-file@^4.0.0:
1167 + version "4.0.0"
1168 + resolved "https://registry.yarnpkg.com/load-json-file/-/load-json-file-4.0.0.tgz#2f5f45ab91e33216234fd53adab668eb4ec0993b"
1169 + dependencies:
1170 + graceful-fs "^4.1.2"
1171 + parse-json "^4.0.0"
1172 + pify "^3.0.0"
1173 + strip-bom "^3.0.0"
1174 +
1175 +locate-path@^2.0.0:
1176 + version "2.0.0"
1177 + resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-2.0.0.tgz#2b568b265eec944c6d9c0de9c3dbbbca0354cd8e"
1178 + dependencies:
1179 + p-locate "^2.0.0"
1180 + path-exists "^3.0.0"
1181 +
1182 +lodash.sortby@^4.7.0:
1183 + version "4.7.0"
1184 + resolved "https://registry.yarnpkg.com/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438"
1185 +
1186 +lodash@^4.13.1, lodash@^4.17.4, lodash@^4.3.0:
1187 + version "4.17.10"
1188 + resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.10.tgz#1b7793cf7259ea38fb3661d4d38b3260af8ae4e7"
1189 +
1190 +longest@^1.0.1:
1191 + version "1.0.1"
1192 + resolved "https://registry.yarnpkg.com/longest/-/longest-1.0.1.tgz#30a0b2da38f73770e8294a0d22e6625ed77d0097"
1193 +
1194 +loose-envify@^1.0.0, loose-envify@^1.3.1:
1195 + version "1.3.1"
1196 + resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.3.1.tgz#d1a8ad33fa9ce0e713d65fdd0ac8b748d478c848"
1197 + dependencies:
1198 + js-tokens "^3.0.0"
1199 +
1200 +lru-cache@^4.0.1:
1201 + version "4.1.3"
1202 + resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-4.1.3.tgz#a1175cf3496dfc8436c156c334b4955992bce69c"
1203 + dependencies:
1204 + pseudomap "^1.0.2"
1205 + yallist "^2.1.2"
1206 +
1207 +mime-db@~1.33.0:
1208 + version "1.33.0"
1209 + resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.33.0.tgz#a3492050a5cb9b63450541e39d9788d2272783db"
1210 +
1211 +mime-types@^2.1.12, mime-types@~2.1.17:
1212 + version "2.1.18"
1213 + resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.18.tgz#6f323f60a83d11146f831ff11fd66e2fe5503bb8"
1214 + dependencies:
1215 + mime-db "~1.33.0"
1216 +
1217 +mimic-fn@^1.0.0:
1218 + version "1.2.0"
1219 + resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-1.2.0.tgz#820c86a39334640e99516928bd03fca88057d022"
1220 +
1221 +"minimatch@2 || 3", minimatch@3.0.4, minimatch@^3.0.2, minimatch@^3.0.3, minimatch@^3.0.4:
1222 + version "3.0.4"
1223 + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
1224 + dependencies:
1225 + brace-expansion "^1.1.7"
1226 +
1227 +minimist@0.0.8:
1228 + version "0.0.8"
1229 + resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"
1230 +
1231 +minimist@^1.1.0:
1232 + version "1.2.0"
1233 + resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284"
1234 +
1235 +minimist@~0.0.1:
1236 + version "0.0.10"
1237 + resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.10.tgz#de3f98543dbf96082be48ad1a0c7cda836301dcf"
1238 +
1239 +mkdirp@0.5.1, mkdirp@0.5.x, mkdirp@^0.5.1:
1240 + version "0.5.1"
1241 + resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
1242 + dependencies:
1243 + minimist "0.0.8"
1244 +
1245 +mocha-standard@1.0.0:
1246 + version "1.0.0"
1247 + resolved "https://registry.yarnpkg.com/mocha-standard/-/mocha-standard-1.0.0.tgz#12150cfdce405564068bac3f9e66661c3ccd15f8"
1248 +
1249 +mocha@5.2.0:
1250 + version "5.2.0"
1251 + resolved "https://registry.yarnpkg.com/mocha/-/mocha-5.2.0.tgz#6d8ae508f59167f940f2b5b3c4a612ae50c90ae6"
1252 + dependencies:
1253 + browser-stdout "1.3.1"
1254 + commander "2.15.1"
1255 + debug "3.1.0"
1256 + diff "3.5.0"
1257 + escape-string-regexp "1.0.5"
1258 + glob "7.1.2"
1259 + growl "1.10.5"
1260 + he "1.1.1"
1261 + minimatch "3.0.4"
1262 + mkdirp "0.5.1"
1263 + supports-color "5.4.0"
1264 +
1265 +ms@2.0.0:
1266 + version "2.0.0"
1267 + resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
1268 +
1269 +mute-stream@0.0.7:
1270 + version "0.0.7"
1271 + resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.7.tgz#3075ce93bc21b8fab43e1bc4da7e8115ed1e7bab"
1272 +
1273 +natural-compare@^1.4.0:
1274 + version "1.4.0"
1275 + resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"
1276 +
1277 +node-fetch@^1.0.1:
1278 + version "1.7.3"
1279 + resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.7.3.tgz#980f6f72d85211a5347c6b2bc18c5b84c3eb47ef"
1280 + dependencies:
1281 + encoding "^0.1.11"
1282 + is-stream "^1.0.1"
1283 +
1284 +nopt@3.x:
1285 + version "3.0.6"
1286 + resolved "https://registry.yarnpkg.com/nopt/-/nopt-3.0.6.tgz#c6465dbf08abcd4db359317f79ac68a646b28ff9"
1287 + dependencies:
1288 + abbrev "1"
1289 +
1290 +normalize-package-data@^2.3.2:
1291 + version "2.4.0"
1292 + resolved "https://registry.yarnpkg.com/normalize-package-data/-/normalize-package-data-2.4.0.tgz#12f95a307d58352075a04907b84ac8be98ac012f"
1293 + dependencies:
1294 + hosted-git-info "^2.1.4"
1295 + is-builtin-module "^1.0.0"
1296 + semver "2 || 3 || 4 || 5"
1297 + validate-npm-package-license "^3.0.1"
1298 +
1299 +nwsapi@^2.0.0:
1300 + version "2.0.1"
1301 + resolved "https://registry.yarnpkg.com/nwsapi/-/nwsapi-2.0.1.tgz#a50d59a2dcb14b6931401171713ced2d0eb3468f"
1302 +
1303 +oauth-sign@~0.8.2:
1304 + version "0.8.2"
1305 + resolved "https://registry.yarnpkg.com/oauth-sign/-/oauth-sign-0.8.2.tgz#46a6ab7f0aead8deae9ec0565780b7d4efeb9d43"
1306 +
1307 +object-assign@^4.0.1, object-assign@^4.1.0, object-assign@^4.1.1:
1308 + version "4.1.1"
1309 + resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
1310 +
1311 +object-keys@^1.0.8:
1312 + version "1.0.11"
1313 + resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.0.11.tgz#c54601778ad560f1142ce0e01bcca8b56d13426d"
1314 +
1315 +once@1.x, once@^1.3.0:
1316 + version "1.4.0"
1317 + resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1"
1318 + dependencies:
1319 + wrappy "1"
1320 +
1321 +onetime@^2.0.0:
1322 + version "2.0.1"
1323 + resolved "https://registry.yarnpkg.com/onetime/-/onetime-2.0.1.tgz#067428230fd67443b2794b22bba528b6867962d4"
1324 + dependencies:
1325 + mimic-fn "^1.0.0"
1326 +
1327 +optimist@^0.6.1:
1328 + version "0.6.1"
1329 + resolved "https://registry.yarnpkg.com/optimist/-/optimist-0.6.1.tgz#da3ea74686fa21a19a111c326e90eb15a0196686"
1330 + dependencies:
1331 + minimist "~0.0.1"
1332 + wordwrap "~0.0.2"
1333 +
1334 +optionator@^0.8.1, optionator@^0.8.2:
1335 + version "0.8.2"
1336 + resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.8.2.tgz#364c5e409d3f4d6301d6c0b4c05bba50180aeb64"
1337 + dependencies:
1338 + deep-is "~0.1.3"
1339 + fast-levenshtein "~2.0.4"
1340 + levn "~0.3.0"
1341 + prelude-ls "~1.1.2"
1342 + type-check "~0.3.2"
1343 + wordwrap "~1.0.0"
1344 +
1345 +os-tmpdir@~1.0.2:
1346 + version "1.0.2"
1347 + resolved "https://registry.yarnpkg.com/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274"
1348 +
1349 +p-limit@^1.1.0:
1350 + version "1.2.0"
1351 + resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-1.2.0.tgz#0e92b6bedcb59f022c13d0f1949dc82d15909f1c"
1352 + dependencies:
1353 + p-try "^1.0.0"
1354 +
1355 +p-locate@^2.0.0:
1356 + version "2.0.0"
1357 + resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-2.0.0.tgz#20a0103b222a70c8fd39cc2e580680f3dde5ec43"
1358 + dependencies:
1359 + p-limit "^1.1.0"
1360 +
1361 +p-try@^1.0.0:
1362 + version "1.0.0"
1363 + resolved "https://registry.yarnpkg.com/p-try/-/p-try-1.0.0.tgz#cbc79cdbaf8fd4228e13f621f2b1a237c1b207b3"
1364 +
1365 +parse-json@^2.2.0:
1366 + version "2.2.0"
1367 + resolved "https://registry.yarnpkg.com/parse-json/-/parse-json-2.2.0.tgz#f480f40434ef80741f8469099f8dea18f55a4dc9"
1368 + dependencies:
1369 + error-ex "^1.2.0"
1370 +
1371 +parse-json@^4.0.0:
1372 + version "4.0.0"
1373 + resolved "https://registry.yarnpkg.com/parse-json/-/parse-json-4.0.0.tgz#be35f5425be1f7f6c747184f98a788cb99477ee0"
1374 + dependencies:
1375 + error-ex "^1.3.1"
1376 + json-parse-better-errors "^1.0.1"
1377 +
1378 +parse5@4.0.0:
1379 + version "4.0.0"
1380 + resolved "https://registry.yarnpkg.com/parse5/-/parse5-4.0.0.tgz#6d78656e3da8d78b4ec0b906f7c08ef1dfe3f608"
1381 +
1382 +path-exists@^2.0.0:
1383 + version "2.1.0"
1384 + resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-2.1.0.tgz#0feb6c64f0fc518d9a754dd5efb62c7022761f4b"
1385 + dependencies:
1386 + pinkie-promise "^2.0.0"
1387 +
1388 +path-exists@^3.0.0:
1389 + version "3.0.0"
1390 + resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-3.0.0.tgz#ce0ebeaa5f78cb18925ea7d810d7b59b010fd515"
1391 +
1392 +path-is-absolute@^1.0.0:
1393 + version "1.0.1"
1394 + resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f"
1395 +
1396 +path-is-inside@^1.0.1, path-is-inside@^1.0.2:
1397 + version "1.0.2"
1398 + resolved "https://registry.yarnpkg.com/path-is-inside/-/path-is-inside-1.0.2.tgz#365417dede44430d1c11af61027facf074bdfc53"
1399 +
1400 +path-parse@^1.0.5:
1401 + version "1.0.5"
1402 + resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.5.tgz#3c1adf871ea9cd6c9431b6ea2bd74a0ff055c4c1"
1403 +
1404 +path-type@^2.0.0:
1405 + version "2.0.0"
1406 + resolved "https://registry.yarnpkg.com/path-type/-/path-type-2.0.0.tgz#f012ccb8415b7096fc2daa1054c3d72389594c73"
1407 + dependencies:
1408 + pify "^2.0.0"
1409 +
1410 +pathval@^1.0.0:
1411 + version "1.1.0"
1412 + resolved "https://registry.yarnpkg.com/pathval/-/pathval-1.1.0.tgz#b942e6d4bde653005ef6b71361def8727d0645e0"
1413 +
1414 +performance-now@^2.1.0:
1415 + version "2.1.0"
1416 + resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"
1417 +
1418 +pify@^2.0.0:
1419 + version "2.3.0"
1420 + resolved "https://registry.yarnpkg.com/pify/-/pify-2.3.0.tgz#ed141a6ac043a849ea588498e7dca8b15330e90c"
1421 +
1422 +pify@^3.0.0:
1423 + version "3.0.0"
1424 + resolved "https://registry.yarnpkg.com/pify/-/pify-3.0.0.tgz#e5a4acd2c101fdf3d9a4d07f0dbc4db49dd28176"
1425 +
1426 +pinkie-promise@^2.0.0:
1427 + version "2.0.1"
1428 + resolved "https://registry.yarnpkg.com/pinkie-promise/-/pinkie-promise-2.0.1.tgz#2135d6dfa7a358c069ac9b178776288228450ffa"
1429 + dependencies:
1430 + pinkie "^2.0.0"
1431 +
1432 +pinkie@^2.0.0:
1433 + version "2.0.4"
1434 + resolved "https://registry.yarnpkg.com/pinkie/-/pinkie-2.0.4.tgz#72556b80cfa0d48a974e80e77248e80ed4f7f870"
1435 +
1436 +pkg-conf@^2.0.0:
1437 + version "2.1.0"
1438 + resolved "https://registry.yarnpkg.com/pkg-conf/-/pkg-conf-2.1.0.tgz#2126514ca6f2abfebd168596df18ba57867f0058"
1439 + dependencies:
1440 + find-up "^2.0.0"
1441 + load-json-file "^4.0.0"
1442 +
1443 +pkg-config@^1.1.0:
1444 + version "1.1.1"
1445 + resolved "https://registry.yarnpkg.com/pkg-config/-/pkg-config-1.1.1.tgz#557ef22d73da3c8837107766c52eadabde298fe4"
1446 + dependencies:
1447 + debug-log "^1.0.0"
1448 + find-root "^1.0.0"
1449 + xtend "^4.0.1"
1450 +
1451 +pkg-dir@^1.0.0:
1452 + version "1.0.0"
1453 + resolved "https://registry.yarnpkg.com/pkg-dir/-/pkg-dir-1.0.0.tgz#7a4b508a8d5bb2d629d447056ff4e9c9314cf3d4"
1454 + dependencies:
1455 + find-up "^1.0.0"
1456 +
1457 +pluralize@^7.0.0:
1458 + version "7.0.0"
1459 + resolved "https://registry.yarnpkg.com/pluralize/-/pluralize-7.0.0.tgz#298b89df8b93b0221dbf421ad2b1b1ea23fc6777"
1460 +
1461 +pn@^1.1.0:
1462 + version "1.1.0"
1463 + resolved "https://registry.yarnpkg.com/pn/-/pn-1.1.0.tgz#e2f4cef0e219f463c179ab37463e4e1ecdccbafb"
1464 +
1465 +prelude-ls@~1.1.2:
1466 + version "1.1.2"
1467 + resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
1468 +
1469 +process-nextick-args@~2.0.0:
1470 + version "2.0.0"
1471 + resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.0.tgz#a37d732f4271b4ab1ad070d35508e8290788ffaa"
1472 +
1473 +progress@^2.0.0:
1474 + version "2.0.0"
1475 + resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.0.tgz#8a1be366bf8fc23db2bd23f10c6fe920b4389d1f"
1476 +
1477 +promise@^7.1.1:
1478 + version "7.3.1"
1479 + resolved "https://registry.yarnpkg.com/promise/-/promise-7.3.1.tgz#064b72602b18f90f29192b8b1bc418ffd1ebd3bf"
1480 + dependencies:
1481 + asap "~2.0.3"
1482 +
1483 +prop-types@^15.6.0:
1484 + version "15.6.1"
1485 + resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.6.1.tgz#36644453564255ddda391191fb3a125cbdf654ca"
1486 + dependencies:
1487 + fbjs "^0.8.16"
1488 + loose-envify "^1.3.1"
1489 + object-assign "^4.1.1"
1490 +
1491 +pseudomap@^1.0.2:
1492 + version "1.0.2"
1493 + resolved "https://registry.yarnpkg.com/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3"
1494 +
1495 +punycode@^1.4.1:
1496 + version "1.4.1"
1497 + resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.4.1.tgz#c0d5a63b2718800ad8e1eb0fa5269c84dd41845e"
1498 +
1499 +punycode@^2.1.0:
1500 + version "2.1.1"
1501 + resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec"
1502 +
1503 +qs@~6.5.1:
1504 + version "6.5.2"
1505 + resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36"
1506 +
1507 +read-pkg-up@^2.0.0:
1508 + version "2.0.0"
1509 + resolved "https://registry.yarnpkg.com/read-pkg-up/-/read-pkg-up-2.0.0.tgz#6b72a8048984e0c41e79510fd5e9fa99b3b549be"
1510 + dependencies:
1511 + find-up "^2.0.0"
1512 + read-pkg "^2.0.0"
1513 +
1514 +read-pkg@^2.0.0:
1515 + version "2.0.0"
1516 + resolved "https://registry.yarnpkg.com/read-pkg/-/read-pkg-2.0.0.tgz#8ef1c0623c6a6db0dc6713c4bfac46332b2368f8"
1517 + dependencies:
1518 + load-json-file "^2.0.0"
1519 + normalize-package-data "^2.3.2"
1520 + path-type "^2.0.0"
1521 +
1522 +readable-stream@^2.2.2:
1523 + version "2.3.6"
1524 + resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.6.tgz#b11c27d88b8ff1fbe070643cf94b0c79ae1b0aaf"
1525 + dependencies:
1526 + core-util-is "~1.0.0"
1527 + inherits "~2.0.3"
1528 + isarray "~1.0.0"
1529 + process-nextick-args "~2.0.0"
1530 + safe-buffer "~5.1.1"
1531 + string_decoder "~1.1.1"
1532 + util-deprecate "~1.0.1"
1533 +
1534 +repeat-string@^1.5.2:
1535 + version "1.6.1"
1536 + resolved "https://registry.yarnpkg.com/repeat-string/-/repeat-string-1.6.1.tgz#8dcae470e1c88abc2d600fff4a776286da75e637"
1537 +
1538 +request-promise-core@1.1.1:
1539 + version "1.1.1"
1540 + resolved "https://registry.yarnpkg.com/request-promise-core/-/request-promise-core-1.1.1.tgz#3eee00b2c5aa83239cfb04c5700da36f81cd08b6"
1541 + dependencies:
1542 + lodash "^4.13.1"
1543 +
1544 +request-promise-native@^1.0.5:
1545 + version "1.0.5"
1546 + resolved "https://registry.yarnpkg.com/request-promise-native/-/request-promise-native-1.0.5.tgz#5281770f68e0c9719e5163fd3fab482215f4fda5"
1547 + dependencies:
1548 + request-promise-core "1.1.1"
1549 + stealthy-require "^1.1.0"
1550 + tough-cookie ">=2.3.3"
1551 +
1552 +request@^2.83.0:
1553 + version "2.87.0"
1554 + resolved "https://registry.yarnpkg.com/request/-/request-2.87.0.tgz#32f00235cd08d482b4d0d68db93a829c0ed5756e"
1555 + dependencies:
1556 + aws-sign2 "~0.7.0"
1557 + aws4 "^1.6.0"
1558 + caseless "~0.12.0"
1559 + combined-stream "~1.0.5"
1560 + extend "~3.0.1"
1561 + forever-agent "~0.6.1"
1562 + form-data "~2.3.1"
1563 + har-validator "~5.0.3"
1564 + http-signature "~1.2.0"
1565 + is-typedarray "~1.0.0"
1566 + isstream "~0.1.2"
1567 + json-stringify-safe "~5.0.1"
1568 + mime-types "~2.1.17"
1569 + oauth-sign "~0.8.2"
1570 + performance-now "^2.1.0"
1571 + qs "~6.5.1"
1572 + safe-buffer "^5.1.1"
1573 + tough-cookie "~2.3.3"
1574 + tunnel-agent "^0.6.0"
1575 + uuid "^3.1.0"
1576 +
1577 +require-uncached@^1.0.3:
1578 + version "1.0.3"
1579 + resolved "https://registry.yarnpkg.com/require-uncached/-/require-uncached-1.0.3.tgz#4e0d56d6c9662fd31e43011c4b95aa49955421d3"
1580 + dependencies:
1581 + caller-path "^0.1.0"
1582 + resolve-from "^1.0.0"
1583 +
1584 +resolve-from@^1.0.0:
1585 + version "1.0.1"
1586 + resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-1.0.1.tgz#26cbfe935d1aeeeabb29bc3fe5aeb01e93d44226"
1587 +
1588 +resolve@1.1.x:
1589 + version "1.1.7"
1590 + resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b"
1591 +
1592 +resolve@^1.3.3, resolve@^1.5.0:
1593 + version "1.7.1"
1594 + resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.7.1.tgz#aadd656374fd298aee895bc026b8297418677fd3"
1595 + dependencies:
1596 + path-parse "^1.0.5"
1597 +
1598 +restore-cursor@^2.0.0:
1599 + version "2.0.0"
1600 + resolved "https://registry.yarnpkg.com/restore-cursor/-/restore-cursor-2.0.0.tgz#9f7ee287f82fd326d4fd162923d62129eee0dfaf"
1601 + dependencies:
1602 + onetime "^2.0.0"
1603 + signal-exit "^3.0.2"
1604 +
1605 +right-align@^0.1.1:
1606 + version "0.1.3"
1607 + resolved "https://registry.yarnpkg.com/right-align/-/right-align-0.1.3.tgz#61339b722fe6a3515689210d24e14c96148613ef"
1608 + dependencies:
1609 + align-text "^0.1.1"
1610 +
1611 +rimraf@^2.2.8:
1612 + version "2.6.2"
1613 + resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.2.tgz#2ed8150d24a16ea8651e6d6ef0f47c4158ce7a36"
1614 + dependencies:
1615 + glob "^7.0.5"
1616 +
1617 +run-async@^2.2.0:
1618 + version "2.3.0"
1619 + resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.3.0.tgz#0371ab4ae0bdd720d4166d7dfda64ff7a445a6c0"
1620 + dependencies:
1621 + is-promise "^2.1.0"
1622 +
1623 +run-parallel@^1.1.2:
1624 + version "1.1.9"
1625 + resolved "https://registry.yarnpkg.com/run-parallel/-/run-parallel-1.1.9.tgz#c9dd3a7cf9f4b2c4b6244e173a6ed866e61dd679"
1626 +
1627 +rx-lite-aggregates@^4.0.8:
1628 + version "4.0.8"
1629 + resolved "https://registry.yarnpkg.com/rx-lite-aggregates/-/rx-lite-aggregates-4.0.8.tgz#753b87a89a11c95467c4ac1626c4efc4e05c67be"
1630 + dependencies:
1631 + rx-lite "*"
1632 +
1633 +rx-lite@*, rx-lite@^4.0.8:
1634 + version "4.0.8"
1635 + resolved "https://registry.yarnpkg.com/rx-lite/-/rx-lite-4.0.8.tgz#0b1e11af8bc44836f04a6407e92da42467b79444"
1636 +
1637 +safe-buffer@^5.0.1, safe-buffer@^5.1.1, safe-buffer@~5.1.0, safe-buffer@~5.1.1:
1638 + version "5.1.2"
1639 + resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d"
1640 +
1641 +"safer-buffer@>= 2.1.2 < 3":
1642 + version "2.1.2"
1643 + resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a"
1644 +
1645 +sax@^1.2.4:
1646 + version "1.2.4"
1647 + resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"
1648 +
1649 +"semver@2 || 3 || 4 || 5", semver@^5.3.0, semver@^5.4.1:
1650 + version "5.5.0"
1651 + resolved "https://registry.yarnpkg.com/semver/-/semver-5.5.0.tgz#dc4bbc7a6ca9d916dee5d43516f0092b58f7b8ab"
1652 +
1653 +setimmediate@^1.0.5:
1654 + version "1.0.5"
1655 + resolved "https://registry.yarnpkg.com/setimmediate/-/setimmediate-1.0.5.tgz#290cbb232e306942d7d7ea9b83732ab7856f8285"
1656 +
1657 +shebang-command@^1.2.0:
1658 + version "1.2.0"
1659 + resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-1.2.0.tgz#44aac65b695b03398968c39f363fee5deafdf1ea"
1660 + dependencies:
1661 + shebang-regex "^1.0.0"
1662 +
1663 +shebang-regex@^1.0.0:
1664 + version "1.0.0"
1665 + resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3"
1666 +
1667 +signal-exit@^3.0.2:
1668 + version "3.0.2"
1669 + resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
1670 +
1671 +slice-ansi@1.0.0:
1672 + version "1.0.0"
1673 + resolved "https://registry.yarnpkg.com/slice-ansi/-/slice-ansi-1.0.0.tgz#044f1a49d8842ff307aad6b505ed178bd950134d"
1674 + dependencies:
1675 + is-fullwidth-code-point "^2.0.0"
1676 +
1677 +source-map@^0.4.4:
1678 + version "0.4.4"
1679 + resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.4.4.tgz#eba4f5da9c0dc999de68032d8b4f76173652036b"
1680 + dependencies:
1681 + amdefine ">=0.0.4"
1682 +
1683 +source-map@~0.2.0:
1684 + version "0.2.0"
1685 + resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.2.0.tgz#dab73fbcfc2ba819b4de03bd6f6eaa48164b3f9d"
1686 + dependencies:
1687 + amdefine ">=0.0.4"
1688 +
1689 +source-map@~0.5.1:
1690 + version "0.5.7"
1691 + resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc"
1692 +
1693 +source-map@~0.6.1:
1694 + version "0.6.1"
1695 + resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
1696 +
1697 +spdx-correct@^3.0.0:
1698 + version "3.0.0"
1699 + resolved "https://registry.yarnpkg.com/spdx-correct/-/spdx-correct-3.0.0.tgz#05a5b4d7153a195bc92c3c425b69f3b2a9524c82"
1700 + dependencies:
1701 + spdx-expression-parse "^3.0.0"
1702 + spdx-license-ids "^3.0.0"
1703 +
1704 +spdx-exceptions@^2.1.0:
1705 + version "2.1.0"
1706 + resolved "https://registry.yarnpkg.com/spdx-exceptions/-/spdx-exceptions-2.1.0.tgz#2c7ae61056c714a5b9b9b2b2af7d311ef5c78fe9"
1707 +
1708 +spdx-expression-parse@^3.0.0:
1709 + version "3.0.0"
1710 + resolved "https://registry.yarnpkg.com/spdx-expression-parse/-/spdx-expression-parse-3.0.0.tgz#99e119b7a5da00e05491c9fa338b7904823b41d0"
1711 + dependencies:
1712 + spdx-exceptions "^2.1.0"
1713 + spdx-license-ids "^3.0.0"
1714 +
1715 +spdx-license-ids@^3.0.0:
1716 + version "3.0.0"
1717 + resolved "https://registry.yarnpkg.com/spdx-license-ids/-/spdx-license-ids-3.0.0.tgz#7a7cd28470cc6d3a1cfe6d66886f6bc430d3ac87"
1718 +
1719 +sprintf-js@~1.0.2:
1720 + version "1.0.3"
1721 + resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c"
1722 +
1723 +sshpk@^1.7.0:
1724 + version "1.14.1"
1725 + resolved "https://registry.yarnpkg.com/sshpk/-/sshpk-1.14.1.tgz#130f5975eddad963f1d56f92b9ac6c51fa9f83eb"
1726 + dependencies:
1727 + asn1 "~0.2.3"
1728 + assert-plus "^1.0.0"
1729 + dashdash "^1.12.0"
1730 + getpass "^0.1.1"
1731 + optionalDependencies:
1732 + bcrypt-pbkdf "^1.0.0"
1733 + ecc-jsbn "~0.1.1"
1734 + jsbn "~0.1.0"
1735 + tweetnacl "~0.14.0"
1736 +
1737 +standard-engine@~8.0.0:
1738 + version "8.0.1"
1739 + resolved "https://registry.yarnpkg.com/standard-engine/-/standard-engine-8.0.1.tgz#0b77be8d7ab963675717dbeac1ef1d6675fb62f0"
1740 + dependencies:
1741 + deglob "^2.1.0"
1742 + get-stdin "^6.0.0"
1743 + minimist "^1.1.0"
1744 + pkg-conf "^2.0.0"
1745 +
1746 +standard@11.0.1:
1747 + version "11.0.1"
1748 + resolved "https://registry.yarnpkg.com/standard/-/standard-11.0.1.tgz#49be40c76f1d564964b22bbf7309929ad0335e29"
1749 + dependencies:
1750 + eslint "~4.18.0"
1751 + eslint-config-standard "11.0.0"
1752 + eslint-config-standard-jsx "5.0.0"
1753 + eslint-plugin-import "~2.9.0"
1754 + eslint-plugin-node "~6.0.0"
1755 + eslint-plugin-promise "~3.7.0"
1756 + eslint-plugin-react "~7.7.0"
1757 + eslint-plugin-standard "~3.0.1"
1758 + standard-engine "~8.0.0"
1759 +
1760 +stealthy-require@^1.1.0:
1761 + version "1.1.1"
1762 + resolved "https://registry.yarnpkg.com/stealthy-require/-/stealthy-require-1.1.1.tgz#35b09875b4ff49f26a777e509b3090a3226bf24b"
1763 +
1764 +string-width@^2.1.0, string-width@^2.1.1:
1765 + version "2.1.1"
1766 + resolved "https://registry.yarnpkg.com/string-width/-/string-width-2.1.1.tgz#ab93f27a8dc13d28cac815c462143a6d9012ae9e"
1767 + dependencies:
1768 + is-fullwidth-code-point "^2.0.0"
1769 + strip-ansi "^4.0.0"
1770 +
1771 +string_decoder@~1.1.1:
1772 + version "1.1.1"
1773 + resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.1.1.tgz#9cf1611ba62685d7030ae9e4ba34149c3af03fc8"
1774 + dependencies:
1775 + safe-buffer "~5.1.0"
1776 +
1777 +strip-ansi@^3.0.0:
1778 + version "3.0.1"
1779 + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-3.0.1.tgz#6a385fb8853d952d5ff05d0e8aaf94278dc63dcf"
1780 + dependencies:
1781 + ansi-regex "^2.0.0"
1782 +
1783 +strip-ansi@^4.0.0:
1784 + version "4.0.0"
1785 + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-4.0.0.tgz#a8479022eb1ac368a871389b635262c505ee368f"
1786 + dependencies:
1787 + ansi-regex "^3.0.0"
1788 +
1789 +strip-bom@^3.0.0:
1790 + version "3.0.0"
1791 + resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3"
1792 +
1793 +strip-json-comments@~2.0.1:
1794 + version "2.0.1"
1795 + resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a"
1796 +
1797 +supports-color@5.4.0, supports-color@^5.3.0:
1798 + version "5.4.0"
1799 + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.4.0.tgz#1c6b337402c2137605efe19f10fec390f6faab54"
1800 + dependencies:
1801 + has-flag "^3.0.0"
1802 +
1803 +supports-color@^2.0.0:
1804 + version "2.0.0"
1805 + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7"
1806 +
1807 +supports-color@^3.1.0:
1808 + version "3.2.3"
1809 + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-3.2.3.tgz#65ac0504b3954171d8a64946b2ae3cbb8a5f54f6"
1810 + dependencies:
1811 + has-flag "^1.0.0"
1812 +
1813 +symbol-tree@^3.2.2:
1814 + version "3.2.2"
1815 + resolved "https://registry.yarnpkg.com/symbol-tree/-/symbol-tree-3.2.2.tgz#ae27db38f660a7ae2e1c3b7d1bc290819b8519e6"
1816 +
1817 +table@4.0.2:
1818 + version "4.0.2"
1819 + resolved "https://registry.yarnpkg.com/table/-/table-4.0.2.tgz#a33447375391e766ad34d3486e6e2aedc84d2e36"
1820 + dependencies:
1821 + ajv "^5.2.3"
1822 + ajv-keywords "^2.1.0"
1823 + chalk "^2.1.0"
1824 + lodash "^4.17.4"
1825 + slice-ansi "1.0.0"
1826 + string-width "^2.1.1"
1827 +
1828 +text-table@~0.2.0:
1829 + version "0.2.0"
1830 + resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4"
1831 +
1832 +through@^2.3.6:
1833 + version "2.3.8"
1834 + resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5"
1835 +
1836 +tmp@^0.0.33:
1837 + version "0.0.33"
1838 + resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9"
1839 + dependencies:
1840 + os-tmpdir "~1.0.2"
1841 +
1842 +tough-cookie@>=2.3.3, tough-cookie@^2.3.3, tough-cookie@~2.3.3:
1843 + version "2.3.4"
1844 + resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.3.4.tgz#ec60cee38ac675063ffc97a5c18970578ee83655"
1845 + dependencies:
1846 + punycode "^1.4.1"
1847 +
1848 +tr46@^1.0.1:
1849 + version "1.0.1"
1850 + resolved "https://registry.yarnpkg.com/tr46/-/tr46-1.0.1.tgz#a8b13fd6bfd2489519674ccde55ba3693b706d09"
1851 + dependencies:
1852 + punycode "^2.1.0"
1853 +
1854 +tunnel-agent@^0.6.0:
1855 + version "0.6.0"
1856 + resolved "https://registry.yarnpkg.com/tunnel-agent/-/tunnel-agent-0.6.0.tgz#27a5dea06b36b04a0a9966774b290868f0fc40fd"
1857 + dependencies:
1858 + safe-buffer "^5.0.1"
1859 +
1860 +tweetnacl@^0.14.3, tweetnacl@~0.14.0:
1861 + version "0.14.5"
1862 + resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-0.14.5.tgz#5ae68177f192d4456269d108afa93ff8743f4f64"
1863 +
1864 +type-check@~0.3.2:
1865 + version "0.3.2"
1866 + resolved "https://registry.yarnpkg.com/type-check/-/type-check-0.3.2.tgz#5884cab512cf1d355e3fb784f30804b2b520db72"
1867 + dependencies:
1868 + prelude-ls "~1.1.2"
1869 +
1870 +type-detect@^4.0.0:
1871 + version "4.0.8"
1872 + resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c"
1873 +
1874 +typedarray@^0.0.6:
1875 + version "0.0.6"
1876 + resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
1877 +
1878 +ua-parser-js@^0.7.9:
1879 + version "0.7.18"
1880 + resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.18.tgz#a7bfd92f56edfb117083b69e31d2aa8882d4b1ed"
1881 +
1882 +uglify-js@^2.6:
1883 + version "2.8.29"
1884 + resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-2.8.29.tgz#29c5733148057bb4e1f75df35b7a9cb72e6a59dd"
1885 + dependencies:
1886 + source-map "~0.5.1"
1887 + yargs "~3.10.0"
1888 + optionalDependencies:
1889 + uglify-to-browserify "~1.0.0"
1890 +
1891 +uglify-to-browserify@~1.0.0:
1892 + version "1.0.2"
1893 + resolved "https://registry.yarnpkg.com/uglify-to-browserify/-/uglify-to-browserify-1.0.2.tgz#6e0924d6bda6b5afe349e39a6d632850a0f882b7"
1894 +
1895 +uniq@^1.0.1:
1896 + version "1.0.1"
1897 + resolved "https://registry.yarnpkg.com/uniq/-/uniq-1.0.1.tgz#b31c5ae8254844a3a8281541ce2b04b865a734ff"
1898 +
1899 +util-deprecate@~1.0.1:
1900 + version "1.0.2"
1901 + resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
1902 +
1903 +uuid@^3.1.0:
1904 + version "3.2.1"
1905 + resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.2.1.tgz#12c528bb9d58d0b9265d9a2f6f0fe8be17ff1f14"
1906 +
1907 +validate-npm-package-license@^3.0.1:
1908 + version "3.0.3"
1909 + resolved "https://registry.yarnpkg.com/validate-npm-package-license/-/validate-npm-package-license-3.0.3.tgz#81643bcbef1bdfecd4623793dc4648948ba98338"
1910 + dependencies:
1911 + spdx-correct "^3.0.0"
1912 + spdx-expression-parse "^3.0.0"
1913 +
1914 +verror@1.10.0:
1915 + version "1.10.0"
1916 + resolved "https://registry.yarnpkg.com/verror/-/verror-1.10.0.tgz#3a105ca17053af55d6e270c1f8288682e18da400"
1917 + dependencies:
1918 + assert-plus "^1.0.0"
1919 + core-util-is "1.0.2"
1920 + extsprintf "^1.2.0"
1921 +
1922 +w3c-hr-time@^1.0.1:
1923 + version "1.0.1"
1924 + resolved "https://registry.yarnpkg.com/w3c-hr-time/-/w3c-hr-time-1.0.1.tgz#82ac2bff63d950ea9e3189a58a65625fedf19045"
1925 + dependencies:
1926 + browser-process-hrtime "^0.1.2"
1927 +
1928 +webidl-conversions@^4.0.2:
1929 + version "4.0.2"
1930 + resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-4.0.2.tgz#a855980b1f0b6b359ba1d5d9fb39ae941faa63ad"
1931 +
1932 +whatwg-encoding@^1.0.1, whatwg-encoding@^1.0.3:
1933 + version "1.0.3"
1934 + resolved "https://registry.yarnpkg.com/whatwg-encoding/-/whatwg-encoding-1.0.3.tgz#57c235bc8657e914d24e1a397d3c82daee0a6ba3"
1935 + dependencies:
1936 + iconv-lite "0.4.19"
1937 +
1938 +whatwg-fetch@>=0.10.0:
1939 + version "2.0.4"
1940 + resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-2.0.4.tgz#dde6a5df315f9d39991aa17621853d720b85566f"
1941 +
1942 +whatwg-mimetype@^2.0.0, whatwg-mimetype@^2.1.0:
1943 + version "2.1.0"
1944 + resolved "https://registry.yarnpkg.com/whatwg-mimetype/-/whatwg-mimetype-2.1.0.tgz#f0f21d76cbba72362eb609dbed2a30cd17fcc7d4"
1945 +
1946 +whatwg-url@^6.4.0, whatwg-url@^6.4.1:
1947 + version "6.4.1"
1948 + resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-6.4.1.tgz#fdb94b440fd4ad836202c16e9737d511f012fd67"
1949 + dependencies:
1950 + lodash.sortby "^4.7.0"
1951 + tr46 "^1.0.1"
1952 + webidl-conversions "^4.0.2"
1953 +
1954 +which@^1.1.1, which@^1.2.9:
1955 + version "1.3.1"
1956 + resolved "https://registry.yarnpkg.com/which/-/which-1.3.1.tgz#a45043d54f5805316da8d62f9f50918d3da70b0a"
1957 + dependencies:
1958 + isexe "^2.0.0"
1959 +
1960 +window-size@0.1.0:
1961 + version "0.1.0"
1962 + resolved "https://registry.yarnpkg.com/window-size/-/window-size-0.1.0.tgz#5438cd2ea93b202efa3a19fe8887aee7c94f9c9d"
1963 +
1964 +wordwrap@0.0.2:
1965 + version "0.0.2"
1966 + resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-0.0.2.tgz#b79669bb42ecb409f83d583cad52ca17eaa1643f"
1967 +
1968 +wordwrap@^1.0.0, wordwrap@~1.0.0:
1969 + version "1.0.0"
1970 + resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb"
1971 +
1972 +wordwrap@~0.0.2:
1973 + version "0.0.3"
1974 + resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-0.0.3.tgz#a3d5da6cd5c0bc0008d37234bbaf1bed63059107"
1975 +
1976 +wrappy@1:
1977 + version "1.0.2"
1978 + resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
1979 +
1980 +write@^0.2.1:
1981 + version "0.2.1"
1982 + resolved "https://registry.yarnpkg.com/write/-/write-0.2.1.tgz#5fc03828e264cea3fe91455476f7a3c566cb0757"
1983 + dependencies:
1984 + mkdirp "^0.5.1"
1985 +
1986 +ws@^4.0.0:
1987 + version "4.1.0"
1988 + resolved "https://registry.yarnpkg.com/ws/-/ws-4.1.0.tgz#a979b5d7d4da68bf54efe0408967c324869a7289"
1989 + dependencies:
1990 + async-limiter "~1.0.0"
1991 + safe-buffer "~5.1.0"
1992 +
1993 +xml-name-validator@^3.0.0:
1994 + version "3.0.0"
1995 + resolved "https://registry.yarnpkg.com/xml-name-validator/-/xml-name-validator-3.0.0.tgz#6ae73e06de4d8c6e47f9fb181f78d648ad457c6a"
1996 +
1997 +xtend@^4.0.1:
1998 + version "4.0.1"
1999 + resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.1.tgz#a5c6d532be656e23db820efb943a1f04998d63af"
2000 +
2001 +yallist@^2.1.2:
2002 + version "2.1.2"
2003 + resolved "https://registry.yarnpkg.com/yallist/-/yallist-2.1.2.tgz#1c11f9218f076089a47dd512f93c6699a6a81d52"
2004 +
2005 +yargs@~3.10.0:
2006 + version "3.10.0"
2007 + resolved "https://registry.yarnpkg.com/yargs/-/yargs-3.10.0.tgz#f7ee7bd857dd7c1d2d38c0e74efbd681d1431fd1"
2008 + dependencies:
2009 + camelcase "^1.0.2"
2010 + cliui "^2.1.0"
2011 + decamelize "^1.0.0"
2012 + window-size "0.1.0"
1 +# Changes
2 +
3 +This file is a manually maintained list of changes for each release. Feel free
4 +to add your changes here when sending pull requests. Also send corrections if
5 +you spot any mistakes.
6 +
7 +## v2.18.1 (2020-01-23)
8 +
9 +* Fix Amazon RDS profile for yaSSL MySQL servers with 2019 CA #2292
10 +
11 +## v2.18.0 (2020-01-21)
12 +
13 +* Add `localInfile` option to control `LOAD DATA LOCAL INFILE`
14 +* Add new Amazon RDS Root 2019 CA to Amazon RDS SSL profile #2280
15 +* Add new error codes up to MySQL 5.7.29
16 +* Fix early detection of bad callback to `connection.query`
17 +* Support Node.js 12.x #2211
18 +* Support Node.js 13.x
19 +* Support non-enumerable properties in object argument to `connection.query` #2253
20 +* Update `bignumber.js` to 9.0.0
21 +* Update `readable-stream` to 2.3.7
22 +
23 +## v2.17.1 (2019-04-18)
24 +
25 +* Update `bignumber.js` to 7.2.1 #2206
26 + - Fix npm deprecation warning
27 +
28 +## v2.17.0 (2019-04-17)
29 +
30 +* Add reverse type lookup for small performance gain #2170
31 +* Fix `connection.threadId` missing on handshake failure
32 +* Fix duplicate packet name in debug output
33 +* Fix no password support for old password protocol
34 +* Remove special case for handshake in determine packet code
35 +* Small performance improvement starting command sequence
36 +* Support auth switch in change user flow #1776
37 +* Support Node.js 11.x
38 +* Update `bignumber.js` to 6.0.0
39 +
40 +## v2.16.0 (2018-07-17)
41 +
42 +* Add Amazon RDS GovCloud SSL certificates #1876
43 +* Add new error codes up to MySQL 5.7.21
44 +* Include connection ID in debug output
45 +* Support Node.js 9.x
46 +* Support Node.js 10.x #2003 #2024 #2026 #2034
47 +* Update Amazon RDS SSL certificates
48 +* Update `bignumber.js` to 4.1.0
49 +* Update `readable-stream` to 2.3.6
50 +* Update `sqlstring` to 2.3.1
51 + - Fix incorrectly replacing non-placeholders in SQL
52 +
53 +## v2.15.0 (2017-10-05)
54 +
55 +* Add new Amazon RDS ca-central-1 certificate CA to Amazon RDS SSL profile #1809
56 +* Add new error codes up to MySQL 5.7.19
57 +* Add `mysql.raw()` to generate pre-escaped values #877 #1821
58 +* Fix "changedRows" to work on non-English servers #1819
59 +* Fix error when server sends RST on `QUIT` #1811
60 +* Fix typo in insecure auth error message
61 +* Support `mysql_native_password` auth switch request for Azure #1396 #1729 #1730
62 +* Update `sqlstring` to 2.3.0
63 + - Add `.toSqlString()` escape overriding
64 + - Small performance improvement on `escapeId`
65 +* Update `bignumber.js` to 4.0.4
66 +
67 +## v2.14.1 (2017-08-01)
68 +
69 +* Fix holding first closure for lifetime of connection #1785
70 +
71 +## v2.14.0 (2017-07-25)
72 +
73 +* Add new Amazon RDS ap-south-1 certificate CA to Amazon RDS SSL profile #1780
74 +* Add new Amazon RDS eu-west-2 certificate CA to Amazon RDS SSL profile #1770
75 +* Add `sql` property to query `Error` objects #1462 #1628 #1629
76 +* Add `sqlMessage` property to `Error` objects #1714
77 +* Fix the MySQL 5.7.17 error codes
78 +* Support Node.js 8.x
79 +* Update `bignumber.js` to 4.0.2
80 +* Update `readable-stream` to 2.3.3
81 +* Use `safe-buffer` for improved Buffer API
82 +
83 +## v2.13.0 (2017-01-24)
84 +
85 +* Accept regular expression as pool cluster pattern #1572
86 +* Accept wildcard anywhere in pool cluster pattern #1570
87 +* Add `acquire` and `release` events to `Pool` for tracking #1366 #1449 #1528 #1625
88 +* Add new error codes up to MySQL 5.7.17
89 +* Fix edge cases when determing Query result packets #1547
90 +* Fix memory leak when using long-running domains #1619 #1620
91 +* Remove unnecessary buffer copies when receiving large packets
92 +* Update `bignumber.js` to 3.1.2
93 +* Use a simple buffer list to improve performance #566 #1590
94 +
95 +## v2.12.0 (2016-11-02)
96 +
97 +* Accept array of type names to `dateStrings` option #605 #1481
98 +* Add `query` method to `PoolNamespace` #1256 #1505 #1506
99 + - Used as `cluster.of(...).query(...)`
100 +* Add new error codes up to MySQL 5.7.16
101 +* Fix edge cases writing certain length coded values
102 +* Fix typo in `HANDSHAKE_NO_SSL_SUPPORT` error message #1534
103 +* Support Node.js 7.x
104 +* Update `bignumber.js` to 2.4.0
105 +* Update `sqlstring` to 2.2.0
106 + - Accept numbers and other value types in `escapeId`
107 + - Escape invalid `Date` objects as `NULL`
108 + - Run `buffer.toString()` through escaping
109 +
110 +## v2.11.1 (2016-06-07)
111 +
112 +* Fix writing truncated packets starting with large string/buffer #1438
113 +
114 +## v2.11.0 (2016-06-06)
115 +
116 +* Add `POOL_CLOSED` code to "Pool is closed." error
117 +* Add `POOL_CONNLIMIT` code to "No connections available." error #1332
118 +* Bind underlying connections in pool to same domain as pool #1242
119 +* Bind underlying socket to same domain as connection #1243
120 +* Fix allocation errors receiving many result rows #918 #1265 #1324 #1415
121 +* Fix edge cases constructing long stack traces #1387
122 +* Fix handshake inactivity timeout on Node.js v4.2.0 #1223 #1236 #1239 #1240 #1241 #1252
123 +* Fix Query stream to emit close after ending #1349 #1350
124 +* Fix type cast for BIGINT columns when number is negative #1376
125 +* Performance improvements for array/object escaping in SqlString #1331
126 +* Performance improvements for formatting in SqlString #1431
127 +* Performance improvements for string escaping in SqlString #1390
128 +* Performance improvements for writing packets to network
129 +* Support Node.js 6.x
130 +* Update `bignumber.js` to 2.3.0
131 +* Update `readable-stream` to 1.1.14
132 +* Use the `sqlstring` module for SQL escaping and formatting
133 +
134 +## v2.10.2 (2016-01-12)
135 +
136 +* Fix exception/hang from certain SSL connection errors #1153
137 +* Update `bignumber.js` to 2.1.4
138 +
139 +## v2.10.1 (2016-01-11)
140 +
141 +* Add new Amazon RDS ap-northeast-2 certificate CA to Amazon RDS SSL profile #1329
142 +
143 +## v2.10.0 (2015-12-15)
144 +
145 +* Add new error codes up to MySQL 5.7.9 #1294
146 +* Add new JSON type constant #1295
147 +* Add types for fractional seconds support
148 +* Fix `connection.destroy()` on pool connection creating sequences #1291
149 +* Fix error code 139 `HA_ERR_TO_BIG_ROW` to be `HA_ERR_TOO_BIG_ROW`
150 +* Fix error when call site error is missing stack #1179
151 +* Fix reading password from MySQL URL that has bare colon #1278
152 +* Handle MySQL servers not closing TCP connection after QUIT -> OK exchange #1277
153 +* Minor SqlString Date to string performance improvement #1233
154 +* Support Node.js 4.x
155 +* Support Node.js 5.x
156 +* Update `bignumber.js` to 2.1.2
157 +
158 +## v2.9.0 (2015-08-19)
159 +
160 +* Accept the `ciphers` property in connection `ssl` option #1185
161 +* Fix bad timezone conversion from `Date` to string for certain times #1045 #1155
162 +
163 +## v2.8.0 (2015-07-13)
164 +
165 +* Add `connect` event to `Connection` #1129
166 +* Default `timeout` for `connection.end` to 30 seconds #1057
167 +* Fix a sync callback when sequence enqueue fails #1147
168 +* Provide static require analysis
169 +* Re-use connection from pool after `conn.changeUser` is used #837 #1088
170 +
171 +## v2.7.0 (2015-05-27)
172 +
173 +* Destroy/end connections removed from the pool on error
174 +* Delay implied connect until after `.query` argument validation
175 +* Do not remove connections with non-fatal errors from the pool
176 +* Error early if `callback` argument to `.query` is not a function #1060
177 +* Lazy-load modules from many entry point; reduced memory use
178 +
179 +## v2.6.2 (2015-04-14)
180 +
181 +* Fix `Connection.createQuery` for no SQL #1058
182 +* Update `bignumber.js` to 2.0.7
183 +
184 +## v2.6.1 (2015-03-26)
185 +
186 +* Update `bignumber.js` to 2.0.5 #1037 #1038
187 +
188 +## v2.6.0 (2015-03-24)
189 +
190 +* Add `poolCluster.remove` to remove pools from the cluster #1006 #1007
191 +* Add optional callback to `poolCluster.end`
192 +* Add `restoreNodeTimeout` option to `PoolCluster` #880 #906
193 +* Fix LOAD DATA INFILE handling in multiple statements #1036
194 +* Fix `poolCluster.add` to throw if `PoolCluster` has been closed
195 +* Fix `poolCluster.add` to throw if `id` already defined
196 +* Fix un-catchable error from `PoolCluster` when MySQL server offline #1033
197 +* Improve speed formatting SQL #1019
198 +* Support io.js
199 +
200 +## v2.5.5 (2015-02-23)
201 +
202 +* Store SSL presets in JS instead of JSON #959
203 +* Support Node.js 0.12
204 +* Update Amazon RDS SSL certificates #1001
205 +
206 +## v2.5.4 (2014-12-16)
207 +
208 +* Fix error if falsy error thrown in callback handler #960
209 +* Fix various error code strings #954
210 +
211 +## v2.5.3 (2014-11-06)
212 +
213 +* Fix `pool.query` streaming interface not emitting connection errors #941
214 +
215 +## v2.5.2 (2014-10-10)
216 +
217 +* Fix receiving large text fields #922
218 +
219 +## v2.5.1 (2014-09-22)
220 +
221 +* Fix `pool.end` race conditions #915
222 +* Fix `pool.getConnection` race conditions
223 +
224 +## v2.5.0 (2014-09-07)
225 +
226 +* Add code `POOL_ENQUEUELIMIT` to error reaching `queueLimit`
227 +* Add `enqueue` event to pool #716
228 +* Add `enqueue` event to protocol and connection #381
229 +* Blacklist unsupported connection flags #881
230 +* Make only column names enumerable in `RowDataPacket` #549 #895
231 +* Support Node.js 0.6 #718
232 +
233 +## v2.4.3 (2014-08-25)
234 +
235 +* Fix `pool.query` to use `typeCast` configuration
236 +
237 +## v2.4.2 (2014-08-03)
238 +
239 +* Fix incorrect sequence packet errors to be catchable #867
240 +* Fix stray protocol packet errors to be catchable #867
241 +* Fix timing of fatal protocol errors bubbling to user #879
242 +
243 +## v2.4.1 (2014-07-17)
244 +
245 +* Fix `pool.query` not invoking callback on connection error #872
246 +
247 +## v2.4.0 (2014-07-13)
248 +
249 +* Add code `POOL_NOEXIST` in PoolCluster error #846
250 +* Add `acquireTimeout` pool option to specify a timeout for acquiring a connection #821 #854
251 +* Add `connection.escapeId`
252 +* Add `pool.escapeId`
253 +* Add `timeout` option to all sequences #855 #863
254 +* Default `connectTimeout` to 10 seconds
255 +* Fix domain binding with `conn.connect`
256 +* Fix `packet.default` to actually be a string
257 +* Fix `PARSER_*` errors to be catchable
258 +* Fix `PROTOCOL_PACKETS_OUT_OF_ORDER` error to be catchable #844
259 +* Include packets that failed parsing under `debug`
260 +* Return `Query` object from `pool.query` like `conn.query` #830
261 +* Use `EventEmitter.listenerCount` when possible for faster counting
262 +
263 +## v2.3.2 (2014-05-29)
264 +
265 +* Fix pool leaking connections after `conn.changeUser` #833
266 +
267 +## v2.3.1 (2014-05-26)
268 +
269 +* Add database errors to error constants
270 +* Add global errors to error constants
271 +* Throw when calling `conn.release` multiple times #824 #827
272 +* Update known error codes
273 +
274 +## v2.3.0 (2014-05-16)
275 +
276 +* Accept MySQL charset (like `UTF8` or `UTF8MB4`) in `charset` option #808
277 +* Accept pool options in connection string to `mysql.createPool` #811
278 +* Clone connection config for new pool connections
279 +* Default `connectTimeout` to 2 minutes
280 +* Reject unauthorized SSL connections (use `ssl.rejectUnauthorized` to override) #816
281 +* Return last error when PoolCluster exhausts connection retries #818
282 +* Remove connection from pool after `conn.changeUser` is released #806
283 +* Throw on unknown SSL profile name #817
284 +* User newer TLS functions when available #809
285 +
286 +## v2.2.0 (2014-04-27)
287 +
288 +* Use indexOf instead of for loops removing conn from pool #611
289 +* Make callback to `pool.query` optional like `conn.query` #585
290 +* Prevent enqueuing sequences after fatal error #400
291 +* Fix geometry parser for empty fields #742
292 +* Accept lower-case charset option
293 +* Throw on unknown charset option #789
294 +* Update known charsets
295 +* Remove console.warn from PoolCluster #744
296 +* Fix `pool.end` to handle queued connections #797
297 +* Fix `pool.releaseConnection` to keep connection queue flowing #797
298 +* Fix SSL handshake error to be catchable #800
299 +* Add `connection.threadId` to get MySQL connection ID #602
300 +* Ensure `pool.getConnection` retrieves good connections #434 #557 #778
301 +* Fix pool cluster wildcard matching #627
302 +* Pass query values through to `SqlString.format` #590
303 +
304 +## v2.1.1 (2014-03-13)
305 +
306 +* fix authentication w/password failure for node.js 0.10.5 #746 #752
307 +* fix authentication w/password TypeError exception for node.js 0.10.0-0.10.4 #747
308 +* fix specifying `values` in `conn.query({...}).on(...)` pattern #755
309 +* fix long stack trace to include the `pool.query(...)` call #715
310 +
311 +## v2.1.0 (2014-02-20)
312 +
313 +* crypto.createHash fix for node.js < 11 #735
314 +* Add `connectTimeout` option to specify a timeout for establishing a connection #726
315 +* SSL support #481
316 +
317 +## v2.0.1
318 +
319 +* internal parser speed improvement #702
320 +* domains support
321 +* 'trace' connection option to control if long stack traces are generated #713 #710 #439
322 +
323 +## v2.0.0 (2014-01-09)
324 +
325 +* stream improvements:
326 + - node 0.8 support #692
327 + - Emit 'close' events from query streams #688
328 +* encoding fix in streaming LOAD DATA LOCAL INFILE #670
329 +* Doc improvements
330 +
331 +## v2.0.0-rc2 (2013-12-07)
332 +
333 +* Streaming LOAD DATA LOCAL INFILE #668
334 +* Doc improvements
335 +
336 +## v2.0.0-rc1 (2013-11-30)
337 +
338 +* Transaction support
339 +* Expose SqlString.format as mysql.format()
340 +* Many bug fixes
341 +* Better support for dates in local time zone
342 +* Doc improvements
343 +
344 +## v2.0.0-alpha9 (2013-08-27)
345 +
346 +* Add query to pool to execute queries directly using the pool
347 +* Add `sqlState` property to `Error` objects #556
348 +* Pool option to set queue limit
349 +* Pool sends 'connection' event when it opens a new connection
350 +* Added stringifyObjects option to treat input as strings rather than objects (#501)
351 +* Support for poolClusters
352 +* Datetime improvements
353 +* Bug fixes
354 +
355 +## v2.0.0-alpha8 (2013-04-30)
356 +
357 +* Switch to old mode for Streams 2 (Node.js v 0.10.x)
358 +* Add stream method to Query Wraps events from the query object into a node v0.10.x Readable stream
359 +* DECIMAL should also be treated as big number
360 +* Removed slow unnecessary stack access
361 +* Added charsets
362 +* Added bigNumberStrings option for forcing BIGINT columns as strings
363 +* Changes date parsing to return String if not a valid JS Date
364 +* Adds support for ?? escape sequence to escape identifiers
365 +* Changes Auth.token() to force password to be in binary, not utf8 (#378)
366 +* Restrict debugging by packet types
367 +* Add 'multipleStatements' option tracking to ConnectionConfig. Fixes GH-408
368 +* Changes Pool to handle 'error' events and dispose connection
369 +* Allows db.query({ sql: "..." }, [ val1, ... ], cb); (#390)
370 +* Improved documentation
371 +* Bug fixes
372 +
373 +## v2.0.0-alpha7 (2013-02-03)
374 +
375 +* Add connection pooling (#351)
376 +
377 +## v2.0.0-alpha6 (2013-01-31)
378 +
379 +* Add supportBigNumbers option (#381, #382)
380 +* Accept prebuilt Query object in connection.query
381 +* Bug fixes
382 +
383 +## v2.0.0-alpha5 (2012-12-03)
384 +
385 +* Add mysql.escapeId to escape identifiers (closes #342)
386 +* Allow custom escaping mode (config.queryFormat)
387 +* Convert DATE columns to configured timezone instead of UTC (#332)
388 +* Convert LONGLONG and NEWDECIMAL to numbers (#333)
389 +* Fix Connection.escape() (fixes #330)
390 +* Changed Readme ambiguity about custom type cast fallback
391 +* Change typeCast to receive Connection instead of Connection.config.timezone
392 +* Fix drain event having useless err parameter
393 +* Add Connection.statistics() back from v0.9
394 +* Add Connection.ping() back from v0.9
395 +
396 +## v2.0.0-alpha4 (2012-10-03)
397 +
398 +* Fix some OOB errors on resume()
399 +* Fix quick pause() / resume() usage
400 +* Properly parse host denied / similar errors
401 +* Add Connection.ChangeUser functionality
402 +* Make sure changeUser errors are fatal
403 +* Enable formatting nested arrays for bulk inserts
404 +* Add Connection.escape functionality
405 +* Renamed 'close' to 'end' event
406 +* Return parsed object instead of Buffer for GEOMETRY types
407 +* Allow nestTables inline (using a string instead of a boolean)
408 +* Check for ZEROFILL_FLAG and format number accordingly
409 +* Add timezone support (default: local)
410 +* Add custom typeCast functionality
411 +* Export mysql column types
412 +* Add connection flags functionality (#237)
413 +* Exports drain event when queue finishes processing (#272, #271, #306)
414 +
415 +## v2.0.0-alpha3 (2012-06-12)
416 +
417 +* Implement support for `LOAD DATA LOCAL INFILE` queries (#182).
418 +* Support OLD\_PASSWORD() accounts like 0.9.x did. You should still upgrade any
419 + user accounts in your your MySQL user table that has short (16 byte) Password
420 + values. Connecting to those accounts is not secure. (#204)
421 +* Ignore function values when escaping objects, allows to use RowDataPacket
422 + objects as query arguments. (Alex Gorbatchev, #213)
423 +* Handle initial error packets from server such as `ER_HOST_NOT_PRIVILEGED`.
424 +* Treat `utf8\_bin` as a String, not Buffer. (#214)
425 +* Handle empty strings in first row column value. (#222)
426 +* Honor Connection#nestTables setting for queries. (#221)
427 +* Remove `CLIENT_INTERACTIVE` flag from config. Improves #225.
428 +* Improve docs for connections settings.
429 +* Implement url string support for Connection configs.
430 +
431 +## v2.0.0-alpha2 (2012-05-31)
432 +
433 +* Specify escaping before for NaN / Infinity (they are as unquoted constants).
434 +* Support for unix domain socket connections (use: {socketPath: '...'}).
435 +* Fix type casting for NULL values for Date/Number fields
436 +* Add `fields` argument to `query()` as well as `'fields'` event. This is
437 + similar to what was available in 0.9.x.
438 +* Support connecting to the sphinx searchd daemon as well as MariaDB (#199).
439 +* Implement long stack trace support, will be removed / disabled if the node
440 + core ever supports it natively.
441 +* Implement `nestTables` option for queries, allows fetching JOIN result sets
442 + with overlapping column names.
443 +* Fix ? placeholder mechanism for values containing '?' characters (#205).
444 +* Detect when `connect()` is called more than once on a connection and provide
445 + the user with a good error message for it (#204).
446 +* Switch to `UTF8_GENERAL_CI` (previously `UTF8_UNICODE_CI`) as the default
447 + charset for all connections to avoid strange MySQL performance issues (#200),
448 + and also make the charset user configurable.
449 +* Fix BLOB type casting for `TINY_BLOB`, `MEDIUM_BLOB` and `LONG_BLOB`.
450 +* Add support for sending and receiving large (> 16 MB) packets.
451 +
452 +## v2.0.0-alpha (2012-05-15)
453 +
454 +This release is a rewrite. You should carefully test your application after
455 +upgrading to avoid problems. This release features many improvements, most
456 +importantly:
457 +
458 +* ~5x faster than v0.9.x for parsing query results
459 +* Support for pause() / resume() (for streaming rows)
460 +* Support for multiple statement queries
461 +* Support for stored procedures
462 +* Support for transactions
463 +* Support for binary columns (as blobs)
464 +* Consistent & well documented error handling
465 +* A new Connection class that has well defined semantics (unlike the old Client class).
466 +* Convenient escaping of objects / arrays that allows for simpler query construction
467 +* A significantly simpler code base
468 +* Many bug fixes & other small improvements (Closed 62 out of 66 GitHub issues)
469 +
470 +Below are a few notes on the upgrade process itself:
471 +
472 +The first thing you will run into is that the old `Client` class is gone and
473 +has been replaced with a less ambitious `Connection` class. So instead of
474 +`mysql.createClient()`, you now have to:
475 +
476 +```js
477 +var mysql = require('mysql');
478 +var connection = mysql.createConnection({
479 + host : 'localhost',
480 + user : 'me',
481 + password : 'secret',
482 +});
483 +
484 +connection.query('SELECT 1', function(err, rows) {
485 + if (err) throw err;
486 +
487 + console.log('Query result: ', rows);
488 +});
489 +
490 +connection.end();
491 +```
492 +
493 +The new `Connection` class does not try to handle re-connects, please study the
494 +`Server disconnects` section in the new Readme.
495 +
496 +Other than that, the interface has stayed very similar. Here are a few things
497 +to check out so:
498 +
499 +* BIGINT's are now cast into strings
500 +* Binary data is now cast to buffers
501 +* The `'row'` event on the `Query` object is now called `'result'` and will
502 + also be emitted for queries that produce an OK/Error response.
503 +* Error handling is consistently defined now, check the Readme
504 +* Escaping has become more powerful which may break your code if you are
505 + currently using objects to fill query placeholders.
506 +* Connections can now be established explicitly again, so you may wish to do so
507 + if you want to handle connection errors specifically.
508 +
509 +That should be most of it, if you run into anything else, please send a patch
510 +or open an issue to improve this document.
511 +
512 +## v0.9.6 (2012-03-12)
513 +
514 +* Escape array values so they produce sql arrays (Roger Castells, Colin Smith)
515 +* docs: mention mysql transaction stop gap solution (Blake Miner)
516 +* docs: Mention affectedRows in FAQ (Michael Baldwin)
517 +
518 +## v0.9.5 (2011-11-26)
519 +
520 +* Fix #142 Driver stalls upon reconnect attempt that's immediately closed
521 +* Add travis build
522 +* Switch to urun as a test runner
523 +* Switch to utest for unit tests
524 +* Remove fast-or-slow dependency for tests
525 +* Split integration tests into individual files again
526 +
527 +## v0.9.4 (2011-08-31)
528 +
529 +* Expose package.json as `mysql.PACKAGE` (#104)
530 +
531 +## v0.9.3 (2011-08-22)
532 +
533 +* Set default `client.user` to root
534 +* Fix #91: Client#format should not mutate params array
535 +* Fix #94: TypeError in client.js
536 +* Parse decimals as string (vadimg)
537 +
538 +## v0.9.2 (2011-08-07)
539 +
540 +* The underlaying socket connection is now managed implicitly rather than explicitly.
541 +* Check the [upgrading guide][] for a full list of changes.
542 +
543 +## v0.9.1 (2011-02-20)
544 +
545 +* Fix issue #49 / `client.escape()` throwing exceptions on objects. (Nick Payne)
546 +* Drop < v0.4.x compatibility. From now on you need node v0.4.x to use this module.
547 +
548 +## Older releases
549 +
550 +These releases were done before maintaining this file:
551 +
552 +* [v0.9.0](https://github.com/mysqljs/mysql/compare/v0.8.0...v0.9.0)
553 + (2011-01-04)
554 +* [v0.8.0](https://github.com/mysqljs/mysql/compare/v0.7.0...v0.8.0)
555 + (2010-10-30)
556 +* [v0.7.0](https://github.com/mysqljs/mysql/compare/v0.6.0...v0.7.0)
557 + (2010-10-14)
558 +* [v0.6.0](https://github.com/mysqljs/mysql/compare/v0.5.0...v0.6.0)
559 + (2010-09-28)
560 +* [v0.5.0](https://github.com/mysqljs/mysql/compare/v0.4.0...v0.5.0)
561 + (2010-09-17)
562 +* [v0.4.0](https://github.com/mysqljs/mysql/compare/v0.3.0...v0.4.0)
563 + (2010-09-02)
564 +* [v0.3.0](https://github.com/mysqljs/mysql/compare/v0.2.0...v0.3.0)
565 + (2010-08-25)
566 +* [v0.2.0](https://github.com/mysqljs/mysql/compare/v0.1.0...v0.2.0)
567 + (2010-08-22)
568 +* [v0.1.0](https://github.com/mysqljs/mysql/commits/v0.1.0)
569 + (2010-08-22)
1 +Copyright (c) 2012 Felix Geisendörfer (felix@debuggable.com) and contributors
2 +
3 + Permission is hereby granted, free of charge, to any person obtaining a copy
4 + of this software and associated documentation files (the "Software"), to deal
5 + in the Software without restriction, including without limitation the rights
6 + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 + copies of the Software, and to permit persons to whom the Software is
8 + furnished to do so, subject to the following conditions:
9 +
10 + The above copyright notice and this permission notice shall be included in
11 + all copies or substantial portions of the Software.
12 +
13 + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 + THE SOFTWARE.
1 +# mysql
2 +
3 +[![NPM Version][npm-version-image]][npm-url]
4 +[![NPM Downloads][npm-downloads-image]][npm-url]
5 +[![Node.js Version][node-image]][node-url]
6 +[![Linux Build][travis-image]][travis-url]
7 +[![Windows Build][appveyor-image]][appveyor-url]
8 +[![Test Coverage][coveralls-image]][coveralls-url]
9 +
10 +## Table of Contents
11 +
12 +- [Install](#install)
13 +- [Introduction](#introduction)
14 +- [Contributors](#contributors)
15 +- [Sponsors](#sponsors)
16 +- [Community](#community)
17 +- [Establishing connections](#establishing-connections)
18 +- [Connection options](#connection-options)
19 + - [SSL options](#ssl-options)
20 + - [Connection flags](#connection-flags)
21 +- [Terminating connections](#terminating-connections)
22 +- [Pooling connections](#pooling-connections)
23 +- [Pool options](#pool-options)
24 +- [Pool events](#pool-events)
25 + - [acquire](#acquire)
26 + - [connection](#connection)
27 + - [enqueue](#enqueue)
28 + - [release](#release)
29 +- [Closing all the connections in a pool](#closing-all-the-connections-in-a-pool)
30 +- [PoolCluster](#poolcluster)
31 + - [PoolCluster options](#poolcluster-options)
32 +- [Switching users and altering connection state](#switching-users-and-altering-connection-state)
33 +- [Server disconnects](#server-disconnects)
34 +- [Performing queries](#performing-queries)
35 +- [Escaping query values](#escaping-query-values)
36 +- [Escaping query identifiers](#escaping-query-identifiers)
37 + - [Preparing Queries](#preparing-queries)
38 + - [Custom format](#custom-format)
39 +- [Getting the id of an inserted row](#getting-the-id-of-an-inserted-row)
40 +- [Getting the number of affected rows](#getting-the-number-of-affected-rows)
41 +- [Getting the number of changed rows](#getting-the-number-of-changed-rows)
42 +- [Getting the connection ID](#getting-the-connection-id)
43 +- [Executing queries in parallel](#executing-queries-in-parallel)
44 +- [Streaming query rows](#streaming-query-rows)
45 + - [Piping results with Streams](#piping-results-with-streams)
46 +- [Multiple statement queries](#multiple-statement-queries)
47 +- [Stored procedures](#stored-procedures)
48 +- [Joins with overlapping column names](#joins-with-overlapping-column-names)
49 +- [Transactions](#transactions)
50 +- [Ping](#ping)
51 +- [Timeouts](#timeouts)
52 +- [Error handling](#error-handling)
53 +- [Exception Safety](#exception-safety)
54 +- [Type casting](#type-casting)
55 + - [Number](#number)
56 + - [Date](#date)
57 + - [Buffer](#buffer)
58 + - [String](#string)
59 + - [Custom type casting](#custom-type-casting)
60 +- [Debugging and reporting problems](#debugging-and-reporting-problems)
61 +- [Security issues](#security-issues)
62 +- [Contributing](#contributing)
63 +- [Running tests](#running-tests)
64 + - [Running unit tests](#running-unit-tests)
65 + - [Running integration tests](#running-integration-tests)
66 +- [Todo](#todo)
67 +
68 +## Install
69 +
70 +This is a [Node.js](https://nodejs.org/en/) module available through the
71 +[npm registry](https://www.npmjs.com/).
72 +
73 +Before installing, [download and install Node.js](https://nodejs.org/en/download/).
74 +Node.js 0.6 or higher is required.
75 +
76 +Installation is done using the
77 +[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):
78 +
79 +```sh
80 +$ npm install mysql
81 +```
82 +
83 +For information about the previous 0.9.x releases, visit the [v0.9 branch][].
84 +
85 +Sometimes I may also ask you to install the latest version from Github to check
86 +if a bugfix is working. In this case, please do:
87 +
88 +```sh
89 +$ npm install mysqljs/mysql
90 +```
91 +
92 +[v0.9 branch]: https://github.com/mysqljs/mysql/tree/v0.9
93 +
94 +## Introduction
95 +
96 +This is a node.js driver for mysql. It is written in JavaScript, does not
97 +require compiling, and is 100% MIT licensed.
98 +
99 +Here is an example on how to use it:
100 +
101 +```js
102 +var mysql = require('mysql');
103 +var connection = mysql.createConnection({
104 + host : 'localhost',
105 + user : 'me',
106 + password : 'secret',
107 + database : 'my_db'
108 +});
109 +
110 +connection.connect();
111 +
112 +connection.query('SELECT 1 + 1 AS solution', function (error, results, fields) {
113 + if (error) throw error;
114 + console.log('The solution is: ', results[0].solution);
115 +});
116 +
117 +connection.end();
118 +```
119 +
120 +From this example, you can learn the following:
121 +
122 +* Every method you invoke on a connection is queued and executed in sequence.
123 +* Closing the connection is done using `end()` which makes sure all remaining
124 + queries are executed before sending a quit packet to the mysql server.
125 +
126 +## Contributors
127 +
128 +Thanks goes to the people who have contributed code to this module, see the
129 +[GitHub Contributors page][].
130 +
131 +[GitHub Contributors page]: https://github.com/mysqljs/mysql/graphs/contributors
132 +
133 +Additionally I'd like to thank the following people:
134 +
135 +* [Andrey Hristov][] (Oracle) - for helping me with protocol questions.
136 +* [Ulf Wendel][] (Oracle) - for helping me with protocol questions.
137 +
138 +[Ulf Wendel]: http://blog.ulf-wendel.de/
139 +[Andrey Hristov]: http://andrey.hristov.com/
140 +
141 +## Sponsors
142 +
143 +The following companies have supported this project financially, allowing me to
144 +spend more time on it (ordered by time of contribution):
145 +
146 +* [Transloadit](http://transloadit.com) (my startup, we do file uploading &
147 + video encoding as a service, check it out)
148 +* [Joyent](http://www.joyent.com/)
149 +* [pinkbike.com](http://pinkbike.com/)
150 +* [Holiday Extras](http://www.holidayextras.co.uk/) (they are [hiring](http://join.holidayextras.co.uk/))
151 +* [Newscope](http://newscope.com/) (they are [hiring](https://newscope.com/unternehmen/jobs/))
152 +
153 +## Community
154 +
155 +If you'd like to discuss this module, or ask questions about it, please use one
156 +of the following:
157 +
158 +* **Mailing list**: https://groups.google.com/forum/#!forum/node-mysql
159 +* **IRC Channel**: #node.js (on freenode.net, I pay attention to any message
160 + including the term `mysql`)
161 +
162 +## Establishing connections
163 +
164 +The recommended way to establish a connection is this:
165 +
166 +```js
167 +var mysql = require('mysql');
168 +var connection = mysql.createConnection({
169 + host : 'example.org',
170 + user : 'bob',
171 + password : 'secret'
172 +});
173 +
174 +connection.connect(function(err) {
175 + if (err) {
176 + console.error('error connecting: ' + err.stack);
177 + return;
178 + }
179 +
180 + console.log('connected as id ' + connection.threadId);
181 +});
182 +```
183 +
184 +However, a connection can also be implicitly established by invoking a query:
185 +
186 +```js
187 +var mysql = require('mysql');
188 +var connection = mysql.createConnection(...);
189 +
190 +connection.query('SELECT 1', function (error, results, fields) {
191 + if (error) throw error;
192 + // connected!
193 +});
194 +```
195 +
196 +Depending on how you like to handle your errors, either method may be
197 +appropriate. Any type of connection error (handshake or network) is considered
198 +a fatal error, see the [Error Handling](#error-handling) section for more
199 +information.
200 +
201 +## Connection options
202 +
203 +When establishing a connection, you can set the following options:
204 +
205 +* `host`: The hostname of the database you are connecting to. (Default:
206 + `localhost`)
207 +* `port`: The port number to connect to. (Default: `3306`)
208 +* `localAddress`: The source IP address to use for TCP connection. (Optional)
209 +* `socketPath`: The path to a unix domain socket to connect to. When used `host`
210 + and `port` are ignored.
211 +* `user`: The MySQL user to authenticate as.
212 +* `password`: The password of that MySQL user.
213 +* `database`: Name of the database to use for this connection (Optional).
214 +* `charset`: The charset for the connection. This is called "collation" in the SQL-level
215 + of MySQL (like `utf8_general_ci`). If a SQL-level charset is specified (like `utf8mb4`)
216 + then the default collation for that charset is used. (Default: `'UTF8_GENERAL_CI'`)
217 +* `timezone`: The timezone configured on the MySQL server. This is used to type cast server date/time values to JavaScript `Date` object and vice versa. This can be `'local'`, `'Z'`, or an offset in the form `+HH:MM` or `-HH:MM`. (Default: `'local'`)
218 +* `connectTimeout`: The milliseconds before a timeout occurs during the initial connection
219 + to the MySQL server. (Default: `10000`)
220 +* `stringifyObjects`: Stringify objects instead of converting to values. See
221 +issue [#501](https://github.com/mysqljs/mysql/issues/501). (Default: `false`)
222 +* `insecureAuth`: Allow connecting to MySQL instances that ask for the old
223 + (insecure) authentication method. (Default: `false`)
224 +* `typeCast`: Determines if column values should be converted to native
225 + JavaScript types. (Default: `true`)
226 +* `queryFormat`: A custom query format function. See [Custom format](#custom-format).
227 +* `supportBigNumbers`: When dealing with big numbers (BIGINT and DECIMAL columns) in the database,
228 + you should enable this option (Default: `false`).
229 +* `bigNumberStrings`: Enabling both `supportBigNumbers` and `bigNumberStrings` forces big numbers
230 + (BIGINT and DECIMAL columns) to be always returned as JavaScript String objects (Default: `false`).
231 + Enabling `supportBigNumbers` but leaving `bigNumberStrings` disabled will return big numbers as String
232 + objects only when they cannot be accurately represented with [JavaScript Number objects] (http://ecma262-5.com/ELS5_HTML.htm#Section_8.5)
233 + (which happens when they exceed the [-2^53, +2^53] range), otherwise they will be returned as
234 + Number objects. This option is ignored if `supportBigNumbers` is disabled.
235 +* `dateStrings`: Force date types (TIMESTAMP, DATETIME, DATE) to be returned as strings rather than
236 + inflated into JavaScript Date objects. Can be `true`/`false` or an array of type names to keep as
237 + strings. (Default: `false`)
238 +* `debug`: Prints protocol details to stdout. Can be `true`/`false` or an array of packet type names
239 + that should be printed. (Default: `false`)
240 +* `trace`: Generates stack traces on `Error` to include call site of library
241 + entrance ("long stack traces"). Slight performance penalty for most calls.
242 + (Default: `true`)
243 +* `localInfile`: Allow `LOAD DATA INFILE` to use the `LOCAL` modifier. (Default: `true`)
244 +* `multipleStatements`: Allow multiple mysql statements per query. Be careful
245 + with this, it could increase the scope of SQL injection attacks. (Default: `false`)
246 +* `flags`: List of connection flags to use other than the default ones. It is
247 + also possible to blacklist default ones. For more information, check
248 + [Connection Flags](#connection-flags).
249 +* `ssl`: object with ssl parameters or a string containing name of ssl profile. See [SSL options](#ssl-options).
250 +
251 +
252 +In addition to passing these options as an object, you can also use a url
253 +string. For example:
254 +
255 +```js
256 +var connection = mysql.createConnection('mysql://user:pass@host/db?debug=true&charset=BIG5_CHINESE_CI&timezone=-0700');
257 +```
258 +
259 +Note: The query values are first attempted to be parsed as JSON, and if that
260 +fails assumed to be plaintext strings.
261 +
262 +### SSL options
263 +
264 +The `ssl` option in the connection options takes a string or an object. When given a string,
265 +it uses one of the predefined SSL profiles included. The following profiles are included:
266 +
267 +* `"Amazon RDS"`: this profile is for connecting to an Amazon RDS server and contains the
268 + certificates from https://rds.amazonaws.com/doc/rds-ssl-ca-cert.pem and
269 + https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem
270 +
271 +When connecting to other servers, you will need to provide an object of options, in the
272 +same format as [tls.createSecureContext](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options).
273 +Please note the arguments expect a string of the certificate, not a file name to the
274 +certificate. Here is a simple example:
275 +
276 +```js
277 +var connection = mysql.createConnection({
278 + host : 'localhost',
279 + ssl : {
280 + ca : fs.readFileSync(__dirname + '/mysql-ca.crt')
281 + }
282 +});
283 +```
284 +
285 +You can also connect to a MySQL server without properly providing the appropriate
286 +CA to trust. _You should not do this_.
287 +
288 +```js
289 +var connection = mysql.createConnection({
290 + host : 'localhost',
291 + ssl : {
292 + // DO NOT DO THIS
293 + // set up your ca correctly to trust the connection
294 + rejectUnauthorized: false
295 + }
296 +});
297 +```
298 +
299 +### Connection flags
300 +
301 +If, for any reason, you would like to change the default connection flags, you
302 +can use the connection option `flags`. Pass a string with a comma separated list
303 +of items to add to the default flags. If you don't want a default flag to be used
304 +prepend the flag with a minus sign. To add a flag that is not in the default list,
305 +just write the flag name, or prefix it with a plus (case insensitive).
306 +
307 +```js
308 +var connection = mysql.createConnection({
309 + // disable FOUND_ROWS flag, enable IGNORE_SPACE flag
310 + flags: '-FOUND_ROWS,IGNORE_SPACE'
311 +});
312 +```
313 +
314 +The following flags are available:
315 +
316 +- `COMPRESS` - Enable protocol compression. This feature is not currently supported
317 + by the Node.js implementation so cannot be turned on. (Default off)
318 +- `CONNECT_WITH_DB` - Ability to specify the database on connection. (Default on)
319 +- `FOUND_ROWS` - Send the found rows instead of the affected rows as `affectedRows`.
320 + (Default on)
321 +- `IGNORE_SIGPIPE` - Don't issue SIGPIPE if network failures. This flag has no effect
322 + on this Node.js implementation. (Default on)
323 +- `IGNORE_SPACE` - Let the parser ignore spaces before the `(` in queries. (Default on)
324 +- `INTERACTIVE` - Indicates to the MySQL server this is an "interactive" client. This
325 + will use the interactive timeouts on the MySQL server and report as interactive in
326 + the process list. (Default off)
327 +- `LOCAL_FILES` - Can use `LOAD DATA LOCAL`. This flag is controlled by the connection
328 + option `localInfile`. (Default on)
329 +- `LONG_FLAG` - Longer flags in Protocol::ColumnDefinition320. (Default on)
330 +- `LONG_PASSWORD` - Use the improved version of Old Password Authentication.
331 + (Default on)
332 +- `MULTI_RESULTS` - Can handle multiple resultsets for queries. (Default on)
333 +- `MULTI_STATEMENTS` - The client may send multiple statement per query or
334 + statement prepare (separated by `;`). This flag is controlled by the connection
335 + option `multipleStatements`. (Default off)
336 +- `NO_SCHEMA`
337 +- `ODBC` Special handling of ODBC behaviour. This flag has no effect on this Node.js
338 + implementation. (Default on)
339 +- `PLUGIN_AUTH` - Uses the plugin authentication mechanism when connecting to the
340 + MySQL server. This feature is not currently supported by the Node.js implementation
341 + so cannot be turned on. (Default off)
342 +- `PROTOCOL_41` - Uses the 4.1 protocol. (Default on)
343 +- `PS_MULTI_RESULTS` - Can handle multiple resultsets for execute. (Default on)
344 +- `REMEMBER_OPTIONS` - This is specific to the C client, and has no effect on this
345 + Node.js implementation. (Default off)
346 +- `RESERVED` - Old flag for the 4.1 protocol. (Default on)
347 +- `SECURE_CONNECTION` - Support native 4.1 authentication. (Default on)
348 +- `SSL` - Use SSL after handshake to encrypt data in transport. This feature is
349 + controlled though the `ssl` connection option, so the flag has no effect.
350 + (Default off)
351 +- `SSL_VERIFY_SERVER_CERT` - Verify the server certificate during SSL set up. This
352 + feature is controlled though the `ssl.rejectUnauthorized` connection option, so
353 + the flag has no effect. (Default off)
354 +- `TRANSACTIONS` - Asks for the transaction status flags. (Default on)
355 +
356 +## Terminating connections
357 +
358 +There are two ways to end a connection. Terminating a connection gracefully is
359 +done by calling the `end()` method:
360 +
361 +```js
362 +connection.end(function(err) {
363 + // The connection is terminated now
364 +});
365 +```
366 +
367 +This will make sure all previously enqueued queries are still before sending a
368 +`COM_QUIT` packet to the MySQL server. If a fatal error occurs before the
369 +`COM_QUIT` packet can be sent, an `err` argument will be provided to the
370 +callback, but the connection will be terminated regardless of that.
371 +
372 +An alternative way to end the connection is to call the `destroy()` method.
373 +This will cause an immediate termination of the underlying socket.
374 +Additionally `destroy()` guarantees that no more events or callbacks will be
375 +triggered for the connection.
376 +
377 +```js
378 +connection.destroy();
379 +```
380 +
381 +Unlike `end()` the `destroy()` method does not take a callback argument.
382 +
383 +## Pooling connections
384 +
385 +Rather than creating and managing connections one-by-one, this module also
386 +provides built-in connection pooling using `mysql.createPool(config)`.
387 +[Read more about connection pooling](https://en.wikipedia.org/wiki/Connection_pool).
388 +
389 +Create a pool and use it directly:
390 +
391 +```js
392 +var mysql = require('mysql');
393 +var pool = mysql.createPool({
394 + connectionLimit : 10,
395 + host : 'example.org',
396 + user : 'bob',
397 + password : 'secret',
398 + database : 'my_db'
399 +});
400 +
401 +pool.query('SELECT 1 + 1 AS solution', function (error, results, fields) {
402 + if (error) throw error;
403 + console.log('The solution is: ', results[0].solution);
404 +});
405 +```
406 +
407 +This is a shortcut for the `pool.getConnection()` -> `connection.query()` ->
408 +`connection.release()` code flow. Using `pool.getConnection()` is useful to
409 +share connection state for subsequent queries. This is because two calls to
410 +`pool.query()` may use two different connections and run in parallel. This is
411 +the basic structure:
412 +
413 +```js
414 +var mysql = require('mysql');
415 +var pool = mysql.createPool(...);
416 +
417 +pool.getConnection(function(err, connection) {
418 + if (err) throw err; // not connected!
419 +
420 + // Use the connection
421 + connection.query('SELECT something FROM sometable', function (error, results, fields) {
422 + // When done with the connection, release it.
423 + connection.release();
424 +
425 + // Handle error after the release.
426 + if (error) throw error;
427 +
428 + // Don't use the connection here, it has been returned to the pool.
429 + });
430 +});
431 +```
432 +
433 +If you would like to close the connection and remove it from the pool, use
434 +`connection.destroy()` instead. The pool will create a new connection the next
435 +time one is needed.
436 +
437 +Connections are lazily created by the pool. If you configure the pool to allow
438 +up to 100 connections, but only ever use 5 simultaneously, only 5 connections
439 +will be made. Connections are also cycled round-robin style, with connections
440 +being taken from the top of the pool and returning to the bottom.
441 +
442 +When a previous connection is retrieved from the pool, a ping packet is sent
443 +to the server to check if the connection is still good.
444 +
445 +## Pool options
446 +
447 +Pools accept all the same [options as a connection](#connection-options).
448 +When creating a new connection, the options are simply passed to the connection
449 +constructor. In addition to those options pools accept a few extras:
450 +
451 +* `acquireTimeout`: The milliseconds before a timeout occurs during the connection
452 + acquisition. This is slightly different from `connectTimeout`, because acquiring
453 + a pool connection does not always involve making a connection. If a connection
454 + request is queued, the time the request spends in the queue does not count
455 + towards this timeout. (Default: `10000`)
456 +* `waitForConnections`: Determines the pool's action when no connections are
457 + available and the limit has been reached. If `true`, the pool will queue the
458 + connection request and call it when one becomes available. If `false`, the
459 + pool will immediately call back with an error. (Default: `true`)
460 +* `connectionLimit`: The maximum number of connections to create at once.
461 + (Default: `10`)
462 +* `queueLimit`: The maximum number of connection requests the pool will queue
463 + before returning an error from `getConnection`. If set to `0`, there is no
464 + limit to the number of queued connection requests. (Default: `0`)
465 +
466 +## Pool events
467 +
468 +### acquire
469 +
470 +The pool will emit an `acquire` event when a connection is acquired from the pool.
471 +This is called after all acquiring activity has been performed on the connection,
472 +right before the connection is handed to the callback of the acquiring code.
473 +
474 +```js
475 +pool.on('acquire', function (connection) {
476 + console.log('Connection %d acquired', connection.threadId);
477 +});
478 +```
479 +
480 +### connection
481 +
482 +The pool will emit a `connection` event when a new connection is made within the pool.
483 +If you need to set session variables on the connection before it gets used, you can
484 +listen to the `connection` event.
485 +
486 +```js
487 +pool.on('connection', function (connection) {
488 + connection.query('SET SESSION auto_increment_increment=1')
489 +});
490 +```
491 +
492 +### enqueue
493 +
494 +The pool will emit an `enqueue` event when a callback has been queued to wait for
495 +an available connection.
496 +
497 +```js
498 +pool.on('enqueue', function () {
499 + console.log('Waiting for available connection slot');
500 +});
501 +```
502 +
503 +### release
504 +
505 +The pool will emit a `release` event when a connection is released back to the
506 +pool. This is called after all release activity has been performed on the connection,
507 +so the connection will be listed as free at the time of the event.
508 +
509 +```js
510 +pool.on('release', function (connection) {
511 + console.log('Connection %d released', connection.threadId);
512 +});
513 +```
514 +
515 +## Closing all the connections in a pool
516 +
517 +When you are done using the pool, you have to end all the connections or the
518 +Node.js event loop will stay active until the connections are closed by the
519 +MySQL server. This is typically done if the pool is used in a script or when
520 +trying to gracefully shutdown a server. To end all the connections in the
521 +pool, use the `end` method on the pool:
522 +
523 +```js
524 +pool.end(function (err) {
525 + // all connections in the pool have ended
526 +});
527 +```
528 +
529 +The `end` method takes an _optional_ callback that you can use to know when
530 +all the connections are ended.
531 +
532 +**Once `pool.end` is called, `pool.getConnection` and other operations
533 +can no longer be performed.** Wait until all connections in the pool are
534 +released before calling `pool.end`. If you use the shortcut method
535 +`pool.query`, in place of `pool.getConnection``connection.query`
536 +`connection.release`, wait until it completes.
537 +
538 +`pool.end` calls `connection.end` on every active connection in the pool.
539 +This queues a `QUIT` packet on the connection and sets a flag to prevent
540 +`pool.getConnection` from creating new connections. All commands / queries
541 +already in progress will complete, but new commands won't execute.
542 +
543 +## PoolCluster
544 +
545 +PoolCluster provides multiple hosts connection. (group & retry & selector)
546 +
547 +```js
548 +// create
549 +var poolCluster = mysql.createPoolCluster();
550 +
551 +// add configurations (the config is a pool config object)
552 +poolCluster.add(config); // add configuration with automatic name
553 +poolCluster.add('MASTER', masterConfig); // add a named configuration
554 +poolCluster.add('SLAVE1', slave1Config);
555 +poolCluster.add('SLAVE2', slave2Config);
556 +
557 +// remove configurations
558 +poolCluster.remove('SLAVE2'); // By nodeId
559 +poolCluster.remove('SLAVE*'); // By target group : SLAVE1-2
560 +
561 +// Target Group : ALL(anonymous, MASTER, SLAVE1-2), Selector : round-robin(default)
562 +poolCluster.getConnection(function (err, connection) {});
563 +
564 +// Target Group : MASTER, Selector : round-robin
565 +poolCluster.getConnection('MASTER', function (err, connection) {});
566 +
567 +// Target Group : SLAVE1-2, Selector : order
568 +// If can't connect to SLAVE1, return SLAVE2. (remove SLAVE1 in the cluster)
569 +poolCluster.on('remove', function (nodeId) {
570 + console.log('REMOVED NODE : ' + nodeId); // nodeId = SLAVE1
571 +});
572 +
573 +// A pattern can be passed with * as wildcard
574 +poolCluster.getConnection('SLAVE*', 'ORDER', function (err, connection) {});
575 +
576 +// The pattern can also be a regular expression
577 +poolCluster.getConnection(/^SLAVE[12]$/, function (err, connection) {});
578 +
579 +// of namespace : of(pattern, selector)
580 +poolCluster.of('*').getConnection(function (err, connection) {});
581 +
582 +var pool = poolCluster.of('SLAVE*', 'RANDOM');
583 +pool.getConnection(function (err, connection) {});
584 +pool.getConnection(function (err, connection) {});
585 +pool.query(function (error, results, fields) {});
586 +
587 +// close all connections
588 +poolCluster.end(function (err) {
589 + // all connections in the pool cluster have ended
590 +});
591 +```
592 +
593 +### PoolCluster options
594 +
595 +* `canRetry`: If `true`, `PoolCluster` will attempt to reconnect when connection fails. (Default: `true`)
596 +* `removeNodeErrorCount`: If connection fails, node's `errorCount` increases.
597 + When `errorCount` is greater than `removeNodeErrorCount`, remove a node in the `PoolCluster`. (Default: `5`)
598 +* `restoreNodeTimeout`: If connection fails, specifies the number of milliseconds
599 + before another connection attempt will be made. If set to `0`, then node will be
600 + removed instead and never re-used. (Default: `0`)
601 +* `defaultSelector`: The default selector. (Default: `RR`)
602 + * `RR`: Select one alternately. (Round-Robin)
603 + * `RANDOM`: Select the node by random function.
604 + * `ORDER`: Select the first node available unconditionally.
605 +
606 +```js
607 +var clusterConfig = {
608 + removeNodeErrorCount: 1, // Remove the node immediately when connection fails.
609 + defaultSelector: 'ORDER'
610 +};
611 +
612 +var poolCluster = mysql.createPoolCluster(clusterConfig);
613 +```
614 +
615 +## Switching users and altering connection state
616 +
617 +MySQL offers a changeUser command that allows you to alter the current user and
618 +other aspects of the connection without shutting down the underlying socket:
619 +
620 +```js
621 +connection.changeUser({user : 'john'}, function(err) {
622 + if (err) throw err;
623 +});
624 +```
625 +
626 +The available options for this feature are:
627 +
628 +* `user`: The name of the new user (defaults to the previous one).
629 +* `password`: The password of the new user (defaults to the previous one).
630 +* `charset`: The new charset (defaults to the previous one).
631 +* `database`: The new database (defaults to the previous one).
632 +
633 +A sometimes useful side effect of this functionality is that this function also
634 +resets any connection state (variables, transactions, etc.).
635 +
636 +Errors encountered during this operation are treated as fatal connection errors
637 +by this module.
638 +
639 +## Server disconnects
640 +
641 +You may lose the connection to a MySQL server due to network problems, the
642 +server timing you out, the server being restarted, or crashing. All of these
643 +events are considered fatal errors, and will have the `err.code =
644 +'PROTOCOL_CONNECTION_LOST'`. See the [Error Handling](#error-handling) section
645 +for more information.
646 +
647 +Re-connecting a connection is done by establishing a new connection. Once
648 +terminated, an existing connection object cannot be re-connected by design.
649 +
650 +With Pool, disconnected connections will be removed from the pool freeing up
651 +space for a new connection to be created on the next getConnection call.
652 +
653 +With PoolCluster, disconnected connections will count as errors against the
654 +related node, incrementing the error code for that node. Once there are more than
655 +`removeNodeErrorCount` errors on a given node, it is removed from the cluster.
656 +When this occurs, the PoolCluster may emit a `POOL_NONEONLINE` error if there are
657 +no longer any matching nodes for the pattern. The `restoreNodeTimeout` config can
658 +be set to restore offline nodes after a given timeout.
659 +
660 +## Performing queries
661 +
662 +The most basic way to perform a query is to call the `.query()` method on an object
663 +(like a `Connection`, `Pool`, or `PoolNamespace` instance).
664 +
665 +The simplest form of .`query()` is `.query(sqlString, callback)`, where a SQL string
666 +is the first argument and the second is a callback:
667 +
668 +```js
669 +connection.query('SELECT * FROM `books` WHERE `author` = "David"', function (error, results, fields) {
670 + // error will be an Error if one occurred during the query
671 + // results will contain the results of the query
672 + // fields will contain information about the returned results fields (if any)
673 +});
674 +```
675 +
676 +The second form `.query(sqlString, values, callback)` comes when using
677 +placeholder values (see [escaping query values](#escaping-query-values)):
678 +
679 +```js
680 +connection.query('SELECT * FROM `books` WHERE `author` = ?', ['David'], function (error, results, fields) {
681 + // error will be an Error if one occurred during the query
682 + // results will contain the results of the query
683 + // fields will contain information about the returned results fields (if any)
684 +});
685 +```
686 +
687 +The third form `.query(options, callback)` comes when using various advanced
688 +options on the query, like [escaping query values](#escaping-query-values),
689 +[joins with overlapping column names](#joins-with-overlapping-column-names),
690 +[timeouts](#timeout), and [type casting](#type-casting).
691 +
692 +```js
693 +connection.query({
694 + sql: 'SELECT * FROM `books` WHERE `author` = ?',
695 + timeout: 40000, // 40s
696 + values: ['David']
697 +}, function (error, results, fields) {
698 + // error will be an Error if one occurred during the query
699 + // results will contain the results of the query
700 + // fields will contain information about the returned results fields (if any)
701 +});
702 +```
703 +
704 +Note that a combination of the second and third forms can be used where the
705 +placeholder values are passed as an argument and not in the options object.
706 +The `values` argument will override the `values` in the option object.
707 +
708 +```js
709 +connection.query({
710 + sql: 'SELECT * FROM `books` WHERE `author` = ?',
711 + timeout: 40000, // 40s
712 + },
713 + ['David'],
714 + function (error, results, fields) {
715 + // error will be an Error if one occurred during the query
716 + // results will contain the results of the query
717 + // fields will contain information about the returned results fields (if any)
718 + }
719 +);
720 +```
721 +
722 +If the query only has a single replacement character (`?`), and the value is
723 +not `null`, `undefined`, or an array, it can be passed directly as the second
724 +argument to `.query`:
725 +
726 +```js
727 +connection.query(
728 + 'SELECT * FROM `books` WHERE `author` = ?',
729 + 'David',
730 + function (error, results, fields) {
731 + // error will be an Error if one occurred during the query
732 + // results will contain the results of the query
733 + // fields will contain information about the returned results fields (if any)
734 + }
735 +);
736 +```
737 +
738 +## Escaping query values
739 +
740 +**Caution** These methods of escaping values only works when the
741 +[NO_BACKSLASH_ESCAPES](https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sqlmode_no_backslash_escapes)
742 +SQL mode is disabled (which is the default state for MySQL servers).
743 +
744 +In order to avoid SQL Injection attacks, you should always escape any user
745 +provided data before using it inside a SQL query. You can do so using the
746 +`mysql.escape()`, `connection.escape()` or `pool.escape()` methods:
747 +
748 +```js
749 +var userId = 'some user provided value';
750 +var sql = 'SELECT * FROM users WHERE id = ' + connection.escape(userId);
751 +connection.query(sql, function (error, results, fields) {
752 + if (error) throw error;
753 + // ...
754 +});
755 +```
756 +
757 +Alternatively, you can use `?` characters as placeholders for values you would
758 +like to have escaped like this:
759 +
760 +```js
761 +connection.query('SELECT * FROM users WHERE id = ?', [userId], function (error, results, fields) {
762 + if (error) throw error;
763 + // ...
764 +});
765 +```
766 +
767 +Multiple placeholders are mapped to values in the same order as passed. For example,
768 +in the following query `foo` equals `a`, `bar` equals `b`, `baz` equals `c`, and
769 +`id` will be `userId`:
770 +
771 +```js
772 +connection.query('UPDATE users SET foo = ?, bar = ?, baz = ? WHERE id = ?', ['a', 'b', 'c', userId], function (error, results, fields) {
773 + if (error) throw error;
774 + // ...
775 +});
776 +```
777 +
778 +This looks similar to prepared statements in MySQL, however it really just uses
779 +the same `connection.escape()` method internally.
780 +
781 +**Caution** This also differs from prepared statements in that all `?` are
782 +replaced, even those contained in comments and strings.
783 +
784 +Different value types are escaped differently, here is how:
785 +
786 +* Numbers are left untouched
787 +* Booleans are converted to `true` / `false`
788 +* Date objects are converted to `'YYYY-mm-dd HH:ii:ss'` strings
789 +* Buffers are converted to hex strings, e.g. `X'0fa5'`
790 +* Strings are safely escaped
791 +* Arrays are turned into list, e.g. `['a', 'b']` turns into `'a', 'b'`
792 +* Nested arrays are turned into grouped lists (for bulk inserts), e.g. `[['a',
793 + 'b'], ['c', 'd']]` turns into `('a', 'b'), ('c', 'd')`
794 +* Objects that have a `toSqlString` method will have `.toSqlString()` called
795 + and the returned value is used as the raw SQL.
796 +* Objects are turned into `key = 'val'` pairs for each enumerable property on
797 + the object. If the property's value is a function, it is skipped; if the
798 + property's value is an object, toString() is called on it and the returned
799 + value is used.
800 +* `undefined` / `null` are converted to `NULL`
801 +* `NaN` / `Infinity` are left as-is. MySQL does not support these, and trying
802 + to insert them as values will trigger MySQL errors until they implement
803 + support.
804 +
805 +This escaping allows you to do neat things like this:
806 +
807 +```js
808 +var post = {id: 1, title: 'Hello MySQL'};
809 +var query = connection.query('INSERT INTO posts SET ?', post, function (error, results, fields) {
810 + if (error) throw error;
811 + // Neat!
812 +});
813 +console.log(query.sql); // INSERT INTO posts SET `id` = 1, `title` = 'Hello MySQL'
814 +```
815 +
816 +And the `toSqlString` method allows you to form complex queries with functions:
817 +
818 +```js
819 +var CURRENT_TIMESTAMP = { toSqlString: function() { return 'CURRENT_TIMESTAMP()'; } };
820 +var sql = mysql.format('UPDATE posts SET modified = ? WHERE id = ?', [CURRENT_TIMESTAMP, 42]);
821 +console.log(sql); // UPDATE posts SET modified = CURRENT_TIMESTAMP() WHERE id = 42
822 +```
823 +
824 +To generate objects with a `toSqlString` method, the `mysql.raw()` method can
825 +be used. This creates an object that will be left un-touched when using in a `?`
826 +placeholder, useful for using functions as dynamic values:
827 +
828 +**Caution** The string provided to `mysql.raw()` will skip all escaping
829 +functions when used, so be careful when passing in unvalidated input.
830 +
831 +```js
832 +var CURRENT_TIMESTAMP = mysql.raw('CURRENT_TIMESTAMP()');
833 +var sql = mysql.format('UPDATE posts SET modified = ? WHERE id = ?', [CURRENT_TIMESTAMP, 42]);
834 +console.log(sql); // UPDATE posts SET modified = CURRENT_TIMESTAMP() WHERE id = 42
835 +```
836 +
837 +If you feel the need to escape queries by yourself, you can also use the escaping
838 +function directly:
839 +
840 +```js
841 +var query = "SELECT * FROM posts WHERE title=" + mysql.escape("Hello MySQL");
842 +
843 +console.log(query); // SELECT * FROM posts WHERE title='Hello MySQL'
844 +```
845 +
846 +## Escaping query identifiers
847 +
848 +If you can't trust an SQL identifier (database / table / column name) because it is
849 +provided by a user, you should escape it with `mysql.escapeId(identifier)`,
850 +`connection.escapeId(identifier)` or `pool.escapeId(identifier)` like this:
851 +
852 +```js
853 +var sorter = 'date';
854 +var sql = 'SELECT * FROM posts ORDER BY ' + connection.escapeId(sorter);
855 +connection.query(sql, function (error, results, fields) {
856 + if (error) throw error;
857 + // ...
858 +});
859 +```
860 +
861 +It also supports adding qualified identifiers. It will escape both parts.
862 +
863 +```js
864 +var sorter = 'date';
865 +var sql = 'SELECT * FROM posts ORDER BY ' + connection.escapeId('posts.' + sorter);
866 +// -> SELECT * FROM posts ORDER BY `posts`.`date`
867 +```
868 +
869 +If you do not want to treat `.` as qualified identifiers, you can set the second
870 +argument to `true` in order to keep the string as a literal identifier:
871 +
872 +```js
873 +var sorter = 'date.2';
874 +var sql = 'SELECT * FROM posts ORDER BY ' + connection.escapeId(sorter, true);
875 +// -> SELECT * FROM posts ORDER BY `date.2`
876 +```
877 +
878 +Alternatively, you can use `??` characters as placeholders for identifiers you would
879 +like to have escaped like this:
880 +
881 +```js
882 +var userId = 1;
883 +var columns = ['username', 'email'];
884 +var query = connection.query('SELECT ?? FROM ?? WHERE id = ?', [columns, 'users', userId], function (error, results, fields) {
885 + if (error) throw error;
886 + // ...
887 +});
888 +
889 +console.log(query.sql); // SELECT `username`, `email` FROM `users` WHERE id = 1
890 +```
891 +**Please note that this last character sequence is experimental and syntax might change**
892 +
893 +When you pass an Object to `.escape()` or `.query()`, `.escapeId()` is used to avoid SQL injection in object keys.
894 +
895 +### Preparing Queries
896 +
897 +You can use mysql.format to prepare a query with multiple insertion points, utilizing the proper escaping for ids and values. A simple example of this follows:
898 +
899 +```js
900 +var sql = "SELECT * FROM ?? WHERE ?? = ?";
901 +var inserts = ['users', 'id', userId];
902 +sql = mysql.format(sql, inserts);
903 +```
904 +
905 +Following this you then have a valid, escaped query that you can then send to the database safely. This is useful if you are looking to prepare the query before actually sending it to the database. As mysql.format is exposed from SqlString.format you also have the option (but are not required) to pass in stringifyObject and timezone, allowing you provide a custom means of turning objects into strings, as well as a location-specific/timezone-aware Date.
906 +
907 +### Custom format
908 +
909 +If you prefer to have another type of query escape format, there's a connection configuration option you can use to define a custom format function. You can access the connection object if you want to use the built-in `.escape()` or any other connection function.
910 +
911 +Here's an example of how to implement another format:
912 +
913 +```js
914 +connection.config.queryFormat = function (query, values) {
915 + if (!values) return query;
916 + return query.replace(/\:(\w+)/g, function (txt, key) {
917 + if (values.hasOwnProperty(key)) {
918 + return this.escape(values[key]);
919 + }
920 + return txt;
921 + }.bind(this));
922 +};
923 +
924 +connection.query("UPDATE posts SET title = :title", { title: "Hello MySQL" });
925 +```
926 +
927 +## Getting the id of an inserted row
928 +
929 +If you are inserting a row into a table with an auto increment primary key, you
930 +can retrieve the insert id like this:
931 +
932 +```js
933 +connection.query('INSERT INTO posts SET ?', {title: 'test'}, function (error, results, fields) {
934 + if (error) throw error;
935 + console.log(results.insertId);
936 +});
937 +```
938 +
939 +When dealing with big numbers (above JavaScript Number precision limit), you should
940 +consider enabling `supportBigNumbers` option to be able to read the insert id as a
941 +string, otherwise it will throw an error.
942 +
943 +This option is also required when fetching big numbers from the database, otherwise
944 +you will get values rounded to hundreds or thousands due to the precision limit.
945 +
946 +## Getting the number of affected rows
947 +
948 +You can get the number of affected rows from an insert, update or delete statement.
949 +
950 +```js
951 +connection.query('DELETE FROM posts WHERE title = "wrong"', function (error, results, fields) {
952 + if (error) throw error;
953 + console.log('deleted ' + results.affectedRows + ' rows');
954 +})
955 +```
956 +
957 +## Getting the number of changed rows
958 +
959 +You can get the number of changed rows from an update statement.
960 +
961 +"changedRows" differs from "affectedRows" in that it does not count updated rows
962 +whose values were not changed.
963 +
964 +```js
965 +connection.query('UPDATE posts SET ...', function (error, results, fields) {
966 + if (error) throw error;
967 + console.log('changed ' + results.changedRows + ' rows');
968 +})
969 +```
970 +
971 +## Getting the connection ID
972 +
973 +You can get the MySQL connection ID ("thread ID") of a given connection using the `threadId`
974 +property.
975 +
976 +```js
977 +connection.connect(function(err) {
978 + if (err) throw err;
979 + console.log('connected as id ' + connection.threadId);
980 +});
981 +```
982 +
983 +## Executing queries in parallel
984 +
985 +The MySQL protocol is sequential, this means that you need multiple connections
986 +to execute queries in parallel. You can use a Pool to manage connections, one
987 +simple approach is to create one connection per incoming http request.
988 +
989 +## Streaming query rows
990 +
991 +Sometimes you may want to select large quantities of rows and process each of
992 +them as they are received. This can be done like this:
993 +
994 +```js
995 +var query = connection.query('SELECT * FROM posts');
996 +query
997 + .on('error', function(err) {
998 + // Handle error, an 'end' event will be emitted after this as well
999 + })
1000 + .on('fields', function(fields) {
1001 + // the field packets for the rows to follow
1002 + })
1003 + .on('result', function(row) {
1004 + // Pausing the connnection is useful if your processing involves I/O
1005 + connection.pause();
1006 +
1007 + processRow(row, function() {
1008 + connection.resume();
1009 + });
1010 + })
1011 + .on('end', function() {
1012 + // all rows have been received
1013 + });
1014 +```
1015 +
1016 +Please note a few things about the example above:
1017 +
1018 +* Usually you will want to receive a certain amount of rows before starting to
1019 + throttle the connection using `pause()`. This number will depend on the
1020 + amount and size of your rows.
1021 +* `pause()` / `resume()` operate on the underlying socket and parser. You are
1022 + guaranteed that no more `'result'` events will fire after calling `pause()`.
1023 +* You MUST NOT provide a callback to the `query()` method when streaming rows.
1024 +* The `'result'` event will fire for both rows as well as OK packets
1025 + confirming the success of a INSERT/UPDATE query.
1026 +* It is very important not to leave the result paused too long, or you may
1027 + encounter `Error: Connection lost: The server closed the connection.`
1028 + The time limit for this is determined by the
1029 + [net_write_timeout setting](https://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html#sysvar_net_write_timeout)
1030 + on your MySQL server.
1031 +
1032 +Additionally you may be interested to know that it is currently not possible to
1033 +stream individual row columns, they will always be buffered up entirely. If you
1034 +have a good use case for streaming large fields to and from MySQL, I'd love to
1035 +get your thoughts and contributions on this.
1036 +
1037 +### Piping results with Streams
1038 +
1039 +The query object provides a convenience method `.stream([options])` that wraps
1040 +query events into a [Readable Stream](http://nodejs.org/api/stream.html#stream_class_stream_readable)
1041 +object. This stream can easily be piped downstream and provides automatic
1042 +pause/resume, based on downstream congestion and the optional `highWaterMark`.
1043 +The `objectMode` parameter of the stream is set to `true` and cannot be changed
1044 +(if you need a byte stream, you will need to use a transform stream, like
1045 +[objstream](https://www.npmjs.com/package/objstream) for example).
1046 +
1047 +For example, piping query results into another stream (with a max buffer of 5
1048 +objects) is simply:
1049 +
1050 +```js
1051 +connection.query('SELECT * FROM posts')
1052 + .stream({highWaterMark: 5})
1053 + .pipe(...);
1054 +```
1055 +
1056 +## Multiple statement queries
1057 +
1058 +Support for multiple statements is disabled for security reasons (it allows for
1059 +SQL injection attacks if values are not properly escaped). To use this feature
1060 +you have to enable it for your connection:
1061 +
1062 +```js
1063 +var connection = mysql.createConnection({multipleStatements: true});
1064 +```
1065 +
1066 +Once enabled, you can execute multiple statement queries like any other query:
1067 +
1068 +```js
1069 +connection.query('SELECT 1; SELECT 2', function (error, results, fields) {
1070 + if (error) throw error;
1071 + // `results` is an array with one element for every statement in the query:
1072 + console.log(results[0]); // [{1: 1}]
1073 + console.log(results[1]); // [{2: 2}]
1074 +});
1075 +```
1076 +
1077 +Additionally you can also stream the results of multiple statement queries:
1078 +
1079 +```js
1080 +var query = connection.query('SELECT 1; SELECT 2');
1081 +
1082 +query
1083 + .on('fields', function(fields, index) {
1084 + // the fields for the result rows that follow
1085 + })
1086 + .on('result', function(row, index) {
1087 + // index refers to the statement this result belongs to (starts at 0)
1088 + });
1089 +```
1090 +
1091 +If one of the statements in your query causes an error, the resulting Error
1092 +object contains a `err.index` property which tells you which statement caused
1093 +it. MySQL will also stop executing any remaining statements when an error
1094 +occurs.
1095 +
1096 +Please note that the interface for streaming multiple statement queries is
1097 +experimental and I am looking forward to feedback on it.
1098 +
1099 +## Stored procedures
1100 +
1101 +You can call stored procedures from your queries as with any other mysql driver.
1102 +If the stored procedure produces several result sets, they are exposed to you
1103 +the same way as the results for multiple statement queries.
1104 +
1105 +## Joins with overlapping column names
1106 +
1107 +When executing joins, you are likely to get result sets with overlapping column
1108 +names.
1109 +
1110 +By default, node-mysql will overwrite colliding column names in the
1111 +order the columns are received from MySQL, causing some of the received values
1112 +to be unavailable.
1113 +
1114 +However, you can also specify that you want your columns to be nested below
1115 +the table name like this:
1116 +
1117 +```js
1118 +var options = {sql: '...', nestTables: true};
1119 +connection.query(options, function (error, results, fields) {
1120 + if (error) throw error;
1121 + /* results will be an array like this now:
1122 + [{
1123 + table1: {
1124 + fieldA: '...',
1125 + fieldB: '...',
1126 + },
1127 + table2: {
1128 + fieldA: '...',
1129 + fieldB: '...',
1130 + },
1131 + }, ...]
1132 + */
1133 +});
1134 +```
1135 +
1136 +Or use a string separator to have your results merged.
1137 +
1138 +```js
1139 +var options = {sql: '...', nestTables: '_'};
1140 +connection.query(options, function (error, results, fields) {
1141 + if (error) throw error;
1142 + /* results will be an array like this now:
1143 + [{
1144 + table1_fieldA: '...',
1145 + table1_fieldB: '...',
1146 + table2_fieldA: '...',
1147 + table2_fieldB: '...',
1148 + }, ...]
1149 + */
1150 +});
1151 +```
1152 +
1153 +## Transactions
1154 +
1155 +Simple transaction support is available at the connection level:
1156 +
1157 +```js
1158 +connection.beginTransaction(function(err) {
1159 + if (err) { throw err; }
1160 + connection.query('INSERT INTO posts SET title=?', title, function (error, results, fields) {
1161 + if (error) {
1162 + return connection.rollback(function() {
1163 + throw error;
1164 + });
1165 + }
1166 +
1167 + var log = 'Post ' + results.insertId + ' added';
1168 +
1169 + connection.query('INSERT INTO log SET data=?', log, function (error, results, fields) {
1170 + if (error) {
1171 + return connection.rollback(function() {
1172 + throw error;
1173 + });
1174 + }
1175 + connection.commit(function(err) {
1176 + if (err) {
1177 + return connection.rollback(function() {
1178 + throw err;
1179 + });
1180 + }
1181 + console.log('success!');
1182 + });
1183 + });
1184 + });
1185 +});
1186 +```
1187 +Please note that beginTransaction(), commit() and rollback() are simply convenience
1188 +functions that execute the START TRANSACTION, COMMIT, and ROLLBACK commands respectively.
1189 +It is important to understand that many commands in MySQL can cause an implicit commit,
1190 +as described [in the MySQL documentation](http://dev.mysql.com/doc/refman/5.5/en/implicit-commit.html)
1191 +
1192 +## Ping
1193 +
1194 +A ping packet can be sent over a connection using the `connection.ping` method. This
1195 +method will send a ping packet to the server and when the server responds, the callback
1196 +will fire. If an error occurred, the callback will fire with an error argument.
1197 +
1198 +```js
1199 +connection.ping(function (err) {
1200 + if (err) throw err;
1201 + console.log('Server responded to ping');
1202 +})
1203 +```
1204 +
1205 +## Timeouts
1206 +
1207 +Every operation takes an optional inactivity timeout option. This allows you to
1208 +specify appropriate timeouts for operations. It is important to note that these
1209 +timeouts are not part of the MySQL protocol, and rather timeout operations through
1210 +the client. This means that when a timeout is reached, the connection it occurred
1211 +on will be destroyed and no further operations can be performed.
1212 +
1213 +```js
1214 +// Kill query after 60s
1215 +connection.query({sql: 'SELECT COUNT(*) AS count FROM big_table', timeout: 60000}, function (error, results, fields) {
1216 + if (error && error.code === 'PROTOCOL_SEQUENCE_TIMEOUT') {
1217 + throw new Error('too long to count table rows!');
1218 + }
1219 +
1220 + if (error) {
1221 + throw error;
1222 + }
1223 +
1224 + console.log(results[0].count + ' rows');
1225 +});
1226 +```
1227 +
1228 +## Error handling
1229 +
1230 +This module comes with a consistent approach to error handling that you should
1231 +review carefully in order to write solid applications.
1232 +
1233 +Most errors created by this module are instances of the JavaScript [Error][]
1234 +object. Additionally they typically come with two extra properties:
1235 +
1236 +* `err.code`: String, contains the MySQL server error symbol if the error is
1237 + a [MySQL server error][] (e.g. `'ER_ACCESS_DENIED_ERROR'`), a Node.js error
1238 + code if it is a Node.js error (e.g. `'ECONNREFUSED'`), or an internal error
1239 + code (e.g. `'PROTOCOL_CONNECTION_LOST'`).
1240 +* `err.errno`: Number, contains the MySQL server error number. Only populated
1241 + from [MySQL server error][].
1242 +* `err.fatal`: Boolean, indicating if this error is terminal to the connection
1243 + object. If the error is not from a MySQL protocol operation, this property
1244 + will not be defined.
1245 +* `err.sql`: String, contains the full SQL of the failed query. This can be
1246 + useful when using a higher level interface like an ORM that is generating
1247 + the queries.
1248 +* `err.sqlState`: String, contains the five-character SQLSTATE value. Only populated from [MySQL server error][].
1249 +* `err.sqlMessage`: String, contains the message string that provides a
1250 + textual description of the error. Only populated from [MySQL server error][].
1251 +
1252 +[Error]: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error
1253 +[MySQL server error]: https://dev.mysql.com/doc/refman/5.5/en/server-error-reference.html
1254 +
1255 +Fatal errors are propagated to *all* pending callbacks. In the example below, a
1256 +fatal error is triggered by trying to connect to an invalid port. Therefore the
1257 +error object is propagated to both pending callbacks:
1258 +
1259 +```js
1260 +var connection = require('mysql').createConnection({
1261 + port: 84943, // WRONG PORT
1262 +});
1263 +
1264 +connection.connect(function(err) {
1265 + console.log(err.code); // 'ECONNREFUSED'
1266 + console.log(err.fatal); // true
1267 +});
1268 +
1269 +connection.query('SELECT 1', function (error, results, fields) {
1270 + console.log(error.code); // 'ECONNREFUSED'
1271 + console.log(error.fatal); // true
1272 +});
1273 +```
1274 +
1275 +Normal errors however are only delegated to the callback they belong to. So in
1276 +the example below, only the first callback receives an error, the second query
1277 +works as expected:
1278 +
1279 +```js
1280 +connection.query('USE name_of_db_that_does_not_exist', function (error, results, fields) {
1281 + console.log(error.code); // 'ER_BAD_DB_ERROR'
1282 +});
1283 +
1284 +connection.query('SELECT 1', function (error, results, fields) {
1285 + console.log(error); // null
1286 + console.log(results.length); // 1
1287 +});
1288 +```
1289 +
1290 +Last but not least: If a fatal errors occurs and there are no pending
1291 +callbacks, or a normal error occurs which has no callback belonging to it, the
1292 +error is emitted as an `'error'` event on the connection object. This is
1293 +demonstrated in the example below:
1294 +
1295 +```js
1296 +connection.on('error', function(err) {
1297 + console.log(err.code); // 'ER_BAD_DB_ERROR'
1298 +});
1299 +
1300 +connection.query('USE name_of_db_that_does_not_exist');
1301 +```
1302 +
1303 +Note: `'error'` events are special in node. If they occur without an attached
1304 +listener, a stack trace is printed and your process is killed.
1305 +
1306 +**tl;dr:** This module does not want you to deal with silent failures. You
1307 +should always provide callbacks to your method calls. If you want to ignore
1308 +this advice and suppress unhandled errors, you can do this:
1309 +
1310 +```js
1311 +// I am Chuck Norris:
1312 +connection.on('error', function() {});
1313 +```
1314 +
1315 +## Exception Safety
1316 +
1317 +This module is exception safe. That means you can continue to use it, even if
1318 +one of your callback functions throws an error which you're catching using
1319 +'uncaughtException' or a domain.
1320 +
1321 +## Type casting
1322 +
1323 +For your convenience, this driver will cast mysql types into native JavaScript
1324 +types by default. The following mappings exist:
1325 +
1326 +### Number
1327 +
1328 +* TINYINT
1329 +* SMALLINT
1330 +* INT
1331 +* MEDIUMINT
1332 +* YEAR
1333 +* FLOAT
1334 +* DOUBLE
1335 +
1336 +### Date
1337 +
1338 +* TIMESTAMP
1339 +* DATE
1340 +* DATETIME
1341 +
1342 +### Buffer
1343 +
1344 +* TINYBLOB
1345 +* MEDIUMBLOB
1346 +* LONGBLOB
1347 +* BLOB
1348 +* BINARY
1349 +* VARBINARY
1350 +* BIT (last byte will be filled with 0 bits as necessary)
1351 +
1352 +### String
1353 +
1354 +**Note** text in the binary character set is returned as `Buffer`, rather
1355 +than a string.
1356 +
1357 +* CHAR
1358 +* VARCHAR
1359 +* TINYTEXT
1360 +* MEDIUMTEXT
1361 +* LONGTEXT
1362 +* TEXT
1363 +* ENUM
1364 +* SET
1365 +* DECIMAL (may exceed float precision)
1366 +* BIGINT (may exceed float precision)
1367 +* TIME (could be mapped to Date, but what date would be set?)
1368 +* GEOMETRY (never used those, get in touch if you do)
1369 +
1370 +It is not recommended (and may go away / change in the future) to disable type
1371 +casting, but you can currently do so on either the connection:
1372 +
1373 +```js
1374 +var connection = require('mysql').createConnection({typeCast: false});
1375 +```
1376 +
1377 +Or on the query level:
1378 +
1379 +```js
1380 +var options = {sql: '...', typeCast: false};
1381 +var query = connection.query(options, function (error, results, fields) {
1382 + if (error) throw error;
1383 + // ...
1384 +});
1385 +```
1386 +
1387 +### Custom type casting
1388 +
1389 +You can also pass a function and handle type casting yourself. You're given some
1390 +column information like database, table and name and also type and length. If you
1391 +just want to apply a custom type casting to a specific type you can do it and then
1392 +fallback to the default.
1393 +
1394 +The function is provided two arguments `field` and `next` and is expected to
1395 +return the value for the given field by invoking the parser functions through
1396 +the `field` object.
1397 +
1398 +The `field` argument is a `Field` object and contains data about the field that
1399 +need to be parsed. The following are some of the properties on a `Field` object:
1400 +
1401 + * `db` - a string of the database the field came from.
1402 + * `table` - a string of the table the field came from.
1403 + * `name` - a string of the field name.
1404 + * `type` - a string of the field type in all caps.
1405 + * `length` - a number of the field length, as given by the database.
1406 +
1407 +The `next` argument is a `function` that, when called, will return the default
1408 +type conversion for the given field.
1409 +
1410 +When getting the field data, the following helper methods are present on the
1411 +`field` object:
1412 +
1413 + * `.string()` - parse the field into a string.
1414 + * `.buffer()` - parse the field into a `Buffer`.
1415 + * `.geometry()` - parse the field as a geometry value.
1416 +
1417 +The MySQL protocol is a text-based protocol. This means that over the wire, all
1418 +field types are represented as a string, which is why only string-like functions
1419 +are available on the `field` object. Based on the type information (like `INT`),
1420 +the type cast should convert the string field into a different JavaScript type
1421 +(like a `number`).
1422 +
1423 +Here's an example of converting `TINYINT(1)` to boolean:
1424 +
1425 +```js
1426 +connection = mysql.createConnection({
1427 + typeCast: function (field, next) {
1428 + if (field.type === 'TINY' && field.length === 1) {
1429 + return (field.string() === '1'); // 1 = true, 0 = false
1430 + } else {
1431 + return next();
1432 + }
1433 + }
1434 +});
1435 +```
1436 +
1437 +__WARNING: YOU MUST INVOKE the parser using one of these three field functions
1438 +in your custom typeCast callback. They can only be called once.__
1439 +
1440 +## Debugging and reporting problems
1441 +
1442 +If you are running into problems, one thing that may help is enabling the
1443 +`debug` mode for the connection:
1444 +
1445 +```js
1446 +var connection = mysql.createConnection({debug: true});
1447 +```
1448 +
1449 +This will print all incoming and outgoing packets on stdout. You can also restrict debugging to
1450 +packet types by passing an array of types to debug:
1451 +
1452 +```js
1453 +var connection = mysql.createConnection({debug: ['ComQueryPacket', 'RowDataPacket']});
1454 +```
1455 +
1456 +to restrict debugging to the query and data packets.
1457 +
1458 +If that does not help, feel free to open a GitHub issue. A good GitHub issue
1459 +will have:
1460 +
1461 +* The minimal amount of code required to reproduce the problem (if possible)
1462 +* As much debugging output and information about your environment (mysql
1463 + version, node version, os, etc.) as you can gather.
1464 +
1465 +## Security issues
1466 +
1467 +Security issues should not be first reported through GitHub or another public
1468 +forum, but kept private in order for the collaborators to assess the report
1469 +and either (a) devise a fix and plan a release date or (b) assert that it is
1470 +not a security issue (in which case it can be posted in a public forum, like
1471 +a GitHub issue).
1472 +
1473 +The primary private forum is email, either by emailing the module's author or
1474 +opening a GitHub issue simply asking to whom a security issues should be
1475 +addressed to without disclosing the issue or type of issue.
1476 +
1477 +An ideal report would include a clear indication of what the security issue is
1478 +and how it would be exploited, ideally with an accompanying proof of concept
1479 +("PoC") for collaborators to work against and validate potentional fixes against.
1480 +
1481 +## Contributing
1482 +
1483 +This project welcomes contributions from the community. Contributions are
1484 +accepted using GitHub pull requests. If you're not familiar with making
1485 +GitHub pull requests, please refer to the
1486 +[GitHub documentation "Creating a pull request"](https://help.github.com/articles/creating-a-pull-request/).
1487 +
1488 +For a good pull request, we ask you provide the following:
1489 +
1490 +1. Try to include a clear description of your pull request in the description.
1491 + It should include the basic "what" and "why"s for the request.
1492 +2. The tests should pass as best as you can. See the [Running tests](#running-tests)
1493 + section on how to run the different tests. GitHub will automatically run
1494 + the tests as well, to act as a safety net.
1495 +3. The pull request should include tests for the change. A new feature should
1496 + have tests for the new feature and bug fixes should include a test that fails
1497 + without the corresponding code change and passes after they are applied.
1498 + The command `npm run test-cov` will generate a `coverage/` folder that
1499 + contains HTML pages of the code coverage, to better understand if everything
1500 + you're adding is being tested.
1501 +4. If the pull request is a new feature, please be sure to include all
1502 + appropriate documentation additions in the `Readme.md` file as well.
1503 +5. To help ensure that your code is similar in style to the existing code,
1504 + run the command `npm run lint` and fix any displayed issues.
1505 +
1506 +## Running tests
1507 +
1508 +The test suite is split into two parts: unit tests and integration tests.
1509 +The unit tests run on any machine while the integration tests require a
1510 +MySQL server instance to be setup.
1511 +
1512 +### Running unit tests
1513 +
1514 +```sh
1515 +$ FILTER=unit npm test
1516 +```
1517 +
1518 +### Running integration tests
1519 +
1520 +Set the environment variables `MYSQL_DATABASE`, `MYSQL_HOST`, `MYSQL_PORT`,
1521 +`MYSQL_USER` and `MYSQL_PASSWORD`. `MYSQL_SOCKET` can also be used in place
1522 +of `MYSQL_HOST` and `MYSQL_PORT` to connect over a UNIX socket. Then run
1523 +`npm test`.
1524 +
1525 +For example, if you have an installation of mysql running on localhost:3306
1526 +and no password set for the `root` user, run:
1527 +
1528 +```sh
1529 +$ mysql -u root -e "CREATE DATABASE IF NOT EXISTS node_mysql_test"
1530 +$ MYSQL_HOST=localhost MYSQL_PORT=3306 MYSQL_DATABASE=node_mysql_test MYSQL_USER=root MYSQL_PASSWORD= FILTER=integration npm test
1531 +```
1532 +
1533 +## Todo
1534 +
1535 +* Prepared statements
1536 +* Support for encodings other than UTF-8 / ASCII
1537 +
1538 +[appveyor-image]: https://badgen.net/appveyor/ci/dougwilson/node-mysql/master?label=windows
1539 +[appveyor-url]: https://ci.appveyor.com/project/dougwilson/node-mysql
1540 +[coveralls-image]: https://badgen.net/coveralls/c/github/mysqljs/mysql/master
1541 +[coveralls-url]: https://coveralls.io/r/mysqljs/mysql?branch=master
1542 +[node-image]: https://badgen.net/npm/node/mysql
1543 +[node-url]: https://nodejs.org/en/download
1544 +[npm-downloads-image]: https://badgen.net/npm/dm/mysql
1545 +[npm-url]: https://npmjs.org/package/mysql
1546 +[npm-version-image]: https://badgen.net/npm/v/mysql
1547 +[travis-image]: https://badgen.net/travis/mysqljs/mysql/master
1548 +[travis-url]: https://travis-ci.org/mysqljs/mysql
1 +var Classes = Object.create(null);
2 +
3 +/**
4 + * Create a new Connection instance.
5 + * @param {object|string} config Configuration or connection string for new MySQL connection
6 + * @return {Connection} A new MySQL connection
7 + * @public
8 + */
9 +exports.createConnection = function createConnection(config) {
10 + var Connection = loadClass('Connection');
11 + var ConnectionConfig = loadClass('ConnectionConfig');
12 +
13 + return new Connection({config: new ConnectionConfig(config)});
14 +};
15 +
16 +/**
17 + * Create a new Pool instance.
18 + * @param {object|string} config Configuration or connection string for new MySQL connections
19 + * @return {Pool} A new MySQL pool
20 + * @public
21 + */
22 +exports.createPool = function createPool(config) {
23 + var Pool = loadClass('Pool');
24 + var PoolConfig = loadClass('PoolConfig');
25 +
26 + return new Pool({config: new PoolConfig(config)});
27 +};
28 +
29 +/**
30 + * Create a new PoolCluster instance.
31 + * @param {object} [config] Configuration for pool cluster
32 + * @return {PoolCluster} New MySQL pool cluster
33 + * @public
34 + */
35 +exports.createPoolCluster = function createPoolCluster(config) {
36 + var PoolCluster = loadClass('PoolCluster');
37 +
38 + return new PoolCluster(config);
39 +};
40 +
41 +/**
42 + * Create a new Query instance.
43 + * @param {string} sql The SQL for the query
44 + * @param {array} [values] Any values to insert into placeholders in sql
45 + * @param {function} [callback] The callback to use when query is complete
46 + * @return {Query} New query object
47 + * @public
48 + */
49 +exports.createQuery = function createQuery(sql, values, callback) {
50 + var Connection = loadClass('Connection');
51 +
52 + return Connection.createQuery(sql, values, callback);
53 +};
54 +
55 +/**
56 + * Escape a value for SQL.
57 + * @param {*} value The value to escape
58 + * @param {boolean} [stringifyObjects=false] Setting if objects should be stringified
59 + * @param {string} [timeZone=local] Setting for time zone to use for Date conversion
60 + * @return {string} Escaped string value
61 + * @public
62 + */
63 +exports.escape = function escape(value, stringifyObjects, timeZone) {
64 + var SqlString = loadClass('SqlString');
65 +
66 + return SqlString.escape(value, stringifyObjects, timeZone);
67 +};
68 +
69 +/**
70 + * Escape an identifier for SQL.
71 + * @param {*} value The value to escape
72 + * @param {boolean} [forbidQualified=false] Setting to treat '.' as part of identifier
73 + * @return {string} Escaped string value
74 + * @public
75 + */
76 +exports.escapeId = function escapeId(value, forbidQualified) {
77 + var SqlString = loadClass('SqlString');
78 +
79 + return SqlString.escapeId(value, forbidQualified);
80 +};
81 +
82 +/**
83 + * Format SQL and replacement values into a SQL string.
84 + * @param {string} sql The SQL for the query
85 + * @param {array} [values] Any values to insert into placeholders in sql
86 + * @param {boolean} [stringifyObjects=false] Setting if objects should be stringified
87 + * @param {string} [timeZone=local] Setting for time zone to use for Date conversion
88 + * @return {string} Formatted SQL string
89 + * @public
90 + */
91 +exports.format = function format(sql, values, stringifyObjects, timeZone) {
92 + var SqlString = loadClass('SqlString');
93 +
94 + return SqlString.format(sql, values, stringifyObjects, timeZone);
95 +};
96 +
97 +/**
98 + * Wrap raw SQL strings from escape overriding.
99 + * @param {string} sql The raw SQL
100 + * @return {object} Wrapped object
101 + * @public
102 + */
103 +exports.raw = function raw(sql) {
104 + var SqlString = loadClass('SqlString');
105 +
106 + return SqlString.raw(sql);
107 +};
108 +
109 +/**
110 + * The type constants.
111 + * @public
112 + */
113 +Object.defineProperty(exports, 'Types', {
114 + get: loadClass.bind(null, 'Types')
115 +});
116 +
117 +/**
118 + * Load the given class.
119 + * @param {string} className Name of class to default
120 + * @return {function|object} Class constructor or exports
121 + * @private
122 + */
123 +function loadClass(className) {
124 + var Class = Classes[className];
125 +
126 + if (Class !== undefined) {
127 + return Class;
128 + }
129 +
130 + // This uses a switch for static require analysis
131 + switch (className) {
132 + case 'Connection':
133 + Class = require('./lib/Connection');
134 + break;
135 + case 'ConnectionConfig':
136 + Class = require('./lib/ConnectionConfig');
137 + break;
138 + case 'Pool':
139 + Class = require('./lib/Pool');
140 + break;
141 + case 'PoolCluster':
142 + Class = require('./lib/PoolCluster');
143 + break;
144 + case 'PoolConfig':
145 + Class = require('./lib/PoolConfig');
146 + break;
147 + case 'SqlString':
148 + Class = require('./lib/protocol/SqlString');
149 + break;
150 + case 'Types':
151 + Class = require('./lib/protocol/constants/types');
152 + break;
153 + default:
154 + throw new Error('Cannot find class \'' + className + '\'');
155 + }
156 +
157 + // Store to prevent invoking require()
158 + Classes[className] = Class;
159 +
160 + return Class;
161 +}
1 +var Crypto = require('crypto');
2 +var Events = require('events');
3 +var Net = require('net');
4 +var tls = require('tls');
5 +var ConnectionConfig = require('./ConnectionConfig');
6 +var Protocol = require('./protocol/Protocol');
7 +var SqlString = require('./protocol/SqlString');
8 +var Query = require('./protocol/sequences/Query');
9 +var Util = require('util');
10 +
11 +module.exports = Connection;
12 +Util.inherits(Connection, Events.EventEmitter);
13 +function Connection(options) {
14 + Events.EventEmitter.call(this);
15 +
16 + this.config = options.config;
17 +
18 + this._socket = options.socket;
19 + this._protocol = new Protocol({config: this.config, connection: this});
20 + this._connectCalled = false;
21 + this.state = 'disconnected';
22 + this.threadId = null;
23 +}
24 +
25 +Connection.createQuery = function createQuery(sql, values, callback) {
26 + if (sql instanceof Query) {
27 + return sql;
28 + }
29 +
30 + var cb = callback;
31 + var options = {};
32 +
33 + if (typeof sql === 'function') {
34 + cb = sql;
35 + } else if (typeof sql === 'object') {
36 + options = Object.create(sql);
37 +
38 + if (typeof values === 'function') {
39 + cb = values;
40 + } else if (values !== undefined) {
41 + Object.defineProperty(options, 'values', { value: values });
42 + }
43 + } else {
44 + options.sql = sql;
45 +
46 + if (typeof values === 'function') {
47 + cb = values;
48 + } else if (values !== undefined) {
49 + options.values = values;
50 + }
51 + }
52 +
53 + if (cb !== undefined) {
54 + cb = wrapCallbackInDomain(null, cb);
55 +
56 + if (cb === undefined) {
57 + throw new TypeError('argument callback must be a function when provided');
58 + }
59 + }
60 +
61 + return new Query(options, cb);
62 +};
63 +
64 +Connection.prototype.connect = function connect(options, callback) {
65 + if (!callback && typeof options === 'function') {
66 + callback = options;
67 + options = {};
68 + }
69 +
70 + if (!this._connectCalled) {
71 + this._connectCalled = true;
72 +
73 + // Connect either via a UNIX domain socket or a TCP socket.
74 + this._socket = (this.config.socketPath)
75 + ? Net.createConnection(this.config.socketPath)
76 + : Net.createConnection(this.config.port, this.config.host);
77 +
78 + // Connect socket to connection domain
79 + if (Events.usingDomains) {
80 + this._socket.domain = this.domain;
81 + }
82 +
83 + var connection = this;
84 + this._protocol.on('data', function(data) {
85 + connection._socket.write(data);
86 + });
87 + this._socket.on('data', wrapToDomain(connection, function (data) {
88 + connection._protocol.write(data);
89 + }));
90 + this._protocol.on('end', function() {
91 + connection._socket.end();
92 + });
93 + this._socket.on('end', wrapToDomain(connection, function () {
94 + connection._protocol.end();
95 + }));
96 +
97 + this._socket.on('error', this._handleNetworkError.bind(this));
98 + this._socket.on('connect', this._handleProtocolConnect.bind(this));
99 + this._protocol.on('handshake', this._handleProtocolHandshake.bind(this));
100 + this._protocol.on('initialize', this._handleProtocolInitialize.bind(this));
101 + this._protocol.on('unhandledError', this._handleProtocolError.bind(this));
102 + this._protocol.on('drain', this._handleProtocolDrain.bind(this));
103 + this._protocol.on('end', this._handleProtocolEnd.bind(this));
104 + this._protocol.on('enqueue', this._handleProtocolEnqueue.bind(this));
105 +
106 + if (this.config.connectTimeout) {
107 + var handleConnectTimeout = this._handleConnectTimeout.bind(this);
108 +
109 + this._socket.setTimeout(this.config.connectTimeout, handleConnectTimeout);
110 + this._socket.once('connect', function() {
111 + this.setTimeout(0, handleConnectTimeout);
112 + });
113 + }
114 + }
115 +
116 + this._protocol.handshake(options, wrapCallbackInDomain(this, callback));
117 +};
118 +
119 +Connection.prototype.changeUser = function changeUser(options, callback) {
120 + if (!callback && typeof options === 'function') {
121 + callback = options;
122 + options = {};
123 + }
124 +
125 + this._implyConnect();
126 +
127 + var charsetNumber = (options.charset)
128 + ? ConnectionConfig.getCharsetNumber(options.charset)
129 + : this.config.charsetNumber;
130 +
131 + return this._protocol.changeUser({
132 + user : options.user || this.config.user,
133 + password : options.password || this.config.password,
134 + database : options.database || this.config.database,
135 + timeout : options.timeout,
136 + charsetNumber : charsetNumber,
137 + currentConfig : this.config
138 + }, wrapCallbackInDomain(this, callback));
139 +};
140 +
141 +Connection.prototype.beginTransaction = function beginTransaction(options, callback) {
142 + if (!callback && typeof options === 'function') {
143 + callback = options;
144 + options = {};
145 + }
146 +
147 + options = options || {};
148 + options.sql = 'START TRANSACTION';
149 + options.values = null;
150 +
151 + return this.query(options, callback);
152 +};
153 +
154 +Connection.prototype.commit = function commit(options, callback) {
155 + if (!callback && typeof options === 'function') {
156 + callback = options;
157 + options = {};
158 + }
159 +
160 + options = options || {};
161 + options.sql = 'COMMIT';
162 + options.values = null;
163 +
164 + return this.query(options, callback);
165 +};
166 +
167 +Connection.prototype.rollback = function rollback(options, callback) {
168 + if (!callback && typeof options === 'function') {
169 + callback = options;
170 + options = {};
171 + }
172 +
173 + options = options || {};
174 + options.sql = 'ROLLBACK';
175 + options.values = null;
176 +
177 + return this.query(options, callback);
178 +};
179 +
180 +Connection.prototype.query = function query(sql, values, cb) {
181 + var query = Connection.createQuery(sql, values, cb);
182 + query._connection = this;
183 +
184 + if (!(typeof sql === 'object' && 'typeCast' in sql)) {
185 + query.typeCast = this.config.typeCast;
186 + }
187 +
188 + if (query.sql) {
189 + query.sql = this.format(query.sql, query.values);
190 + }
191 +
192 + if (query._callback) {
193 + query._callback = wrapCallbackInDomain(this, query._callback);
194 + }
195 +
196 + this._implyConnect();
197 +
198 + return this._protocol._enqueue(query);
199 +};
200 +
201 +Connection.prototype.ping = function ping(options, callback) {
202 + if (!callback && typeof options === 'function') {
203 + callback = options;
204 + options = {};
205 + }
206 +
207 + this._implyConnect();
208 + this._protocol.ping(options, wrapCallbackInDomain(this, callback));
209 +};
210 +
211 +Connection.prototype.statistics = function statistics(options, callback) {
212 + if (!callback && typeof options === 'function') {
213 + callback = options;
214 + options = {};
215 + }
216 +
217 + this._implyConnect();
218 + this._protocol.stats(options, wrapCallbackInDomain(this, callback));
219 +};
220 +
221 +Connection.prototype.end = function end(options, callback) {
222 + var cb = callback;
223 + var opts = options;
224 +
225 + if (!callback && typeof options === 'function') {
226 + cb = options;
227 + opts = null;
228 + }
229 +
230 + // create custom options reference
231 + opts = Object.create(opts || null);
232 +
233 + if (opts.timeout === undefined) {
234 + // default timeout of 30 seconds
235 + opts.timeout = 30000;
236 + }
237 +
238 + this._implyConnect();
239 + this._protocol.quit(opts, wrapCallbackInDomain(this, cb));
240 +};
241 +
242 +Connection.prototype.destroy = function() {
243 + this.state = 'disconnected';
244 + this._implyConnect();
245 + this._socket.destroy();
246 + this._protocol.destroy();
247 +};
248 +
249 +Connection.prototype.pause = function() {
250 + this._socket.pause();
251 + this._protocol.pause();
252 +};
253 +
254 +Connection.prototype.resume = function() {
255 + this._socket.resume();
256 + this._protocol.resume();
257 +};
258 +
259 +Connection.prototype.escape = function(value) {
260 + return SqlString.escape(value, false, this.config.timezone);
261 +};
262 +
263 +Connection.prototype.escapeId = function escapeId(value) {
264 + return SqlString.escapeId(value, false);
265 +};
266 +
267 +Connection.prototype.format = function(sql, values) {
268 + if (typeof this.config.queryFormat === 'function') {
269 + return this.config.queryFormat.call(this, sql, values, this.config.timezone);
270 + }
271 + return SqlString.format(sql, values, this.config.stringifyObjects, this.config.timezone);
272 +};
273 +
274 +if (tls.TLSSocket) {
275 + // 0.11+ environment
276 + Connection.prototype._startTLS = function _startTLS(onSecure) {
277 + var connection = this;
278 +
279 + createSecureContext(this.config, function (err, secureContext) {
280 + if (err) {
281 + onSecure(err);
282 + return;
283 + }
284 +
285 + // "unpipe"
286 + connection._socket.removeAllListeners('data');
287 + connection._protocol.removeAllListeners('data');
288 +
289 + // socket <-> encrypted
290 + var rejectUnauthorized = connection.config.ssl.rejectUnauthorized;
291 + var secureEstablished = false;
292 + var secureSocket = new tls.TLSSocket(connection._socket, {
293 + rejectUnauthorized : rejectUnauthorized,
294 + requestCert : true,
295 + secureContext : secureContext,
296 + isServer : false
297 + });
298 +
299 + // error handler for secure socket
300 + secureSocket.on('_tlsError', function(err) {
301 + if (secureEstablished) {
302 + connection._handleNetworkError(err);
303 + } else {
304 + onSecure(err);
305 + }
306 + });
307 +
308 + // cleartext <-> protocol
309 + secureSocket.pipe(connection._protocol);
310 + connection._protocol.on('data', function(data) {
311 + secureSocket.write(data);
312 + });
313 +
314 + secureSocket.on('secure', function() {
315 + secureEstablished = true;
316 +
317 + onSecure(rejectUnauthorized ? this.ssl.verifyError() : null);
318 + });
319 +
320 + // start TLS communications
321 + secureSocket._start();
322 + });
323 + };
324 +} else {
325 + // pre-0.11 environment
326 + Connection.prototype._startTLS = function _startTLS(onSecure) {
327 + // before TLS:
328 + // _socket <-> _protocol
329 + // after:
330 + // _socket <-> securePair.encrypted <-> securePair.cleartext <-> _protocol
331 +
332 + var connection = this;
333 + var credentials = Crypto.createCredentials({
334 + ca : this.config.ssl.ca,
335 + cert : this.config.ssl.cert,
336 + ciphers : this.config.ssl.ciphers,
337 + key : this.config.ssl.key,
338 + passphrase : this.config.ssl.passphrase
339 + });
340 +
341 + var rejectUnauthorized = this.config.ssl.rejectUnauthorized;
342 + var secureEstablished = false;
343 + var securePair = tls.createSecurePair(credentials, false, true, rejectUnauthorized);
344 +
345 + // error handler for secure pair
346 + securePair.on('error', function(err) {
347 + if (secureEstablished) {
348 + connection._handleNetworkError(err);
349 + } else {
350 + onSecure(err);
351 + }
352 + });
353 +
354 + // "unpipe"
355 + this._socket.removeAllListeners('data');
356 + this._protocol.removeAllListeners('data');
357 +
358 + // socket <-> encrypted
359 + securePair.encrypted.pipe(this._socket);
360 + this._socket.on('data', function(data) {
361 + securePair.encrypted.write(data);
362 + });
363 +
364 + // cleartext <-> protocol
365 + securePair.cleartext.pipe(this._protocol);
366 + this._protocol.on('data', function(data) {
367 + securePair.cleartext.write(data);
368 + });
369 +
370 + // secure established
371 + securePair.on('secure', function() {
372 + secureEstablished = true;
373 +
374 + if (!rejectUnauthorized) {
375 + onSecure();
376 + return;
377 + }
378 +
379 + var verifyError = this.ssl.verifyError();
380 + var err = verifyError;
381 +
382 + // node.js 0.6 support
383 + if (typeof err === 'string') {
384 + err = new Error(verifyError);
385 + err.code = verifyError;
386 + }
387 +
388 + onSecure(err);
389 + });
390 +
391 + // node.js 0.8 bug
392 + securePair._cycle = securePair.cycle;
393 + securePair.cycle = function cycle() {
394 + if (this.ssl && this.ssl.error) {
395 + this.error();
396 + }
397 +
398 + return this._cycle.apply(this, arguments);
399 + };
400 + };
401 +}
402 +
403 +Connection.prototype._handleConnectTimeout = function() {
404 + if (this._socket) {
405 + this._socket.setTimeout(0);
406 + this._socket.destroy();
407 + }
408 +
409 + var err = new Error('connect ETIMEDOUT');
410 + err.errorno = 'ETIMEDOUT';
411 + err.code = 'ETIMEDOUT';
412 + err.syscall = 'connect';
413 +
414 + this._handleNetworkError(err);
415 +};
416 +
417 +Connection.prototype._handleNetworkError = function(err) {
418 + this._protocol.handleNetworkError(err);
419 +};
420 +
421 +Connection.prototype._handleProtocolError = function(err) {
422 + this.state = 'protocol_error';
423 + this.emit('error', err);
424 +};
425 +
426 +Connection.prototype._handleProtocolDrain = function() {
427 + this.emit('drain');
428 +};
429 +
430 +Connection.prototype._handleProtocolConnect = function() {
431 + this.state = 'connected';
432 + this.emit('connect');
433 +};
434 +
435 +Connection.prototype._handleProtocolHandshake = function _handleProtocolHandshake() {
436 + this.state = 'authenticated';
437 +};
438 +
439 +Connection.prototype._handleProtocolInitialize = function _handleProtocolInitialize(packet) {
440 + this.threadId = packet.threadId;
441 +};
442 +
443 +Connection.prototype._handleProtocolEnd = function(err) {
444 + this.state = 'disconnected';
445 + this.emit('end', err);
446 +};
447 +
448 +Connection.prototype._handleProtocolEnqueue = function _handleProtocolEnqueue(sequence) {
449 + this.emit('enqueue', sequence);
450 +};
451 +
452 +Connection.prototype._implyConnect = function() {
453 + if (!this._connectCalled) {
454 + this.connect();
455 + }
456 +};
457 +
458 +function createSecureContext (config, cb) {
459 + var context = null;
460 + var error = null;
461 +
462 + try {
463 + context = tls.createSecureContext({
464 + ca : config.ssl.ca,
465 + cert : config.ssl.cert,
466 + ciphers : config.ssl.ciphers,
467 + key : config.ssl.key,
468 + passphrase : config.ssl.passphrase
469 + });
470 + } catch (err) {
471 + error = err;
472 + }
473 +
474 + cb(error, context);
475 +}
476 +
477 +function unwrapFromDomain(fn) {
478 + return function () {
479 + var domains = [];
480 + var ret;
481 +
482 + while (process.domain) {
483 + domains.shift(process.domain);
484 + process.domain.exit();
485 + }
486 +
487 + try {
488 + ret = fn.apply(this, arguments);
489 + } finally {
490 + for (var i = 0; i < domains.length; i++) {
491 + domains[i].enter();
492 + }
493 + }
494 +
495 + return ret;
496 + };
497 +}
498 +
499 +function wrapCallbackInDomain(ee, fn) {
500 + if (typeof fn !== 'function') {
501 + return undefined;
502 + }
503 +
504 + if (fn.domain) {
505 + return fn;
506 + }
507 +
508 + var domain = process.domain;
509 +
510 + if (domain) {
511 + return domain.bind(fn);
512 + } else if (ee) {
513 + return unwrapFromDomain(wrapToDomain(ee, fn));
514 + } else {
515 + return fn;
516 + }
517 +}
518 +
519 +function wrapToDomain(ee, fn) {
520 + return function () {
521 + if (Events.usingDomains && ee.domain) {
522 + ee.domain.enter();
523 + fn.apply(this, arguments);
524 + ee.domain.exit();
525 + } else {
526 + fn.apply(this, arguments);
527 + }
528 + };
529 +}
1 +var urlParse = require('url').parse;
2 +var ClientConstants = require('./protocol/constants/client');
3 +var Charsets = require('./protocol/constants/charsets');
4 +var SSLProfiles = null;
5 +
6 +module.exports = ConnectionConfig;
7 +function ConnectionConfig(options) {
8 + if (typeof options === 'string') {
9 + options = ConnectionConfig.parseUrl(options);
10 + }
11 +
12 + this.host = options.host || 'localhost';
13 + this.port = options.port || 3306;
14 + this.localAddress = options.localAddress;
15 + this.socketPath = options.socketPath;
16 + this.user = options.user || undefined;
17 + this.password = options.password || undefined;
18 + this.database = options.database;
19 + this.connectTimeout = (options.connectTimeout === undefined)
20 + ? (10 * 1000)
21 + : options.connectTimeout;
22 + this.insecureAuth = options.insecureAuth || false;
23 + this.supportBigNumbers = options.supportBigNumbers || false;
24 + this.bigNumberStrings = options.bigNumberStrings || false;
25 + this.dateStrings = options.dateStrings || false;
26 + this.debug = options.debug;
27 + this.trace = options.trace !== false;
28 + this.stringifyObjects = options.stringifyObjects || false;
29 + this.timezone = options.timezone || 'local';
30 + this.flags = options.flags || '';
31 + this.queryFormat = options.queryFormat;
32 + this.pool = options.pool || undefined;
33 + this.ssl = (typeof options.ssl === 'string')
34 + ? ConnectionConfig.getSSLProfile(options.ssl)
35 + : (options.ssl || false);
36 + this.localInfile = (options.localInfile === undefined)
37 + ? true
38 + : options.localInfile;
39 + this.multipleStatements = options.multipleStatements || false;
40 + this.typeCast = (options.typeCast === undefined)
41 + ? true
42 + : options.typeCast;
43 +
44 + if (this.timezone[0] === ' ') {
45 + // "+" is a url encoded char for space so it
46 + // gets translated to space when giving a
47 + // connection string..
48 + this.timezone = '+' + this.timezone.substr(1);
49 + }
50 +
51 + if (this.ssl) {
52 + // Default rejectUnauthorized to true
53 + this.ssl.rejectUnauthorized = this.ssl.rejectUnauthorized !== false;
54 + }
55 +
56 + this.maxPacketSize = 0;
57 + this.charsetNumber = (options.charset)
58 + ? ConnectionConfig.getCharsetNumber(options.charset)
59 + : options.charsetNumber || Charsets.UTF8_GENERAL_CI;
60 +
61 + // Set the client flags
62 + var defaultFlags = ConnectionConfig.getDefaultFlags(options);
63 + this.clientFlags = ConnectionConfig.mergeFlags(defaultFlags, options.flags);
64 +}
65 +
66 +ConnectionConfig.mergeFlags = function mergeFlags(defaultFlags, userFlags) {
67 + var allFlags = ConnectionConfig.parseFlagList(defaultFlags);
68 + var newFlags = ConnectionConfig.parseFlagList(userFlags);
69 +
70 + // Merge the new flags
71 + for (var flag in newFlags) {
72 + if (allFlags[flag] !== false) {
73 + allFlags[flag] = newFlags[flag];
74 + }
75 + }
76 +
77 + // Build flags
78 + var flags = 0x0;
79 + for (var flag in allFlags) {
80 + if (allFlags[flag]) {
81 + // TODO: Throw here on some future release
82 + flags |= ClientConstants['CLIENT_' + flag] || 0x0;
83 + }
84 + }
85 +
86 + return flags;
87 +};
88 +
89 +ConnectionConfig.getCharsetNumber = function getCharsetNumber(charset) {
90 + var num = Charsets[charset.toUpperCase()];
91 +
92 + if (num === undefined) {
93 + throw new TypeError('Unknown charset \'' + charset + '\'');
94 + }
95 +
96 + return num;
97 +};
98 +
99 +ConnectionConfig.getDefaultFlags = function getDefaultFlags(options) {
100 + var defaultFlags = [
101 + '-COMPRESS', // Compression protocol *NOT* supported
102 + '-CONNECT_ATTRS', // Does *NOT* send connection attributes in Protocol::HandshakeResponse41
103 + '+CONNECT_WITH_DB', // One can specify db on connect in Handshake Response Packet
104 + '+FOUND_ROWS', // Send found rows instead of affected rows
105 + '+IGNORE_SIGPIPE', // Don't issue SIGPIPE if network failures
106 + '+IGNORE_SPACE', // Let the parser ignore spaces before '('
107 + '+LOCAL_FILES', // Can use LOAD DATA LOCAL
108 + '+LONG_FLAG', // Longer flags in Protocol::ColumnDefinition320
109 + '+LONG_PASSWORD', // Use the improved version of Old Password Authentication
110 + '+MULTI_RESULTS', // Can handle multiple resultsets for COM_QUERY
111 + '+ODBC', // Special handling of ODBC behaviour
112 + '-PLUGIN_AUTH', // Does *NOT* support auth plugins
113 + '+PROTOCOL_41', // Uses the 4.1 protocol
114 + '+PS_MULTI_RESULTS', // Can handle multiple resultsets for COM_STMT_EXECUTE
115 + '+RESERVED', // Unused
116 + '+SECURE_CONNECTION', // Supports Authentication::Native41
117 + '+TRANSACTIONS' // Expects status flags
118 + ];
119 +
120 + if (options && options.localInfile !== undefined && !options.localInfile) {
121 + // Disable LOCAL modifier for LOAD DATA INFILE
122 + defaultFlags.push('-LOCAL_FILES');
123 + }
124 +
125 + if (options && options.multipleStatements) {
126 + // May send multiple statements per COM_QUERY and COM_STMT_PREPARE
127 + defaultFlags.push('+MULTI_STATEMENTS');
128 + }
129 +
130 + return defaultFlags;
131 +};
132 +
133 +ConnectionConfig.getSSLProfile = function getSSLProfile(name) {
134 + if (!SSLProfiles) {
135 + SSLProfiles = require('./protocol/constants/ssl_profiles');
136 + }
137 +
138 + var ssl = SSLProfiles[name];
139 +
140 + if (ssl === undefined) {
141 + throw new TypeError('Unknown SSL profile \'' + name + '\'');
142 + }
143 +
144 + return ssl;
145 +};
146 +
147 +ConnectionConfig.parseFlagList = function parseFlagList(flagList) {
148 + var allFlags = Object.create(null);
149 +
150 + if (!flagList) {
151 + return allFlags;
152 + }
153 +
154 + var flags = !Array.isArray(flagList)
155 + ? String(flagList || '').toUpperCase().split(/\s*,+\s*/)
156 + : flagList;
157 +
158 + for (var i = 0; i < flags.length; i++) {
159 + var flag = flags[i];
160 + var offset = 1;
161 + var state = flag[0];
162 +
163 + if (state === undefined) {
164 + // TODO: throw here on some future release
165 + continue;
166 + }
167 +
168 + if (state !== '-' && state !== '+') {
169 + offset = 0;
170 + state = '+';
171 + }
172 +
173 + allFlags[flag.substr(offset)] = state === '+';
174 + }
175 +
176 + return allFlags;
177 +};
178 +
179 +ConnectionConfig.parseUrl = function(url) {
180 + url = urlParse(url, true);
181 +
182 + var options = {
183 + host : url.hostname,
184 + port : url.port,
185 + database : url.pathname.substr(1)
186 + };
187 +
188 + if (url.auth) {
189 + var auth = url.auth.split(':');
190 + options.user = auth.shift();
191 + options.password = auth.join(':');
192 + }
193 +
194 + if (url.query) {
195 + for (var key in url.query) {
196 + var value = url.query[key];
197 +
198 + try {
199 + // Try to parse this as a JSON expression first
200 + options[key] = JSON.parse(value);
201 + } catch (err) {
202 + // Otherwise assume it is a plain string
203 + options[key] = value;
204 + }
205 + }
206 + }
207 +
208 + return options;
209 +};
1 +var mysql = require('../');
2 +var Connection = require('./Connection');
3 +var EventEmitter = require('events').EventEmitter;
4 +var Util = require('util');
5 +var PoolConnection = require('./PoolConnection');
6 +
7 +module.exports = Pool;
8 +
9 +Util.inherits(Pool, EventEmitter);
10 +function Pool(options) {
11 + EventEmitter.call(this);
12 + this.config = options.config;
13 + this.config.connectionConfig.pool = this;
14 +
15 + this._acquiringConnections = [];
16 + this._allConnections = [];
17 + this._freeConnections = [];
18 + this._connectionQueue = [];
19 + this._closed = false;
20 +}
21 +
22 +Pool.prototype.getConnection = function (cb) {
23 +
24 + if (this._closed) {
25 + var err = new Error('Pool is closed.');
26 + err.code = 'POOL_CLOSED';
27 + process.nextTick(function () {
28 + cb(err);
29 + });
30 + return;
31 + }
32 +
33 + var connection;
34 + var pool = this;
35 +
36 + if (this._freeConnections.length > 0) {
37 + connection = this._freeConnections.shift();
38 + this.acquireConnection(connection, cb);
39 + return;
40 + }
41 +
42 + if (this.config.connectionLimit === 0 || this._allConnections.length < this.config.connectionLimit) {
43 + connection = new PoolConnection(this, { config: this.config.newConnectionConfig() });
44 +
45 + this._acquiringConnections.push(connection);
46 + this._allConnections.push(connection);
47 +
48 + connection.connect({timeout: this.config.acquireTimeout}, function onConnect(err) {
49 + spliceConnection(pool._acquiringConnections, connection);
50 +
51 + if (pool._closed) {
52 + err = new Error('Pool is closed.');
53 + err.code = 'POOL_CLOSED';
54 + }
55 +
56 + if (err) {
57 + pool._purgeConnection(connection);
58 + cb(err);
59 + return;
60 + }
61 +
62 + pool.emit('connection', connection);
63 + pool.emit('acquire', connection);
64 + cb(null, connection);
65 + });
66 + return;
67 + }
68 +
69 + if (!this.config.waitForConnections) {
70 + process.nextTick(function(){
71 + var err = new Error('No connections available.');
72 + err.code = 'POOL_CONNLIMIT';
73 + cb(err);
74 + });
75 + return;
76 + }
77 +
78 + this._enqueueCallback(cb);
79 +};
80 +
81 +Pool.prototype.acquireConnection = function acquireConnection(connection, cb) {
82 + if (connection._pool !== this) {
83 + throw new Error('Connection acquired from wrong pool.');
84 + }
85 +
86 + var changeUser = this._needsChangeUser(connection);
87 + var pool = this;
88 +
89 + this._acquiringConnections.push(connection);
90 +
91 + function onOperationComplete(err) {
92 + spliceConnection(pool._acquiringConnections, connection);
93 +
94 + if (pool._closed) {
95 + err = new Error('Pool is closed.');
96 + err.code = 'POOL_CLOSED';
97 + }
98 +
99 + if (err) {
100 + pool._connectionQueue.unshift(cb);
101 + pool._purgeConnection(connection);
102 + return;
103 + }
104 +
105 + if (changeUser) {
106 + pool.emit('connection', connection);
107 + }
108 +
109 + pool.emit('acquire', connection);
110 + cb(null, connection);
111 + }
112 +
113 + if (changeUser) {
114 + // restore user back to pool configuration
115 + connection.config = this.config.newConnectionConfig();
116 + connection.changeUser({timeout: this.config.acquireTimeout}, onOperationComplete);
117 + } else {
118 + // ping connection
119 + connection.ping({timeout: this.config.acquireTimeout}, onOperationComplete);
120 + }
121 +};
122 +
123 +Pool.prototype.releaseConnection = function releaseConnection(connection) {
124 +
125 + if (this._acquiringConnections.indexOf(connection) !== -1) {
126 + // connection is being acquired
127 + return;
128 + }
129 +
130 + if (connection._pool) {
131 + if (connection._pool !== this) {
132 + throw new Error('Connection released to wrong pool');
133 + }
134 +
135 + if (this._freeConnections.indexOf(connection) !== -1) {
136 + // connection already in free connection pool
137 + // this won't catch all double-release cases
138 + throw new Error('Connection already released');
139 + } else {
140 + // add connection to end of free queue
141 + this._freeConnections.push(connection);
142 + this.emit('release', connection);
143 + }
144 + }
145 +
146 + if (this._closed) {
147 + // empty the connection queue
148 + this._connectionQueue.splice(0).forEach(function (cb) {
149 + var err = new Error('Pool is closed.');
150 + err.code = 'POOL_CLOSED';
151 + process.nextTick(function () {
152 + cb(err);
153 + });
154 + });
155 + } else if (this._connectionQueue.length) {
156 + // get connection with next waiting callback
157 + this.getConnection(this._connectionQueue.shift());
158 + }
159 +};
160 +
161 +Pool.prototype.end = function (cb) {
162 + this._closed = true;
163 +
164 + if (typeof cb !== 'function') {
165 + cb = function (err) {
166 + if (err) throw err;
167 + };
168 + }
169 +
170 + var calledBack = false;
171 + var waitingClose = 0;
172 +
173 + function onEnd(err) {
174 + if (!calledBack && (err || --waitingClose <= 0)) {
175 + calledBack = true;
176 + cb(err);
177 + }
178 + }
179 +
180 + while (this._allConnections.length !== 0) {
181 + waitingClose++;
182 + this._purgeConnection(this._allConnections[0], onEnd);
183 + }
184 +
185 + if (waitingClose === 0) {
186 + process.nextTick(onEnd);
187 + }
188 +};
189 +
190 +Pool.prototype.query = function (sql, values, cb) {
191 + var query = Connection.createQuery(sql, values, cb);
192 +
193 + if (!(typeof sql === 'object' && 'typeCast' in sql)) {
194 + query.typeCast = this.config.connectionConfig.typeCast;
195 + }
196 +
197 + if (this.config.connectionConfig.trace) {
198 + // Long stack trace support
199 + query._callSite = new Error();
200 + }
201 +
202 + this.getConnection(function (err, conn) {
203 + if (err) {
204 + query.on('error', function () {});
205 + query.end(err);
206 + return;
207 + }
208 +
209 + // Release connection based off event
210 + query.once('end', function() {
211 + conn.release();
212 + });
213 +
214 + conn.query(query);
215 + });
216 +
217 + return query;
218 +};
219 +
220 +Pool.prototype._enqueueCallback = function _enqueueCallback(callback) {
221 +
222 + if (this.config.queueLimit && this._connectionQueue.length >= this.config.queueLimit) {
223 + process.nextTick(function () {
224 + var err = new Error('Queue limit reached.');
225 + err.code = 'POOL_ENQUEUELIMIT';
226 + callback(err);
227 + });
228 + return;
229 + }
230 +
231 + // Bind to domain, as dequeue will likely occur in a different domain
232 + var cb = process.domain
233 + ? process.domain.bind(callback)
234 + : callback;
235 +
236 + this._connectionQueue.push(cb);
237 + this.emit('enqueue');
238 +};
239 +
240 +Pool.prototype._needsChangeUser = function _needsChangeUser(connection) {
241 + var connConfig = connection.config;
242 + var poolConfig = this.config.connectionConfig;
243 +
244 + // check if changeUser values are different
245 + return connConfig.user !== poolConfig.user
246 + || connConfig.database !== poolConfig.database
247 + || connConfig.password !== poolConfig.password
248 + || connConfig.charsetNumber !== poolConfig.charsetNumber;
249 +};
250 +
251 +Pool.prototype._purgeConnection = function _purgeConnection(connection, callback) {
252 + var cb = callback || function () {};
253 +
254 + if (connection.state === 'disconnected') {
255 + connection.destroy();
256 + }
257 +
258 + this._removeConnection(connection);
259 +
260 + if (connection.state !== 'disconnected' && !connection._protocol._quitSequence) {
261 + connection._realEnd(cb);
262 + return;
263 + }
264 +
265 + process.nextTick(cb);
266 +};
267 +
268 +Pool.prototype._removeConnection = function(connection) {
269 + connection._pool = null;
270 +
271 + // Remove connection from all connections
272 + spliceConnection(this._allConnections, connection);
273 +
274 + // Remove connection from free connections
275 + spliceConnection(this._freeConnections, connection);
276 +
277 + this.releaseConnection(connection);
278 +};
279 +
280 +Pool.prototype.escape = function(value) {
281 + return mysql.escape(value, this.config.connectionConfig.stringifyObjects, this.config.connectionConfig.timezone);
282 +};
283 +
284 +Pool.prototype.escapeId = function escapeId(value) {
285 + return mysql.escapeId(value, false);
286 +};
287 +
288 +function spliceConnection(array, connection) {
289 + var index;
290 + if ((index = array.indexOf(connection)) !== -1) {
291 + // Remove connection from all connections
292 + array.splice(index, 1);
293 + }
294 +}
1 +var Pool = require('./Pool');
2 +var PoolConfig = require('./PoolConfig');
3 +var PoolNamespace = require('./PoolNamespace');
4 +var PoolSelector = require('./PoolSelector');
5 +var Util = require('util');
6 +var EventEmitter = require('events').EventEmitter;
7 +
8 +module.exports = PoolCluster;
9 +
10 +/**
11 + * PoolCluster
12 + * @constructor
13 + * @param {object} [config] The pool cluster configuration
14 + * @public
15 + */
16 +function PoolCluster(config) {
17 + EventEmitter.call(this);
18 +
19 + config = config || {};
20 + this._canRetry = typeof config.canRetry === 'undefined' ? true : config.canRetry;
21 + this._defaultSelector = config.defaultSelector || 'RR';
22 + this._removeNodeErrorCount = config.removeNodeErrorCount || 5;
23 + this._restoreNodeTimeout = config.restoreNodeTimeout || 0;
24 +
25 + this._closed = false;
26 + this._findCaches = Object.create(null);
27 + this._lastId = 0;
28 + this._namespaces = Object.create(null);
29 + this._nodes = Object.create(null);
30 +}
31 +
32 +Util.inherits(PoolCluster, EventEmitter);
33 +
34 +PoolCluster.prototype.add = function add(id, config) {
35 + if (this._closed) {
36 + throw new Error('PoolCluster is closed.');
37 + }
38 +
39 + var nodeId = typeof id === 'object'
40 + ? 'CLUSTER::' + (++this._lastId)
41 + : String(id);
42 +
43 + if (this._nodes[nodeId] !== undefined) {
44 + throw new Error('Node ID "' + nodeId + '" is already defined in PoolCluster.');
45 + }
46 +
47 + var poolConfig = typeof id !== 'object'
48 + ? new PoolConfig(config)
49 + : new PoolConfig(id);
50 +
51 + this._nodes[nodeId] = {
52 + id : nodeId,
53 + errorCount : 0,
54 + pool : new Pool({config: poolConfig}),
55 + _offlineUntil : 0
56 + };
57 +
58 + this._clearFindCaches();
59 +};
60 +
61 +PoolCluster.prototype.end = function end(callback) {
62 + var cb = callback !== undefined
63 + ? callback
64 + : _cb;
65 +
66 + if (typeof cb !== 'function') {
67 + throw TypeError('callback argument must be a function');
68 + }
69 +
70 + if (this._closed) {
71 + process.nextTick(cb);
72 + return;
73 + }
74 +
75 + this._closed = true;
76 +
77 + var calledBack = false;
78 + var nodeIds = Object.keys(this._nodes);
79 + var waitingClose = 0;
80 +
81 + function onEnd(err) {
82 + if (!calledBack && (err || --waitingClose <= 0)) {
83 + calledBack = true;
84 + cb(err);
85 + }
86 + }
87 +
88 + for (var i = 0; i < nodeIds.length; i++) {
89 + var nodeId = nodeIds[i];
90 + var node = this._nodes[nodeId];
91 +
92 + waitingClose++;
93 + node.pool.end(onEnd);
94 + }
95 +
96 + if (waitingClose === 0) {
97 + process.nextTick(onEnd);
98 + }
99 +};
100 +
101 +PoolCluster.prototype.of = function(pattern, selector) {
102 + pattern = pattern || '*';
103 +
104 + selector = selector || this._defaultSelector;
105 + selector = selector.toUpperCase();
106 + if (typeof PoolSelector[selector] === 'undefined') {
107 + selector = this._defaultSelector;
108 + }
109 +
110 + var key = pattern + selector;
111 +
112 + if (typeof this._namespaces[key] === 'undefined') {
113 + this._namespaces[key] = new PoolNamespace(this, pattern, selector);
114 + }
115 +
116 + return this._namespaces[key];
117 +};
118 +
119 +PoolCluster.prototype.remove = function remove(pattern) {
120 + var foundNodeIds = this._findNodeIds(pattern, true);
121 +
122 + for (var i = 0; i < foundNodeIds.length; i++) {
123 + var node = this._getNode(foundNodeIds[i]);
124 +
125 + if (node) {
126 + this._removeNode(node);
127 + }
128 + }
129 +};
130 +
131 +PoolCluster.prototype.getConnection = function(pattern, selector, cb) {
132 + var namespace;
133 + if (typeof pattern === 'function') {
134 + cb = pattern;
135 + namespace = this.of();
136 + } else {
137 + if (typeof selector === 'function') {
138 + cb = selector;
139 + selector = this._defaultSelector;
140 + }
141 +
142 + namespace = this.of(pattern, selector);
143 + }
144 +
145 + namespace.getConnection(cb);
146 +};
147 +
148 +PoolCluster.prototype._clearFindCaches = function _clearFindCaches() {
149 + this._findCaches = Object.create(null);
150 +};
151 +
152 +PoolCluster.prototype._decreaseErrorCount = function _decreaseErrorCount(node) {
153 + var errorCount = node.errorCount;
154 +
155 + if (errorCount > this._removeNodeErrorCount) {
156 + errorCount = this._removeNodeErrorCount;
157 + }
158 +
159 + if (errorCount < 1) {
160 + errorCount = 1;
161 + }
162 +
163 + node.errorCount = errorCount - 1;
164 +
165 + if (node._offlineUntil) {
166 + node._offlineUntil = 0;
167 + this.emit('online', node.id);
168 + }
169 +};
170 +
171 +PoolCluster.prototype._findNodeIds = function _findNodeIds(pattern, includeOffline) {
172 + var currentTime = 0;
173 + var foundNodeIds = this._findCaches[pattern];
174 +
175 + if (foundNodeIds === undefined) {
176 + var expression = patternRegExp(pattern);
177 + var nodeIds = Object.keys(this._nodes);
178 +
179 + foundNodeIds = nodeIds.filter(function (id) {
180 + return id.match(expression);
181 + });
182 +
183 + this._findCaches[pattern] = foundNodeIds;
184 + }
185 +
186 + if (includeOffline) {
187 + return foundNodeIds;
188 + }
189 +
190 + return foundNodeIds.filter(function (nodeId) {
191 + var node = this._getNode(nodeId);
192 +
193 + if (!node._offlineUntil) {
194 + return true;
195 + }
196 +
197 + if (!currentTime) {
198 + currentTime = getMonotonicMilliseconds();
199 + }
200 +
201 + return node._offlineUntil <= currentTime;
202 + }, this);
203 +};
204 +
205 +PoolCluster.prototype._getNode = function _getNode(id) {
206 + return this._nodes[id] || null;
207 +};
208 +
209 +PoolCluster.prototype._increaseErrorCount = function _increaseErrorCount(node) {
210 + var errorCount = ++node.errorCount;
211 +
212 + if (this._removeNodeErrorCount > errorCount) {
213 + return;
214 + }
215 +
216 + if (this._restoreNodeTimeout > 0) {
217 + node._offlineUntil = getMonotonicMilliseconds() + this._restoreNodeTimeout;
218 + this.emit('offline', node.id);
219 + return;
220 + }
221 +
222 + this._removeNode(node);
223 + this.emit('remove', node.id);
224 +};
225 +
226 +PoolCluster.prototype._getConnection = function(node, cb) {
227 + var self = this;
228 +
229 + node.pool.getConnection(function (err, connection) {
230 + if (err) {
231 + self._increaseErrorCount(node);
232 + cb(err);
233 + return;
234 + } else {
235 + self._decreaseErrorCount(node);
236 + }
237 +
238 + connection._clusterId = node.id;
239 +
240 + cb(null, connection);
241 + });
242 +};
243 +
244 +PoolCluster.prototype._removeNode = function _removeNode(node) {
245 + delete this._nodes[node.id];
246 +
247 + this._clearFindCaches();
248 +
249 + node.pool.end(_noop);
250 +};
251 +
252 +function getMonotonicMilliseconds() {
253 + var ms;
254 +
255 + if (typeof process.hrtime === 'function') {
256 + ms = process.hrtime();
257 + ms = ms[0] * 1e3 + ms[1] * 1e-6;
258 + } else {
259 + ms = process.uptime() * 1000;
260 + }
261 +
262 + return Math.floor(ms);
263 +}
264 +
265 +function isRegExp(val) {
266 + return typeof val === 'object'
267 + && Object.prototype.toString.call(val) === '[object RegExp]';
268 +}
269 +
270 +function patternRegExp(pattern) {
271 + if (isRegExp(pattern)) {
272 + return pattern;
273 + }
274 +
275 + var source = pattern
276 + .replace(/([.+?^=!:${}()|\[\]\/\\])/g, '\\$1')
277 + .replace(/\*/g, '.*');
278 +
279 + return new RegExp('^' + source + '$');
280 +}
281 +
282 +function _cb(err) {
283 + if (err) {
284 + throw err;
285 + }
286 +}
287 +
288 +function _noop() {}
1 +
2 +var ConnectionConfig = require('./ConnectionConfig');
3 +
4 +module.exports = PoolConfig;
5 +function PoolConfig(options) {
6 + if (typeof options === 'string') {
7 + options = ConnectionConfig.parseUrl(options);
8 + }
9 +
10 + this.acquireTimeout = (options.acquireTimeout === undefined)
11 + ? 10 * 1000
12 + : Number(options.acquireTimeout);
13 + this.connectionConfig = new ConnectionConfig(options);
14 + this.waitForConnections = (options.waitForConnections === undefined)
15 + ? true
16 + : Boolean(options.waitForConnections);
17 + this.connectionLimit = (options.connectionLimit === undefined)
18 + ? 10
19 + : Number(options.connectionLimit);
20 + this.queueLimit = (options.queueLimit === undefined)
21 + ? 0
22 + : Number(options.queueLimit);
23 +}
24 +
25 +PoolConfig.prototype.newConnectionConfig = function newConnectionConfig() {
26 + var connectionConfig = new ConnectionConfig(this.connectionConfig);
27 +
28 + connectionConfig.clientFlags = this.connectionConfig.clientFlags;
29 + connectionConfig.maxPacketSize = this.connectionConfig.maxPacketSize;
30 +
31 + return connectionConfig;
32 +};
1 +var inherits = require('util').inherits;
2 +var Connection = require('./Connection');
3 +var Events = require('events');
4 +
5 +module.exports = PoolConnection;
6 +inherits(PoolConnection, Connection);
7 +
8 +function PoolConnection(pool, options) {
9 + Connection.call(this, options);
10 + this._pool = pool;
11 +
12 + // Bind connection to pool domain
13 + if (Events.usingDomains) {
14 + this.domain = pool.domain;
15 + }
16 +
17 + // When a fatal error occurs the connection's protocol ends, which will cause
18 + // the connection to end as well, thus we only need to watch for the end event
19 + // and we will be notified of disconnects.
20 + this.on('end', this._removeFromPool);
21 + this.on('error', function (err) {
22 + if (err.fatal) {
23 + this._removeFromPool();
24 + }
25 + });
26 +}
27 +
28 +PoolConnection.prototype.release = function release() {
29 + var pool = this._pool;
30 +
31 + if (!pool || pool._closed) {
32 + return undefined;
33 + }
34 +
35 + return pool.releaseConnection(this);
36 +};
37 +
38 +// TODO: Remove this when we are removing PoolConnection#end
39 +PoolConnection.prototype._realEnd = Connection.prototype.end;
40 +
41 +PoolConnection.prototype.end = function () {
42 + console.warn(
43 + 'Calling conn.end() to release a pooled connection is ' +
44 + 'deprecated. In next version calling conn.end() will be ' +
45 + 'restored to default conn.end() behavior. Use ' +
46 + 'conn.release() instead.'
47 + );
48 + this.release();
49 +};
50 +
51 +PoolConnection.prototype.destroy = function () {
52 + Connection.prototype.destroy.apply(this, arguments);
53 + this._removeFromPool(this);
54 +};
55 +
56 +PoolConnection.prototype._removeFromPool = function _removeFromPool() {
57 + if (!this._pool || this._pool._closed) {
58 + return;
59 + }
60 +
61 + var pool = this._pool;
62 + this._pool = null;
63 +
64 + pool._purgeConnection(this);
65 +};
1 +var Connection = require('./Connection');
2 +var PoolSelector = require('./PoolSelector');
3 +
4 +module.exports = PoolNamespace;
5 +
6 +/**
7 + * PoolNamespace
8 + * @constructor
9 + * @param {PoolCluster} cluster The parent cluster for the namespace
10 + * @param {string} pattern The selection pattern to use
11 + * @param {string} selector The selector name to use
12 + * @public
13 + */
14 +function PoolNamespace(cluster, pattern, selector) {
15 + this._cluster = cluster;
16 + this._pattern = pattern;
17 + this._selector = new PoolSelector[selector]();
18 +}
19 +
20 +PoolNamespace.prototype.getConnection = function(cb) {
21 + var clusterNode = this._getClusterNode();
22 + var cluster = this._cluster;
23 + var namespace = this;
24 +
25 + if (clusterNode === null) {
26 + var err = null;
27 +
28 + if (this._cluster._findNodeIds(this._pattern, true).length !== 0) {
29 + err = new Error('Pool does not have online node.');
30 + err.code = 'POOL_NONEONLINE';
31 + } else {
32 + err = new Error('Pool does not exist.');
33 + err.code = 'POOL_NOEXIST';
34 + }
35 +
36 + cb(err);
37 + return;
38 + }
39 +
40 + cluster._getConnection(clusterNode, function(err, connection) {
41 + var retry = err && cluster._canRetry
42 + && cluster._findNodeIds(namespace._pattern).length !== 0;
43 +
44 + if (retry) {
45 + namespace.getConnection(cb);
46 + return;
47 + }
48 +
49 + if (err) {
50 + cb(err);
51 + return;
52 + }
53 +
54 + cb(null, connection);
55 + });
56 +};
57 +
58 +PoolNamespace.prototype.query = function (sql, values, cb) {
59 + var cluster = this._cluster;
60 + var clusterNode = this._getClusterNode();
61 + var query = Connection.createQuery(sql, values, cb);
62 + var namespace = this;
63 +
64 + if (clusterNode === null) {
65 + var err = null;
66 +
67 + if (this._cluster._findNodeIds(this._pattern, true).length !== 0) {
68 + err = new Error('Pool does not have online node.');
69 + err.code = 'POOL_NONEONLINE';
70 + } else {
71 + err = new Error('Pool does not exist.');
72 + err.code = 'POOL_NOEXIST';
73 + }
74 +
75 + process.nextTick(function () {
76 + query.on('error', function () {});
77 + query.end(err);
78 + });
79 + return query;
80 + }
81 +
82 + if (!(typeof sql === 'object' && 'typeCast' in sql)) {
83 + query.typeCast = clusterNode.pool.config.connectionConfig.typeCast;
84 + }
85 +
86 + if (clusterNode.pool.config.connectionConfig.trace) {
87 + // Long stack trace support
88 + query._callSite = new Error();
89 + }
90 +
91 + cluster._getConnection(clusterNode, function (err, conn) {
92 + var retry = err && cluster._canRetry
93 + && cluster._findNodeIds(namespace._pattern).length !== 0;
94 +
95 + if (retry) {
96 + namespace.query(query);
97 + return;
98 + }
99 +
100 + if (err) {
101 + query.on('error', function () {});
102 + query.end(err);
103 + return;
104 + }
105 +
106 + // Release connection based off event
107 + query.once('end', function() {
108 + conn.release();
109 + });
110 +
111 + conn.query(query);
112 + });
113 +
114 + return query;
115 +};
116 +
117 +PoolNamespace.prototype._getClusterNode = function _getClusterNode() {
118 + var foundNodeIds = this._cluster._findNodeIds(this._pattern);
119 + var nodeId;
120 +
121 + switch (foundNodeIds.length) {
122 + case 0:
123 + nodeId = null;
124 + break;
125 + case 1:
126 + nodeId = foundNodeIds[0];
127 + break;
128 + default:
129 + nodeId = this._selector(foundNodeIds);
130 + break;
131 + }
132 +
133 + return nodeId !== null
134 + ? this._cluster._getNode(nodeId)
135 + : null;
136 +};
1 +
2 +/**
3 + * PoolSelector
4 + */
5 +var PoolSelector = module.exports = {};
6 +
7 +PoolSelector.RR = function PoolSelectorRoundRobin() {
8 + var index = 0;
9 +
10 + return function(clusterIds) {
11 + if (index >= clusterIds.length) {
12 + index = 0;
13 + }
14 +
15 + var clusterId = clusterIds[index++];
16 +
17 + return clusterId;
18 + };
19 +};
20 +
21 +PoolSelector.RANDOM = function PoolSelectorRandom() {
22 + return function(clusterIds) {
23 + return clusterIds[Math.floor(Math.random() * clusterIds.length)];
24 + };
25 +};
26 +
27 +PoolSelector.ORDER = function PoolSelectorOrder() {
28 + return function(clusterIds) {
29 + return clusterIds[0];
30 + };
31 +};
1 +var Buffer = require('safe-buffer').Buffer;
2 +var Crypto = require('crypto');
3 +var Auth = exports;
4 +
5 +function auth(name, data, options) {
6 + options = options || {};
7 +
8 + switch (name) {
9 + case 'mysql_native_password':
10 + return Auth.token(options.password, data.slice(0, 20));
11 + default:
12 + return undefined;
13 + }
14 +}
15 +Auth.auth = auth;
16 +
17 +function sha1(msg) {
18 + var hash = Crypto.createHash('sha1');
19 + hash.update(msg, 'binary');
20 + return hash.digest('binary');
21 +}
22 +Auth.sha1 = sha1;
23 +
24 +function xor(a, b) {
25 + a = Buffer.from(a, 'binary');
26 + b = Buffer.from(b, 'binary');
27 + var result = Buffer.allocUnsafe(a.length);
28 + for (var i = 0; i < a.length; i++) {
29 + result[i] = (a[i] ^ b[i]);
30 + }
31 + return result;
32 +}
33 +Auth.xor = xor;
34 +
35 +Auth.token = function(password, scramble) {
36 + if (!password) {
37 + return Buffer.alloc(0);
38 + }
39 +
40 + // password must be in binary format, not utf8
41 + var stage1 = sha1((Buffer.from(password, 'utf8')).toString('binary'));
42 + var stage2 = sha1(stage1);
43 + var stage3 = sha1(scramble.toString('binary') + stage2);
44 + return xor(stage3, stage1);
45 +};
46 +
47 +// This is a port of sql/password.c:hash_password which needs to be used for
48 +// pre-4.1 passwords.
49 +Auth.hashPassword = function(password) {
50 + var nr = [0x5030, 0x5735];
51 + var add = 7;
52 + var nr2 = [0x1234, 0x5671];
53 + var result = Buffer.alloc(8);
54 +
55 + if (typeof password === 'string'){
56 + password = Buffer.from(password);
57 + }
58 +
59 + for (var i = 0; i < password.length; i++) {
60 + var c = password[i];
61 + if (c === 32 || c === 9) {
62 + // skip space in password
63 + continue;
64 + }
65 +
66 + // nr^= (((nr & 63)+add)*c)+ (nr << 8);
67 + // nr = xor(nr, add(mul(add(and(nr, 63), add), c), shl(nr, 8)))
68 + nr = this.xor32(nr, this.add32(this.mul32(this.add32(this.and32(nr, [0, 63]), [0, add]), [0, c]), this.shl32(nr, 8)));
69 +
70 + // nr2+=(nr2 << 8) ^ nr;
71 + // nr2 = add(nr2, xor(shl(nr2, 8), nr))
72 + nr2 = this.add32(nr2, this.xor32(this.shl32(nr2, 8), nr));
73 +
74 + // add+=tmp;
75 + add += c;
76 + }
77 +
78 + this.int31Write(result, nr, 0);
79 + this.int31Write(result, nr2, 4);
80 +
81 + return result;
82 +};
83 +
84 +Auth.randomInit = function(seed1, seed2) {
85 + return {
86 + max_value : 0x3FFFFFFF,
87 + max_value_dbl : 0x3FFFFFFF,
88 + seed1 : seed1 % 0x3FFFFFFF,
89 + seed2 : seed2 % 0x3FFFFFFF
90 + };
91 +};
92 +
93 +Auth.myRnd = function(r){
94 + r.seed1 = (r.seed1 * 3 + r.seed2) % r.max_value;
95 + r.seed2 = (r.seed1 + r.seed2 + 33) % r.max_value;
96 +
97 + return r.seed1 / r.max_value_dbl;
98 +};
99 +
100 +Auth.scramble323 = function(message, password) {
101 + if (!password) {
102 + return Buffer.alloc(0);
103 + }
104 +
105 + var to = Buffer.allocUnsafe(8);
106 + var hashPass = this.hashPassword(password);
107 + var hashMessage = this.hashPassword(message.slice(0, 8));
108 + var seed1 = this.int32Read(hashPass, 0) ^ this.int32Read(hashMessage, 0);
109 + var seed2 = this.int32Read(hashPass, 4) ^ this.int32Read(hashMessage, 4);
110 + var r = this.randomInit(seed1, seed2);
111 +
112 + for (var i = 0; i < 8; i++){
113 + to[i] = Math.floor(this.myRnd(r) * 31) + 64;
114 + }
115 + var extra = (Math.floor(this.myRnd(r) * 31));
116 +
117 + for (var i = 0; i < 8; i++){
118 + to[i] ^= extra;
119 + }
120 +
121 + return to;
122 +};
123 +
124 +Auth.xor32 = function(a, b){
125 + return [a[0] ^ b[0], a[1] ^ b[1]];
126 +};
127 +
128 +Auth.add32 = function(a, b){
129 + var w1 = a[1] + b[1];
130 + var w2 = a[0] + b[0] + ((w1 & 0xFFFF0000) >> 16);
131 +
132 + return [w2 & 0xFFFF, w1 & 0xFFFF];
133 +};
134 +
135 +Auth.mul32 = function(a, b){
136 + // based on this example of multiplying 32b ints using 16b
137 + // http://www.dsprelated.com/showmessage/89790/1.php
138 + var w1 = a[1] * b[1];
139 + var w2 = (((a[1] * b[1]) >> 16) & 0xFFFF) + ((a[0] * b[1]) & 0xFFFF) + (a[1] * b[0] & 0xFFFF);
140 +
141 + return [w2 & 0xFFFF, w1 & 0xFFFF];
142 +};
143 +
144 +Auth.and32 = function(a, b){
145 + return [a[0] & b[0], a[1] & b[1]];
146 +};
147 +
148 +Auth.shl32 = function(a, b){
149 + // assume b is 16 or less
150 + var w1 = a[1] << b;
151 + var w2 = (a[0] << b) | ((w1 & 0xFFFF0000) >> 16);
152 +
153 + return [w2 & 0xFFFF, w1 & 0xFFFF];
154 +};
155 +
156 +Auth.int31Write = function(buffer, number, offset) {
157 + buffer[offset] = (number[0] >> 8) & 0x7F;
158 + buffer[offset + 1] = (number[0]) & 0xFF;
159 + buffer[offset + 2] = (number[1] >> 8) & 0xFF;
160 + buffer[offset + 3] = (number[1]) & 0xFF;
161 +};
162 +
163 +Auth.int32Read = function(buffer, offset){
164 + return (buffer[offset] << 24)
165 + + (buffer[offset + 1] << 16)
166 + + (buffer[offset + 2] << 8)
167 + + (buffer[offset + 3]);
168 +};
1 +
2 +module.exports = BufferList;
3 +function BufferList() {
4 + this.bufs = [];
5 + this.size = 0;
6 +}
7 +
8 +BufferList.prototype.shift = function shift() {
9 + var buf = this.bufs.shift();
10 +
11 + if (buf) {
12 + this.size -= buf.length;
13 + }
14 +
15 + return buf;
16 +};
17 +
18 +BufferList.prototype.push = function push(buf) {
19 + if (!buf || !buf.length) {
20 + return;
21 + }
22 +
23 + this.bufs.push(buf);
24 + this.size += buf.length;
25 +};
1 +module.exports = PacketHeader;
2 +function PacketHeader(length, number) {
3 + this.length = length;
4 + this.number = number;
5 +}
1 +var BIT_16 = Math.pow(2, 16);
2 +var BIT_24 = Math.pow(2, 24);
3 +var BUFFER_ALLOC_SIZE = Math.pow(2, 8);
4 +// The maximum precision JS Numbers can hold precisely
5 +// Don't panic: Good enough to represent byte values up to 8192 TB
6 +var IEEE_754_BINARY_64_PRECISION = Math.pow(2, 53);
7 +var MAX_PACKET_LENGTH = Math.pow(2, 24) - 1;
8 +var Buffer = require('safe-buffer').Buffer;
9 +
10 +module.exports = PacketWriter;
11 +function PacketWriter() {
12 + this._buffer = null;
13 + this._offset = 0;
14 +}
15 +
16 +PacketWriter.prototype.toBuffer = function toBuffer(parser) {
17 + if (!this._buffer) {
18 + this._buffer = Buffer.alloc(0);
19 + this._offset = 0;
20 + }
21 +
22 + var buffer = this._buffer;
23 + var length = this._offset;
24 + var packets = Math.floor(length / MAX_PACKET_LENGTH) + 1;
25 +
26 + this._buffer = Buffer.allocUnsafe(length + packets * 4);
27 + this._offset = 0;
28 +
29 + for (var packet = 0; packet < packets; packet++) {
30 + var isLast = (packet + 1 === packets);
31 + var packetLength = (isLast)
32 + ? length % MAX_PACKET_LENGTH
33 + : MAX_PACKET_LENGTH;
34 +
35 + var packetNumber = parser.incrementPacketNumber();
36 +
37 + this.writeUnsignedNumber(3, packetLength);
38 + this.writeUnsignedNumber(1, packetNumber);
39 +
40 + var start = packet * MAX_PACKET_LENGTH;
41 + var end = start + packetLength;
42 +
43 + this.writeBuffer(buffer.slice(start, end));
44 + }
45 +
46 + return this._buffer;
47 +};
48 +
49 +PacketWriter.prototype.writeUnsignedNumber = function(bytes, value) {
50 + this._allocate(bytes);
51 +
52 + for (var i = 0; i < bytes; i++) {
53 + this._buffer[this._offset++] = (value >> (i * 8)) & 0xff;
54 + }
55 +};
56 +
57 +PacketWriter.prototype.writeFiller = function(bytes) {
58 + this._allocate(bytes);
59 +
60 + for (var i = 0; i < bytes; i++) {
61 + this._buffer[this._offset++] = 0x00;
62 + }
63 +};
64 +
65 +PacketWriter.prototype.writeNullTerminatedString = function(value, encoding) {
66 + // Typecast undefined into '' and numbers into strings
67 + value = value || '';
68 + value = value + '';
69 +
70 + var bytes = Buffer.byteLength(value, encoding || 'utf-8') + 1;
71 + this._allocate(bytes);
72 +
73 + this._buffer.write(value, this._offset, encoding);
74 + this._buffer[this._offset + bytes - 1] = 0x00;
75 +
76 + this._offset += bytes;
77 +};
78 +
79 +PacketWriter.prototype.writeString = function(value) {
80 + // Typecast undefined into '' and numbers into strings
81 + value = value || '';
82 + value = value + '';
83 +
84 + var bytes = Buffer.byteLength(value, 'utf-8');
85 + this._allocate(bytes);
86 +
87 + this._buffer.write(value, this._offset, 'utf-8');
88 +
89 + this._offset += bytes;
90 +};
91 +
92 +PacketWriter.prototype.writeBuffer = function(value) {
93 + var bytes = value.length;
94 +
95 + this._allocate(bytes);
96 + value.copy(this._buffer, this._offset);
97 + this._offset += bytes;
98 +};
99 +
100 +PacketWriter.prototype.writeLengthCodedNumber = function(value) {
101 + if (value === null) {
102 + this._allocate(1);
103 + this._buffer[this._offset++] = 251;
104 + return;
105 + }
106 +
107 + if (value <= 250) {
108 + this._allocate(1);
109 + this._buffer[this._offset++] = value;
110 + return;
111 + }
112 +
113 + if (value > IEEE_754_BINARY_64_PRECISION) {
114 + throw new Error(
115 + 'writeLengthCodedNumber: JS precision range exceeded, your ' +
116 + 'number is > 53 bit: "' + value + '"'
117 + );
118 + }
119 +
120 + if (value < BIT_16) {
121 + this._allocate(3);
122 + this._buffer[this._offset++] = 252;
123 + } else if (value < BIT_24) {
124 + this._allocate(4);
125 + this._buffer[this._offset++] = 253;
126 + } else {
127 + this._allocate(9);
128 + this._buffer[this._offset++] = 254;
129 + }
130 +
131 + // 16 Bit
132 + this._buffer[this._offset++] = value & 0xff;
133 + this._buffer[this._offset++] = (value >> 8) & 0xff;
134 +
135 + if (value < BIT_16) {
136 + return;
137 + }
138 +
139 + // 24 Bit
140 + this._buffer[this._offset++] = (value >> 16) & 0xff;
141 +
142 + if (value < BIT_24) {
143 + return;
144 + }
145 +
146 + this._buffer[this._offset++] = (value >> 24) & 0xff;
147 +
148 + // Hack: Get the most significant 32 bit (JS bitwise operators are 32 bit)
149 + value = value.toString(2);
150 + value = value.substr(0, value.length - 32);
151 + value = parseInt(value, 2);
152 +
153 + this._buffer[this._offset++] = value & 0xff;
154 + this._buffer[this._offset++] = (value >> 8) & 0xff;
155 + this._buffer[this._offset++] = (value >> 16) & 0xff;
156 +
157 + // Set last byte to 0, as we can only support 53 bits in JS (see above)
158 + this._buffer[this._offset++] = 0;
159 +};
160 +
161 +PacketWriter.prototype.writeLengthCodedBuffer = function(value) {
162 + var bytes = value.length;
163 + this.writeLengthCodedNumber(bytes);
164 + this.writeBuffer(value);
165 +};
166 +
167 +PacketWriter.prototype.writeNullTerminatedBuffer = function(value) {
168 + this.writeBuffer(value);
169 + this.writeFiller(1); // 0x00 terminator
170 +};
171 +
172 +PacketWriter.prototype.writeLengthCodedString = function(value) {
173 + if (value === null) {
174 + this.writeLengthCodedNumber(null);
175 + return;
176 + }
177 +
178 + value = (value === undefined)
179 + ? ''
180 + : String(value);
181 +
182 + var bytes = Buffer.byteLength(value, 'utf-8');
183 + this.writeLengthCodedNumber(bytes);
184 +
185 + if (!bytes) {
186 + return;
187 + }
188 +
189 + this._allocate(bytes);
190 + this._buffer.write(value, this._offset, 'utf-8');
191 + this._offset += bytes;
192 +};
193 +
194 +PacketWriter.prototype._allocate = function _allocate(bytes) {
195 + if (!this._buffer) {
196 + this._buffer = Buffer.alloc(Math.max(BUFFER_ALLOC_SIZE, bytes));
197 + this._offset = 0;
198 + return;
199 + }
200 +
201 + var bytesRemaining = this._buffer.length - this._offset;
202 + if (bytesRemaining >= bytes) {
203 + return;
204 + }
205 +
206 + var newSize = this._buffer.length + Math.max(BUFFER_ALLOC_SIZE, bytes);
207 + var oldBuffer = this._buffer;
208 +
209 + this._buffer = Buffer.alloc(newSize);
210 + oldBuffer.copy(this._buffer);
211 +};
1 +var PacketHeader = require('./PacketHeader');
2 +var BigNumber = require('bignumber.js');
3 +var Buffer = require('safe-buffer').Buffer;
4 +var BufferList = require('./BufferList');
5 +
6 +var MAX_PACKET_LENGTH = Math.pow(2, 24) - 1;
7 +var MUL_32BIT = Math.pow(2, 32);
8 +var PACKET_HEADER_LENGTH = 4;
9 +
10 +module.exports = Parser;
11 +function Parser(options) {
12 + options = options || {};
13 +
14 + this._supportBigNumbers = options.config && options.config.supportBigNumbers;
15 + this._buffer = Buffer.alloc(0);
16 + this._nextBuffers = new BufferList();
17 + this._longPacketBuffers = new BufferList();
18 + this._offset = 0;
19 + this._packetEnd = null;
20 + this._packetHeader = null;
21 + this._packetOffset = null;
22 + this._onError = options.onError || function(err) { throw err; };
23 + this._onPacket = options.onPacket || function() {};
24 + this._nextPacketNumber = 0;
25 + this._encoding = 'utf-8';
26 + this._paused = false;
27 +}
28 +
29 +Parser.prototype.write = function write(chunk) {
30 + this._nextBuffers.push(chunk);
31 +
32 + while (!this._paused) {
33 + var packetHeader = this._tryReadPacketHeader();
34 +
35 + if (!packetHeader) {
36 + break;
37 + }
38 +
39 + if (!this._combineNextBuffers(packetHeader.length)) {
40 + break;
41 + }
42 +
43 + this._parsePacket(packetHeader);
44 + }
45 +};
46 +
47 +Parser.prototype.append = function append(chunk) {
48 + if (!chunk || chunk.length === 0) {
49 + return;
50 + }
51 +
52 + // Calculate slice ranges
53 + var sliceEnd = this._buffer.length;
54 + var sliceStart = this._packetOffset === null
55 + ? this._offset
56 + : this._packetOffset;
57 + var sliceLength = sliceEnd - sliceStart;
58 +
59 + // Get chunk data
60 + var buffer = null;
61 + var chunks = !(chunk instanceof Array || Array.isArray(chunk)) ? [chunk] : chunk;
62 + var length = 0;
63 + var offset = 0;
64 +
65 + for (var i = 0; i < chunks.length; i++) {
66 + length += chunks[i].length;
67 + }
68 +
69 + if (sliceLength !== 0) {
70 + // Create a new Buffer
71 + buffer = Buffer.allocUnsafe(sliceLength + length);
72 + offset = 0;
73 +
74 + // Copy data slice
75 + offset += this._buffer.copy(buffer, 0, sliceStart, sliceEnd);
76 +
77 + // Copy chunks
78 + for (var i = 0; i < chunks.length; i++) {
79 + offset += chunks[i].copy(buffer, offset);
80 + }
81 + } else if (chunks.length > 1) {
82 + // Create a new Buffer
83 + buffer = Buffer.allocUnsafe(length);
84 + offset = 0;
85 +
86 + // Copy chunks
87 + for (var i = 0; i < chunks.length; i++) {
88 + offset += chunks[i].copy(buffer, offset);
89 + }
90 + } else {
91 + // Buffer is the only chunk
92 + buffer = chunks[0];
93 + }
94 +
95 + // Adjust data-tracking pointers
96 + this._buffer = buffer;
97 + this._offset = this._offset - sliceStart;
98 + this._packetEnd = this._packetEnd !== null
99 + ? this._packetEnd - sliceStart
100 + : null;
101 + this._packetOffset = this._packetOffset !== null
102 + ? this._packetOffset - sliceStart
103 + : null;
104 +};
105 +
106 +Parser.prototype.pause = function() {
107 + this._paused = true;
108 +};
109 +
110 +Parser.prototype.resume = function() {
111 + this._paused = false;
112 +
113 + // nextTick() to avoid entering write() multiple times within the same stack
114 + // which would cause problems as write manipulates the state of the object.
115 + process.nextTick(this.write.bind(this));
116 +};
117 +
118 +Parser.prototype.peak = function peak(offset) {
119 + return this._buffer[this._offset + (offset >>> 0)];
120 +};
121 +
122 +Parser.prototype.parseUnsignedNumber = function parseUnsignedNumber(bytes) {
123 + if (bytes === 1) {
124 + return this._buffer[this._offset++];
125 + }
126 +
127 + var buffer = this._buffer;
128 + var offset = this._offset + bytes - 1;
129 + var value = 0;
130 +
131 + if (bytes > 4) {
132 + var err = new Error('parseUnsignedNumber: Supports only up to 4 bytes');
133 + err.offset = (this._offset - this._packetOffset - 1);
134 + err.code = 'PARSER_UNSIGNED_TOO_LONG';
135 + throw err;
136 + }
137 +
138 + while (offset >= this._offset) {
139 + value = ((value << 8) | buffer[offset]) >>> 0;
140 + offset--;
141 + }
142 +
143 + this._offset += bytes;
144 +
145 + return value;
146 +};
147 +
148 +Parser.prototype.parseLengthCodedString = function() {
149 + var length = this.parseLengthCodedNumber();
150 +
151 + if (length === null) {
152 + return null;
153 + }
154 +
155 + return this.parseString(length);
156 +};
157 +
158 +Parser.prototype.parseLengthCodedBuffer = function() {
159 + var length = this.parseLengthCodedNumber();
160 +
161 + if (length === null) {
162 + return null;
163 + }
164 +
165 + return this.parseBuffer(length);
166 +};
167 +
168 +Parser.prototype.parseLengthCodedNumber = function parseLengthCodedNumber() {
169 + if (this._offset >= this._buffer.length) {
170 + var err = new Error('Parser: read past end');
171 + err.offset = (this._offset - this._packetOffset);
172 + err.code = 'PARSER_READ_PAST_END';
173 + throw err;
174 + }
175 +
176 + var bits = this._buffer[this._offset++];
177 +
178 + if (bits <= 250) {
179 + return bits;
180 + }
181 +
182 + switch (bits) {
183 + case 251:
184 + return null;
185 + case 252:
186 + return this.parseUnsignedNumber(2);
187 + case 253:
188 + return this.parseUnsignedNumber(3);
189 + case 254:
190 + break;
191 + default:
192 + var err = new Error('Unexpected first byte' + (bits ? ': 0x' + bits.toString(16) : ''));
193 + err.offset = (this._offset - this._packetOffset - 1);
194 + err.code = 'PARSER_BAD_LENGTH_BYTE';
195 + throw err;
196 + }
197 +
198 + var low = this.parseUnsignedNumber(4);
199 + var high = this.parseUnsignedNumber(4);
200 + var value;
201 +
202 + if (high >>> 21) {
203 + value = BigNumber(MUL_32BIT).times(high).plus(low).toString();
204 +
205 + if (this._supportBigNumbers) {
206 + return value;
207 + }
208 +
209 + var err = new Error(
210 + 'parseLengthCodedNumber: JS precision range exceeded, ' +
211 + 'number is >= 53 bit: "' + value + '"'
212 + );
213 + err.offset = (this._offset - this._packetOffset - 8);
214 + err.code = 'PARSER_JS_PRECISION_RANGE_EXCEEDED';
215 + throw err;
216 + }
217 +
218 + value = low + (MUL_32BIT * high);
219 +
220 + return value;
221 +};
222 +
223 +Parser.prototype.parseFiller = function(length) {
224 + return this.parseBuffer(length);
225 +};
226 +
227 +Parser.prototype.parseNullTerminatedBuffer = function() {
228 + var end = this._nullByteOffset();
229 + var value = this._buffer.slice(this._offset, end);
230 + this._offset = end + 1;
231 +
232 + return value;
233 +};
234 +
235 +Parser.prototype.parseNullTerminatedString = function() {
236 + var end = this._nullByteOffset();
237 + var value = this._buffer.toString(this._encoding, this._offset, end);
238 + this._offset = end + 1;
239 +
240 + return value;
241 +};
242 +
243 +Parser.prototype._nullByteOffset = function() {
244 + var offset = this._offset;
245 +
246 + while (this._buffer[offset] !== 0x00) {
247 + offset++;
248 +
249 + if (offset >= this._buffer.length) {
250 + var err = new Error('Offset of null terminated string not found.');
251 + err.offset = (this._offset - this._packetOffset);
252 + err.code = 'PARSER_MISSING_NULL_BYTE';
253 + throw err;
254 + }
255 + }
256 +
257 + return offset;
258 +};
259 +
260 +Parser.prototype.parsePacketTerminatedBuffer = function parsePacketTerminatedBuffer() {
261 + var length = this._packetEnd - this._offset;
262 + return this.parseBuffer(length);
263 +};
264 +
265 +Parser.prototype.parsePacketTerminatedString = function() {
266 + var length = this._packetEnd - this._offset;
267 + return this.parseString(length);
268 +};
269 +
270 +Parser.prototype.parseBuffer = function(length) {
271 + var response = Buffer.alloc(length);
272 + this._buffer.copy(response, 0, this._offset, this._offset + length);
273 +
274 + this._offset += length;
275 + return response;
276 +};
277 +
278 +Parser.prototype.parseString = function(length) {
279 + var offset = this._offset;
280 + var end = offset + length;
281 + var value = this._buffer.toString(this._encoding, offset, end);
282 +
283 + this._offset = end;
284 + return value;
285 +};
286 +
287 +Parser.prototype.parseGeometryValue = function() {
288 + var buffer = this.parseLengthCodedBuffer();
289 + var offset = 4;
290 +
291 + if (buffer === null || !buffer.length) {
292 + return null;
293 + }
294 +
295 + function parseGeometry() {
296 + var result = null;
297 + var byteOrder = buffer.readUInt8(offset); offset += 1;
298 + var wkbType = byteOrder ? buffer.readUInt32LE(offset) : buffer.readUInt32BE(offset); offset += 4;
299 + switch (wkbType) {
300 + case 1: // WKBPoint
301 + var x = byteOrder ? buffer.readDoubleLE(offset) : buffer.readDoubleBE(offset); offset += 8;
302 + var y = byteOrder ? buffer.readDoubleLE(offset) : buffer.readDoubleBE(offset); offset += 8;
303 + result = {x: x, y: y};
304 + break;
305 + case 2: // WKBLineString
306 + var numPoints = byteOrder ? buffer.readUInt32LE(offset) : buffer.readUInt32BE(offset); offset += 4;
307 + result = [];
308 + for (var i = numPoints; i > 0; i--) {
309 + var x = byteOrder ? buffer.readDoubleLE(offset) : buffer.readDoubleBE(offset); offset += 8;
310 + var y = byteOrder ? buffer.readDoubleLE(offset) : buffer.readDoubleBE(offset); offset += 8;
311 + result.push({x: x, y: y});
312 + }
313 + break;
314 + case 3: // WKBPolygon
315 + var numRings = byteOrder ? buffer.readUInt32LE(offset) : buffer.readUInt32BE(offset); offset += 4;
316 + result = [];
317 + for (var i = numRings; i > 0; i--) {
318 + var numPoints = byteOrder ? buffer.readUInt32LE(offset) : buffer.readUInt32BE(offset); offset += 4;
319 + var line = [];
320 + for (var j = numPoints; j > 0; j--) {
321 + var x = byteOrder ? buffer.readDoubleLE(offset) : buffer.readDoubleBE(offset); offset += 8;
322 + var y = byteOrder ? buffer.readDoubleLE(offset) : buffer.readDoubleBE(offset); offset += 8;
323 + line.push({x: x, y: y});
324 + }
325 + result.push(line);
326 + }
327 + break;
328 + case 4: // WKBMultiPoint
329 + case 5: // WKBMultiLineString
330 + case 6: // WKBMultiPolygon
331 + case 7: // WKBGeometryCollection
332 + var num = byteOrder ? buffer.readUInt32LE(offset) : buffer.readUInt32BE(offset); offset += 4;
333 + var result = [];
334 + for (var i = num; i > 0; i--) {
335 + result.push(parseGeometry());
336 + }
337 + break;
338 + }
339 + return result;
340 + }
341 + return parseGeometry();
342 +};
343 +
344 +Parser.prototype.reachedPacketEnd = function() {
345 + return this._offset === this._packetEnd;
346 +};
347 +
348 +Parser.prototype.incrementPacketNumber = function() {
349 + var currentPacketNumber = this._nextPacketNumber;
350 + this._nextPacketNumber = (this._nextPacketNumber + 1) % 256;
351 +
352 + return currentPacketNumber;
353 +};
354 +
355 +Parser.prototype.resetPacketNumber = function() {
356 + this._nextPacketNumber = 0;
357 +};
358 +
359 +Parser.prototype.packetLength = function packetLength() {
360 + if (!this._packetHeader) {
361 + return null;
362 + }
363 +
364 + return this._packetHeader.length + this._longPacketBuffers.size;
365 +};
366 +
367 +Parser.prototype._combineNextBuffers = function _combineNextBuffers(bytes) {
368 + var length = this._buffer.length - this._offset;
369 +
370 + if (length >= bytes) {
371 + return true;
372 + }
373 +
374 + if ((length + this._nextBuffers.size) < bytes) {
375 + return false;
376 + }
377 +
378 + var buffers = [];
379 + var bytesNeeded = bytes - length;
380 +
381 + while (bytesNeeded > 0) {
382 + var buffer = this._nextBuffers.shift();
383 + buffers.push(buffer);
384 + bytesNeeded -= buffer.length;
385 + }
386 +
387 + this.append(buffers);
388 + return true;
389 +};
390 +
391 +Parser.prototype._combineLongPacketBuffers = function _combineLongPacketBuffers() {
392 + if (!this._longPacketBuffers.size) {
393 + return;
394 + }
395 +
396 + // Calculate bytes
397 + var remainingBytes = this._buffer.length - this._offset;
398 + var trailingPacketBytes = this._buffer.length - this._packetEnd;
399 +
400 + // Create buffer
401 + var buf = null;
402 + var buffer = Buffer.allocUnsafe(remainingBytes + this._longPacketBuffers.size);
403 + var offset = 0;
404 +
405 + // Copy long buffers
406 + while ((buf = this._longPacketBuffers.shift())) {
407 + offset += buf.copy(buffer, offset);
408 + }
409 +
410 + // Copy remaining bytes
411 + this._buffer.copy(buffer, offset, this._offset);
412 +
413 + this._buffer = buffer;
414 + this._offset = 0;
415 + this._packetEnd = this._buffer.length - trailingPacketBytes;
416 + this._packetOffset = 0;
417 +};
418 +
419 +Parser.prototype._parsePacket = function _parsePacket(packetHeader) {
420 + this._packetEnd = this._offset + packetHeader.length;
421 + this._packetOffset = this._offset;
422 +
423 + if (packetHeader.length === MAX_PACKET_LENGTH) {
424 + this._longPacketBuffers.push(this._buffer.slice(this._packetOffset, this._packetEnd));
425 + this._advanceToNextPacket();
426 + return;
427 + }
428 +
429 + this._combineLongPacketBuffers();
430 +
431 + var hadException = true;
432 + try {
433 + this._onPacket(packetHeader);
434 + hadException = false;
435 + } catch (err) {
436 + if (!err || typeof err.code !== 'string' || err.code.substr(0, 7) !== 'PARSER_') {
437 + throw err; // Rethrow non-MySQL errors
438 + }
439 +
440 + // Pass down parser errors
441 + this._onError(err);
442 + hadException = false;
443 + } finally {
444 + this._advanceToNextPacket();
445 +
446 + // If there was an exception, the parser while loop will be broken out
447 + // of after the finally block. So schedule a blank write to re-enter it
448 + // to continue parsing any bytes that may already have been received.
449 + if (hadException) {
450 + process.nextTick(this.write.bind(this));
451 + }
452 + }
453 +};
454 +
455 +Parser.prototype._tryReadPacketHeader = function _tryReadPacketHeader() {
456 + if (this._packetHeader) {
457 + return this._packetHeader;
458 + }
459 +
460 + if (!this._combineNextBuffers(PACKET_HEADER_LENGTH)) {
461 + return null;
462 + }
463 +
464 + this._packetHeader = new PacketHeader(
465 + this.parseUnsignedNumber(3),
466 + this.parseUnsignedNumber(1)
467 + );
468 +
469 + if (this._packetHeader.number !== this._nextPacketNumber) {
470 + var err = new Error(
471 + 'Packets out of order. Got: ' + this._packetHeader.number + ' ' +
472 + 'Expected: ' + this._nextPacketNumber
473 + );
474 +
475 + err.code = 'PROTOCOL_PACKETS_OUT_OF_ORDER';
476 + err.fatal = true;
477 +
478 + this._onError(err);
479 + }
480 +
481 + this.incrementPacketNumber();
482 +
483 + return this._packetHeader;
484 +};
485 +
486 +Parser.prototype._advanceToNextPacket = function() {
487 + this._offset = this._packetEnd;
488 + this._packetHeader = null;
489 + this._packetEnd = null;
490 + this._packetOffset = null;
491 +};
1 +var Parser = require('./Parser');
2 +var Sequences = require('./sequences');
3 +var Packets = require('./packets');
4 +var Stream = require('stream').Stream;
5 +var Util = require('util');
6 +var PacketWriter = require('./PacketWriter');
7 +
8 +module.exports = Protocol;
9 +Util.inherits(Protocol, Stream);
10 +function Protocol(options) {
11 + Stream.call(this);
12 +
13 + options = options || {};
14 +
15 + this.readable = true;
16 + this.writable = true;
17 +
18 + this._config = options.config || {};
19 + this._connection = options.connection;
20 + this._callback = null;
21 + this._fatalError = null;
22 + this._quitSequence = null;
23 + this._handshake = false;
24 + this._handshaked = false;
25 + this._ended = false;
26 + this._destroyed = false;
27 + this._queue = [];
28 + this._handshakeInitializationPacket = null;
29 +
30 + this._parser = new Parser({
31 + onError : this.handleParserError.bind(this),
32 + onPacket : this._parsePacket.bind(this),
33 + config : this._config
34 + });
35 +}
36 +
37 +Protocol.prototype.write = function(buffer) {
38 + this._parser.write(buffer);
39 + return true;
40 +};
41 +
42 +Protocol.prototype.handshake = function handshake(options, callback) {
43 + if (typeof options === 'function') {
44 + callback = options;
45 + options = {};
46 + }
47 +
48 + options = options || {};
49 + options.config = this._config;
50 +
51 + var sequence = this._enqueue(new Sequences.Handshake(options, callback));
52 +
53 + this._handshake = true;
54 +
55 + return sequence;
56 +};
57 +
58 +Protocol.prototype.query = function query(options, callback) {
59 + return this._enqueue(new Sequences.Query(options, callback));
60 +};
61 +
62 +Protocol.prototype.changeUser = function changeUser(options, callback) {
63 + return this._enqueue(new Sequences.ChangeUser(options, callback));
64 +};
65 +
66 +Protocol.prototype.ping = function ping(options, callback) {
67 + if (typeof options === 'function') {
68 + callback = options;
69 + options = {};
70 + }
71 +
72 + return this._enqueue(new Sequences.Ping(options, callback));
73 +};
74 +
75 +Protocol.prototype.stats = function stats(options, callback) {
76 + if (typeof options === 'function') {
77 + callback = options;
78 + options = {};
79 + }
80 +
81 + return this._enqueue(new Sequences.Statistics(options, callback));
82 +};
83 +
84 +Protocol.prototype.quit = function quit(options, callback) {
85 + if (typeof options === 'function') {
86 + callback = options;
87 + options = {};
88 + }
89 +
90 + var self = this;
91 + var sequence = this._enqueue(new Sequences.Quit(options, callback));
92 +
93 + sequence.on('end', function () {
94 + self.end();
95 + });
96 +
97 + return this._quitSequence = sequence;
98 +};
99 +
100 +Protocol.prototype.end = function() {
101 + if (this._ended) {
102 + return;
103 + }
104 + this._ended = true;
105 +
106 + if (this._quitSequence && (this._quitSequence._ended || this._queue[0] === this._quitSequence)) {
107 + this._quitSequence.end();
108 + this.emit('end');
109 + return;
110 + }
111 +
112 + var err = new Error('Connection lost: The server closed the connection.');
113 + err.fatal = true;
114 + err.code = 'PROTOCOL_CONNECTION_LOST';
115 +
116 + this._delegateError(err);
117 +};
118 +
119 +Protocol.prototype.pause = function() {
120 + this._parser.pause();
121 + // Since there is a file stream in query, we must transmit pause/resume event to current sequence.
122 + var seq = this._queue[0];
123 + if (seq && seq.emit) {
124 + seq.emit('pause');
125 + }
126 +};
127 +
128 +Protocol.prototype.resume = function() {
129 + this._parser.resume();
130 + // Since there is a file stream in query, we must transmit pause/resume event to current sequence.
131 + var seq = this._queue[0];
132 + if (seq && seq.emit) {
133 + seq.emit('resume');
134 + }
135 +};
136 +
137 +Protocol.prototype._enqueue = function(sequence) {
138 + if (!this._validateEnqueue(sequence)) {
139 + return sequence;
140 + }
141 +
142 + if (this._config.trace) {
143 + // Long stack trace support
144 + sequence._callSite = sequence._callSite || new Error();
145 + }
146 +
147 + this._queue.push(sequence);
148 + this.emit('enqueue', sequence);
149 +
150 + var self = this;
151 + sequence
152 + .on('error', function(err) {
153 + self._delegateError(err, sequence);
154 + })
155 + .on('packet', function(packet) {
156 + sequence._timer.active();
157 + self._emitPacket(packet);
158 + })
159 + .on('timeout', function() {
160 + var err = new Error(sequence.constructor.name + ' inactivity timeout');
161 +
162 + err.code = 'PROTOCOL_SEQUENCE_TIMEOUT';
163 + err.fatal = true;
164 + err.timeout = sequence._timeout;
165 +
166 + self._delegateError(err, sequence);
167 + });
168 +
169 + if (sequence.constructor === Sequences.Handshake) {
170 + sequence.on('start-tls', function () {
171 + sequence._timer.active();
172 + self._connection._startTLS(function(err) {
173 + if (err) {
174 + // SSL negotiation error are fatal
175 + err.code = 'HANDSHAKE_SSL_ERROR';
176 + err.fatal = true;
177 + sequence.end(err);
178 + return;
179 + }
180 +
181 + sequence._timer.active();
182 + sequence._tlsUpgradeCompleteHandler();
183 + });
184 + });
185 +
186 + sequence.on('end', function () {
187 + self._handshaked = true;
188 +
189 + if (!self._fatalError) {
190 + self.emit('handshake', self._handshakeInitializationPacket);
191 + }
192 + });
193 + }
194 +
195 + sequence.on('end', function () {
196 + self._dequeue(sequence);
197 + });
198 +
199 + if (this._queue.length === 1) {
200 + this._parser.resetPacketNumber();
201 + this._startSequence(sequence);
202 + }
203 +
204 + return sequence;
205 +};
206 +
207 +Protocol.prototype._validateEnqueue = function _validateEnqueue(sequence) {
208 + var err;
209 + var prefix = 'Cannot enqueue ' + sequence.constructor.name;
210 +
211 + if (this._fatalError) {
212 + err = new Error(prefix + ' after fatal error.');
213 + err.code = 'PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR';
214 + } else if (this._quitSequence) {
215 + err = new Error(prefix + ' after invoking quit.');
216 + err.code = 'PROTOCOL_ENQUEUE_AFTER_QUIT';
217 + } else if (this._destroyed) {
218 + err = new Error(prefix + ' after being destroyed.');
219 + err.code = 'PROTOCOL_ENQUEUE_AFTER_DESTROY';
220 + } else if ((this._handshake || this._handshaked) && sequence.constructor === Sequences.Handshake) {
221 + err = new Error(prefix + ' after already enqueuing a Handshake.');
222 + err.code = 'PROTOCOL_ENQUEUE_HANDSHAKE_TWICE';
223 + } else {
224 + return true;
225 + }
226 +
227 + var self = this;
228 + err.fatal = false;
229 +
230 + // add error handler
231 + sequence.on('error', function (err) {
232 + self._delegateError(err, sequence);
233 + });
234 +
235 + process.nextTick(function () {
236 + sequence.end(err);
237 + });
238 +
239 + return false;
240 +};
241 +
242 +Protocol.prototype._parsePacket = function() {
243 + var sequence = this._queue[0];
244 +
245 + if (!sequence) {
246 + var err = new Error('Received packet with no active sequence.');
247 + err.code = 'PROTOCOL_STRAY_PACKET';
248 + err.fatal = true;
249 +
250 + this._delegateError(err);
251 + return;
252 + }
253 +
254 + var Packet = this._determinePacket(sequence);
255 + var packet = new Packet({protocol41: this._config.protocol41});
256 + var packetName = Packet.name;
257 +
258 + // Special case: Faster dispatch, and parsing done inside sequence
259 + if (Packet === Packets.RowDataPacket) {
260 + sequence.RowDataPacket(packet, this._parser, this._connection);
261 +
262 + if (this._config.debug) {
263 + this._debugPacket(true, packet);
264 + }
265 +
266 + return;
267 + }
268 +
269 + if (this._config.debug) {
270 + this._parsePacketDebug(packet);
271 + } else {
272 + packet.parse(this._parser);
273 + }
274 +
275 + if (Packet === Packets.HandshakeInitializationPacket) {
276 + this._handshakeInitializationPacket = packet;
277 + this.emit('initialize', packet);
278 + }
279 +
280 + sequence._timer.active();
281 +
282 + if (!sequence[packetName]) {
283 + var err = new Error('Received packet in the wrong sequence.');
284 + err.code = 'PROTOCOL_INCORRECT_PACKET_SEQUENCE';
285 + err.fatal = true;
286 +
287 + this._delegateError(err);
288 + return;
289 + }
290 +
291 + sequence[packetName](packet);
292 +};
293 +
294 +Protocol.prototype._parsePacketDebug = function _parsePacketDebug(packet) {
295 + try {
296 + packet.parse(this._parser);
297 + } finally {
298 + this._debugPacket(true, packet);
299 + }
300 +};
301 +
302 +Protocol.prototype._emitPacket = function(packet) {
303 + var packetWriter = new PacketWriter();
304 + packet.write(packetWriter);
305 + this.emit('data', packetWriter.toBuffer(this._parser));
306 +
307 + if (this._config.debug) {
308 + this._debugPacket(false, packet);
309 + }
310 +};
311 +
312 +Protocol.prototype._determinePacket = function(sequence) {
313 + var firstByte = this._parser.peak();
314 +
315 + if (sequence.determinePacket) {
316 + var Packet = sequence.determinePacket(firstByte, this._parser);
317 + if (Packet) {
318 + return Packet;
319 + }
320 + }
321 +
322 + switch (firstByte) {
323 + case 0x00: return Packets.OkPacket;
324 + case 0xfe: return Packets.EofPacket;
325 + case 0xff: return Packets.ErrorPacket;
326 + }
327 +
328 + throw new Error('Could not determine packet, firstByte = ' + firstByte);
329 +};
330 +
331 +Protocol.prototype._dequeue = function(sequence) {
332 + sequence._timer.stop();
333 +
334 + // No point in advancing the queue, we are dead
335 + if (this._fatalError) {
336 + return;
337 + }
338 +
339 + this._queue.shift();
340 +
341 + var sequence = this._queue[0];
342 + if (!sequence) {
343 + this.emit('drain');
344 + return;
345 + }
346 +
347 + this._parser.resetPacketNumber();
348 +
349 + this._startSequence(sequence);
350 +};
351 +
352 +Protocol.prototype._startSequence = function(sequence) {
353 + if (sequence._timeout > 0 && isFinite(sequence._timeout)) {
354 + sequence._timer.start(sequence._timeout);
355 + }
356 +
357 + if (sequence.constructor === Sequences.ChangeUser) {
358 + sequence.start(this._handshakeInitializationPacket);
359 + } else {
360 + sequence.start();
361 + }
362 +};
363 +
364 +Protocol.prototype.handleNetworkError = function(err) {
365 + err.fatal = true;
366 +
367 + var sequence = this._queue[0];
368 + if (sequence) {
369 + sequence.end(err);
370 + } else {
371 + this._delegateError(err);
372 + }
373 +};
374 +
375 +Protocol.prototype.handleParserError = function handleParserError(err) {
376 + var sequence = this._queue[0];
377 + if (sequence) {
378 + sequence.end(err);
379 + } else {
380 + this._delegateError(err);
381 + }
382 +};
383 +
384 +Protocol.prototype._delegateError = function(err, sequence) {
385 + // Stop delegating errors after the first fatal error
386 + if (this._fatalError) {
387 + return;
388 + }
389 +
390 + if (err.fatal) {
391 + this._fatalError = err;
392 + }
393 +
394 + if (this._shouldErrorBubbleUp(err, sequence)) {
395 + // Can't use regular 'error' event here as that always destroys the pipe
396 + // between socket and protocol which is not what we want (unless the
397 + // exception was fatal).
398 + this.emit('unhandledError', err);
399 + } else if (err.fatal) {
400 + // Send fatal error to all sequences in the queue
401 + var queue = this._queue;
402 + process.nextTick(function () {
403 + queue.forEach(function (sequence) {
404 + sequence.end(err);
405 + });
406 + queue.length = 0;
407 + });
408 + }
409 +
410 + // Make sure the stream we are piping to is getting closed
411 + if (err.fatal) {
412 + this.emit('end', err);
413 + }
414 +};
415 +
416 +Protocol.prototype._shouldErrorBubbleUp = function(err, sequence) {
417 + if (sequence) {
418 + if (sequence.hasErrorHandler()) {
419 + return false;
420 + } else if (!err.fatal) {
421 + return true;
422 + }
423 + }
424 +
425 + return (err.fatal && !this._hasPendingErrorHandlers());
426 +};
427 +
428 +Protocol.prototype._hasPendingErrorHandlers = function() {
429 + return this._queue.some(function(sequence) {
430 + return sequence.hasErrorHandler();
431 + });
432 +};
433 +
434 +Protocol.prototype.destroy = function() {
435 + this._destroyed = true;
436 + this._parser.pause();
437 +
438 + if (this._connection.state !== 'disconnected') {
439 + if (!this._ended) {
440 + this.end();
441 + }
442 + }
443 +};
444 +
445 +Protocol.prototype._debugPacket = function(incoming, packet) {
446 + var connection = this._connection;
447 + var direction = incoming
448 + ? '<--'
449 + : '-->';
450 + var packetName = packet.constructor.name;
451 + var threadId = connection && connection.threadId !== null
452 + ? ' (' + connection.threadId + ')'
453 + : '';
454 +
455 + // check for debug packet restriction
456 + if (Array.isArray(this._config.debug) && this._config.debug.indexOf(packetName) === -1) {
457 + return;
458 + }
459 +
460 + var packetPayload = Util.inspect(packet).replace(/^[^{]+/, '');
461 +
462 + console.log('%s%s %s %s\n', direction, threadId, packetName, packetPayload);
463 +};
1 +module.exports = ResultSet;
2 +function ResultSet(resultSetHeaderPacket) {
3 + this.resultSetHeaderPacket = resultSetHeaderPacket;
4 + this.fieldPackets = [];
5 + this.eofPackets = [];
6 + this.rows = [];
7 +}
1 +module.exports = require('sqlstring');
1 +var Timers = require('timers');
2 +
3 +module.exports = Timer;
4 +function Timer(object) {
5 + this._object = object;
6 + this._timeout = null;
7 +}
8 +
9 +Timer.prototype.active = function active() {
10 + if (this._timeout) {
11 + if (this._timeout.refresh) {
12 + this._timeout.refresh();
13 + } else {
14 + Timers.active(this._timeout);
15 + }
16 + }
17 +};
18 +
19 +Timer.prototype.start = function start(msecs) {
20 + this.stop();
21 + this._timeout = Timers.setTimeout(this._onTimeout.bind(this), msecs);
22 +};
23 +
24 +Timer.prototype.stop = function stop() {
25 + if (this._timeout) {
26 + Timers.clearTimeout(this._timeout);
27 + this._timeout = null;
28 + }
29 +};
30 +
31 +Timer.prototype._onTimeout = function _onTimeout() {
32 + return this._object._onTimeout();
33 +};
1 +exports.BIG5_CHINESE_CI = 1;
2 +exports.LATIN2_CZECH_CS = 2;
3 +exports.DEC8_SWEDISH_CI = 3;
4 +exports.CP850_GENERAL_CI = 4;
5 +exports.LATIN1_GERMAN1_CI = 5;
6 +exports.HP8_ENGLISH_CI = 6;
7 +exports.KOI8R_GENERAL_CI = 7;
8 +exports.LATIN1_SWEDISH_CI = 8;
9 +exports.LATIN2_GENERAL_CI = 9;
10 +exports.SWE7_SWEDISH_CI = 10;
11 +exports.ASCII_GENERAL_CI = 11;
12 +exports.UJIS_JAPANESE_CI = 12;
13 +exports.SJIS_JAPANESE_CI = 13;
14 +exports.CP1251_BULGARIAN_CI = 14;
15 +exports.LATIN1_DANISH_CI = 15;
16 +exports.HEBREW_GENERAL_CI = 16;
17 +exports.TIS620_THAI_CI = 18;
18 +exports.EUCKR_KOREAN_CI = 19;
19 +exports.LATIN7_ESTONIAN_CS = 20;
20 +exports.LATIN2_HUNGARIAN_CI = 21;
21 +exports.KOI8U_GENERAL_CI = 22;
22 +exports.CP1251_UKRAINIAN_CI = 23;
23 +exports.GB2312_CHINESE_CI = 24;
24 +exports.GREEK_GENERAL_CI = 25;
25 +exports.CP1250_GENERAL_CI = 26;
26 +exports.LATIN2_CROATIAN_CI = 27;
27 +exports.GBK_CHINESE_CI = 28;
28 +exports.CP1257_LITHUANIAN_CI = 29;
29 +exports.LATIN5_TURKISH_CI = 30;
30 +exports.LATIN1_GERMAN2_CI = 31;
31 +exports.ARMSCII8_GENERAL_CI = 32;
32 +exports.UTF8_GENERAL_CI = 33;
33 +exports.CP1250_CZECH_CS = 34;
34 +exports.UCS2_GENERAL_CI = 35;
35 +exports.CP866_GENERAL_CI = 36;
36 +exports.KEYBCS2_GENERAL_CI = 37;
37 +exports.MACCE_GENERAL_CI = 38;
38 +exports.MACROMAN_GENERAL_CI = 39;
39 +exports.CP852_GENERAL_CI = 40;
40 +exports.LATIN7_GENERAL_CI = 41;
41 +exports.LATIN7_GENERAL_CS = 42;
42 +exports.MACCE_BIN = 43;
43 +exports.CP1250_CROATIAN_CI = 44;
44 +exports.UTF8MB4_GENERAL_CI = 45;
45 +exports.UTF8MB4_BIN = 46;
46 +exports.LATIN1_BIN = 47;
47 +exports.LATIN1_GENERAL_CI = 48;
48 +exports.LATIN1_GENERAL_CS = 49;
49 +exports.CP1251_BIN = 50;
50 +exports.CP1251_GENERAL_CI = 51;
51 +exports.CP1251_GENERAL_CS = 52;
52 +exports.MACROMAN_BIN = 53;
53 +exports.UTF16_GENERAL_CI = 54;
54 +exports.UTF16_BIN = 55;
55 +exports.UTF16LE_GENERAL_CI = 56;
56 +exports.CP1256_GENERAL_CI = 57;
57 +exports.CP1257_BIN = 58;
58 +exports.CP1257_GENERAL_CI = 59;
59 +exports.UTF32_GENERAL_CI = 60;
60 +exports.UTF32_BIN = 61;
61 +exports.UTF16LE_BIN = 62;
62 +exports.BINARY = 63;
63 +exports.ARMSCII8_BIN = 64;
64 +exports.ASCII_BIN = 65;
65 +exports.CP1250_BIN = 66;
66 +exports.CP1256_BIN = 67;
67 +exports.CP866_BIN = 68;
68 +exports.DEC8_BIN = 69;
69 +exports.GREEK_BIN = 70;
70 +exports.HEBREW_BIN = 71;
71 +exports.HP8_BIN = 72;
72 +exports.KEYBCS2_BIN = 73;
73 +exports.KOI8R_BIN = 74;
74 +exports.KOI8U_BIN = 75;
75 +exports.LATIN2_BIN = 77;
76 +exports.LATIN5_BIN = 78;
77 +exports.LATIN7_BIN = 79;
78 +exports.CP850_BIN = 80;
79 +exports.CP852_BIN = 81;
80 +exports.SWE7_BIN = 82;
81 +exports.UTF8_BIN = 83;
82 +exports.BIG5_BIN = 84;
83 +exports.EUCKR_BIN = 85;
84 +exports.GB2312_BIN = 86;
85 +exports.GBK_BIN = 87;
86 +exports.SJIS_BIN = 88;
87 +exports.TIS620_BIN = 89;
88 +exports.UCS2_BIN = 90;
89 +exports.UJIS_BIN = 91;
90 +exports.GEOSTD8_GENERAL_CI = 92;
91 +exports.GEOSTD8_BIN = 93;
92 +exports.LATIN1_SPANISH_CI = 94;
93 +exports.CP932_JAPANESE_CI = 95;
94 +exports.CP932_BIN = 96;
95 +exports.EUCJPMS_JAPANESE_CI = 97;
96 +exports.EUCJPMS_BIN = 98;
97 +exports.CP1250_POLISH_CI = 99;
98 +exports.UTF16_UNICODE_CI = 101;
99 +exports.UTF16_ICELANDIC_CI = 102;
100 +exports.UTF16_LATVIAN_CI = 103;
101 +exports.UTF16_ROMANIAN_CI = 104;
102 +exports.UTF16_SLOVENIAN_CI = 105;
103 +exports.UTF16_POLISH_CI = 106;
104 +exports.UTF16_ESTONIAN_CI = 107;
105 +exports.UTF16_SPANISH_CI = 108;
106 +exports.UTF16_SWEDISH_CI = 109;
107 +exports.UTF16_TURKISH_CI = 110;
108 +exports.UTF16_CZECH_CI = 111;
109 +exports.UTF16_DANISH_CI = 112;
110 +exports.UTF16_LITHUANIAN_CI = 113;
111 +exports.UTF16_SLOVAK_CI = 114;
112 +exports.UTF16_SPANISH2_CI = 115;
113 +exports.UTF16_ROMAN_CI = 116;
114 +exports.UTF16_PERSIAN_CI = 117;
115 +exports.UTF16_ESPERANTO_CI = 118;
116 +exports.UTF16_HUNGARIAN_CI = 119;
117 +exports.UTF16_SINHALA_CI = 120;
118 +exports.UTF16_GERMAN2_CI = 121;
119 +exports.UTF16_CROATIAN_MYSQL561_CI = 122;
120 +exports.UTF16_UNICODE_520_CI = 123;
121 +exports.UTF16_VIETNAMESE_CI = 124;
122 +exports.UCS2_UNICODE_CI = 128;
123 +exports.UCS2_ICELANDIC_CI = 129;
124 +exports.UCS2_LATVIAN_CI = 130;
125 +exports.UCS2_ROMANIAN_CI = 131;
126 +exports.UCS2_SLOVENIAN_CI = 132;
127 +exports.UCS2_POLISH_CI = 133;
128 +exports.UCS2_ESTONIAN_CI = 134;
129 +exports.UCS2_SPANISH_CI = 135;
130 +exports.UCS2_SWEDISH_CI = 136;
131 +exports.UCS2_TURKISH_CI = 137;
132 +exports.UCS2_CZECH_CI = 138;
133 +exports.UCS2_DANISH_CI = 139;
134 +exports.UCS2_LITHUANIAN_CI = 140;
135 +exports.UCS2_SLOVAK_CI = 141;
136 +exports.UCS2_SPANISH2_CI = 142;
137 +exports.UCS2_ROMAN_CI = 143;
138 +exports.UCS2_PERSIAN_CI = 144;
139 +exports.UCS2_ESPERANTO_CI = 145;
140 +exports.UCS2_HUNGARIAN_CI = 146;
141 +exports.UCS2_SINHALA_CI = 147;
142 +exports.UCS2_GERMAN2_CI = 148;
143 +exports.UCS2_CROATIAN_MYSQL561_CI = 149;
144 +exports.UCS2_UNICODE_520_CI = 150;
145 +exports.UCS2_VIETNAMESE_CI = 151;
146 +exports.UCS2_GENERAL_MYSQL500_CI = 159;
147 +exports.UTF32_UNICODE_CI = 160;
148 +exports.UTF32_ICELANDIC_CI = 161;
149 +exports.UTF32_LATVIAN_CI = 162;
150 +exports.UTF32_ROMANIAN_CI = 163;
151 +exports.UTF32_SLOVENIAN_CI = 164;
152 +exports.UTF32_POLISH_CI = 165;
153 +exports.UTF32_ESTONIAN_CI = 166;
154 +exports.UTF32_SPANISH_CI = 167;
155 +exports.UTF32_SWEDISH_CI = 168;
156 +exports.UTF32_TURKISH_CI = 169;
157 +exports.UTF32_CZECH_CI = 170;
158 +exports.UTF32_DANISH_CI = 171;
159 +exports.UTF32_LITHUANIAN_CI = 172;
160 +exports.UTF32_SLOVAK_CI = 173;
161 +exports.UTF32_SPANISH2_CI = 174;
162 +exports.UTF32_ROMAN_CI = 175;
163 +exports.UTF32_PERSIAN_CI = 176;
164 +exports.UTF32_ESPERANTO_CI = 177;
165 +exports.UTF32_HUNGARIAN_CI = 178;
166 +exports.UTF32_SINHALA_CI = 179;
167 +exports.UTF32_GERMAN2_CI = 180;
168 +exports.UTF32_CROATIAN_MYSQL561_CI = 181;
169 +exports.UTF32_UNICODE_520_CI = 182;
170 +exports.UTF32_VIETNAMESE_CI = 183;
171 +exports.UTF8_UNICODE_CI = 192;
172 +exports.UTF8_ICELANDIC_CI = 193;
173 +exports.UTF8_LATVIAN_CI = 194;
174 +exports.UTF8_ROMANIAN_CI = 195;
175 +exports.UTF8_SLOVENIAN_CI = 196;
176 +exports.UTF8_POLISH_CI = 197;
177 +exports.UTF8_ESTONIAN_CI = 198;
178 +exports.UTF8_SPANISH_CI = 199;
179 +exports.UTF8_SWEDISH_CI = 200;
180 +exports.UTF8_TURKISH_CI = 201;
181 +exports.UTF8_CZECH_CI = 202;
182 +exports.UTF8_DANISH_CI = 203;
183 +exports.UTF8_LITHUANIAN_CI = 204;
184 +exports.UTF8_SLOVAK_CI = 205;
185 +exports.UTF8_SPANISH2_CI = 206;
186 +exports.UTF8_ROMAN_CI = 207;
187 +exports.UTF8_PERSIAN_CI = 208;
188 +exports.UTF8_ESPERANTO_CI = 209;
189 +exports.UTF8_HUNGARIAN_CI = 210;
190 +exports.UTF8_SINHALA_CI = 211;
191 +exports.UTF8_GERMAN2_CI = 212;
192 +exports.UTF8_CROATIAN_MYSQL561_CI = 213;
193 +exports.UTF8_UNICODE_520_CI = 214;
194 +exports.UTF8_VIETNAMESE_CI = 215;
195 +exports.UTF8_GENERAL_MYSQL500_CI = 223;
196 +exports.UTF8MB4_UNICODE_CI = 224;
197 +exports.UTF8MB4_ICELANDIC_CI = 225;
198 +exports.UTF8MB4_LATVIAN_CI = 226;
199 +exports.UTF8MB4_ROMANIAN_CI = 227;
200 +exports.UTF8MB4_SLOVENIAN_CI = 228;
201 +exports.UTF8MB4_POLISH_CI = 229;
202 +exports.UTF8MB4_ESTONIAN_CI = 230;
203 +exports.UTF8MB4_SPANISH_CI = 231;
204 +exports.UTF8MB4_SWEDISH_CI = 232;
205 +exports.UTF8MB4_TURKISH_CI = 233;
206 +exports.UTF8MB4_CZECH_CI = 234;
207 +exports.UTF8MB4_DANISH_CI = 235;
208 +exports.UTF8MB4_LITHUANIAN_CI = 236;
209 +exports.UTF8MB4_SLOVAK_CI = 237;
210 +exports.UTF8MB4_SPANISH2_CI = 238;
211 +exports.UTF8MB4_ROMAN_CI = 239;
212 +exports.UTF8MB4_PERSIAN_CI = 240;
213 +exports.UTF8MB4_ESPERANTO_CI = 241;
214 +exports.UTF8MB4_HUNGARIAN_CI = 242;
215 +exports.UTF8MB4_SINHALA_CI = 243;
216 +exports.UTF8MB4_GERMAN2_CI = 244;
217 +exports.UTF8MB4_CROATIAN_MYSQL561_CI = 245;
218 +exports.UTF8MB4_UNICODE_520_CI = 246;
219 +exports.UTF8MB4_VIETNAMESE_CI = 247;
220 +exports.UTF8_GENERAL50_CI = 253;
221 +
222 +// short aliases
223 +exports.ARMSCII8 = exports.ARMSCII8_GENERAL_CI;
224 +exports.ASCII = exports.ASCII_GENERAL_CI;
225 +exports.BIG5 = exports.BIG5_CHINESE_CI;
226 +exports.BINARY = exports.BINARY;
227 +exports.CP1250 = exports.CP1250_GENERAL_CI;
228 +exports.CP1251 = exports.CP1251_GENERAL_CI;
229 +exports.CP1256 = exports.CP1256_GENERAL_CI;
230 +exports.CP1257 = exports.CP1257_GENERAL_CI;
231 +exports.CP866 = exports.CP866_GENERAL_CI;
232 +exports.CP850 = exports.CP850_GENERAL_CI;
233 +exports.CP852 = exports.CP852_GENERAL_CI;
234 +exports.CP932 = exports.CP932_JAPANESE_CI;
235 +exports.DEC8 = exports.DEC8_SWEDISH_CI;
236 +exports.EUCJPMS = exports.EUCJPMS_JAPANESE_CI;
237 +exports.EUCKR = exports.EUCKR_KOREAN_CI;
238 +exports.GB2312 = exports.GB2312_CHINESE_CI;
239 +exports.GBK = exports.GBK_CHINESE_CI;
240 +exports.GEOSTD8 = exports.GEOSTD8_GENERAL_CI;
241 +exports.GREEK = exports.GREEK_GENERAL_CI;
242 +exports.HEBREW = exports.HEBREW_GENERAL_CI;
243 +exports.HP8 = exports.HP8_ENGLISH_CI;
244 +exports.KEYBCS2 = exports.KEYBCS2_GENERAL_CI;
245 +exports.KOI8R = exports.KOI8R_GENERAL_CI;
246 +exports.KOI8U = exports.KOI8U_GENERAL_CI;
247 +exports.LATIN1 = exports.LATIN1_SWEDISH_CI;
248 +exports.LATIN2 = exports.LATIN2_GENERAL_CI;
249 +exports.LATIN5 = exports.LATIN5_TURKISH_CI;
250 +exports.LATIN7 = exports.LATIN7_GENERAL_CI;
251 +exports.MACCE = exports.MACCE_GENERAL_CI;
252 +exports.MACROMAN = exports.MACROMAN_GENERAL_CI;
253 +exports.SJIS = exports.SJIS_JAPANESE_CI;
254 +exports.SWE7 = exports.SWE7_SWEDISH_CI;
255 +exports.TIS620 = exports.TIS620_THAI_CI;
256 +exports.UCS2 = exports.UCS2_GENERAL_CI;
257 +exports.UJIS = exports.UJIS_JAPANESE_CI;
258 +exports.UTF16 = exports.UTF16_GENERAL_CI;
259 +exports.UTF16LE = exports.UTF16LE_GENERAL_CI;
260 +exports.UTF8 = exports.UTF8_GENERAL_CI;
261 +exports.UTF8MB4 = exports.UTF8MB4_GENERAL_CI;
262 +exports.UTF32 = exports.UTF32_GENERAL_CI;
1 +// Manually extracted from mysql-5.5.23/include/mysql_com.h
2 +exports.CLIENT_LONG_PASSWORD = 1; /* new more secure passwords */
3 +exports.CLIENT_FOUND_ROWS = 2; /* Found instead of affected rows */
4 +exports.CLIENT_LONG_FLAG = 4; /* Get all column flags */
5 +exports.CLIENT_CONNECT_WITH_DB = 8; /* One can specify db on connect */
6 +exports.CLIENT_NO_SCHEMA = 16; /* Don't allow database.table.column */
7 +exports.CLIENT_COMPRESS = 32; /* Can use compression protocol */
8 +exports.CLIENT_ODBC = 64; /* Odbc client */
9 +exports.CLIENT_LOCAL_FILES = 128; /* Can use LOAD DATA LOCAL */
10 +exports.CLIENT_IGNORE_SPACE = 256; /* Ignore spaces before '(' */
11 +exports.CLIENT_PROTOCOL_41 = 512; /* New 4.1 protocol */
12 +exports.CLIENT_INTERACTIVE = 1024; /* This is an interactive client */
13 +exports.CLIENT_SSL = 2048; /* Switch to SSL after handshake */
14 +exports.CLIENT_IGNORE_SIGPIPE = 4096; /* IGNORE sigpipes */
15 +exports.CLIENT_TRANSACTIONS = 8192; /* Client knows about transactions */
16 +exports.CLIENT_RESERVED = 16384; /* Old flag for 4.1 protocol */
17 +exports.CLIENT_SECURE_CONNECTION = 32768; /* New 4.1 authentication */
18 +
19 +exports.CLIENT_MULTI_STATEMENTS = 65536; /* Enable/disable multi-stmt support */
20 +exports.CLIENT_MULTI_RESULTS = 131072; /* Enable/disable multi-results */
21 +exports.CLIENT_PS_MULTI_RESULTS = 262144; /* Multi-results in PS-protocol */
22 +
23 +exports.CLIENT_PLUGIN_AUTH = 524288; /* Client supports plugin authentication */
24 +
25 +exports.CLIENT_SSL_VERIFY_SERVER_CERT = 1073741824;
26 +exports.CLIENT_REMEMBER_OPTIONS = 2147483648;
This diff could not be displayed because it is too large.
1 +// Manually extracted from mysql-5.5.23/include/mysql_com.h
2 +exports.NOT_NULL_FLAG = 1; /* Field can't be NULL */
3 +exports.PRI_KEY_FLAG = 2; /* Field is part of a primary key */
4 +exports.UNIQUE_KEY_FLAG = 4; /* Field is part of a unique key */
5 +exports.MULTIPLE_KEY_FLAG = 8; /* Field is part of a key */
6 +exports.BLOB_FLAG = 16; /* Field is a blob */
7 +exports.UNSIGNED_FLAG = 32; /* Field is unsigned */
8 +exports.ZEROFILL_FLAG = 64; /* Field is zerofill */
9 +exports.BINARY_FLAG = 128; /* Field is binary */
10 +
11 +/* The following are only sent to new clients */
12 +exports.ENUM_FLAG = 256; /* field is an enum */
13 +exports.AUTO_INCREMENT_FLAG = 512; /* field is a autoincrement field */
14 +exports.TIMESTAMP_FLAG = 1024; /* Field is a timestamp */
15 +exports.SET_FLAG = 2048; /* field is a set */
16 +exports.NO_DEFAULT_VALUE_FLAG = 4096; /* Field doesn't have default value */
17 +exports.ON_UPDATE_NOW_FLAG = 8192; /* Field is set to NOW on UPDATE */
18 +exports.NUM_FLAG = 32768; /* Field is num (for clients) */
1 +// Manually extracted from mysql-5.5.23/include/mysql_com.h
2 +
3 +/**
4 + Is raised when a multi-statement transaction
5 + has been started, either explicitly, by means
6 + of BEGIN or COMMIT AND CHAIN, or
7 + implicitly, by the first transactional
8 + statement, when autocommit=off.
9 +*/
10 +exports.SERVER_STATUS_IN_TRANS = 1;
11 +exports.SERVER_STATUS_AUTOCOMMIT = 2; /* Server in auto_commit mode */
12 +exports.SERVER_MORE_RESULTS_EXISTS = 8; /* Multi query - next query exists */
13 +exports.SERVER_QUERY_NO_GOOD_INDEX_USED = 16;
14 +exports.SERVER_QUERY_NO_INDEX_USED = 32;
15 +/**
16 + The server was able to fulfill the clients request and opened a
17 + read-only non-scrollable cursor for a query. This flag comes
18 + in reply to COM_STMT_EXECUTE and COM_STMT_FETCH commands.
19 +*/
20 +exports.SERVER_STATUS_CURSOR_EXISTS = 64;
21 +/**
22 + This flag is sent when a read-only cursor is exhausted, in reply to
23 + COM_STMT_FETCH command.
24 +*/
25 +exports.SERVER_STATUS_LAST_ROW_SENT = 128;
26 +exports.SERVER_STATUS_DB_DROPPED = 256; /* A database was dropped */
27 +exports.SERVER_STATUS_NO_BACKSLASH_ESCAPES = 512;
28 +/**
29 + Sent to the client if after a prepared statement reprepare
30 + we discovered that the new statement returns a different
31 + number of result set columns.
32 +*/
33 +exports.SERVER_STATUS_METADATA_CHANGED = 1024;
34 +exports.SERVER_QUERY_WAS_SLOW = 2048;
35 +
36 +/**
37 + To mark ResultSet containing output parameter values.
38 +*/
39 +exports.SERVER_PS_OUT_PARAMS = 4096;
1 +// Certificates for Amazon RDS
2 +exports['Amazon RDS'] = {
3 + ca: [
4 + /**
5 + * Amazon RDS global certificate 2010 to 2015
6 + *
7 + * CN = aws.amazon.com/rds/
8 + * OU = RDS
9 + * O = Amazon.com
10 + * L = Seattle
11 + * ST = Washington
12 + * C = US
13 + * P = 2010-04-05T22:44:31Z/2015-04-04T22:41:31Z
14 + * F = 7F:09:8D:A5:7D:BB:A6:EF:7C:70:D8:CA:4E:49:11:55:7E:89:A7:D3
15 + */
16 + '-----BEGIN CERTIFICATE-----\n'
17 + + 'MIIDQzCCAqygAwIBAgIJAOd1tlfiGoEoMA0GCSqGSIb3DQEBBQUAMHUxCzAJBgNV\n'
18 + + 'BAYTAlVTMRMwEQYDVQQIEwpXYXNoaW5ndG9uMRAwDgYDVQQHEwdTZWF0dGxlMRMw\n'
19 + + 'EQYDVQQKEwpBbWF6b24uY29tMQwwCgYDVQQLEwNSRFM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+ 'UCmmYqgiVkAGWRETVo+byOSDZ4swb10=\n'
35 + + '-----END CERTIFICATE-----\n',
36 +
37 + /**
38 + * Amazon RDS global root CA 2015 to 2020
39 + *
40 + * CN = Amazon RDS Root CA
41 + * OU = Amazon RDS
42 + * O = Amazon Web Services, Inc.
43 + * L = Seattle
44 + * ST = Washington
45 + * C = US
46 + * P = 2015-02-05T09:11:31Z/2020-03-05T09:11:31Z
47 + * F = E8:11:88:56:E7:A7:CE:3E:5E:DC:9A:31:25:1B:93:AC:DC:43:CE:B0
48 + */
49 + '-----BEGIN CERTIFICATE-----\n'
50 + + 'MIID9DCCAtygAwIBAgIBQjANBgkqhkiG9w0BAQUFADCBijELMAkGA1UEBhMCVVMx\n'
51 + + 'EzARBgNVBAgMCldhc2hpbmd0b24xEDAOBgNVBAcMB1NlYXR0bGUxIjAgBgNVBAoM\n'
52 + + 'GUFtYXpvbiBXZWIgU2VydmljZXMsIEluYy4xEzARBgNVBAsMCkFtYXpvbiBSRFMx\n'
53 + + 'GzAZBgNVBAMMEkFtYXpvbiBSRFMgUm9vdCBDQTAeFw0xNTAyMDUwOTExMzFaFw0y\n'
54 + + 'MDAzMDUwOTExMzFaMIGKMQswCQYDVQQGEwJVUzETMBEGA1UECAwKV2FzaGluZ3Rv\n'
55 + + 'bjEQMA4GA1UEBwwHU2VhdHRsZTEiMCAGA1UECgwZQW1hem9uIFdlYiBTZXJ2aWNl\n'
56 + + 'cywgSW5jLjETMBEGA1UECwwKQW1hem9uIFJEUzEbMBkGA1UEAwwSQW1hem9uIFJE\n'
57 + + 'UyBSb290IENBMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuD8nrZ8V\n'
58 + + 'u+VA8yVlUipCZIKPTDcOILYpUe8Tct0YeQQr0uyl018StdBsa3CjBgvwpDRq1HgF\n'
59 + + 'Ji2N3+39+shCNspQeE6aYU+BHXhKhIIStt3r7gl/4NqYiDDMWKHxHq0nsGDFfArf\n'
60 + + 'AOcjZdJagOMqb3fF46flc8k2E7THTm9Sz4L7RY1WdABMuurpICLFE3oHcGdapOb9\n'
61 + + 'T53pQR+xpHW9atkcf3pf7gbO0rlKVSIoUenBlZipUlp1VZl/OD/E+TtRhDDNdI2J\n'
62 + + 'P/DSMM3aEsq6ZQkfbz/Ilml+Lx3tJYXUDmp+ZjzMPLk/+3beT8EhrwtcG3VPpvwp\n'
63 + + 'BIOqsqVVTvw/CwIDAQABo2MwYTAOBgNVHQ8BAf8EBAMCAQYwDwYDVR0TAQH/BAUw\n'
64 + + 'AwEB/zAdBgNVHQ4EFgQUTgLurD72FchM7Sz1BcGPnIQISYMwHwYDVR0jBBgwFoAU\n'
65 + + 'TgLurD72FchM7Sz1BcGPnIQISYMwDQYJKoZIhvcNAQEFBQADggEBAHZcgIio8pAm\n'
66 + + 'MjHD5cl6wKjXxScXKtXygWH2BoDMYBJF9yfyKO2jEFxYKbHePpnXB1R04zJSWAw5\n'
67 + + '2EUuDI1pSBh9BA82/5PkuNlNeSTB3dXDD2PEPdzVWbSKvUB8ZdooV+2vngL0Zm4r\n'
68 + + '47QPyd18yPHrRIbtBtHR/6CwKevLZ394zgExqhnekYKIqqEX41xsUV0Gm6x4vpjf\n'
69 + + '2u6O/+YE2U+qyyxHE5Wd5oqde0oo9UUpFETJPVb6Q2cEeQib8PBAyi0i6KnF+kIV\n'
70 + + 'A9dY7IHSubtCK/i8wxMVqfd5GtbA8mmpeJFwnDvm9rBEsHybl08qlax9syEwsUYr\n'
71 + + '/40NawZfTUU=\n'
72 + + '-----END CERTIFICATE-----\n',
73 +
74 + /**
75 + * Amazon RDS global root CA 2019 to 2024
76 + *
77 + * CN = Amazon RDS Root 2019 CA
78 + * OU = Amazon RDS
79 + * O = Amazon Web Services, Inc.
80 + * L = Seattle
81 + * ST = Washington
82 + * C = US
83 + * P = 2019-08-22T17:08:50Z/2024-08-22T17:08:50Z
84 + * F = D4:0D:DB:29:E3:75:0D:FF:A6:71:C3:14:0B:BF:5F:47:8D:1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n'
101 + + 'BAMCAQYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUc19g2LzLA5j0Kxc0LjZa\n'
102 + + 'pmD/vB8wHwYDVR0jBBgwFoAUc19g2LzLA5j0Kxc0LjZapmD/vB8wDQYJKoZIhvcN\n'
103 + + 'AQELBQADggEBAHAG7WTmyjzPRIM85rVj+fWHsLIvqpw6DObIjMWokpliCeMINZFV\n'
104 + + 'ynfgBKsf1ExwbvJNzYFXW6dihnguDG9VMPpi2up/ctQTN8tm9nDKOy08uNZoofMc\n'
105 + + 'NUZxKCEkVKZv+IL4oHoeayt8egtv3ujJM6V14AstMQ6SwvwvA93EP/Ug2e4WAXHu\n'
106 + + 'cbI1NAbUgVDqp+DRdfvZkgYKryjTWd/0+1fS8X1bBZVWzl7eirNVnHbSH2ZDpNuY\n'
107 + + '0SBd8dj5F6ld3t58ydZbrTHze7JJOd8ijySAp4/kiu9UfZWuTPABzDa/DSdz9Dk/\n'
108 + + 'zPW4CXXvhLmE02TA9/HeCw3KEHIwicNuEfw=\n'
109 + + '-----END CERTIFICATE-----\n',
110 +
111 + /**
112 + * Amazon RDS ap-northeast-1 certificate CA 2015 to 2020
113 + *
114 + * CN = Amazon RDS ap-northeast-1 CA
115 + * OU = Amazon RDS
116 + * O = Amazon Web Services, Inc.
117 + * L = Seattle
118 + * ST = Washington
119 + * C = US
120 + * P = 2015-02-05T22:03:06Z/2020-03-05T22:03:06Z
121 + * F = 4B:2D:8A:E0:C1:A3:A9:AF:A7:BB:65:0C:5A:16:8A:39:3C:03:F2:C5
122 + */
123 + '-----BEGIN CERTIFICATE-----\n'
124 + + 'MIIEATCCAumgAwIBAgIBRDANBgkqhkiG9w0BAQUFADCBijELMAkGA1UEBhMCVVMx\n'
125 + + 'EzARBgNVBAgMCldhc2hpbmd0b24xEDAOBgNVBAcMB1NlYXR0bGUxIjAgBgNVBAoM\n'
126 + + 'GUFtYXpvbiBXZWIgU2VydmljZXMsIEluYy4xEzARBgNVBAs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+ 'JkBiGWiuzqn7gO5MJ0nMMro1+gq29qjZnYX1pDHPgsRjUX8R+juRhgJ3JSHijRbf\n'
142 + + '4qNJrnwga7pj94MhcLq9u0f6dxH6dXbyMv21T4TZMTmcFduf1KgaiVx1PEyJjC6r\n'
143 + + 'M+Ru+A0eM+jJ7uCjUoZKcpX8xkj4nmSnz9NMPog3wdOSB9cAW7XIc5mHa656wr7I\n'
144 + + 'WJxVcYNHTXIjCcng2zMKd1aCcl2KSFfy56sRfT7J5Wp69QSr+jq8KM55gw8uqAwi\n'
145 + + 'VPrXn2899T1rcTtFYFP16WXjGuc0\n'
146 + + '-----END CERTIFICATE-----\n',
147 +
148 + /**
149 + * Amazon RDS ap-northeast-2 certificate CA 2015 to 2020
150 + *
151 + * CN = Amazon RDS ap-northeast-2 CA
152 + * OU = Amazon RDS
153 + * O = Amazon Web Services, Inc.
154 + * L = Seattle
155 + * ST = Washington
156 + * C = US
157 + * P = 2015-11-06T00:05:46Z/2020-03-05T00:05:46Z
158 + * F = 77:D9:33:4E:CE:56:FC:42:7B:29:57:8D:67:59:ED:29:4E:18:CB:6B
159 + */
160 + '-----BEGIN CERTIFICATE-----\n'
161 + + 'MIIEATCCAumgAwIBAgIBTDANBgkqhkiG9w0BAQUFADCBijELMAkGA1UEBhMCVVMx\n'
162 + + 'EzARBgNVBAgMCldhc2hpbmd0b24xEDAOBgNVBAcMB1NlYXR0bGUxIjAgBgNVBAoM\n'
163 + + 'GUFtYXpvbiBXZWIgU2VydmljZXMsIEluYy4xEzARBgNVBAsMCkFtYXpvbiBSRFMx\n'
164 + + 'GzAZBgNVBAMMEkFtYXpvbiBSRFMgUm9vdCBDQTAeFw0xNTExMDYwMDA1NDZaFw0y\n'
165 + + 'MDAzMDUwMDA1NDZaMIGUMQswCQYDVQQGEwJVUzETMBEGA1UECAwKV2FzaGluZ3Rv\n'
166 + + 'bjEQMA4GA1UEBwwHU2VhdHRsZTEiMCAGA1UECgwZQW1hem9uIFdlYiBTZXJ2aW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yXteoGca/kA+/IqrAPlk0pWQ4aEL0yTWN2h2dnjoD7oX\n'
182 + + 'byIuL/g9AGRh97+ssn7D6bDRPTbW\n'
183 + + '-----END CERTIFICATE-----\n',
184 +
185 + /**
186 + * Amazon RDS ap-southeast-1 certificate CA 2015 to 2020
187 + *
188 + * CN = Amazon RDS ap-southeast-1 CA
189 + * OU = Amazon RDS
190 + * O = Amazon Web Services, Inc.
191 + * L = Seattle
192 + * ST = Washington
193 + * C = US
194 + * P = 2015-02-05T22:03:19Z/2020-03-05T22:03:19Z
195 + * F = 0E:EC:5D:BD:F9:80:EE:A9:A0:8D:81:AC:37:D9:8D:34:1C:CD:27:D1
196 + */
197 + '-----BEGIN CERTIFICATE-----\n'
198 + + 'MIIEATCCAumgAwIBAgIBRTANBgkqhkiG9w0BAQUFADCBijELMAkGA1UEBhMCVVMx\n'
199 + + 'EzARBgNVBAgMCldhc2hpbmd0b24xEDAOBgNVBAcMB1NlYXR0bGUxIjAgBgNVBAoM\n'
200 + + 'GUFtYXpvbiBXZWIgU2VydmljZXMsIEluYy4xEzARBgNVBAsMCkFtYXpvbiBSRFMx\n'
201 + + 'GzAZBgNVBAMMEkFtYXpvbiBSRFMgUm9vdCBDQTAeFw0xNTAyMDUyMjAzMTlaFw0y\n'
202 + + 'MDAzMDUyMjAzMTlaMIGUMQswCQYDVQQGEwJVUzETMBEGA1UECAwKV2FzaGluZ3Rv\n'
203 + + 'bjEQMA4GA1UEBwwHU2VhdHRsZTEiMCAGA1UECgwZQW1hem9uIFdlYiBTZXJ2aWNl\n'
204 + + 'cywgSW5jLjETMBEGA1UECwwKQW1hem9uIFJEUzElMCMGA1UEAwwcQW1hem9uIFJE\n'
205 + + 'UyBhcC1zb3V0aGVhc3QtMSBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC\n'
206 + + 'ggEBANaXElmSEYt/UtxHFsARFhSUahTf1KNJzR0Dmay6hqOXQuRVbKRwPd19u5vx\n'
207 + + 'DdF1sLT7D69IK3VDnUiQScaCv2Dpu9foZt+rLx+cpx1qiQd1UHrvqq8xPzQOqCdC\n'
208 + + 'RFStq6yVYZ69yfpfoI67AjclMOjl2Vph3ftVnqP0IgVKZdzeC7fd+umGgR9xY0Qr\n'
209 + + 'Ubhd/lWdsbNvzK3f1TPWcfIKQnpvSt85PIEDJir6/nuJUKMtmJRwTymJf0i+JZ4x\n'
210 + + '7dJa341p2kHKcHMgOPW7nJQklGBA70ytjUV6/qebS3yIugr/28mwReflg3TJzVDl\n'
211 + + 'EOvi6pqbqNbkMuEwGDCmEQIVqgkCAwEAAaNmMGQwDgYDVR0PAQH/BAQDAgEGMBIG\n'
212 + + 'A1UdEwEB/wQIMAYBAf8CAQAwHQYDVR0OBBYEFAu93/4k5xbWOsgdCdn+/KdiRuit\n'
213 + + 'MB8GA1UdIwQYMBaAFE4C7qw+9hXITO0s9QXBj5yECEmDMA0GCSqGSIb3DQEBBQUA\n'
214 + + 'A4IBAQBlcjSyscpPjf5+MgzMuAsCxByqUt+WFspwcMCpwdaBeHOPSQrXNqX2Sk6P\n'
215 + + 'kth6oCivA64trWo8tFMvPYlUA1FYVD5WpN0kCK+P5pD4KHlaDsXhuhClJzp/OP8t\n'
216 + + 'pOyUr5109RHLxqoKB5J5m1XA7rgcFjnMxwBSWFe3/4uMk/+4T53YfCVXuc6QV3i7\n'
217 + + 'I/2LAJwFf//pTtt6fZenYfCsahnr2nvrNRNyAxcfvGZ/4Opn/mJtR6R/AjvQZHiR\n'
218 + + 'bkRNKF2GW0ueK5W4FkZVZVhhX9xh1Aj2Ollb+lbOqADaVj+AT3PoJPZ3MPQHKCXm\n'
219 + + 'xwG0LOLlRr/TfD6li1AfOVTAJXv9\n'
220 + + '-----END CERTIFICATE-----\n',
221 +
222 + /**
223 + * Amazon RDS ap-southeast-2 certificate CA 2015 to 2020
224 + *
225 + * CN = Amazon RDS ap-southeast-2 CA
226 + * OU = Amazon RDS
227 + * O = Amazon Web Services, Inc.
228 + * L = Seattle
229 + * ST = Washington
230 + * C = US
231 + * P = 2015-02-05T22:03:24Z/2020-03-05T22:03:24Z
232 + * F = 20:D9:A8:82:23:AB:B9:E5:C5:24:10:D3:4D:0F:3D:B1:31:DF:E5:14
233 + */
234 + '-----BEGIN CERTIFICATE-----\n'
235 + + 'MIIEATCCAumgAwIBAgIBRjANBgkqhkiG9w0BAQUFADCBijELMAkGA1UEBhMCVVMx\n'
236 + + 'EzARBgNVBAgMCldhc2hpbmd0b24xEDAOBgNVBAcMB1NlYXR0bGUxIjAgBgNVBAoM\n'
237 + + 'GUFtYXpvbiBXZWIgU2VydmljZXMsIEluYy4xEzARBgNVBAsMCkFtYXpvbiBSRFMx\n'
238 + + 'GzAZBgNVBAMMEkFtYXpvbiBSRFMgUm9vdCBDQTAeFw0xNTAyMDUyMjAzMjRaFw0y\n'
239 + + 'MDAzMDUyMjAzMjRaMIGUMQswCQYDVQQGEwJVUzETMBEGA1UECAwKV2FzaGluZ3Rv\n'
240 + + 'bjEQMA4GA1UEBwwHU2VhdHRsZTEiMCAGA1UECgwZQW1hem9uIFdlYiBTZXJ2aWNl\n'
241 + + 'cywgSW5jLjETMBEGA1UECwwKQW1hem9uIFJEUzElMCMGA1UEAwwcQW1hem9uIFJE\n'
242 + + 'UyBhcC1zb3V0aGVhc3QtMiBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC\n'
243 + + 'ggEBAJqBAJutz69hFOh3BtLHZTbwE8eejGGKayn9hu98YMDPzWzGXWCmW+ZYWELA\n'
244 + + 'cY3cNWNF8K4FqKXFr2ssorBYim1UtYFX8yhydT2hMD5zgQ2sCGUpuidijuPA6zaq\n'
245 + + 'Z3tdhVR94f0q8mpwpv2zqR9PcqaGDx2VR1x773FupRPRo7mEW1vC3IptHCQlP/zE\n'
246 + + '7jQiLl28bDIH2567xg7e7E9WnZToRnhlYdTaDaJsHTzi5mwILi4cihSok7Shv/ME\n'
247 + + 'hnukvxeSPUpaVtFaBhfBqq055ePq9I+Ns4KGreTKMhU0O9fkkaBaBmPaFgmeX/XO\n'
248 + + 'n2AX7gMouo3mtv34iDTZ0h6YCGkCAwEAAaNmMGQwDgYDVR0PAQH/BAQDAgEGMBIG\n'
249 + + 'A1UdEwEB/wQIMAYBAf8CAQAwHQYDVR0OBBYEFIlQnY0KHYWn1jYumSdJYfwj/Nfw\n'
250 + + 'MB8GA1UdIwQYMBaAFE4C7qw+9hXITO0s9QXBj5yECEmDMA0GCSqGSIb3DQEBBQUA\n'
251 + + 'A4IBAQA0wVU6/l41cTzHc4azc4CDYY2Wd90DFWiH9C/mw0SgToYfCJ/5Cfi0NT/Y\n'
252 + + 'PRnk3GchychCJgoPA/k9d0//IhYEAIiIDjyFVgjbTkKV3sh4RbdldKVOUB9kumz/\n'
253 + + 'ZpShplsGt3z4QQiVnKfrAgqxWDjR0I0pQKkxXa6Sjkicos9LQxVtJ0XA4ieG1E7z\n'
254 + + 'zJr+6t80wmzxvkInSaWP3xNJK9azVRTrgQZQlvkbpDbExl4mNTG66VD3bAp6t3Wa\n'
255 + + 'B49//uDdfZmPkqqbX+hsxp160OH0rxJppwO3Bh869PkDnaPEd/Pxw7PawC+li0gi\n'
256 + + 'NRV8iCEx85aFxcyOhqn0WZOasxee\n'
257 + + '-----END CERTIFICATE-----\n',
258 +
259 + /**
260 + * Amazon RDS eu-central-1 certificate CA 2015 to 2020
261 + *
262 + * CN = Amazon RDS eu-central-1 CA
263 + * OU = Amazon RDS
264 + * O = Amazon Web Services, Inc.
265 + * L = Seattle
266 + * ST = Washington
267 + * C = US
268 + * P = 2015-02-05T22:03:31Z/2020-03-05T22:03:31Z
269 + * F = 94:B4:DF:B9:6D:7E:F7:C3:B7:BF:51:E9:A6:B7:44:A0:D0:82:11:84
270 + */
271 + '-----BEGIN CERTIFICATE-----\n'
272 + + 'MIID/zCCAuegAwIBAgIBRzANBgkqhkiG9w0BAQUFADCBijELMAkGA1UEBhMCVVMx\n'
273 + + 'EzARBgNVBAgMCldhc2hpbmd0b24xE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kqhkiG9w0BAQUFAAOC\n'
288 + + 'AQEAHpMmeVQNqcxgfQdbDIi5UIy+E7zZykmtAygN1XQrvga9nXTis4kOTN6g5/+g\n'
289 + + 'HCx7jIXeNJzAbvg8XFqBN84Quqgpl/tQkbpco9Jh1HDs558D5NnZQxNqH5qXQ3Mm\n'
290 + + 'uPgCw0pYcPOa7bhs07i+MdVwPBsX27CFDtsgAIru8HvKxY1oTZrWnyIRo93tt/pk\n'
291 + + 'WuItVMVHjaQZVfTCow0aDUbte6Vlw82KjUFq+n2NMSCJDiDKsDDHT6BJc4AJHIq3\n'
292 + + '/4Z52MSC9KMr0yAaaoWfW/yMEj9LliQauAgwVjArF4q78rxpfKTG9Rfd8U1BZANP\n'
293 + + '7FrFMN0ThjfA1IvmOYcgskY5bQ==\n'
294 + + '-----END CERTIFICATE-----\n',
295 +
296 + /**
297 + * Amazon RDS eu-west-1 certificate CA 2015 to 2020
298 + *
299 + * CN = Amazon RDS eu-west-1 CA
300 + * OU = Amazon RDS
301 + * O = Amazon Web Services, Inc.
302 + * L = Seattle
303 + * ST = Washington
304 + * C = US
305 + * P = 2015-02-05T22:03:35Z/2020-03-05T22:03:35Z
306 + * F = 1A:95:F0:43:82:D2:5D:A6:AD:F5:13:27:0B:40:8A:72:D9:92:F3:E0
307 + */
308 + '-----BEGIN CERTIFICATE-----\n'
309 + + 'MIID/DCCAuSgAwIBAgIBSDANBgkqhkiG9w0BAQUFADCBijELMAkGA1UEBhMCVVMx\n'
310 + + 'EzARBgNVBAgMCldhc2hpbmd0b24xEDAOBgNVBAcMB1NlYXR0bGUxIjAgBgNVBAoM\n'
311 + + 'GUFtYXpvbiBXZWIgU2VydmljZXMsIEluYy4xEzARBgNVBAsMCkFtYXpvbiBSRFMx\n'
312 + + 'GzAZBgNVBAMMEkFtYXpvbiBSRFMgUm9vdCBDQTAeFw0xNTAyMDUyMjAzMzVaFw0y\n'
313 + + 'MDAzMDUyMjAzMzVaMIGPMQswCQYDVQQGEwJVUzETM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
328 + + 'kpgk10VZ75b8m3UhmpZ/2uRY+JEHImH5WpcTJ7wNiPNJsciZMznGtrgOnPzYco8L\n'
329 + + 'cDleOASIZifNMQi9PKOJKvi0ITz0B/imr8KBsW0YjZVJ54HMa7W1lwugSM7aMAs+\n'
330 + + 'E3Sd5lS+SHwWaOCHwhOEVA==\n'
331 + + '-----END CERTIFICATE-----\n',
332 +
333 + /**
334 + * Amazon RDS sa-east-1 certificate CA 2015 to 2020
335 + *
336 + * CN = Amazon RDS sa-east-1 CA
337 + * OU = Amazon RDS
338 + * O = Amazon Web Services, Inc.
339 + * L = Seattle
340 + * ST = Washington
341 + * C = US
342 + * P = 2015-02-05T22:03:40Z/2020-03-05T22:03:40Z
343 + * F = 32:10:3D:FA:6D:42:F5:35:98:40:15:F4:4C:74:74:27:CB:CE:D4:B5
344 + */
345 + '-----BEGIN CERTIFICATE-----\n'
346 + + 'MIID/DCCAuSgAwIBAgIBSTANBgkqhkiG9w0BAQUFADCBijELMAkGA1UEBhMCVVMx\n'
347 + + 'EzARBgNVBAgMCldhc2hpbmd0b24xEDAOBgNVBAcMB1NlYXR0bGUxIjAgBgNVBAoM\n'
348 + + 'GUFtYXpvbiBXZWIgU2VydmljZXMsIEluYy4xEzARBgNVBAsMCkFtYXpvbiBSRFMx\n'
349 + + 'GzAZBgNVBAMMEkFtYXpvbiBSRFMgUm9vdCBDQTAeFw0xNTAyMDUyMjAzNDBaFw0y\n'
350 + + 'MDAzMDUyMjAzNDBaMIGPMQswCQYDVQQGEwJVUzETMBEGA1UECAwKV2FzaGluZ3Rv\n'
351 + + 'bjEQMA4GA1UEBwwHU2VhdHRsZTEiMCAGA1UECgwZQW1hem9uIFdlYiBTZXJ2aWNl\n'
352 + + 'cywgSW5jLjETMBEGA1UECwwKQW1hem9uIFJEUzEgMB4GA1UEAwwXQW1hem9uIFJE\n'
353 + + 'UyBzYS1lYXN0LTEgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCU\n'
354 + + 'X4OBnQ5xA6TLJAiFEI6l7bUWjoVJBa/VbMdCCSs2i2dOKmqUaXu2ix2zcPILj3lZ\n'
355 + + 'GMk3d/2zvTK/cKhcFrewHUBamTeVHdEmynhMQamqNmkM4ptYzFcvEUw1TGxHT4pV\n'
356 + + 'Q6gSN7+/AJewQvyHexHo8D0+LDN0/Wa9mRm4ixCYH2CyYYJNKaZt9+EZfNu+PPS4\n'
357 + + '8iB0TWH0DgQkbWMBfCRgolLLitAZklZ4dvdlEBS7evN1/7ttBxUK6SvkeeSx3zBl\n'
358 + + 'ww3BlXqc3bvTQL0A+RRysaVyFbvtp9domFaDKZCpMmDFAN/ntx215xmQdrSt+K3F\n'
359 + + 'cXdGQYHx5q410CAclGnbAgMBAAGjZjBkMA4GA1UdDwEB/wQEAwIBBjASBgNVHRMB\n'
360 + + 'Af8ECDAGAQH/AgEAMB0GA1UdDgQWBBT6iVWnm/uakS+tEX2mzIfw+8JL0zAfBgNV\n'
361 + + 'HSMEGDAWgBROAu6sPvYVyEztLPUFwY+chAhJgzANBgkqhkiG9w0BAQUFAAOCAQEA\n'
362 + + 'FmDD+QuDklXn2EgShwQxV13+txPRuVdOSrutHhoCgMwFWCMtPPtBAKs6KPY7Guvw\n'
363 + + 'DpJoZSehDiOfsgMirjOWjvfkeWSNvKfjWTVneX7pZD9W5WPnsDBvTbCGezm+v87z\n'
364 + + 'b+ZM2ZMo98m/wkMcIEAgdSKilR2fuw8rLkAjhYFfs0A7tDgZ9noKwgHvoE4dsrI0\n'
365 + + 'KZYco6DlP/brASfHTPa2puBLN9McK3v+h0JaSqqm5Ro2Bh56tZkQh8AWy/miuDuK\n'
366 + + '3+hNEVdxosxlkM1TPa1DGj0EzzK0yoeerXuH2HX7LlCrrxf6/wdKnjR12PMrLQ4A\n'
367 + + 'pCqkcWw894z6bV9MAvKe6A==\n'
368 + + '-----END CERTIFICATE-----\n',
369 +
370 + /**
371 + * Amazon RDS us-east-1 certificate CA 2015 to 2020
372 + *
373 + * CN = Amazon RDS us-east-1 CA
374 + * OU = Amazon RDS
375 + * O = Amazon Web Services, Inc.
376 + * L = Seattle
377 + * ST = Washington
378 + * C = US
379 + * P = 2015-02-05T21:54:04Z/2020-03-05T21:54:04Z
380 + * F = 34:47:8A:90:8A:83:AE:45:DC:B6:16:76:D2:35:EC:E9:75:C6:2C:63
381 + */
382 + '-----BEGIN CERTIFICATE-----\n'
383 + + 'MIID/DCCAuSgAwIBAgIBQzANBgkqhkiG9w0BAQUFADCBijELMAkGA1UEBhMCVVMx\n'
384 + + 'EzARBgNVBAgMCldhc2hpbmd0b24xEDAOBgNVBAcMB1NlYXR0bGUxIjAgBgNVBAoM\n'
385 + + 'GUFtYXpvbiBXZWIgU2VydmljZXMsIEluYy4xEzARBgNVBAsMCkFtYXpvbiBSRFMx\n'
386 + + 'GzAZBgNVBAMMEkFtYXpvbiBSRFMgUm9vdCBDQTAeFw0xNTAyMDUyMTU0MDRaFw0y\n'
387 + + 'MDAzMDUyMTU0MDRaMIGPMQswCQYDVQQGEwJVUzETMBEGA1UECAwKV2FzaGluZ3Rv\n'
388 + + 'bjEQMA4GA1UEBwwHU2VhdHRsZTEiMCAGA1UECgwZQW1hem9uIFdlYiBTZXJ2aWNl\n'
389 + + 'cywgSW5jLjETMBEGA1UECwwKQW1hem9uIFJEUzEgMB4GA1UEAwwXQW1hem9uIFJE\n'
390 + + 'UyB1cy1lYXN0LTEgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDI\n'
391 + + 'UIuwh8NusKHk1SqPXcP7OqxY3S/M2ZyQWD3w7Bfihpyyy/fc1w0/suIpX3kbMhAV\n'
392 + + '2ESwged2/2zSx4pVnjp/493r4luhSqQYzru78TuPt9bhJIJ51WXunZW2SWkisSaf\n'
393 + + 'USYUzVN9ezR/bjXTumSUQaLIouJt3OHLX49s+3NAbUyOI8EdvgBQWD68H1epsC0n\n'
394 + + 'CI5s+pIktyOZ59c4DCDLQcXErQ+tNbDC++oct1ANd/q8p9URonYwGCGOBy7sbCYq\n'
395 + + '9eVHh1Iy2M+SNXddVOGw5EuruvHoCIQyOz5Lz4zSuZA9dRbrfztNOpezCNYu6NKM\n'
396 + + 'n+hzcvdiyxv77uNm8EaxAgMBAAGjZjBkMA4GA1UdDwEB/wQEAwIBBjASBgNVHRMB\n'
397 + + 'Af8ECDAGAQH/AgEAMB0GA1UdDgQWBBQSQG3TmMe6Sa3KufaPBa72v4QFDzAfBgNV\n'
398 + + 'HSMEGDAWgBROAu6sPvYVyEztLPUFwY+chAhJgzANBgkqhkiG9w0BAQUFAAOCAQEA\n'
399 + + 'L/mOZfB3187xTmjOHMqN2G2oSKHBKiQLM9uv8+97qT+XR+TVsBT6b3yoPpMAGhHA\n'
400 + + 'Pc7nxAF5gPpuzatx0OTLPcmYucFmfqT/1qA5WlgCnMNtczyNMH97lKFTNV7Njtek\n'
401 + + 'jWEzAEQSyEWrkNpNlC4j6kMYyPzVXQeXUeZTgJ9FNnVZqmvfjip2N22tawMjrCn5\n'
402 + + '7KN/zN65EwY2oO9XsaTwwWmBu3NrDdMbzJnbxoWcFWj4RBwanR1XjQOVNhDwmCOl\n'
403 + + '/1Et13b8CPyj69PC8BOVU6cfTSx8WUVy0qvYOKHNY9Bqa5BDnIL3IVmUkeTlM1mt\n'
404 + + 'enRpyBj+Bk9rh/ICdiRKmA==\n'
405 + + '-----END CERTIFICATE-----\n',
406 +
407 + /**
408 + * Amazon RDS us-west-1 certificate CA 2015 to 2020
409 + *
410 + * CN = Amazon RDS us-west-1 CA
411 + * OU = Amazon RDS
412 + * O = Amazon Web Services, Inc.
413 + * L = Seattle
414 + * ST = Washington
415 + * C = US
416 + * P = 2015-02-05T22:03:45Z/2020-03-05T22:03:45Z
417 + * F = EF:94:2F:E3:58:0E:09:D6:79:C2:16:97:91:FB:37:EA:D7:70:A8:4B
418 + */
419 + '-----BEGIN CERTIFICATE-----\n'
420 + + 'MIID/DCCAuSgAwIBAgIBSjANBgkqhk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y4oOD8bzAfBgNV\n'
435 + + 'HSMEGDAWgBROAu6sPvYVyEztLPUFwY+chAhJgzANBgkqhkiG9w0BAQUFAAOCAQEA\n'
436 + + 'CXGAY3feAak6lHdqj6+YWjy6yyUnLK37bRxZDsyDVXrPRQaXRzPTzx79jvDwEb/H\n'
437 + + 'Q/bdQ7zQRWqJcbivQlwhuPJ4kWPUZgSt3JUUuqkMsDzsvj/bwIjlrEFDOdHGh0mi\n'
438 + + 'eVIngFEjUXjMh+5aHPEF9BlQnB8LfVtKj18e15UDTXFa+xJPFxUR7wDzCfo4WI1m\n'
439 + + 'sUMG4q1FkGAZgsoyFPZfF8IVvgCuGdR8z30VWKklFxttlK0eGLlPAyIO0CQxPQlo\n'
440 + + 'saNJrHf4tLOgZIWk+LpDhNd9Et5EzvJ3aURUsKY4pISPPF5WdvM9OE59bERwUErd\n'
441 + + 'nuOuQWQeeadMceZnauRzJQ==\n'
442 + + '-----END CERTIFICATE-----\n',
443 +
444 + /**
445 + * Amazon RDS us-west-2 certificate CA 2015 to 2020
446 + *
447 + * CN = Amazon RDS us-west-2 CA
448 + * OU = Amazon RDS
449 + * O = Amazon Web Services, Inc.
450 + * L = Seattle
451 + * ST = Washington
452 + * C = US
453 + * P = 2015-02-05T22:03:50Z/2020-03-05T22:03:50Z
454 + * F = 94:2C:A8:B0:23:48:17:F0:CD:2F:19:7F:C1:E0:21:7C:65:79:13:3A
455 + */
456 + '-----BEGIN CERTIFICATE-----\n'
457 + + 'MIID/DCCAuSgAwIBAgIBSzANBgkqhkiG9w0BAQUFADCBijELMAkGA1UEBhMCVVMx\n'
458 + + 'EzARBgNVBAgMCldhc2hpbmd0b24xEDAOBgNVBAcMB1NlYXR0bGUxIjAgBgNVBAoM\n'
459 + + 'GUFtYXpvbiBXZWIgU2VydmljZXMsIEluYy4xEzARBgNVBAsMCkFtYXpvbiBSRFMx\n'
460 + + 'GzAZBgNVBAMMEkFtYXpvbiBSRFMgUm9vdCBDQTAeFw0xNTAyMDU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UYkzPvCkXe9wEz5zdUTOCptDt89rBR9CstL9vE7WYUgiVVmBJffWbHQLtfjv6OF\n'
476 + + 'NMb0QME981kGRzc2WhgP71YS2hHd1kXtsoYP1yTu4vThSKsoN4bkiHsaC1cRkLoy\n'
477 + + '0fFA4wpB3WloMEvCDaUvvH1LZlBXTNlwi9KtcwD4tDxkkBt4tQczKLGpQ/nF/W9n\n'
478 + + '8YDWk3IIc1sd0bkZqoau2Q==\n'
479 + + '-----END CERTIFICATE-----\n',
480 +
481 + /**
482 + * Amazon RDS ap-south-1 certificate CA 2016 to 2020
483 + *
484 + * CN = Amazon RDS ap-south-1 CA
485 + * OU = Amazon RDS
486 + * O = Amazon Web Services, Inc.
487 + * L = Seattle
488 + * ST = Washington
489 + * C = US
490 + * P = 2016-05-03T21:29:22Z/2020-03-05T21:29:22Z
491 + * F = F3:A3:C2:52:D9:82:20:AC:8C:62:31:2A:8C:AD:5D:7B:1C:31:F1:DD
492 + */
493 + '-----BEGIN CERTIFICATE-----\n'
494 + + 'MIID/TCCAuWgAwIBAgIBTTANBgkqhkiG9w0BAQsFADCBijELMAkGA1UEBhMCVVMx\n'
495 + + 'EzARBgNVBAgMCldhc2hpbmd0b24xEDAOBgNVBAcMB1NlYXR0bGUxIjAgBgNVBAoM\n'
496 + + 'GUFtYXpvbiBXZWIgU2VydmljZXMsIEluYy4xEzARBgNVBAsMCkFtYXpvbiBSRFMx\n'
497 + + 'GzAZBgNVBAMMEkFtYXpvbiBSRFMgUm9vdCBDQTAeFw0xNjA1MDMyMTI5MjJaFw0y\n'
498 + + 'MDAzMDUyMTI5MjJaMIGQMQswCQYDVQQGEwJVUzETMBEGA1UECAwKV2FzaGluZ3Rv\n'
499 + + 'bjEQMA4GA1UEBwwHU2VhdHRsZTEiMCAGA1UECgwZQW1hem9uIFdlYiBTZXJ2aWNl\n'
500 + + 'cywgSW5jLjETMBEGA1UECwwKQW1hem9uIFJEUzEhMB8GA1UEAwwYQW1hem9uIFJE\n'
501 + + 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END CERTIFICATE-----\n',
517 +
518 + /**
519 + * Amazon RDS us-east-2 certificate CA 2016 to 2020
520 + *
521 + * CN = Amazon RDS us-east-2 CA
522 + * OU = Amazon RDS
523 + * O = Amazon Web Services, Inc.
524 + * L = Seattle
525 + * ST = Washington
526 + * C = US
527 + * P = 2016-08-11T19:58:45Z/2020-03-05T19:58:45Z
528 + * F = 9B:78:E3:64:7F:74:BC:B2:52:18:CF:13:C3:62:B8:35:9D:3D:5F:B6
529 + */
530 + '-----BEGIN CERTIFICATE-----\n'
531 + + 'MIID/DCCAuSgAwIBAgIBTjANBgkqhkiG9w0BAQsFADCBijELMAkGA1UEBhMCVVMx\n'
532 + + 'EzARBgNVBAgMCldhc2hpbmd0b24xEDAOBgNVBAcMB1NlYXR0bGUxIjAgBgNVBAoM\n'
533 + + 'GUFtYXpvbiBXZWIgU2VydmljZXMsIEluYy4xEzARBgNVBAsMCkFtYXpvbiBSRFMx\n'
534 + + 'GzAZBgNVBAMMEkFtYXpvbiBSRFMgUm9vdCBDQTAeFw0xNjA4MTExOTU4NDVaFw0y\n'
535 + + 'MDAzMDUxOTU4NDVaMIGPMQswCQYDVQQGEwJVUzETMBEGA1UECAwKV2FzaGluZ3Rv\n'
536 + + 'bjEQMA4GA1UEBwwHU2VhdHRsZTEiMCAGA1UECgwZQW1hem9uIFdlYiBTZXJ2aWNl\n'
537 + + 'cywgSW5jLjETMBEGA1UECwwKQW1hem9uIFJEUzEgMB4GA1UEAwwXQW1hem9uIFJE\n'
538 + + 'UyB1cy1lYXN0LTIgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCp\n'
539 + + 'WnnUX7wM0zzstccX+4iXKJa9GR0a2PpvB1paEX4QRCgfhEdQWDaSqyrWNgdVCKkt\n'
540 + + '1aQkWu5j6VAC2XIG7kKoonm1ZdBVyBLqW5lXNywlaiU9yhJkwo8BR+/OqgE+PLt/\n'
541 + + 'EO1mlN0PQudja/XkExCXTO29TG2j7F/O7hox6vTyHNHc0H88zS21uPuBE+jivViS\n'
542 + + 'yzj/BkyoQ85hnkues3f9R6gCGdc+J51JbZnmgzUkvXjAEuKhAm9JksVOxcOKUYe5\n'
543 + + 'ERhn0U9zjzpfbAITIkul97VVa5IxskFFTHIPJbvRKHJkiF6wTJww/tc9wm+fSCJ1\n'
544 + + '+DbQTGZgkQ3bJrqRN29/AgMBAAGjZjBkMA4GA1UdDwEB/wQEAwIBBjASBgNVHRMB\n'
545 + + 'Af8ECDAGAQH/AgEAMB0GA1UdDgQWBBSAHQzUYYZbepwKEMvGdHp8wzHnfDAfBgNV\n'
546 + + 'HSMEGDAWgBROAu6sPvYVyEztLPUFwY+chAhJgzANBgkqhkiG9w0BAQsFAAOCAQEA\n'
547 + + 'MbaEzSYZ+aZeTBxf8yi0ta8K4RdwEJsEmP6IhFFQHYUtva2Cynl4Q9tZg3RMsybT\n'
548 + + '9mlnSQQlbN/wqIIXbkrcgFcHoXG9Odm/bDtUwwwDaiEhXVfeQom3G77QHOWMTCGK\n'
549 + + 'qadwuh5msrb17JdXZoXr4PYHDKP7j0ONfAyFNER2+uecblHfRSpVq5UeF3L6ZJb8\n'
550 + + 'fSw/GtAV6an+/0r+Qm+PiI2H5XuZ4GmRJYnGMhqWhBYrY7p3jtVnKcsh39wgfUnW\n'
551 + + 'AvZEZG/yhFyAZW0Essa39LiL5VSq14Y1DOj0wgnhSY/9WHxaAo1HB1T9OeZknYbD\n'
552 + + 'fl/EGSZ0TEvZkENrXcPlVA==\n'
553 + + '-----END CERTIFICATE-----\n',
554 +
555 + /**
556 + * Amazon RDS ca-central-1 certificate CA 2016 to 2020
557 + *
558 + * CN = Amazon RDS ca-central-1 CA
559 + * OU = Amazon RDS
560 + * O = Amazon Web Services, Inc.
561 + * L = Seattle
562 + * ST = Washington
563 + * C = US
564 + * P = 2016-09-15T00:10:11Z/2020-03-05T00:10:11Z
565 + * F = D7:E0:16:AB:8A:0B:63:9F:67:1F:16:87:42:F4:0A:EE:73:A6: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wEB/wQEAwIBBjASBgNV\n'
582 + + 'HRMBAf8ECDAGAQH/AgEAMB0GA1UdDgQWBBToYWxE1lawl6Ks6NsvpbHQ3GKEtzAf\n'
583 + + 'BgNVHSMEGDAWgBROAu6sPvYVyEztLPUFwY+chAhJgzANBgkqhkiG9w0BAQsFAAOC\n'
584 + + 'AQEAG/8tQ0ooi3hoQpa5EJz0/E5VYBsAz3YxA2HoIonn0jJyG16bzB4yZt4vNQMA\n'
585 + + 'KsNlQ1uwDWYL1nz63axieUUFIxqxl1KmwfhsmLgZ0Hd2mnTPIl2Hw3uj5+wdgGBg\n'
586 + + 'agnAZ0bajsBYgD2VGQbqjdk2Qn7Fjy3LEWIvGZx4KyZ99OJ2QxB7JOPdauURAtWA\n'
587 + + 'DKYkP4LLJxtj07DSzG8kuRWb9B47uqUD+eKDIyjfjbnzGtd9HqqzYFau7EX3HVD9\n'
588 + + '9Qhnjl7bTZ6YfAEZ3nH2t3Vc0z76XfGh47rd0pNRhMV+xpok75asKf/lNh5mcUrr\n'
589 + + 'VKwflyMkQpSbDCmcdJ90N2xEXQ==\n'
590 + + '-----END CERTIFICATE-----\n',
591 +
592 + /**
593 + * Amazon RDS eu-west-2 certificate CA 2016 to 2020
594 + *
595 + * CN = Amazon RDS eu-west-2 CA
596 + * OU = Amazon RDS
597 + * O = Amazon Web Services, Inc.
598 + * L = Seattle
599 + * ST = Washington
600 + * C = US
601 + * P = 2016-10-10T17:44:42Z/2020-03-05T17:44:42Z
602 + * F = 47:79:51:9F:FF:07:D3:F4:27:D3:AB:64:56:7F:00:45:BB:84:C1:71
603 + */
604 + '-----BEGIN CERTIFICATE-----\n'
605 + + 'MIID/DCCAuSgAwIBAgIBUDANBgkqhkiG9w0BAQsFADCBijELMAkGA1UEBhMCVVMx\n'
606 + + 'EzARBgNVBAgMCldhc2hpbmd0b24xEDAOBgNVBAcMB1NlYXR0bGUxIjAgBgNVBAoM\n'
607 + + 'GUFtYXpvbiBXZWIgU2VydmljZXMsIElu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DAk1SD\n'
622 + + 'RSgfEBon5vvKEtlnTf9a3pv8WXOAkhfxnryr9FH6NiB8obISHNQNPHn0ljT2/T+I\n'
623 + + 'Y6ytfRvKHa0cu3V0NXbJm2B4KEOt4QCDiFxUIX9z6eB4Kditwu05OgQh6KcogOiP\n'
624 + + 'JesWxBMXXGoDC1rIYTFO7szwDyOHlCcVXJDNsTJhc32oDWYdeIbW7o/5I+aQsrXZ\n'
625 + + 'C96HykZcgWzz6sElrQxUaT3IoMw/5nmw4uWKKnZnxgI9bY4fpQwMeBZ96iHfFxvH\n'
626 + + 'mqfEEuC7uUoPofXdBp2ObQ==\n'
627 + + '-----END CERTIFICATE-----\n',
628 +
629 + /**
630 + * Amazon RDS us-gov-west-1 CA 2017 to 2022
631 + *
632 + * CN = Amazon RDS us-gov-west-1 CA
633 + * OU = Amazon RDS
634 + * O = Amazon Web Services, Inc.
635 + * L = Seattle
636 + * ST = Washington
637 + * C = US
638 + * P = 2017-05-19T22:31:19Z/2022-05-18T12:00:00Z
639 + * F = 77:55:8C:C4:5E:71:1F:1B:57:E3:DA:6E:5B:74:27:12:4E:E8:69:E8
640 + */
641 + '-----BEGIN CERTIFICATE-----\n'
642 + + 'MIIECjCCAvKgAwIBAgICEAAwDQYJKoZIhvcNAQELBQAwgZMxCzAJBgNVBAYTAlVT\n'
643 + + 'MRAwDgYDVQQHDAdTZWF0dGxlMRMwEQYDVQQIDApXYXNoaW5ndG9uMSIwIAYDVQQK\n'
644 + + 'DBlBbWF6b24gV2ViIFNlcnZpY2VzLCBJbmMuMRMwEQYDVQQLDApBbWF6b24gUkRT\n'
645 + + 'MSQwIgYDVQQDDBtBbWF6b24gUkRTIEdvdkNsb3VkIFJvb3QgQ0EwHhcNMTcwNTE5\n'
646 + + 'MjIzMTE5WhcNMjIwNTE4MTIwMDAwWjCBkzELMAkGA1UEBhMCVVMxEzARBgNVBAgM\n'
647 + + 'Cldhc2hpbmd0b24xEDAOBgNVBAcMB1NlYXR0bGUxIjAgB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+ + 'RuUCvyQecy2ZFNAa3jmd5ycNdL63RWe8oayRBpQBxPPCbHfILxGZEdJbCH9aJ2D/\n'
663 + + 'l8oHIDnvOLdv7/cBjyYuvmprgPtu3QEkbre5Hln/\n'
664 + + '-----END CERTIFICATE-----\n',
665 +
666 + /**
667 + * Amazon RDS eu-west-3 certificate CA 2017 to 2020
668 + *
669 + * CN = Amazon RDS eu-west-3 CA
670 + * OU = Amazon RDS
671 + * O = Amazon Web Services, Inc.
672 + * L = Seattle
673 + * ST = Washington
674 + * C = US
675 + * P = 2017-08-25T21:39:26Z/2020-03-05T21:39:26Z
676 + * F = FD:35:A7:84:60:68:98:00:12:54:ED:34:26:8C:66:0F:72:DD:B2:F4
677 + */
678 + '-----BEGIN CERTIFICATE-----\n'
679 + + 'MIID/DCCAuSgAwIBAgIBUTANBgkqhkiG9w0BAQsFADCBijELMAkGA1UEBhMCVVMx\n'
680 + + 'EzARBgNVBAgMCldhc2hpbmd0b24xEDAOBgNVBAcMB1NlYXR0bGUxIjAgBgNVBAoM\n'
681 + + 'GUFtYXpvbiBXZWIgU2VydmljZXMsIEluYy4xEzARBgNVBAsMCkFtYXpvbiBSRFMx\n'
682 + + 'GzAZBgNVBAMMEkFtYXpvbiBSRFMgUm9vdCBDQTAeFw0xNzA4MjUyMTM5MjZaFw0y\n'
683 + + 'MDAzMDUyMTM5MjZaMIGPMQswCQYDVQQGEwJVUzETMBEGA1UECAwKV2FzaGluZ3Rv\n'
684 + + 'bjEQMA4GA1UEBwwHU2VhdHRsZTEiMCAGA1UECgwZQW1hem9uIFdlYiBTZXJ2aWNl\n'
685 + + 'cywgSW5jLjETMBEGA1UECwwKQW1hem9uIFJEUzEgMB4GA1UEAwwXQW1hem9uIFJE\n'
686 + + 'UyBldS13ZXN0LTMgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC+\n'
687 + + 'xmlEC/3a4cJH+UPwXCE02lC7Zq5NHd0dn6peMeLN8agb6jW4VfSY0NydjRj2DJZ8\n'
688 + + 'K7wV6sub5NUGT1NuFmvSmdbNR2T59KX0p2dVvxmXHHtIpQ9Y8Aq3ZfhmC5q5Bqgw\n'
689 + + 'tMA1xayDi7HmoPX3R8kk9ktAZQf6lDeksCvok8idjTu9tiSpDiMwds5BjMsWfyjZ\n'
690 + + 'd13PTGGNHYVdP692BSyXzSP1Vj84nJKnciW8tAqwIiadreJt5oXyrCXi8ekUMs80\n'
691 + + 'cUTuGm3aA3Q7PB5ljJMPqz0eVddaiIvmTJ9O3Ez3Du/HpImyMzXjkFaf+oNXf/Hx\n'
692 + + '/EW5jCRR6vEiXJcDRDS7AgMBAAGjZjBkMA4GA1UdDwEB/wQEAwIBBjASBgNVHRMB\n'
693 + + 'Af8ECDAGAQH/AgEAMB0GA1UdDgQWBBRZ9mRtS5fHk3ZKhG20Oack4cAqMTAfBgNV\n'
694 + + 'HSMEGDAWgBROAu6sPvYVyEztLPUFwY+chAhJgzANBgkqhkiG9w0BAQsFAAOCAQEA\n'
695 + + 'F/u/9L6ExQwD73F/bhCw7PWcwwqsK1mypIdrjdIsu0JSgwWwGCXmrIspA3n3Dqxq\n'
696 + + 'sMhAJD88s9Em7337t+naar2VyLO63MGwjj+vA4mtvQRKq8ScIpiEc7xN6g8HUMsd\n'
697 + + 'gPG9lBGfNjuAZsrGJflrko4HyuSM7zHExMjXLH+CXcv/m3lWOZwnIvlVMa4x0Tz0\n'
698 + + 'A4fklaawryngzeEjuW6zOiYCzjZtPlP8Fw0SpzppJ8VpQfrZ751RDo4yudmPqoPK\n'
699 + + '5EUe36L8U+oYBXnC5TlYs9bpVv9o5wJQI5qA9oQE2eFWxF1E0AyZ4V5sgGUBStaX\n'
700 + + 'BjDDWul0wSo7rt1Tq7XpnA==\n'
701 + + '-----END CERTIFICATE-----\n',
702 +
703 + /**
704 + * Amazon RDS ap-northeast-3 certificate CA 2017 to 2020
705 + *
706 + * CN = Amazon RDS ap-northeast-3 CA
707 + * OU = Amazon RDS
708 + * O = Amazon Web Services, Inc.
709 + * L = Seattle
710 + * ST = Washington
711 + * C = US
712 + * P = 2017-12-01T00:55:42Z/2020-03-05T00:55:42Z
713 + * F = C0:C7:D4:B3:91:40:A0:77:43:28:BF:AF:77:57:DF:FD:98:FB:10:3F
714 + */
715 + '-----BEGIN CERTIFICATE-----\n'
716 + + 'MIIEATCCAumgAwIBAgIBTjANBgkqhkiG9w0BAQUFADCBijELMAkGA1UEBhMCVVMx\n'
717 + + 'EzARBgNVBAgMCldhc2hpbmd0b24xEDAOBgNVBAcMB1NlYXR0bGUxIjAgBgNVBAoM\n'
718 + + 'GUFtYXpvbiBXZWIgU2VydmljZXMsIEluYy4xEzARBgNVBAsMCkFtYXpvbiBSRFMx\n'
719 + + 'GzAZBgNVBAMMEkFtYXpvbiBSRFMgUm9vdCBDQTAeFw0xNzEyMDEwMDU1NDJaFw0y\n'
720 + + 'MDAzMDUwMDU1NDJaMIGUMQswCQYDVQQGEwJVUzETMBEGA1UECAwKV2FzaGluZ3Rv\n'
721 + + 'bjEQMA4GA1UEBwwHU2VhdHRsZTEiMCAGA1UECgwZQW1hem9uIFdlYiBTZXJ2aWNl\n'
722 + + 'cywgSW5jLjETMBEGA1UECwwKQW1hem9uIFJEUzElMCMGA1UEAwwcQW1hem9uIFJE\n'
723 + + 'UyBhcC1ub3J0aGVhc3QtMyBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC\n'
724 + + 'ggEBAMZtQNnm/XT19mTa10ftHLzg5UhajoI65JHv4TQNdGXdsv+CQdGYU49BJ9Eu\n'
725 + + '3bYgiEtTzR2lQe9zGMvtuJobLhOWuavzp7IixoIQcHkFHN6wJ1CvqrxgvJfBq6Hy\n'
726 + + 'EuCDCiU+PPDLUNA6XM6Qx3IpHd1wrJkjRB80dhmMSpxmRmx849uFafhN+P1QybsM\n'
727 + + 'TI0o48VON2+vj+mNuQTyLMMP8D4odSQHjaoG+zyJfJGZeAyqQyoOUOFEyQaHC3TT\n'
728 + + '3IDSNCQlpxb9LerbCoKu79WFBBq3CS5cYpg8/fsnV2CniRBFFUumBt5z4dhw9RJU\n'
729 + + 'qlUXXO1ZyzpGd+c5v6FtrfXtnIUCAwEAAaNmMGQwDgYDVR0PAQH/BAQDAgEGMBIG\n'
730 + + 'A1UdEwEB/wQIMAYBAf8CAQAwHQYDVR0OBBYEFETv7ELNplYy/xTeIOInl6nzeiHg\n'
731 + + 'MB8GA1UdIwQYMBaAFE4C7qw+9hXITO0s9QXBj5yECEmDMA0GCSqGSIb3DQEBBQUA\n'
732 + + 'A4IBAQCpKxOQcd0tEKb3OtsOY8q/MPwTyustGk2Rt7t9G68idADp8IytB7M0SDRo\n'
733 + + 'wWZqynEq7orQVKdVOanhEWksNDzGp0+FPAf/KpVvdYCd7ru3+iI+V4ZEp2JFdjuZ\n'
734 + + 'Zz0PIjS6AgsZqE5Ri1J+NmfmjGZCPhsHnGZiBaenX6K5VRwwwmLN6xtoqrrfR5zL\n'
735 + + 'QfBeeZNJG6KiM3R/DxJ5rAa6Fz+acrhJ60L7HprhB7SFtj1RCijau3+ZwiGmUOMr\n'
736 + + 'yKlMv+VgmzSw7o4Hbxy1WVrA6zQsTHHSGf+vkQn2PHvnFMUEu/ZLbTDYFNmTLK91\n'
737 + + 'K6o4nMsEvhBKgo4z7H1EqqxXhvN2\n'
738 + + '-----END CERTIFICATE-----\n',
739 +
740 + /**
741 + * Amazon RDS GovCloud Root CA 2017 to 2022
742 + *
743 + * CN = Amazon RDS GovCloud Root CA
744 + * OU = Amazon RDS
745 + * O = Amazon Web Services, Inc.
746 + * L = Seattle
747 + * ST = Washington
748 + * C = US
749 + * P = 2017-05-19T22:29:11Z/2022-05-18T22:29:11Z
750 + * F = A3:61:F9:C9:A2:5B:91:FE:73:A6:52:E3:59:14:8E:CE:35:12:0F:FD
751 + */
752 + '-----BEGIN CERTIFICATE-----\n'
753 + + 'MIIEDjCCAvagAwIBAgIJAMM61RQn3/kdMA0GCSqGSIb3DQEBCwUAMIGT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UrgnFaXc4zAfBgNVHSMEGDAWgBRJEM+kuDUuZTmCnA4wUrgnFaXc4zAN\n'
769 + + 'BgkqhkiG9w0BAQsFAAOCAQEAcfA7uirXsNZyI2j4AJFVtOTKOZlQwqbyNducnmlg\n'
770 + + '/5nug9fAkwM4AgvF5bBOD1Hw6khdsccMwIj+1S7wpL+EYb/nSc8G0qe1p/9lZ/mZ\n'
771 + + 'ff5g4JOa26lLuCrZDqAk4TzYnt6sQKfa5ZXVUUn0BK3okhiXS0i+NloMyaBCL7vk\n'
772 + + 'kDwkHwEqflRKfZ9/oFTcCfoiHPA7AdBtaPVr0/Kj9L7k+ouz122huqG5KqX0Zpo8\n'
773 + + 'S0IGvcd2FZjNSNPttNAK7YuBVsZ0m2nIH1SLp//00v7yAHIgytQwwB17PBcp4NXD\n'
774 + + 'pCfTa27ng9mMMC2YLqWQpW4TkqjDin2ZC+5X/mbrjzTvVg==\n'
775 + + '-----END CERTIFICATE-----\n',
776 +
777 + /**
778 + * Amazon RDS ap-east-1 certificate CA 2019 to 2022
779 + *
780 + * CN = Amazon RDS ap-east-1 CA
781 + * OU = Amazon RDS
782 + * O = Amazon Web Services, Inc.
783 + * L = Seattle
784 + * ST = Washington
785 + * C = US
786 + * P = 2019-02-17T02:47:00Z/2022-06-01T12:00:00Z
787 + * F = BC:F8:70:75:1F:93:3F:A7:82:86:67:63:A8:86:1F:A4:E8:07:CE:06
788 + */
789 + '-----BEGIN CERTIFICATE-----\n'
790 + + 'MIIEBzCCAu+gAwIBAgICEAAwDQYJKoZIhvcNAQELBQAwgZQxCzAJBgNVBAYTAlVT\n'
791 + + 'MRAwDgYDVQQHDAdTZWF0dGxlMRMwEQYDVQQIDApXYXNoaW5ndG9uMSIwIAYDVQQK\n'
792 + + 'DBlBbWF6b24gV2ViIFNlcnZpY2VzLCBJbmMuMRMwEQYDVQQLDApBbWF6b24gUkRT\n'
793 + + 'MSUwIwYDVQQDDBxBbWF6b24gUkRTIGFwLWVhc3QtMSBSb290I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
808 + + '0lTNJfR12yBma5VQy7vzeFku/SisKwX0Lov1oHD4MVhJoHbUJYkmAjxorcIHORvh\n'
809 + + 'I3Vj5XrgDWtLDPL8/Id/roul/L+WX5ir+PGScKBfQIIN2lWdZoqdsx8YWqhm/ikL\n'
810 + + 'C6qNieSwcvWL7C03ri0DefTQMY54r5wP33QU5hJ71JoaZI3YTeT0Nf+NRL4hM++w\n'
811 + + 'Q0veeNzBQXg1f/JxfeA39IDIX1kiCf71tGlT\n'
812 + + '-----END CERTIFICATE-----\n',
813 +
814 + /**
815 + * Amazon RDS ap-northeast-1 certificate CA 2019 to 2024
816 + *
817 + * CN = Amazon RDS ap-northeast-1 2019 CA
818 + * OU = Amazon RDS
819 + * O = Amazon Web Services, Inc.
820 + * L = Seattle
821 + * ST = Washington
822 + * C = US
823 + * P = 2019-09-18T16:56:20Z/2024-08-22T17:08:50Z
824 + * F = 47:A3:F9:20:64:5C:9F:9D:48:8C:7D:E6:0B:86:D6:05:13:00:16:A1
825 + */
826 + '-----BEGIN CERTIFICATE-----\n'
827 + + 'MIIEDDCCAvSgAwIBAgICcEUwDQYJKoZIhvcNAQELBQAwgY8xCzAJBgNVBAYTAlVT\n'
828 + + 'MRAwDgYDVQQHDAdTZWF0dGxlMRMwEQYDVQQIDApXYXNoaW5ndG9uMSIwIAYDVQQK\n'
829 + + 'DBlBbWF6b24gV2ViIFNlcnZpY2VzLCBJbmMuMRMwEQYDVQQLDApBbWF6b24gUkRT\n'
830 + + 'MSAwHgYDVQQDDBdBbWF6b24gUkRTIFJvb3QgMjAxOSBDQTAeFw0xOTA5MTgxNjU2\n'
831 + + 'MjBaFw0yNDA4MjIxNzA4NTBaMIGZMQswCQYDVQQGEwJVUzETMBEGA1UECAwKV2Fz\n'
832 + + 'aGluZ3RvbjEQMA4GA1UEBwwHU2VhdHRsZTEiMCAGA1UECgwZQW1hem9uIFdlYiBT\n'
833 + + 'ZXJ2aWNlcywgSW5jLjETMBEGA1UECwwKQW1hem9uIFJE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 + + '2sGWyuPZPCk3gq+5pCjbD0c6DkhcMGI6WwxvM5V/zSM=\n'
849 + + '-----END CERTIFICATE-----\n',
850 +
851 + /**
852 + * Amazon RDS ap-northeast-2 certificate CA 2019 to 2024
853 + *
854 + * CN = Amazon RDS ap-northeast-2 2019 CA
855 + * OU = Amazon RDS
856 + * O = Amazon Web Services, Inc.
857 + * L = Seattle
858 + * ST = Washington
859 + * C = US
860 + * P = 2019-09-10T17:46:21Z/2024-08-22T17:08:50Z
861 + * F = 8E:1C:70:C1:64:BD:FC:F9:93:9B:A2:67:CA:CF:52:F0:E1:F7:B4:F0
862 + */
863 + '-----BEGIN CERTIFICATE-----\n'
864 + + 'MIIEDDCCAvSgAwIBAgICOFAwDQYJKoZIhvcNAQELBQAwgY8xCzAJBgNVBAYTAlVT\n'
865 + + 'MRAwDgYDVQQHDAdTZWF0dGxlMRMwEQYDVQQIDApXYXNoaW5ndG9uMSIwIAYDVQQK\n'
866 + + 'DBlBbWF6b24gV2ViIFNlcnZpY2VzLCBJbmMuMRMwEQYDVQQLDApBbWF6b24gUkRT\n'
867 + + 'MSAwHgYDVQQDDBdBbWF6b24gUkRTIFJvb3QgMjAxOSBDQTAeFw0xOTA5MTAxNzQ2\n'
868 + + 'MjFaFw0yNDA4MjIxNzA4NTBaMIGZMQswCQYDVQQGEwJVUzETMBEGA1UECAwKV2Fz\n'
869 + + 'aGluZ3RvbjEQMA4GA1UEBwwHU2VhdHRsZTEiMCAGA1UECgwZQW1hem9uIFdlYiBT\n'
870 + + 'ZXJ2aWNlcywgSW5jLjETMBEGA1UECwwKQW1hem9uIFJEUzEqMCgGA1UEAwwhQW1h\n'
871 + + 'em9uIFJEUyBhcC1ub3J0aGVhc3QtMiAyMDE5IENBMIIBIjANBgkqhkiG9w0BAQEF\n'
872 + + 'AAOCAQ8AMIIBCgKCAQEAzU72e6XbaJbi4HjJoRNjKxzUEuChKQIt7k3CWzNnmjc5\n'
873 + + '8I1MjCpa2W1iw1BYVysXSNSsLOtUsfvBZxi/1uyMn5ZCaf9aeoA9UsSkFSZBjOCN\n'
874 + + 'DpKPCmfV1zcEOvJz26+1m8WDg+8Oa60QV0ou2AU1tYcw98fOQjcAES0JXXB80P2s\n'
875 + + '3UfkNcnDz+l4k7j4SllhFPhH6BQ4lD2NiFAP4HwoG6FeJUn45EPjzrydxjq6v5Fc\n'
876 + + 'cQ8rGuHADVXotDbEhaYhNjIrsPL+puhjWfhJjheEw8c4whRZNp6gJ/b6WEes/ZhZ\n'
877 + + 'h32DwsDsZw0BfRDUMgUn8TdecNexHUw8vQWeC181hwIDAQABo2YwZDAOBgNVHQ8B\n'
878 + + 'Af8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBADAdBgNVHQ4EFgQUwW9bWgkWkr0U\n'
879 + + 'lrOsq2kvIdrECDgwHwYDVR0jBBgwFoAUc19g2LzLA5j0Kxc0LjZapmD/vB8wDQYJ\n'
880 + + 'KoZIhvcNAQELBQADggEBAEugF0Gj7HVhX0ehPZoGRYRt3PBuI2YjfrrJRTZ9X5wc\n'
881 + + '9T8oHmw07mHmNy1qqWvooNJg09bDGfB0k5goC2emDiIiGfc/kvMLI7u+eQOoMKj6\n'
882 + + 'mkfCncyRN3ty08Po45vTLBFZGUvtQmjM6yKewc4sXiASSBmQUpsMbiHRCL72M5qV\n'
883 + + 'obcJOjGcIdDTmV1BHdWT+XcjynsGjUqOvQWWhhLPrn4jWe6Xuxll75qlrpn3IrIx\n'
884 + + 'CRBv/5r7qbcQJPOgwQsyK4kv9Ly8g7YT1/vYBlR3cRsYQjccw5ceWUj2DrMVWhJ4\n'
885 + + 'prf+E3Aa4vYmLLOUUvKnDQ1k3RGNu56V0tonsQbfsaM=\n'
886 + + '-----END CERTIFICATE-----\n',
887 +
888 + /**
889 + * Amazon RDS ap-northeast-3 certificate CA 2019 to 2024
890 + *
891 + * CN = Amazon RDS ap-northeast-3 2019 CA
892 + * OU = Amazon RDS
893 + * O = Amazon Web Services, Inc.
894 + * L = Seattle
895 + * ST = Washington
896 + * C = US
897 + * P = 2019-09-17T20:05:29Z/2024-08-22T17:08:50Z
898 + * F = D1:08:B1:40:6D:6C:80:8E:F4:C1:2C:8A:1F:66:17:01:54:CD:1A:4E
899 + */
900 + '-----BEGIN CERTIFICATE-----\n'
901 + + 'MIIEDDCCAvSgAwIBAgICOYIwDQYJKoZIhvcNAQELBQAwgY8xCzAJBgNVBAYTAlVT\n'
902 + + 'MRAwDgYDVQQHDAdTZWF0dGxlMRMwEQYDVQQIDApXYXNoaW5ndG9uMSIwIAYDVQQK\n'
903 + + 'DBlBbWF6b24gV2ViIFNlcnZpY2VzLCBJbmMuMRMwEQYDVQQLDApBbWF6b24gUkRT\n'
904 + + 'MSAwHgYDVQQDDBdBbWF6b24gUkRTIFJvb3QgMjAxOSBDQTAeFw0xOTA5MTcyMDA1\n'
905 + + 'MjlaFw0yNDA4MjIxNzA4NTBaMIGZMQswCQYDVQQGEwJVUzETMBEGA1UECAwKV2Fz\n'
906 + + 'aGluZ3RvbjEQMA4GA1UEBwwHU2VhdHRsZTEiMCAGA1UECgwZQW1hem9uIFdlYiBT\n'
907 + + 'ZXJ2aWNlcywgSW5jLjETMBEGA1UECwwKQW1hem9uIFJEUzEqMCgGA1UEAwwhQW1h\n'
908 + + 'em9uIFJEUyBhcC1ub3J0aGVhc3QtMyAyMDE5IENBMIIBIjANBgkqhkiG9w0BAQEF\n'
909 + + 'AAOCAQ8AMIIBCgKCAQEA4dMak8W+XW8y/2F6nRiytFiA4XLwePadqWebGtlIgyCS\n'
910 + + 'kbug8Jv5w7nlMkuxOxoUeD4WhI6A9EkAn3r0REM/2f0aYnd2KPxeqS2MrtdxxHw1\n'
911 + + 'xoOxk2x0piNSlOz6yog1idsKR5Wurf94fvM9FdTrMYPPrDabbGqiBMsZZmoHLvA3\n'
912 + + 'Z+57HEV2tU0Ei3vWeGIqnNjIekS+E06KhASxrkNU5vi611UsnYZlSi0VtJsH4UGV\n'
913 + + 'LhnHl53aZL0YFO5mn/fzuNG/51qgk/6EFMMhaWInXX49Dia9FnnuWXwVwi6uX1Wn\n'
914 + + '7kjoHi5VtmC8ZlGEHroxX2DxEr6bhJTEpcLMnoQMqwIDAQABo2YwZDAOBgNVHQ8B\n'
915 + + 'Af8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBADAdBgNVHQ4EFgQUsUI5Cb3SWB8+\n'
916 + + 'gv1YLN/ABPMdxSAwHwYDVR0jBBgwFoAUc19g2LzLA5j0Kxc0LjZapmD/vB8wDQYJ\n'
917 + + 'KoZIhvcNAQELBQADggEBAJAF3E9PM1uzVL8YNdzb6fwJrxxqI2shvaMVmC1mXS+w\n'
918 + + 'G0zh4v2hBZOf91l1EO0rwFD7+fxoI6hzQfMxIczh875T6vUXePKVOCOKI5wCrDad\n'
919 + + 'zQbVqbFbdhsBjF4aUilOdtw2qjjs9JwPuB0VXN4/jY7m21oKEOcnpe36+7OiSPjN\n'
920 + + 'xngYewCXKrSRqoj3mw+0w/+exYj3Wsush7uFssX18av78G+ehKPIVDXptOCP/N7W\n'
921 + + '8iKVNeQ2QGTnu2fzWsGUSvMGyM7yqT+h1ILaT//yQS8er511aHMLc142bD4D9VSy\n'
922 + + 'DgactwPDTShK/PXqhvNey9v/sKXm4XatZvwcc8KYlW4=\n'
923 + + '-----END CERTIFICATE-----\n',
924 +
925 + /**
926 + * Amazon RDS ap-south-1 certificate CA 2019 to 2024
927 + *
928 + * CN = Amazon RDS ap-south-1 2019 CA
929 + * OU = Amazon RDS
930 + * O = Amazon Web Services, Inc.
931 + * L = Seattle
932 + * ST = Washington
933 + * C = US
934 + * P = 2019-09-04T17:13:04Z/2024-08-22T17:08:50Z
935 + * F = D6:AD:45:A9:54:36:E4:BA:9C:B7:9B:06:8C:0C:CD:CC:1E:81:B5:00
936 + */
937 + '-----BEGIN CERTIFICATE-----\n'
938 + + 'MIIECDCCAvCgAwIBAgICVIYwDQYJKoZIhvcNAQELBQAwgY8xCzAJBgNVBAYTAlVT\n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GlH6W6TAfBgNVHSMEGDAWgBRzX2DYvMsDmPQrFzQuNlqmYP+8HzANBgkqhkiG\n'
954 + + '9w0BAQsFAAOCAQEAZ17hhr3dII3hUfuHQ1hPWGrpJOX/G9dLzkprEIcCidkmRYl+\n'
955 + + 'hu1Pe3caRMh/17+qsoEErmnVq5jNY9X1GZL04IZH8YbHc7iRHw3HcWAdhN8633+K\n'
956 + + 'jYEB2LbJ3vluCGnCejq9djDb6alOugdLMJzxOkHDhMZ6/gYbECOot+ph1tQuZXzD\n'
957 + + 'tZ7prRsrcuPBChHlPjmGy8M9z8u+kF196iNSUGC4lM8vLkHM7ycc1/ZOwRq9aaTe\n'
958 + + 'iOghbQQyAEe03MWCyDGtSmDfr0qEk+CHN+6hPiaL8qKt4s+V9P7DeK4iW08ny8Ox\n'
959 + + 'AVS7u0OK/5+jKMAMrKwpYrBydOjTUTHScocyNw==\n'
960 + + '-----END CERTIFICATE-----\n',
961 +
962 + /**
963 + * Amazon RDS ap-southeast-1 certificate CA 2019 to 2024
964 + *
965 + * CN = Amazon RDS ap-southeast-1 2019 CA
966 + * OU = Amazon RDS
967 + * O = Amazon Web Services, Inc.
968 + * L = Seattle
969 + * ST = Washington
970 + * C = US
971 + * P = 2019-09-13T20:11:42Z/2024-08-22T17:08:50Z
972 + * F = 0D:20:FB:91:DE:BE:D2:CF:F3:F8:F8:43:AF:68:C6:03:76:F3:DD:B8
973 + */
974 + '-----BEGIN CERTIFICATE-----\n'
975 + + 'MIIEDDCCAvSgAwIBAgICY4kwDQYJKoZIhvcNAQELBQAwgY8xCzAJBgNVBAYTAlVT\n'
976 + + 'MRAwDgYDVQQHDAdTZWF0dGxlMRMwEQYDVQQIDApXYXNoaW5ndG9uMSIwIAYDVQQK\n'
977 + + 'DBlBbWF6b24gV2ViIFNlcnZpY2VzLCBJbmMuMRMwEQYDVQQLDApBbWF6b24gUkRT\n'
978 + + 'MSAwHgYDVQQDDBdBbWF6b24gUkRTIFJvb3QgMjAxOSBDQTA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yjpt9nG56IAcV8BcRJh4o/2IfLNzC/dVuYJV8wj7XzwlvjysenwdrJCoLadkTr1h\n'
994 + + 'eIdG6Le07sB9IxrGJL9e04afk37h7c8ESGSE4E+oS4JQEi3ATq8ne1B9DQ9SasXi\n'
995 + + 'IRmhNAaISDzOPdyLXi9N9V9Lwe/DHcja7hgLGYx3UqfjhLhOKwp8HtoZORixAmOI\n'
996 + + 'HfILgNmwyugAbuZoCazSKKBhQ0wgO0WZ66ZKTMG8Oho=\n'
997 + + '-----END CERTIFICATE-----\n',
998 +
999 + /**
1000 + * Amazon RDS ap-southeast-2 certificate CA 2019 to 2024
1001 + *
1002 + * CN = Amazon RDS ap-southeast-2 2019 CA
1003 + * OU = Amazon RDS
1004 + * O = Amazon Web Services, Inc.
1005 + * L = Seattle
1006 + * ST = Washington
1007 + * C = US
1008 + * P = 2019-09-16T19:53:47Z/2024-08-22T17:08:50Z
1009 + * F = D5:D4:51:83:D9:A3:AC:47:B0:0A:5A:77:D8:A0:79:A9:6A:3F:6D:96
1010 + */
1011 + '-----BEGIN CERTIFICATE-----\n'
1012 + + 'MIIEDDCCAvSgAwIBAgICEkYwDQYJKoZIhvcNAQELBQAwgY8xCzAJBgNVBAYTAlVT\n'
1013 + + 'MRAwDgYDVQQHDAdTZWF0dGxlMRMwEQYDVQQIDApXYXNoaW5ndG9uMSIwIAYDVQQK\n'
1014 + + 'DBlBbWF6b24gV2ViIFNlcnZpY2VzLCBJbmMuMRMwEQYDVQQLDApBbWF6b24gUkRT\n'
1015 + + 'MSAwHgYDVQQDDBdBbWF6b24gUkRTIFJvb3QgMjAxOSBDQTAeFw0xOTA5MTYxOTUz\n'
1016 + + 'NDdaFw0yNDA4MjIxNzA4NTBaMIGZMQswCQYDVQQGEwJVUzETMBEGA1UECAwKV2Fz\n'
1017 + + 'aGluZ3RvbjEQMA4GA1UEBwwHU2VhdHRsZTEiMCAGA1UECgwZQW1hem9uIFdlYiBT\n'
1018 + + 'ZXJ2aWNlcywgSW5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wIwynrdZrKRyRv6CVtR\n'
1033 + + 'FZ8DeJgoNZT3y/GT254VqMxxfuy2Ccb/RInd16tEvVk=\n'
1034 + + '-----END CERTIFICATE-----\n',
1035 +
1036 + /**
1037 + * Amazon RDS ca-central-1 certificate CA 2019 to 2024
1038 + *
1039 + * CN = Amazon RDS ca-central-1 2019 CA
1040 + * OU = Amazon RDS
1041 + * O = Amazon Web Services, Inc.
1042 + * L = Seattle
1043 + * ST = Washington
1044 + * C = US
1045 + * P = 2019-09-10T20:52:25Z/2024-08-22T17:08:50Z
1046 + * F = A1:03:46:F2:BB:29:BF:4F:EC:04:7E:82:9A:A6:C0:11:4D:AB:82:25
1047 + */
1048 + '-----BEGIN CERTIFICATE-----\n'
1049 + + 'MIIECjCCAvKgAwIBAgICEzUwDQYJKoZIhvcNAQELBQAwgY8xCzAJBgNVBAYTAlVT\n'
1050 + + 'MRAwDgYDVQQHDAdTZWF0dGxlMRMwEQYDVQQIDApXYXNoaW5ndG9uMSIwIAYDVQQK\n'
1051 + + 'DBlBbWF6b24gV2ViIFNlcnZpY2VzLCBJbmMuMRMwEQYDVQQLDApBbWF6b24gUkRT\n'
1052 + + 'MSAwHgYDVQQDDBdBbWF6b24gUkRTIFJvb3QgMjAxOSBDQTAeFw0xOTA5MTAyMDUy\n'
1053 + + 'MjVaFw0yNDA4MjIxNzA4NTBaMIGXMQswCQYDVQQGEwJVUzETMBEGA1UECAwKV2Fz\n'
1054 + + 'aGluZ3RvbjEQMA4GA1UEBwwHU2VhdHRsZTEiMCAGA1UECgwZQW1hem9uIFdlYiBT\n'
1055 + + 'ZXJ2aWNlcywgSW5jLjETMBEGA1UECwwKQW1hem9uIFJEUzEoMCYGA1UEAwwfQW1h\n'
1056 + + 'em9uIFJEUyBjYS1jZW50cmFsLTEgMjAxOSBDQTCCASIwDQYJKoZIhvcNAQEBBQAD\n'
1057 + + 'ggEPADCCAQoCggEBAOxHqdcPSA2uBjsCP4DLSlqSoPuQ/X1kkJLusVRKiQE2zayB\n'
1058 + + 'viuCBt4VB9Qsh2rW3iYGM+usDjltGnI1iUWA5KHcvHszSMkWAOYWLiMNKTlg6LCp\n'
1059 + + 'XnE89tvj5dIH6U8WlDvXLdjB/h30gW9JEX7S8supsBSci2GxEzb5mRdKaDuuF/0O\n'
1060 + + 'qvz4YE04pua3iZ9QwmMFuTAOYzD1M72aOpj+7Ac+YLMM61qOtU+AU6MndnQkKoQi\n'
1061 + + 'qmUN2A9IFaqHFzRlSdXwKCKUA4otzmz+/N3vFwjb5F4DSsbsrMfjeHMo6o/nb6Nh\n'
1062 + + 'YDb0VJxxPee6TxSuN7CQJ2FxMlFUezcoXqwqXD0CAwEAAaNmMGQwDgYDVR0PAQH/\n'
1063 + + 'BAQDAgEGMBIGA1UdEwEB/wQIMAYBAf8CAQAwHQYDVR0OBBYEFDGGpon9WfIpsggE\n'
1064 + + 'CxHq8hZ7E2ESMB8GA1UdIwQYMBaAFHNfYNi8ywOY9CsXNC42WqZg/7wfMA0GCSqG\n'
1065 + + 'SIb3DQEBCwUAA4IBAQAvpeQYEGZvoTVLgV9rd2+StPYykMsmFjWQcyn3dBTZRXC2\n'
1066 + + 'lKq7QhQczMAOhEaaN29ZprjQzsA2X/UauKzLR2Uyqc2qOeO9/YOl0H3qauo8C/W9\n'
1067 + + 'r8xqPbOCDLEXlOQ19fidXyyEPHEq5WFp8j+fTh+s8WOx2M7IuC0ANEetIZURYhSp\n'
1068 + + 'xl9XOPRCJxOhj7JdelhpweX0BJDNHeUFi0ClnFOws8oKQ7sQEv66d5ddxqqZ3NVv\n'
1069 + + 'RbCvCtEutQMOUMIuaygDlMn1anSM8N7Wndx8G6+Uy67AnhjGx7jw/0YPPxopEj6x\n'
1070 + + 'JXP8j0sJbcT9K/9/fPVLNT25RvQ/93T2+IQL4Ca2\n'
1071 + + '-----END CERTIFICATE-----\n',
1072 +
1073 + /**
1074 + * Amazon RDS eu-central-1 certificate CA 2019 to 2024
1075 + *
1076 + * CN = Amazon RDS eu-central-1 2019 CA
1077 + * OU = Amazon RDS
1078 + * O = Amazon Web Services, Inc.
1079 + * L = Seattle
1080 + * ST = Washington
1081 + * C = US
1082 + * P = 2019-09-11T19:36:20Z/2024-08-22T17:08:50Z
1083 + * F = 53:46:18:4A:42:65:A2:8C:5F:5B:0A:AD:E2:2C:80:E5:E6:8A:6D:2F
1084 + */
1085 + '-----BEGIN CERTIFICATE-----\n'
1086 + + 'MIIECjCCAvKgAwIBAgICV2YwDQYJKoZIhvcNAQELBQAwgY8xCzAJBgNVBAYTAlVT\n'
1087 + + 'MRAwDgYDVQQHDAdTZWF0dGxlMRMwEQYDVQQIDApXYXNoaW5ndG9uMSIwIAYDVQQK\n'
1088 + + 'DBlBbWF6b24gV2ViIFNlcnZpY2VzLCBJbmMuMRMwEQYDVQQLDApBbWF6b24gUkRT\n'
1089 + + 'MSAwHgYDVQQDDBdBbWF6b24gUkRTIFJvb3QgMjAxOSBDQTAeFw0xOTA5MTExOTM2\n'
1090 + + 'MjBaFw0yNDA4MjIxNzA4NTBaMIGXMQswCQYDVQQGEwJVUzETMBEGA1UECAwKV2Fz\n'
1091 + + 'aGluZ3RvbjEQMA4GA1UEBwwHU2VhdHRsZTEiMCAGA1UECgwZQW1hem9uIFdlYiBT\n'
1092 + + 'ZXJ2aWNlcywgSW5jLjETMBEGA1UECwwKQW1hem9uIFJEUzEoMCYGA1UEAwwfQW1h\n'
1093 + + 'em9uIFJEUyBldS1jZW50cmFsLTEgMjAxOSBDQTCCASIwDQYJKoZIhvcNAQEBBQAD\n'
1094 + + 'ggEPADCCAQoCggEBAMEx54X2pHVv86APA0RWqxxRNmdkhAyp2R1cFWumKQRofoFv\n'
1095 + + 'n+SPXdkpIINpMuEIGJANozdiEz7SPsrAf8WHyD93j/ZxrdQftRcIGH41xasetKGl\n'
1096 + + 'I67uans8d+pgJgBKGb/Z+B5m+UsIuEVekpvgpwKtmmaLFC/NCGuSsJoFsRqoa6Gh\n'
1097 + + 'm34W6yJoY87UatddCqLY4IIXaBFsgK9Q/wYzYLbnWM6ZZvhJ52VMtdhcdzeTHNW0\n'
1098 + + '5LGuXJOF7Ahb4JkEhoo6TS2c0NxB4l4MBfBPgti+O7WjR3FfZHpt18A6Zkq6A2u6\n'
1099 + + 'D/oTSL6c9/3sAaFTFgMyL3wHb2YlW0BPiljZIqECAwEAAaNmMGQwDgYDVR0PAQH/\n'
1100 + + 'BAQDAgEGMBIGA1UdEwEB/wQIMAYBAf8CAQAwHQYDVR0OBBYEFOcAToAc6skWffJa\n'
1101 + + 'TnreaswAfrbcMB8GA1UdIwQYMBaAFHNfYNi8ywOY9CsXNC42WqZg/7wfMA0GCSqG\n'
1102 + + 'SIb3DQEBCwUAA4IBAQA1d0Whc1QtspK496mFWfFEQNegLh0a9GWYlJm+Htcj5Nxt\n'
1103 + + 'DAIGXb+8xrtOZFHmYP7VLCT5Zd2C+XytqseK/+s07iAr0/EPF+O2qcyQWMN5KhgE\n'
1104 + + 'cXw2SwuP9FPV3i+YAm11PBVeenrmzuk9NrdHQ7TxU4v7VGhcsd2C++0EisrmquWH\n'
1105 + + 'mgIfmVDGxphwoES52cY6t3fbnXmTkvENvR+h3rj+fUiSz0aSo+XZUGHPgvuEKM/W\n'
1106 + + 'CBD9Smc9CBoBgvy7BgHRgRUmwtABZHFUIEjHI5rIr7ZvYn+6A0O6sogRfvVYtWFc\n'
1107 + + 'qpyrW1YX8mD0VlJ8fGKM3G+aCOsiiPKDV/Uafrm+\n'
1108 + + '-----END CERTIFICATE-----\n',
1109 +
1110 + /**
1111 + * Amazon RDS eu-north-1 certificate CA 2019 to 2024
1112 + *
1113 + * CN = Amazon RDS eu-north-1 2019 CA
1114 + * OU = Amazon RDS
1115 + * O = Amazon Web Services, Inc.
1116 + * L = Seattle
1117 + * ST = Washington
1118 + * C = US
1119 + * P = 2019-09-12T18:19:44Z/2024-08-22T17:08:50Z
1120 + * F = D0:CA:9C:6E:47:4C:4F:DB:85:28:03:4A:60:AC:14:E0:E6:DF:D4:42
1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A1UdDwEB/wQE\n'
1137 + + 'AwIBBjASBgNVHRMBAf8ECDAGAQH/AgEAMB0GA1UdDgQWBBRR0UpnbQyjnHChgmOc\n'
1138 + + 'hnlc0PogzTAfBgNVHSMEGDAWgBRzX2DYvMsDmPQrFzQuNlqmYP+8HzANBgkqhkiG\n'
1139 + + '9w0BAQsFAAOCAQEAKJD4xVzSf4zSGTBJrmamo86jl1NHQxXUApAZuBZEc8tqC6TI\n'
1140 + + 'T5CeoSr9CMuVC8grYyBjXblC4OsM5NMvmsrXl/u5C9dEwtBFjo8mm53rOOIm1fxl\n'
1141 + + 'I1oYB/9mtO9ANWjkykuLzWeBlqDT/i7ckaKwalhLODsRDO73vRhYNjsIUGloNsKe\n'
1142 + + 'pxw3dzHwAZx4upSdEVG4RGCZ1D0LJ4Gw40OfD69hfkDfRVVxKGrbEzqxXRvovmDc\n'
1143 + + 'tKLdYZO/6REoca36v4BlgIs1CbUXJGLSXUwtg7YXGLSVBJ/U0+22iGJmBSNcoyUN\n'
1144 + + 'cjPFD9JQEhDDIYYKSGzIYpvslvGc4T5ISXFiuQ==\n'
1145 + + '-----END CERTIFICATE-----\n',
1146 +
1147 + /**
1148 + * Amazon RDS eu-west-1 certificate CA 2019 to 2024
1149 + *
1150 + * CN = Amazon RDS eu-west-1 2019 CA
1151 + * OU = Amazon RDS
1152 + * O = Amazon Web Services, Inc.
1153 + * L = Seattle
1154 + * ST = Washington
1155 + * C = US
1156 + * P = 2019-09-11T17:31:48Z/2024-08-22T17:08:50Z
1157 + * F = 2D:1A:A6:3E:0D:EB:D6:26:03:3E:A1:8A:0A:DF:14:80:78:EC:B6:63
1158 + */
1159 + '-----BEGIN CERTIFICATE-----\n'
1160 + + 'MIIEBzCCAu+gAwIBAgICYpgwDQYJKoZIhvcNAQELBQAwgY8xCzAJBgNVBAYTAlVT\n'
1161 + + 'MRAwDgYDVQQHDAdTZWF0dGxlMRMwEQYDVQQIDApXYXNoaW5ndG9uMSIwIAYDVQQK\n'
1162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nWBKj5xV1A1mYd0kIgDdkjCwQkiKF5bjIbGkT3YEFFbXoJlSP\n'
1177 + + '0lZZ/hDaOHI8wbLT44SzOvPEEmWF9EE7SJzkvSdQrUAWR9FwDLaU427ALI3ngNHy\n'
1178 + + 'lGJ2hse1fvSRNbmg8Sc9GBv8oqNIBPVuw+AJzHTacZ1OkyLZrz1c1QvwvwN2a+Jd\n'
1179 + + 'vH0V0YIhv66llKcYDMUQJAQi4+8nbRxXWv6Gq3pvrFoorzsnkr42V3JpbhnYiK+9\n'
1180 + + 'nRKd4uWl62KRZjGkfMbmsqZpj2fdSWMY1UGyN1k+kDmCSWYdrTRDP0xjtIocwg+A\n'
1181 + + 'J116n4hV/5mbA0BaPiS2krtv17YAeHABZcvz\n'
1182 + + '-----END CERTIFICATE-----\n',
1183 +
1184 + /**
1185 + * Amazon RDS eu-west-2 certificate CA 2019 to 2024
1186 + *
1187 + * CN = Amazon RDS eu-west-2 2019 CA
1188 + * OU = Amazon RDS
1189 + * O = Amazon Web Services, Inc.
1190 + * L = Seattle
1191 + * ST = Washington
1192 + * C = US
1193 + * P = 2019-09-12T21:32:32Z/2024-08-22T17:08:50Z
1194 + * F = 60:65:44:F4:74:6E:2E:29:50:19:38:7C:4B:BE:18:B9:5B:D4:CD:23
1195 + */
1196 + '-----BEGIN CERTIFICATE-----\n'
1197 + + 'MIIEBzCCAu+gAwIBAgICZIEwDQYJKoZIhvcNAQELBQAwgY8xCzAJBgNVBAYTAlVT\n'
1198 + + 'MRAwDgYDVQQHDAdTZWF0dGxlMRMwEQYDVQQIDApXYXNoaW5ndG9uMSIwIAYDVQQK\n'
1199 + + 'DBlBbWF6b24gV2ViIFNlcnZpY2VzLCBJbmMuMRMwEQYDVQQLDApBbWF6b24gUkRT\n'
1200 + + 'MSAwHgYDVQQDDBdBbWF6b24gUkRTIFJvb3QgMjAxOSBDQTAeFw0xOTA5MTIyMTMy\n'
1201 + + 'MzJaFw0yNDA4MjIxNzA4NTBaMIGUMQswCQYD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hkn6z8nwB10\n'
1216 + + '7RjLtJPrK8igxdpr3tGUzfAOyiPrIDncY7UJaL84GFp7WWAkH0WG3H8Y8DRcRXOU\n'
1217 + + 'mqDxDLUP3rNuow3jnGxiUY+gGX5OqaZg4f4P6QzOSmeQYs6nLpH0PiN00+oS1BbD\n'
1218 + + 'bpWdZEttILPI+vAYkU4QuBKKDjJL6HbSd+cn\n'
1219 + + '-----END CERTIFICATE-----\n',
1220 +
1221 + /**
1222 + * Amazon RDS eu-west-3 certificate CA 2019 to 2024
1223 + *
1224 + * CN = Amazon RDS eu-west-3 2019 CA
1225 + * OU = Amazon RDS
1226 + * O = Amazon Web Services, Inc.
1227 + * L = Seattle
1228 + * ST = Washington
1229 + * C = US
1230 + * P = 2019-09-18T17:03:15Z/2024-08-22T17:08:50Z
1231 + * F = 6F:79:56:B0:74:9C:C6:3E:3B:50:26:C8:51:55:08:F0:BB:7E:32:04
1232 + */
1233 + '-----BEGIN CERTIFICATE-----\n'
1234 + + 'MIIEBzCCAu+gAwIBAgICJDQwDQYJKoZIhvcNAQELBQAwgY8xCzAJBgNVBAYTAlVT\n'
1235 + + 'MRAwDgYDVQQHDAdTZWF0dGxlMRMwEQYDVQQIDApXYXNoaW5ndG9uMSIwIAYDVQQK\n'
1236 + + 'DBlBbWF6b24gV2ViIFNlcnZpY2VzLCBJbmMuMRMwEQYDVQQLDApBbWF6b24gUkRT\n'
1237 + + 'MSAwHgYDVQQDDBdBbWF6b24gUkRTIFJvb3QgMjAxOSBDQTAeFw0xOTA5MTgxNzAz\n'
1238 + + 'MTVaFw0yNDA4MjIxNzA4NTBaMIGUMQswCQYDVQQGEwJVUzETMBEGA1UECAwKV2Fz\n'
1239 + + 'aGluZ3RvbjEQMA4GA1UEBwwHU2VhdHRsZTEiMCAGA1UECgwZQW1hem9uIFdlYiBT\n'
1240 + + 'ZXJ2aWNlcywgSW5jLjETMBEGA1UECwwKQW1hem9uIFJEUzElMCMGA1UEAwwcQW1h\n'
1241 + + 'em9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R5Mu4DWkK5Q8Ep\n'
1256 + + '-----END CERTIFICATE-----\n',
1257 +
1258 + /**
1259 + * Amazon RDS me-south-1 certificate CA 2019 to 2024
1260 + *
1261 + * CN = Amazon RDS me-south-1 Root CA
1262 + * OU = Amazon RDS
1263 + * O = Amazon Web Services, Inc.
1264 + * L = Seattle
1265 + * ST = Washington
1266 + * C = US
1267 + * P = 2019-05-10T21:48:27Z/2024-05-08T21:48:27Z
1268 + * F = 8A:69:D7:00:FB:5D:62:9C:B0:D1:75:6F:B7:B6:38:AA:76:C4:BD:1F
1269 + */
1270 + '-----BEGIN CERTIFICATE-----\n'
1271 + + 'MIIEEjCCAvqgAwIBAgIJANew34ehz5l8MA0GCSqGSIb3DQEBCwUAMIGVMQswCQYD\n'
1272 + + 'VQQGEwJVUzEQMA4GA1UEBwwHU2VhdHRsZTETMBEGA1UECAwKV2FzaGluZ3RvbjEi\n'
1273 + + 'MCAGA1UECgwZQW1hem9uIFdlYiBTZXJ2aWNlcywgSW5jLjETMBEGA1UECwwKQW1h\n'
1274 + + 'em9uIFJEUzEmMCQGA1UEAwwdQW1hem9uIFJEUyBtZS1zb3V0aC0xIFJvb3QgQ0Ew\n'
1275 + + 'HhcNMTkwNTEwMjE0ODI3WhcNMjQwNTA4MjE0ODI3WjCBlTELMAkGA1UEBhMCVVMx\n'
1276 + + 'EDAOBgNVBAcMB1NlYXR0bGUxEzARBgNVBAgMCldhc2hpbmd0b24xIjAgBgNVBAoM\n'
1277 + + 'GUFtYXpvbiBXZWIgU2VydmljZXMsIEluYy4xEzARBgNVBAsMCkFtYXpvbiBSRFMx\n'
1278 + + 'JjAkBgNVBAMMHUFtYXpvbiBSRFMgbWUtc291dGgtMSBSb290IENBMIIBIjANBgkq\n'
1279 + + 'hkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAp7BYV88MukcY+rq0r79+C8UzkT30fEfT\n'
1280 + + 'aPXbx1d6M7uheGN4FMaoYmL+JE1NZPaMRIPTHhFtLSdPccInvenRDIatcXX+jgOk\n'
1281 + + 'UA6lnHQ98pwN0pfDUyz/Vph4jBR9LcVkBbe0zdoKKp+HGbMPRU0N2yNrog9gM5O8\n'
1282 + + 'gkU/3O2csJ/OFQNnj4c2NQloGMUpEmedwJMOyQQfcUyt9CvZDfIPNnheUS29jGSw\n'
1283 + + 'ERpJe/AENu8Pxyc72jaXQuD+FEi2Ck6lBkSlWYQFhTottAeGvVFNCzKszCntrtqd\n'
1284 + + 'rdYUwurYsLTXDHv9nW2hfDUQa0mhXf9gNDOBIVAZugR9NqNRNyYLHQIDAQABo2Mw\n'
1285 + + 'YTAOBgNVHQ8BAf8EBAMCAQYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQU54cf\n'
1286 + + 'DjgwBx4ycBH8+/r8WXdaiqYwHwYDVR0jBBgwFoAU54cfDjgwBx4ycBH8+/r8WXda\n'
1287 + + 'iqYwDQYJKoZIhvcNAQELBQADggEBAIIMTSPx/dR7jlcxggr+O6OyY49Rlap2laKA\n'
1288 + + 'eC/XI4ySP3vQkIFlP822U9Kh8a9s46eR0uiwV4AGLabcu0iKYfXjPkIprVCqeXV7\n'
1289 + + 'ny9oDtrbflyj7NcGdZLvuzSwgl9SYTJp7PVCZtZutsPYlbJrBPHwFABvAkMvRtDB\n'
1290 + + 'hitIg4AESDGPoCl94sYHpfDfjpUDMSrAMDUyO6DyBdZH5ryRMAs3lGtsmkkNUrso\n'
1291 + + 'aTW6R05681Z0mvkRdb+cdXtKOSuDZPoe2wJJIaz3IlNQNSrB5TImMYgmt6iAsFhv\n'
1292 + + '3vfTSTKrZDNTJn4ybG6pq1zWExoXsktZPylJly6R3RBwV6nwqBM=\n'
1293 + + '-----END CERTIFICATE-----\n',
1294 +
1295 + /**
1296 + * Amazon RDS sa-east-1 certificate CA 2019 to 2024
1297 + *
1298 + * CN = Amazon RDS sa-east-1 2019 CA
1299 + * OU = Amazon RDS
1300 + * O = Amazon Web Services, Inc.
1301 + * L = Seattle
1302 + * ST = Washington
1303 + * C = US
1304 + * P = 2019-09-05T18:46:29Z/2024-08-22T17:08:50Z
1305 + * F = 8C:34:0F:AA:FB:10:80:9C:05:CE:D7:BF:0B:12:4D:07:42:39:74:7A
1306 + */
1307 + '-----BEGIN CERTIFICATE-----\n'
1308 + + 'MIIEBzCCAu+gAwIBAgICQ2QwDQYJKoZIhvcNAQELBQAwgY8xCzAJBgNVBAYTAlVT\n'
1309 + + 'MRAwDgYDVQQHDAdTZWF0dGxlMRMwEQYDVQQIDApXYXNoaW5ndG9uMSIwIAYDVQQK\n'
1310 + + 'DBlBbWF6b24gV2ViIFNlcnZpY2VzLCBJbmMuMRMwEQYDVQQLDApBbWF6b24gUkRT\n'
1311 + + 'MSAwHgYDVQQDDBdBbWF6b24gUkRTIFJvb3QgMjAxOSBDQTAeFw0xOTA5MDUxODQ2\n'
1312 + + 'MjlaFw0yNDA4MjIxNzA4NTBaMIGUMQswCQYDVQQGEwJVUzETMBEGA1UECAwKV2Fz\n'
1313 + + 'aGluZ3RvbjEQMA4GA1UEBwwHU2VhdHRsZTEiMCAGA1UECgwZQW1hem9uIFdlYiBT\n'
1314 + + 'ZXJ2aWNlcywgSW5jLjETMBEGA1UECwwKQW1hem9uIFJEUzElMCMGA1UEAwwcQW1h\n'
1315 + + 'em9uIFJEUyBzYS1lYXN0LTEgMjAxOSBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEP\n'
1316 + + 'ADCCAQoCggEBAMMvR+ReRnOzqJzoaPipNTt1Z2VA968jlN1+SYKUrYM3No+Vpz0H\n'
1317 + + 'M6Tn0oYB66ByVsXiGc28ulsqX1HbHsxqDPwvQTKvO7SrmDokoAkjJgLocOLUAeld\n'
1318 + + '5AwvUjxGRP6yY90NV7X786MpnYb2Il9DIIaV9HjCmPt+rjy2CZjS0UjPjCKNfB8J\n'
1319 + + 'bFjgW6GGscjeyGb/zFwcom5p4j0rLydbNaOr9wOyQrtt3ZQWLYGY9Zees/b8pmcc\n'
1320 + + 'Jt+7jstZ2UMV32OO/kIsJ4rMUn2r/uxccPwAc1IDeRSSxOrnFKhW3Cu69iB3bHp7\n'
1321 + + 'JbawY12g7zshE4I14sHjv3QoXASoXjx4xgMCAwEAAaNmMGQwDgYDVR0PAQH/BAQD\n'
1322 + + 'AgEGMBIGA1UdEwEB/wQIMAYBAf8CAQAwHQYDVR0OBBYEFI1Fc/Ql2jx+oJPgBVYq\n'
1323 + + 'ccgP0pQ8MB8GA1UdIwQYMBaAFHNfYNi8ywOY9CsXNC42WqZg/7wfMA0GCSqGSIb3\n'
1324 + + 'DQEBCwUAA4IBAQB4VVVabVp70myuYuZ3vltQIWqSUMhkaTzehMgGcHjMf9iLoZ/I\n'
1325 + + '93KiFUSGnek5cRePyS9wcpp0fcBT3FvkjpUdCjVtdttJgZFhBxgTd8y26ImdDDMR\n'
1326 + + '4+BUuhI5msvjL08f+Vkkpu1GQcGmyFVPFOy/UY8iefu+QyUuiBUnUuEDd49Hw0Fn\n'
1327 + + '/kIPII6Vj82a2mWV/Q8e+rgN8dIRksRjKI03DEoP8lhPlsOkhdwU6Uz9Vu6NOB2Q\n'
1328 + + 'Ls1kbcxAc7cFSyRVJEhh12Sz9d0q/CQSTFsVJKOjSNQBQfVnLz1GwO/IieUEAr4C\n'
1329 + + 'jkTntH0r1LX5b/GwN4R887LvjAEdTbg1his7\n'
1330 + + '-----END CERTIFICATE-----\n',
1331 +
1332 + /**
1333 + * Amazon RDS us-east-1 certificate CA 2019 to 2024
1334 + *
1335 + * CN = Amazon RDS us-east-1 2019 CA
1336 + * OU = Amazon RDS
1337 + * O = Amazon Web Services, Inc.
1338 + * L = Seattle
1339 + * ST = Washington
1340 + * C = US
1341 + * P = 2019-09-19T18:16:53Z/2024-08-22T17:08:50Z
1342 + * F = F0:ED:82:3E:D1:44:47:BA:B5:57:FD:F3:E4:92:74:66:98:8C:1C:78
1343 + */
1344 + '-----BEGIN CERTIFICATE-----\n'
1345 + + 'MIIEBzCCAu+gAwIBAgICJVUwDQYJ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PqhoWZcrVY9mU7tuemR\n'
1360 + + 'RBnQIj1jMB8GA1UdIwQYMBaAFHNfYNi8ywOY9CsXNC42WqZg/7wfMA0GCSqGSIb3\n'
1361 + + 'DQEBCwUAA4IBAQB6zOLZ+YINEs72heHIWlPZ8c6WY8MDU+Be5w1M+BK2kpcVhCUK\n'
1362 + + 'PJO4nMXpgamEX8DIiaO7emsunwJzMSvavSPRnxXXTKIc0i/g1EbiDjnYX9d85DkC\n'
1363 + + 'E1LaAUCmCZBVi9fIe0H2r9whIh4uLWZA41oMnJx/MOmo3XyMfQoWcqaSFlMqfZM4\n'
1364 + + '0rNoB/tdHLNuV4eIdaw2mlHxdWDtF4oH+HFm+2cVBUVC1jXKrFv/euRVtsTT+A6i\n'
1365 + + 'h2XBHKxQ1Y4HgAn0jACP2QSPEmuoQEIa57bEKEcZsBR8SDY6ZdTd2HLRIApcCOSF\n'
1366 + + 'MRM8CKLeF658I0XgF8D5EsYoKPsA+74Z+jDH\n'
1367 + + '-----END CERTIFICATE-----\n',
1368 +
1369 + /**
1370 + * Amazon RDS us-east-2 certificate CA 2019 to 2024
1371 + *
1372 + * CN = Amazon RDS us-east-2 2019 CA
1373 + * OU = Amazon RDS
1374 + * O = Amazon Web Services, Inc.
1375 + * L = Seattle
1376 + * ST = Washington
1377 + * C = US
1378 + * P = 2019-09-13T17:06:41Z/2024-08-22T17:08:50Z
1379 + * F = E9:FE:27:2A:A0:0F:CE:DF:AD:51:03:A6:94:F7:1F:6F:BD:1E:28:D3
1380 + */
1381 + '-----BEGIN CERTIFICATE-----\n'
1382 + + 'MIIECDCCAvCgAwIBAgIDAIVCMA0GCSqGSIb3DQEBCwUAMIGPMQswCQYDVQQGEwJV\n'
1383 + + 'UzEQMA4GA1UEBwwHU2VhdHRsZTETMBEGA1UECAwKV2FzaGluZ3RvbjEiMCAGA1UE\n'
1384 + + 'CgwZQW1hem9uIFdlYiBTZXJ2aWNlcywgSW5jLjETMBEGA1UECwwKQW1hem9uIFJE\n'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lnMO85fVDU1Dz3lLHGJ/YG1pt1Cqq2QQ200JcWCvBRgdvH6MjHoDQpqZ\n'
1400 + + 'HvQ3vLgOGqCLNQKFuet9BdpsHzsctKvCVaeBqbGpeCtt3Hh/26tgx0rorPLw90A2\n'
1401 + + 'V8QSkZJjlcKkLa58N5CMM8Xz8KLWg3MZeT4DmlUXVCukqK2RGuP2L+aME8dOxqNv\n'
1402 + + 'OnOz1zrL5mR2iJoDpk8+VE/eBDmJX40IJk6jBjWoxAO/RXq+vBozuF5YHN1ujE92\n'
1403 + + 'tO8HItgTp37XT8bJBAiAnt5mxw+NLSqtxk2QdQ==\n'
1404 + + '-----END CERTIFICATE-----\n',
1405 +
1406 + /**
1407 + * Amazon RDS us-west-1 certificate CA 2019 to 2024
1408 + *
1409 + * CN = Amazon RDS us-west-1 2019 CA
1410 + * OU = Amazon RDS
1411 + * O = Amazon Web Services, Inc.
1412 + * L = Seattle
1413 + * ST = Washington
1414 + * C = US
1415 + * P = 2019-09-06T17:40:21Z/2024-08-22T17:08:50Z
1416 + * F = 1C:9F:DF:84:E6:13:32:F3:91:12:2D:0D:A5:9A:16:5D:AC:DC:E8:93
1417 + */
1418 + '-----BEGIN CERTIFICATE-----\n'
1419 + + 'MIIECDCCAvCgAwIBAgIDAIkHMA0GCSqGSIb3DQEBCwUAMIGPMQswCQYDVQQGEwJV\n'
1420 + + 'UzEQMA4GA1UEBwwHU2VhdHRsZTETMBEGA1UECAwKV2FzaGluZ3RvbjEiMCAGA1UE\n'
1421 + + 'CgwZQW1hem9uIFdlYiBTZXJ2aWNlcywgSW5jLjETMBEGA1UECwwKQW1hem9uIFJE\n'
1422 + + 'UzEgMB4GA1UEAwwXQW1hem9uIFJEUyBSb290IDIwMTkgQ0EwHhcNMTkwOTA2MTc0\n'
1423 + + 'MDIxWhcNMjQwODIyMTcwODUwWjCBlDELMAkGA1UEBhMCVVMxEzARBgNVBAgMCldh\n'
1424 + + 'c2hpbmd0b24xEDAOBgNVBAcMB1NlY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KEkHZRZ4mEiMgr3YLkv8gSmeitx57\n'
1439 + + 'Z6dVemNtUic/LVo5Iqw4n3TBS0iF2C1Q1xT/s3h+0SXZlfOWttzSluDvoMv5PvCd\n'
1440 + + 'pFjNn+aXLAALoihL1MJSsxydtsLjOBro5eK0Vw==\n'
1441 + + '-----END CERTIFICATE-----\n',
1442 +
1443 + /**
1444 + * Amazon RDS us-west-2 certificate CA 2019 to 2024
1445 + *
1446 + * CN = Amazon RDS us-west-2 2019 CA
1447 + * OU = Amazon RDS
1448 + * O = Amazon Web Services, Inc.
1449 + * L = Seattle
1450 + * ST = Washington
1451 + * C = US
1452 + * P = 2019-09-16T18:21:15Z/2024-08-22T17:08:50Z
1453 + * F = C8:DE:1D:13:AD:35:9B:3D:EA:18:2A:DC:B4:79:6D:22:47:75:3C:4A
1454 + */
1455 + '-----BEGIN CERTIFICATE-----\n'
1456 + + 'MIIEBzCCAu+gAwIBAgICUYkwDQYJKoZIhvcNAQELBQAwgY8xCzAJBgNVBAYTAlVT\n'
1457 + + 'MRAwDgYDVQQHDAdTZWF0dGxlMRMwEQYDVQQIDApXYXNoaW5ndG9uMSIwIAYDVQQK\n'
1458 + + 'DBlBbWF6b24gV2ViIFNlcnZpY2VzLCBJbmMuMRMwEQYDVQQLDApBbWF6b24gUkRT\n'
1459 + + 'MSAwHgYDVQQDDBdBbWF6b24gUkRTIFJvb3QgMjAxOSBDQTAeFw0xOTA5MTYxODIx\n'
1460 + + 'MTVaFw0yNDA4MjIxNzA4NTBaMIGUMQswCQYDVQQGEwJVUzETMBEGA1UECAwKV2Fz\n'
1461 + + 'aGluZ3RvbjEQMA4GA1UEBwwHU2VhdHRsZTEiMCAGA1UECgwZQW1hem9uIFdlYiBT\n'
1462 + + 'ZXJ2aWNlcywgSW5jLjETMBEGA1UECwwKQW1hem9uIFJEUzElMCMGA1UEAwwcQW1h\n'
1463 + + 'em9uIFJEUyB1cy13ZXN0LTIgMjAxOSBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEP\n'
1464 + + 'ADCCAQoCggEBANCEZBZyu6yJQFZBJmSUZfSZd3Ui2gitczMKC4FLr0QzkbxY+cLa\n'
1465 + + 'uVONIOrPt4Rwi+3h/UdnUg917xao3S53XDf1TDMFEYp4U8EFPXqCn/GXBIWlU86P\n'
1466 + + 'PvBN+gzw3nS+aco7WXb+woTouvFVkk8FGU7J532llW8o/9ydQyDIMtdIkKTuMfho\n'
1467 + + 'OiNHSaNc+QXQ32TgvM9A/6q7ksUoNXGCP8hDOkSZ/YOLiI5TcdLh/aWj00ziL5bj\n'
1468 + + 'pvytiMZkilnc9dLY9QhRNr0vGqL0xjmWdoEXz9/OwjmCihHqJq+20MJPsvFm7D6a\n'
1469 + + '2NKybR9U+ddrjb8/iyLOjURUZnj5O+2+OPcCAwEAAaNmMGQwDgYDVR0PAQH/BAQD\n'
1470 + + 'AgEGMBIGA1UdEwEB/wQIMAYBAf8CAQAwHQYDVR0OBBYEFEBxMBdv81xuzqcK5TVu\n'
1471 + + 'pHj+Aor8MB8GA1UdIwQYMBaAFHNfYNi8ywOY9CsXNC42WqZg/7wfMA0GCSqGSIb3\n'
1472 + + 'DQEBCwUAA4IBAQBZkfiVqGoJjBI37aTlLOSjLcjI75L5wBrwO39q+B4cwcmpj58P\n'
1473 + + '3sivv+jhYfAGEbQnGRzjuFoyPzWnZ1DesRExX+wrmHsLLQbF2kVjLZhEJMHF9eB7\n'
1474 + + 'GZlTPdTzHErcnuXkwA/OqyXMpj9aghcQFuhCNguEfnROY9sAoK2PTfnTz9NJHL+Q\n'
1475 + + 'UpDLEJEUfc0GZMVWYhahc0x38ZnSY2SKacIPECQrTI0KpqZv/P+ijCEcMD9xmYEb\n'
1476 + + 'jL4en+XKS1uJpw5fIU5Sj0MxhdGstH6S84iAE5J3GM3XHklGSFwwqPYvuTXvANH6\n'
1477 + + 'uboynxRgSae59jIlAK6Jrr6GWMwQRbgcaAlW\n'
1478 + + '-----END CERTIFICATE-----\n'
1479 + ]
1480 +};
1 +/**
2 + * MySQL type constants
3 + *
4 + * Extracted from version 5.7.29
5 + *
6 + * !! Generated by generate-type-constants.js, do not modify by hand !!
7 + */
8 +
9 +exports.DECIMAL = 0;
10 +exports.TINY = 1;
11 +exports.SHORT = 2;
12 +exports.LONG = 3;
13 +exports.FLOAT = 4;
14 +exports.DOUBLE = 5;
15 +exports.NULL = 6;
16 +exports.TIMESTAMP = 7;
17 +exports.LONGLONG = 8;
18 +exports.INT24 = 9;
19 +exports.DATE = 10;
20 +exports.TIME = 11;
21 +exports.DATETIME = 12;
22 +exports.YEAR = 13;
23 +exports.NEWDATE = 14;
24 +exports.VARCHAR = 15;
25 +exports.BIT = 16;
26 +exports.TIMESTAMP2 = 17;
27 +exports.DATETIME2 = 18;
28 +exports.TIME2 = 19;
29 +exports.JSON = 245;
30 +exports.NEWDECIMAL = 246;
31 +exports.ENUM = 247;
32 +exports.SET = 248;
33 +exports.TINY_BLOB = 249;
34 +exports.MEDIUM_BLOB = 250;
35 +exports.LONG_BLOB = 251;
36 +exports.BLOB = 252;
37 +exports.VAR_STRING = 253;
38 +exports.STRING = 254;
39 +exports.GEOMETRY = 255;
40 +
41 +// Lookup-by-number table
42 +exports[0] = 'DECIMAL';
43 +exports[1] = 'TINY';
44 +exports[2] = 'SHORT';
45 +exports[3] = 'LONG';
46 +exports[4] = 'FLOAT';
47 +exports[5] = 'DOUBLE';
48 +exports[6] = 'NULL';
49 +exports[7] = 'TIMESTAMP';
50 +exports[8] = 'LONGLONG';
51 +exports[9] = 'INT24';
52 +exports[10] = 'DATE';
53 +exports[11] = 'TIME';
54 +exports[12] = 'DATETIME';
55 +exports[13] = 'YEAR';
56 +exports[14] = 'NEWDATE';
57 +exports[15] = 'VARCHAR';
58 +exports[16] = 'BIT';
59 +exports[17] = 'TIMESTAMP2';
60 +exports[18] = 'DATETIME2';
61 +exports[19] = 'TIME2';
62 +exports[245] = 'JSON';
63 +exports[246] = 'NEWDECIMAL';
64 +exports[247] = 'ENUM';
65 +exports[248] = 'SET';
66 +exports[249] = 'TINY_BLOB';
67 +exports[250] = 'MEDIUM_BLOB';
68 +exports[251] = 'LONG_BLOB';
69 +exports[252] = 'BLOB';
70 +exports[253] = 'VAR_STRING';
71 +exports[254] = 'STRING';
72 +exports[255] = 'GEOMETRY';
1 +module.exports = AuthSwitchRequestPacket;
2 +function AuthSwitchRequestPacket(options) {
3 + options = options || {};
4 +
5 + this.status = 0xfe;
6 + this.authMethodName = options.authMethodName;
7 + this.authMethodData = options.authMethodData;
8 +}
9 +
10 +AuthSwitchRequestPacket.prototype.parse = function parse(parser) {
11 + this.status = parser.parseUnsignedNumber(1);
12 + this.authMethodName = parser.parseNullTerminatedString();
13 + this.authMethodData = parser.parsePacketTerminatedBuffer();
14 +};
15 +
16 +AuthSwitchRequestPacket.prototype.write = function write(writer) {
17 + writer.writeUnsignedNumber(1, this.status);
18 + writer.writeNullTerminatedString(this.authMethodName);
19 + writer.writeBuffer(this.authMethodData);
20 +};
1 +module.exports = AuthSwitchResponsePacket;
2 +function AuthSwitchResponsePacket(options) {
3 + options = options || {};
4 +
5 + this.data = options.data;
6 +}
7 +
8 +AuthSwitchResponsePacket.prototype.parse = function parse(parser) {
9 + this.data = parser.parsePacketTerminatedBuffer();
10 +};
11 +
12 +AuthSwitchResponsePacket.prototype.write = function write(writer) {
13 + writer.writeBuffer(this.data);
14 +};
1 +var Buffer = require('safe-buffer').Buffer;
2 +
3 +module.exports = ClientAuthenticationPacket;
4 +function ClientAuthenticationPacket(options) {
5 + options = options || {};
6 +
7 + this.clientFlags = options.clientFlags;
8 + this.maxPacketSize = options.maxPacketSize;
9 + this.charsetNumber = options.charsetNumber;
10 + this.filler = undefined;
11 + this.user = options.user;
12 + this.scrambleBuff = options.scrambleBuff;
13 + this.database = options.database;
14 + this.protocol41 = options.protocol41;
15 +}
16 +
17 +ClientAuthenticationPacket.prototype.parse = function(parser) {
18 + if (this.protocol41) {
19 + this.clientFlags = parser.parseUnsignedNumber(4);
20 + this.maxPacketSize = parser.parseUnsignedNumber(4);
21 + this.charsetNumber = parser.parseUnsignedNumber(1);
22 + this.filler = parser.parseFiller(23);
23 + this.user = parser.parseNullTerminatedString();
24 + this.scrambleBuff = parser.parseLengthCodedBuffer();
25 + this.database = parser.parseNullTerminatedString();
26 + } else {
27 + this.clientFlags = parser.parseUnsignedNumber(2);
28 + this.maxPacketSize = parser.parseUnsignedNumber(3);
29 + this.user = parser.parseNullTerminatedString();
30 + this.scrambleBuff = parser.parseBuffer(8);
31 + this.database = parser.parseLengthCodedBuffer();
32 + }
33 +};
34 +
35 +ClientAuthenticationPacket.prototype.write = function(writer) {
36 + if (this.protocol41) {
37 + writer.writeUnsignedNumber(4, this.clientFlags);
38 + writer.writeUnsignedNumber(4, this.maxPacketSize);
39 + writer.writeUnsignedNumber(1, this.charsetNumber);
40 + writer.writeFiller(23);
41 + writer.writeNullTerminatedString(this.user);
42 + writer.writeLengthCodedBuffer(this.scrambleBuff);
43 + writer.writeNullTerminatedString(this.database);
44 + } else {
45 + writer.writeUnsignedNumber(2, this.clientFlags);
46 + writer.writeUnsignedNumber(3, this.maxPacketSize);
47 + writer.writeNullTerminatedString(this.user);
48 + writer.writeBuffer(this.scrambleBuff);
49 + if (this.database && this.database.length) {
50 + writer.writeFiller(1);
51 + writer.writeBuffer(Buffer.from(this.database));
52 + }
53 + }
54 +};
1 +module.exports = ComChangeUserPacket;
2 +function ComChangeUserPacket(options) {
3 + options = options || {};
4 +
5 + this.command = 0x11;
6 + this.user = options.user;
7 + this.scrambleBuff = options.scrambleBuff;
8 + this.database = options.database;
9 + this.charsetNumber = options.charsetNumber;
10 +}
11 +
12 +ComChangeUserPacket.prototype.parse = function(parser) {
13 + this.command = parser.parseUnsignedNumber(1);
14 + this.user = parser.parseNullTerminatedString();
15 + this.scrambleBuff = parser.parseLengthCodedBuffer();
16 + this.database = parser.parseNullTerminatedString();
17 + this.charsetNumber = parser.parseUnsignedNumber(1);
18 +};
19 +
20 +ComChangeUserPacket.prototype.write = function(writer) {
21 + writer.writeUnsignedNumber(1, this.command);
22 + writer.writeNullTerminatedString(this.user);
23 + writer.writeLengthCodedBuffer(this.scrambleBuff);
24 + writer.writeNullTerminatedString(this.database);
25 + writer.writeUnsignedNumber(2, this.charsetNumber);
26 +};
1 +module.exports = ComPingPacket;
2 +function ComPingPacket() {
3 + this.command = 0x0e;
4 +}
5 +
6 +ComPingPacket.prototype.write = function(writer) {
7 + writer.writeUnsignedNumber(1, this.command);
8 +};
9 +
10 +ComPingPacket.prototype.parse = function(parser) {
11 + this.command = parser.parseUnsignedNumber(1);
12 +};
1 +module.exports = ComQueryPacket;
2 +function ComQueryPacket(sql) {
3 + this.command = 0x03;
4 + this.sql = sql;
5 +}
6 +
7 +ComQueryPacket.prototype.write = function(writer) {
8 + writer.writeUnsignedNumber(1, this.command);
9 + writer.writeString(this.sql);
10 +};
11 +
12 +ComQueryPacket.prototype.parse = function(parser) {
13 + this.command = parser.parseUnsignedNumber(1);
14 + this.sql = parser.parsePacketTerminatedString();
15 +};
1 +module.exports = ComQuitPacket;
2 +function ComQuitPacket() {
3 + this.command = 0x01;
4 +}
5 +
6 +ComQuitPacket.prototype.parse = function parse(parser) {
7 + this.command = parser.parseUnsignedNumber(1);
8 +};
9 +
10 +ComQuitPacket.prototype.write = function write(writer) {
11 + writer.writeUnsignedNumber(1, this.command);
12 +};
1 +module.exports = ComStatisticsPacket;
2 +function ComStatisticsPacket() {
3 + this.command = 0x09;
4 +}
5 +
6 +ComStatisticsPacket.prototype.write = function(writer) {
7 + writer.writeUnsignedNumber(1, this.command);
8 +};
9 +
10 +ComStatisticsPacket.prototype.parse = function(parser) {
11 + this.command = parser.parseUnsignedNumber(1);
12 +};
1 +module.exports = EmptyPacket;
2 +function EmptyPacket() {
3 +}
4 +
5 +EmptyPacket.prototype.parse = function parse() {
6 +};
7 +
8 +EmptyPacket.prototype.write = function write() {
9 +};
1 +module.exports = EofPacket;
2 +function EofPacket(options) {
3 + options = options || {};
4 +
5 + this.fieldCount = undefined;
6 + this.warningCount = options.warningCount;
7 + this.serverStatus = options.serverStatus;
8 + this.protocol41 = options.protocol41;
9 +}
10 +
11 +EofPacket.prototype.parse = function(parser) {
12 + this.fieldCount = parser.parseUnsignedNumber(1);
13 + if (this.protocol41) {
14 + this.warningCount = parser.parseUnsignedNumber(2);
15 + this.serverStatus = parser.parseUnsignedNumber(2);
16 + }
17 +};
18 +
19 +EofPacket.prototype.write = function(writer) {
20 + writer.writeUnsignedNumber(1, 0xfe);
21 + if (this.protocol41) {
22 + writer.writeUnsignedNumber(2, this.warningCount);
23 + writer.writeUnsignedNumber(2, this.serverStatus);
24 + }
25 +};
1 +module.exports = ErrorPacket;
2 +function ErrorPacket(options) {
3 + options = options || {};
4 +
5 + this.fieldCount = options.fieldCount;
6 + this.errno = options.errno;
7 + this.sqlStateMarker = options.sqlStateMarker;
8 + this.sqlState = options.sqlState;
9 + this.message = options.message;
10 +}
11 +
12 +ErrorPacket.prototype.parse = function(parser) {
13 + this.fieldCount = parser.parseUnsignedNumber(1);
14 + this.errno = parser.parseUnsignedNumber(2);
15 +
16 + // sqlStateMarker ('#' = 0x23) indicates error packet format
17 + if (parser.peak() === 0x23) {
18 + this.sqlStateMarker = parser.parseString(1);
19 + this.sqlState = parser.parseString(5);
20 + }
21 +
22 + this.message = parser.parsePacketTerminatedString();
23 +};
24 +
25 +ErrorPacket.prototype.write = function(writer) {
26 + writer.writeUnsignedNumber(1, 0xff);
27 + writer.writeUnsignedNumber(2, this.errno);
28 +
29 + if (this.sqlStateMarker) {
30 + writer.writeString(this.sqlStateMarker);
31 + writer.writeString(this.sqlState);
32 + }
33 +
34 + writer.writeString(this.message);
35 +};
1 +var Types = require('../constants/types');
2 +
3 +module.exports = Field;
4 +function Field(options) {
5 + options = options || {};
6 +
7 + this.parser = options.parser;
8 + this.packet = options.packet;
9 + this.db = options.packet.db;
10 + this.table = options.packet.table;
11 + this.name = options.packet.name;
12 + this.type = Types[options.packet.type];
13 + this.length = options.packet.length;
14 +}
15 +
16 +Field.prototype.string = function () {
17 + return this.parser.parseLengthCodedString();
18 +};
19 +
20 +Field.prototype.buffer = function () {
21 + return this.parser.parseLengthCodedBuffer();
22 +};
23 +
24 +Field.prototype.geometry = function () {
25 + return this.parser.parseGeometryValue();
26 +};
1 +module.exports = FieldPacket;
2 +function FieldPacket(options) {
3 + options = options || {};
4 +
5 + this.catalog = options.catalog;
6 + this.db = options.db;
7 + this.table = options.table;
8 + this.orgTable = options.orgTable;
9 + this.name = options.name;
10 + this.orgName = options.orgName;
11 + this.charsetNr = options.charsetNr;
12 + this.length = options.length;
13 + this.type = options.type;
14 + this.flags = options.flags;
15 + this.decimals = options.decimals;
16 + this.default = options.default;
17 + this.zeroFill = options.zeroFill;
18 + this.protocol41 = options.protocol41;
19 +}
20 +
21 +FieldPacket.prototype.parse = function(parser) {
22 + if (this.protocol41) {
23 + this.catalog = parser.parseLengthCodedString();
24 + this.db = parser.parseLengthCodedString();
25 + this.table = parser.parseLengthCodedString();
26 + this.orgTable = parser.parseLengthCodedString();
27 + this.name = parser.parseLengthCodedString();
28 + this.orgName = parser.parseLengthCodedString();
29 +
30 + if (parser.parseLengthCodedNumber() !== 0x0c) {
31 + var err = new TypeError('Received invalid field length');
32 + err.code = 'PARSER_INVALID_FIELD_LENGTH';
33 + throw err;
34 + }
35 +
36 + this.charsetNr = parser.parseUnsignedNumber(2);
37 + this.length = parser.parseUnsignedNumber(4);
38 + this.type = parser.parseUnsignedNumber(1);
39 + this.flags = parser.parseUnsignedNumber(2);
40 + this.decimals = parser.parseUnsignedNumber(1);
41 +
42 + var filler = parser.parseBuffer(2);
43 + if (filler[0] !== 0x0 || filler[1] !== 0x0) {
44 + var err = new TypeError('Received invalid filler');
45 + err.code = 'PARSER_INVALID_FILLER';
46 + throw err;
47 + }
48 +
49 + // parsed flags
50 + this.zeroFill = (this.flags & 0x0040 ? true : false);
51 +
52 + if (parser.reachedPacketEnd()) {
53 + return;
54 + }
55 +
56 + this.default = parser.parseLengthCodedString();
57 + } else {
58 + this.table = parser.parseLengthCodedString();
59 + this.name = parser.parseLengthCodedString();
60 + this.length = parser.parseUnsignedNumber(parser.parseUnsignedNumber(1));
61 + this.type = parser.parseUnsignedNumber(parser.parseUnsignedNumber(1));
62 + }
63 +};
64 +
65 +FieldPacket.prototype.write = function(writer) {
66 + if (this.protocol41) {
67 + writer.writeLengthCodedString(this.catalog);
68 + writer.writeLengthCodedString(this.db);
69 + writer.writeLengthCodedString(this.table);
70 + writer.writeLengthCodedString(this.orgTable);
71 + writer.writeLengthCodedString(this.name);
72 + writer.writeLengthCodedString(this.orgName);
73 +
74 + writer.writeLengthCodedNumber(0x0c);
75 + writer.writeUnsignedNumber(2, this.charsetNr || 0);
76 + writer.writeUnsignedNumber(4, this.length || 0);
77 + writer.writeUnsignedNumber(1, this.type || 0);
78 + writer.writeUnsignedNumber(2, this.flags || 0);
79 + writer.writeUnsignedNumber(1, this.decimals || 0);
80 + writer.writeFiller(2);
81 +
82 + if (this.default !== undefined) {
83 + writer.writeLengthCodedString(this.default);
84 + }
85 + } else {
86 + writer.writeLengthCodedString(this.table);
87 + writer.writeLengthCodedString(this.name);
88 + writer.writeUnsignedNumber(1, 0x01);
89 + writer.writeUnsignedNumber(1, this.length);
90 + writer.writeUnsignedNumber(1, 0x01);
91 + writer.writeUnsignedNumber(1, this.type);
92 + }
93 +};
1 +var Buffer = require('safe-buffer').Buffer;
2 +var Client = require('../constants/client');
3 +
4 +module.exports = HandshakeInitializationPacket;
5 +function HandshakeInitializationPacket(options) {
6 + options = options || {};
7 +
8 + this.protocolVersion = options.protocolVersion;
9 + this.serverVersion = options.serverVersion;
10 + this.threadId = options.threadId;
11 + this.scrambleBuff1 = options.scrambleBuff1;
12 + this.filler1 = options.filler1;
13 + this.serverCapabilities1 = options.serverCapabilities1;
14 + this.serverLanguage = options.serverLanguage;
15 + this.serverStatus = options.serverStatus;
16 + this.serverCapabilities2 = options.serverCapabilities2;
17 + this.scrambleLength = options.scrambleLength;
18 + this.filler2 = options.filler2;
19 + this.scrambleBuff2 = options.scrambleBuff2;
20 + this.filler3 = options.filler3;
21 + this.pluginData = options.pluginData;
22 + this.protocol41 = options.protocol41;
23 +
24 + if (this.protocol41) {
25 + // force set the bit in serverCapabilities1
26 + this.serverCapabilities1 |= Client.CLIENT_PROTOCOL_41;
27 + }
28 +}
29 +
30 +HandshakeInitializationPacket.prototype.parse = function(parser) {
31 + this.protocolVersion = parser.parseUnsignedNumber(1);
32 + this.serverVersion = parser.parseNullTerminatedString();
33 + this.threadId = parser.parseUnsignedNumber(4);
34 + this.scrambleBuff1 = parser.parseBuffer(8);
35 + this.filler1 = parser.parseFiller(1);
36 + this.serverCapabilities1 = parser.parseUnsignedNumber(2);
37 + this.serverLanguage = parser.parseUnsignedNumber(1);
38 + this.serverStatus = parser.parseUnsignedNumber(2);
39 +
40 + this.protocol41 = (this.serverCapabilities1 & (1 << 9)) > 0;
41 +
42 + if (this.protocol41) {
43 + this.serverCapabilities2 = parser.parseUnsignedNumber(2);
44 + this.scrambleLength = parser.parseUnsignedNumber(1);
45 + this.filler2 = parser.parseFiller(10);
46 + // scrambleBuff2 should be 0x00 terminated, but sphinx does not do this
47 + // so we assume scrambleBuff2 to be 12 byte and treat the next byte as a
48 + // filler byte.
49 + this.scrambleBuff2 = parser.parseBuffer(12);
50 + this.filler3 = parser.parseFiller(1);
51 + } else {
52 + this.filler2 = parser.parseFiller(13);
53 + }
54 +
55 + if (parser.reachedPacketEnd()) {
56 + return;
57 + }
58 +
59 + // According to the docs this should be 0x00 terminated, but MariaDB does
60 + // not do this, so we assume this string to be packet terminated.
61 + this.pluginData = parser.parsePacketTerminatedString();
62 +
63 + // However, if there is a trailing '\0', strip it
64 + var lastChar = this.pluginData.length - 1;
65 + if (this.pluginData[lastChar] === '\0') {
66 + this.pluginData = this.pluginData.substr(0, lastChar);
67 + }
68 +};
69 +
70 +HandshakeInitializationPacket.prototype.write = function(writer) {
71 + writer.writeUnsignedNumber(1, this.protocolVersion);
72 + writer.writeNullTerminatedString(this.serverVersion);
73 + writer.writeUnsignedNumber(4, this.threadId);
74 + writer.writeBuffer(this.scrambleBuff1);
75 + writer.writeFiller(1);
76 + writer.writeUnsignedNumber(2, this.serverCapabilities1);
77 + writer.writeUnsignedNumber(1, this.serverLanguage);
78 + writer.writeUnsignedNumber(2, this.serverStatus);
79 + if (this.protocol41) {
80 + writer.writeUnsignedNumber(2, this.serverCapabilities2);
81 + writer.writeUnsignedNumber(1, this.scrambleLength);
82 + writer.writeFiller(10);
83 + }
84 + writer.writeNullTerminatedBuffer(this.scrambleBuff2);
85 +
86 + if (this.pluginData !== undefined) {
87 + writer.writeNullTerminatedString(this.pluginData);
88 + }
89 +};
90 +
91 +HandshakeInitializationPacket.prototype.scrambleBuff = function() {
92 + var buffer = null;
93 +
94 + if (typeof this.scrambleBuff2 === 'undefined') {
95 + buffer = Buffer.from(this.scrambleBuff1);
96 + } else {
97 + buffer = Buffer.allocUnsafe(this.scrambleBuff1.length + this.scrambleBuff2.length);
98 + this.scrambleBuff1.copy(buffer, 0);
99 + this.scrambleBuff2.copy(buffer, this.scrambleBuff1.length);
100 + }
101 +
102 + return buffer;
103 +};
1 +module.exports = LocalDataFilePacket;
2 +
3 +/**
4 + * Create a new LocalDataFilePacket
5 + * @constructor
6 + * @param {Buffer} data The data contents of the packet
7 + * @public
8 + */
9 +function LocalDataFilePacket(data) {
10 + this.data = data;
11 +}
12 +
13 +LocalDataFilePacket.prototype.write = function(writer) {
14 + writer.writeBuffer(this.data);
15 +};
1 +module.exports = LocalInfileRequestPacket;
2 +function LocalInfileRequestPacket(options) {
3 + options = options || {};
4 +
5 + this.filename = options.filename;
6 +}
7 +
8 +LocalInfileRequestPacket.prototype.parse = function parse(parser) {
9 + if (parser.parseLengthCodedNumber() !== null) {
10 + var err = new TypeError('Received invalid field length');
11 + err.code = 'PARSER_INVALID_FIELD_LENGTH';
12 + throw err;
13 + }
14 +
15 + this.filename = parser.parsePacketTerminatedString();
16 +};
17 +
18 +LocalInfileRequestPacket.prototype.write = function write(writer) {
19 + writer.writeLengthCodedNumber(null);
20 + writer.writeString(this.filename);
21 +};
1 +
2 +// Language-neutral expression to match ER_UPDATE_INFO
3 +var ER_UPDATE_INFO_REGEXP = /^[^:0-9]+: [0-9]+[^:0-9]+: ([0-9]+)[^:0-9]+: [0-9]+[^:0-9]*$/;
4 +
5 +module.exports = OkPacket;
6 +function OkPacket(options) {
7 + options = options || {};
8 +
9 + this.fieldCount = undefined;
10 + this.affectedRows = undefined;
11 + this.insertId = undefined;
12 + this.serverStatus = undefined;
13 + this.warningCount = undefined;
14 + this.message = undefined;
15 + this.protocol41 = options.protocol41;
16 +}
17 +
18 +OkPacket.prototype.parse = function(parser) {
19 + this.fieldCount = parser.parseUnsignedNumber(1);
20 + this.affectedRows = parser.parseLengthCodedNumber();
21 + this.insertId = parser.parseLengthCodedNumber();
22 + if (this.protocol41) {
23 + this.serverStatus = parser.parseUnsignedNumber(2);
24 + this.warningCount = parser.parseUnsignedNumber(2);
25 + }
26 + this.message = parser.parsePacketTerminatedString();
27 + this.changedRows = 0;
28 +
29 + var m = ER_UPDATE_INFO_REGEXP.exec(this.message);
30 + if (m !== null) {
31 + this.changedRows = parseInt(m[1], 10);
32 + }
33 +};
34 +
35 +OkPacket.prototype.write = function(writer) {
36 + writer.writeUnsignedNumber(1, 0x00);
37 + writer.writeLengthCodedNumber(this.affectedRows || 0);
38 + writer.writeLengthCodedNumber(this.insertId || 0);
39 + if (this.protocol41) {
40 + writer.writeUnsignedNumber(2, this.serverStatus || 0);
41 + writer.writeUnsignedNumber(2, this.warningCount || 0);
42 + }
43 + writer.writeString(this.message);
44 +};
1 +module.exports = OldPasswordPacket;
2 +function OldPasswordPacket(options) {
3 + options = options || {};
4 +
5 + this.scrambleBuff = options.scrambleBuff;
6 +}
7 +
8 +OldPasswordPacket.prototype.parse = function(parser) {
9 + this.scrambleBuff = parser.parsePacketTerminatedBuffer();
10 +};
11 +
12 +OldPasswordPacket.prototype.write = function(writer) {
13 + writer.writeBuffer(this.scrambleBuff);
14 +};
1 +module.exports = ResultSetHeaderPacket;
2 +function ResultSetHeaderPacket(options) {
3 + options = options || {};
4 +
5 + this.fieldCount = options.fieldCount;
6 +}
7 +
8 +ResultSetHeaderPacket.prototype.parse = function(parser) {
9 + this.fieldCount = parser.parseLengthCodedNumber();
10 +};
11 +
12 +ResultSetHeaderPacket.prototype.write = function(writer) {
13 + writer.writeLengthCodedNumber(this.fieldCount);
14 +};
1 +var Types = require('../constants/types');
2 +var Charsets = require('../constants/charsets');
3 +var Field = require('./Field');
4 +var IEEE_754_BINARY_64_PRECISION = Math.pow(2, 53);
5 +
6 +module.exports = RowDataPacket;
7 +function RowDataPacket() {
8 +}
9 +
10 +Object.defineProperty(RowDataPacket.prototype, 'parse', {
11 + configurable : true,
12 + enumerable : false,
13 + value : parse
14 +});
15 +
16 +Object.defineProperty(RowDataPacket.prototype, '_typeCast', {
17 + configurable : true,
18 + enumerable : false,
19 + value : typeCast
20 +});
21 +
22 +function parse(parser, fieldPackets, typeCast, nestTables, connection) {
23 + var self = this;
24 + var next = function () {
25 + return self._typeCast(fieldPacket, parser, connection.config.timezone, connection.config.supportBigNumbers, connection.config.bigNumberStrings, connection.config.dateStrings);
26 + };
27 +
28 + for (var i = 0; i < fieldPackets.length; i++) {
29 + var fieldPacket = fieldPackets[i];
30 + var value;
31 +
32 + if (typeof typeCast === 'function') {
33 + value = typeCast.apply(connection, [ new Field({ packet: fieldPacket, parser: parser }), next ]);
34 + } else {
35 + value = (typeCast)
36 + ? this._typeCast(fieldPacket, parser, connection.config.timezone, connection.config.supportBigNumbers, connection.config.bigNumberStrings, connection.config.dateStrings)
37 + : ( (fieldPacket.charsetNr === Charsets.BINARY)
38 + ? parser.parseLengthCodedBuffer()
39 + : parser.parseLengthCodedString() );
40 + }
41 +
42 + if (typeof nestTables === 'string' && nestTables.length) {
43 + this[fieldPacket.table + nestTables + fieldPacket.name] = value;
44 + } else if (nestTables) {
45 + this[fieldPacket.table] = this[fieldPacket.table] || {};
46 + this[fieldPacket.table][fieldPacket.name] = value;
47 + } else {
48 + this[fieldPacket.name] = value;
49 + }
50 + }
51 +}
52 +
53 +function typeCast(field, parser, timeZone, supportBigNumbers, bigNumberStrings, dateStrings) {
54 + var numberString;
55 +
56 + switch (field.type) {
57 + case Types.TIMESTAMP:
58 + case Types.TIMESTAMP2:
59 + case Types.DATE:
60 + case Types.DATETIME:
61 + case Types.DATETIME2:
62 + case Types.NEWDATE:
63 + var dateString = parser.parseLengthCodedString();
64 +
65 + if (typeMatch(field.type, dateStrings)) {
66 + return dateString;
67 + }
68 +
69 + if (dateString === null) {
70 + return null;
71 + }
72 +
73 + var originalString = dateString;
74 + if (field.type === Types.DATE) {
75 + dateString += ' 00:00:00';
76 + }
77 +
78 + if (timeZone !== 'local') {
79 + dateString += ' ' + timeZone;
80 + }
81 +
82 + var dt = new Date(dateString);
83 + if (isNaN(dt.getTime())) {
84 + return originalString;
85 + }
86 +
87 + return dt;
88 + case Types.TINY:
89 + case Types.SHORT:
90 + case Types.LONG:
91 + case Types.INT24:
92 + case Types.YEAR:
93 + case Types.FLOAT:
94 + case Types.DOUBLE:
95 + numberString = parser.parseLengthCodedString();
96 + return (numberString === null || (field.zeroFill && numberString[0] === '0'))
97 + ? numberString : Number(numberString);
98 + case Types.NEWDECIMAL:
99 + case Types.LONGLONG:
100 + numberString = parser.parseLengthCodedString();
101 + return (numberString === null || (field.zeroFill && numberString[0] === '0'))
102 + ? numberString
103 + : ((supportBigNumbers && (bigNumberStrings || (Number(numberString) >= IEEE_754_BINARY_64_PRECISION) || Number(numberString) <= -IEEE_754_BINARY_64_PRECISION))
104 + ? numberString
105 + : Number(numberString));
106 + case Types.BIT:
107 + return parser.parseLengthCodedBuffer();
108 + case Types.STRING:
109 + case Types.VAR_STRING:
110 + case Types.TINY_BLOB:
111 + case Types.MEDIUM_BLOB:
112 + case Types.LONG_BLOB:
113 + case Types.BLOB:
114 + return (field.charsetNr === Charsets.BINARY)
115 + ? parser.parseLengthCodedBuffer()
116 + : parser.parseLengthCodedString();
117 + case Types.GEOMETRY:
118 + return parser.parseGeometryValue();
119 + default:
120 + return parser.parseLengthCodedString();
121 + }
122 +}
123 +
124 +function typeMatch(type, list) {
125 + if (Array.isArray(list)) {
126 + return list.indexOf(Types[type]) !== -1;
127 + } else {
128 + return Boolean(list);
129 + }
130 +}
1 +// http://dev.mysql.com/doc/internals/en/ssl.html
2 +// http://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::SSLRequest
3 +
4 +var ClientConstants = require('../constants/client');
5 +
6 +module.exports = SSLRequestPacket;
7 +
8 +function SSLRequestPacket(options) {
9 + options = options || {};
10 + this.clientFlags = options.clientFlags | ClientConstants.CLIENT_SSL;
11 + this.maxPacketSize = options.maxPacketSize;
12 + this.charsetNumber = options.charsetNumber;
13 +}
14 +
15 +SSLRequestPacket.prototype.parse = function(parser) {
16 + // TODO: check SSLRequest packet v41 vs pre v41
17 + this.clientFlags = parser.parseUnsignedNumber(4);
18 + this.maxPacketSize = parser.parseUnsignedNumber(4);
19 + this.charsetNumber = parser.parseUnsignedNumber(1);
20 +};
21 +
22 +SSLRequestPacket.prototype.write = function(writer) {
23 + writer.writeUnsignedNumber(4, this.clientFlags);
24 + writer.writeUnsignedNumber(4, this.maxPacketSize);
25 + writer.writeUnsignedNumber(1, this.charsetNumber);
26 + writer.writeFiller(23);
27 +};
1 +module.exports = StatisticsPacket;
2 +function StatisticsPacket() {
3 + this.message = undefined;
4 +}
5 +
6 +StatisticsPacket.prototype.parse = function(parser) {
7 + this.message = parser.parsePacketTerminatedString();
8 +
9 + var items = this.message.split(/\s\s/);
10 + for (var i = 0; i < items.length; i++) {
11 + var m = items[i].match(/^(.+)\:\s+(.+)$/);
12 + if (m !== null) {
13 + this[m[1].toLowerCase().replace(/\s/g, '_')] = Number(m[2]);
14 + }
15 + }
16 +};
17 +
18 +StatisticsPacket.prototype.write = function(writer) {
19 + writer.writeString(this.message);
20 +};
1 +module.exports = UseOldPasswordPacket;
2 +function UseOldPasswordPacket(options) {
3 + options = options || {};
4 +
5 + this.firstByte = options.firstByte || 0xfe;
6 +}
7 +
8 +UseOldPasswordPacket.prototype.parse = function(parser) {
9 + this.firstByte = parser.parseUnsignedNumber(1);
10 +};
11 +
12 +UseOldPasswordPacket.prototype.write = function(writer) {
13 + writer.writeUnsignedNumber(1, this.firstByte);
14 +};
1 +exports.AuthSwitchRequestPacket = require('./AuthSwitchRequestPacket');
2 +exports.AuthSwitchResponsePacket = require('./AuthSwitchResponsePacket');
3 +exports.ClientAuthenticationPacket = require('./ClientAuthenticationPacket');
4 +exports.ComChangeUserPacket = require('./ComChangeUserPacket');
5 +exports.ComPingPacket = require('./ComPingPacket');
6 +exports.ComQueryPacket = require('./ComQueryPacket');
7 +exports.ComQuitPacket = require('./ComQuitPacket');
8 +exports.ComStatisticsPacket = require('./ComStatisticsPacket');
9 +exports.EmptyPacket = require('./EmptyPacket');
10 +exports.EofPacket = require('./EofPacket');
11 +exports.ErrorPacket = require('./ErrorPacket');
12 +exports.Field = require('./Field');
13 +exports.FieldPacket = require('./FieldPacket');
14 +exports.HandshakeInitializationPacket = require('./HandshakeInitializationPacket');
15 +exports.LocalDataFilePacket = require('./LocalDataFilePacket');
16 +exports.LocalInfileRequestPacket = require('./LocalInfileRequestPacket');
17 +exports.OkPacket = require('./OkPacket');
18 +exports.OldPasswordPacket = require('./OldPasswordPacket');
19 +exports.ResultSetHeaderPacket = require('./ResultSetHeaderPacket');
20 +exports.RowDataPacket = require('./RowDataPacket');
21 +exports.SSLRequestPacket = require('./SSLRequestPacket');
22 +exports.StatisticsPacket = require('./StatisticsPacket');
23 +exports.UseOldPasswordPacket = require('./UseOldPasswordPacket');
1 +var Sequence = require('./Sequence');
2 +var Util = require('util');
3 +var Packets = require('../packets');
4 +var Auth = require('../Auth');
5 +
6 +module.exports = ChangeUser;
7 +Util.inherits(ChangeUser, Sequence);
8 +function ChangeUser(options, callback) {
9 + Sequence.call(this, options, callback);
10 +
11 + this._user = options.user;
12 + this._password = options.password;
13 + this._database = options.database;
14 + this._charsetNumber = options.charsetNumber;
15 + this._currentConfig = options.currentConfig;
16 +}
17 +
18 +ChangeUser.prototype.determinePacket = function determinePacket(firstByte) {
19 + switch (firstByte) {
20 + case 0xfe: return Packets.AuthSwitchRequestPacket;
21 + case 0xff: return Packets.ErrorPacket;
22 + default: return undefined;
23 + }
24 +};
25 +
26 +ChangeUser.prototype.start = function(handshakeInitializationPacket) {
27 + var scrambleBuff = handshakeInitializationPacket.scrambleBuff();
28 + scrambleBuff = Auth.token(this._password, scrambleBuff);
29 +
30 + var packet = new Packets.ComChangeUserPacket({
31 + user : this._user,
32 + scrambleBuff : scrambleBuff,
33 + database : this._database,
34 + charsetNumber : this._charsetNumber
35 + });
36 +
37 + this._currentConfig.user = this._user;
38 + this._currentConfig.password = this._password;
39 + this._currentConfig.database = this._database;
40 + this._currentConfig.charsetNumber = this._charsetNumber;
41 +
42 + this.emit('packet', packet);
43 +};
44 +
45 +ChangeUser.prototype['AuthSwitchRequestPacket'] = function (packet) {
46 + var name = packet.authMethodName;
47 + var data = Auth.auth(name, packet.authMethodData, {
48 + password: this._password
49 + });
50 +
51 + if (data !== undefined) {
52 + this.emit('packet', new Packets.AuthSwitchResponsePacket({
53 + data: data
54 + }));
55 + } else {
56 + var err = new Error('MySQL is requesting the ' + name + ' authentication method, which is not supported.');
57 + err.code = 'UNSUPPORTED_AUTH_METHOD';
58 + err.fatal = true;
59 + this.end(err);
60 + }
61 +};
62 +
63 +ChangeUser.prototype['ErrorPacket'] = function(packet) {
64 + var err = this._packetToError(packet);
65 + err.fatal = true;
66 + this.end(err);
67 +};
1 +var Sequence = require('./Sequence');
2 +var Util = require('util');
3 +var Packets = require('../packets');
4 +var Auth = require('../Auth');
5 +var ClientConstants = require('../constants/client');
6 +
7 +module.exports = Handshake;
8 +Util.inherits(Handshake, Sequence);
9 +function Handshake(options, callback) {
10 + Sequence.call(this, options, callback);
11 +
12 + options = options || {};
13 +
14 + this._config = options.config;
15 + this._handshakeInitializationPacket = null;
16 +}
17 +
18 +Handshake.prototype.determinePacket = function determinePacket(firstByte, parser) {
19 + if (firstByte === 0xff) {
20 + return Packets.ErrorPacket;
21 + }
22 +
23 + if (!this._handshakeInitializationPacket) {
24 + return Packets.HandshakeInitializationPacket;
25 + }
26 +
27 + if (firstByte === 0xfe) {
28 + return (parser.packetLength() === 1)
29 + ? Packets.UseOldPasswordPacket
30 + : Packets.AuthSwitchRequestPacket;
31 + }
32 +
33 + return undefined;
34 +};
35 +
36 +Handshake.prototype['AuthSwitchRequestPacket'] = function (packet) {
37 + var name = packet.authMethodName;
38 + var data = Auth.auth(name, packet.authMethodData, {
39 + password: this._config.password
40 + });
41 +
42 + if (data !== undefined) {
43 + this.emit('packet', new Packets.AuthSwitchResponsePacket({
44 + data: data
45 + }));
46 + } else {
47 + var err = new Error('MySQL is requesting the ' + name + ' authentication method, which is not supported.');
48 + err.code = 'UNSUPPORTED_AUTH_METHOD';
49 + err.fatal = true;
50 + this.end(err);
51 + }
52 +};
53 +
54 +Handshake.prototype['HandshakeInitializationPacket'] = function(packet) {
55 + this._handshakeInitializationPacket = packet;
56 +
57 + this._config.protocol41 = packet.protocol41;
58 +
59 + var serverSSLSupport = packet.serverCapabilities1 & ClientConstants.CLIENT_SSL;
60 +
61 + if (this._config.ssl) {
62 + if (!serverSSLSupport) {
63 + var err = new Error('Server does not support secure connection');
64 +
65 + err.code = 'HANDSHAKE_NO_SSL_SUPPORT';
66 + err.fatal = true;
67 +
68 + this.end(err);
69 + return;
70 + }
71 +
72 + this._config.clientFlags |= ClientConstants.CLIENT_SSL;
73 + this.emit('packet', new Packets.SSLRequestPacket({
74 + clientFlags : this._config.clientFlags,
75 + maxPacketSize : this._config.maxPacketSize,
76 + charsetNumber : this._config.charsetNumber
77 + }));
78 + this.emit('start-tls');
79 + } else {
80 + this._sendCredentials();
81 + }
82 +};
83 +
84 +Handshake.prototype._tlsUpgradeCompleteHandler = function() {
85 + this._sendCredentials();
86 +};
87 +
88 +Handshake.prototype._sendCredentials = function() {
89 + var packet = this._handshakeInitializationPacket;
90 + this.emit('packet', new Packets.ClientAuthenticationPacket({
91 + clientFlags : this._config.clientFlags,
92 + maxPacketSize : this._config.maxPacketSize,
93 + charsetNumber : this._config.charsetNumber,
94 + user : this._config.user,
95 + database : this._config.database,
96 + protocol41 : packet.protocol41,
97 + scrambleBuff : (packet.protocol41)
98 + ? Auth.token(this._config.password, packet.scrambleBuff())
99 + : Auth.scramble323(packet.scrambleBuff(), this._config.password)
100 + }));
101 +};
102 +
103 +Handshake.prototype['UseOldPasswordPacket'] = function() {
104 + if (!this._config.insecureAuth) {
105 + var err = new Error(
106 + 'MySQL server is requesting the old and insecure pre-4.1 auth mechanism. ' +
107 + 'Upgrade the user password or use the {insecureAuth: true} option.'
108 + );
109 +
110 + err.code = 'HANDSHAKE_INSECURE_AUTH';
111 + err.fatal = true;
112 +
113 + this.end(err);
114 + return;
115 + }
116 +
117 + this.emit('packet', new Packets.OldPasswordPacket({
118 + scrambleBuff: Auth.scramble323(this._handshakeInitializationPacket.scrambleBuff(), this._config.password)
119 + }));
120 +};
121 +
122 +Handshake.prototype['ErrorPacket'] = function(packet) {
123 + var err = this._packetToError(packet, true);
124 + err.fatal = true;
125 + this.end(err);
126 +};
1 +var Sequence = require('./Sequence');
2 +var Util = require('util');
3 +var Packets = require('../packets');
4 +
5 +module.exports = Ping;
6 +Util.inherits(Ping, Sequence);
7 +
8 +function Ping(options, callback) {
9 + if (!callback && typeof options === 'function') {
10 + callback = options;
11 + options = {};
12 + }
13 +
14 + Sequence.call(this, options, callback);
15 +}
16 +
17 +Ping.prototype.start = function() {
18 + this.emit('packet', new Packets.ComPingPacket());
19 +};
1 +var ClientConstants = require('../constants/client');
2 +var fs = require('fs');
3 +var Packets = require('../packets');
4 +var ResultSet = require('../ResultSet');
5 +var Sequence = require('./Sequence');
6 +var ServerStatus = require('../constants/server_status');
7 +var Readable = require('readable-stream');
8 +var Util = require('util');
9 +
10 +module.exports = Query;
11 +Util.inherits(Query, Sequence);
12 +function Query(options, callback) {
13 + Sequence.call(this, options, callback);
14 +
15 + this.sql = options.sql;
16 + this.values = options.values;
17 + this.typeCast = (options.typeCast === undefined)
18 + ? true
19 + : options.typeCast;
20 + this.nestTables = options.nestTables || false;
21 +
22 + this._resultSet = null;
23 + this._results = [];
24 + this._fields = [];
25 + this._index = 0;
26 + this._loadError = null;
27 +}
28 +
29 +Query.prototype.start = function() {
30 + this.emit('packet', new Packets.ComQueryPacket(this.sql));
31 +};
32 +
33 +Query.prototype.determinePacket = function determinePacket(byte, parser) {
34 + var resultSet = this._resultSet;
35 +
36 + if (!resultSet) {
37 + switch (byte) {
38 + case 0x00: return Packets.OkPacket;
39 + case 0xfb: return Packets.LocalInfileRequestPacket;
40 + case 0xff: return Packets.ErrorPacket;
41 + default: return Packets.ResultSetHeaderPacket;
42 + }
43 + }
44 +
45 + if (resultSet.eofPackets.length === 0) {
46 + return (resultSet.fieldPackets.length < resultSet.resultSetHeaderPacket.fieldCount)
47 + ? Packets.FieldPacket
48 + : Packets.EofPacket;
49 + }
50 +
51 + if (byte === 0xff) {
52 + return Packets.ErrorPacket;
53 + }
54 +
55 + if (byte === 0xfe && parser.packetLength() < 9) {
56 + return Packets.EofPacket;
57 + }
58 +
59 + return Packets.RowDataPacket;
60 +};
61 +
62 +Query.prototype['OkPacket'] = function(packet) {
63 + // try...finally for exception safety
64 + try {
65 + if (!this._callback) {
66 + this.emit('result', packet, this._index);
67 + } else {
68 + this._results.push(packet);
69 + this._fields.push(undefined);
70 + }
71 + } finally {
72 + this._index++;
73 + this._resultSet = null;
74 + this._handleFinalResultPacket(packet);
75 + }
76 +};
77 +
78 +Query.prototype['ErrorPacket'] = function(packet) {
79 + var err = this._packetToError(packet);
80 +
81 + var results = (this._results.length > 0)
82 + ? this._results
83 + : undefined;
84 +
85 + var fields = (this._fields.length > 0)
86 + ? this._fields
87 + : undefined;
88 +
89 + err.index = this._index;
90 + err.sql = this.sql;
91 +
92 + this.end(err, results, fields);
93 +};
94 +
95 +Query.prototype['LocalInfileRequestPacket'] = function(packet) {
96 + if (this._connection.config.clientFlags & ClientConstants.CLIENT_LOCAL_FILES) {
97 + this._sendLocalDataFile(packet.filename);
98 + } else {
99 + this._loadError = new Error('Load local files command is disabled');
100 + this._loadError.code = 'LOCAL_FILES_DISABLED';
101 + this._loadError.fatal = false;
102 +
103 + this.emit('packet', new Packets.EmptyPacket());
104 + }
105 +};
106 +
107 +Query.prototype['ResultSetHeaderPacket'] = function(packet) {
108 + this._resultSet = new ResultSet(packet);
109 +};
110 +
111 +Query.prototype['FieldPacket'] = function(packet) {
112 + this._resultSet.fieldPackets.push(packet);
113 +};
114 +
115 +Query.prototype['EofPacket'] = function(packet) {
116 + this._resultSet.eofPackets.push(packet);
117 +
118 + if (this._resultSet.eofPackets.length === 1 && !this._callback) {
119 + this.emit('fields', this._resultSet.fieldPackets, this._index);
120 + }
121 +
122 + if (this._resultSet.eofPackets.length !== 2) {
123 + return;
124 + }
125 +
126 + if (this._callback) {
127 + this._results.push(this._resultSet.rows);
128 + this._fields.push(this._resultSet.fieldPackets);
129 + }
130 +
131 + this._index++;
132 + this._resultSet = null;
133 + this._handleFinalResultPacket(packet);
134 +};
135 +
136 +Query.prototype._handleFinalResultPacket = function(packet) {
137 + if (packet.serverStatus & ServerStatus.SERVER_MORE_RESULTS_EXISTS) {
138 + return;
139 + }
140 +
141 + var results = (this._results.length > 1)
142 + ? this._results
143 + : this._results[0];
144 +
145 + var fields = (this._fields.length > 1)
146 + ? this._fields
147 + : this._fields[0];
148 +
149 + this.end(this._loadError, results, fields);
150 +};
151 +
152 +Query.prototype['RowDataPacket'] = function(packet, parser, connection) {
153 + packet.parse(parser, this._resultSet.fieldPackets, this.typeCast, this.nestTables, connection);
154 +
155 + if (this._callback) {
156 + this._resultSet.rows.push(packet);
157 + } else {
158 + this.emit('result', packet, this._index);
159 + }
160 +};
161 +
162 +Query.prototype._sendLocalDataFile = function(path) {
163 + var self = this;
164 + var localStream = fs.createReadStream(path, {
165 + flag : 'r',
166 + encoding : null,
167 + autoClose : true
168 + });
169 +
170 + this.on('pause', function () {
171 + localStream.pause();
172 + });
173 +
174 + this.on('resume', function () {
175 + localStream.resume();
176 + });
177 +
178 + localStream.on('data', function (data) {
179 + self.emit('packet', new Packets.LocalDataFilePacket(data));
180 + });
181 +
182 + localStream.on('error', function (err) {
183 + self._loadError = err;
184 + localStream.emit('end');
185 + });
186 +
187 + localStream.on('end', function () {
188 + self.emit('packet', new Packets.EmptyPacket());
189 + });
190 +};
191 +
192 +Query.prototype.stream = function(options) {
193 + var self = this;
194 +
195 + options = options || {};
196 + options.objectMode = true;
197 +
198 + var stream = new Readable(options);
199 +
200 + stream._read = function() {
201 + self._connection && self._connection.resume();
202 + };
203 +
204 + stream.once('end', function() {
205 + process.nextTick(function () {
206 + stream.emit('close');
207 + });
208 + });
209 +
210 + this.on('result', function(row, i) {
211 + if (!stream.push(row)) self._connection.pause();
212 + stream.emit('result', row, i); // replicate old emitter
213 + });
214 +
215 + this.on('error', function(err) {
216 + stream.emit('error', err); // Pass on any errors
217 + });
218 +
219 + this.on('end', function() {
220 + stream.push(null); // pushing null, indicating EOF
221 + });
222 +
223 + this.on('fields', function(fields, i) {
224 + stream.emit('fields', fields, i); // replicate old emitter
225 + });
226 +
227 + return stream;
228 +};
1 +var Sequence = require('./Sequence');
2 +var Util = require('util');
3 +var Packets = require('../packets');
4 +
5 +module.exports = Quit;
6 +Util.inherits(Quit, Sequence);
7 +function Quit(options, callback) {
8 + if (!callback && typeof options === 'function') {
9 + callback = options;
10 + options = {};
11 + }
12 +
13 + Sequence.call(this, options, callback);
14 +
15 + this._started = false;
16 +}
17 +
18 +Quit.prototype.end = function end(err) {
19 + if (this._ended) {
20 + return;
21 + }
22 +
23 + if (!this._started) {
24 + Sequence.prototype.end.call(this, err);
25 + return;
26 + }
27 +
28 + if (err && err.code === 'ECONNRESET' && err.syscall === 'read') {
29 + // Ignore read errors after packet sent
30 + Sequence.prototype.end.call(this);
31 + return;
32 + }
33 +
34 + Sequence.prototype.end.call(this, err);
35 +};
36 +
37 +Quit.prototype.start = function() {
38 + this._started = true;
39 + this.emit('packet', new Packets.ComQuitPacket());
40 +};
1 +var Util = require('util');
2 +var EventEmitter = require('events').EventEmitter;
3 +var Packets = require('../packets');
4 +var ErrorConstants = require('../constants/errors');
5 +var Timer = require('../Timer');
6 +
7 +// istanbul ignore next: Node.js < 0.10 not covered
8 +var listenerCount = EventEmitter.listenerCount
9 + || function(emitter, type){ return emitter.listeners(type).length; };
10 +
11 +var LONG_STACK_DELIMITER = '\n --------------------\n';
12 +
13 +module.exports = Sequence;
14 +Util.inherits(Sequence, EventEmitter);
15 +function Sequence(options, callback) {
16 + if (typeof options === 'function') {
17 + callback = options;
18 + options = {};
19 + }
20 +
21 + EventEmitter.call(this);
22 +
23 + options = options || {};
24 +
25 + this._callback = callback;
26 + this._callSite = null;
27 + this._ended = false;
28 + this._timeout = options.timeout;
29 + this._timer = new Timer(this);
30 +}
31 +
32 +Sequence.determinePacket = function(byte) {
33 + switch (byte) {
34 + case 0x00: return Packets.OkPacket;
35 + case 0xfe: return Packets.EofPacket;
36 + case 0xff: return Packets.ErrorPacket;
37 + default: return undefined;
38 + }
39 +};
40 +
41 +Sequence.prototype.hasErrorHandler = function() {
42 + return Boolean(this._callback) || listenerCount(this, 'error') > 1;
43 +};
44 +
45 +Sequence.prototype._packetToError = function(packet) {
46 + var code = ErrorConstants[packet.errno] || 'UNKNOWN_CODE_PLEASE_REPORT';
47 + var err = new Error(code + ': ' + packet.message);
48 + err.code = code;
49 + err.errno = packet.errno;
50 +
51 + err.sqlMessage = packet.message;
52 + err.sqlState = packet.sqlState;
53 +
54 + return err;
55 +};
56 +
57 +Sequence.prototype.end = function(err) {
58 + if (this._ended) {
59 + return;
60 + }
61 +
62 + this._ended = true;
63 +
64 + if (err) {
65 + this._addLongStackTrace(err);
66 + }
67 +
68 + // Without this we are leaking memory. This problem was introduced in
69 + // 8189925374e7ce3819bbe88b64c7b15abac96b16. I suspect that the error object
70 + // causes a cyclic reference that the GC does not detect properly, but I was
71 + // unable to produce a standalone version of this leak. This would be a great
72 + // challenge for somebody interested in difficult problems : )!
73 + this._callSite = null;
74 +
75 + // try...finally for exception safety
76 + try {
77 + if (err) {
78 + this.emit('error', err);
79 + }
80 + } finally {
81 + try {
82 + if (this._callback) {
83 + this._callback.apply(this, arguments);
84 + }
85 + } finally {
86 + this.emit('end');
87 + }
88 + }
89 +};
90 +
91 +Sequence.prototype['OkPacket'] = function(packet) {
92 + this.end(null, packet);
93 +};
94 +
95 +Sequence.prototype['ErrorPacket'] = function(packet) {
96 + this.end(this._packetToError(packet));
97 +};
98 +
99 +// Implemented by child classes
100 +Sequence.prototype.start = function() {};
101 +
102 +Sequence.prototype._addLongStackTrace = function _addLongStackTrace(err) {
103 + var callSiteStack = this._callSite && this._callSite.stack;
104 +
105 + if (!callSiteStack || typeof callSiteStack !== 'string') {
106 + // No recorded call site
107 + return;
108 + }
109 +
110 + if (err.stack.indexOf(LONG_STACK_DELIMITER) !== -1) {
111 + // Error stack already looks long
112 + return;
113 + }
114 +
115 + var index = callSiteStack.indexOf('\n');
116 +
117 + if (index !== -1) {
118 + // Append recorded call site
119 + err.stack += LONG_STACK_DELIMITER + callSiteStack.substr(index + 1);
120 + }
121 +};
122 +
123 +Sequence.prototype._onTimeout = function _onTimeout() {
124 + this.emit('timeout');
125 +};
1 +var Sequence = require('./Sequence');
2 +var Util = require('util');
3 +var Packets = require('../packets');
4 +
5 +module.exports = Statistics;
6 +Util.inherits(Statistics, Sequence);
7 +function Statistics(options, callback) {
8 + if (!callback && typeof options === 'function') {
9 + callback = options;
10 + options = {};
11 + }
12 +
13 + Sequence.call(this, options, callback);
14 +}
15 +
16 +Statistics.prototype.start = function() {
17 + this.emit('packet', new Packets.ComStatisticsPacket());
18 +};
19 +
20 +Statistics.prototype['StatisticsPacket'] = function (packet) {
21 + this.end(null, packet);
22 +};
23 +
24 +Statistics.prototype.determinePacket = function determinePacket(firstByte) {
25 + if (firstByte === 0x55) {
26 + return Packets.StatisticsPacket;
27 + }
28 +
29 + return undefined;
30 +};
1 +exports.ChangeUser = require('./ChangeUser');
2 +exports.Handshake = require('./Handshake');
3 +exports.Ping = require('./Ping');
4 +exports.Query = require('./Query');
5 +exports.Quit = require('./Quit');
6 +exports.Sequence = require('./Sequence');
7 +exports.Statistics = require('./Statistics');
1 +{
2 + "_from": "mysql",
3 + "_id": "mysql@2.18.1",
4 + "_inBundle": false,
5 + "_integrity": "sha512-Bca+gk2YWmqp2Uf6k5NFEurwY/0td0cpebAucFpY/3jhrwrVGuxU2uQFCHjU19SJfje0yQvi+rVWdq78hR5lig==",
6 + "_location": "/mysql",
7 + "_phantomChildren": {},
8 + "_requested": {
9 + "type": "tag",
10 + "registry": true,
11 + "raw": "mysql",
12 + "name": "mysql",
13 + "escapedName": "mysql",
14 + "rawSpec": "",
15 + "saveSpec": null,
16 + "fetchSpec": "latest"
17 + },
18 + "_requiredBy": [
19 + "#USER",
20 + "/"
21 + ],
22 + "_resolved": "https://registry.npmjs.org/mysql/-/mysql-2.18.1.tgz",
23 + "_shasum": "2254143855c5a8c73825e4522baf2ea021766717",
24 + "_spec": "mysql",
25 + "_where": "C:\\Users\\user\\Desktop\\Singer-Composer",
26 + "author": {
27 + "name": "Felix Geisendörfer",
28 + "email": "felix@debuggable.com",
29 + "url": "http://debuggable.com/"
30 + },
31 + "bugs": {
32 + "url": "https://github.com/mysqljs/mysql/issues"
33 + },
34 + "bundleDependencies": false,
35 + "contributors": [
36 + {
37 + "name": "Andrey Sidorov",
38 + "email": "sidorares@yandex.ru"
39 + },
40 + {
41 + "name": "Bradley Grainger",
42 + "email": "bgrainger@gmail.com"
43 + },
44 + {
45 + "name": "Douglas Christopher Wilson",
46 + "email": "doug@somethingdoug.com"
47 + },
48 + {
49 + "name": "Diogo Resende",
50 + "email": "dresende@thinkdigital.pt"
51 + },
52 + {
53 + "name": "Nathan Woltman",
54 + "email": "nwoltman@outlook.com"
55 + }
56 + ],
57 + "dependencies": {
58 + "bignumber.js": "9.0.0",
59 + "readable-stream": "2.3.7",
60 + "safe-buffer": "5.1.2",
61 + "sqlstring": "2.3.1"
62 + },
63 + "deprecated": false,
64 + "description": "A node.js driver for mysql. It is written in JavaScript, does not require compiling, and is 100% MIT licensed.",
65 + "devDependencies": {
66 + "after": "0.8.2",
67 + "eslint": "5.16.0",
68 + "seedrandom": "3.0.5",
69 + "timezone-mock": "0.0.7",
70 + "urun": "0.0.8",
71 + "utest": "0.0.8"
72 + },
73 + "engines": {
74 + "node": ">= 0.6"
75 + },
76 + "files": [
77 + "lib/",
78 + "Changes.md",
79 + "License",
80 + "Readme.md",
81 + "index.js"
82 + ],
83 + "homepage": "https://github.com/mysqljs/mysql#readme",
84 + "license": "MIT",
85 + "name": "mysql",
86 + "repository": {
87 + "type": "git",
88 + "url": "git+https://github.com/mysqljs/mysql.git"
89 + },
90 + "scripts": {
91 + "lint": "eslint . && node tool/lint-readme.js",
92 + "test": "node test/run.js",
93 + "test-ci": "node tool/install-nyc.js --nyc-optional --reporter=text -- npm test",
94 + "test-cov": "node tool/install-nyc.js --reporter=html --reporter=text -- npm test",
95 + "version": "node tool/version-changes.js && git add Changes.md"
96 + },
97 + "version": "2.18.1"
98 +}
1 +'use strict';
2 +
3 +if (typeof process === 'undefined' ||
4 + !process.version ||
5 + process.version.indexOf('v0.') === 0 ||
6 + process.version.indexOf('v1.') === 0 && process.version.indexOf('v1.8.') !== 0) {
7 + module.exports = { nextTick: nextTick };
8 +} else {
9 + module.exports = process
10 +}
11 +
12 +function nextTick(fn, arg1, arg2, arg3) {
13 + if (typeof fn !== 'function') {
14 + throw new TypeError('"callback" argument must be a function');
15 + }
16 + var len = arguments.length;
17 + var args, i;
18 + switch (len) {
19 + case 0:
20 + case 1:
21 + return process.nextTick(fn);
22 + case 2:
23 + return process.nextTick(function afterTickOne() {
24 + fn.call(null, arg1);
25 + });
26 + case 3:
27 + return process.nextTick(function afterTickTwo() {
28 + fn.call(null, arg1, arg2);
29 + });
30 + case 4:
31 + return process.nextTick(function afterTickThree() {
32 + fn.call(null, arg1, arg2, arg3);
33 + });
34 + default:
35 + args = new Array(len - 1);
36 + i = 0;
37 + while (i < args.length) {
38 + args[i++] = arguments[i];
39 + }
40 + return process.nextTick(function afterTick() {
41 + fn.apply(null, args);
42 + });
43 + }
44 +}
45 +
1 +# Copyright (c) 2015 Calvin Metcalf
2 +
3 +Permission is hereby granted, free of charge, to any person obtaining a copy
4 +of this software and associated documentation files (the "Software"), to deal
5 +in the Software without restriction, including without limitation the rights
6 +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 +copies of the Software, and to permit persons to whom the Software is
8 +furnished to do so, subject to the following conditions:
9 +
10 +The above copyright notice and this permission notice shall be included in all
11 +copies or substantial portions of the Software.
12 +
13 +**THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 +SOFTWARE.**
1 +{
2 + "_from": "process-nextick-args@~2.0.0",
3 + "_id": "process-nextick-args@2.0.1",
4 + "_inBundle": false,
5 + "_integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==",
6 + "_location": "/process-nextick-args",
7 + "_phantomChildren": {},
8 + "_requested": {
9 + "type": "range",
10 + "registry": true,
11 + "raw": "process-nextick-args@~2.0.0",
12 + "name": "process-nextick-args",
13 + "escapedName": "process-nextick-args",
14 + "rawSpec": "~2.0.0",
15 + "saveSpec": null,
16 + "fetchSpec": "~2.0.0"
17 + },
18 + "_requiredBy": [
19 + "/readable-stream"
20 + ],
21 + "_resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz",
22 + "_shasum": "7820d9b16120cc55ca9ae7792680ae7dba6d7fe2",
23 + "_spec": "process-nextick-args@~2.0.0",
24 + "_where": "C:\\Users\\user\\Desktop\\Singer-Composer\\node_modules\\readable-stream",
25 + "author": "",
26 + "bugs": {
27 + "url": "https://github.com/calvinmetcalf/process-nextick-args/issues"
28 + },
29 + "bundleDependencies": false,
30 + "deprecated": false,
31 + "description": "process.nextTick but always with args",
32 + "devDependencies": {
33 + "tap": "~0.2.6"
34 + },
35 + "files": [
36 + "index.js"
37 + ],
38 + "homepage": "https://github.com/calvinmetcalf/process-nextick-args",
39 + "license": "MIT",
40 + "main": "index.js",
41 + "name": "process-nextick-args",
42 + "repository": {
43 + "type": "git",
44 + "url": "git+https://github.com/calvinmetcalf/process-nextick-args.git"
45 + },
46 + "scripts": {
47 + "test": "node test.js"
48 + },
49 + "version": "2.0.1"
50 +}
1 +process-nextick-args
2 +=====
3 +
4 +[![Build Status](https://travis-ci.org/calvinmetcalf/process-nextick-args.svg?branch=master)](https://travis-ci.org/calvinmetcalf/process-nextick-args)
5 +
6 +```bash
7 +npm install --save process-nextick-args
8 +```
9 +
10 +Always be able to pass arguments to process.nextTick, no matter the platform
11 +
12 +```js
13 +var pna = require('process-nextick-args');
14 +
15 +pna.nextTick(function (a, b, c) {
16 + console.log(a, b, c);
17 +}, 'step', 3, 'profit');
18 +```
1 +sudo: false
2 +language: node_js
3 +before_install:
4 + - (test $NPM_LEGACY && npm install -g npm@2 && npm install -g npm@3) || true
5 +notifications:
6 + email: false
7 +matrix:
8 + fast_finish: true
9 + include:
10 + - node_js: '0.8'
11 + env: NPM_LEGACY=true
12 + - node_js: '0.10'
13 + env: NPM_LEGACY=true
14 + - node_js: '0.11'
15 + env: NPM_LEGACY=true
16 + - node_js: '0.12'
17 + env: NPM_LEGACY=true
18 + - node_js: 1
19 + env: NPM_LEGACY=true
20 + - node_js: 2
21 + env: NPM_LEGACY=true
22 + - node_js: 3
23 + env: NPM_LEGACY=true
24 + - node_js: 4
25 + - node_js: 5
26 + - node_js: 6
27 + - node_js: 7
28 + - node_js: 8
29 + - node_js: 9
30 +script: "npm run test"
31 +env:
32 + global:
33 + - secure: rE2Vvo7vnjabYNULNyLFxOyt98BoJexDqsiOnfiD6kLYYsiQGfr/sbZkPMOFm9qfQG7pjqx+zZWZjGSswhTt+626C0t/njXqug7Yps4c3dFblzGfreQHp7wNX5TFsvrxd6dAowVasMp61sJcRnB2w8cUzoe3RAYUDHyiHktwqMc=
34 + - secure: g9YINaKAdMatsJ28G9jCGbSaguXCyxSTy+pBO6Ch0Cf57ZLOTka3HqDj8p3nV28LUIHZ3ut5WO43CeYKwt4AUtLpBS3a0dndHdY6D83uY6b2qh5hXlrcbeQTq2cvw2y95F7hm4D1kwrgZ7ViqaKggRcEupAL69YbJnxeUDKWEdI=
1 +# Developer's Certificate of Origin 1.1
2 +
3 +By making a contribution to this project, I certify that:
4 +
5 +* (a) The contribution was created in whole or in part by me and I
6 + have the right to submit it under the open source license
7 + indicated in the file; or
8 +
9 +* (b) The contribution is based upon previous work that, to the best
10 + of my knowledge, is covered under an appropriate open source
11 + license and I have the right under that license to submit that
12 + work with modifications, whether created in whole or in part
13 + by me, under the same open source license (unless I am
14 + permitted to submit under a different license), as indicated
15 + in the file; or
16 +
17 +* (c) The contribution was provided directly to me by some other
18 + person who certified (a), (b) or (c) and I have not modified
19 + it.
20 +
21 +* (d) I understand and agree that this project and the contribution
22 + are public and that a record of the contribution (including all
23 + personal information I submit with it, including my sign-off) is
24 + maintained indefinitely and may be redistributed consistent with
25 + this project or the open source license(s) involved.
26 +
27 +## Moderation Policy
28 +
29 +The [Node.js Moderation Policy] applies to this WG.
30 +
31 +## Code of Conduct
32 +
33 +The [Node.js Code of Conduct][] applies to this WG.
34 +
35 +[Node.js Code of Conduct]:
36 +https://github.com/nodejs/node/blob/master/CODE_OF_CONDUCT.md
37 +[Node.js Moderation Policy]:
38 +https://github.com/nodejs/TSC/blob/master/Moderation-Policy.md
1 +### Streams Working Group
2 +
3 +The Node.js Streams is jointly governed by a Working Group
4 +(WG)
5 +that is responsible for high-level guidance of the project.
6 +
7 +The WG has final authority over this project including:
8 +
9 +* Technical direction
10 +* Project governance and process (including this policy)
11 +* Contribution policy
12 +* GitHub repository hosting
13 +* Conduct guidelines
14 +* Maintaining the list of additional Collaborators
15 +
16 +For the current list of WG members, see the project
17 +[README.md](./README.md#current-project-team-members).
18 +
19 +### Collaborators
20 +
21 +The readable-stream GitHub repository is
22 +maintained by the WG and additional Collaborators who are added by the
23 +WG on an ongoing basis.
24 +
25 +Individuals making significant and valuable contributions are made
26 +Collaborators and given commit-access to the project. These
27 +individuals are identified by the WG and their addition as
28 +Collaborators is discussed during the WG meeting.
29 +
30 +_Note:_ If you make a significant contribution and are not considered
31 +for commit-access log an issue or contact a WG member directly and it
32 +will be brought up in the next WG meeting.
33 +
34 +Modifications of the contents of the readable-stream repository are
35 +made on
36 +a collaborative basis. Anybody with a GitHub account may propose a
37 +modification via pull request and it will be considered by the project
38 +Collaborators. All pull requests must be reviewed and accepted by a
39 +Collaborator with sufficient expertise who is able to take full
40 +responsibility for the change. In the case of pull requests proposed
41 +by an existing Collaborator, an additional Collaborator is required
42 +for sign-off. Consensus should be sought if additional Collaborators
43 +participate and there is disagreement around a particular
44 +modification. See _Consensus Seeking Process_ below for further detail
45 +on the consensus model used for governance.
46 +
47 +Collaborators may opt to elevate significant or controversial
48 +modifications, or modifications that have not found consensus to the
49 +WG for discussion by assigning the ***WG-agenda*** tag to a pull
50 +request or issue. The WG should serve as the final arbiter where
51 +required.
52 +
53 +For the current list of Collaborators, see the project
54 +[README.md](./README.md#members).
55 +
56 +### WG Membership
57 +
58 +WG seats are not time-limited. There is no fixed size of the WG.
59 +However, the expected target is between 6 and 12, to ensure adequate
60 +coverage of important areas of expertise, balanced with the ability to
61 +make decisions efficiently.
62 +
63 +There is no specific set of requirements or qualifications for WG
64 +membership beyond these rules.
65 +
66 +The WG may add additional members to the WG by unanimous consensus.
67 +
68 +A WG member may be removed from the WG by voluntary resignation, or by
69 +unanimous consensus of all other WG members.
70 +
71 +Changes to WG membership should be posted in the agenda, and may be
72 +suggested as any other agenda item (see "WG Meetings" below).
73 +
74 +If an addition or removal is proposed during a meeting, and the full
75 +WG is not in attendance to participate, then the addition or removal
76 +is added to the agenda for the subsequent meeting. This is to ensure
77 +that all members are given the opportunity to participate in all
78 +membership decisions. If a WG member is unable to attend a meeting
79 +where a planned membership decision is being made, then their consent
80 +is assumed.
81 +
82 +No more than 1/3 of the WG members may be affiliated with the same
83 +employer. If removal or resignation of a WG member, or a change of
84 +employment by a WG member, creates a situation where more than 1/3 of
85 +the WG membership shares an employer, then the situation must be
86 +immediately remedied by the resignation or removal of one or more WG
87 +members affiliated with the over-represented employer(s).
88 +
89 +### WG Meetings
90 +
91 +The WG meets occasionally on a Google Hangout On Air. A designated moderator
92 +approved by the WG runs the meeting. Each meeting should be
93 +published to YouTube.
94 +
95 +Items are added to the WG agenda that are considered contentious or
96 +are modifications of governance, contribution policy, WG membership,
97 +or release process.
98 +
99 +The intention of the agenda is not to approve or review all patches;
100 +that should happen continuously on GitHub and be handled by the larger
101 +group of Collaborators.
102 +
103 +Any community member or contributor can ask that something be added to
104 +the next meeting's agenda by logging a GitHub Issue. Any Collaborator,
105 +WG member or the moderator can add the item to the agenda by adding
106 +the ***WG-agenda*** tag to the issue.
107 +
108 +Prior to each WG meeting the moderator will share the Agenda with
109 +members of the WG. WG members can add any items they like to the
110 +agenda at the beginning of each meeting. The moderator and the WG
111 +cannot veto or remove items.
112 +
113 +The WG may invite persons or representatives from certain projects to
114 +participate in a non-voting capacity.
115 +
116 +The moderator is responsible for summarizing the discussion of each
117 +agenda item and sends it as a pull request after the meeting.
118 +
119 +### Consensus Seeking Process
120 +
121 +The WG follows a
122 +[Consensus
123 +Seeking](http://en.wikipedia.org/wiki/Consensus-seeking_decision-making)
124 +decision-making model.
125 +
126 +When an agenda item has appeared to reach a consensus the moderator
127 +will ask "Does anyone object?" as a final call for dissent from the
128 +consensus.
129 +
130 +If an agenda item cannot reach a consensus a WG member can call for
131 +either a closing vote or a vote to table the issue to the next
132 +meeting. The call for a vote must be seconded by a majority of the WG
133 +or else the discussion will continue. Simple majority wins.
134 +
135 +Note that changes to WG membership require a majority consensus. See
136 +"WG Membership" above.
1 +Node.js is licensed for use as follows:
2 +
3 +"""
4 +Copyright Node.js contributors. All rights reserved.
5 +
6 +Permission is hereby granted, free of charge, to any person obtaining a copy
7 +of this software and associated documentation files (the "Software"), to
8 +deal in the Software without restriction, including without limitation the
9 +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 +sell copies of the Software, and to permit persons to whom the Software is
11 +furnished to do so, subject to the following conditions:
12 +
13 +The above copyright notice and this permission notice shall be included in
14 +all copies or substantial portions of the Software.
15 +
16 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 +IN THE SOFTWARE.
23 +"""
24 +
25 +This license applies to parts of Node.js originating from the
26 +https://github.com/joyent/node repository:
27 +
28 +"""
29 +Copyright Joyent, Inc. and other Node contributors. All rights reserved.
30 +Permission is hereby granted, free of charge, to any person obtaining a copy
31 +of this software and associated documentation files (the "Software"), to
32 +deal in the Software without restriction, including without limitation the
33 +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
34 +sell copies of the Software, and to permit persons to whom the Software is
35 +furnished to do so, subject to the following conditions:
36 +
37 +The above copyright notice and this permission notice shall be included in
38 +all copies or substantial portions of the Software.
39 +
40 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
41 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
42 +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
43 +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
44 +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
45 +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
46 +IN THE SOFTWARE.
47 +"""
1 +# readable-stream
2 +
3 +***Node-core v8.11.1 streams for userland*** [![Build Status](https://travis-ci.org/nodejs/readable-stream.svg?branch=master)](https://travis-ci.org/nodejs/readable-stream)
4 +
5 +
6 +[![NPM](https://nodei.co/npm/readable-stream.png?downloads=true&downloadRank=true)](https://nodei.co/npm/readable-stream/)
7 +[![NPM](https://nodei.co/npm-dl/readable-stream.png?&months=6&height=3)](https://nodei.co/npm/readable-stream/)
8 +
9 +
10 +[![Sauce Test Status](https://saucelabs.com/browser-matrix/readable-stream.svg)](https://saucelabs.com/u/readable-stream)
11 +
12 +```bash
13 +npm install --save readable-stream
14 +```
15 +
16 +***Node-core streams for userland***
17 +
18 +This package is a mirror of the Streams2 and Streams3 implementations in
19 +Node-core.
20 +
21 +Full documentation may be found on the [Node.js website](https://nodejs.org/dist/v8.11.1/docs/api/stream.html).
22 +
23 +If you want to guarantee a stable streams base, regardless of what version of
24 +Node you, or the users of your libraries are using, use **readable-stream** *only* and avoid the *"stream"* module in Node-core, for background see [this blogpost](http://r.va.gg/2014/06/why-i-dont-use-nodes-core-stream-module.html).
25 +
26 +As of version 2.0.0 **readable-stream** uses semantic versioning.
27 +
28 +# Streams Working Group
29 +
30 +`readable-stream` is maintained by the Streams Working Group, which
31 +oversees the development and maintenance of the Streams API within
32 +Node.js. The responsibilities of the Streams Working Group include:
33 +
34 +* Addressing stream issues on the Node.js issue tracker.
35 +* Authoring and editing stream documentation within the Node.js project.
36 +* Reviewing changes to stream subclasses within the Node.js project.
37 +* Redirecting changes to streams from the Node.js project to this
38 + project.
39 +* Assisting in the implementation of stream providers within Node.js.
40 +* Recommending versions of `readable-stream` to be included in Node.js.
41 +* Messaging about the future of streams to give the community advance
42 + notice of changes.
43 +
44 +<a name="members"></a>
45 +## Team Members
46 +
47 +* **Chris Dickinson** ([@chrisdickinson](https://github.com/chrisdickinson)) &lt;christopher.s.dickinson@gmail.com&gt;
48 + - Release GPG key: 9554F04D7259F04124DE6B476D5A82AC7E37093B
49 +* **Calvin Metcalf** ([@calvinmetcalf](https://github.com/calvinmetcalf)) &lt;calvin.metcalf@gmail.com&gt;
50 + - Release GPG key: F3EF5F62A87FC27A22E643F714CE4FF5015AA242
51 +* **Rod Vagg** ([@rvagg](https://github.com/rvagg)) &lt;rod@vagg.org&gt;
52 + - Release GPG key: DD8F2338BAE7501E3DD5AC78C273792F7D83545D
53 +* **Sam Newman** ([@sonewman](https://github.com/sonewman)) &lt;newmansam@outlook.com&gt;
54 +* **Mathias Buus** ([@mafintosh](https://github.com/mafintosh)) &lt;mathiasbuus@gmail.com&gt;
55 +* **Domenic Denicola** ([@domenic](https://github.com/domenic)) &lt;d@domenic.me&gt;
56 +* **Matteo Collina** ([@mcollina](https://github.com/mcollina)) &lt;matteo.collina@gmail.com&gt;
57 + - Release GPG key: 3ABC01543F22DD2239285CDD818674489FBC127E
58 +* **Irina Shestak** ([@lrlna](https://github.com/lrlna)) &lt;shestak.irina@gmail.com&gt;
1 +# streams WG Meeting 2015-01-30
2 +
3 +## Links
4 +
5 +* **Google Hangouts Video**: http://www.youtube.com/watch?v=I9nDOSGfwZg
6 +* **GitHub Issue**: https://github.com/iojs/readable-stream/issues/106
7 +* **Original Minutes Google Doc**: https://docs.google.com/document/d/17aTgLnjMXIrfjgNaTUnHQO7m3xgzHR2VXBTmi03Qii4/
8 +
9 +## Agenda
10 +
11 +Extracted from https://github.com/iojs/readable-stream/labels/wg-agenda prior to meeting.
12 +
13 +* adopt a charter [#105](https://github.com/iojs/readable-stream/issues/105)
14 +* release and versioning strategy [#101](https://github.com/iojs/readable-stream/issues/101)
15 +* simpler stream creation [#102](https://github.com/iojs/readable-stream/issues/102)
16 +* proposal: deprecate implicit flowing of streams [#99](https://github.com/iojs/readable-stream/issues/99)
17 +
18 +## Minutes
19 +
20 +### adopt a charter
21 +
22 +* group: +1's all around
23 +
24 +### What versioning scheme should be adopted?
25 +* group: +1’s 3.0.0
26 +* domenic+group: pulling in patches from other sources where appropriate
27 +* mikeal: version independently, suggesting versions for io.js
28 +* mikeal+domenic: work with TC to notify in advance of changes
29 +simpler stream creation
30 +
31 +### streamline creation of streams
32 +* sam: streamline creation of streams
33 +* domenic: nice simple solution posted
34 + but, we lose the opportunity to change the model
35 + may not be backwards incompatible (double check keys)
36 +
37 + **action item:** domenic will check
38 +
39 +### remove implicit flowing of streams on(‘data’)
40 +* add isFlowing / isPaused
41 +* mikeal: worrying that we’re documenting polyfill methods – confuses users
42 +* domenic: more reflective API is probably good, with warning labels for users
43 +* new section for mad scientists (reflective stream access)
44 +* calvin: name the “third state”
45 +* mikeal: maybe borrow the name from whatwg?
46 +* domenic: we’re missing the “third state”
47 +* consensus: kind of difficult to name the third state
48 +* mikeal: figure out differences in states / compat
49 +* mathias: always flow on data – eliminates third state
50 + * explore what it breaks
51 +
52 +**action items:**
53 +* ask isaac for ability to list packages by what public io.js APIs they use (esp. Stream)
54 +* ask rod/build for infrastructure
55 +* **chris**: explore the “flow on data” approach
56 +* add isPaused/isFlowing
57 +* add new docs section
58 +* move isPaused to that section
59 +
60 +
1 +module.exports = require('./lib/_stream_duplex.js');
1 +module.exports = require('./readable').Duplex
1 +// Copyright Joyent, Inc. and other Node contributors.
2 +//
3 +// Permission is hereby granted, free of charge, to any person obtaining a
4 +// copy of this software and associated documentation files (the
5 +// "Software"), to deal in the Software without restriction, including
6 +// without limitation the rights to use, copy, modify, merge, publish,
7 +// distribute, sublicense, and/or sell copies of the Software, and to permit
8 +// persons to whom the Software is furnished to do so, subject to the
9 +// following conditions:
10 +//
11 +// The above copyright notice and this permission notice shall be included
12 +// in all copies or substantial portions of the Software.
13 +//
14 +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17 +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 +// USE OR OTHER DEALINGS IN THE SOFTWARE.
21 +
22 +// a duplex stream is just a stream that is both readable and writable.
23 +// Since JS doesn't have multiple prototypal inheritance, this class
24 +// prototypally inherits from Readable, and then parasitically from
25 +// Writable.
26 +
27 +'use strict';
28 +
29 +/*<replacement>*/
30 +
31 +var pna = require('process-nextick-args');
32 +/*</replacement>*/
33 +
34 +/*<replacement>*/
35 +var objectKeys = Object.keys || function (obj) {
36 + var keys = [];
37 + for (var key in obj) {
38 + keys.push(key);
39 + }return keys;
40 +};
41 +/*</replacement>*/
42 +
43 +module.exports = Duplex;
44 +
45 +/*<replacement>*/
46 +var util = Object.create(require('core-util-is'));
47 +util.inherits = require('inherits');
48 +/*</replacement>*/
49 +
50 +var Readable = require('./_stream_readable');
51 +var Writable = require('./_stream_writable');
52 +
53 +util.inherits(Duplex, Readable);
54 +
55 +{
56 + // avoid scope creep, the keys array can then be collected
57 + var keys = objectKeys(Writable.prototype);
58 + for (var v = 0; v < keys.length; v++) {
59 + var method = keys[v];
60 + if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
61 + }
62 +}
63 +
64 +function Duplex(options) {
65 + if (!(this instanceof Duplex)) return new Duplex(options);
66 +
67 + Readable.call(this, options);
68 + Writable.call(this, options);
69 +
70 + if (options && options.readable === false) this.readable = false;
71 +
72 + if (options && options.writable === false) this.writable = false;
73 +
74 + this.allowHalfOpen = true;
75 + if (options && options.allowHalfOpen === false) this.allowHalfOpen = false;
76 +
77 + this.once('end', onend);
78 +}
79 +
80 +Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', {
81 + // making it explicit this property is not enumerable
82 + // because otherwise some prototype manipulation in
83 + // userland will fail
84 + enumerable: false,
85 + get: function () {
86 + return this._writableState.highWaterMark;
87 + }
88 +});
89 +
90 +// the no-half-open enforcer
91 +function onend() {
92 + // if we allow half-open state, or if the writable side ended,
93 + // then we're ok.
94 + if (this.allowHalfOpen || this._writableState.ended) return;
95 +
96 + // no more data can be written.
97 + // But allow more writes to happen in this tick.
98 + pna.nextTick(onEndNT, this);
99 +}
100 +
101 +function onEndNT(self) {
102 + self.end();
103 +}
104 +
105 +Object.defineProperty(Duplex.prototype, 'destroyed', {
106 + get: function () {
107 + if (this._readableState === undefined || this._writableState === undefined) {
108 + return false;
109 + }
110 + return this._readableState.destroyed && this._writableState.destroyed;
111 + },
112 + set: function (value) {
113 + // we ignore the value if the stream
114 + // has not been initialized yet
115 + if (this._readableState === undefined || this._writableState === undefined) {
116 + return;
117 + }
118 +
119 + // backward compatibility, the user is explicitly
120 + // managing destroyed
121 + this._readableState.destroyed = value;
122 + this._writableState.destroyed = value;
123 + }
124 +});
125 +
126 +Duplex.prototype._destroy = function (err, cb) {
127 + this.push(null);
128 + this.end();
129 +
130 + pna.nextTick(cb, err);
131 +};
...\ No newline at end of file ...\ No newline at end of file
1 +// Copyright Joyent, Inc. and other Node contributors.
2 +//
3 +// Permission is hereby granted, free of charge, to any person obtaining a
4 +// copy of this software and associated documentation files (the
5 +// "Software"), to deal in the Software without restriction, including
6 +// without limitation the rights to use, copy, modify, merge, publish,
7 +// distribute, sublicense, and/or sell copies of the Software, and to permit
8 +// persons to whom the Software is furnished to do so, subject to the
9 +// following conditions:
10 +//
11 +// The above copyright notice and this permission notice shall be included
12 +// in all copies or substantial portions of the Software.
13 +//
14 +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17 +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 +// USE OR OTHER DEALINGS IN THE SOFTWARE.
21 +
22 +// a passthrough stream.
23 +// basically just the most minimal sort of Transform stream.
24 +// Every written chunk gets output as-is.
25 +
26 +'use strict';
27 +
28 +module.exports = PassThrough;
29 +
30 +var Transform = require('./_stream_transform');
31 +
32 +/*<replacement>*/
33 +var util = Object.create(require('core-util-is'));
34 +util.inherits = require('inherits');
35 +/*</replacement>*/
36 +
37 +util.inherits(PassThrough, Transform);
38 +
39 +function PassThrough(options) {
40 + if (!(this instanceof PassThrough)) return new PassThrough(options);
41 +
42 + Transform.call(this, options);
43 +}
44 +
45 +PassThrough.prototype._transform = function (chunk, encoding, cb) {
46 + cb(null, chunk);
47 +};
...\ No newline at end of file ...\ No newline at end of file
1 +// Copyright Joyent, Inc. and other Node contributors.
2 +//
3 +// Permission is hereby granted, free of charge, to any person obtaining a
4 +// copy of this software and associated documentation files (the
5 +// "Software"), to deal in the Software without restriction, including
6 +// without limitation the rights to use, copy, modify, merge, publish,
7 +// distribute, sublicense, and/or sell copies of the Software, and to permit
8 +// persons to whom the Software is furnished to do so, subject to the
9 +// following conditions:
10 +//
11 +// The above copyright notice and this permission notice shall be included
12 +// in all copies or substantial portions of the Software.
13 +//
14 +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17 +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 +// USE OR OTHER DEALINGS IN THE SOFTWARE.
21 +
22 +'use strict';
23 +
24 +/*<replacement>*/
25 +
26 +var pna = require('process-nextick-args');
27 +/*</replacement>*/
28 +
29 +module.exports = Readable;
30 +
31 +/*<replacement>*/
32 +var isArray = require('isarray');
33 +/*</replacement>*/
34 +
35 +/*<replacement>*/
36 +var Duplex;
37 +/*</replacement>*/
38 +
39 +Readable.ReadableState = ReadableState;
40 +
41 +/*<replacement>*/
42 +var EE = require('events').EventEmitter;
43 +
44 +var EElistenerCount = function (emitter, type) {
45 + return emitter.listeners(type).length;
46 +};
47 +/*</replacement>*/
48 +
49 +/*<replacement>*/
50 +var Stream = require('./internal/streams/stream');
51 +/*</replacement>*/
52 +
53 +/*<replacement>*/
54 +
55 +var Buffer = require('safe-buffer').Buffer;
56 +var OurUint8Array = global.Uint8Array || function () {};
57 +function _uint8ArrayToBuffer(chunk) {
58 + return Buffer.from(chunk);
59 +}
60 +function _isUint8Array(obj) {
61 + return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
62 +}
63 +
64 +/*</replacement>*/
65 +
66 +/*<replacement>*/
67 +var util = Object.create(require('core-util-is'));
68 +util.inherits = require('inherits');
69 +/*</replacement>*/
70 +
71 +/*<replacement>*/
72 +var debugUtil = require('util');
73 +var debug = void 0;
74 +if (debugUtil && debugUtil.debuglog) {
75 + debug = debugUtil.debuglog('stream');
76 +} else {
77 + debug = function () {};
78 +}
79 +/*</replacement>*/
80 +
81 +var BufferList = require('./internal/streams/BufferList');
82 +var destroyImpl = require('./internal/streams/destroy');
83 +var StringDecoder;
84 +
85 +util.inherits(Readable, Stream);
86 +
87 +var kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume'];
88 +
89 +function prependListener(emitter, event, fn) {
90 + // Sadly this is not cacheable as some libraries bundle their own
91 + // event emitter implementation with them.
92 + if (typeof emitter.prependListener === 'function') return emitter.prependListener(event, fn);
93 +
94 + // This is a hack to make sure that our error handler is attached before any
95 + // userland ones. NEVER DO THIS. This is here only because this code needs
96 + // to continue to work with older versions of Node.js that do not include
97 + // the prependListener() method. The goal is to eventually remove this hack.
98 + if (!emitter._events || !emitter._events[event]) emitter.on(event, fn);else if (isArray(emitter._events[event])) emitter._events[event].unshift(fn);else emitter._events[event] = [fn, emitter._events[event]];
99 +}
100 +
101 +function ReadableState(options, stream) {
102 + Duplex = Duplex || require('./_stream_duplex');
103 +
104 + options = options || {};
105 +
106 + // Duplex streams are both readable and writable, but share
107 + // the same options object.
108 + // However, some cases require setting options to different
109 + // values for the readable and the writable sides of the duplex stream.
110 + // These options can be provided separately as readableXXX and writableXXX.
111 + var isDuplex = stream instanceof Duplex;
112 +
113 + // object stream flag. Used to make read(n) ignore n and to
114 + // make all the buffer merging and length checks go away
115 + this.objectMode = !!options.objectMode;
116 +
117 + if (isDuplex) this.objectMode = this.objectMode || !!options.readableObjectMode;
118 +
119 + // the point at which it stops calling _read() to fill the buffer
120 + // Note: 0 is a valid value, means "don't call _read preemptively ever"
121 + var hwm = options.highWaterMark;
122 + var readableHwm = options.readableHighWaterMark;
123 + var defaultHwm = this.objectMode ? 16 : 16 * 1024;
124 +
125 + if (hwm || hwm === 0) this.highWaterMark = hwm;else if (isDuplex && (readableHwm || readableHwm === 0)) this.highWaterMark = readableHwm;else this.highWaterMark = defaultHwm;
126 +
127 + // cast to ints.
128 + this.highWaterMark = Math.floor(this.highWaterMark);
129 +
130 + // A linked list is used to store data chunks instead of an array because the
131 + // linked list can remove elements from the beginning faster than
132 + // array.shift()
133 + this.buffer = new BufferList();
134 + this.length = 0;
135 + this.pipes = null;
136 + this.pipesCount = 0;
137 + this.flowing = null;
138 + this.ended = false;
139 + this.endEmitted = false;
140 + this.reading = false;
141 +
142 + // a flag to be able to tell if the event 'readable'/'data' is emitted
143 + // immediately, or on a later tick. We set this to true at first, because
144 + // any actions that shouldn't happen until "later" should generally also
145 + // not happen before the first read call.
146 + this.sync = true;
147 +
148 + // whenever we return null, then we set a flag to say
149 + // that we're awaiting a 'readable' event emission.
150 + this.needReadable = false;
151 + this.emittedReadable = false;
152 + this.readableListening = false;
153 + this.resumeScheduled = false;
154 +
155 + // has it been destroyed
156 + this.destroyed = false;
157 +
158 + // Crypto is kind of old and crusty. Historically, its default string
159 + // encoding is 'binary' so we have to make this configurable.
160 + // Everything else in the universe uses 'utf8', though.
161 + this.defaultEncoding = options.defaultEncoding || 'utf8';
162 +
163 + // the number of writers that are awaiting a drain event in .pipe()s
164 + this.awaitDrain = 0;
165 +
166 + // if true, a maybeReadMore has been scheduled
167 + this.readingMore = false;
168 +
169 + this.decoder = null;
170 + this.encoding = null;
171 + if (options.encoding) {
172 + if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
173 + this.decoder = new StringDecoder(options.encoding);
174 + this.encoding = options.encoding;
175 + }
176 +}
177 +
178 +function Readable(options) {
179 + Duplex = Duplex || require('./_stream_duplex');
180 +
181 + if (!(this instanceof Readable)) return new Readable(options);
182 +
183 + this._readableState = new ReadableState(options, this);
184 +
185 + // legacy
186 + this.readable = true;
187 +
188 + if (options) {
189 + if (typeof options.read === 'function') this._read = options.read;
190 +
191 + if (typeof options.destroy === 'function') this._destroy = options.destroy;
192 + }
193 +
194 + Stream.call(this);
195 +}
196 +
197 +Object.defineProperty(Readable.prototype, 'destroyed', {
198 + get: function () {
199 + if (this._readableState === undefined) {
200 + return false;
201 + }
202 + return this._readableState.destroyed;
203 + },
204 + set: function (value) {
205 + // we ignore the value if the stream
206 + // has not been initialized yet
207 + if (!this._readableState) {
208 + return;
209 + }
210 +
211 + // backward compatibility, the user is explicitly
212 + // managing destroyed
213 + this._readableState.destroyed = value;
214 + }
215 +});
216 +
217 +Readable.prototype.destroy = destroyImpl.destroy;
218 +Readable.prototype._undestroy = destroyImpl.undestroy;
219 +Readable.prototype._destroy = function (err, cb) {
220 + this.push(null);
221 + cb(err);
222 +};
223 +
224 +// Manually shove something into the read() buffer.
225 +// This returns true if the highWaterMark has not been hit yet,
226 +// similar to how Writable.write() returns true if you should
227 +// write() some more.
228 +Readable.prototype.push = function (chunk, encoding) {
229 + var state = this._readableState;
230 + var skipChunkCheck;
231 +
232 + if (!state.objectMode) {
233 + if (typeof chunk === 'string') {
234 + encoding = encoding || state.defaultEncoding;
235 + if (encoding !== state.encoding) {
236 + chunk = Buffer.from(chunk, encoding);
237 + encoding = '';
238 + }
239 + skipChunkCheck = true;
240 + }
241 + } else {
242 + skipChunkCheck = true;
243 + }
244 +
245 + return readableAddChunk(this, chunk, encoding, false, skipChunkCheck);
246 +};
247 +
248 +// Unshift should *always* be something directly out of read()
249 +Readable.prototype.unshift = function (chunk) {
250 + return readableAddChunk(this, chunk, null, true, false);
251 +};
252 +
253 +function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
254 + var state = stream._readableState;
255 + if (chunk === null) {
256 + state.reading = false;
257 + onEofChunk(stream, state);
258 + } else {
259 + var er;
260 + if (!skipChunkCheck) er = chunkInvalid(state, chunk);
261 + if (er) {
262 + stream.emit('error', er);
263 + } else if (state.objectMode || chunk && chunk.length > 0) {
264 + if (typeof chunk !== 'string' && !state.objectMode && Object.getPrototypeOf(chunk) !== Buffer.prototype) {
265 + chunk = _uint8ArrayToBuffer(chunk);
266 + }
267 +
268 + if (addToFront) {
269 + if (state.endEmitted) stream.emit('error', new Error('stream.unshift() after end event'));else addChunk(stream, state, chunk, true);
270 + } else if (state.ended) {
271 + stream.emit('error', new Error('stream.push() after EOF'));
272 + } else {
273 + state.reading = false;
274 + if (state.decoder && !encoding) {
275 + chunk = state.decoder.write(chunk);
276 + if (state.objectMode || chunk.length !== 0) addChunk(stream, state, chunk, false);else maybeReadMore(stream, state);
277 + } else {
278 + addChunk(stream, state, chunk, false);
279 + }
280 + }
281 + } else if (!addToFront) {
282 + state.reading = false;
283 + }
284 + }
285 +
286 + return needMoreData(state);
287 +}
288 +
289 +function addChunk(stream, state, chunk, addToFront) {
290 + if (state.flowing && state.length === 0 && !state.sync) {
291 + stream.emit('data', chunk);
292 + stream.read(0);
293 + } else {
294 + // update the buffer info.
295 + state.length += state.objectMode ? 1 : chunk.length;
296 + if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk);
297 +
298 + if (state.needReadable) emitReadable(stream);
299 + }
300 + maybeReadMore(stream, state);
301 +}
302 +
303 +function chunkInvalid(state, chunk) {
304 + var er;
305 + if (!_isUint8Array(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
306 + er = new TypeError('Invalid non-string/buffer chunk');
307 + }
308 + return er;
309 +}
310 +
311 +// if it's past the high water mark, we can push in some more.
312 +// Also, if we have no data yet, we can stand some
313 +// more bytes. This is to work around cases where hwm=0,
314 +// such as the repl. Also, if the push() triggered a
315 +// readable event, and the user called read(largeNumber) such that
316 +// needReadable was set, then we ought to push more, so that another
317 +// 'readable' event will be triggered.
318 +function needMoreData(state) {
319 + return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0);
320 +}
321 +
322 +Readable.prototype.isPaused = function () {
323 + return this._readableState.flowing === false;
324 +};
325 +
326 +// backwards compatibility.
327 +Readable.prototype.setEncoding = function (enc) {
328 + if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
329 + this._readableState.decoder = new StringDecoder(enc);
330 + this._readableState.encoding = enc;
331 + return this;
332 +};
333 +
334 +// Don't raise the hwm > 8MB
335 +var MAX_HWM = 0x800000;
336 +function computeNewHighWaterMark(n) {
337 + if (n >= MAX_HWM) {
338 + n = MAX_HWM;
339 + } else {
340 + // Get the next highest power of 2 to prevent increasing hwm excessively in
341 + // tiny amounts
342 + n--;
343 + n |= n >>> 1;
344 + n |= n >>> 2;
345 + n |= n >>> 4;
346 + n |= n >>> 8;
347 + n |= n >>> 16;
348 + n++;
349 + }
350 + return n;
351 +}
352 +
353 +// This function is designed to be inlinable, so please take care when making
354 +// changes to the function body.
355 +function howMuchToRead(n, state) {
356 + if (n <= 0 || state.length === 0 && state.ended) return 0;
357 + if (state.objectMode) return 1;
358 + if (n !== n) {
359 + // Only flow one buffer at a time
360 + if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length;
361 + }
362 + // If we're asking for more than the current hwm, then raise the hwm.
363 + if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n);
364 + if (n <= state.length) return n;
365 + // Don't have enough
366 + if (!state.ended) {
367 + state.needReadable = true;
368 + return 0;
369 + }
370 + return state.length;
371 +}
372 +
373 +// you can override either this method, or the async _read(n) below.
374 +Readable.prototype.read = function (n) {
375 + debug('read', n);
376 + n = parseInt(n, 10);
377 + var state = this._readableState;
378 + var nOrig = n;
379 +
380 + if (n !== 0) state.emittedReadable = false;
381 +
382 + // if we're doing read(0) to trigger a readable event, but we
383 + // already have a bunch of data in the buffer, then just trigger
384 + // the 'readable' event and move on.
385 + if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) {
386 + debug('read: emitReadable', state.length, state.ended);
387 + if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this);
388 + return null;
389 + }
390 +
391 + n = howMuchToRead(n, state);
392 +
393 + // if we've ended, and we're now clear, then finish it up.
394 + if (n === 0 && state.ended) {
395 + if (state.length === 0) endReadable(this);
396 + return null;
397 + }
398 +
399 + // All the actual chunk generation logic needs to be
400 + // *below* the call to _read. The reason is that in certain
401 + // synthetic stream cases, such as passthrough streams, _read
402 + // may be a completely synchronous operation which may change
403 + // the state of the read buffer, providing enough data when
404 + // before there was *not* enough.
405 + //
406 + // So, the steps are:
407 + // 1. Figure out what the state of things will be after we do
408 + // a read from the buffer.
409 + //
410 + // 2. If that resulting state will trigger a _read, then call _read.
411 + // Note that this may be asynchronous, or synchronous. Yes, it is
412 + // deeply ugly to write APIs this way, but that still doesn't mean
413 + // that the Readable class should behave improperly, as streams are
414 + // designed to be sync/async agnostic.
415 + // Take note if the _read call is sync or async (ie, if the read call
416 + // has returned yet), so that we know whether or not it's safe to emit
417 + // 'readable' etc.
418 + //
419 + // 3. Actually pull the requested chunks out of the buffer and return.
420 +
421 + // if we need a readable event, then we need to do some reading.
422 + var doRead = state.needReadable;
423 + debug('need readable', doRead);
424 +
425 + // if we currently have less than the highWaterMark, then also read some
426 + if (state.length === 0 || state.length - n < state.highWaterMark) {
427 + doRead = true;
428 + debug('length less than watermark', doRead);
429 + }
430 +
431 + // however, if we've ended, then there's no point, and if we're already
432 + // reading, then it's unnecessary.
433 + if (state.ended || state.reading) {
434 + doRead = false;
435 + debug('reading or ended', doRead);
436 + } else if (doRead) {
437 + debug('do read');
438 + state.reading = true;
439 + state.sync = true;
440 + // if the length is currently zero, then we *need* a readable event.
441 + if (state.length === 0) state.needReadable = true;
442 + // call internal read method
443 + this._read(state.highWaterMark);
444 + state.sync = false;
445 + // If _read pushed data synchronously, then `reading` will be false,
446 + // and we need to re-evaluate how much data we can return to the user.
447 + if (!state.reading) n = howMuchToRead(nOrig, state);
448 + }
449 +
450 + var ret;
451 + if (n > 0) ret = fromList(n, state);else ret = null;
452 +
453 + if (ret === null) {
454 + state.needReadable = true;
455 + n = 0;
456 + } else {
457 + state.length -= n;
458 + }
459 +
460 + if (state.length === 0) {
461 + // If we have nothing in the buffer, then we want to know
462 + // as soon as we *do* get something into the buffer.
463 + if (!state.ended) state.needReadable = true;
464 +
465 + // If we tried to read() past the EOF, then emit end on the next tick.
466 + if (nOrig !== n && state.ended) endReadable(this);
467 + }
468 +
469 + if (ret !== null) this.emit('data', ret);
470 +
471 + return ret;
472 +};
473 +
474 +function onEofChunk(stream, state) {
475 + if (state.ended) return;
476 + if (state.decoder) {
477 + var chunk = state.decoder.end();
478 + if (chunk && chunk.length) {
479 + state.buffer.push(chunk);
480 + state.length += state.objectMode ? 1 : chunk.length;
481 + }
482 + }
483 + state.ended = true;
484 +
485 + // emit 'readable' now to make sure it gets picked up.
486 + emitReadable(stream);
487 +}
488 +
489 +// Don't emit readable right away in sync mode, because this can trigger
490 +// another read() call => stack overflow. This way, it might trigger
491 +// a nextTick recursion warning, but that's not so bad.
492 +function emitReadable(stream) {
493 + var state = stream._readableState;
494 + state.needReadable = false;
495 + if (!state.emittedReadable) {
496 + debug('emitReadable', state.flowing);
497 + state.emittedReadable = true;
498 + if (state.sync) pna.nextTick(emitReadable_, stream);else emitReadable_(stream);
499 + }
500 +}
501 +
502 +function emitReadable_(stream) {
503 + debug('emit readable');
504 + stream.emit('readable');
505 + flow(stream);
506 +}
507 +
508 +// at this point, the user has presumably seen the 'readable' event,
509 +// and called read() to consume some data. that may have triggered
510 +// in turn another _read(n) call, in which case reading = true if
511 +// it's in progress.
512 +// However, if we're not ended, or reading, and the length < hwm,
513 +// then go ahead and try to read some more preemptively.
514 +function maybeReadMore(stream, state) {
515 + if (!state.readingMore) {
516 + state.readingMore = true;
517 + pna.nextTick(maybeReadMore_, stream, state);
518 + }
519 +}
520 +
521 +function maybeReadMore_(stream, state) {
522 + var len = state.length;
523 + while (!state.reading && !state.flowing && !state.ended && state.length < state.highWaterMark) {
524 + debug('maybeReadMore read 0');
525 + stream.read(0);
526 + if (len === state.length)
527 + // didn't get any data, stop spinning.
528 + break;else len = state.length;
529 + }
530 + state.readingMore = false;
531 +}
532 +
533 +// abstract method. to be overridden in specific implementation classes.
534 +// call cb(er, data) where data is <= n in length.
535 +// for virtual (non-string, non-buffer) streams, "length" is somewhat
536 +// arbitrary, and perhaps not very meaningful.
537 +Readable.prototype._read = function (n) {
538 + this.emit('error', new Error('_read() is not implemented'));
539 +};
540 +
541 +Readable.prototype.pipe = function (dest, pipeOpts) {
542 + var src = this;
543 + var state = this._readableState;
544 +
545 + switch (state.pipesCount) {
546 + case 0:
547 + state.pipes = dest;
548 + break;
549 + case 1:
550 + state.pipes = [state.pipes, dest];
551 + break;
552 + default:
553 + state.pipes.push(dest);
554 + break;
555 + }
556 + state.pipesCount += 1;
557 + debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
558 +
559 + var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
560 +
561 + var endFn = doEnd ? onend : unpipe;
562 + if (state.endEmitted) pna.nextTick(endFn);else src.once('end', endFn);
563 +
564 + dest.on('unpipe', onunpipe);
565 + function onunpipe(readable, unpipeInfo) {
566 + debug('onunpipe');
567 + if (readable === src) {
568 + if (unpipeInfo && unpipeInfo.hasUnpiped === false) {
569 + unpipeInfo.hasUnpiped = true;
570 + cleanup();
571 + }
572 + }
573 + }
574 +
575 + function onend() {
576 + debug('onend');
577 + dest.end();
578 + }
579 +
580 + // when the dest drains, it reduces the awaitDrain counter
581 + // on the source. This would be more elegant with a .once()
582 + // handler in flow(), but adding and removing repeatedly is
583 + // too slow.
584 + var ondrain = pipeOnDrain(src);
585 + dest.on('drain', ondrain);
586 +
587 + var cleanedUp = false;
588 + function cleanup() {
589 + debug('cleanup');
590 + // cleanup event handlers once the pipe is broken
591 + dest.removeListener('close', onclose);
592 + dest.removeListener('finish', onfinish);
593 + dest.removeListener('drain', ondrain);
594 + dest.removeListener('error', onerror);
595 + dest.removeListener('unpipe', onunpipe);
596 + src.removeListener('end', onend);
597 + src.removeListener('end', unpipe);
598 + src.removeListener('data', ondata);
599 +
600 + cleanedUp = true;
601 +
602 + // if the reader is waiting for a drain event from this
603 + // specific writer, then it would cause it to never start
604 + // flowing again.
605 + // So, if this is awaiting a drain, then we just call it now.
606 + // If we don't know, then assume that we are waiting for one.
607 + if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
608 + }
609 +
610 + // If the user pushes more data while we're writing to dest then we'll end up
611 + // in ondata again. However, we only want to increase awaitDrain once because
612 + // dest will only emit one 'drain' event for the multiple writes.
613 + // => Introduce a guard on increasing awaitDrain.
614 + var increasedAwaitDrain = false;
615 + src.on('data', ondata);
616 + function ondata(chunk) {
617 + debug('ondata');
618 + increasedAwaitDrain = false;
619 + var ret = dest.write(chunk);
620 + if (false === ret && !increasedAwaitDrain) {
621 + // If the user unpiped during `dest.write()`, it is possible
622 + // to get stuck in a permanently paused state if that write
623 + // also returned false.
624 + // => Check whether `dest` is still a piping destination.
625 + if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) {
626 + debug('false write response, pause', src._readableState.awaitDrain);
627 + src._readableState.awaitDrain++;
628 + increasedAwaitDrain = true;
629 + }
630 + src.pause();
631 + }
632 + }
633 +
634 + // if the dest has an error, then stop piping into it.
635 + // however, don't suppress the throwing behavior for this.
636 + function onerror(er) {
637 + debug('onerror', er);
638 + unpipe();
639 + dest.removeListener('error', onerror);
640 + if (EElistenerCount(dest, 'error') === 0) dest.emit('error', er);
641 + }
642 +
643 + // Make sure our error handler is attached before userland ones.
644 + prependListener(dest, 'error', onerror);
645 +
646 + // Both close and finish should trigger unpipe, but only once.
647 + function onclose() {
648 + dest.removeListener('finish', onfinish);
649 + unpipe();
650 + }
651 + dest.once('close', onclose);
652 + function onfinish() {
653 + debug('onfinish');
654 + dest.removeListener('close', onclose);
655 + unpipe();
656 + }
657 + dest.once('finish', onfinish);
658 +
659 + function unpipe() {
660 + debug('unpipe');
661 + src.unpipe(dest);
662 + }
663 +
664 + // tell the dest that it's being piped to
665 + dest.emit('pipe', src);
666 +
667 + // start the flow if it hasn't been started already.
668 + if (!state.flowing) {
669 + debug('pipe resume');
670 + src.resume();
671 + }
672 +
673 + return dest;
674 +};
675 +
676 +function pipeOnDrain(src) {
677 + return function () {
678 + var state = src._readableState;
679 + debug('pipeOnDrain', state.awaitDrain);
680 + if (state.awaitDrain) state.awaitDrain--;
681 + if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) {
682 + state.flowing = true;
683 + flow(src);
684 + }
685 + };
686 +}
687 +
688 +Readable.prototype.unpipe = function (dest) {
689 + var state = this._readableState;
690 + var unpipeInfo = { hasUnpiped: false };
691 +
692 + // if we're not piping anywhere, then do nothing.
693 + if (state.pipesCount === 0) return this;
694 +
695 + // just one destination. most common case.
696 + if (state.pipesCount === 1) {
697 + // passed in one, but it's not the right one.
698 + if (dest && dest !== state.pipes) return this;
699 +
700 + if (!dest) dest = state.pipes;
701 +
702 + // got a match.
703 + state.pipes = null;
704 + state.pipesCount = 0;
705 + state.flowing = false;
706 + if (dest) dest.emit('unpipe', this, unpipeInfo);
707 + return this;
708 + }
709 +
710 + // slow case. multiple pipe destinations.
711 +
712 + if (!dest) {
713 + // remove all.
714 + var dests = state.pipes;
715 + var len = state.pipesCount;
716 + state.pipes = null;
717 + state.pipesCount = 0;
718 + state.flowing = false;
719 +
720 + for (var i = 0; i < len; i++) {
721 + dests[i].emit('unpipe', this, unpipeInfo);
722 + }return this;
723 + }
724 +
725 + // try to find the right one.
726 + var index = indexOf(state.pipes, dest);
727 + if (index === -1) return this;
728 +
729 + state.pipes.splice(index, 1);
730 + state.pipesCount -= 1;
731 + if (state.pipesCount === 1) state.pipes = state.pipes[0];
732 +
733 + dest.emit('unpipe', this, unpipeInfo);
734 +
735 + return this;
736 +};
737 +
738 +// set up data events if they are asked for
739 +// Ensure readable listeners eventually get something
740 +Readable.prototype.on = function (ev, fn) {
741 + var res = Stream.prototype.on.call(this, ev, fn);
742 +
743 + if (ev === 'data') {
744 + // Start flowing on next tick if stream isn't explicitly paused
745 + if (this._readableState.flowing !== false) this.resume();
746 + } else if (ev === 'readable') {
747 + var state = this._readableState;
748 + if (!state.endEmitted && !state.readableListening) {
749 + state.readableListening = state.needReadable = true;
750 + state.emittedReadable = false;
751 + if (!state.reading) {
752 + pna.nextTick(nReadingNextTick, this);
753 + } else if (state.length) {
754 + emitReadable(this);
755 + }
756 + }
757 + }
758 +
759 + return res;
760 +};
761 +Readable.prototype.addListener = Readable.prototype.on;
762 +
763 +function nReadingNextTick(self) {
764 + debug('readable nexttick read 0');
765 + self.read(0);
766 +}
767 +
768 +// pause() and resume() are remnants of the legacy readable stream API
769 +// If the user uses them, then switch into old mode.
770 +Readable.prototype.resume = function () {
771 + var state = this._readableState;
772 + if (!state.flowing) {
773 + debug('resume');
774 + state.flowing = true;
775 + resume(this, state);
776 + }
777 + return this;
778 +};
779 +
780 +function resume(stream, state) {
781 + if (!state.resumeScheduled) {
782 + state.resumeScheduled = true;
783 + pna.nextTick(resume_, stream, state);
784 + }
785 +}
786 +
787 +function resume_(stream, state) {
788 + if (!state.reading) {
789 + debug('resume read 0');
790 + stream.read(0);
791 + }
792 +
793 + state.resumeScheduled = false;
794 + state.awaitDrain = 0;
795 + stream.emit('resume');
796 + flow(stream);
797 + if (state.flowing && !state.reading) stream.read(0);
798 +}
799 +
800 +Readable.prototype.pause = function () {
801 + debug('call pause flowing=%j', this._readableState.flowing);
802 + if (false !== this._readableState.flowing) {
803 + debug('pause');
804 + this._readableState.flowing = false;
805 + this.emit('pause');
806 + }
807 + return this;
808 +};
809 +
810 +function flow(stream) {
811 + var state = stream._readableState;
812 + debug('flow', state.flowing);
813 + while (state.flowing && stream.read() !== null) {}
814 +}
815 +
816 +// wrap an old-style stream as the async data source.
817 +// This is *not* part of the readable stream interface.
818 +// It is an ugly unfortunate mess of history.
819 +Readable.prototype.wrap = function (stream) {
820 + var _this = this;
821 +
822 + var state = this._readableState;
823 + var paused = false;
824 +
825 + stream.on('end', function () {
826 + debug('wrapped end');
827 + if (state.decoder && !state.ended) {
828 + var chunk = state.decoder.end();
829 + if (chunk && chunk.length) _this.push(chunk);
830 + }
831 +
832 + _this.push(null);
833 + });
834 +
835 + stream.on('data', function (chunk) {
836 + debug('wrapped data');
837 + if (state.decoder) chunk = state.decoder.write(chunk);
838 +
839 + // don't skip over falsy values in objectMode
840 + if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return;
841 +
842 + var ret = _this.push(chunk);
843 + if (!ret) {
844 + paused = true;
845 + stream.pause();
846 + }
847 + });
848 +
849 + // proxy all the other methods.
850 + // important when wrapping filters and duplexes.
851 + for (var i in stream) {
852 + if (this[i] === undefined && typeof stream[i] === 'function') {
853 + this[i] = function (method) {
854 + return function () {
855 + return stream[method].apply(stream, arguments);
856 + };
857 + }(i);
858 + }
859 + }
860 +
861 + // proxy certain important events.
862 + for (var n = 0; n < kProxyEvents.length; n++) {
863 + stream.on(kProxyEvents[n], this.emit.bind(this, kProxyEvents[n]));
864 + }
865 +
866 + // when we try to consume some more bytes, simply unpause the
867 + // underlying stream.
868 + this._read = function (n) {
869 + debug('wrapped _read', n);
870 + if (paused) {
871 + paused = false;
872 + stream.resume();
873 + }
874 + };
875 +
876 + return this;
877 +};
878 +
879 +Object.defineProperty(Readable.prototype, 'readableHighWaterMark', {
880 + // making it explicit this property is not enumerable
881 + // because otherwise some prototype manipulation in
882 + // userland will fail
883 + enumerable: false,
884 + get: function () {
885 + return this._readableState.highWaterMark;
886 + }
887 +});
888 +
889 +// exposed for testing purposes only.
890 +Readable._fromList = fromList;
891 +
892 +// Pluck off n bytes from an array of buffers.
893 +// Length is the combined lengths of all the buffers in the list.
894 +// This function is designed to be inlinable, so please take care when making
895 +// changes to the function body.
896 +function fromList(n, state) {
897 + // nothing buffered
898 + if (state.length === 0) return null;
899 +
900 + var ret;
901 + if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) {
902 + // read it all, truncate the list
903 + if (state.decoder) ret = state.buffer.join('');else if (state.buffer.length === 1) ret = state.buffer.head.data;else ret = state.buffer.concat(state.length);
904 + state.buffer.clear();
905 + } else {
906 + // read part of list
907 + ret = fromListPartial(n, state.buffer, state.decoder);
908 + }
909 +
910 + return ret;
911 +}
912 +
913 +// Extracts only enough buffered data to satisfy the amount requested.
914 +// This function is designed to be inlinable, so please take care when making
915 +// changes to the function body.
916 +function fromListPartial(n, list, hasStrings) {
917 + var ret;
918 + if (n < list.head.data.length) {
919 + // slice is the same for buffers and strings
920 + ret = list.head.data.slice(0, n);
921 + list.head.data = list.head.data.slice(n);
922 + } else if (n === list.head.data.length) {
923 + // first chunk is a perfect match
924 + ret = list.shift();
925 + } else {
926 + // result spans more than one buffer
927 + ret = hasStrings ? copyFromBufferString(n, list) : copyFromBuffer(n, list);
928 + }
929 + return ret;
930 +}
931 +
932 +// Copies a specified amount of characters from the list of buffered data
933 +// chunks.
934 +// This function is designed to be inlinable, so please take care when making
935 +// changes to the function body.
936 +function copyFromBufferString(n, list) {
937 + var p = list.head;
938 + var c = 1;
939 + var ret = p.data;
940 + n -= ret.length;
941 + while (p = p.next) {
942 + var str = p.data;
943 + var nb = n > str.length ? str.length : n;
944 + if (nb === str.length) ret += str;else ret += str.slice(0, n);
945 + n -= nb;
946 + if (n === 0) {
947 + if (nb === str.length) {
948 + ++c;
949 + if (p.next) list.head = p.next;else list.head = list.tail = null;
950 + } else {
951 + list.head = p;
952 + p.data = str.slice(nb);
953 + }
954 + break;
955 + }
956 + ++c;
957 + }
958 + list.length -= c;
959 + return ret;
960 +}
961 +
962 +// Copies a specified amount of bytes from the list of buffered data chunks.
963 +// This function is designed to be inlinable, so please take care when making
964 +// changes to the function body.
965 +function copyFromBuffer(n, list) {
966 + var ret = Buffer.allocUnsafe(n);
967 + var p = list.head;
968 + var c = 1;
969 + p.data.copy(ret);
970 + n -= p.data.length;
971 + while (p = p.next) {
972 + var buf = p.data;
973 + var nb = n > buf.length ? buf.length : n;
974 + buf.copy(ret, ret.length - n, 0, nb);
975 + n -= nb;
976 + if (n === 0) {
977 + if (nb === buf.length) {
978 + ++c;
979 + if (p.next) list.head = p.next;else list.head = list.tail = null;
980 + } else {
981 + list.head = p;
982 + p.data = buf.slice(nb);
983 + }
984 + break;
985 + }
986 + ++c;
987 + }
988 + list.length -= c;
989 + return ret;
990 +}
991 +
992 +function endReadable(stream) {
993 + var state = stream._readableState;
994 +
995 + // If we get here before consuming all the bytes, then that is a
996 + // bug in node. Should never happen.
997 + if (state.length > 0) throw new Error('"endReadable()" called on non-empty stream');
998 +
999 + if (!state.endEmitted) {
1000 + state.ended = true;
1001 + pna.nextTick(endReadableNT, state, stream);
1002 + }
1003 +}
1004 +
1005 +function endReadableNT(state, stream) {
1006 + // Check that we didn't get one last unshift.
1007 + if (!state.endEmitted && state.length === 0) {
1008 + state.endEmitted = true;
1009 + stream.readable = false;
1010 + stream.emit('end');
1011 + }
1012 +}
1013 +
1014 +function indexOf(xs, x) {
1015 + for (var i = 0, l = xs.length; i < l; i++) {
1016 + if (xs[i] === x) return i;
1017 + }
1018 + return -1;
1019 +}
...\ No newline at end of file ...\ No newline at end of file
1 +// Copyright Joyent, Inc. and other Node contributors.
2 +//
3 +// Permission is hereby granted, free of charge, to any person obtaining a
4 +// copy of this software and associated documentation files (the
5 +// "Software"), to deal in the Software without restriction, including
6 +// without limitation the rights to use, copy, modify, merge, publish,
7 +// distribute, sublicense, and/or sell copies of the Software, and to permit
8 +// persons to whom the Software is furnished to do so, subject to the
9 +// following conditions:
10 +//
11 +// The above copyright notice and this permission notice shall be included
12 +// in all copies or substantial portions of the Software.
13 +//
14 +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17 +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 +// USE OR OTHER DEALINGS IN THE SOFTWARE.
21 +
22 +// a transform stream is a readable/writable stream where you do
23 +// something with the data. Sometimes it's called a "filter",
24 +// but that's not a great name for it, since that implies a thing where
25 +// some bits pass through, and others are simply ignored. (That would
26 +// be a valid example of a transform, of course.)
27 +//
28 +// While the output is causally related to the input, it's not a
29 +// necessarily symmetric or synchronous transformation. For example,
30 +// a zlib stream might take multiple plain-text writes(), and then
31 +// emit a single compressed chunk some time in the future.
32 +//
33 +// Here's how this works:
34 +//
35 +// The Transform stream has all the aspects of the readable and writable
36 +// stream classes. When you write(chunk), that calls _write(chunk,cb)
37 +// internally, and returns false if there's a lot of pending writes
38 +// buffered up. When you call read(), that calls _read(n) until
39 +// there's enough pending readable data buffered up.
40 +//
41 +// In a transform stream, the written data is placed in a buffer. When
42 +// _read(n) is called, it transforms the queued up data, calling the
43 +// buffered _write cb's as it consumes chunks. If consuming a single
44 +// written chunk would result in multiple output chunks, then the first
45 +// outputted bit calls the readcb, and subsequent chunks just go into
46 +// the read buffer, and will cause it to emit 'readable' if necessary.
47 +//
48 +// This way, back-pressure is actually determined by the reading side,
49 +// since _read has to be called to start processing a new chunk. However,
50 +// a pathological inflate type of transform can cause excessive buffering
51 +// here. For example, imagine a stream where every byte of input is
52 +// interpreted as an integer from 0-255, and then results in that many
53 +// bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in
54 +// 1kb of data being output. In this case, you could write a very small
55 +// amount of input, and end up with a very large amount of output. In
56 +// such a pathological inflating mechanism, there'd be no way to tell
57 +// the system to stop doing the transform. A single 4MB write could
58 +// cause the system to run out of memory.
59 +//
60 +// However, even in such a pathological case, only a single written chunk
61 +// would be consumed, and then the rest would wait (un-transformed) until
62 +// the results of the previous transformed chunk were consumed.
63 +
64 +'use strict';
65 +
66 +module.exports = Transform;
67 +
68 +var Duplex = require('./_stream_duplex');
69 +
70 +/*<replacement>*/
71 +var util = Object.create(require('core-util-is'));
72 +util.inherits = require('inherits');
73 +/*</replacement>*/
74 +
75 +util.inherits(Transform, Duplex);
76 +
77 +function afterTransform(er, data) {
78 + var ts = this._transformState;
79 + ts.transforming = false;
80 +
81 + var cb = ts.writecb;
82 +
83 + if (!cb) {
84 + return this.emit('error', new Error('write callback called multiple times'));
85 + }
86 +
87 + ts.writechunk = null;
88 + ts.writecb = null;
89 +
90 + if (data != null) // single equals check for both `null` and `undefined`
91 + this.push(data);
92 +
93 + cb(er);
94 +
95 + var rs = this._readableState;
96 + rs.reading = false;
97 + if (rs.needReadable || rs.length < rs.highWaterMark) {
98 + this._read(rs.highWaterMark);
99 + }
100 +}
101 +
102 +function Transform(options) {
103 + if (!(this instanceof Transform)) return new Transform(options);
104 +
105 + Duplex.call(this, options);
106 +
107 + this._transformState = {
108 + afterTransform: afterTransform.bind(this),
109 + needTransform: false,
110 + transforming: false,
111 + writecb: null,
112 + writechunk: null,
113 + writeencoding: null
114 + };
115 +
116 + // start out asking for a readable event once data is transformed.
117 + this._readableState.needReadable = true;
118 +
119 + // we have implemented the _read method, and done the other things
120 + // that Readable wants before the first _read call, so unset the
121 + // sync guard flag.
122 + this._readableState.sync = false;
123 +
124 + if (options) {
125 + if (typeof options.transform === 'function') this._transform = options.transform;
126 +
127 + if (typeof options.flush === 'function') this._flush = options.flush;
128 + }
129 +
130 + // When the writable side finishes, then flush out anything remaining.
131 + this.on('prefinish', prefinish);
132 +}
133 +
134 +function prefinish() {
135 + var _this = this;
136 +
137 + if (typeof this._flush === 'function') {
138 + this._flush(function (er, data) {
139 + done(_this, er, data);
140 + });
141 + } else {
142 + done(this, null, null);
143 + }
144 +}
145 +
146 +Transform.prototype.push = function (chunk, encoding) {
147 + this._transformState.needTransform = false;
148 + return Duplex.prototype.push.call(this, chunk, encoding);
149 +};
150 +
151 +// This is the part where you do stuff!
152 +// override this function in implementation classes.
153 +// 'chunk' is an input chunk.
154 +//
155 +// Call `push(newChunk)` to pass along transformed output
156 +// to the readable side. You may call 'push' zero or more times.
157 +//
158 +// Call `cb(err)` when you are done with this chunk. If you pass
159 +// an error, then that'll put the hurt on the whole operation. If you
160 +// never call cb(), then you'll never get another chunk.
161 +Transform.prototype._transform = function (chunk, encoding, cb) {
162 + throw new Error('_transform() is not implemented');
163 +};
164 +
165 +Transform.prototype._write = function (chunk, encoding, cb) {
166 + var ts = this._transformState;
167 + ts.writecb = cb;
168 + ts.writechunk = chunk;
169 + ts.writeencoding = encoding;
170 + if (!ts.transforming) {
171 + var rs = this._readableState;
172 + if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark);
173 + }
174 +};
175 +
176 +// Doesn't matter what the args are here.
177 +// _transform does all the work.
178 +// That we got here means that the readable side wants more data.
179 +Transform.prototype._read = function (n) {
180 + var ts = this._transformState;
181 +
182 + if (ts.writechunk !== null && ts.writecb && !ts.transforming) {
183 + ts.transforming = true;
184 + this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
185 + } else {
186 + // mark that we need a transform, so that any data that comes in
187 + // will get processed, now that we've asked for it.
188 + ts.needTransform = true;
189 + }
190 +};
191 +
192 +Transform.prototype._destroy = function (err, cb) {
193 + var _this2 = this;
194 +
195 + Duplex.prototype._destroy.call(this, err, function (err2) {
196 + cb(err2);
197 + _this2.emit('close');
198 + });
199 +};
200 +
201 +function done(stream, er, data) {
202 + if (er) return stream.emit('error', er);
203 +
204 + if (data != null) // single equals check for both `null` and `undefined`
205 + stream.push(data);
206 +
207 + // if there's nothing in the write buffer, then that means
208 + // that nothing more will ever be provided
209 + if (stream._writableState.length) throw new Error('Calling transform done when ws.length != 0');
210 +
211 + if (stream._transformState.transforming) throw new Error('Calling transform done when still transforming');
212 +
213 + return stream.push(null);
214 +}
...\ No newline at end of file ...\ No newline at end of file
1 +// Copyright Joyent, Inc. and other Node contributors.
2 +//
3 +// Permission is hereby granted, free of charge, to any person obtaining a
4 +// copy of this software and associated documentation files (the
5 +// "Software"), to deal in the Software without restriction, including
6 +// without limitation the rights to use, copy, modify, merge, publish,
7 +// distribute, sublicense, and/or sell copies of the Software, and to permit
8 +// persons to whom the Software is furnished to do so, subject to the
9 +// following conditions:
10 +//
11 +// The above copyright notice and this permission notice shall be included
12 +// in all copies or substantial portions of the Software.
13 +//
14 +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17 +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 +// USE OR OTHER DEALINGS IN THE SOFTWARE.
21 +
22 +// A bit simpler than readable streams.
23 +// Implement an async ._write(chunk, encoding, cb), and it'll handle all
24 +// the drain event emission and buffering.
25 +
26 +'use strict';
27 +
28 +/*<replacement>*/
29 +
30 +var pna = require('process-nextick-args');
31 +/*</replacement>*/
32 +
33 +module.exports = Writable;
34 +
35 +/* <replacement> */
36 +function WriteReq(chunk, encoding, cb) {
37 + this.chunk = chunk;
38 + this.encoding = encoding;
39 + this.callback = cb;
40 + this.next = null;
41 +}
42 +
43 +// It seems a linked list but it is not
44 +// there will be only 2 of these for each stream
45 +function CorkedRequest(state) {
46 + var _this = this;
47 +
48 + this.next = null;
49 + this.entry = null;
50 + this.finish = function () {
51 + onCorkedFinish(_this, state);
52 + };
53 +}
54 +/* </replacement> */
55 +
56 +/*<replacement>*/
57 +var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : pna.nextTick;
58 +/*</replacement>*/
59 +
60 +/*<replacement>*/
61 +var Duplex;
62 +/*</replacement>*/
63 +
64 +Writable.WritableState = WritableState;
65 +
66 +/*<replacement>*/
67 +var util = Object.create(require('core-util-is'));
68 +util.inherits = require('inherits');
69 +/*</replacement>*/
70 +
71 +/*<replacement>*/
72 +var internalUtil = {
73 + deprecate: require('util-deprecate')
74 +};
75 +/*</replacement>*/
76 +
77 +/*<replacement>*/
78 +var Stream = require('./internal/streams/stream');
79 +/*</replacement>*/
80 +
81 +/*<replacement>*/
82 +
83 +var Buffer = require('safe-buffer').Buffer;
84 +var OurUint8Array = global.Uint8Array || function () {};
85 +function _uint8ArrayToBuffer(chunk) {
86 + return Buffer.from(chunk);
87 +}
88 +function _isUint8Array(obj) {
89 + return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
90 +}
91 +
92 +/*</replacement>*/
93 +
94 +var destroyImpl = require('./internal/streams/destroy');
95 +
96 +util.inherits(Writable, Stream);
97 +
98 +function nop() {}
99 +
100 +function WritableState(options, stream) {
101 + Duplex = Duplex || require('./_stream_duplex');
102 +
103 + options = options || {};
104 +
105 + // Duplex streams are both readable and writable, but share
106 + // the same options object.
107 + // However, some cases require setting options to different
108 + // values for the readable and the writable sides of the duplex stream.
109 + // These options can be provided separately as readableXXX and writableXXX.
110 + var isDuplex = stream instanceof Duplex;
111 +
112 + // object stream flag to indicate whether or not this stream
113 + // contains buffers or objects.
114 + this.objectMode = !!options.objectMode;
115 +
116 + if (isDuplex) this.objectMode = this.objectMode || !!options.writableObjectMode;
117 +
118 + // the point at which write() starts returning false
119 + // Note: 0 is a valid value, means that we always return false if
120 + // the entire buffer is not flushed immediately on write()
121 + var hwm = options.highWaterMark;
122 + var writableHwm = options.writableHighWaterMark;
123 + var defaultHwm = this.objectMode ? 16 : 16 * 1024;
124 +
125 + if (hwm || hwm === 0) this.highWaterMark = hwm;else if (isDuplex && (writableHwm || writableHwm === 0)) this.highWaterMark = writableHwm;else this.highWaterMark = defaultHwm;
126 +
127 + // cast to ints.
128 + this.highWaterMark = Math.floor(this.highWaterMark);
129 +
130 + // if _final has been called
131 + this.finalCalled = false;
132 +
133 + // drain event flag.
134 + this.needDrain = false;
135 + // at the start of calling end()
136 + this.ending = false;
137 + // when end() has been called, and returned
138 + this.ended = false;
139 + // when 'finish' is emitted
140 + this.finished = false;
141 +
142 + // has it been destroyed
143 + this.destroyed = false;
144 +
145 + // should we decode strings into buffers before passing to _write?
146 + // this is here so that some node-core streams can optimize string
147 + // handling at a lower level.
148 + var noDecode = options.decodeStrings === false;
149 + this.decodeStrings = !noDecode;
150 +
151 + // Crypto is kind of old and crusty. Historically, its default string
152 + // encoding is 'binary' so we have to make this configurable.
153 + // Everything else in the universe uses 'utf8', though.
154 + this.defaultEncoding = options.defaultEncoding || 'utf8';
155 +
156 + // not an actual buffer we keep track of, but a measurement
157 + // of how much we're waiting to get pushed to some underlying
158 + // socket or file.
159 + this.length = 0;
160 +
161 + // a flag to see when we're in the middle of a write.
162 + this.writing = false;
163 +
164 + // when true all writes will be buffered until .uncork() call
165 + this.corked = 0;
166 +
167 + // a flag to be able to tell if the onwrite cb is called immediately,
168 + // or on a later tick. We set this to true at first, because any
169 + // actions that shouldn't happen until "later" should generally also
170 + // not happen before the first write call.
171 + this.sync = true;
172 +
173 + // a flag to know if we're processing previously buffered items, which
174 + // may call the _write() callback in the same tick, so that we don't
175 + // end up in an overlapped onwrite situation.
176 + this.bufferProcessing = false;
177 +
178 + // the callback that's passed to _write(chunk,cb)
179 + this.onwrite = function (er) {
180 + onwrite(stream, er);
181 + };
182 +
183 + // the callback that the user supplies to write(chunk,encoding,cb)
184 + this.writecb = null;
185 +
186 + // the amount that is being written when _write is called.
187 + this.writelen = 0;
188 +
189 + this.bufferedRequest = null;
190 + this.lastBufferedRequest = null;
191 +
192 + // number of pending user-supplied write callbacks
193 + // this must be 0 before 'finish' can be emitted
194 + this.pendingcb = 0;
195 +
196 + // emit prefinish if the only thing we're waiting for is _write cbs
197 + // This is relevant for synchronous Transform streams
198 + this.prefinished = false;
199 +
200 + // True if the error was already emitted and should not be thrown again
201 + this.errorEmitted = false;
202 +
203 + // count buffered requests
204 + this.bufferedRequestCount = 0;
205 +
206 + // allocate the first CorkedRequest, there is always
207 + // one allocated and free to use, and we maintain at most two
208 + this.corkedRequestsFree = new CorkedRequest(this);
209 +}
210 +
211 +WritableState.prototype.getBuffer = function getBuffer() {
212 + var current = this.bufferedRequest;
213 + var out = [];
214 + while (current) {
215 + out.push(current);
216 + current = current.next;
217 + }
218 + return out;
219 +};
220 +
221 +(function () {
222 + try {
223 + Object.defineProperty(WritableState.prototype, 'buffer', {
224 + get: internalUtil.deprecate(function () {
225 + return this.getBuffer();
226 + }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.', 'DEP0003')
227 + });
228 + } catch (_) {}
229 +})();
230 +
231 +// Test _writableState for inheritance to account for Duplex streams,
232 +// whose prototype chain only points to Readable.
233 +var realHasInstance;
234 +if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === 'function') {
235 + realHasInstance = Function.prototype[Symbol.hasInstance];
236 + Object.defineProperty(Writable, Symbol.hasInstance, {
237 + value: function (object) {
238 + if (realHasInstance.call(this, object)) return true;
239 + if (this !== Writable) return false;
240 +
241 + return object && object._writableState instanceof WritableState;
242 + }
243 + });
244 +} else {
245 + realHasInstance = function (object) {
246 + return object instanceof this;
247 + };
248 +}
249 +
250 +function Writable(options) {
251 + Duplex = Duplex || require('./_stream_duplex');
252 +
253 + // Writable ctor is applied to Duplexes, too.
254 + // `realHasInstance` is necessary because using plain `instanceof`
255 + // would return false, as no `_writableState` property is attached.
256 +
257 + // Trying to use the custom `instanceof` for Writable here will also break the
258 + // Node.js LazyTransform implementation, which has a non-trivial getter for
259 + // `_writableState` that would lead to infinite recursion.
260 + if (!realHasInstance.call(Writable, this) && !(this instanceof Duplex)) {
261 + return new Writable(options);
262 + }
263 +
264 + this._writableState = new WritableState(options, this);
265 +
266 + // legacy.
267 + this.writable = true;
268 +
269 + if (options) {
270 + if (typeof options.write === 'function') this._write = options.write;
271 +
272 + if (typeof options.writev === 'function') this._writev = options.writev;
273 +
274 + if (typeof options.destroy === 'function') this._destroy = options.destroy;
275 +
276 + if (typeof options.final === 'function') this._final = options.final;
277 + }
278 +
279 + Stream.call(this);
280 +}
281 +
282 +// Otherwise people can pipe Writable streams, which is just wrong.
283 +Writable.prototype.pipe = function () {
284 + this.emit('error', new Error('Cannot pipe, not readable'));
285 +};
286 +
287 +function writeAfterEnd(stream, cb) {
288 + var er = new Error('write after end');
289 + // TODO: defer error events consistently everywhere, not just the cb
290 + stream.emit('error', er);
291 + pna.nextTick(cb, er);
292 +}
293 +
294 +// Checks that a user-supplied chunk is valid, especially for the particular
295 +// mode the stream is in. Currently this means that `null` is never accepted
296 +// and undefined/non-string values are only allowed in object mode.
297 +function validChunk(stream, state, chunk, cb) {
298 + var valid = true;
299 + var er = false;
300 +
301 + if (chunk === null) {
302 + er = new TypeError('May not write null values to stream');
303 + } else if (typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
304 + er = new TypeError('Invalid non-string/buffer chunk');
305 + }
306 + if (er) {
307 + stream.emit('error', er);
308 + pna.nextTick(cb, er);
309 + valid = false;
310 + }
311 + return valid;
312 +}
313 +
314 +Writable.prototype.write = function (chunk, encoding, cb) {
315 + var state = this._writableState;
316 + var ret = false;
317 + var isBuf = !state.objectMode && _isUint8Array(chunk);
318 +
319 + if (isBuf && !Buffer.isBuffer(chunk)) {
320 + chunk = _uint8ArrayToBuffer(chunk);
321 + }
322 +
323 + if (typeof encoding === 'function') {
324 + cb = encoding;
325 + encoding = null;
326 + }
327 +
328 + if (isBuf) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
329 +
330 + if (typeof cb !== 'function') cb = nop;
331 +
332 + if (state.ended) writeAfterEnd(this, cb);else if (isBuf || validChunk(this, state, chunk, cb)) {
333 + state.pendingcb++;
334 + ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb);
335 + }
336 +
337 + return ret;
338 +};
339 +
340 +Writable.prototype.cork = function () {
341 + var state = this._writableState;
342 +
343 + state.corked++;
344 +};
345 +
346 +Writable.prototype.uncork = function () {
347 + var state = this._writableState;
348 +
349 + if (state.corked) {
350 + state.corked--;
351 +
352 + if (!state.writing && !state.corked && !state.finished && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
353 + }
354 +};
355 +
356 +Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
357 + // node::ParseEncoding() requires lower case.
358 + if (typeof encoding === 'string') encoding = encoding.toLowerCase();
359 + if (!(['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', 'raw'].indexOf((encoding + '').toLowerCase()) > -1)) throw new TypeError('Unknown encoding: ' + encoding);
360 + this._writableState.defaultEncoding = encoding;
361 + return this;
362 +};
363 +
364 +function decodeChunk(state, chunk, encoding) {
365 + if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
366 + chunk = Buffer.from(chunk, encoding);
367 + }
368 + return chunk;
369 +}
370 +
371 +Object.defineProperty(Writable.prototype, 'writableHighWaterMark', {
372 + // making it explicit this property is not enumerable
373 + // because otherwise some prototype manipulation in
374 + // userland will fail
375 + enumerable: false,
376 + get: function () {
377 + return this._writableState.highWaterMark;
378 + }
379 +});
380 +
381 +// if we're already writing something, then just put this
382 +// in the queue, and wait our turn. Otherwise, call _write
383 +// If we return false, then we need a drain event, so set that flag.
384 +function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
385 + if (!isBuf) {
386 + var newChunk = decodeChunk(state, chunk, encoding);
387 + if (chunk !== newChunk) {
388 + isBuf = true;
389 + encoding = 'buffer';
390 + chunk = newChunk;
391 + }
392 + }
393 + var len = state.objectMode ? 1 : chunk.length;
394 +
395 + state.length += len;
396 +
397 + var ret = state.length < state.highWaterMark;
398 + // we must ensure that previous needDrain will not be reset to false.
399 + if (!ret) state.needDrain = true;
400 +
401 + if (state.writing || state.corked) {
402 + var last = state.lastBufferedRequest;
403 + state.lastBufferedRequest = {
404 + chunk: chunk,
405 + encoding: encoding,
406 + isBuf: isBuf,
407 + callback: cb,
408 + next: null
409 + };
410 + if (last) {
411 + last.next = state.lastBufferedRequest;
412 + } else {
413 + state.bufferedRequest = state.lastBufferedRequest;
414 + }
415 + state.bufferedRequestCount += 1;
416 + } else {
417 + doWrite(stream, state, false, len, chunk, encoding, cb);
418 + }
419 +
420 + return ret;
421 +}
422 +
423 +function doWrite(stream, state, writev, len, chunk, encoding, cb) {
424 + state.writelen = len;
425 + state.writecb = cb;
426 + state.writing = true;
427 + state.sync = true;
428 + if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite);
429 + state.sync = false;
430 +}
431 +
432 +function onwriteError(stream, state, sync, er, cb) {
433 + --state.pendingcb;
434 +
435 + if (sync) {
436 + // defer the callback if we are being called synchronously
437 + // to avoid piling up things on the stack
438 + pna.nextTick(cb, er);
439 + // this can emit finish, and it will always happen
440 + // after error
441 + pna.nextTick(finishMaybe, stream, state);
442 + stream._writableState.errorEmitted = true;
443 + stream.emit('error', er);
444 + } else {
445 + // the caller expect this to happen before if
446 + // it is async
447 + cb(er);
448 + stream._writableState.errorEmitted = true;
449 + stream.emit('error', er);
450 + // this can emit finish, but finish must
451 + // always follow error
452 + finishMaybe(stream, state);
453 + }
454 +}
455 +
456 +function onwriteStateUpdate(state) {
457 + state.writing = false;
458 + state.writecb = null;
459 + state.length -= state.writelen;
460 + state.writelen = 0;
461 +}
462 +
463 +function onwrite(stream, er) {
464 + var state = stream._writableState;
465 + var sync = state.sync;
466 + var cb = state.writecb;
467 +
468 + onwriteStateUpdate(state);
469 +
470 + if (er) onwriteError(stream, state, sync, er, cb);else {
471 + // Check if we're actually ready to finish, but don't emit yet
472 + var finished = needFinish(state);
473 +
474 + if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
475 + clearBuffer(stream, state);
476 + }
477 +
478 + if (sync) {
479 + /*<replacement>*/
480 + asyncWrite(afterWrite, stream, state, finished, cb);
481 + /*</replacement>*/
482 + } else {
483 + afterWrite(stream, state, finished, cb);
484 + }
485 + }
486 +}
487 +
488 +function afterWrite(stream, state, finished, cb) {
489 + if (!finished) onwriteDrain(stream, state);
490 + state.pendingcb--;
491 + cb();
492 + finishMaybe(stream, state);
493 +}
494 +
495 +// Must force callback to be called on nextTick, so that we don't
496 +// emit 'drain' before the write() consumer gets the 'false' return
497 +// value, and has a chance to attach a 'drain' listener.
498 +function onwriteDrain(stream, state) {
499 + if (state.length === 0 && state.needDrain) {
500 + state.needDrain = false;
501 + stream.emit('drain');
502 + }
503 +}
504 +
505 +// if there's something in the buffer waiting, then process it
506 +function clearBuffer(stream, state) {
507 + state.bufferProcessing = true;
508 + var entry = state.bufferedRequest;
509 +
510 + if (stream._writev && entry && entry.next) {
511 + // Fast case, write everything using _writev()
512 + var l = state.bufferedRequestCount;
513 + var buffer = new Array(l);
514 + var holder = state.corkedRequestsFree;
515 + holder.entry = entry;
516 +
517 + var count = 0;
518 + var allBuffers = true;
519 + while (entry) {
520 + buffer[count] = entry;
521 + if (!entry.isBuf) allBuffers = false;
522 + entry = entry.next;
523 + count += 1;
524 + }
525 + buffer.allBuffers = allBuffers;
526 +
527 + doWrite(stream, state, true, state.length, buffer, '', holder.finish);
528 +
529 + // doWrite is almost always async, defer these to save a bit of time
530 + // as the hot path ends with doWrite
531 + state.pendingcb++;
532 + state.lastBufferedRequest = null;
533 + if (holder.next) {
534 + state.corkedRequestsFree = holder.next;
535 + holder.next = null;
536 + } else {
537 + state.corkedRequestsFree = new CorkedRequest(state);
538 + }
539 + state.bufferedRequestCount = 0;
540 + } else {
541 + // Slow case, write chunks one-by-one
542 + while (entry) {
543 + var chunk = entry.chunk;
544 + var encoding = entry.encoding;
545 + var cb = entry.callback;
546 + var len = state.objectMode ? 1 : chunk.length;
547 +
548 + doWrite(stream, state, false, len, chunk, encoding, cb);
549 + entry = entry.next;
550 + state.bufferedRequestCount--;
551 + // if we didn't call the onwrite immediately, then
552 + // it means that we need to wait until it does.
553 + // also, that means that the chunk and cb are currently
554 + // being processed, so move the buffer counter past them.
555 + if (state.writing) {
556 + break;
557 + }
558 + }
559 +
560 + if (entry === null) state.lastBufferedRequest = null;
561 + }
562 +
563 + state.bufferedRequest = entry;
564 + state.bufferProcessing = false;
565 +}
566 +
567 +Writable.prototype._write = function (chunk, encoding, cb) {
568 + cb(new Error('_write() is not implemented'));
569 +};
570 +
571 +Writable.prototype._writev = null;
572 +
573 +Writable.prototype.end = function (chunk, encoding, cb) {
574 + var state = this._writableState;
575 +
576 + if (typeof chunk === 'function') {
577 + cb = chunk;
578 + chunk = null;
579 + encoding = null;
580 + } else if (typeof encoding === 'function') {
581 + cb = encoding;
582 + encoding = null;
583 + }
584 +
585 + if (chunk !== null && chunk !== undefined) this.write(chunk, encoding);
586 +
587 + // .end() fully uncorks
588 + if (state.corked) {
589 + state.corked = 1;
590 + this.uncork();
591 + }
592 +
593 + // ignore unnecessary end() calls.
594 + if (!state.ending && !state.finished) endWritable(this, state, cb);
595 +};
596 +
597 +function needFinish(state) {
598 + return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
599 +}
600 +function callFinal(stream, state) {
601 + stream._final(function (err) {
602 + state.pendingcb--;
603 + if (err) {
604 + stream.emit('error', err);
605 + }
606 + state.prefinished = true;
607 + stream.emit('prefinish');
608 + finishMaybe(stream, state);
609 + });
610 +}
611 +function prefinish(stream, state) {
612 + if (!state.prefinished && !state.finalCalled) {
613 + if (typeof stream._final === 'function') {
614 + state.pendingcb++;
615 + state.finalCalled = true;
616 + pna.nextTick(callFinal, stream, state);
617 + } else {
618 + state.prefinished = true;
619 + stream.emit('prefinish');
620 + }
621 + }
622 +}
623 +
624 +function finishMaybe(stream, state) {
625 + var need = needFinish(state);
626 + if (need) {
627 + prefinish(stream, state);
628 + if (state.pendingcb === 0) {
629 + state.finished = true;
630 + stream.emit('finish');
631 + }
632 + }
633 + return need;
634 +}
635 +
636 +function endWritable(stream, state, cb) {
637 + state.ending = true;
638 + finishMaybe(stream, state);
639 + if (cb) {
640 + if (state.finished) pna.nextTick(cb);else stream.once('finish', cb);
641 + }
642 + state.ended = true;
643 + stream.writable = false;
644 +}
645 +
646 +function onCorkedFinish(corkReq, state, err) {
647 + var entry = corkReq.entry;
648 + corkReq.entry = null;
649 + while (entry) {
650 + var cb = entry.callback;
651 + state.pendingcb--;
652 + cb(err);
653 + entry = entry.next;
654 + }
655 + if (state.corkedRequestsFree) {
656 + state.corkedRequestsFree.next = corkReq;
657 + } else {
658 + state.corkedRequestsFree = corkReq;
659 + }
660 +}
661 +
662 +Object.defineProperty(Writable.prototype, 'destroyed', {
663 + get: function () {
664 + if (this._writableState === undefined) {
665 + return false;
666 + }
667 + return this._writableState.destroyed;
668 + },
669 + set: function (value) {
670 + // we ignore the value if the stream
671 + // has not been initialized yet
672 + if (!this._writableState) {
673 + return;
674 + }
675 +
676 + // backward compatibility, the user is explicitly
677 + // managing destroyed
678 + this._writableState.destroyed = value;
679 + }
680 +});
681 +
682 +Writable.prototype.destroy = destroyImpl.destroy;
683 +Writable.prototype._undestroy = destroyImpl.undestroy;
684 +Writable.prototype._destroy = function (err, cb) {
685 + this.end();
686 + cb(err);
687 +};
...\ No newline at end of file ...\ No newline at end of file
1 +'use strict';
2 +
3 +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4 +
5 +var Buffer = require('safe-buffer').Buffer;
6 +var util = require('util');
7 +
8 +function copyBuffer(src, target, offset) {
9 + src.copy(target, offset);
10 +}
11 +
12 +module.exports = function () {
13 + function BufferList() {
14 + _classCallCheck(this, BufferList);
15 +
16 + this.head = null;
17 + this.tail = null;
18 + this.length = 0;
19 + }
20 +
21 + BufferList.prototype.push = function push(v) {
22 + var entry = { data: v, next: null };
23 + if (this.length > 0) this.tail.next = entry;else this.head = entry;
24 + this.tail = entry;
25 + ++this.length;
26 + };
27 +
28 + BufferList.prototype.unshift = function unshift(v) {
29 + var entry = { data: v, next: this.head };
30 + if (this.length === 0) this.tail = entry;
31 + this.head = entry;
32 + ++this.length;
33 + };
34 +
35 + BufferList.prototype.shift = function shift() {
36 + if (this.length === 0) return;
37 + var ret = this.head.data;
38 + if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next;
39 + --this.length;
40 + return ret;
41 + };
42 +
43 + BufferList.prototype.clear = function clear() {
44 + this.head = this.tail = null;
45 + this.length = 0;
46 + };
47 +
48 + BufferList.prototype.join = function join(s) {
49 + if (this.length === 0) return '';
50 + var p = this.head;
51 + var ret = '' + p.data;
52 + while (p = p.next) {
53 + ret += s + p.data;
54 + }return ret;
55 + };
56 +
57 + BufferList.prototype.concat = function concat(n) {
58 + if (this.length === 0) return Buffer.alloc(0);
59 + if (this.length === 1) return this.head.data;
60 + var ret = Buffer.allocUnsafe(n >>> 0);
61 + var p = this.head;
62 + var i = 0;
63 + while (p) {
64 + copyBuffer(p.data, ret, i);
65 + i += p.data.length;
66 + p = p.next;
67 + }
68 + return ret;
69 + };
70 +
71 + return BufferList;
72 +}();
73 +
74 +if (util && util.inspect && util.inspect.custom) {
75 + module.exports.prototype[util.inspect.custom] = function () {
76 + var obj = util.inspect({ length: this.length });
77 + return this.constructor.name + ' ' + obj;
78 + };
79 +}
...\ No newline at end of file ...\ No newline at end of file
1 +'use strict';
2 +
3 +/*<replacement>*/
4 +
5 +var pna = require('process-nextick-args');
6 +/*</replacement>*/
7 +
8 +// undocumented cb() API, needed for core, not for public API
9 +function destroy(err, cb) {
10 + var _this = this;
11 +
12 + var readableDestroyed = this._readableState && this._readableState.destroyed;
13 + var writableDestroyed = this._writableState && this._writableState.destroyed;
14 +
15 + if (readableDestroyed || writableDestroyed) {
16 + if (cb) {
17 + cb(err);
18 + } else if (err && (!this._writableState || !this._writableState.errorEmitted)) {
19 + pna.nextTick(emitErrorNT, this, err);
20 + }
21 + return this;
22 + }
23 +
24 + // we set destroyed to true before firing error callbacks in order
25 + // to make it re-entrance safe in case destroy() is called within callbacks
26 +
27 + if (this._readableState) {
28 + this._readableState.destroyed = true;
29 + }
30 +
31 + // if this is a duplex stream mark the writable part as destroyed as well
32 + if (this._writableState) {
33 + this._writableState.destroyed = true;
34 + }
35 +
36 + this._destroy(err || null, function (err) {
37 + if (!cb && err) {
38 + pna.nextTick(emitErrorNT, _this, err);
39 + if (_this._writableState) {
40 + _this._writableState.errorEmitted = true;
41 + }
42 + } else if (cb) {
43 + cb(err);
44 + }
45 + });
46 +
47 + return this;
48 +}
49 +
50 +function undestroy() {
51 + if (this._readableState) {
52 + this._readableState.destroyed = false;
53 + this._readableState.reading = false;
54 + this._readableState.ended = false;
55 + this._readableState.endEmitted = false;
56 + }
57 +
58 + if (this._writableState) {
59 + this._writableState.destroyed = false;
60 + this._writableState.ended = false;
61 + this._writableState.ending = false;
62 + this._writableState.finished = false;
63 + this._writableState.errorEmitted = false;
64 + }
65 +}
66 +
67 +function emitErrorNT(self, err) {
68 + self.emit('error', err);
69 +}
70 +
71 +module.exports = {
72 + destroy: destroy,
73 + undestroy: undestroy
74 +};
...\ No newline at end of file ...\ No newline at end of file
1 +module.exports = require('events').EventEmitter;
1 +{
2 + "_from": "readable-stream@2.3.7",
3 + "_id": "readable-stream@2.3.7",
4 + "_inBundle": false,
5 + "_integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==",
6 + "_location": "/readable-stream",
7 + "_phantomChildren": {},
8 + "_requested": {
9 + "type": "version",
10 + "registry": true,
11 + "raw": "readable-stream@2.3.7",
12 + "name": "readable-stream",
13 + "escapedName": "readable-stream",
14 + "rawSpec": "2.3.7",
15 + "saveSpec": null,
16 + "fetchSpec": "2.3.7"
17 + },
18 + "_requiredBy": [
19 + "/mysql"
20 + ],
21 + "_resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz",
22 + "_shasum": "1eca1cf711aef814c04f62252a36a62f6cb23b57",
23 + "_spec": "readable-stream@2.3.7",
24 + "_where": "C:\\Users\\user\\Desktop\\Singer-Composer\\node_modules\\mysql",
25 + "browser": {
26 + "util": false,
27 + "./readable.js": "./readable-browser.js",
28 + "./writable.js": "./writable-browser.js",
29 + "./duplex.js": "./duplex-browser.js",
30 + "./lib/internal/streams/stream.js": "./lib/internal/streams/stream-browser.js"
31 + },
32 + "bugs": {
33 + "url": "https://github.com/nodejs/readable-stream/issues"
34 + },
35 + "bundleDependencies": false,
36 + "dependencies": {
37 + "core-util-is": "~1.0.0",
38 + "inherits": "~2.0.3",
39 + "isarray": "~1.0.0",
40 + "process-nextick-args": "~2.0.0",
41 + "safe-buffer": "~5.1.1",
42 + "string_decoder": "~1.1.1",
43 + "util-deprecate": "~1.0.1"
44 + },
45 + "deprecated": false,
46 + "description": "Streams3, a user-land copy of the stream library from Node.js",
47 + "devDependencies": {
48 + "assert": "^1.4.0",
49 + "babel-polyfill": "^6.9.1",
50 + "buffer": "^4.9.0",
51 + "lolex": "^2.3.2",
52 + "nyc": "^6.4.0",
53 + "tap": "^0.7.0",
54 + "tape": "^4.8.0"
55 + },
56 + "homepage": "https://github.com/nodejs/readable-stream#readme",
57 + "keywords": [
58 + "readable",
59 + "stream",
60 + "pipe"
61 + ],
62 + "license": "MIT",
63 + "main": "readable.js",
64 + "name": "readable-stream",
65 + "nyc": {
66 + "include": [
67 + "lib/**.js"
68 + ]
69 + },
70 + "repository": {
71 + "type": "git",
72 + "url": "git://github.com/nodejs/readable-stream.git"
73 + },
74 + "scripts": {
75 + "ci": "tap test/parallel/*.js test/ours/*.js --tap | tee test.tap && node test/verify-dependencies.js",
76 + "cover": "nyc npm test",
77 + "report": "nyc report --reporter=lcov",
78 + "test": "tap test/parallel/*.js test/ours/*.js && node test/verify-dependencies.js"
79 + },
80 + "version": "2.3.7"
81 +}
1 +module.exports = require('./readable').PassThrough
1 +exports = module.exports = require('./lib/_stream_readable.js');
2 +exports.Stream = exports;
3 +exports.Readable = exports;
4 +exports.Writable = require('./lib/_stream_writable.js');
5 +exports.Duplex = require('./lib/_stream_duplex.js');
6 +exports.Transform = require('./lib/_stream_transform.js');
7 +exports.PassThrough = require('./lib/_stream_passthrough.js');
1 +var Stream = require('stream');
2 +if (process.env.READABLE_STREAM === 'disable' && Stream) {
3 + module.exports = Stream;
4 + exports = module.exports = Stream.Readable;
5 + exports.Readable = Stream.Readable;
6 + exports.Writable = Stream.Writable;
7 + exports.Duplex = Stream.Duplex;
8 + exports.Transform = Stream.Transform;
9 + exports.PassThrough = Stream.PassThrough;
10 + exports.Stream = Stream;
11 +} else {
12 + exports = module.exports = require('./lib/_stream_readable.js');
13 + exports.Stream = Stream || exports;
14 + exports.Readable = exports;
15 + exports.Writable = require('./lib/_stream_writable.js');
16 + exports.Duplex = require('./lib/_stream_duplex.js');
17 + exports.Transform = require('./lib/_stream_transform.js');
18 + exports.PassThrough = require('./lib/_stream_passthrough.js');
19 +}
1 +module.exports = require('./readable').Transform
1 +module.exports = require('./lib/_stream_writable.js');
1 +var Stream = require("stream")
2 +var Writable = require("./lib/_stream_writable.js")
3 +
4 +if (process.env.READABLE_STREAM === 'disable') {
5 + module.exports = Stream && Stream.Writable || Writable
6 +} else {
7 + module.exports = Writable
8 +}
1 +2.3.1 / 2018-02-24
2 +==================
3 +
4 + * Fix incorrectly replacing non-placeholders in SQL
5 +
6 +2.3.0 / 2017-10-01
7 +==================
8 +
9 + * Add `.toSqlString()` escape overriding
10 + * Add `raw` method to wrap raw strings for escape overriding
11 + * Small performance improvement on `escapeId`
12 +
13 +2.2.0 / 2016-11-01
14 +==================
15 +
16 + * Escape invalid `Date` objects as `NULL`
17 +
18 +2.1.0 / 2016-09-26
19 +==================
20 +
21 + * Accept numbers and other value types in `escapeId`
22 + * Run `buffer.toString()` through escaping
23 +
24 +2.0.1 / 2016-06-06
25 +==================
26 +
27 + * Fix npm package to include missing `lib/` directory
28 +
29 +2.0.0 / 2016-06-06
30 +==================
31 +
32 + * Bring repository up-to-date with `mysql` module changes
33 + * Support Node.js 0.6.x
34 +
35 +1.0.0 / 2014-11-09
36 +==================
37 +
38 + * Support Node.js 0.8.x
39 +
40 +0.0.1 / 2014-02-25
41 +==================
42 +
43 + * Initial release
1 +Copyright (c) 2012 Felix Geisendörfer (felix@debuggable.com) and contributors
2 +
3 + Permission is hereby granted, free of charge, to any person obtaining a copy
4 + of this software and associated documentation files (the "Software"), to deal
5 + in the Software without restriction, including without limitation the rights
6 + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 + copies of the Software, and to permit persons to whom the Software is
8 + furnished to do so, subject to the following conditions:
9 +
10 + The above copyright notice and this permission notice shall be included in
11 + all copies or substantial portions of the Software.
12 +
13 + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 + THE SOFTWARE.
1 +# sqlstring
2 +
3 +[![NPM Version][npm-version-image]][npm-url]
4 +[![NPM Downloads][npm-downloads-image]][npm-url]
5 +[![Node.js Version][node-image]][node-url]
6 +[![Build Status][travis-image]][travis-url]
7 +[![Coverage Status][coveralls-image]][coveralls-url]
8 +
9 +Simple SQL escape and format for MySQL
10 +
11 +## Install
12 +
13 +```sh
14 +$ npm install sqlstring
15 +```
16 +
17 +## Usage
18 +
19 +<!-- eslint-disable no-unused-vars -->
20 +
21 +```js
22 +var SqlString = require('sqlstring');
23 +```
24 +
25 +### Escaping query values
26 +
27 +**Caution** These methods of escaping values only works when the
28 +[NO_BACKSLASH_ESCAPES](https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sqlmode_no_backslash_escapes)
29 +SQL mode is disabled (which is the default state for MySQL servers).
30 +
31 +In order to avoid SQL Injection attacks, you should always escape any user
32 +provided data before using it inside a SQL query. You can do so using the
33 +`SqlString.escape()` method:
34 +
35 +```js
36 +var userId = 'some user provided value';
37 +var sql = 'SELECT * FROM users WHERE id = ' + SqlString.escape(userId);
38 +console.log(sql); // SELECT * FROM users WHERE id = 'some user provided value'
39 +```
40 +
41 +Alternatively, you can use `?` characters as placeholders for values you would
42 +like to have escaped like this:
43 +
44 +```js
45 +var userId = 1;
46 +var sql = SqlString.format('SELECT * FROM users WHERE id = ?', [userId]);
47 +console.log(sql); // SELECT * FROM users WHERE id = 1
48 +```
49 +
50 +Multiple placeholders are mapped to values in the same order as passed. For example,
51 +in the following query `foo` equals `a`, `bar` equals `b`, `baz` equals `c`, and
52 +`id` will be `userId`:
53 +
54 +```js
55 +var userId = 1;
56 +var sql = SqlString.format('UPDATE users SET foo = ?, bar = ?, baz = ? WHERE id = ?',
57 + ['a', 'b', 'c', userId]);
58 +console.log(sql); // UPDATE users SET foo = 'a', bar = 'b', baz = 'c' WHERE id = 1
59 +```
60 +
61 +This looks similar to prepared statements in MySQL, however it really just uses
62 +the same `SqlString.escape()` method internally.
63 +
64 +**Caution** This also differs from prepared statements in that all `?` are
65 +replaced, even those contained in comments and strings.
66 +
67 +Different value types are escaped differently, here is how:
68 +
69 +* Numbers are left untouched
70 +* Booleans are converted to `true` / `false`
71 +* Date objects are converted to `'YYYY-mm-dd HH:ii:ss'` strings
72 +* Buffers are converted to hex strings, e.g. `X'0fa5'`
73 +* Strings are safely escaped
74 +* Arrays are turned into list, e.g. `['a', 'b']` turns into `'a', 'b'`
75 +* Nested arrays are turned into grouped lists (for bulk inserts), e.g. `[['a',
76 + 'b'], ['c', 'd']]` turns into `('a', 'b'), ('c', 'd')`
77 +* Objects that have a `toSqlString` method will have `.toSqlString()` called
78 + and the returned value is used as the raw SQL.
79 +* Objects are turned into `key = 'val'` pairs for each enumerable property on
80 + the object. If the property's value is a function, it is skipped; if the
81 + property's value is an object, toString() is called on it and the returned
82 + value is used.
83 +* `undefined` / `null` are converted to `NULL`
84 +* `NaN` / `Infinity` are left as-is. MySQL does not support these, and trying
85 + to insert them as values will trigger MySQL errors until they implement
86 + support.
87 +
88 +You may have noticed that this escaping allows you to do neat things like this:
89 +
90 +```js
91 +var post = {id: 1, title: 'Hello MySQL'};
92 +var sql = SqlString.format('INSERT INTO posts SET ?', post);
93 +console.log(sql); // INSERT INTO posts SET `id` = 1, `title` = 'Hello MySQL'
94 +```
95 +
96 +And the `toSqlString` method allows you to form complex queries with functions:
97 +
98 +```js
99 +var CURRENT_TIMESTAMP = { toSqlString: function() { return 'CURRENT_TIMESTAMP()'; } };
100 +var sql = SqlString.format('UPDATE posts SET modified = ? WHERE id = ?', [CURRENT_TIMESTAMP, 42]);
101 +console.log(sql); // UPDATE posts SET modified = CURRENT_TIMESTAMP() WHERE id = 42
102 +```
103 +
104 +To generate objects with a `toSqlString` method, the `SqlString.raw()` method can
105 +be used. This creates an object that will be left un-touched when using in a `?`
106 +placeholder, useful for using functions as dynamic values:
107 +
108 +**Caution** The string provided to `SqlString.raw()` will skip all escaping
109 +functions when used, so be careful when passing in unvalidated input.
110 +
111 +```js
112 +var CURRENT_TIMESTAMP = SqlString.raw('CURRENT_TIMESTAMP()');
113 +var sql = SqlString.format('UPDATE posts SET modified = ? WHERE id = ?', [CURRENT_TIMESTAMP, 42]);
114 +console.log(sql); // UPDATE posts SET modified = CURRENT_TIMESTAMP() WHERE id = 42
115 +```
116 +
117 +If you feel the need to escape queries by yourself, you can also use the escaping
118 +function directly:
119 +
120 +```js
121 +var sql = 'SELECT * FROM posts WHERE title=' + SqlString.escape('Hello MySQL');
122 +console.log(sql); // SELECT * FROM posts WHERE title='Hello MySQL'
123 +```
124 +
125 +### Escaping query identifiers
126 +
127 +If you can't trust an SQL identifier (database / table / column name) because it is
128 +provided by a user, you should escape it with `SqlString.escapeId(identifier)` like this:
129 +
130 +```js
131 +var sorter = 'date';
132 +var sql = 'SELECT * FROM posts ORDER BY ' + SqlString.escapeId(sorter);
133 +console.log(sql); // SELECT * FROM posts ORDER BY `date`
134 +```
135 +
136 +It also supports adding qualified identifiers. It will escape both parts.
137 +
138 +```js
139 +var sorter = 'date';
140 +var sql = 'SELECT * FROM posts ORDER BY ' + SqlString.escapeId('posts.' + sorter);
141 +console.log(sql); // SELECT * FROM posts ORDER BY `posts`.`date`
142 +```
143 +
144 +If you do not want to treat `.` as qualified identifiers, you can set the second
145 +argument to `true` in order to keep the string as a literal identifier:
146 +
147 +```js
148 +var sorter = 'date.2';
149 +var sql = 'SELECT * FROM posts ORDER BY ' + SqlString.escapeId(sorter, true);
150 +console.log(sql); // SELECT * FROM posts ORDER BY `date.2`
151 +```
152 +
153 +Alternatively, you can use `??` characters as placeholders for identifiers you would
154 +like to have escaped like this:
155 +
156 +```js
157 +var userId = 1;
158 +var columns = ['username', 'email'];
159 +var sql = SqlString.format('SELECT ?? FROM ?? WHERE id = ?', [columns, 'users', userId]);
160 +console.log(sql); // SELECT `username`, `email` FROM `users` WHERE id = 1
161 +```
162 +**Please note that this last character sequence is experimental and syntax might change**
163 +
164 +When you pass an Object to `.escape()` or `.format()`, `.escapeId()` is used to avoid SQL injection in object keys.
165 +
166 +### Formatting queries
167 +
168 +You can use `SqlString.format` to prepare a query with multiple insertion points,
169 +utilizing the proper escaping for ids and values. A simple example of this follows:
170 +
171 +```js
172 +var userId = 1;
173 +var inserts = ['users', 'id', userId];
174 +var sql = SqlString.format('SELECT * FROM ?? WHERE ?? = ?', inserts);
175 +console.log(sql); // SELECT * FROM `users` WHERE `id` = 1
176 +```
177 +
178 +Following this you then have a valid, escaped query that you can then send to the database safely.
179 +This is useful if you are looking to prepare the query before actually sending it to the database.
180 +You also have the option (but are not required) to pass in `stringifyObject` and `timeZone`,
181 +allowing you provide a custom means of turning objects into strings, as well as a
182 +location-specific/timezone-aware `Date`.
183 +
184 +This can be further combined with the `SqlString.raw()` helper to generate SQL
185 +that includes MySQL functions as dynamic vales:
186 +
187 +```js
188 +var userId = 1;
189 +var data = { email: 'foobar@example.com', modified: SqlString.raw('NOW()') };
190 +var sql = SqlString.format('UPDATE ?? SET ? WHERE `id` = ?', ['users', data, userId]);
191 +console.log(sql); // UPDATE `users` SET `email` = 'foobar@example.com', `modified` = NOW() WHERE `id` = 1
192 +```
193 +
194 +## License
195 +
196 +[MIT](LICENSE)
197 +
198 +[npm-version-image]: https://img.shields.io/npm/v/sqlstring.svg
199 +[npm-downloads-image]: https://img.shields.io/npm/dm/sqlstring.svg
200 +[npm-url]: https://npmjs.org/package/sqlstring
201 +[travis-image]: https://img.shields.io/travis/mysqljs/sqlstring/master.svg
202 +[travis-url]: https://travis-ci.org/mysqljs/sqlstring
203 +[coveralls-image]: https://img.shields.io/coveralls/mysqljs/sqlstring/master.svg
204 +[coveralls-url]: https://coveralls.io/r/mysqljs/sqlstring?branch=master
205 +[node-image]: https://img.shields.io/node/v/sqlstring.svg
206 +[node-url]: https://nodejs.org/en/download
1 +module.exports = require('./lib/SqlString');
1 +var SqlString = exports;
2 +
3 +var ID_GLOBAL_REGEXP = /`/g;
4 +var QUAL_GLOBAL_REGEXP = /\./g;
5 +var CHARS_GLOBAL_REGEXP = /[\0\b\t\n\r\x1a\"\'\\]/g; // eslint-disable-line no-control-regex
6 +var CHARS_ESCAPE_MAP = {
7 + '\0' : '\\0',
8 + '\b' : '\\b',
9 + '\t' : '\\t',
10 + '\n' : '\\n',
11 + '\r' : '\\r',
12 + '\x1a' : '\\Z',
13 + '"' : '\\"',
14 + '\'' : '\\\'',
15 + '\\' : '\\\\'
16 +};
17 +
18 +SqlString.escapeId = function escapeId(val, forbidQualified) {
19 + if (Array.isArray(val)) {
20 + var sql = '';
21 +
22 + for (var i = 0; i < val.length; i++) {
23 + sql += (i === 0 ? '' : ', ') + SqlString.escapeId(val[i], forbidQualified);
24 + }
25 +
26 + return sql;
27 + } else if (forbidQualified) {
28 + return '`' + String(val).replace(ID_GLOBAL_REGEXP, '``') + '`';
29 + } else {
30 + return '`' + String(val).replace(ID_GLOBAL_REGEXP, '``').replace(QUAL_GLOBAL_REGEXP, '`.`') + '`';
31 + }
32 +};
33 +
34 +SqlString.escape = function escape(val, stringifyObjects, timeZone) {
35 + if (val === undefined || val === null) {
36 + return 'NULL';
37 + }
38 +
39 + switch (typeof val) {
40 + case 'boolean': return (val) ? 'true' : 'false';
41 + case 'number': return val + '';
42 + case 'object':
43 + if (val instanceof Date) {
44 + return SqlString.dateToString(val, timeZone || 'local');
45 + } else if (Array.isArray(val)) {
46 + return SqlString.arrayToList(val, timeZone);
47 + } else if (Buffer.isBuffer(val)) {
48 + return SqlString.bufferToString(val);
49 + } else if (typeof val.toSqlString === 'function') {
50 + return String(val.toSqlString());
51 + } else if (stringifyObjects) {
52 + return escapeString(val.toString());
53 + } else {
54 + return SqlString.objectToValues(val, timeZone);
55 + }
56 + default: return escapeString(val);
57 + }
58 +};
59 +
60 +SqlString.arrayToList = function arrayToList(array, timeZone) {
61 + var sql = '';
62 +
63 + for (var i = 0; i < array.length; i++) {
64 + var val = array[i];
65 +
66 + if (Array.isArray(val)) {
67 + sql += (i === 0 ? '' : ', ') + '(' + SqlString.arrayToList(val, timeZone) + ')';
68 + } else {
69 + sql += (i === 0 ? '' : ', ') + SqlString.escape(val, true, timeZone);
70 + }
71 + }
72 +
73 + return sql;
74 +};
75 +
76 +SqlString.format = function format(sql, values, stringifyObjects, timeZone) {
77 + if (values == null) {
78 + return sql;
79 + }
80 +
81 + if (!(values instanceof Array || Array.isArray(values))) {
82 + values = [values];
83 + }
84 +
85 + var chunkIndex = 0;
86 + var placeholdersRegex = /\?+/g;
87 + var result = '';
88 + var valuesIndex = 0;
89 + var match;
90 +
91 + while (valuesIndex < values.length && (match = placeholdersRegex.exec(sql))) {
92 + var len = match[0].length;
93 +
94 + if (len > 2) {
95 + continue;
96 + }
97 +
98 + var value = len === 2
99 + ? SqlString.escapeId(values[valuesIndex])
100 + : SqlString.escape(values[valuesIndex], stringifyObjects, timeZone);
101 +
102 + result += sql.slice(chunkIndex, match.index) + value;
103 + chunkIndex = placeholdersRegex.lastIndex;
104 + valuesIndex++;
105 + }
106 +
107 + if (chunkIndex === 0) {
108 + // Nothing was replaced
109 + return sql;
110 + }
111 +
112 + if (chunkIndex < sql.length) {
113 + return result + sql.slice(chunkIndex);
114 + }
115 +
116 + return result;
117 +};
118 +
119 +SqlString.dateToString = function dateToString(date, timeZone) {
120 + var dt = new Date(date);
121 +
122 + if (isNaN(dt.getTime())) {
123 + return 'NULL';
124 + }
125 +
126 + var year;
127 + var month;
128 + var day;
129 + var hour;
130 + var minute;
131 + var second;
132 + var millisecond;
133 +
134 + if (timeZone === 'local') {
135 + year = dt.getFullYear();
136 + month = dt.getMonth() + 1;
137 + day = dt.getDate();
138 + hour = dt.getHours();
139 + minute = dt.getMinutes();
140 + second = dt.getSeconds();
141 + millisecond = dt.getMilliseconds();
142 + } else {
143 + var tz = convertTimezone(timeZone);
144 +
145 + if (tz !== false && tz !== 0) {
146 + dt.setTime(dt.getTime() + (tz * 60000));
147 + }
148 +
149 + year = dt.getUTCFullYear();
150 + month = dt.getUTCMonth() + 1;
151 + day = dt.getUTCDate();
152 + hour = dt.getUTCHours();
153 + minute = dt.getUTCMinutes();
154 + second = dt.getUTCSeconds();
155 + millisecond = dt.getUTCMilliseconds();
156 + }
157 +
158 + // YYYY-MM-DD HH:mm:ss.mmm
159 + var str = zeroPad(year, 4) + '-' + zeroPad(month, 2) + '-' + zeroPad(day, 2) + ' ' +
160 + zeroPad(hour, 2) + ':' + zeroPad(minute, 2) + ':' + zeroPad(second, 2) + '.' +
161 + zeroPad(millisecond, 3);
162 +
163 + return escapeString(str);
164 +};
165 +
166 +SqlString.bufferToString = function bufferToString(buffer) {
167 + return 'X' + escapeString(buffer.toString('hex'));
168 +};
169 +
170 +SqlString.objectToValues = function objectToValues(object, timeZone) {
171 + var sql = '';
172 +
173 + for (var key in object) {
174 + var val = object[key];
175 +
176 + if (typeof val === 'function') {
177 + continue;
178 + }
179 +
180 + sql += (sql.length === 0 ? '' : ', ') + SqlString.escapeId(key) + ' = ' + SqlString.escape(val, true, timeZone);
181 + }
182 +
183 + return sql;
184 +};
185 +
186 +SqlString.raw = function raw(sql) {
187 + if (typeof sql !== 'string') {
188 + throw new TypeError('argument sql must be a string');
189 + }
190 +
191 + return {
192 + toSqlString: function toSqlString() { return sql; }
193 + };
194 +};
195 +
196 +function escapeString(val) {
197 + var chunkIndex = CHARS_GLOBAL_REGEXP.lastIndex = 0;
198 + var escapedVal = '';
199 + var match;
200 +
201 + while ((match = CHARS_GLOBAL_REGEXP.exec(val))) {
202 + escapedVal += val.slice(chunkIndex, match.index) + CHARS_ESCAPE_MAP[match[0]];
203 + chunkIndex = CHARS_GLOBAL_REGEXP.lastIndex;
204 + }
205 +
206 + if (chunkIndex === 0) {
207 + // Nothing was escaped
208 + return "'" + val + "'";
209 + }
210 +
211 + if (chunkIndex < val.length) {
212 + return "'" + escapedVal + val.slice(chunkIndex) + "'";
213 + }
214 +
215 + return "'" + escapedVal + "'";
216 +}
217 +
218 +function zeroPad(number, length) {
219 + number = number.toString();
220 + while (number.length < length) {
221 + number = '0' + number;
222 + }
223 +
224 + return number;
225 +}
226 +
227 +function convertTimezone(tz) {
228 + if (tz === 'Z') {
229 + return 0;
230 + }
231 +
232 + var m = tz.match(/([\+\-\s])(\d\d):?(\d\d)?/);
233 + if (m) {
234 + return (m[1] === '-' ? -1 : 1) * (parseInt(m[2], 10) + ((m[3] ? parseInt(m[3], 10) : 0) / 60)) * 60;
235 + }
236 + return false;
237 +}
1 +{
2 + "_from": "sqlstring@2.3.1",
3 + "_id": "sqlstring@2.3.1",
4 + "_inBundle": false,
5 + "_integrity": "sha1-R1OT/56RR5rqYtyvDKPRSYOn+0A=",
6 + "_location": "/sqlstring",
7 + "_phantomChildren": {},
8 + "_requested": {
9 + "type": "version",
10 + "registry": true,
11 + "raw": "sqlstring@2.3.1",
12 + "name": "sqlstring",
13 + "escapedName": "sqlstring",
14 + "rawSpec": "2.3.1",
15 + "saveSpec": null,
16 + "fetchSpec": "2.3.1"
17 + },
18 + "_requiredBy": [
19 + "/mysql"
20 + ],
21 + "_resolved": "https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.1.tgz",
22 + "_shasum": "475393ff9e91479aea62dcaf0ca3d14983a7fb40",
23 + "_spec": "sqlstring@2.3.1",
24 + "_where": "C:\\Users\\user\\Desktop\\Singer-Composer\\node_modules\\mysql",
25 + "bugs": {
26 + "url": "https://github.com/mysqljs/sqlstring/issues"
27 + },
28 + "bundleDependencies": false,
29 + "contributors": [
30 + {
31 + "name": "Adri Van Houdt",
32 + "email": "adri.van.houdt@gmail.com"
33 + },
34 + {
35 + "name": "Douglas Christopher Wilson",
36 + "email": "doug@somethingdoug.com"
37 + },
38 + {
39 + "name": "fengmk2",
40 + "email": "fengmk2@gmail.com",
41 + "url": "http://fengmk2.github.com"
42 + },
43 + {
44 + "name": "Kevin Jose Martin",
45 + "email": "kevin@tiliq.com"
46 + },
47 + {
48 + "name": "Nathan Woltman",
49 + "email": "nwoltman@outlook.com"
50 + },
51 + {
52 + "name": "Sergej Sintschilin",
53 + "email": "seregpie@gmail.com"
54 + }
55 + ],
56 + "deprecated": false,
57 + "description": "Simple SQL escape and format for MySQL",
58 + "devDependencies": {
59 + "beautify-benchmark": "0.2.4",
60 + "benchmark": "2.1.4",
61 + "eslint": "4.18.1",
62 + "eslint-plugin-markdown": "1.0.0-beta.6",
63 + "nyc": "10.3.2",
64 + "urun": "0.0.8",
65 + "utest": "0.0.8"
66 + },
67 + "engines": {
68 + "node": ">= 0.6"
69 + },
70 + "files": [
71 + "lib/",
72 + "HISTORY.md",
73 + "LICENSE",
74 + "README.md",
75 + "index.js"
76 + ],
77 + "homepage": "https://github.com/mysqljs/sqlstring#readme",
78 + "keywords": [
79 + "sqlstring",
80 + "sql",
81 + "escape",
82 + "sql escape"
83 + ],
84 + "license": "MIT",
85 + "name": "sqlstring",
86 + "repository": {
87 + "type": "git",
88 + "url": "git+https://github.com/mysqljs/sqlstring.git"
89 + },
90 + "scripts": {
91 + "bench": "node benchmark/index.js",
92 + "lint": "eslint --plugin markdown --ext js,md .",
93 + "test": "node test/run.js",
94 + "test-ci": "nyc --reporter=text npm test",
95 + "test-cov": "nyc --reporter=html --reporter=text npm test"
96 + },
97 + "version": "2.3.1"
98 +}
1 +sudo: false
2 +language: node_js
3 +before_install:
4 + - npm install -g npm@2
5 + - test $NPM_LEGACY && npm install -g npm@latest-3 || npm install npm -g
6 +notifications:
7 + email: false
8 +matrix:
9 + fast_finish: true
10 + include:
11 + - node_js: '0.8'
12 + env:
13 + - TASK=test
14 + - NPM_LEGACY=true
15 + - node_js: '0.10'
16 + env:
17 + - TASK=test
18 + - NPM_LEGACY=true
19 + - node_js: '0.11'
20 + env:
21 + - TASK=test
22 + - NPM_LEGACY=true
23 + - node_js: '0.12'
24 + env:
25 + - TASK=test
26 + - NPM_LEGACY=true
27 + - node_js: 1
28 + env:
29 + - TASK=test
30 + - NPM_LEGACY=true
31 + - node_js: 2
32 + env:
33 + - TASK=test
34 + - NPM_LEGACY=true
35 + - node_js: 3
36 + env:
37 + - TASK=test
38 + - NPM_LEGACY=true
39 + - node_js: 4
40 + env: TASK=test
41 + - node_js: 5
42 + env: TASK=test
43 + - node_js: 6
44 + env: TASK=test
45 + - node_js: 7
46 + env: TASK=test
47 + - node_js: 8
48 + env: TASK=test
49 + - node_js: 9
50 + env: TASK=test
1 +Node.js is licensed for use as follows:
2 +
3 +"""
4 +Copyright Node.js contributors. All rights reserved.
5 +
6 +Permission is hereby granted, free of charge, to any person obtaining a copy
7 +of this software and associated documentation files (the "Software"), to
8 +deal in the Software without restriction, including without limitation the
9 +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 +sell copies of the Software, and to permit persons to whom the Software is
11 +furnished to do so, subject to the following conditions:
12 +
13 +The above copyright notice and this permission notice shall be included in
14 +all copies or substantial portions of the Software.
15 +
16 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 +IN THE SOFTWARE.
23 +"""
24 +
25 +This license applies to parts of Node.js originating from the
26 +https://github.com/joyent/node repository:
27 +
28 +"""
29 +Copyright Joyent, Inc. and other Node contributors. All rights reserved.
30 +Permission is hereby granted, free of charge, to any person obtaining a copy
31 +of this software and associated documentation files (the "Software"), to
32 +deal in the Software without restriction, including without limitation the
33 +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
34 +sell copies of the Software, and to permit persons to whom the Software is
35 +furnished to do so, subject to the following conditions:
36 +
37 +The above copyright notice and this permission notice shall be included in
38 +all copies or substantial portions of the Software.
39 +
40 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
41 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
42 +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
43 +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
44 +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
45 +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
46 +IN THE SOFTWARE.
47 +"""
48 +
1 +# string_decoder
2 +
3 +***Node-core v8.9.4 string_decoder for userland***
4 +
5 +
6 +[![NPM](https://nodei.co/npm/string_decoder.png?downloads=true&downloadRank=true)](https://nodei.co/npm/string_decoder/)
7 +[![NPM](https://nodei.co/npm-dl/string_decoder.png?&months=6&height=3)](https://nodei.co/npm/string_decoder/)
8 +
9 +
10 +```bash
11 +npm install --save string_decoder
12 +```
13 +
14 +***Node-core string_decoder for userland***
15 +
16 +This package is a mirror of the string_decoder implementation in Node-core.
17 +
18 +Full documentation may be found on the [Node.js website](https://nodejs.org/dist/v8.9.4/docs/api/).
19 +
20 +As of version 1.0.0 **string_decoder** uses semantic versioning.
21 +
22 +## Previous versions
23 +
24 +Previous version numbers match the versions found in Node core, e.g. 0.10.24 matches Node 0.10.24, likewise 0.11.10 matches Node 0.11.10.
25 +
26 +## Update
27 +
28 +The *build/* directory contains a build script that will scrape the source from the [nodejs/node](https://github.com/nodejs/node) repo given a specific Node version.
29 +
30 +## Streams Working Group
31 +
32 +`string_decoder` is maintained by the Streams Working Group, which
33 +oversees the development and maintenance of the Streams API within
34 +Node.js. The responsibilities of the Streams Working Group include:
35 +
36 +* Addressing stream issues on the Node.js issue tracker.
37 +* Authoring and editing stream documentation within the Node.js project.
38 +* Reviewing changes to stream subclasses within the Node.js project.
39 +* Redirecting changes to streams from the Node.js project to this
40 + project.
41 +* Assisting in the implementation of stream providers within Node.js.
42 +* Recommending versions of `readable-stream` to be included in Node.js.
43 +* Messaging about the future of streams to give the community advance
44 + notice of changes.
45 +
46 +See [readable-stream](https://github.com/nodejs/readable-stream) for
47 +more details.
1 +// Copyright Joyent, Inc. and other Node contributors.
2 +//
3 +// Permission is hereby granted, free of charge, to any person obtaining a
4 +// copy of this software and associated documentation files (the
5 +// "Software"), to deal in the Software without restriction, including
6 +// without limitation the rights to use, copy, modify, merge, publish,
7 +// distribute, sublicense, and/or sell copies of the Software, and to permit
8 +// persons to whom the Software is furnished to do so, subject to the
9 +// following conditions:
10 +//
11 +// The above copyright notice and this permission notice shall be included
12 +// in all copies or substantial portions of the Software.
13 +//
14 +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17 +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 +// USE OR OTHER DEALINGS IN THE SOFTWARE.
21 +
22 +'use strict';
23 +
24 +/*<replacement>*/
25 +
26 +var Buffer = require('safe-buffer').Buffer;
27 +/*</replacement>*/
28 +
29 +var isEncoding = Buffer.isEncoding || function (encoding) {
30 + encoding = '' + encoding;
31 + switch (encoding && encoding.toLowerCase()) {
32 + case 'hex':case 'utf8':case 'utf-8':case 'ascii':case 'binary':case 'base64':case 'ucs2':case 'ucs-2':case 'utf16le':case 'utf-16le':case 'raw':
33 + return true;
34 + default:
35 + return false;
36 + }
37 +};
38 +
39 +function _normalizeEncoding(enc) {
40 + if (!enc) return 'utf8';
41 + var retried;
42 + while (true) {
43 + switch (enc) {
44 + case 'utf8':
45 + case 'utf-8':
46 + return 'utf8';
47 + case 'ucs2':
48 + case 'ucs-2':
49 + case 'utf16le':
50 + case 'utf-16le':
51 + return 'utf16le';
52 + case 'latin1':
53 + case 'binary':
54 + return 'latin1';
55 + case 'base64':
56 + case 'ascii':
57 + case 'hex':
58 + return enc;
59 + default:
60 + if (retried) return; // undefined
61 + enc = ('' + enc).toLowerCase();
62 + retried = true;
63 + }
64 + }
65 +};
66 +
67 +// Do not cache `Buffer.isEncoding` when checking encoding names as some
68 +// modules monkey-patch it to support additional encodings
69 +function normalizeEncoding(enc) {
70 + var nenc = _normalizeEncoding(enc);
71 + if (typeof nenc !== 'string' && (Buffer.isEncoding === isEncoding || !isEncoding(enc))) throw new Error('Unknown encoding: ' + enc);
72 + return nenc || enc;
73 +}
74 +
75 +// StringDecoder provides an interface for efficiently splitting a series of
76 +// buffers into a series of JS strings without breaking apart multi-byte
77 +// characters.
78 +exports.StringDecoder = StringDecoder;
79 +function StringDecoder(encoding) {
80 + this.encoding = normalizeEncoding(encoding);
81 + var nb;
82 + switch (this.encoding) {
83 + case 'utf16le':
84 + this.text = utf16Text;
85 + this.end = utf16End;
86 + nb = 4;
87 + break;
88 + case 'utf8':
89 + this.fillLast = utf8FillLast;
90 + nb = 4;
91 + break;
92 + case 'base64':
93 + this.text = base64Text;
94 + this.end = base64End;
95 + nb = 3;
96 + break;
97 + default:
98 + this.write = simpleWrite;
99 + this.end = simpleEnd;
100 + return;
101 + }
102 + this.lastNeed = 0;
103 + this.lastTotal = 0;
104 + this.lastChar = Buffer.allocUnsafe(nb);
105 +}
106 +
107 +StringDecoder.prototype.write = function (buf) {
108 + if (buf.length === 0) return '';
109 + var r;
110 + var i;
111 + if (this.lastNeed) {
112 + r = this.fillLast(buf);
113 + if (r === undefined) return '';
114 + i = this.lastNeed;
115 + this.lastNeed = 0;
116 + } else {
117 + i = 0;
118 + }
119 + if (i < buf.length) return r ? r + this.text(buf, i) : this.text(buf, i);
120 + return r || '';
121 +};
122 +
123 +StringDecoder.prototype.end = utf8End;
124 +
125 +// Returns only complete characters in a Buffer
126 +StringDecoder.prototype.text = utf8Text;
127 +
128 +// Attempts to complete a partial non-UTF-8 character using bytes from a Buffer
129 +StringDecoder.prototype.fillLast = function (buf) {
130 + if (this.lastNeed <= buf.length) {
131 + buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, this.lastNeed);
132 + return this.lastChar.toString(this.encoding, 0, this.lastTotal);
133 + }
134 + buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, buf.length);
135 + this.lastNeed -= buf.length;
136 +};
137 +
138 +// Checks the type of a UTF-8 byte, whether it's ASCII, a leading byte, or a
139 +// continuation byte. If an invalid byte is detected, -2 is returned.
140 +function utf8CheckByte(byte) {
141 + if (byte <= 0x7F) return 0;else if (byte >> 5 === 0x06) return 2;else if (byte >> 4 === 0x0E) return 3;else if (byte >> 3 === 0x1E) return 4;
142 + return byte >> 6 === 0x02 ? -1 : -2;
143 +}
144 +
145 +// Checks at most 3 bytes at the end of a Buffer in order to detect an
146 +// incomplete multi-byte UTF-8 character. The total number of bytes (2, 3, or 4)
147 +// needed to complete the UTF-8 character (if applicable) are returned.
148 +function utf8CheckIncomplete(self, buf, i) {
149 + var j = buf.length - 1;
150 + if (j < i) return 0;
151 + var nb = utf8CheckByte(buf[j]);
152 + if (nb >= 0) {
153 + if (nb > 0) self.lastNeed = nb - 1;
154 + return nb;
155 + }
156 + if (--j < i || nb === -2) return 0;
157 + nb = utf8CheckByte(buf[j]);
158 + if (nb >= 0) {
159 + if (nb > 0) self.lastNeed = nb - 2;
160 + return nb;
161 + }
162 + if (--j < i || nb === -2) return 0;
163 + nb = utf8CheckByte(buf[j]);
164 + if (nb >= 0) {
165 + if (nb > 0) {
166 + if (nb === 2) nb = 0;else self.lastNeed = nb - 3;
167 + }
168 + return nb;
169 + }
170 + return 0;
171 +}
172 +
173 +// Validates as many continuation bytes for a multi-byte UTF-8 character as
174 +// needed or are available. If we see a non-continuation byte where we expect
175 +// one, we "replace" the validated continuation bytes we've seen so far with
176 +// a single UTF-8 replacement character ('\ufffd'), to match v8's UTF-8 decoding
177 +// behavior. The continuation byte check is included three times in the case
178 +// where all of the continuation bytes for a character exist in the same buffer.
179 +// It is also done this way as a slight performance increase instead of using a
180 +// loop.
181 +function utf8CheckExtraBytes(self, buf, p) {
182 + if ((buf[0] & 0xC0) !== 0x80) {
183 + self.lastNeed = 0;
184 + return '\ufffd';
185 + }
186 + if (self.lastNeed > 1 && buf.length > 1) {
187 + if ((buf[1] & 0xC0) !== 0x80) {
188 + self.lastNeed = 1;
189 + return '\ufffd';
190 + }
191 + if (self.lastNeed > 2 && buf.length > 2) {
192 + if ((buf[2] & 0xC0) !== 0x80) {
193 + self.lastNeed = 2;
194 + return '\ufffd';
195 + }
196 + }
197 + }
198 +}
199 +
200 +// Attempts to complete a multi-byte UTF-8 character using bytes from a Buffer.
201 +function utf8FillLast(buf) {
202 + var p = this.lastTotal - this.lastNeed;
203 + var r = utf8CheckExtraBytes(this, buf, p);
204 + if (r !== undefined) return r;
205 + if (this.lastNeed <= buf.length) {
206 + buf.copy(this.lastChar, p, 0, this.lastNeed);
207 + return this.lastChar.toString(this.encoding, 0, this.lastTotal);
208 + }
209 + buf.copy(this.lastChar, p, 0, buf.length);
210 + this.lastNeed -= buf.length;
211 +}
212 +
213 +// Returns all complete UTF-8 characters in a Buffer. If the Buffer ended on a
214 +// partial character, the character's bytes are buffered until the required
215 +// number of bytes are available.
216 +function utf8Text(buf, i) {
217 + var total = utf8CheckIncomplete(this, buf, i);
218 + if (!this.lastNeed) return buf.toString('utf8', i);
219 + this.lastTotal = total;
220 + var end = buf.length - (total - this.lastNeed);
221 + buf.copy(this.lastChar, 0, end);
222 + return buf.toString('utf8', i, end);
223 +}
224 +
225 +// For UTF-8, a replacement character is added when ending on a partial
226 +// character.
227 +function utf8End(buf) {
228 + var r = buf && buf.length ? this.write(buf) : '';
229 + if (this.lastNeed) return r + '\ufffd';
230 + return r;
231 +}
232 +
233 +// UTF-16LE typically needs two bytes per character, but even if we have an even
234 +// number of bytes available, we need to check if we end on a leading/high
235 +// surrogate. In that case, we need to wait for the next two bytes in order to
236 +// decode the last character properly.
237 +function utf16Text(buf, i) {
238 + if ((buf.length - i) % 2 === 0) {
239 + var r = buf.toString('utf16le', i);
240 + if (r) {
241 + var c = r.charCodeAt(r.length - 1);
242 + if (c >= 0xD800 && c <= 0xDBFF) {
243 + this.lastNeed = 2;
244 + this.lastTotal = 4;
245 + this.lastChar[0] = buf[buf.length - 2];
246 + this.lastChar[1] = buf[buf.length - 1];
247 + return r.slice(0, -1);
248 + }
249 + }
250 + return r;
251 + }
252 + this.lastNeed = 1;
253 + this.lastTotal = 2;
254 + this.lastChar[0] = buf[buf.length - 1];
255 + return buf.toString('utf16le', i, buf.length - 1);
256 +}
257 +
258 +// For UTF-16LE we do not explicitly append special replacement characters if we
259 +// end on a partial character, we simply let v8 handle that.
260 +function utf16End(buf) {
261 + var r = buf && buf.length ? this.write(buf) : '';
262 + if (this.lastNeed) {
263 + var end = this.lastTotal - this.lastNeed;
264 + return r + this.lastChar.toString('utf16le', 0, end);
265 + }
266 + return r;
267 +}
268 +
269 +function base64Text(buf, i) {
270 + var n = (buf.length - i) % 3;
271 + if (n === 0) return buf.toString('base64', i);
272 + this.lastNeed = 3 - n;
273 + this.lastTotal = 3;
274 + if (n === 1) {
275 + this.lastChar[0] = buf[buf.length - 1];
276 + } else {
277 + this.lastChar[0] = buf[buf.length - 2];
278 + this.lastChar[1] = buf[buf.length - 1];
279 + }
280 + return buf.toString('base64', i, buf.length - n);
281 +}
282 +
283 +function base64End(buf) {
284 + var r = buf && buf.length ? this.write(buf) : '';
285 + if (this.lastNeed) return r + this.lastChar.toString('base64', 0, 3 - this.lastNeed);
286 + return r;
287 +}
288 +
289 +// Pass bytes on through for single-byte encodings (e.g. ascii, latin1, hex)
290 +function simpleWrite(buf) {
291 + return buf.toString(this.encoding);
292 +}
293 +
294 +function simpleEnd(buf) {
295 + return buf && buf.length ? this.write(buf) : '';
296 +}
...\ No newline at end of file ...\ No newline at end of file
1 +{
2 + "_from": "string_decoder@~1.1.1",
3 + "_id": "string_decoder@1.1.1",
4 + "_inBundle": false,
5 + "_integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
6 + "_location": "/string_decoder",
7 + "_phantomChildren": {},
8 + "_requested": {
9 + "type": "range",
10 + "registry": true,
11 + "raw": "string_decoder@~1.1.1",
12 + "name": "string_decoder",
13 + "escapedName": "string_decoder",
14 + "rawSpec": "~1.1.1",
15 + "saveSpec": null,
16 + "fetchSpec": "~1.1.1"
17 + },
18 + "_requiredBy": [
19 + "/readable-stream"
20 + ],
21 + "_resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
22 + "_shasum": "9cf1611ba62685d7030ae9e4ba34149c3af03fc8",
23 + "_spec": "string_decoder@~1.1.1",
24 + "_where": "C:\\Users\\user\\Desktop\\Singer-Composer\\node_modules\\readable-stream",
25 + "bugs": {
26 + "url": "https://github.com/nodejs/string_decoder/issues"
27 + },
28 + "bundleDependencies": false,
29 + "dependencies": {
30 + "safe-buffer": "~5.1.0"
31 + },
32 + "deprecated": false,
33 + "description": "The string_decoder module from Node core",
34 + "devDependencies": {
35 + "babel-polyfill": "^6.23.0",
36 + "core-util-is": "^1.0.2",
37 + "inherits": "^2.0.3",
38 + "tap": "~0.4.8"
39 + },
40 + "homepage": "https://github.com/nodejs/string_decoder",
41 + "keywords": [
42 + "string",
43 + "decoder",
44 + "browser",
45 + "browserify"
46 + ],
47 + "license": "MIT",
48 + "main": "lib/string_decoder.js",
49 + "name": "string_decoder",
50 + "repository": {
51 + "type": "git",
52 + "url": "git://github.com/nodejs/string_decoder.git"
53 + },
54 + "scripts": {
55 + "ci": "tap test/parallel/*.js test/ours/*.js --tap | tee test.tap && node test/verify-dependencies.js",
56 + "test": "tap test/parallel/*.js && node test/verify-dependencies"
57 + },
58 + "version": "1.1.1"
59 +}
1 +
2 +1.0.2 / 2015-10-07
3 +==================
4 +
5 + * use try/catch when checking `localStorage` (#3, @kumavis)
6 +
7 +1.0.1 / 2014-11-25
8 +==================
9 +
10 + * browser: use `console.warn()` for deprecation calls
11 + * browser: more jsdocs
12 +
13 +1.0.0 / 2014-04-30
14 +==================
15 +
16 + * initial commit
1 +(The MIT License)
2 +
3 +Copyright (c) 2014 Nathan Rajlich <nathan@tootallnate.net>
4 +
5 +Permission is hereby granted, free of charge, to any person
6 +obtaining a copy of this software and associated documentation
7 +files (the "Software"), to deal in the Software without
8 +restriction, including without limitation the rights to use,
9 +copy, modify, merge, publish, distribute, sublicense, and/or sell
10 +copies of the Software, and to permit persons to whom the
11 +Software is furnished to do so, subject to the following
12 +conditions:
13 +
14 +The above copyright notice and this permission notice shall be
15 +included in all copies or substantial portions of the Software.
16 +
17 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19 +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 +OTHER DEALINGS IN THE SOFTWARE.
1 +util-deprecate
2 +==============
3 +### The Node.js `util.deprecate()` function with browser support
4 +
5 +In Node.js, this module simply re-exports the `util.deprecate()` function.
6 +
7 +In the web browser (i.e. via browserify), a browser-specific implementation
8 +of the `util.deprecate()` function is used.
9 +
10 +
11 +## API
12 +
13 +A `deprecate()` function is the only thing exposed by this module.
14 +
15 +``` javascript
16 +// setup:
17 +exports.foo = deprecate(foo, 'foo() is deprecated, use bar() instead');
18 +
19 +
20 +// users see:
21 +foo();
22 +// foo() is deprecated, use bar() instead
23 +foo();
24 +foo();
25 +```
26 +
27 +
28 +## License
29 +
30 +(The MIT License)
31 +
32 +Copyright (c) 2014 Nathan Rajlich <nathan@tootallnate.net>
33 +
34 +Permission is hereby granted, free of charge, to any person
35 +obtaining a copy of this software and associated documentation
36 +files (the "Software"), to deal in the Software without
37 +restriction, including without limitation the rights to use,
38 +copy, modify, merge, publish, distribute, sublicense, and/or sell
39 +copies of the Software, and to permit persons to whom the
40 +Software is furnished to do so, subject to the following
41 +conditions:
42 +
43 +The above copyright notice and this permission notice shall be
44 +included in all copies or substantial portions of the Software.
45 +
46 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
47 +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
48 +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
49 +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
50 +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
51 +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
52 +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
53 +OTHER DEALINGS IN THE SOFTWARE.
1 +
2 +/**
3 + * Module exports.
4 + */
5 +
6 +module.exports = deprecate;
7 +
8 +/**
9 + * Mark that a method should not be used.
10 + * Returns a modified function which warns once by default.
11 + *
12 + * If `localStorage.noDeprecation = true` is set, then it is a no-op.
13 + *
14 + * If `localStorage.throwDeprecation = true` is set, then deprecated functions
15 + * will throw an Error when invoked.
16 + *
17 + * If `localStorage.traceDeprecation = true` is set, then deprecated functions
18 + * will invoke `console.trace()` instead of `console.error()`.
19 + *
20 + * @param {Function} fn - the function to deprecate
21 + * @param {String} msg - the string to print to the console when `fn` is invoked
22 + * @returns {Function} a new "deprecated" version of `fn`
23 + * @api public
24 + */
25 +
26 +function deprecate (fn, msg) {
27 + if (config('noDeprecation')) {
28 + return fn;
29 + }
30 +
31 + var warned = false;
32 + function deprecated() {
33 + if (!warned) {
34 + if (config('throwDeprecation')) {
35 + throw new Error(msg);
36 + } else if (config('traceDeprecation')) {
37 + console.trace(msg);
38 + } else {
39 + console.warn(msg);
40 + }
41 + warned = true;
42 + }
43 + return fn.apply(this, arguments);
44 + }
45 +
46 + return deprecated;
47 +}
48 +
49 +/**
50 + * Checks `localStorage` for boolean values for the given `name`.
51 + *
52 + * @param {String} name
53 + * @returns {Boolean}
54 + * @api private
55 + */
56 +
57 +function config (name) {
58 + // accessing global.localStorage can trigger a DOMException in sandboxed iframes
59 + try {
60 + if (!global.localStorage) return false;
61 + } catch (_) {
62 + return false;
63 + }
64 + var val = global.localStorage[name];
65 + if (null == val) return false;
66 + return String(val).toLowerCase() === 'true';
67 +}
1 +
2 +/**
3 + * For Node.js, simply re-export the core `util.deprecate` function.
4 + */
5 +
6 +module.exports = require('util').deprecate;
1 +{
2 + "_from": "util-deprecate@~1.0.1",
3 + "_id": "util-deprecate@1.0.2",
4 + "_inBundle": false,
5 + "_integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=",
6 + "_location": "/util-deprecate",
7 + "_phantomChildren": {},
8 + "_requested": {
9 + "type": "range",
10 + "registry": true,
11 + "raw": "util-deprecate@~1.0.1",
12 + "name": "util-deprecate",
13 + "escapedName": "util-deprecate",
14 + "rawSpec": "~1.0.1",
15 + "saveSpec": null,
16 + "fetchSpec": "~1.0.1"
17 + },
18 + "_requiredBy": [
19 + "/readable-stream"
20 + ],
21 + "_resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
22 + "_shasum": "450d4dc9fa70de732762fbd2d4a28981419a0ccf",
23 + "_spec": "util-deprecate@~1.0.1",
24 + "_where": "C:\\Users\\user\\Desktop\\Singer-Composer\\node_modules\\readable-stream",
25 + "author": {
26 + "name": "Nathan Rajlich",
27 + "email": "nathan@tootallnate.net",
28 + "url": "http://n8.io/"
29 + },
30 + "browser": "browser.js",
31 + "bugs": {
32 + "url": "https://github.com/TooTallNate/util-deprecate/issues"
33 + },
34 + "bundleDependencies": false,
35 + "deprecated": false,
36 + "description": "The Node.js `util.deprecate()` function with browser support",
37 + "homepage": "https://github.com/TooTallNate/util-deprecate",
38 + "keywords": [
39 + "util",
40 + "deprecate",
41 + "browserify",
42 + "browser",
43 + "node"
44 + ],
45 + "license": "MIT",
46 + "main": "node.js",
47 + "name": "util-deprecate",
48 + "repository": {
49 + "type": "git",
50 + "url": "git://github.com/TooTallNate/util-deprecate.git"
51 + },
52 + "scripts": {
53 + "test": "echo \"Error: no test specified\" && exit 1"
54 + },
55 + "version": "1.0.2"
56 +}
...@@ -138,6 +138,11 @@ ...@@ -138,6 +138,11 @@
138 "tweetnacl": "^0.14.3" 138 "tweetnacl": "^0.14.3"
139 } 139 }
140 }, 140 },
141 + "bignumber.js": {
142 + "version": "9.0.0",
143 + "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.0.0.tgz",
144 + "integrity": "sha512-t/OYhhJ2SD+YGBQcjY8GzzDHEk9f3nerxjtfa6tlMXfe7frs/WozhvCNoGvpM0P3bNf3Gq5ZRMlGr5f3r4/N8A=="
145 + },
141 "body-parser": { 146 "body-parser": {
142 "version": "1.19.0", 147 "version": "1.19.0",
143 "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.0.tgz", 148 "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.0.tgz",
...@@ -250,8 +255,7 @@ ...@@ -250,8 +255,7 @@
250 "core-util-is": { 255 "core-util-is": {
251 "version": "1.0.2", 256 "version": "1.0.2",
252 "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", 257 "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
253 - "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", 258 + "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac="
254 - "dev": true
255 }, 259 },
256 "cssom": { 260 "cssom": {
257 "version": "0.3.8", 261 "version": "0.3.8",
...@@ -652,6 +656,11 @@ ...@@ -652,6 +656,11 @@
652 "integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=", 656 "integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=",
653 "dev": true 657 "dev": true
654 }, 658 },
659 + "isarray": {
660 + "version": "1.0.0",
661 + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
662 + "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE="
663 + },
655 "isstream": { 664 "isstream": {
656 "version": "0.1.2", 665 "version": "0.1.2",
657 "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", 666 "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz",
...@@ -822,6 +831,17 @@ ...@@ -822,6 +831,17 @@
822 "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", 831 "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
823 "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" 832 "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
824 }, 833 },
834 + "mysql": {
835 + "version": "2.18.1",
836 + "resolved": "https://registry.npmjs.org/mysql/-/mysql-2.18.1.tgz",
837 + "integrity": "sha512-Bca+gk2YWmqp2Uf6k5NFEurwY/0td0cpebAucFpY/3jhrwrVGuxU2uQFCHjU19SJfje0yQvi+rVWdq78hR5lig==",
838 + "requires": {
839 + "bignumber.js": "9.0.0",
840 + "readable-stream": "2.3.7",
841 + "safe-buffer": "5.1.2",
842 + "sqlstring": "2.3.1"
843 + }
844 + },
825 "negotiator": { 845 "negotiator": {
826 "version": "0.6.2", 846 "version": "0.6.2",
827 "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz", 847 "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz",
...@@ -932,6 +952,11 @@ ...@@ -932,6 +952,11 @@
932 "integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=", 952 "integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=",
933 "dev": true 953 "dev": true
934 }, 954 },
955 + "process-nextick-args": {
956 + "version": "2.0.1",
957 + "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz",
958 + "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag=="
959 + },
935 "proxy-addr": { 960 "proxy-addr": {
936 "version": "2.0.7", 961 "version": "2.0.7",
937 "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", 962 "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz",
...@@ -980,6 +1005,20 @@ ...@@ -980,6 +1005,20 @@
980 "unpipe": "1.0.0" 1005 "unpipe": "1.0.0"
981 } 1006 }
982 }, 1007 },
1008 + "readable-stream": {
1009 + "version": "2.3.7",
1010 + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz",
1011 + "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==",
1012 + "requires": {
1013 + "core-util-is": "~1.0.0",
1014 + "inherits": "~2.0.3",
1015 + "isarray": "~1.0.0",
1016 + "process-nextick-args": "~2.0.0",
1017 + "safe-buffer": "~5.1.1",
1018 + "string_decoder": "~1.1.1",
1019 + "util-deprecate": "~1.0.1"
1020 + }
1021 + },
983 "request": { 1022 "request": {
984 "version": "2.88.2", 1023 "version": "2.88.2",
985 "resolved": "https://registry.npmjs.org/request/-/request-2.88.2.tgz", 1024 "resolved": "https://registry.npmjs.org/request/-/request-2.88.2.tgz",
...@@ -1102,6 +1141,11 @@ ...@@ -1102,6 +1141,11 @@
1102 "dev": true, 1141 "dev": true,
1103 "optional": true 1142 "optional": true
1104 }, 1143 },
1144 + "sqlstring": {
1145 + "version": "2.3.1",
1146 + "resolved": "https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.1.tgz",
1147 + "integrity": "sha1-R1OT/56RR5rqYtyvDKPRSYOn+0A="
1148 + },
1105 "sshpk": { 1149 "sshpk": {
1106 "version": "1.16.1", 1150 "version": "1.16.1",
1107 "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.16.1.tgz", 1151 "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.16.1.tgz",
...@@ -1130,6 +1174,14 @@ ...@@ -1130,6 +1174,14 @@
1130 "integrity": "sha1-NbCYdbT/SfJqd35QmzCQoyJr8ks=", 1174 "integrity": "sha1-NbCYdbT/SfJqd35QmzCQoyJr8ks=",
1131 "dev": true 1175 "dev": true
1132 }, 1176 },
1177 + "string_decoder": {
1178 + "version": "1.1.1",
1179 + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
1180 + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
1181 + "requires": {
1182 + "safe-buffer": "~5.1.0"
1183 + }
1184 + },
1133 "supports-color": { 1185 "supports-color": {
1134 "version": "5.5.0", 1186 "version": "5.5.0",
1135 "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", 1187 "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
...@@ -1224,6 +1276,11 @@ ...@@ -1224,6 +1276,11 @@
1224 "punycode": "^2.1.0" 1276 "punycode": "^2.1.0"
1225 } 1277 }
1226 }, 1278 },
1279 + "util-deprecate": {
1280 + "version": "1.0.2",
1281 + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
1282 + "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8="
1283 + },
1227 "utils-merge": { 1284 "utils-merge": {
1228 "version": "1.0.1", 1285 "version": "1.0.1",
1229 "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", 1286 "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz",
......
...@@ -10,7 +10,8 @@ ...@@ -10,7 +10,8 @@
10 "license": "ISC", 10 "license": "ISC",
11 "dependencies": { 11 "dependencies": {
12 "ejs": "^3.1.6", 12 "ejs": "^3.1.6",
13 - "express": "^4.17.1" 13 + "express": "^4.17.1",
14 + "mysql": "^2.18.1"
14 }, 15 },
15 "devDependencies": { 16 "devDependencies": {
16 "connect-flash": "^0.1.1", 17 "connect-flash": "^0.1.1",
......