[Service] Integrate DeviceHome and SignalingServer
[platform/framework/web/wrtjs.git] / device_home / node_modules / qrcode / build / qrcode.js
1 (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.QRCode = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
2 // can-promise has a crash in some versions of react native that dont have
3 // standard global objects
4 // https://github.com/soldair/node-qrcode/issues/157
5
6 module.exports = function () {
7   return typeof Promise === 'function' && Promise.prototype && Promise.prototype.then
8 }
9
10 },{}],2:[function(require,module,exports){
11 /**
12  * Alignment pattern are fixed reference pattern in defined positions
13  * in a matrix symbology, which enables the decode software to re-synchronise
14  * the coordinate mapping of the image modules in the event of moderate amounts
15  * of distortion of the image.
16  *
17  * Alignment patterns are present only in QR Code symbols of version 2 or larger
18  * and their number depends on the symbol version.
19  */
20
21 var getSymbolSize = require('./utils').getSymbolSize
22
23 /**
24  * Calculate the row/column coordinates of the center module of each alignment pattern
25  * for the specified QR Code version.
26  *
27  * The alignment patterns are positioned symmetrically on either side of the diagonal
28  * running from the top left corner of the symbol to the bottom right corner.
29  *
30  * Since positions are simmetrical only half of the coordinates are returned.
31  * Each item of the array will represent in turn the x and y coordinate.
32  * @see {@link getPositions}
33  *
34  * @param  {Number} version QR Code version
35  * @return {Array}          Array of coordinate
36  */
37 exports.getRowColCoords = function getRowColCoords (version) {
38   if (version === 1) return []
39
40   var posCount = Math.floor(version / 7) + 2
41   var size = getSymbolSize(version)
42   var intervals = size === 145 ? 26 : Math.ceil((size - 13) / (2 * posCount - 2)) * 2
43   var positions = [size - 7] // Last coord is always (size - 7)
44
45   for (var i = 1; i < posCount - 1; i++) {
46     positions[i] = positions[i - 1] - intervals
47   }
48
49   positions.push(6) // First coord is always 6
50
51   return positions.reverse()
52 }
53
54 /**
55  * Returns an array containing the positions of each alignment pattern.
56  * Each array's element represent the center point of the pattern as (x, y) coordinates
57  *
58  * Coordinates are calculated expanding the row/column coordinates returned by {@link getRowColCoords}
59  * and filtering out the items that overlaps with finder pattern
60  *
61  * @example
62  * For a Version 7 symbol {@link getRowColCoords} returns values 6, 22 and 38.
63  * The alignment patterns, therefore, are to be centered on (row, column)
64  * positions (6,22), (22,6), (22,22), (22,38), (38,22), (38,38).
65  * Note that the coordinates (6,6), (6,38), (38,6) are occupied by finder patterns
66  * and are not therefore used for alignment patterns.
67  *
68  * var pos = getPositions(7)
69  * // [[6,22], [22,6], [22,22], [22,38], [38,22], [38,38]]
70  *
71  * @param  {Number} version QR Code version
72  * @return {Array}          Array of coordinates
73  */
74 exports.getPositions = function getPositions (version) {
75   var coords = []
76   var pos = exports.getRowColCoords(version)
77   var posLength = pos.length
78
79   for (var i = 0; i < posLength; i++) {
80     for (var j = 0; j < posLength; j++) {
81       // Skip if position is occupied by finder patterns
82       if ((i === 0 && j === 0) ||             // top-left
83           (i === 0 && j === posLength - 1) || // bottom-left
84           (i === posLength - 1 && j === 0)) { // top-right
85         continue
86       }
87
88       coords.push([pos[i], pos[j]])
89     }
90   }
91
92   return coords
93 }
94
95 },{"./utils":21}],3:[function(require,module,exports){
96 var Mode = require('./mode')
97
98 /**
99  * Array of characters available in alphanumeric mode
100  *
101  * As per QR Code specification, to each character
102  * is assigned a value from 0 to 44 which in this case coincides
103  * with the array index
104  *
105  * @type {Array}
106  */
107 var ALPHA_NUM_CHARS = [
108   '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
109   'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
110   'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
111   ' ', '$', '%', '*', '+', '-', '.', '/', ':'
112 ]
113
114 function AlphanumericData (data) {
115   this.mode = Mode.ALPHANUMERIC
116   this.data = data
117 }
118
119 AlphanumericData.getBitsLength = function getBitsLength (length) {
120   return 11 * Math.floor(length / 2) + 6 * (length % 2)
121 }
122
123 AlphanumericData.prototype.getLength = function getLength () {
124   return this.data.length
125 }
126
127 AlphanumericData.prototype.getBitsLength = function getBitsLength () {
128   return AlphanumericData.getBitsLength(this.data.length)
129 }
130
131 AlphanumericData.prototype.write = function write (bitBuffer) {
132   var i
133
134   // Input data characters are divided into groups of two characters
135   // and encoded as 11-bit binary codes.
136   for (i = 0; i + 2 <= this.data.length; i += 2) {
137     // The character value of the first character is multiplied by 45
138     var value = ALPHA_NUM_CHARS.indexOf(this.data[i]) * 45
139
140     // The character value of the second digit is added to the product
141     value += ALPHA_NUM_CHARS.indexOf(this.data[i + 1])
142
143     // The sum is then stored as 11-bit binary number
144     bitBuffer.put(value, 11)
145   }
146
147   // If the number of input data characters is not a multiple of two,
148   // the character value of the final character is encoded as a 6-bit binary number.
149   if (this.data.length % 2) {
150     bitBuffer.put(ALPHA_NUM_CHARS.indexOf(this.data[i]), 6)
151   }
152 }
153
154 module.exports = AlphanumericData
155
156 },{"./mode":14}],4:[function(require,module,exports){
157 function BitBuffer () {
158   this.buffer = []
159   this.length = 0
160 }
161
162 BitBuffer.prototype = {
163
164   get: function (index) {
165     var bufIndex = Math.floor(index / 8)
166     return ((this.buffer[bufIndex] >>> (7 - index % 8)) & 1) === 1
167   },
168
169   put: function (num, length) {
170     for (var i = 0; i < length; i++) {
171       this.putBit(((num >>> (length - i - 1)) & 1) === 1)
172     }
173   },
174
175   getLengthInBits: function () {
176     return this.length
177   },
178
179   putBit: function (bit) {
180     var bufIndex = Math.floor(this.length / 8)
181     if (this.buffer.length <= bufIndex) {
182       this.buffer.push(0)
183     }
184
185     if (bit) {
186       this.buffer[bufIndex] |= (0x80 >>> (this.length % 8))
187     }
188
189     this.length++
190   }
191 }
192
193 module.exports = BitBuffer
194
195 },{}],5:[function(require,module,exports){
196 var BufferUtil = require('../utils/buffer')
197
198 /**
199  * Helper class to handle QR Code symbol modules
200  *
201  * @param {Number} size Symbol size
202  */
203 function BitMatrix (size) {
204   if (!size || size < 1) {
205     throw new Error('BitMatrix size must be defined and greater than 0')
206   }
207
208   this.size = size
209   this.data = BufferUtil.alloc(size * size)
210   this.reservedBit = BufferUtil.alloc(size * size)
211 }
212
213 /**
214  * Set bit value at specified location
215  * If reserved flag is set, this bit will be ignored during masking process
216  *
217  * @param {Number}  row
218  * @param {Number}  col
219  * @param {Boolean} value
220  * @param {Boolean} reserved
221  */
222 BitMatrix.prototype.set = function (row, col, value, reserved) {
223   var index = row * this.size + col
224   this.data[index] = value
225   if (reserved) this.reservedBit[index] = true
226 }
227
228 /**
229  * Returns bit value at specified location
230  *
231  * @param  {Number}  row
232  * @param  {Number}  col
233  * @return {Boolean}
234  */
235 BitMatrix.prototype.get = function (row, col) {
236   return this.data[row * this.size + col]
237 }
238
239 /**
240  * Applies xor operator at specified location
241  * (used during masking process)
242  *
243  * @param {Number}  row
244  * @param {Number}  col
245  * @param {Boolean} value
246  */
247 BitMatrix.prototype.xor = function (row, col, value) {
248   this.data[row * this.size + col] ^= value
249 }
250
251 /**
252  * Check if bit at specified location is reserved
253  *
254  * @param {Number}   row
255  * @param {Number}   col
256  * @return {Boolean}
257  */
258 BitMatrix.prototype.isReserved = function (row, col) {
259   return this.reservedBit[row * this.size + col]
260 }
261
262 module.exports = BitMatrix
263
264 },{"../utils/buffer":28}],6:[function(require,module,exports){
265 var BufferUtil = require('../utils/buffer')
266 var Mode = require('./mode')
267
268 function ByteData (data) {
269   this.mode = Mode.BYTE
270   this.data = BufferUtil.from(data)
271 }
272
273 ByteData.getBitsLength = function getBitsLength (length) {
274   return length * 8
275 }
276
277 ByteData.prototype.getLength = function getLength () {
278   return this.data.length
279 }
280
281 ByteData.prototype.getBitsLength = function getBitsLength () {
282   return ByteData.getBitsLength(this.data.length)
283 }
284
285 ByteData.prototype.write = function (bitBuffer) {
286   for (var i = 0, l = this.data.length; i < l; i++) {
287     bitBuffer.put(this.data[i], 8)
288   }
289 }
290
291 module.exports = ByteData
292
293 },{"../utils/buffer":28,"./mode":14}],7:[function(require,module,exports){
294 var ECLevel = require('./error-correction-level')\r
295 \r
296 var EC_BLOCKS_TABLE = [\r
297 // L  M  Q  H\r
298   1, 1, 1, 1,\r
299   1, 1, 1, 1,\r
300   1, 1, 2, 2,\r
301   1, 2, 2, 4,\r
302   1, 2, 4, 4,\r
303   2, 4, 4, 4,\r
304   2, 4, 6, 5,\r
305   2, 4, 6, 6,\r
306   2, 5, 8, 8,\r
307   4, 5, 8, 8,\r
308   4, 5, 8, 11,\r
309   4, 8, 10, 11,\r
310   4, 9, 12, 16,\r
311   4, 9, 16, 16,\r
312   6, 10, 12, 18,\r
313   6, 10, 17, 16,\r
314   6, 11, 16, 19,\r
315   6, 13, 18, 21,\r
316   7, 14, 21, 25,\r
317   8, 16, 20, 25,\r
318   8, 17, 23, 25,\r
319   9, 17, 23, 34,\r
320   9, 18, 25, 30,\r
321   10, 20, 27, 32,\r
322   12, 21, 29, 35,\r
323   12, 23, 34, 37,\r
324   12, 25, 34, 40,\r
325   13, 26, 35, 42,\r
326   14, 28, 38, 45,\r
327   15, 29, 40, 48,\r
328   16, 31, 43, 51,\r
329   17, 33, 45, 54,\r
330   18, 35, 48, 57,\r
331   19, 37, 51, 60,\r
332   19, 38, 53, 63,\r
333   20, 40, 56, 66,\r
334   21, 43, 59, 70,\r
335   22, 45, 62, 74,\r
336   24, 47, 65, 77,\r
337   25, 49, 68, 81\r
338 ]\r
339 \r
340 var EC_CODEWORDS_TABLE = [\r
341 // L  M  Q  H\r
342   7, 10, 13, 17,\r
343   10, 16, 22, 28,\r
344   15, 26, 36, 44,\r
345   20, 36, 52, 64,\r
346   26, 48, 72, 88,\r
347   36, 64, 96, 112,\r
348   40, 72, 108, 130,\r
349   48, 88, 132, 156,\r
350   60, 110, 160, 192,\r
351   72, 130, 192, 224,\r
352   80, 150, 224, 264,\r
353   96, 176, 260, 308,\r
354   104, 198, 288, 352,\r
355   120, 216, 320, 384,\r
356   132, 240, 360, 432,\r
357   144, 280, 408, 480,\r
358   168, 308, 448, 532,\r
359   180, 338, 504, 588,\r
360   196, 364, 546, 650,\r
361   224, 416, 600, 700,\r
362   224, 442, 644, 750,\r
363   252, 476, 690, 816,\r
364   270, 504, 750, 900,\r
365   300, 560, 810, 960,\r
366   312, 588, 870, 1050,\r
367   336, 644, 952, 1110,\r
368   360, 700, 1020, 1200,\r
369   390, 728, 1050, 1260,\r
370   420, 784, 1140, 1350,\r
371   450, 812, 1200, 1440,\r
372   480, 868, 1290, 1530,\r
373   510, 924, 1350, 1620,\r
374   540, 980, 1440, 1710,\r
375   570, 1036, 1530, 1800,\r
376   570, 1064, 1590, 1890,\r
377   600, 1120, 1680, 1980,\r
378   630, 1204, 1770, 2100,\r
379   660, 1260, 1860, 2220,\r
380   720, 1316, 1950, 2310,\r
381   750, 1372, 2040, 2430\r
382 ]\r
383 \r
384 /**\r
385  * Returns the number of error correction block that the QR Code should contain\r
386  * for the specified version and error correction level.\r
387  *\r
388  * @param  {Number} version              QR Code version\r
389  * @param  {Number} errorCorrectionLevel Error correction level\r
390  * @return {Number}                      Number of error correction blocks\r
391  */\r
392 exports.getBlocksCount = function getBlocksCount (version, errorCorrectionLevel) {\r
393   switch (errorCorrectionLevel) {\r
394     case ECLevel.L:\r
395       return EC_BLOCKS_TABLE[(version - 1) * 4 + 0]\r
396     case ECLevel.M:\r
397       return EC_BLOCKS_TABLE[(version - 1) * 4 + 1]\r
398     case ECLevel.Q:\r
399       return EC_BLOCKS_TABLE[(version - 1) * 4 + 2]\r
400     case ECLevel.H:\r
401       return EC_BLOCKS_TABLE[(version - 1) * 4 + 3]\r
402     default:\r
403       return undefined\r
404   }\r
405 }\r
406 \r
407 /**\r
408  * Returns the number of error correction codewords to use for the specified\r
409  * version and error correction level.\r
410  *\r
411  * @param  {Number} version              QR Code version\r
412  * @param  {Number} errorCorrectionLevel Error correction level\r
413  * @return {Number}                      Number of error correction codewords\r
414  */\r
415 exports.getTotalCodewordsCount = function getTotalCodewordsCount (version, errorCorrectionLevel) {\r
416   switch (errorCorrectionLevel) {\r
417     case ECLevel.L:\r
418       return EC_CODEWORDS_TABLE[(version - 1) * 4 + 0]\r
419     case ECLevel.M:\r
420       return EC_CODEWORDS_TABLE[(version - 1) * 4 + 1]\r
421     case ECLevel.Q:\r
422       return EC_CODEWORDS_TABLE[(version - 1) * 4 + 2]\r
423     case ECLevel.H:\r
424       return EC_CODEWORDS_TABLE[(version - 1) * 4 + 3]\r
425     default:\r
426       return undefined\r
427   }\r
428 }\r
429
430 },{"./error-correction-level":8}],8:[function(require,module,exports){
431 exports.L = { bit: 1 }
432 exports.M = { bit: 0 }
433 exports.Q = { bit: 3 }
434 exports.H = { bit: 2 }
435
436 function fromString (string) {
437   if (typeof string !== 'string') {
438     throw new Error('Param is not a string')
439   }
440
441   var lcStr = string.toLowerCase()
442
443   switch (lcStr) {
444     case 'l':
445     case 'low':
446       return exports.L
447
448     case 'm':
449     case 'medium':
450       return exports.M
451
452     case 'q':
453     case 'quartile':
454       return exports.Q
455
456     case 'h':
457     case 'high':
458       return exports.H
459
460     default:
461       throw new Error('Unknown EC Level: ' + string)
462   }
463 }
464
465 exports.isValid = function isValid (level) {
466   return level && typeof level.bit !== 'undefined' &&
467     level.bit >= 0 && level.bit < 4
468 }
469
470 exports.from = function from (value, defaultValue) {
471   if (exports.isValid(value)) {
472     return value
473   }
474
475   try {
476     return fromString(value)
477   } catch (e) {
478     return defaultValue
479   }
480 }
481
482 },{}],9:[function(require,module,exports){
483 var getSymbolSize = require('./utils').getSymbolSize
484 var FINDER_PATTERN_SIZE = 7
485
486 /**
487  * Returns an array containing the positions of each finder pattern.
488  * Each array's element represent the top-left point of the pattern as (x, y) coordinates
489  *
490  * @param  {Number} version QR Code version
491  * @return {Array}          Array of coordinates
492  */
493 exports.getPositions = function getPositions (version) {
494   var size = getSymbolSize(version)
495
496   return [
497     // top-left
498     [0, 0],
499     // top-right
500     [size - FINDER_PATTERN_SIZE, 0],
501     // bottom-left
502     [0, size - FINDER_PATTERN_SIZE]
503   ]
504 }
505
506 },{"./utils":21}],10:[function(require,module,exports){
507 var Utils = require('./utils')
508
509 var G15 = (1 << 10) | (1 << 8) | (1 << 5) | (1 << 4) | (1 << 2) | (1 << 1) | (1 << 0)
510 var G15_MASK = (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1)
511 var G15_BCH = Utils.getBCHDigit(G15)
512
513 /**
514  * Returns format information with relative error correction bits
515  *
516  * The format information is a 15-bit sequence containing 5 data bits,
517  * with 10 error correction bits calculated using the (15, 5) BCH code.
518  *
519  * @param  {Number} errorCorrectionLevel Error correction level
520  * @param  {Number} mask                 Mask pattern
521  * @return {Number}                      Encoded format information bits
522  */
523 exports.getEncodedBits = function getEncodedBits (errorCorrectionLevel, mask) {
524   var data = ((errorCorrectionLevel.bit << 3) | mask)
525   var d = data << 10
526
527   while (Utils.getBCHDigit(d) - G15_BCH >= 0) {
528     d ^= (G15 << (Utils.getBCHDigit(d) - G15_BCH))
529   }
530
531   // xor final data with mask pattern in order to ensure that
532   // no combination of Error Correction Level and data mask pattern
533   // will result in an all-zero data string
534   return ((data << 10) | d) ^ G15_MASK
535 }
536
537 },{"./utils":21}],11:[function(require,module,exports){
538 var BufferUtil = require('../utils/buffer')
539
540 var EXP_TABLE = BufferUtil.alloc(512)
541 var LOG_TABLE = BufferUtil.alloc(256)
542 /**
543  * Precompute the log and anti-log tables for faster computation later
544  *
545  * For each possible value in the galois field 2^8, we will pre-compute
546  * the logarithm and anti-logarithm (exponential) of this value
547  *
548  * ref {@link https://en.wikiversity.org/wiki/Reed%E2%80%93Solomon_codes_for_coders#Introduction_to_mathematical_fields}
549  */
550 ;(function initTables () {
551   var x = 1
552   for (var i = 0; i < 255; i++) {
553     EXP_TABLE[i] = x
554     LOG_TABLE[x] = i
555
556     x <<= 1 // multiply by 2
557
558     // The QR code specification says to use byte-wise modulo 100011101 arithmetic.
559     // This means that when a number is 256 or larger, it should be XORed with 0x11D.
560     if (x & 0x100) { // similar to x >= 256, but a lot faster (because 0x100 == 256)
561       x ^= 0x11D
562     }
563   }
564
565   // Optimization: double the size of the anti-log table so that we don't need to mod 255 to
566   // stay inside the bounds (because we will mainly use this table for the multiplication of
567   // two GF numbers, no more).
568   // @see {@link mul}
569   for (i = 255; i < 512; i++) {
570     EXP_TABLE[i] = EXP_TABLE[i - 255]
571   }
572 }())
573
574 /**
575  * Returns log value of n inside Galois Field
576  *
577  * @param  {Number} n
578  * @return {Number}
579  */
580 exports.log = function log (n) {
581   if (n < 1) throw new Error('log(' + n + ')')
582   return LOG_TABLE[n]
583 }
584
585 /**
586  * Returns anti-log value of n inside Galois Field
587  *
588  * @param  {Number} n
589  * @return {Number}
590  */
591 exports.exp = function exp (n) {
592   return EXP_TABLE[n]
593 }
594
595 /**
596  * Multiplies two number inside Galois Field
597  *
598  * @param  {Number} x
599  * @param  {Number} y
600  * @return {Number}
601  */
602 exports.mul = function mul (x, y) {
603   if (x === 0 || y === 0) return 0
604
605   // should be EXP_TABLE[(LOG_TABLE[x] + LOG_TABLE[y]) % 255] if EXP_TABLE wasn't oversized
606   // @see {@link initTables}
607   return EXP_TABLE[LOG_TABLE[x] + LOG_TABLE[y]]
608 }
609
610 },{"../utils/buffer":28}],12:[function(require,module,exports){
611 var Mode = require('./mode')
612 var Utils = require('./utils')
613
614 function KanjiData (data) {
615   this.mode = Mode.KANJI
616   this.data = data
617 }
618
619 KanjiData.getBitsLength = function getBitsLength (length) {
620   return length * 13
621 }
622
623 KanjiData.prototype.getLength = function getLength () {
624   return this.data.length
625 }
626
627 KanjiData.prototype.getBitsLength = function getBitsLength () {
628   return KanjiData.getBitsLength(this.data.length)
629 }
630
631 KanjiData.prototype.write = function (bitBuffer) {
632   var i
633
634   // In the Shift JIS system, Kanji characters are represented by a two byte combination.
635   // These byte values are shifted from the JIS X 0208 values.
636   // JIS X 0208 gives details of the shift coded representation.
637   for (i = 0; i < this.data.length; i++) {
638     var value = Utils.toSJIS(this.data[i])
639
640     // For characters with Shift JIS values from 0x8140 to 0x9FFC:
641     if (value >= 0x8140 && value <= 0x9FFC) {
642       // Subtract 0x8140 from Shift JIS value
643       value -= 0x8140
644
645     // For characters with Shift JIS values from 0xE040 to 0xEBBF
646     } else if (value >= 0xE040 && value <= 0xEBBF) {
647       // Subtract 0xC140 from Shift JIS value
648       value -= 0xC140
649     } else {
650       throw new Error(
651         'Invalid SJIS character: ' + this.data[i] + '\n' +
652         'Make sure your charset is UTF-8')
653     }
654
655     // Multiply most significant byte of result by 0xC0
656     // and add least significant byte to product
657     value = (((value >>> 8) & 0xff) * 0xC0) + (value & 0xff)
658
659     // Convert result to a 13-bit binary string
660     bitBuffer.put(value, 13)
661   }
662 }
663
664 module.exports = KanjiData
665
666 },{"./mode":14,"./utils":21}],13:[function(require,module,exports){
667 /**
668  * Data mask pattern reference
669  * @type {Object}
670  */
671 exports.Patterns = {
672   PATTERN000: 0,
673   PATTERN001: 1,
674   PATTERN010: 2,
675   PATTERN011: 3,
676   PATTERN100: 4,
677   PATTERN101: 5,
678   PATTERN110: 6,
679   PATTERN111: 7
680 }
681
682 /**
683  * Weighted penalty scores for the undesirable features
684  * @type {Object}
685  */
686 var PenaltyScores = {
687   N1: 3,
688   N2: 3,
689   N3: 40,
690   N4: 10
691 }
692
693 /**
694  * Check if mask pattern value is valid
695  *
696  * @param  {Number}  mask    Mask pattern
697  * @return {Boolean}         true if valid, false otherwise
698  */
699 exports.isValid = function isValid (mask) {
700   return mask != null && mask !== '' && !isNaN(mask) && mask >= 0 && mask <= 7
701 }
702
703 /**
704  * Returns mask pattern from a value.
705  * If value is not valid, returns undefined
706  *
707  * @param  {Number|String} value        Mask pattern value
708  * @return {Number}                     Valid mask pattern or undefined
709  */
710 exports.from = function from (value) {
711   return exports.isValid(value) ? parseInt(value, 10) : undefined
712 }
713
714 /**
715 * Find adjacent modules in row/column with the same color
716 * and assign a penalty value.
717 *
718 * Points: N1 + i
719 * i is the amount by which the number of adjacent modules of the same color exceeds 5
720 */
721 exports.getPenaltyN1 = function getPenaltyN1 (data) {
722   var size = data.size
723   var points = 0
724   var sameCountCol = 0
725   var sameCountRow = 0
726   var lastCol = null
727   var lastRow = null
728
729   for (var row = 0; row < size; row++) {
730     sameCountCol = sameCountRow = 0
731     lastCol = lastRow = null
732
733     for (var col = 0; col < size; col++) {
734       var module = data.get(row, col)
735       if (module === lastCol) {
736         sameCountCol++
737       } else {
738         if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5)
739         lastCol = module
740         sameCountCol = 1
741       }
742
743       module = data.get(col, row)
744       if (module === lastRow) {
745         sameCountRow++
746       } else {
747         if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5)
748         lastRow = module
749         sameCountRow = 1
750       }
751     }
752
753     if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5)
754     if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5)
755   }
756
757   return points
758 }
759
760 /**
761  * Find 2x2 blocks with the same color and assign a penalty value
762  *
763  * Points: N2 * (m - 1) * (n - 1)
764  */
765 exports.getPenaltyN2 = function getPenaltyN2 (data) {
766   var size = data.size
767   var points = 0
768
769   for (var row = 0; row < size - 1; row++) {
770     for (var col = 0; col < size - 1; col++) {
771       var last = data.get(row, col) +
772         data.get(row, col + 1) +
773         data.get(row + 1, col) +
774         data.get(row + 1, col + 1)
775
776       if (last === 4 || last === 0) points++
777     }
778   }
779
780   return points * PenaltyScores.N2
781 }
782
783 /**
784  * Find 1:1:3:1:1 ratio (dark:light:dark:light:dark) pattern in row/column,
785  * preceded or followed by light area 4 modules wide
786  *
787  * Points: N3 * number of pattern found
788  */
789 exports.getPenaltyN3 = function getPenaltyN3 (data) {
790   var size = data.size
791   var points = 0
792   var bitsCol = 0
793   var bitsRow = 0
794
795   for (var row = 0; row < size; row++) {
796     bitsCol = bitsRow = 0
797     for (var col = 0; col < size; col++) {
798       bitsCol = ((bitsCol << 1) & 0x7FF) | data.get(row, col)
799       if (col >= 10 && (bitsCol === 0x5D0 || bitsCol === 0x05D)) points++
800
801       bitsRow = ((bitsRow << 1) & 0x7FF) | data.get(col, row)
802       if (col >= 10 && (bitsRow === 0x5D0 || bitsRow === 0x05D)) points++
803     }
804   }
805
806   return points * PenaltyScores.N3
807 }
808
809 /**
810  * Calculate proportion of dark modules in entire symbol
811  *
812  * Points: N4 * k
813  *
814  * k is the rating of the deviation of the proportion of dark modules
815  * in the symbol from 50% in steps of 5%
816  */
817 exports.getPenaltyN4 = function getPenaltyN4 (data) {
818   var darkCount = 0
819   var modulesCount = data.data.length
820
821   for (var i = 0; i < modulesCount; i++) darkCount += data.data[i]
822
823   var k = Math.abs(Math.ceil((darkCount * 100 / modulesCount) / 5) - 10)
824
825   return k * PenaltyScores.N4
826 }
827
828 /**
829  * Return mask value at given position
830  *
831  * @param  {Number} maskPattern Pattern reference value
832  * @param  {Number} i           Row
833  * @param  {Number} j           Column
834  * @return {Boolean}            Mask value
835  */
836 function getMaskAt (maskPattern, i, j) {
837   switch (maskPattern) {
838     case exports.Patterns.PATTERN000: return (i + j) % 2 === 0
839     case exports.Patterns.PATTERN001: return i % 2 === 0
840     case exports.Patterns.PATTERN010: return j % 3 === 0
841     case exports.Patterns.PATTERN011: return (i + j) % 3 === 0
842     case exports.Patterns.PATTERN100: return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 === 0
843     case exports.Patterns.PATTERN101: return (i * j) % 2 + (i * j) % 3 === 0
844     case exports.Patterns.PATTERN110: return ((i * j) % 2 + (i * j) % 3) % 2 === 0
845     case exports.Patterns.PATTERN111: return ((i * j) % 3 + (i + j) % 2) % 2 === 0
846
847     default: throw new Error('bad maskPattern:' + maskPattern)
848   }
849 }
850
851 /**
852  * Apply a mask pattern to a BitMatrix
853  *
854  * @param  {Number}    pattern Pattern reference number
855  * @param  {BitMatrix} data    BitMatrix data
856  */
857 exports.applyMask = function applyMask (pattern, data) {
858   var size = data.size
859
860   for (var col = 0; col < size; col++) {
861     for (var row = 0; row < size; row++) {
862       if (data.isReserved(row, col)) continue
863       data.xor(row, col, getMaskAt(pattern, row, col))
864     }
865   }
866 }
867
868 /**
869  * Returns the best mask pattern for data
870  *
871  * @param  {BitMatrix} data
872  * @return {Number} Mask pattern reference number
873  */
874 exports.getBestMask = function getBestMask (data, setupFormatFunc) {
875   var numPatterns = Object.keys(exports.Patterns).length
876   var bestPattern = 0
877   var lowerPenalty = Infinity
878
879   for (var p = 0; p < numPatterns; p++) {
880     setupFormatFunc(p)
881     exports.applyMask(p, data)
882
883     // Calculate penalty
884     var penalty =
885       exports.getPenaltyN1(data) +
886       exports.getPenaltyN2(data) +
887       exports.getPenaltyN3(data) +
888       exports.getPenaltyN4(data)
889
890     // Undo previously applied mask
891     exports.applyMask(p, data)
892
893     if (penalty < lowerPenalty) {
894       lowerPenalty = penalty
895       bestPattern = p
896     }
897   }
898
899   return bestPattern
900 }
901
902 },{}],14:[function(require,module,exports){
903 var VersionCheck = require('./version-check')
904 var Regex = require('./regex')
905
906 /**
907  * Numeric mode encodes data from the decimal digit set (0 - 9)
908  * (byte values 30HEX to 39HEX).
909  * Normally, 3 data characters are represented by 10 bits.
910  *
911  * @type {Object}
912  */
913 exports.NUMERIC = {
914   id: 'Numeric',
915   bit: 1 << 0,
916   ccBits: [10, 12, 14]
917 }
918
919 /**
920  * Alphanumeric mode encodes data from a set of 45 characters,
921  * i.e. 10 numeric digits (0 - 9),
922  *      26 alphabetic characters (A - Z),
923  *   and 9 symbols (SP, $, %, *, +, -, ., /, :).
924  * Normally, two input characters are represented by 11 bits.
925  *
926  * @type {Object}
927  */
928 exports.ALPHANUMERIC = {
929   id: 'Alphanumeric',
930   bit: 1 << 1,
931   ccBits: [9, 11, 13]
932 }
933
934 /**
935  * In byte mode, data is encoded at 8 bits per character.
936  *
937  * @type {Object}
938  */
939 exports.BYTE = {
940   id: 'Byte',
941   bit: 1 << 2,
942   ccBits: [8, 16, 16]
943 }
944
945 /**
946  * The Kanji mode efficiently encodes Kanji characters in accordance with
947  * the Shift JIS system based on JIS X 0208.
948  * The Shift JIS values are shifted from the JIS X 0208 values.
949  * JIS X 0208 gives details of the shift coded representation.
950  * Each two-byte character value is compacted to a 13-bit binary codeword.
951  *
952  * @type {Object}
953  */
954 exports.KANJI = {
955   id: 'Kanji',
956   bit: 1 << 3,
957   ccBits: [8, 10, 12]
958 }
959
960 /**
961  * Mixed mode will contain a sequences of data in a combination of any of
962  * the modes described above
963  *
964  * @type {Object}
965  */
966 exports.MIXED = {
967   bit: -1
968 }
969
970 /**
971  * Returns the number of bits needed to store the data length
972  * according to QR Code specifications.
973  *
974  * @param  {Mode}   mode    Data mode
975  * @param  {Number} version QR Code version
976  * @return {Number}         Number of bits
977  */
978 exports.getCharCountIndicator = function getCharCountIndicator (mode, version) {
979   if (!mode.ccBits) throw new Error('Invalid mode: ' + mode)
980
981   if (!VersionCheck.isValid(version)) {
982     throw new Error('Invalid version: ' + version)
983   }
984
985   if (version >= 1 && version < 10) return mode.ccBits[0]
986   else if (version < 27) return mode.ccBits[1]
987   return mode.ccBits[2]
988 }
989
990 /**
991  * Returns the most efficient mode to store the specified data
992  *
993  * @param  {String} dataStr Input data string
994  * @return {Mode}           Best mode
995  */
996 exports.getBestModeForData = function getBestModeForData (dataStr) {
997   if (Regex.testNumeric(dataStr)) return exports.NUMERIC
998   else if (Regex.testAlphanumeric(dataStr)) return exports.ALPHANUMERIC
999   else if (Regex.testKanji(dataStr)) return exports.KANJI
1000   else return exports.BYTE
1001 }
1002
1003 /**
1004  * Return mode name as string
1005  *
1006  * @param {Mode} mode Mode object
1007  * @returns {String}  Mode name
1008  */
1009 exports.toString = function toString (mode) {
1010   if (mode && mode.id) return mode.id
1011   throw new Error('Invalid mode')
1012 }
1013
1014 /**
1015  * Check if input param is a valid mode object
1016  *
1017  * @param   {Mode}    mode Mode object
1018  * @returns {Boolean} True if valid mode, false otherwise
1019  */
1020 exports.isValid = function isValid (mode) {
1021   return mode && mode.bit && mode.ccBits
1022 }
1023
1024 /**
1025  * Get mode object from its name
1026  *
1027  * @param   {String} string Mode name
1028  * @returns {Mode}          Mode object
1029  */
1030 function fromString (string) {
1031   if (typeof string !== 'string') {
1032     throw new Error('Param is not a string')
1033   }
1034
1035   var lcStr = string.toLowerCase()
1036
1037   switch (lcStr) {
1038     case 'numeric':
1039       return exports.NUMERIC
1040     case 'alphanumeric':
1041       return exports.ALPHANUMERIC
1042     case 'kanji':
1043       return exports.KANJI
1044     case 'byte':
1045       return exports.BYTE
1046     default:
1047       throw new Error('Unknown mode: ' + string)
1048   }
1049 }
1050
1051 /**
1052  * Returns mode from a value.
1053  * If value is not a valid mode, returns defaultValue
1054  *
1055  * @param  {Mode|String} value        Encoding mode
1056  * @param  {Mode}        defaultValue Fallback value
1057  * @return {Mode}                     Encoding mode
1058  */
1059 exports.from = function from (value, defaultValue) {
1060   if (exports.isValid(value)) {
1061     return value
1062   }
1063
1064   try {
1065     return fromString(value)
1066   } catch (e) {
1067     return defaultValue
1068   }
1069 }
1070
1071 },{"./regex":19,"./version-check":22}],15:[function(require,module,exports){
1072 var Mode = require('./mode')
1073
1074 function NumericData (data) {
1075   this.mode = Mode.NUMERIC
1076   this.data = data.toString()
1077 }
1078
1079 NumericData.getBitsLength = function getBitsLength (length) {
1080   return 10 * Math.floor(length / 3) + ((length % 3) ? ((length % 3) * 3 + 1) : 0)
1081 }
1082
1083 NumericData.prototype.getLength = function getLength () {
1084   return this.data.length
1085 }
1086
1087 NumericData.prototype.getBitsLength = function getBitsLength () {
1088   return NumericData.getBitsLength(this.data.length)
1089 }
1090
1091 NumericData.prototype.write = function write (bitBuffer) {
1092   var i, group, value
1093
1094   // The input data string is divided into groups of three digits,
1095   // and each group is converted to its 10-bit binary equivalent.
1096   for (i = 0; i + 3 <= this.data.length; i += 3) {
1097     group = this.data.substr(i, 3)
1098     value = parseInt(group, 10)
1099
1100     bitBuffer.put(value, 10)
1101   }
1102
1103   // If the number of input digits is not an exact multiple of three,
1104   // the final one or two digits are converted to 4 or 7 bits respectively.
1105   var remainingNum = this.data.length - i
1106   if (remainingNum > 0) {
1107     group = this.data.substr(i)
1108     value = parseInt(group, 10)
1109
1110     bitBuffer.put(value, remainingNum * 3 + 1)
1111   }
1112 }
1113
1114 module.exports = NumericData
1115
1116 },{"./mode":14}],16:[function(require,module,exports){
1117 var BufferUtil = require('../utils/buffer')
1118 var GF = require('./galois-field')
1119
1120 /**
1121  * Multiplies two polynomials inside Galois Field
1122  *
1123  * @param  {Buffer} p1 Polynomial
1124  * @param  {Buffer} p2 Polynomial
1125  * @return {Buffer}    Product of p1 and p2
1126  */
1127 exports.mul = function mul (p1, p2) {
1128   var coeff = BufferUtil.alloc(p1.length + p2.length - 1)
1129
1130   for (var i = 0; i < p1.length; i++) {
1131     for (var j = 0; j < p2.length; j++) {
1132       coeff[i + j] ^= GF.mul(p1[i], p2[j])
1133     }
1134   }
1135
1136   return coeff
1137 }
1138
1139 /**
1140  * Calculate the remainder of polynomials division
1141  *
1142  * @param  {Buffer} divident Polynomial
1143  * @param  {Buffer} divisor  Polynomial
1144  * @return {Buffer}          Remainder
1145  */
1146 exports.mod = function mod (divident, divisor) {
1147   var result = BufferUtil.from(divident)
1148
1149   while ((result.length - divisor.length) >= 0) {
1150     var coeff = result[0]
1151
1152     for (var i = 0; i < divisor.length; i++) {
1153       result[i] ^= GF.mul(divisor[i], coeff)
1154     }
1155
1156     // remove all zeros from buffer head
1157     var offset = 0
1158     while (offset < result.length && result[offset] === 0) offset++
1159     result = result.slice(offset)
1160   }
1161
1162   return result
1163 }
1164
1165 /**
1166  * Generate an irreducible generator polynomial of specified degree
1167  * (used by Reed-Solomon encoder)
1168  *
1169  * @param  {Number} degree Degree of the generator polynomial
1170  * @return {Buffer}        Buffer containing polynomial coefficients
1171  */
1172 exports.generateECPolynomial = function generateECPolynomial (degree) {
1173   var poly = BufferUtil.from([1])
1174   for (var i = 0; i < degree; i++) {
1175     poly = exports.mul(poly, [1, GF.exp(i)])
1176   }
1177
1178   return poly
1179 }
1180
1181 },{"../utils/buffer":28,"./galois-field":11}],17:[function(require,module,exports){
1182 var BufferUtil = require('../utils/buffer')
1183 var Utils = require('./utils')
1184 var ECLevel = require('./error-correction-level')
1185 var BitBuffer = require('./bit-buffer')
1186 var BitMatrix = require('./bit-matrix')
1187 var AlignmentPattern = require('./alignment-pattern')
1188 var FinderPattern = require('./finder-pattern')
1189 var MaskPattern = require('./mask-pattern')
1190 var ECCode = require('./error-correction-code')
1191 var ReedSolomonEncoder = require('./reed-solomon-encoder')
1192 var Version = require('./version')
1193 var FormatInfo = require('./format-info')
1194 var Mode = require('./mode')
1195 var Segments = require('./segments')
1196 var isArray = require('isarray')
1197
1198 /**
1199  * QRCode for JavaScript
1200  *
1201  * modified by Ryan Day for nodejs support
1202  * Copyright (c) 2011 Ryan Day
1203  *
1204  * Licensed under the MIT license:
1205  *   http://www.opensource.org/licenses/mit-license.php
1206  *
1207 //---------------------------------------------------------------------
1208 // QRCode for JavaScript
1209 //
1210 // Copyright (c) 2009 Kazuhiko Arase
1211 //
1212 // URL: http://www.d-project.com/
1213 //
1214 // Licensed under the MIT license:
1215 //   http://www.opensource.org/licenses/mit-license.php
1216 //
1217 // The word "QR Code" is registered trademark of
1218 // DENSO WAVE INCORPORATED
1219 //   http://www.denso-wave.com/qrcode/faqpatent-e.html
1220 //
1221 //---------------------------------------------------------------------
1222 */
1223
1224 /**
1225  * Add finder patterns bits to matrix
1226  *
1227  * @param  {BitMatrix} matrix  Modules matrix
1228  * @param  {Number}    version QR Code version
1229  */
1230 function setupFinderPattern (matrix, version) {
1231   var size = matrix.size
1232   var pos = FinderPattern.getPositions(version)
1233
1234   for (var i = 0; i < pos.length; i++) {
1235     var row = pos[i][0]
1236     var col = pos[i][1]
1237
1238     for (var r = -1; r <= 7; r++) {
1239       if (row + r <= -1 || size <= row + r) continue
1240
1241       for (var c = -1; c <= 7; c++) {
1242         if (col + c <= -1 || size <= col + c) continue
1243
1244         if ((r >= 0 && r <= 6 && (c === 0 || c === 6)) ||
1245           (c >= 0 && c <= 6 && (r === 0 || r === 6)) ||
1246           (r >= 2 && r <= 4 && c >= 2 && c <= 4)) {
1247           matrix.set(row + r, col + c, true, true)
1248         } else {
1249           matrix.set(row + r, col + c, false, true)
1250         }
1251       }
1252     }
1253   }
1254 }
1255
1256 /**
1257  * Add timing pattern bits to matrix
1258  *
1259  * Note: this function must be called before {@link setupAlignmentPattern}
1260  *
1261  * @param  {BitMatrix} matrix Modules matrix
1262  */
1263 function setupTimingPattern (matrix) {
1264   var size = matrix.size
1265
1266   for (var r = 8; r < size - 8; r++) {
1267     var value = r % 2 === 0
1268     matrix.set(r, 6, value, true)
1269     matrix.set(6, r, value, true)
1270   }
1271 }
1272
1273 /**
1274  * Add alignment patterns bits to matrix
1275  *
1276  * Note: this function must be called after {@link setupTimingPattern}
1277  *
1278  * @param  {BitMatrix} matrix  Modules matrix
1279  * @param  {Number}    version QR Code version
1280  */
1281 function setupAlignmentPattern (matrix, version) {
1282   var pos = AlignmentPattern.getPositions(version)
1283
1284   for (var i = 0; i < pos.length; i++) {
1285     var row = pos[i][0]
1286     var col = pos[i][1]
1287
1288     for (var r = -2; r <= 2; r++) {
1289       for (var c = -2; c <= 2; c++) {
1290         if (r === -2 || r === 2 || c === -2 || c === 2 ||
1291           (r === 0 && c === 0)) {
1292           matrix.set(row + r, col + c, true, true)
1293         } else {
1294           matrix.set(row + r, col + c, false, true)
1295         }
1296       }
1297     }
1298   }
1299 }
1300
1301 /**
1302  * Add version info bits to matrix
1303  *
1304  * @param  {BitMatrix} matrix  Modules matrix
1305  * @param  {Number}    version QR Code version
1306  */
1307 function setupVersionInfo (matrix, version) {
1308   var size = matrix.size
1309   var bits = Version.getEncodedBits(version)
1310   var row, col, mod
1311
1312   for (var i = 0; i < 18; i++) {
1313     row = Math.floor(i / 3)
1314     col = i % 3 + size - 8 - 3
1315     mod = ((bits >> i) & 1) === 1
1316
1317     matrix.set(row, col, mod, true)
1318     matrix.set(col, row, mod, true)
1319   }
1320 }
1321
1322 /**
1323  * Add format info bits to matrix
1324  *
1325  * @param  {BitMatrix} matrix               Modules matrix
1326  * @param  {ErrorCorrectionLevel}    errorCorrectionLevel Error correction level
1327  * @param  {Number}    maskPattern          Mask pattern reference value
1328  */
1329 function setupFormatInfo (matrix, errorCorrectionLevel, maskPattern) {
1330   var size = matrix.size
1331   var bits = FormatInfo.getEncodedBits(errorCorrectionLevel, maskPattern)
1332   var i, mod
1333
1334   for (i = 0; i < 15; i++) {
1335     mod = ((bits >> i) & 1) === 1
1336
1337     // vertical
1338     if (i < 6) {
1339       matrix.set(i, 8, mod, true)
1340     } else if (i < 8) {
1341       matrix.set(i + 1, 8, mod, true)
1342     } else {
1343       matrix.set(size - 15 + i, 8, mod, true)
1344     }
1345
1346     // horizontal
1347     if (i < 8) {
1348       matrix.set(8, size - i - 1, mod, true)
1349     } else if (i < 9) {
1350       matrix.set(8, 15 - i - 1 + 1, mod, true)
1351     } else {
1352       matrix.set(8, 15 - i - 1, mod, true)
1353     }
1354   }
1355
1356   // fixed module
1357   matrix.set(size - 8, 8, 1, true)
1358 }
1359
1360 /**
1361  * Add encoded data bits to matrix
1362  *
1363  * @param  {BitMatrix} matrix Modules matrix
1364  * @param  {Buffer}    data   Data codewords
1365  */
1366 function setupData (matrix, data) {
1367   var size = matrix.size
1368   var inc = -1
1369   var row = size - 1
1370   var bitIndex = 7
1371   var byteIndex = 0
1372
1373   for (var col = size - 1; col > 0; col -= 2) {
1374     if (col === 6) col--
1375
1376     while (true) {
1377       for (var c = 0; c < 2; c++) {
1378         if (!matrix.isReserved(row, col - c)) {
1379           var dark = false
1380
1381           if (byteIndex < data.length) {
1382             dark = (((data[byteIndex] >>> bitIndex) & 1) === 1)
1383           }
1384
1385           matrix.set(row, col - c, dark)
1386           bitIndex--
1387
1388           if (bitIndex === -1) {
1389             byteIndex++
1390             bitIndex = 7
1391           }
1392         }
1393       }
1394
1395       row += inc
1396
1397       if (row < 0 || size <= row) {
1398         row -= inc
1399         inc = -inc
1400         break
1401       }
1402     }
1403   }
1404 }
1405
1406 /**
1407  * Create encoded codewords from data input
1408  *
1409  * @param  {Number}   version              QR Code version
1410  * @param  {ErrorCorrectionLevel}   errorCorrectionLevel Error correction level
1411  * @param  {ByteData} data                 Data input
1412  * @return {Buffer}                        Buffer containing encoded codewords
1413  */
1414 function createData (version, errorCorrectionLevel, segments) {
1415   // Prepare data buffer
1416   var buffer = new BitBuffer()
1417
1418   segments.forEach(function (data) {
1419     // prefix data with mode indicator (4 bits)
1420     buffer.put(data.mode.bit, 4)
1421
1422     // Prefix data with character count indicator.
1423     // The character count indicator is a string of bits that represents the
1424     // number of characters that are being encoded.
1425     // The character count indicator must be placed after the mode indicator
1426     // and must be a certain number of bits long, depending on the QR version
1427     // and data mode
1428     // @see {@link Mode.getCharCountIndicator}.
1429     buffer.put(data.getLength(), Mode.getCharCountIndicator(data.mode, version))
1430
1431     // add binary data sequence to buffer
1432     data.write(buffer)
1433   })
1434
1435   // Calculate required number of bits
1436   var totalCodewords = Utils.getSymbolTotalCodewords(version)
1437   var ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel)
1438   var dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8
1439
1440   // Add a terminator.
1441   // If the bit string is shorter than the total number of required bits,
1442   // a terminator of up to four 0s must be added to the right side of the string.
1443   // If the bit string is more than four bits shorter than the required number of bits,
1444   // add four 0s to the end.
1445   if (buffer.getLengthInBits() + 4 <= dataTotalCodewordsBits) {
1446     buffer.put(0, 4)
1447   }
1448
1449   // If the bit string is fewer than four bits shorter, add only the number of 0s that
1450   // are needed to reach the required number of bits.
1451
1452   // After adding the terminator, if the number of bits in the string is not a multiple of 8,
1453   // pad the string on the right with 0s to make the string's length a multiple of 8.
1454   while (buffer.getLengthInBits() % 8 !== 0) {
1455     buffer.putBit(0)
1456   }
1457
1458   // Add pad bytes if the string is still shorter than the total number of required bits.
1459   // Extend the buffer to fill the data capacity of the symbol corresponding to
1460   // the Version and Error Correction Level by adding the Pad Codewords 11101100 (0xEC)
1461   // and 00010001 (0x11) alternately.
1462   var remainingByte = (dataTotalCodewordsBits - buffer.getLengthInBits()) / 8
1463   for (var i = 0; i < remainingByte; i++) {
1464     buffer.put(i % 2 ? 0x11 : 0xEC, 8)
1465   }
1466
1467   return createCodewords(buffer, version, errorCorrectionLevel)
1468 }
1469
1470 /**
1471  * Encode input data with Reed-Solomon and return codewords with
1472  * relative error correction bits
1473  *
1474  * @param  {BitBuffer} bitBuffer            Data to encode
1475  * @param  {Number}    version              QR Code version
1476  * @param  {ErrorCorrectionLevel} errorCorrectionLevel Error correction level
1477  * @return {Buffer}                         Buffer containing encoded codewords
1478  */
1479 function createCodewords (bitBuffer, version, errorCorrectionLevel) {
1480   // Total codewords for this QR code version (Data + Error correction)
1481   var totalCodewords = Utils.getSymbolTotalCodewords(version)
1482
1483   // Total number of error correction codewords
1484   var ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel)
1485
1486   // Total number of data codewords
1487   var dataTotalCodewords = totalCodewords - ecTotalCodewords
1488
1489   // Total number of blocks
1490   var ecTotalBlocks = ECCode.getBlocksCount(version, errorCorrectionLevel)
1491
1492   // Calculate how many blocks each group should contain
1493   var blocksInGroup2 = totalCodewords % ecTotalBlocks
1494   var blocksInGroup1 = ecTotalBlocks - blocksInGroup2
1495
1496   var totalCodewordsInGroup1 = Math.floor(totalCodewords / ecTotalBlocks)
1497
1498   var dataCodewordsInGroup1 = Math.floor(dataTotalCodewords / ecTotalBlocks)
1499   var dataCodewordsInGroup2 = dataCodewordsInGroup1 + 1
1500
1501   // Number of EC codewords is the same for both groups
1502   var ecCount = totalCodewordsInGroup1 - dataCodewordsInGroup1
1503
1504   // Initialize a Reed-Solomon encoder with a generator polynomial of degree ecCount
1505   var rs = new ReedSolomonEncoder(ecCount)
1506
1507   var offset = 0
1508   var dcData = new Array(ecTotalBlocks)
1509   var ecData = new Array(ecTotalBlocks)
1510   var maxDataSize = 0
1511   var buffer = BufferUtil.from(bitBuffer.buffer)
1512
1513   // Divide the buffer into the required number of blocks
1514   for (var b = 0; b < ecTotalBlocks; b++) {
1515     var dataSize = b < blocksInGroup1 ? dataCodewordsInGroup1 : dataCodewordsInGroup2
1516
1517     // extract a block of data from buffer
1518     dcData[b] = buffer.slice(offset, offset + dataSize)
1519
1520     // Calculate EC codewords for this data block
1521     ecData[b] = rs.encode(dcData[b])
1522
1523     offset += dataSize
1524     maxDataSize = Math.max(maxDataSize, dataSize)
1525   }
1526
1527   // Create final data
1528   // Interleave the data and error correction codewords from each block
1529   var data = BufferUtil.alloc(totalCodewords)
1530   var index = 0
1531   var i, r
1532
1533   // Add data codewords
1534   for (i = 0; i < maxDataSize; i++) {
1535     for (r = 0; r < ecTotalBlocks; r++) {
1536       if (i < dcData[r].length) {
1537         data[index++] = dcData[r][i]
1538       }
1539     }
1540   }
1541
1542   // Apped EC codewords
1543   for (i = 0; i < ecCount; i++) {
1544     for (r = 0; r < ecTotalBlocks; r++) {
1545       data[index++] = ecData[r][i]
1546     }
1547   }
1548
1549   return data
1550 }
1551
1552 /**
1553  * Build QR Code symbol
1554  *
1555  * @param  {String} data                 Input string
1556  * @param  {Number} version              QR Code version
1557  * @param  {ErrorCorretionLevel} errorCorrectionLevel Error level
1558  * @param  {MaskPattern} maskPattern     Mask pattern
1559  * @return {Object}                      Object containing symbol data
1560  */
1561 function createSymbol (data, version, errorCorrectionLevel, maskPattern) {
1562   var segments
1563
1564   if (isArray(data)) {
1565     segments = Segments.fromArray(data)
1566   } else if (typeof data === 'string') {
1567     var estimatedVersion = version
1568
1569     if (!estimatedVersion) {
1570       var rawSegments = Segments.rawSplit(data)
1571
1572       // Estimate best version that can contain raw splitted segments
1573       estimatedVersion = Version.getBestVersionForData(rawSegments,
1574         errorCorrectionLevel)
1575     }
1576
1577     // Build optimized segments
1578     // If estimated version is undefined, try with the highest version
1579     segments = Segments.fromString(data, estimatedVersion || 40)
1580   } else {
1581     throw new Error('Invalid data')
1582   }
1583
1584   // Get the min version that can contain data
1585   var bestVersion = Version.getBestVersionForData(segments,
1586       errorCorrectionLevel)
1587
1588   // If no version is found, data cannot be stored
1589   if (!bestVersion) {
1590     throw new Error('The amount of data is too big to be stored in a QR Code')
1591   }
1592
1593   // If not specified, use min version as default
1594   if (!version) {
1595     version = bestVersion
1596
1597   // Check if the specified version can contain the data
1598   } else if (version < bestVersion) {
1599     throw new Error('\n' +
1600       'The chosen QR Code version cannot contain this amount of data.\n' +
1601       'Minimum version required to store current data is: ' + bestVersion + '.\n'
1602     )
1603   }
1604
1605   var dataBits = createData(version, errorCorrectionLevel, segments)
1606
1607   // Allocate matrix buffer
1608   var moduleCount = Utils.getSymbolSize(version)
1609   var modules = new BitMatrix(moduleCount)
1610
1611   // Add function modules
1612   setupFinderPattern(modules, version)
1613   setupTimingPattern(modules)
1614   setupAlignmentPattern(modules, version)
1615
1616   // Add temporary dummy bits for format info just to set them as reserved.
1617   // This is needed to prevent these bits from being masked by {@link MaskPattern.applyMask}
1618   // since the masking operation must be performed only on the encoding region.
1619   // These blocks will be replaced with correct values later in code.
1620   setupFormatInfo(modules, errorCorrectionLevel, 0)
1621
1622   if (version >= 7) {
1623     setupVersionInfo(modules, version)
1624   }
1625
1626   // Add data codewords
1627   setupData(modules, dataBits)
1628
1629   if (isNaN(maskPattern)) {
1630     // Find best mask pattern
1631     maskPattern = MaskPattern.getBestMask(modules,
1632       setupFormatInfo.bind(null, modules, errorCorrectionLevel))
1633   }
1634
1635   // Apply mask pattern
1636   MaskPattern.applyMask(maskPattern, modules)
1637
1638   // Replace format info bits with correct values
1639   setupFormatInfo(modules, errorCorrectionLevel, maskPattern)
1640
1641   return {
1642     modules: modules,
1643     version: version,
1644     errorCorrectionLevel: errorCorrectionLevel,
1645     maskPattern: maskPattern,
1646     segments: segments
1647   }
1648 }
1649
1650 /**
1651  * QR Code
1652  *
1653  * @param {String | Array} data                 Input data
1654  * @param {Object} options                      Optional configurations
1655  * @param {Number} options.version              QR Code version
1656  * @param {String} options.errorCorrectionLevel Error correction level
1657  * @param {Function} options.toSJISFunc         Helper func to convert utf8 to sjis
1658  */
1659 exports.create = function create (data, options) {
1660   if (typeof data === 'undefined' || data === '') {
1661     throw new Error('No input text')
1662   }
1663
1664   var errorCorrectionLevel = ECLevel.M
1665   var version
1666   var mask
1667
1668   if (typeof options !== 'undefined') {
1669     // Use higher error correction level as default
1670     errorCorrectionLevel = ECLevel.from(options.errorCorrectionLevel, ECLevel.M)
1671     version = Version.from(options.version)
1672     mask = MaskPattern.from(options.maskPattern)
1673
1674     if (options.toSJISFunc) {
1675       Utils.setToSJISFunction(options.toSJISFunc)
1676     }
1677   }
1678
1679   return createSymbol(data, version, errorCorrectionLevel, mask)
1680 }
1681
1682 },{"../utils/buffer":28,"./alignment-pattern":2,"./bit-buffer":4,"./bit-matrix":5,"./error-correction-code":7,"./error-correction-level":8,"./finder-pattern":9,"./format-info":10,"./mask-pattern":13,"./mode":14,"./reed-solomon-encoder":18,"./segments":20,"./utils":21,"./version":23,"isarray":33}],18:[function(require,module,exports){
1683 var BufferUtil = require('../utils/buffer')
1684 var Polynomial = require('./polynomial')
1685 var Buffer = require('buffer').Buffer
1686
1687 function ReedSolomonEncoder (degree) {
1688   this.genPoly = undefined
1689   this.degree = degree
1690
1691   if (this.degree) this.initialize(this.degree)
1692 }
1693
1694 /**
1695  * Initialize the encoder.
1696  * The input param should correspond to the number of error correction codewords.
1697  *
1698  * @param  {Number} degree
1699  */
1700 ReedSolomonEncoder.prototype.initialize = function initialize (degree) {
1701   // create an irreducible generator polynomial
1702   this.degree = degree
1703   this.genPoly = Polynomial.generateECPolynomial(this.degree)
1704 }
1705
1706 /**
1707  * Encodes a chunk of data
1708  *
1709  * @param  {Buffer} data Buffer containing input data
1710  * @return {Buffer}      Buffer containing encoded data
1711  */
1712 ReedSolomonEncoder.prototype.encode = function encode (data) {
1713   if (!this.genPoly) {
1714     throw new Error('Encoder not initialized')
1715   }
1716
1717   // Calculate EC for this data block
1718   // extends data size to data+genPoly size
1719   var pad = BufferUtil.alloc(this.degree)
1720   var paddedData = Buffer.concat([data, pad], data.length + this.degree)
1721
1722   // The error correction codewords are the remainder after dividing the data codewords
1723   // by a generator polynomial
1724   var remainder = Polynomial.mod(paddedData, this.genPoly)
1725
1726   // return EC data blocks (last n byte, where n is the degree of genPoly)
1727   // If coefficients number in remainder are less than genPoly degree,
1728   // pad with 0s to the left to reach the needed number of coefficients
1729   var start = this.degree - remainder.length
1730   if (start > 0) {
1731     var buff = BufferUtil.alloc(this.degree)
1732     remainder.copy(buff, start)
1733
1734     return buff
1735   }
1736
1737   return remainder
1738 }
1739
1740 module.exports = ReedSolomonEncoder
1741
1742 },{"../utils/buffer":28,"./polynomial":16,"buffer":30}],19:[function(require,module,exports){
1743 var numeric = '[0-9]+'
1744 var alphanumeric = '[A-Z $%*+\\-./:]+'
1745 var kanji = '(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|' +
1746   '[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|' +
1747   '[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|' +
1748   '[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+'
1749 kanji = kanji.replace(/u/g, '\\u')
1750
1751 var byte = '(?:(?![A-Z0-9 $%*+\\-./:]|' + kanji + ')(?:.|[\r\n]))+'
1752
1753 exports.KANJI = new RegExp(kanji, 'g')
1754 exports.BYTE_KANJI = new RegExp('[^A-Z0-9 $%*+\\-./:]+', 'g')
1755 exports.BYTE = new RegExp(byte, 'g')
1756 exports.NUMERIC = new RegExp(numeric, 'g')
1757 exports.ALPHANUMERIC = new RegExp(alphanumeric, 'g')
1758
1759 var TEST_KANJI = new RegExp('^' + kanji + '$')
1760 var TEST_NUMERIC = new RegExp('^' + numeric + '$')
1761 var TEST_ALPHANUMERIC = new RegExp('^[A-Z0-9 $%*+\\-./:]+$')
1762
1763 exports.testKanji = function testKanji (str) {
1764   return TEST_KANJI.test(str)
1765 }
1766
1767 exports.testNumeric = function testNumeric (str) {
1768   return TEST_NUMERIC.test(str)
1769 }
1770
1771 exports.testAlphanumeric = function testAlphanumeric (str) {
1772   return TEST_ALPHANUMERIC.test(str)
1773 }
1774
1775 },{}],20:[function(require,module,exports){
1776 var Mode = require('./mode')
1777 var NumericData = require('./numeric-data')
1778 var AlphanumericData = require('./alphanumeric-data')
1779 var ByteData = require('./byte-data')
1780 var KanjiData = require('./kanji-data')
1781 var Regex = require('./regex')
1782 var Utils = require('./utils')
1783 var dijkstra = require('dijkstrajs')
1784
1785 /**
1786  * Returns UTF8 byte length
1787  *
1788  * @param  {String} str Input string
1789  * @return {Number}     Number of byte
1790  */
1791 function getStringByteLength (str) {
1792   return unescape(encodeURIComponent(str)).length
1793 }
1794
1795 /**
1796  * Get a list of segments of the specified mode
1797  * from a string
1798  *
1799  * @param  {Mode}   mode Segment mode
1800  * @param  {String} str  String to process
1801  * @return {Array}       Array of object with segments data
1802  */
1803 function getSegments (regex, mode, str) {
1804   var segments = []
1805   var result
1806
1807   while ((result = regex.exec(str)) !== null) {
1808     segments.push({
1809       data: result[0],
1810       index: result.index,
1811       mode: mode,
1812       length: result[0].length
1813     })
1814   }
1815
1816   return segments
1817 }
1818
1819 /**
1820  * Extracts a series of segments with the appropriate
1821  * modes from a string
1822  *
1823  * @param  {String} dataStr Input string
1824  * @return {Array}          Array of object with segments data
1825  */
1826 function getSegmentsFromString (dataStr) {
1827   var numSegs = getSegments(Regex.NUMERIC, Mode.NUMERIC, dataStr)
1828   var alphaNumSegs = getSegments(Regex.ALPHANUMERIC, Mode.ALPHANUMERIC, dataStr)
1829   var byteSegs
1830   var kanjiSegs
1831
1832   if (Utils.isKanjiModeEnabled()) {
1833     byteSegs = getSegments(Regex.BYTE, Mode.BYTE, dataStr)
1834     kanjiSegs = getSegments(Regex.KANJI, Mode.KANJI, dataStr)
1835   } else {
1836     byteSegs = getSegments(Regex.BYTE_KANJI, Mode.BYTE, dataStr)
1837     kanjiSegs = []
1838   }
1839
1840   var segs = numSegs.concat(alphaNumSegs, byteSegs, kanjiSegs)
1841
1842   return segs
1843     .sort(function (s1, s2) {
1844       return s1.index - s2.index
1845     })
1846     .map(function (obj) {
1847       return {
1848         data: obj.data,
1849         mode: obj.mode,
1850         length: obj.length
1851       }
1852     })
1853 }
1854
1855 /**
1856  * Returns how many bits are needed to encode a string of
1857  * specified length with the specified mode
1858  *
1859  * @param  {Number} length String length
1860  * @param  {Mode} mode     Segment mode
1861  * @return {Number}        Bit length
1862  */
1863 function getSegmentBitsLength (length, mode) {
1864   switch (mode) {
1865     case Mode.NUMERIC:
1866       return NumericData.getBitsLength(length)
1867     case Mode.ALPHANUMERIC:
1868       return AlphanumericData.getBitsLength(length)
1869     case Mode.KANJI:
1870       return KanjiData.getBitsLength(length)
1871     case Mode.BYTE:
1872       return ByteData.getBitsLength(length)
1873   }
1874 }
1875
1876 /**
1877  * Merges adjacent segments which have the same mode
1878  *
1879  * @param  {Array} segs Array of object with segments data
1880  * @return {Array}      Array of object with segments data
1881  */
1882 function mergeSegments (segs) {
1883   return segs.reduce(function (acc, curr) {
1884     var prevSeg = acc.length - 1 >= 0 ? acc[acc.length - 1] : null
1885     if (prevSeg && prevSeg.mode === curr.mode) {
1886       acc[acc.length - 1].data += curr.data
1887       return acc
1888     }
1889
1890     acc.push(curr)
1891     return acc
1892   }, [])
1893 }
1894
1895 /**
1896  * Generates a list of all possible nodes combination which
1897  * will be used to build a segments graph.
1898  *
1899  * Nodes are divided by groups. Each group will contain a list of all the modes
1900  * in which is possible to encode the given text.
1901  *
1902  * For example the text '12345' can be encoded as Numeric, Alphanumeric or Byte.
1903  * The group for '12345' will contain then 3 objects, one for each
1904  * possible encoding mode.
1905  *
1906  * Each node represents a possible segment.
1907  *
1908  * @param  {Array} segs Array of object with segments data
1909  * @return {Array}      Array of object with segments data
1910  */
1911 function buildNodes (segs) {
1912   var nodes = []
1913   for (var i = 0; i < segs.length; i++) {
1914     var seg = segs[i]
1915
1916     switch (seg.mode) {
1917       case Mode.NUMERIC:
1918         nodes.push([seg,
1919           { data: seg.data, mode: Mode.ALPHANUMERIC, length: seg.length },
1920           { data: seg.data, mode: Mode.BYTE, length: seg.length }
1921         ])
1922         break
1923       case Mode.ALPHANUMERIC:
1924         nodes.push([seg,
1925           { data: seg.data, mode: Mode.BYTE, length: seg.length }
1926         ])
1927         break
1928       case Mode.KANJI:
1929         nodes.push([seg,
1930           { data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) }
1931         ])
1932         break
1933       case Mode.BYTE:
1934         nodes.push([
1935           { data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) }
1936         ])
1937     }
1938   }
1939
1940   return nodes
1941 }
1942
1943 /**
1944  * Builds a graph from a list of nodes.
1945  * All segments in each node group will be connected with all the segments of
1946  * the next group and so on.
1947  *
1948  * At each connection will be assigned a weight depending on the
1949  * segment's byte length.
1950  *
1951  * @param  {Array} nodes    Array of object with segments data
1952  * @param  {Number} version QR Code version
1953  * @return {Object}         Graph of all possible segments
1954  */
1955 function buildGraph (nodes, version) {
1956   var table = {}
1957   var graph = {'start': {}}
1958   var prevNodeIds = ['start']
1959
1960   for (var i = 0; i < nodes.length; i++) {
1961     var nodeGroup = nodes[i]
1962     var currentNodeIds = []
1963
1964     for (var j = 0; j < nodeGroup.length; j++) {
1965       var node = nodeGroup[j]
1966       var key = '' + i + j
1967
1968       currentNodeIds.push(key)
1969       table[key] = { node: node, lastCount: 0 }
1970       graph[key] = {}
1971
1972       for (var n = 0; n < prevNodeIds.length; n++) {
1973         var prevNodeId = prevNodeIds[n]
1974
1975         if (table[prevNodeId] && table[prevNodeId].node.mode === node.mode) {
1976           graph[prevNodeId][key] =
1977             getSegmentBitsLength(table[prevNodeId].lastCount + node.length, node.mode) -
1978             getSegmentBitsLength(table[prevNodeId].lastCount, node.mode)
1979
1980           table[prevNodeId].lastCount += node.length
1981         } else {
1982           if (table[prevNodeId]) table[prevNodeId].lastCount = node.length
1983
1984           graph[prevNodeId][key] = getSegmentBitsLength(node.length, node.mode) +
1985             4 + Mode.getCharCountIndicator(node.mode, version) // switch cost
1986         }
1987       }
1988     }
1989
1990     prevNodeIds = currentNodeIds
1991   }
1992
1993   for (n = 0; n < prevNodeIds.length; n++) {
1994     graph[prevNodeIds[n]]['end'] = 0
1995   }
1996
1997   return { map: graph, table: table }
1998 }
1999
2000 /**
2001  * Builds a segment from a specified data and mode.
2002  * If a mode is not specified, the more suitable will be used.
2003  *
2004  * @param  {String} data             Input data
2005  * @param  {Mode | String} modesHint Data mode
2006  * @return {Segment}                 Segment
2007  */
2008 function buildSingleSegment (data, modesHint) {
2009   var mode
2010   var bestMode = Mode.getBestModeForData(data)
2011
2012   mode = Mode.from(modesHint, bestMode)
2013
2014   // Make sure data can be encoded
2015   if (mode !== Mode.BYTE && mode.bit < bestMode.bit) {
2016     throw new Error('"' + data + '"' +
2017       ' cannot be encoded with mode ' + Mode.toString(mode) +
2018       '.\n Suggested mode is: ' + Mode.toString(bestMode))
2019   }
2020
2021   // Use Mode.BYTE if Kanji support is disabled
2022   if (mode === Mode.KANJI && !Utils.isKanjiModeEnabled()) {
2023     mode = Mode.BYTE
2024   }
2025
2026   switch (mode) {
2027     case Mode.NUMERIC:
2028       return new NumericData(data)
2029
2030     case Mode.ALPHANUMERIC:
2031       return new AlphanumericData(data)
2032
2033     case Mode.KANJI:
2034       return new KanjiData(data)
2035
2036     case Mode.BYTE:
2037       return new ByteData(data)
2038   }
2039 }
2040
2041 /**
2042  * Builds a list of segments from an array.
2043  * Array can contain Strings or Objects with segment's info.
2044  *
2045  * For each item which is a string, will be generated a segment with the given
2046  * string and the more appropriate encoding mode.
2047  *
2048  * For each item which is an object, will be generated a segment with the given
2049  * data and mode.
2050  * Objects must contain at least the property "data".
2051  * If property "mode" is not present, the more suitable mode will be used.
2052  *
2053  * @param  {Array} array Array of objects with segments data
2054  * @return {Array}       Array of Segments
2055  */
2056 exports.fromArray = function fromArray (array) {
2057   return array.reduce(function (acc, seg) {
2058     if (typeof seg === 'string') {
2059       acc.push(buildSingleSegment(seg, null))
2060     } else if (seg.data) {
2061       acc.push(buildSingleSegment(seg.data, seg.mode))
2062     }
2063
2064     return acc
2065   }, [])
2066 }
2067
2068 /**
2069  * Builds an optimized sequence of segments from a string,
2070  * which will produce the shortest possible bitstream.
2071  *
2072  * @param  {String} data    Input string
2073  * @param  {Number} version QR Code version
2074  * @return {Array}          Array of segments
2075  */
2076 exports.fromString = function fromString (data, version) {
2077   var segs = getSegmentsFromString(data, Utils.isKanjiModeEnabled())
2078
2079   var nodes = buildNodes(segs)
2080   var graph = buildGraph(nodes, version)
2081   var path = dijkstra.find_path(graph.map, 'start', 'end')
2082
2083   var optimizedSegs = []
2084   for (var i = 1; i < path.length - 1; i++) {
2085     optimizedSegs.push(graph.table[path[i]].node)
2086   }
2087
2088   return exports.fromArray(mergeSegments(optimizedSegs))
2089 }
2090
2091 /**
2092  * Splits a string in various segments with the modes which
2093  * best represent their content.
2094  * The produced segments are far from being optimized.
2095  * The output of this function is only used to estimate a QR Code version
2096  * which may contain the data.
2097  *
2098  * @param  {string} data Input string
2099  * @return {Array}       Array of segments
2100  */
2101 exports.rawSplit = function rawSplit (data) {
2102   return exports.fromArray(
2103     getSegmentsFromString(data, Utils.isKanjiModeEnabled())
2104   )
2105 }
2106
2107 },{"./alphanumeric-data":3,"./byte-data":6,"./kanji-data":12,"./mode":14,"./numeric-data":15,"./regex":19,"./utils":21,"dijkstrajs":31}],21:[function(require,module,exports){
2108 var toSJISFunction
2109 var CODEWORDS_COUNT = [
2110   0, // Not used
2111   26, 44, 70, 100, 134, 172, 196, 242, 292, 346,
2112   404, 466, 532, 581, 655, 733, 815, 901, 991, 1085,
2113   1156, 1258, 1364, 1474, 1588, 1706, 1828, 1921, 2051, 2185,
2114   2323, 2465, 2611, 2761, 2876, 3034, 3196, 3362, 3532, 3706
2115 ]
2116
2117 /**
2118  * Returns the QR Code size for the specified version
2119  *
2120  * @param  {Number} version QR Code version
2121  * @return {Number}         size of QR code
2122  */
2123 exports.getSymbolSize = function getSymbolSize (version) {
2124   if (!version) throw new Error('"version" cannot be null or undefined')
2125   if (version < 1 || version > 40) throw new Error('"version" should be in range from 1 to 40')
2126   return version * 4 + 17
2127 }
2128
2129 /**
2130  * Returns the total number of codewords used to store data and EC information.
2131  *
2132  * @param  {Number} version QR Code version
2133  * @return {Number}         Data length in bits
2134  */
2135 exports.getSymbolTotalCodewords = function getSymbolTotalCodewords (version) {
2136   return CODEWORDS_COUNT[version]
2137 }
2138
2139 /**
2140  * Encode data with Bose-Chaudhuri-Hocquenghem
2141  *
2142  * @param  {Number} data Value to encode
2143  * @return {Number}      Encoded value
2144  */
2145 exports.getBCHDigit = function (data) {
2146   var digit = 0
2147
2148   while (data !== 0) {
2149     digit++
2150     data >>>= 1
2151   }
2152
2153   return digit
2154 }
2155
2156 exports.setToSJISFunction = function setToSJISFunction (f) {
2157   if (typeof f !== 'function') {
2158     throw new Error('"toSJISFunc" is not a valid function.')
2159   }
2160
2161   toSJISFunction = f
2162 }
2163
2164 exports.isKanjiModeEnabled = function () {
2165   return typeof toSJISFunction !== 'undefined'
2166 }
2167
2168 exports.toSJIS = function toSJIS (kanji) {
2169   return toSJISFunction(kanji)
2170 }
2171
2172 },{}],22:[function(require,module,exports){
2173 /**
2174  * Check if QR Code version is valid
2175  *
2176  * @param  {Number}  version QR Code version
2177  * @return {Boolean}         true if valid version, false otherwise
2178  */
2179 exports.isValid = function isValid (version) {
2180   return !isNaN(version) && version >= 1 && version <= 40
2181 }
2182
2183 },{}],23:[function(require,module,exports){
2184 var Utils = require('./utils')
2185 var ECCode = require('./error-correction-code')
2186 var ECLevel = require('./error-correction-level')
2187 var Mode = require('./mode')
2188 var VersionCheck = require('./version-check')
2189 var isArray = require('isarray')
2190
2191 // Generator polynomial used to encode version information
2192 var G18 = (1 << 12) | (1 << 11) | (1 << 10) | (1 << 9) | (1 << 8) | (1 << 5) | (1 << 2) | (1 << 0)
2193 var G18_BCH = Utils.getBCHDigit(G18)
2194
2195 function getBestVersionForDataLength (mode, length, errorCorrectionLevel) {
2196   for (var currentVersion = 1; currentVersion <= 40; currentVersion++) {
2197     if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, mode)) {
2198       return currentVersion
2199     }
2200   }
2201
2202   return undefined
2203 }
2204
2205 function getReservedBitsCount (mode, version) {
2206   // Character count indicator + mode indicator bits
2207   return Mode.getCharCountIndicator(mode, version) + 4
2208 }
2209
2210 function getTotalBitsFromDataArray (segments, version) {
2211   var totalBits = 0
2212
2213   segments.forEach(function (data) {
2214     var reservedBits = getReservedBitsCount(data.mode, version)
2215     totalBits += reservedBits + data.getBitsLength()
2216   })
2217
2218   return totalBits
2219 }
2220
2221 function getBestVersionForMixedData (segments, errorCorrectionLevel) {
2222   for (var currentVersion = 1; currentVersion <= 40; currentVersion++) {
2223     var length = getTotalBitsFromDataArray(segments, currentVersion)
2224     if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, Mode.MIXED)) {
2225       return currentVersion
2226     }
2227   }
2228
2229   return undefined
2230 }
2231
2232 /**
2233  * Returns version number from a value.
2234  * If value is not a valid version, returns defaultValue
2235  *
2236  * @param  {Number|String} value        QR Code version
2237  * @param  {Number}        defaultValue Fallback value
2238  * @return {Number}                     QR Code version number
2239  */
2240 exports.from = function from (value, defaultValue) {
2241   if (VersionCheck.isValid(value)) {
2242     return parseInt(value, 10)
2243   }
2244
2245   return defaultValue
2246 }
2247
2248 /**
2249  * Returns how much data can be stored with the specified QR code version
2250  * and error correction level
2251  *
2252  * @param  {Number} version              QR Code version (1-40)
2253  * @param  {Number} errorCorrectionLevel Error correction level
2254  * @param  {Mode}   mode                 Data mode
2255  * @return {Number}                      Quantity of storable data
2256  */
2257 exports.getCapacity = function getCapacity (version, errorCorrectionLevel, mode) {
2258   if (!VersionCheck.isValid(version)) {
2259     throw new Error('Invalid QR Code version')
2260   }
2261
2262   // Use Byte mode as default
2263   if (typeof mode === 'undefined') mode = Mode.BYTE
2264
2265   // Total codewords for this QR code version (Data + Error correction)
2266   var totalCodewords = Utils.getSymbolTotalCodewords(version)
2267
2268   // Total number of error correction codewords
2269   var ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel)
2270
2271   // Total number of data codewords
2272   var dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8
2273
2274   if (mode === Mode.MIXED) return dataTotalCodewordsBits
2275
2276   var usableBits = dataTotalCodewordsBits - getReservedBitsCount(mode, version)
2277
2278   // Return max number of storable codewords
2279   switch (mode) {
2280     case Mode.NUMERIC:
2281       return Math.floor((usableBits / 10) * 3)
2282
2283     case Mode.ALPHANUMERIC:
2284       return Math.floor((usableBits / 11) * 2)
2285
2286     case Mode.KANJI:
2287       return Math.floor(usableBits / 13)
2288
2289     case Mode.BYTE:
2290     default:
2291       return Math.floor(usableBits / 8)
2292   }
2293 }
2294
2295 /**
2296  * Returns the minimum version needed to contain the amount of data
2297  *
2298  * @param  {Segment} data                    Segment of data
2299  * @param  {Number} [errorCorrectionLevel=H] Error correction level
2300  * @param  {Mode} mode                       Data mode
2301  * @return {Number}                          QR Code version
2302  */
2303 exports.getBestVersionForData = function getBestVersionForData (data, errorCorrectionLevel) {
2304   var seg
2305
2306   var ecl = ECLevel.from(errorCorrectionLevel, ECLevel.M)
2307
2308   if (isArray(data)) {
2309     if (data.length > 1) {
2310       return getBestVersionForMixedData(data, ecl)
2311     }
2312
2313     if (data.length === 0) {
2314       return 1
2315     }
2316
2317     seg = data[0]
2318   } else {
2319     seg = data
2320   }
2321
2322   return getBestVersionForDataLength(seg.mode, seg.getLength(), ecl)
2323 }
2324
2325 /**
2326  * Returns version information with relative error correction bits
2327  *
2328  * The version information is included in QR Code symbols of version 7 or larger.
2329  * It consists of an 18-bit sequence containing 6 data bits,
2330  * with 12 error correction bits calculated using the (18, 6) Golay code.
2331  *
2332  * @param  {Number} version QR Code version
2333  * @return {Number}         Encoded version info bits
2334  */
2335 exports.getEncodedBits = function getEncodedBits (version) {
2336   if (!VersionCheck.isValid(version) || version < 7) {
2337     throw new Error('Invalid QR Code version')
2338   }
2339
2340   var d = version << 12
2341
2342   while (Utils.getBCHDigit(d) - G18_BCH >= 0) {
2343     d ^= (G18 << (Utils.getBCHDigit(d) - G18_BCH))
2344   }
2345
2346   return (version << 12) | d
2347 }
2348
2349 },{"./error-correction-code":7,"./error-correction-level":8,"./mode":14,"./utils":21,"./version-check":22,"isarray":33}],24:[function(require,module,exports){
2350
2351 var canPromise = require('./can-promise')
2352
2353 var QRCode = require('./core/qrcode')
2354 var CanvasRenderer = require('./renderer/canvas')
2355 var SvgRenderer = require('./renderer/svg-tag.js')
2356
2357 function renderCanvas (renderFunc, canvas, text, opts, cb) {
2358   var args = [].slice.call(arguments, 1)
2359   var argsNum = args.length
2360   var isLastArgCb = typeof args[argsNum - 1] === 'function'
2361
2362   if (!isLastArgCb && !canPromise()) {
2363     throw new Error('Callback required as last argument')
2364   }
2365
2366   if (isLastArgCb) {
2367     if (argsNum < 2) {
2368       throw new Error('Too few arguments provided')
2369     }
2370
2371     if (argsNum === 2) {
2372       cb = text
2373       text = canvas
2374       canvas = opts = undefined
2375     } else if (argsNum === 3) {
2376       if (canvas.getContext && typeof cb === 'undefined') {
2377         cb = opts
2378         opts = undefined
2379       } else {
2380         cb = opts
2381         opts = text
2382         text = canvas
2383         canvas = undefined
2384       }
2385     }
2386   } else {
2387     if (argsNum < 1) {
2388       throw new Error('Too few arguments provided')
2389     }
2390
2391     if (argsNum === 1) {
2392       text = canvas
2393       canvas = opts = undefined
2394     } else if (argsNum === 2 && !canvas.getContext) {
2395       opts = text
2396       text = canvas
2397       canvas = undefined
2398     }
2399
2400     return new Promise(function (resolve, reject) {
2401       try {
2402         var data = QRCode.create(text, opts)
2403         resolve(renderFunc(data, canvas, opts))
2404       } catch (e) {
2405         reject(e)
2406       }
2407     })
2408   }
2409
2410   try {
2411     var data = QRCode.create(text, opts)
2412     cb(null, renderFunc(data, canvas, opts))
2413   } catch (e) {
2414     cb(e)
2415   }
2416 }
2417
2418 exports.create = QRCode.create
2419 exports.toCanvas = renderCanvas.bind(null, CanvasRenderer.render)
2420 exports.toDataURL = renderCanvas.bind(null, CanvasRenderer.renderToDataURL)
2421
2422 // only svg for now.
2423 exports.toString = renderCanvas.bind(null, function (data, _, opts) {
2424   return SvgRenderer.render(data, opts)
2425 })
2426
2427 },{"./can-promise":1,"./core/qrcode":17,"./renderer/canvas":25,"./renderer/svg-tag.js":26}],25:[function(require,module,exports){
2428 var Utils = require('./utils')
2429
2430 function clearCanvas (ctx, canvas, size) {
2431   ctx.clearRect(0, 0, canvas.width, canvas.height)
2432
2433   if (!canvas.style) canvas.style = {}
2434   canvas.height = size
2435   canvas.width = size
2436   canvas.style.height = size + 'px'
2437   canvas.style.width = size + 'px'
2438 }
2439
2440 function getCanvasElement () {
2441   try {
2442     return document.createElement('canvas')
2443   } catch (e) {
2444     throw new Error('You need to specify a canvas element')
2445   }
2446 }
2447
2448 exports.render = function render (qrData, canvas, options) {
2449   var opts = options
2450   var canvasEl = canvas
2451
2452   if (typeof opts === 'undefined' && (!canvas || !canvas.getContext)) {
2453     opts = canvas
2454     canvas = undefined
2455   }
2456
2457   if (!canvas) {
2458     canvasEl = getCanvasElement()
2459   }
2460
2461   opts = Utils.getOptions(opts)
2462   var size = Utils.getImageWidth(qrData.modules.size, opts)
2463
2464   var ctx = canvasEl.getContext('2d')
2465   var image = ctx.createImageData(size, size)
2466   Utils.qrToImageData(image.data, qrData, opts)
2467
2468   clearCanvas(ctx, canvasEl, size)
2469   ctx.putImageData(image, 0, 0)
2470
2471   return canvasEl
2472 }
2473
2474 exports.renderToDataURL = function renderToDataURL (qrData, canvas, options) {
2475   var opts = options
2476
2477   if (typeof opts === 'undefined' && (!canvas || !canvas.getContext)) {
2478     opts = canvas
2479     canvas = undefined
2480   }
2481
2482   if (!opts) opts = {}
2483
2484   var canvasEl = exports.render(qrData, canvas, opts)
2485
2486   var type = opts.type || 'image/png'
2487   var rendererOpts = opts.rendererOpts || {}
2488
2489   return canvasEl.toDataURL(type, rendererOpts.quality)
2490 }
2491
2492 },{"./utils":27}],26:[function(require,module,exports){
2493 var Utils = require('./utils')
2494
2495 function getColorAttrib (color, attrib) {
2496   var alpha = color.a / 255
2497   var str = attrib + '="' + color.hex + '"'
2498
2499   return alpha < 1
2500     ? str + ' ' + attrib + '-opacity="' + alpha.toFixed(2).slice(1) + '"'
2501     : str
2502 }
2503
2504 function svgCmd (cmd, x, y) {
2505   var str = cmd + x
2506   if (typeof y !== 'undefined') str += ' ' + y
2507
2508   return str
2509 }
2510
2511 function qrToPath (data, size, margin) {
2512   var path = ''
2513   var moveBy = 0
2514   var newRow = false
2515   var lineLength = 0
2516
2517   for (var i = 0; i < data.length; i++) {
2518     var col = Math.floor(i % size)
2519     var row = Math.floor(i / size)
2520
2521     if (!col && !newRow) newRow = true
2522
2523     if (data[i]) {
2524       lineLength++
2525
2526       if (!(i > 0 && col > 0 && data[i - 1])) {
2527         path += newRow
2528           ? svgCmd('M', col + margin, 0.5 + row + margin)
2529           : svgCmd('m', moveBy, 0)
2530
2531         moveBy = 0
2532         newRow = false
2533       }
2534
2535       if (!(col + 1 < size && data[i + 1])) {
2536         path += svgCmd('h', lineLength)
2537         lineLength = 0
2538       }
2539     } else {
2540       moveBy++
2541     }
2542   }
2543
2544   return path
2545 }
2546
2547 exports.render = function render (qrData, options, cb) {
2548   var opts = Utils.getOptions(options)
2549   var size = qrData.modules.size
2550   var data = qrData.modules.data
2551   var qrcodesize = size + opts.margin * 2
2552
2553   var bg = !opts.color.light.a
2554     ? ''
2555     : '<path ' + getColorAttrib(opts.color.light, 'fill') +
2556       ' d="M0 0h' + qrcodesize + 'v' + qrcodesize + 'H0z"/>'
2557
2558   var path =
2559     '<path ' + getColorAttrib(opts.color.dark, 'stroke') +
2560     ' d="' + qrToPath(data, size, opts.margin) + '"/>'
2561
2562   var viewBox = 'viewBox="' + '0 0 ' + qrcodesize + ' ' + qrcodesize + '"'
2563
2564   var width = !opts.width ? '' : 'width="' + opts.width + '" height="' + opts.width + '" '
2565
2566   var svgTag = '<svg xmlns="http://www.w3.org/2000/svg" ' + width + viewBox + ' shape-rendering="crispEdges">' + bg + path + '</svg>\n'
2567
2568   if (typeof cb === 'function') {
2569     cb(null, svgTag)
2570   }
2571
2572   return svgTag
2573 }
2574
2575 },{"./utils":27}],27:[function(require,module,exports){
2576 function hex2rgba (hex) {
2577   if (typeof hex === 'number') {
2578     hex = hex.toString()
2579   }
2580
2581   if (typeof hex !== 'string') {
2582     throw new Error('Color should be defined as hex string')
2583   }
2584
2585   var hexCode = hex.slice().replace('#', '').split('')
2586   if (hexCode.length < 3 || hexCode.length === 5 || hexCode.length > 8) {
2587     throw new Error('Invalid hex color: ' + hex)
2588   }
2589
2590   // Convert from short to long form (fff -> ffffff)
2591   if (hexCode.length === 3 || hexCode.length === 4) {
2592     hexCode = Array.prototype.concat.apply([], hexCode.map(function (c) {
2593       return [c, c]
2594     }))
2595   }
2596
2597   // Add default alpha value
2598   if (hexCode.length === 6) hexCode.push('F', 'F')
2599
2600   var hexValue = parseInt(hexCode.join(''), 16)
2601
2602   return {
2603     r: (hexValue >> 24) & 255,
2604     g: (hexValue >> 16) & 255,
2605     b: (hexValue >> 8) & 255,
2606     a: hexValue & 255,
2607     hex: '#' + hexCode.slice(0, 6).join('')
2608   }
2609 }
2610
2611 exports.getOptions = function getOptions (options) {
2612   if (!options) options = {}
2613   if (!options.color) options.color = {}
2614
2615   var margin = typeof options.margin === 'undefined' ||
2616     options.margin === null ||
2617     options.margin < 0 ? 4 : options.margin
2618
2619   var width = options.width && options.width >= 21 ? options.width : undefined
2620   var scale = options.scale || 4
2621
2622   return {
2623     width: width,
2624     scale: width ? 4 : scale,
2625     margin: margin,
2626     color: {
2627       dark: hex2rgba(options.color.dark || '#000000ff'),
2628       light: hex2rgba(options.color.light || '#ffffffff')
2629     },
2630     type: options.type,
2631     rendererOpts: options.rendererOpts || {}
2632   }
2633 }
2634
2635 exports.getScale = function getScale (qrSize, opts) {
2636   return opts.width && opts.width >= qrSize + opts.margin * 2
2637     ? opts.width / (qrSize + opts.margin * 2)
2638     : opts.scale
2639 }
2640
2641 exports.getImageWidth = function getImageWidth (qrSize, opts) {
2642   var scale = exports.getScale(qrSize, opts)
2643   return Math.floor((qrSize + opts.margin * 2) * scale)
2644 }
2645
2646 exports.qrToImageData = function qrToImageData (imgData, qr, opts) {
2647   var size = qr.modules.size
2648   var data = qr.modules.data
2649   var scale = exports.getScale(size, opts)
2650   var symbolSize = Math.floor((size + opts.margin * 2) * scale)
2651   var scaledMargin = opts.margin * scale
2652   var palette = [opts.color.light, opts.color.dark]
2653
2654   for (var i = 0; i < symbolSize; i++) {
2655     for (var j = 0; j < symbolSize; j++) {
2656       var posDst = (i * symbolSize + j) * 4
2657       var pxColor = opts.color.light
2658
2659       if (i >= scaledMargin && j >= scaledMargin &&
2660         i < symbolSize - scaledMargin && j < symbolSize - scaledMargin) {
2661         var iSrc = Math.floor((i - scaledMargin) / scale)
2662         var jSrc = Math.floor((j - scaledMargin) / scale)
2663         pxColor = palette[data[iSrc * size + jSrc] ? 1 : 0]
2664       }
2665
2666       imgData[posDst++] = pxColor.r
2667       imgData[posDst++] = pxColor.g
2668       imgData[posDst++] = pxColor.b
2669       imgData[posDst] = pxColor.a
2670     }
2671   }
2672 }
2673
2674 },{}],28:[function(require,module,exports){
2675 /**
2676  * Implementation of a subset of node.js Buffer methods for the browser.
2677  * Based on https://github.com/feross/buffer
2678  */
2679
2680 /* eslint-disable no-proto */
2681
2682 'use strict'
2683
2684 var isArray = require('isarray')
2685
2686 function typedArraySupport () {
2687   // Can typed array instances be augmented?
2688   try {
2689     var arr = new Uint8Array(1)
2690     arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }}
2691     return arr.foo() === 42
2692   } catch (e) {
2693     return false
2694   }
2695 }
2696
2697 Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport()
2698
2699 var K_MAX_LENGTH = Buffer.TYPED_ARRAY_SUPPORT
2700     ? 0x7fffffff
2701     : 0x3fffffff
2702
2703 function Buffer (arg, offset, length) {
2704   if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) {
2705     return new Buffer(arg, offset, length)
2706   }
2707
2708   if (typeof arg === 'number') {
2709     return allocUnsafe(this, arg)
2710   }
2711
2712   return from(this, arg, offset, length)
2713 }
2714
2715 if (Buffer.TYPED_ARRAY_SUPPORT) {
2716   Buffer.prototype.__proto__ = Uint8Array.prototype
2717   Buffer.__proto__ = Uint8Array
2718
2719   // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
2720   if (typeof Symbol !== 'undefined' && Symbol.species &&
2721       Buffer[Symbol.species] === Buffer) {
2722     Object.defineProperty(Buffer, Symbol.species, {
2723       value: null,
2724       configurable: true,
2725       enumerable: false,
2726       writable: false
2727     })
2728   }
2729 }
2730
2731 function checked (length) {
2732   // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
2733   // length is NaN (which is otherwise coerced to zero.)
2734   if (length >= K_MAX_LENGTH) {
2735     throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
2736                          'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
2737   }
2738   return length | 0
2739 }
2740
2741 function isnan (val) {
2742   return val !== val // eslint-disable-line no-self-compare
2743 }
2744
2745 function createBuffer (that, length) {
2746   var buf
2747   if (Buffer.TYPED_ARRAY_SUPPORT) {
2748     buf = new Uint8Array(length)
2749     buf.__proto__ = Buffer.prototype
2750   } else {
2751     // Fallback: Return an object instance of the Buffer class
2752     buf = that
2753     if (buf === null) {
2754       buf = new Buffer(length)
2755     }
2756     buf.length = length
2757   }
2758
2759   return buf
2760 }
2761
2762 function allocUnsafe (that, size) {
2763   var buf = createBuffer(that, size < 0 ? 0 : checked(size) | 0)
2764
2765   if (!Buffer.TYPED_ARRAY_SUPPORT) {
2766     for (var i = 0; i < size; ++i) {
2767       buf[i] = 0
2768     }
2769   }
2770
2771   return buf
2772 }
2773
2774 function fromString (that, string) {
2775   var length = byteLength(string) | 0
2776   var buf = createBuffer(that, length)
2777
2778   var actual = buf.write(string)
2779
2780   if (actual !== length) {
2781     // Writing a hex string, for example, that contains invalid characters will
2782     // cause everything after the first invalid character to be ignored. (e.g.
2783     // 'abxxcd' will be treated as 'ab')
2784     buf = buf.slice(0, actual)
2785   }
2786
2787   return buf
2788 }
2789
2790 function fromArrayLike (that, array) {
2791   var length = array.length < 0 ? 0 : checked(array.length) | 0
2792   var buf = createBuffer(that, length)
2793   for (var i = 0; i < length; i += 1) {
2794     buf[i] = array[i] & 255
2795   }
2796   return buf
2797 }
2798
2799 function fromArrayBuffer (that, array, byteOffset, length) {
2800   if (byteOffset < 0 || array.byteLength < byteOffset) {
2801     throw new RangeError('\'offset\' is out of bounds')
2802   }
2803
2804   if (array.byteLength < byteOffset + (length || 0)) {
2805     throw new RangeError('\'length\' is out of bounds')
2806   }
2807
2808   var buf
2809   if (byteOffset === undefined && length === undefined) {
2810     buf = new Uint8Array(array)
2811   } else if (length === undefined) {
2812     buf = new Uint8Array(array, byteOffset)
2813   } else {
2814     buf = new Uint8Array(array, byteOffset, length)
2815   }
2816
2817   if (Buffer.TYPED_ARRAY_SUPPORT) {
2818     // Return an augmented `Uint8Array` instance, for best performance
2819     buf.__proto__ = Buffer.prototype
2820   } else {
2821     // Fallback: Return an object instance of the Buffer class
2822     buf = fromArrayLike(that, buf)
2823   }
2824
2825   return buf
2826 }
2827
2828 function fromObject (that, obj) {
2829   if (Buffer.isBuffer(obj)) {
2830     var len = checked(obj.length) | 0
2831     var buf = createBuffer(that, len)
2832
2833     if (buf.length === 0) {
2834       return buf
2835     }
2836
2837     obj.copy(buf, 0, 0, len)
2838     return buf
2839   }
2840
2841   if (obj) {
2842     if ((typeof ArrayBuffer !== 'undefined' &&
2843         obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
2844       if (typeof obj.length !== 'number' || isnan(obj.length)) {
2845         return createBuffer(that, 0)
2846       }
2847       return fromArrayLike(that, obj)
2848     }
2849
2850     if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
2851       return fromArrayLike(that, obj.data)
2852     }
2853   }
2854
2855   throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
2856 }
2857
2858 function utf8ToBytes (string, units) {
2859   units = units || Infinity
2860   var codePoint
2861   var length = string.length
2862   var leadSurrogate = null
2863   var bytes = []
2864
2865   for (var i = 0; i < length; ++i) {
2866     codePoint = string.charCodeAt(i)
2867
2868     // is surrogate component
2869     if (codePoint > 0xD7FF && codePoint < 0xE000) {
2870       // last char was a lead
2871       if (!leadSurrogate) {
2872         // no lead yet
2873         if (codePoint > 0xDBFF) {
2874           // unexpected trail
2875           if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
2876           continue
2877         } else if (i + 1 === length) {
2878           // unpaired lead
2879           if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
2880           continue
2881         }
2882
2883         // valid lead
2884         leadSurrogate = codePoint
2885
2886         continue
2887       }
2888
2889       // 2 leads in a row
2890       if (codePoint < 0xDC00) {
2891         if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
2892         leadSurrogate = codePoint
2893         continue
2894       }
2895
2896       // valid surrogate pair
2897       codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
2898     } else if (leadSurrogate) {
2899       // valid bmp char, but last char was a lead
2900       if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
2901     }
2902
2903     leadSurrogate = null
2904
2905     // encode utf8
2906     if (codePoint < 0x80) {
2907       if ((units -= 1) < 0) break
2908       bytes.push(codePoint)
2909     } else if (codePoint < 0x800) {
2910       if ((units -= 2) < 0) break
2911       bytes.push(
2912         codePoint >> 0x6 | 0xC0,
2913         codePoint & 0x3F | 0x80
2914       )
2915     } else if (codePoint < 0x10000) {
2916       if ((units -= 3) < 0) break
2917       bytes.push(
2918         codePoint >> 0xC | 0xE0,
2919         codePoint >> 0x6 & 0x3F | 0x80,
2920         codePoint & 0x3F | 0x80
2921       )
2922     } else if (codePoint < 0x110000) {
2923       if ((units -= 4) < 0) break
2924       bytes.push(
2925         codePoint >> 0x12 | 0xF0,
2926         codePoint >> 0xC & 0x3F | 0x80,
2927         codePoint >> 0x6 & 0x3F | 0x80,
2928         codePoint & 0x3F | 0x80
2929       )
2930     } else {
2931       throw new Error('Invalid code point')
2932     }
2933   }
2934
2935   return bytes
2936 }
2937
2938 function byteLength (string) {
2939   if (Buffer.isBuffer(string)) {
2940     return string.length
2941   }
2942   if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
2943       (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
2944     return string.byteLength
2945   }
2946   if (typeof string !== 'string') {
2947     string = '' + string
2948   }
2949
2950   var len = string.length
2951   if (len === 0) return 0
2952
2953   return utf8ToBytes(string).length
2954 }
2955
2956 function blitBuffer (src, dst, offset, length) {
2957   for (var i = 0; i < length; ++i) {
2958     if ((i + offset >= dst.length) || (i >= src.length)) break
2959     dst[i + offset] = src[i]
2960   }
2961   return i
2962 }
2963
2964 function utf8Write (buf, string, offset, length) {
2965   return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
2966 }
2967
2968 function from (that, value, offset, length) {
2969   if (typeof value === 'number') {
2970     throw new TypeError('"value" argument must not be a number')
2971   }
2972
2973   if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
2974     return fromArrayBuffer(that, value, offset, length)
2975   }
2976
2977   if (typeof value === 'string') {
2978     return fromString(that, value, offset)
2979   }
2980
2981   return fromObject(that, value)
2982 }
2983
2984 Buffer.prototype.write = function write (string, offset, length) {
2985   // Buffer#write(string)
2986   if (offset === undefined) {
2987     length = this.length
2988     offset = 0
2989   // Buffer#write(string, encoding)
2990   } else if (length === undefined && typeof offset === 'string') {
2991     length = this.length
2992     offset = 0
2993   // Buffer#write(string, offset[, length])
2994   } else if (isFinite(offset)) {
2995     offset = offset | 0
2996     if (isFinite(length)) {
2997       length = length | 0
2998     } else {
2999       length = undefined
3000     }
3001   }
3002
3003   var remaining = this.length - offset
3004   if (length === undefined || length > remaining) length = remaining
3005
3006   if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
3007     throw new RangeError('Attempt to write outside buffer bounds')
3008   }
3009
3010   return utf8Write(this, string, offset, length)
3011 }
3012
3013 Buffer.prototype.slice = function slice (start, end) {
3014   var len = this.length
3015   start = ~~start
3016   end = end === undefined ? len : ~~end
3017
3018   if (start < 0) {
3019     start += len
3020     if (start < 0) start = 0
3021   } else if (start > len) {
3022     start = len
3023   }
3024
3025   if (end < 0) {
3026     end += len
3027     if (end < 0) end = 0
3028   } else if (end > len) {
3029     end = len
3030   }
3031
3032   if (end < start) end = start
3033
3034   var newBuf
3035   if (Buffer.TYPED_ARRAY_SUPPORT) {
3036     newBuf = this.subarray(start, end)
3037     // Return an augmented `Uint8Array` instance
3038     newBuf.__proto__ = Buffer.prototype
3039   } else {
3040     var sliceLen = end - start
3041     newBuf = new Buffer(sliceLen, undefined)
3042     for (var i = 0; i < sliceLen; ++i) {
3043       newBuf[i] = this[i + start]
3044     }
3045   }
3046
3047   return newBuf
3048 }
3049
3050 Buffer.prototype.copy = function copy (target, targetStart, start, end) {
3051   if (!start) start = 0
3052   if (!end && end !== 0) end = this.length
3053   if (targetStart >= target.length) targetStart = target.length
3054   if (!targetStart) targetStart = 0
3055   if (end > 0 && end < start) end = start
3056
3057   // Copy 0 bytes; we're done
3058   if (end === start) return 0
3059   if (target.length === 0 || this.length === 0) return 0
3060
3061   // Fatal error conditions
3062   if (targetStart < 0) {
3063     throw new RangeError('targetStart out of bounds')
3064   }
3065   if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
3066   if (end < 0) throw new RangeError('sourceEnd out of bounds')
3067
3068   // Are we oob?
3069   if (end > this.length) end = this.length
3070   if (target.length - targetStart < end - start) {
3071     end = target.length - targetStart + start
3072   }
3073
3074   var len = end - start
3075   var i
3076
3077   if (this === target && start < targetStart && targetStart < end) {
3078     // descending copy from end
3079     for (i = len - 1; i >= 0; --i) {
3080       target[i + targetStart] = this[i + start]
3081     }
3082   } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
3083     // ascending copy from start
3084     for (i = 0; i < len; ++i) {
3085       target[i + targetStart] = this[i + start]
3086     }
3087   } else {
3088     Uint8Array.prototype.set.call(
3089       target,
3090       this.subarray(start, start + len),
3091       targetStart
3092     )
3093   }
3094
3095   return len
3096 }
3097
3098 Buffer.prototype.fill = function fill (val, start, end) {
3099   // Handle string cases:
3100   if (typeof val === 'string') {
3101     if (typeof start === 'string') {
3102       start = 0
3103       end = this.length
3104     } else if (typeof end === 'string') {
3105       end = this.length
3106     }
3107     if (val.length === 1) {
3108       var code = val.charCodeAt(0)
3109       if (code < 256) {
3110         val = code
3111       }
3112     }
3113   } else if (typeof val === 'number') {
3114     val = val & 255
3115   }
3116
3117   // Invalid ranges are not set to a default, so can range check early.
3118   if (start < 0 || this.length < start || this.length < end) {
3119     throw new RangeError('Out of range index')
3120   }
3121
3122   if (end <= start) {
3123     return this
3124   }
3125
3126   start = start >>> 0
3127   end = end === undefined ? this.length : end >>> 0
3128
3129   if (!val) val = 0
3130
3131   var i
3132   if (typeof val === 'number') {
3133     for (i = start; i < end; ++i) {
3134       this[i] = val
3135     }
3136   } else {
3137     var bytes = Buffer.isBuffer(val)
3138       ? val
3139       : new Buffer(val)
3140     var len = bytes.length
3141     for (i = 0; i < end - start; ++i) {
3142       this[i + start] = bytes[i % len]
3143     }
3144   }
3145
3146   return this
3147 }
3148
3149 Buffer.concat = function concat (list, length) {
3150   if (!isArray(list)) {
3151     throw new TypeError('"list" argument must be an Array of Buffers')
3152   }
3153
3154   if (list.length === 0) {
3155     return createBuffer(null, 0)
3156   }
3157
3158   var i
3159   if (length === undefined) {
3160     length = 0
3161     for (i = 0; i < list.length; ++i) {
3162       length += list[i].length
3163     }
3164   }
3165
3166   var buffer = allocUnsafe(null, length)
3167   var pos = 0
3168   for (i = 0; i < list.length; ++i) {
3169     var buf = list[i]
3170     if (!Buffer.isBuffer(buf)) {
3171       throw new TypeError('"list" argument must be an Array of Buffers')
3172     }
3173     buf.copy(buffer, pos)
3174     pos += buf.length
3175   }
3176   return buffer
3177 }
3178
3179 Buffer.byteLength = byteLength
3180
3181 Buffer.prototype._isBuffer = true
3182 Buffer.isBuffer = function isBuffer (b) {
3183   return !!(b != null && b._isBuffer)
3184 }
3185
3186 module.exports.alloc = function (size) {
3187   var buffer = new Buffer(size)
3188   buffer.fill(0)
3189   return buffer
3190 }
3191
3192 module.exports.from = function (data) {
3193   return new Buffer(data)
3194 }
3195
3196 },{"isarray":33}],29:[function(require,module,exports){
3197 'use strict'
3198
3199 exports.byteLength = byteLength
3200 exports.toByteArray = toByteArray
3201 exports.fromByteArray = fromByteArray
3202
3203 var lookup = []
3204 var revLookup = []
3205 var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
3206
3207 var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
3208 for (var i = 0, len = code.length; i < len; ++i) {
3209   lookup[i] = code[i]
3210   revLookup[code.charCodeAt(i)] = i
3211 }
3212
3213 // Support decoding URL-safe base64 strings, as Node.js does.
3214 // See: https://en.wikipedia.org/wiki/Base64#URL_applications
3215 revLookup['-'.charCodeAt(0)] = 62
3216 revLookup['_'.charCodeAt(0)] = 63
3217
3218 function getLens (b64) {
3219   var len = b64.length
3220
3221   if (len % 4 > 0) {
3222     throw new Error('Invalid string. Length must be a multiple of 4')
3223   }
3224
3225   // Trim off extra bytes after placeholder bytes are found
3226   // See: https://github.com/beatgammit/base64-js/issues/42
3227   var validLen = b64.indexOf('=')
3228   if (validLen === -1) validLen = len
3229
3230   var placeHoldersLen = validLen === len
3231     ? 0
3232     : 4 - (validLen % 4)
3233
3234   return [validLen, placeHoldersLen]
3235 }
3236
3237 // base64 is 4/3 + up to two characters of the original data
3238 function byteLength (b64) {
3239   var lens = getLens(b64)
3240   var validLen = lens[0]
3241   var placeHoldersLen = lens[1]
3242   return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
3243 }
3244
3245 function _byteLength (b64, validLen, placeHoldersLen) {
3246   return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
3247 }
3248
3249 function toByteArray (b64) {
3250   var tmp
3251   var lens = getLens(b64)
3252   var validLen = lens[0]
3253   var placeHoldersLen = lens[1]
3254
3255   var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen))
3256
3257   var curByte = 0
3258
3259   // if there are placeholders, only get up to the last complete 4 chars
3260   var len = placeHoldersLen > 0
3261     ? validLen - 4
3262     : validLen
3263
3264   var i
3265   for (i = 0; i < len; i += 4) {
3266     tmp =
3267       (revLookup[b64.charCodeAt(i)] << 18) |
3268       (revLookup[b64.charCodeAt(i + 1)] << 12) |
3269       (revLookup[b64.charCodeAt(i + 2)] << 6) |
3270       revLookup[b64.charCodeAt(i + 3)]
3271     arr[curByte++] = (tmp >> 16) & 0xFF
3272     arr[curByte++] = (tmp >> 8) & 0xFF
3273     arr[curByte++] = tmp & 0xFF
3274   }
3275
3276   if (placeHoldersLen === 2) {
3277     tmp =
3278       (revLookup[b64.charCodeAt(i)] << 2) |
3279       (revLookup[b64.charCodeAt(i + 1)] >> 4)
3280     arr[curByte++] = tmp & 0xFF
3281   }
3282
3283   if (placeHoldersLen === 1) {
3284     tmp =
3285       (revLookup[b64.charCodeAt(i)] << 10) |
3286       (revLookup[b64.charCodeAt(i + 1)] << 4) |
3287       (revLookup[b64.charCodeAt(i + 2)] >> 2)
3288     arr[curByte++] = (tmp >> 8) & 0xFF
3289     arr[curByte++] = tmp & 0xFF
3290   }
3291
3292   return arr
3293 }
3294
3295 function tripletToBase64 (num) {
3296   return lookup[num >> 18 & 0x3F] +
3297     lookup[num >> 12 & 0x3F] +
3298     lookup[num >> 6 & 0x3F] +
3299     lookup[num & 0x3F]
3300 }
3301
3302 function encodeChunk (uint8, start, end) {
3303   var tmp
3304   var output = []
3305   for (var i = start; i < end; i += 3) {
3306     tmp =
3307       ((uint8[i] << 16) & 0xFF0000) +
3308       ((uint8[i + 1] << 8) & 0xFF00) +
3309       (uint8[i + 2] & 0xFF)
3310     output.push(tripletToBase64(tmp))
3311   }
3312   return output.join('')
3313 }
3314
3315 function fromByteArray (uint8) {
3316   var tmp
3317   var len = uint8.length
3318   var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
3319   var parts = []
3320   var maxChunkLength = 16383 // must be multiple of 3
3321
3322   // go through the array every three bytes, we'll deal with trailing stuff later
3323   for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
3324     parts.push(encodeChunk(
3325       uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)
3326     ))
3327   }
3328
3329   // pad the end with zeros, but make sure to not forget the extra bytes
3330   if (extraBytes === 1) {
3331     tmp = uint8[len - 1]
3332     parts.push(
3333       lookup[tmp >> 2] +
3334       lookup[(tmp << 4) & 0x3F] +
3335       '=='
3336     )
3337   } else if (extraBytes === 2) {
3338     tmp = (uint8[len - 2] << 8) + uint8[len - 1]
3339     parts.push(
3340       lookup[tmp >> 10] +
3341       lookup[(tmp >> 4) & 0x3F] +
3342       lookup[(tmp << 2) & 0x3F] +
3343       '='
3344     )
3345   }
3346
3347   return parts.join('')
3348 }
3349
3350 },{}],30:[function(require,module,exports){
3351 /*!
3352  * The buffer module from node.js, for the browser.
3353  *
3354  * @author   Feross Aboukhadijeh <https://feross.org>
3355  * @license  MIT
3356  */
3357 /* eslint-disable no-proto */
3358
3359 'use strict'
3360
3361 var base64 = require('base64-js')
3362 var ieee754 = require('ieee754')
3363 var customInspectSymbol =
3364   (typeof Symbol === 'function' && typeof Symbol.for === 'function')
3365     ? Symbol.for('nodejs.util.inspect.custom')
3366     : null
3367
3368 exports.Buffer = Buffer
3369 exports.SlowBuffer = SlowBuffer
3370 exports.INSPECT_MAX_BYTES = 50
3371
3372 var K_MAX_LENGTH = 0x7fffffff
3373 exports.kMaxLength = K_MAX_LENGTH
3374
3375 /**
3376  * If `Buffer.TYPED_ARRAY_SUPPORT`:
3377  *   === true    Use Uint8Array implementation (fastest)
3378  *   === false   Print warning and recommend using `buffer` v4.x which has an Object
3379  *               implementation (most compatible, even IE6)
3380  *
3381  * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
3382  * Opera 11.6+, iOS 4.2+.
3383  *
3384  * We report that the browser does not support typed arrays if the are not subclassable
3385  * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
3386  * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
3387  * for __proto__ and has a buggy typed array implementation.
3388  */
3389 Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport()
3390
3391 if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
3392     typeof console.error === 'function') {
3393   console.error(
3394     'This browser lacks typed array (Uint8Array) support which is required by ' +
3395     '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
3396   )
3397 }
3398
3399 function typedArraySupport () {
3400   // Can typed array instances can be augmented?
3401   try {
3402     var arr = new Uint8Array(1)
3403     var proto = { foo: function () { return 42 } }
3404     Object.setPrototypeOf(proto, Uint8Array.prototype)
3405     Object.setPrototypeOf(arr, proto)
3406     return arr.foo() === 42
3407   } catch (e) {
3408     return false
3409   }
3410 }
3411
3412 Object.defineProperty(Buffer.prototype, 'parent', {
3413   enumerable: true,
3414   get: function () {
3415     if (!Buffer.isBuffer(this)) return undefined
3416     return this.buffer
3417   }
3418 })
3419
3420 Object.defineProperty(Buffer.prototype, 'offset', {
3421   enumerable: true,
3422   get: function () {
3423     if (!Buffer.isBuffer(this)) return undefined
3424     return this.byteOffset
3425   }
3426 })
3427
3428 function createBuffer (length) {
3429   if (length > K_MAX_LENGTH) {
3430     throw new RangeError('The value "' + length + '" is invalid for option "size"')
3431   }
3432   // Return an augmented `Uint8Array` instance
3433   var buf = new Uint8Array(length)
3434   Object.setPrototypeOf(buf, Buffer.prototype)
3435   return buf
3436 }
3437
3438 /**
3439  * The Buffer constructor returns instances of `Uint8Array` that have their
3440  * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
3441  * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
3442  * and the `Uint8Array` methods. Square bracket notation works as expected -- it
3443  * returns a single octet.
3444  *
3445  * The `Uint8Array` prototype remains unmodified.
3446  */
3447
3448 function Buffer (arg, encodingOrOffset, length) {
3449   // Common case.
3450   if (typeof arg === 'number') {
3451     if (typeof encodingOrOffset === 'string') {
3452       throw new TypeError(
3453         'The "string" argument must be of type string. Received type number'
3454       )
3455     }
3456     return allocUnsafe(arg)
3457   }
3458   return from(arg, encodingOrOffset, length)
3459 }
3460
3461 // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
3462 if (typeof Symbol !== 'undefined' && Symbol.species != null &&
3463     Buffer[Symbol.species] === Buffer) {
3464   Object.defineProperty(Buffer, Symbol.species, {
3465     value: null,
3466     configurable: true,
3467     enumerable: false,
3468     writable: false
3469   })
3470 }
3471
3472 Buffer.poolSize = 8192 // not used by this implementation
3473
3474 function from (value, encodingOrOffset, length) {
3475   if (typeof value === 'string') {
3476     return fromString(value, encodingOrOffset)
3477   }
3478
3479   if (ArrayBuffer.isView(value)) {
3480     return fromArrayLike(value)
3481   }
3482
3483   if (value == null) {
3484     throw new TypeError(
3485       'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
3486       'or Array-like Object. Received type ' + (typeof value)
3487     )
3488   }
3489
3490   if (isInstance(value, ArrayBuffer) ||
3491       (value && isInstance(value.buffer, ArrayBuffer))) {
3492     return fromArrayBuffer(value, encodingOrOffset, length)
3493   }
3494
3495   if (typeof value === 'number') {
3496     throw new TypeError(
3497       'The "value" argument must not be of type number. Received type number'
3498     )
3499   }
3500
3501   var valueOf = value.valueOf && value.valueOf()
3502   if (valueOf != null && valueOf !== value) {
3503     return Buffer.from(valueOf, encodingOrOffset, length)
3504   }
3505
3506   var b = fromObject(value)
3507   if (b) return b
3508
3509   if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null &&
3510       typeof value[Symbol.toPrimitive] === 'function') {
3511     return Buffer.from(
3512       value[Symbol.toPrimitive]('string'), encodingOrOffset, length
3513     )
3514   }
3515
3516   throw new TypeError(
3517     'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
3518     'or Array-like Object. Received type ' + (typeof value)
3519   )
3520 }
3521
3522 /**
3523  * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
3524  * if value is a number.
3525  * Buffer.from(str[, encoding])
3526  * Buffer.from(array)
3527  * Buffer.from(buffer)
3528  * Buffer.from(arrayBuffer[, byteOffset[, length]])
3529  **/
3530 Buffer.from = function (value, encodingOrOffset, length) {
3531   return from(value, encodingOrOffset, length)
3532 }
3533
3534 // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
3535 // https://github.com/feross/buffer/pull/148
3536 Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype)
3537 Object.setPrototypeOf(Buffer, Uint8Array)
3538
3539 function assertSize (size) {
3540   if (typeof size !== 'number') {
3541     throw new TypeError('"size" argument must be of type number')
3542   } else if (size < 0) {
3543     throw new RangeError('The value "' + size + '" is invalid for option "size"')
3544   }
3545 }
3546
3547 function alloc (size, fill, encoding) {
3548   assertSize(size)
3549   if (size <= 0) {
3550     return createBuffer(size)
3551   }
3552   if (fill !== undefined) {
3553     // Only pay attention to encoding if it's a string. This
3554     // prevents accidentally sending in a number that would
3555     // be interpretted as a start offset.
3556     return typeof encoding === 'string'
3557       ? createBuffer(size).fill(fill, encoding)
3558       : createBuffer(size).fill(fill)
3559   }
3560   return createBuffer(size)
3561 }
3562
3563 /**
3564  * Creates a new filled Buffer instance.
3565  * alloc(size[, fill[, encoding]])
3566  **/
3567 Buffer.alloc = function (size, fill, encoding) {
3568   return alloc(size, fill, encoding)
3569 }
3570
3571 function allocUnsafe (size) {
3572   assertSize(size)
3573   return createBuffer(size < 0 ? 0 : checked(size) | 0)
3574 }
3575
3576 /**
3577  * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
3578  * */
3579 Buffer.allocUnsafe = function (size) {
3580   return allocUnsafe(size)
3581 }
3582 /**
3583  * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
3584  */
3585 Buffer.allocUnsafeSlow = function (size) {
3586   return allocUnsafe(size)
3587 }
3588
3589 function fromString (string, encoding) {
3590   if (typeof encoding !== 'string' || encoding === '') {
3591     encoding = 'utf8'
3592   }
3593
3594   if (!Buffer.isEncoding(encoding)) {
3595     throw new TypeError('Unknown encoding: ' + encoding)
3596   }
3597
3598   var length = byteLength(string, encoding) | 0
3599   var buf = createBuffer(length)
3600
3601   var actual = buf.write(string, encoding)
3602
3603   if (actual !== length) {
3604     // Writing a hex string, for example, that contains invalid characters will
3605     // cause everything after the first invalid character to be ignored. (e.g.
3606     // 'abxxcd' will be treated as 'ab')
3607     buf = buf.slice(0, actual)
3608   }
3609
3610   return buf
3611 }
3612
3613 function fromArrayLike (array) {
3614   var length = array.length < 0 ? 0 : checked(array.length) | 0
3615   var buf = createBuffer(length)
3616   for (var i = 0; i < length; i += 1) {
3617     buf[i] = array[i] & 255
3618   }
3619   return buf
3620 }
3621
3622 function fromArrayBuffer (array, byteOffset, length) {
3623   if (byteOffset < 0 || array.byteLength < byteOffset) {
3624     throw new RangeError('"offset" is outside of buffer bounds')
3625   }
3626
3627   if (array.byteLength < byteOffset + (length || 0)) {
3628     throw new RangeError('"length" is outside of buffer bounds')
3629   }
3630
3631   var buf
3632   if (byteOffset === undefined && length === undefined) {
3633     buf = new Uint8Array(array)
3634   } else if (length === undefined) {
3635     buf = new Uint8Array(array, byteOffset)
3636   } else {
3637     buf = new Uint8Array(array, byteOffset, length)
3638   }
3639
3640   // Return an augmented `Uint8Array` instance
3641   Object.setPrototypeOf(buf, Buffer.prototype)
3642
3643   return buf
3644 }
3645
3646 function fromObject (obj) {
3647   if (Buffer.isBuffer(obj)) {
3648     var len = checked(obj.length) | 0
3649     var buf = createBuffer(len)
3650
3651     if (buf.length === 0) {
3652       return buf
3653     }
3654
3655     obj.copy(buf, 0, 0, len)
3656     return buf
3657   }
3658
3659   if (obj.length !== undefined) {
3660     if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
3661       return createBuffer(0)
3662     }
3663     return fromArrayLike(obj)
3664   }
3665
3666   if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
3667     return fromArrayLike(obj.data)
3668   }
3669 }
3670
3671 function checked (length) {
3672   // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
3673   // length is NaN (which is otherwise coerced to zero.)
3674   if (length >= K_MAX_LENGTH) {
3675     throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
3676                          'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
3677   }
3678   return length | 0
3679 }
3680
3681 function SlowBuffer (length) {
3682   if (+length != length) { // eslint-disable-line eqeqeq
3683     length = 0
3684   }
3685   return Buffer.alloc(+length)
3686 }
3687
3688 Buffer.isBuffer = function isBuffer (b) {
3689   return b != null && b._isBuffer === true &&
3690     b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false
3691 }
3692
3693 Buffer.compare = function compare (a, b) {
3694   if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength)
3695   if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength)
3696   if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
3697     throw new TypeError(
3698       'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
3699     )
3700   }
3701
3702   if (a === b) return 0
3703
3704   var x = a.length
3705   var y = b.length
3706
3707   for (var i = 0, len = Math.min(x, y); i < len; ++i) {
3708     if (a[i] !== b[i]) {
3709       x = a[i]
3710       y = b[i]
3711       break
3712     }
3713   }
3714
3715   if (x < y) return -1
3716   if (y < x) return 1
3717   return 0
3718 }
3719
3720 Buffer.isEncoding = function isEncoding (encoding) {
3721   switch (String(encoding).toLowerCase()) {
3722     case 'hex':
3723     case 'utf8':
3724     case 'utf-8':
3725     case 'ascii':
3726     case 'latin1':
3727     case 'binary':
3728     case 'base64':
3729     case 'ucs2':
3730     case 'ucs-2':
3731     case 'utf16le':
3732     case 'utf-16le':
3733       return true
3734     default:
3735       return false
3736   }
3737 }
3738
3739 Buffer.concat = function concat (list, length) {
3740   if (!Array.isArray(list)) {
3741     throw new TypeError('"list" argument must be an Array of Buffers')
3742   }
3743
3744   if (list.length === 0) {
3745     return Buffer.alloc(0)
3746   }
3747
3748   var i
3749   if (length === undefined) {
3750     length = 0
3751     for (i = 0; i < list.length; ++i) {
3752       length += list[i].length
3753     }
3754   }
3755
3756   var buffer = Buffer.allocUnsafe(length)
3757   var pos = 0
3758   for (i = 0; i < list.length; ++i) {
3759     var buf = list[i]
3760     if (isInstance(buf, Uint8Array)) {
3761       buf = Buffer.from(buf)
3762     }
3763     if (!Buffer.isBuffer(buf)) {
3764       throw new TypeError('"list" argument must be an Array of Buffers')
3765     }
3766     buf.copy(buffer, pos)
3767     pos += buf.length
3768   }
3769   return buffer
3770 }
3771
3772 function byteLength (string, encoding) {
3773   if (Buffer.isBuffer(string)) {
3774     return string.length
3775   }
3776   if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
3777     return string.byteLength
3778   }
3779   if (typeof string !== 'string') {
3780     throw new TypeError(
3781       'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
3782       'Received type ' + typeof string
3783     )
3784   }
3785
3786   var len = string.length
3787   var mustMatch = (arguments.length > 2 && arguments[2] === true)
3788   if (!mustMatch && len === 0) return 0
3789
3790   // Use a for loop to avoid recursion
3791   var loweredCase = false
3792   for (;;) {
3793     switch (encoding) {
3794       case 'ascii':
3795       case 'latin1':
3796       case 'binary':
3797         return len
3798       case 'utf8':
3799       case 'utf-8':
3800         return utf8ToBytes(string).length
3801       case 'ucs2':
3802       case 'ucs-2':
3803       case 'utf16le':
3804       case 'utf-16le':
3805         return len * 2
3806       case 'hex':
3807         return len >>> 1
3808       case 'base64':
3809         return base64ToBytes(string).length
3810       default:
3811         if (loweredCase) {
3812           return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8
3813         }
3814         encoding = ('' + encoding).toLowerCase()
3815         loweredCase = true
3816     }
3817   }
3818 }
3819 Buffer.byteLength = byteLength
3820
3821 function slowToString (encoding, start, end) {
3822   var loweredCase = false
3823
3824   // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
3825   // property of a typed array.
3826
3827   // This behaves neither like String nor Uint8Array in that we set start/end
3828   // to their upper/lower bounds if the value passed is out of range.
3829   // undefined is handled specially as per ECMA-262 6th Edition,
3830   // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
3831   if (start === undefined || start < 0) {
3832     start = 0
3833   }
3834   // Return early if start > this.length. Done here to prevent potential uint32
3835   // coercion fail below.
3836   if (start > this.length) {
3837     return ''
3838   }
3839
3840   if (end === undefined || end > this.length) {
3841     end = this.length
3842   }
3843
3844   if (end <= 0) {
3845     return ''
3846   }
3847
3848   // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
3849   end >>>= 0
3850   start >>>= 0
3851
3852   if (end <= start) {
3853     return ''
3854   }
3855
3856   if (!encoding) encoding = 'utf8'
3857
3858   while (true) {
3859     switch (encoding) {
3860       case 'hex':
3861         return hexSlice(this, start, end)
3862
3863       case 'utf8':
3864       case 'utf-8':
3865         return utf8Slice(this, start, end)
3866
3867       case 'ascii':
3868         return asciiSlice(this, start, end)
3869
3870       case 'latin1':
3871       case 'binary':
3872         return latin1Slice(this, start, end)
3873
3874       case 'base64':
3875         return base64Slice(this, start, end)
3876
3877       case 'ucs2':
3878       case 'ucs-2':
3879       case 'utf16le':
3880       case 'utf-16le':
3881         return utf16leSlice(this, start, end)
3882
3883       default:
3884         if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
3885         encoding = (encoding + '').toLowerCase()
3886         loweredCase = true
3887     }
3888   }
3889 }
3890
3891 // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
3892 // to detect a Buffer instance. It's not possible to use `instanceof Buffer`
3893 // reliably in a browserify context because there could be multiple different
3894 // copies of the 'buffer' package in use. This method works even for Buffer
3895 // instances that were created from another copy of the `buffer` package.
3896 // See: https://github.com/feross/buffer/issues/154
3897 Buffer.prototype._isBuffer = true
3898
3899 function swap (b, n, m) {
3900   var i = b[n]
3901   b[n] = b[m]
3902   b[m] = i
3903 }
3904
3905 Buffer.prototype.swap16 = function swap16 () {
3906   var len = this.length
3907   if (len % 2 !== 0) {
3908     throw new RangeError('Buffer size must be a multiple of 16-bits')
3909   }
3910   for (var i = 0; i < len; i += 2) {
3911     swap(this, i, i + 1)
3912   }
3913   return this
3914 }
3915
3916 Buffer.prototype.swap32 = function swap32 () {
3917   var len = this.length
3918   if (len % 4 !== 0) {
3919     throw new RangeError('Buffer size must be a multiple of 32-bits')
3920   }
3921   for (var i = 0; i < len; i += 4) {
3922     swap(this, i, i + 3)
3923     swap(this, i + 1, i + 2)
3924   }
3925   return this
3926 }
3927
3928 Buffer.prototype.swap64 = function swap64 () {
3929   var len = this.length
3930   if (len % 8 !== 0) {
3931     throw new RangeError('Buffer size must be a multiple of 64-bits')
3932   }
3933   for (var i = 0; i < len; i += 8) {
3934     swap(this, i, i + 7)
3935     swap(this, i + 1, i + 6)
3936     swap(this, i + 2, i + 5)
3937     swap(this, i + 3, i + 4)
3938   }
3939   return this
3940 }
3941
3942 Buffer.prototype.toString = function toString () {
3943   var length = this.length
3944   if (length === 0) return ''
3945   if (arguments.length === 0) return utf8Slice(this, 0, length)
3946   return slowToString.apply(this, arguments)
3947 }
3948
3949 Buffer.prototype.toLocaleString = Buffer.prototype.toString
3950
3951 Buffer.prototype.equals = function equals (b) {
3952   if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
3953   if (this === b) return true
3954   return Buffer.compare(this, b) === 0
3955 }
3956
3957 Buffer.prototype.inspect = function inspect () {
3958   var str = ''
3959   var max = exports.INSPECT_MAX_BYTES
3960   str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim()
3961   if (this.length > max) str += ' ... '
3962   return '<Buffer ' + str + '>'
3963 }
3964 if (customInspectSymbol) {
3965   Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect
3966 }
3967
3968 Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
3969   if (isInstance(target, Uint8Array)) {
3970     target = Buffer.from(target, target.offset, target.byteLength)
3971   }
3972   if (!Buffer.isBuffer(target)) {
3973     throw new TypeError(
3974       'The "target" argument must be one of type Buffer or Uint8Array. ' +
3975       'Received type ' + (typeof target)
3976     )
3977   }
3978
3979   if (start === undefined) {
3980     start = 0
3981   }
3982   if (end === undefined) {
3983     end = target ? target.length : 0
3984   }
3985   if (thisStart === undefined) {
3986     thisStart = 0
3987   }
3988   if (thisEnd === undefined) {
3989     thisEnd = this.length
3990   }
3991
3992   if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
3993     throw new RangeError('out of range index')
3994   }
3995
3996   if (thisStart >= thisEnd && start >= end) {
3997     return 0
3998   }
3999   if (thisStart >= thisEnd) {
4000     return -1
4001   }
4002   if (start >= end) {
4003     return 1
4004   }
4005
4006   start >>>= 0
4007   end >>>= 0
4008   thisStart >>>= 0
4009   thisEnd >>>= 0
4010
4011   if (this === target) return 0
4012
4013   var x = thisEnd - thisStart
4014   var y = end - start
4015   var len = Math.min(x, y)
4016
4017   var thisCopy = this.slice(thisStart, thisEnd)
4018   var targetCopy = target.slice(start, end)
4019
4020   for (var i = 0; i < len; ++i) {
4021     if (thisCopy[i] !== targetCopy[i]) {
4022       x = thisCopy[i]
4023       y = targetCopy[i]
4024       break
4025     }
4026   }
4027
4028   if (x < y) return -1
4029   if (y < x) return 1
4030   return 0
4031 }
4032
4033 // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
4034 // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
4035 //
4036 // Arguments:
4037 // - buffer - a Buffer to search
4038 // - val - a string, Buffer, or number
4039 // - byteOffset - an index into `buffer`; will be clamped to an int32
4040 // - encoding - an optional encoding, relevant is val is a string
4041 // - dir - true for indexOf, false for lastIndexOf
4042 function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
4043   // Empty buffer means no match
4044   if (buffer.length === 0) return -1
4045
4046   // Normalize byteOffset
4047   if (typeof byteOffset === 'string') {
4048     encoding = byteOffset
4049     byteOffset = 0
4050   } else if (byteOffset > 0x7fffffff) {
4051     byteOffset = 0x7fffffff
4052   } else if (byteOffset < -0x80000000) {
4053     byteOffset = -0x80000000
4054   }
4055   byteOffset = +byteOffset // Coerce to Number.
4056   if (numberIsNaN(byteOffset)) {
4057     // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
4058     byteOffset = dir ? 0 : (buffer.length - 1)
4059   }
4060
4061   // Normalize byteOffset: negative offsets start from the end of the buffer
4062   if (byteOffset < 0) byteOffset = buffer.length + byteOffset
4063   if (byteOffset >= buffer.length) {
4064     if (dir) return -1
4065     else byteOffset = buffer.length - 1
4066   } else if (byteOffset < 0) {
4067     if (dir) byteOffset = 0
4068     else return -1
4069   }
4070
4071   // Normalize val
4072   if (typeof val === 'string') {
4073     val = Buffer.from(val, encoding)
4074   }
4075
4076   // Finally, search either indexOf (if dir is true) or lastIndexOf
4077   if (Buffer.isBuffer(val)) {
4078     // Special case: looking for empty string/buffer always fails
4079     if (val.length === 0) {
4080       return -1
4081     }
4082     return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
4083   } else if (typeof val === 'number') {
4084     val = val & 0xFF // Search for a byte value [0-255]
4085     if (typeof Uint8Array.prototype.indexOf === 'function') {
4086       if (dir) {
4087         return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
4088       } else {
4089         return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
4090       }
4091     }
4092     return arrayIndexOf(buffer, [val], byteOffset, encoding, dir)
4093   }
4094
4095   throw new TypeError('val must be string, number or Buffer')
4096 }
4097
4098 function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
4099   var indexSize = 1
4100   var arrLength = arr.length
4101   var valLength = val.length
4102
4103   if (encoding !== undefined) {
4104     encoding = String(encoding).toLowerCase()
4105     if (encoding === 'ucs2' || encoding === 'ucs-2' ||
4106         encoding === 'utf16le' || encoding === 'utf-16le') {
4107       if (arr.length < 2 || val.length < 2) {
4108         return -1
4109       }
4110       indexSize = 2
4111       arrLength /= 2
4112       valLength /= 2
4113       byteOffset /= 2
4114     }
4115   }
4116
4117   function read (buf, i) {
4118     if (indexSize === 1) {
4119       return buf[i]
4120     } else {
4121       return buf.readUInt16BE(i * indexSize)
4122     }
4123   }
4124
4125   var i
4126   if (dir) {
4127     var foundIndex = -1
4128     for (i = byteOffset; i < arrLength; i++) {
4129       if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
4130         if (foundIndex === -1) foundIndex = i
4131         if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
4132       } else {
4133         if (foundIndex !== -1) i -= i - foundIndex
4134         foundIndex = -1
4135       }
4136     }
4137   } else {
4138     if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
4139     for (i = byteOffset; i >= 0; i--) {
4140       var found = true
4141       for (var j = 0; j < valLength; j++) {
4142         if (read(arr, i + j) !== read(val, j)) {
4143           found = false
4144           break
4145         }
4146       }
4147       if (found) return i
4148     }
4149   }
4150
4151   return -1
4152 }
4153
4154 Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
4155   return this.indexOf(val, byteOffset, encoding) !== -1
4156 }
4157
4158 Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
4159   return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
4160 }
4161
4162 Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
4163   return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
4164 }
4165
4166 function hexWrite (buf, string, offset, length) {
4167   offset = Number(offset) || 0
4168   var remaining = buf.length - offset
4169   if (!length) {
4170     length = remaining
4171   } else {
4172     length = Number(length)
4173     if (length > remaining) {
4174       length = remaining
4175     }
4176   }
4177
4178   var strLen = string.length
4179
4180   if (length > strLen / 2) {
4181     length = strLen / 2
4182   }
4183   for (var i = 0; i < length; ++i) {
4184     var parsed = parseInt(string.substr(i * 2, 2), 16)
4185     if (numberIsNaN(parsed)) return i
4186     buf[offset + i] = parsed
4187   }
4188   return i
4189 }
4190
4191 function utf8Write (buf, string, offset, length) {
4192   return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
4193 }
4194
4195 function asciiWrite (buf, string, offset, length) {
4196   return blitBuffer(asciiToBytes(string), buf, offset, length)
4197 }
4198
4199 function latin1Write (buf, string, offset, length) {
4200   return asciiWrite(buf, string, offset, length)
4201 }
4202
4203 function base64Write (buf, string, offset, length) {
4204   return blitBuffer(base64ToBytes(string), buf, offset, length)
4205 }
4206
4207 function ucs2Write (buf, string, offset, length) {
4208   return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
4209 }
4210
4211 Buffer.prototype.write = function write (string, offset, length, encoding) {
4212   // Buffer#write(string)
4213   if (offset === undefined) {
4214     encoding = 'utf8'
4215     length = this.length
4216     offset = 0
4217   // Buffer#write(string, encoding)
4218   } else if (length === undefined && typeof offset === 'string') {
4219     encoding = offset
4220     length = this.length
4221     offset = 0
4222   // Buffer#write(string, offset[, length][, encoding])
4223   } else if (isFinite(offset)) {
4224     offset = offset >>> 0
4225     if (isFinite(length)) {
4226       length = length >>> 0
4227       if (encoding === undefined) encoding = 'utf8'
4228     } else {
4229       encoding = length
4230       length = undefined
4231     }
4232   } else {
4233     throw new Error(
4234       'Buffer.write(string, encoding, offset[, length]) is no longer supported'
4235     )
4236   }
4237
4238   var remaining = this.length - offset
4239   if (length === undefined || length > remaining) length = remaining
4240
4241   if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
4242     throw new RangeError('Attempt to write outside buffer bounds')
4243   }
4244
4245   if (!encoding) encoding = 'utf8'
4246
4247   var loweredCase = false
4248   for (;;) {
4249     switch (encoding) {
4250       case 'hex':
4251         return hexWrite(this, string, offset, length)
4252
4253       case 'utf8':
4254       case 'utf-8':
4255         return utf8Write(this, string, offset, length)
4256
4257       case 'ascii':
4258         return asciiWrite(this, string, offset, length)
4259
4260       case 'latin1':
4261       case 'binary':
4262         return latin1Write(this, string, offset, length)
4263
4264       case 'base64':
4265         // Warning: maxLength not taken into account in base64Write
4266         return base64Write(this, string, offset, length)
4267
4268       case 'ucs2':
4269       case 'ucs-2':
4270       case 'utf16le':
4271       case 'utf-16le':
4272         return ucs2Write(this, string, offset, length)
4273
4274       default:
4275         if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
4276         encoding = ('' + encoding).toLowerCase()
4277         loweredCase = true
4278     }
4279   }
4280 }
4281
4282 Buffer.prototype.toJSON = function toJSON () {
4283   return {
4284     type: 'Buffer',
4285     data: Array.prototype.slice.call(this._arr || this, 0)
4286   }
4287 }
4288
4289 function base64Slice (buf, start, end) {
4290   if (start === 0 && end === buf.length) {
4291     return base64.fromByteArray(buf)
4292   } else {
4293     return base64.fromByteArray(buf.slice(start, end))
4294   }
4295 }
4296
4297 function utf8Slice (buf, start, end) {
4298   end = Math.min(buf.length, end)
4299   var res = []
4300
4301   var i = start
4302   while (i < end) {
4303     var firstByte = buf[i]
4304     var codePoint = null
4305     var bytesPerSequence = (firstByte > 0xEF) ? 4
4306       : (firstByte > 0xDF) ? 3
4307         : (firstByte > 0xBF) ? 2
4308           : 1
4309
4310     if (i + bytesPerSequence <= end) {
4311       var secondByte, thirdByte, fourthByte, tempCodePoint
4312
4313       switch (bytesPerSequence) {
4314         case 1:
4315           if (firstByte < 0x80) {
4316             codePoint = firstByte
4317           }
4318           break
4319         case 2:
4320           secondByte = buf[i + 1]
4321           if ((secondByte & 0xC0) === 0x80) {
4322             tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
4323             if (tempCodePoint > 0x7F) {
4324               codePoint = tempCodePoint
4325             }
4326           }
4327           break
4328         case 3:
4329           secondByte = buf[i + 1]
4330           thirdByte = buf[i + 2]
4331           if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
4332             tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
4333             if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
4334               codePoint = tempCodePoint
4335             }
4336           }
4337           break
4338         case 4:
4339           secondByte = buf[i + 1]
4340           thirdByte = buf[i + 2]
4341           fourthByte = buf[i + 3]
4342           if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
4343             tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
4344             if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
4345               codePoint = tempCodePoint
4346             }
4347           }
4348       }
4349     }
4350
4351     if (codePoint === null) {
4352       // we did not generate a valid codePoint so insert a
4353       // replacement char (U+FFFD) and advance only 1 byte
4354       codePoint = 0xFFFD
4355       bytesPerSequence = 1
4356     } else if (codePoint > 0xFFFF) {
4357       // encode to utf16 (surrogate pair dance)
4358       codePoint -= 0x10000
4359       res.push(codePoint >>> 10 & 0x3FF | 0xD800)
4360       codePoint = 0xDC00 | codePoint & 0x3FF
4361     }
4362
4363     res.push(codePoint)
4364     i += bytesPerSequence
4365   }
4366
4367   return decodeCodePointsArray(res)
4368 }
4369
4370 // Based on http://stackoverflow.com/a/22747272/680742, the browser with
4371 // the lowest limit is Chrome, with 0x10000 args.
4372 // We go 1 magnitude less, for safety
4373 var MAX_ARGUMENTS_LENGTH = 0x1000
4374
4375 function decodeCodePointsArray (codePoints) {
4376   var len = codePoints.length
4377   if (len <= MAX_ARGUMENTS_LENGTH) {
4378     return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
4379   }
4380
4381   // Decode in chunks to avoid "call stack size exceeded".
4382   var res = ''
4383   var i = 0
4384   while (i < len) {
4385     res += String.fromCharCode.apply(
4386       String,
4387       codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
4388     )
4389   }
4390   return res
4391 }
4392
4393 function asciiSlice (buf, start, end) {
4394   var ret = ''
4395   end = Math.min(buf.length, end)
4396
4397   for (var i = start; i < end; ++i) {
4398     ret += String.fromCharCode(buf[i] & 0x7F)
4399   }
4400   return ret
4401 }
4402
4403 function latin1Slice (buf, start, end) {
4404   var ret = ''
4405   end = Math.min(buf.length, end)
4406
4407   for (var i = start; i < end; ++i) {
4408     ret += String.fromCharCode(buf[i])
4409   }
4410   return ret
4411 }
4412
4413 function hexSlice (buf, start, end) {
4414   var len = buf.length
4415
4416   if (!start || start < 0) start = 0
4417   if (!end || end < 0 || end > len) end = len
4418
4419   var out = ''
4420   for (var i = start; i < end; ++i) {
4421     out += hexSliceLookupTable[buf[i]]
4422   }
4423   return out
4424 }
4425
4426 function utf16leSlice (buf, start, end) {
4427   var bytes = buf.slice(start, end)
4428   var res = ''
4429   for (var i = 0; i < bytes.length; i += 2) {
4430     res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256))
4431   }
4432   return res
4433 }
4434
4435 Buffer.prototype.slice = function slice (start, end) {
4436   var len = this.length
4437   start = ~~start
4438   end = end === undefined ? len : ~~end
4439
4440   if (start < 0) {
4441     start += len
4442     if (start < 0) start = 0
4443   } else if (start > len) {
4444     start = len
4445   }
4446
4447   if (end < 0) {
4448     end += len
4449     if (end < 0) end = 0
4450   } else if (end > len) {
4451     end = len
4452   }
4453
4454   if (end < start) end = start
4455
4456   var newBuf = this.subarray(start, end)
4457   // Return an augmented `Uint8Array` instance
4458   Object.setPrototypeOf(newBuf, Buffer.prototype)
4459
4460   return newBuf
4461 }
4462
4463 /*
4464  * Need to make sure that buffer isn't trying to write out of bounds.
4465  */
4466 function checkOffset (offset, ext, length) {
4467   if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
4468   if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
4469 }
4470
4471 Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
4472   offset = offset >>> 0
4473   byteLength = byteLength >>> 0
4474   if (!noAssert) checkOffset(offset, byteLength, this.length)
4475
4476   var val = this[offset]
4477   var mul = 1
4478   var i = 0
4479   while (++i < byteLength && (mul *= 0x100)) {
4480     val += this[offset + i] * mul
4481   }
4482
4483   return val
4484 }
4485
4486 Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
4487   offset = offset >>> 0
4488   byteLength = byteLength >>> 0
4489   if (!noAssert) {
4490     checkOffset(offset, byteLength, this.length)
4491   }
4492
4493   var val = this[offset + --byteLength]
4494   var mul = 1
4495   while (byteLength > 0 && (mul *= 0x100)) {
4496     val += this[offset + --byteLength] * mul
4497   }
4498
4499   return val
4500 }
4501
4502 Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
4503   offset = offset >>> 0
4504   if (!noAssert) checkOffset(offset, 1, this.length)
4505   return this[offset]
4506 }
4507
4508 Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
4509   offset = offset >>> 0
4510   if (!noAssert) checkOffset(offset, 2, this.length)
4511   return this[offset] | (this[offset + 1] << 8)
4512 }
4513
4514 Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
4515   offset = offset >>> 0
4516   if (!noAssert) checkOffset(offset, 2, this.length)
4517   return (this[offset] << 8) | this[offset + 1]
4518 }
4519
4520 Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
4521   offset = offset >>> 0
4522   if (!noAssert) checkOffset(offset, 4, this.length)
4523
4524   return ((this[offset]) |
4525       (this[offset + 1] << 8) |
4526       (this[offset + 2] << 16)) +
4527       (this[offset + 3] * 0x1000000)
4528 }
4529
4530 Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
4531   offset = offset >>> 0
4532   if (!noAssert) checkOffset(offset, 4, this.length)
4533
4534   return (this[offset] * 0x1000000) +
4535     ((this[offset + 1] << 16) |
4536     (this[offset + 2] << 8) |
4537     this[offset + 3])
4538 }
4539
4540 Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
4541   offset = offset >>> 0
4542   byteLength = byteLength >>> 0
4543   if (!noAssert) checkOffset(offset, byteLength, this.length)
4544
4545   var val = this[offset]
4546   var mul = 1
4547   var i = 0
4548   while (++i < byteLength && (mul *= 0x100)) {
4549     val += this[offset + i] * mul
4550   }
4551   mul *= 0x80
4552
4553   if (val >= mul) val -= Math.pow(2, 8 * byteLength)
4554
4555   return val
4556 }
4557
4558 Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
4559   offset = offset >>> 0
4560   byteLength = byteLength >>> 0
4561   if (!noAssert) checkOffset(offset, byteLength, this.length)
4562
4563   var i = byteLength
4564   var mul = 1
4565   var val = this[offset + --i]
4566   while (i > 0 && (mul *= 0x100)) {
4567     val += this[offset + --i] * mul
4568   }
4569   mul *= 0x80
4570
4571   if (val >= mul) val -= Math.pow(2, 8 * byteLength)
4572
4573   return val
4574 }
4575
4576 Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
4577   offset = offset >>> 0
4578   if (!noAssert) checkOffset(offset, 1, this.length)
4579   if (!(this[offset] & 0x80)) return (this[offset])
4580   return ((0xff - this[offset] + 1) * -1)
4581 }
4582
4583 Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
4584   offset = offset >>> 0
4585   if (!noAssert) checkOffset(offset, 2, this.length)
4586   var val = this[offset] | (this[offset + 1] << 8)
4587   return (val & 0x8000) ? val | 0xFFFF0000 : val
4588 }
4589
4590 Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
4591   offset = offset >>> 0
4592   if (!noAssert) checkOffset(offset, 2, this.length)
4593   var val = this[offset + 1] | (this[offset] << 8)
4594   return (val & 0x8000) ? val | 0xFFFF0000 : val
4595 }
4596
4597 Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
4598   offset = offset >>> 0
4599   if (!noAssert) checkOffset(offset, 4, this.length)
4600
4601   return (this[offset]) |
4602     (this[offset + 1] << 8) |
4603     (this[offset + 2] << 16) |
4604     (this[offset + 3] << 24)
4605 }
4606
4607 Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
4608   offset = offset >>> 0
4609   if (!noAssert) checkOffset(offset, 4, this.length)
4610
4611   return (this[offset] << 24) |
4612     (this[offset + 1] << 16) |
4613     (this[offset + 2] << 8) |
4614     (this[offset + 3])
4615 }
4616
4617 Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
4618   offset = offset >>> 0
4619   if (!noAssert) checkOffset(offset, 4, this.length)
4620   return ieee754.read(this, offset, true, 23, 4)
4621 }
4622
4623 Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
4624   offset = offset >>> 0
4625   if (!noAssert) checkOffset(offset, 4, this.length)
4626   return ieee754.read(this, offset, false, 23, 4)
4627 }
4628
4629 Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
4630   offset = offset >>> 0
4631   if (!noAssert) checkOffset(offset, 8, this.length)
4632   return ieee754.read(this, offset, true, 52, 8)
4633 }
4634
4635 Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
4636   offset = offset >>> 0
4637   if (!noAssert) checkOffset(offset, 8, this.length)
4638   return ieee754.read(this, offset, false, 52, 8)
4639 }
4640
4641 function checkInt (buf, value, offset, ext, max, min) {
4642   if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
4643   if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
4644   if (offset + ext > buf.length) throw new RangeError('Index out of range')
4645 }
4646
4647 Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
4648   value = +value
4649   offset = offset >>> 0
4650   byteLength = byteLength >>> 0
4651   if (!noAssert) {
4652     var maxBytes = Math.pow(2, 8 * byteLength) - 1
4653     checkInt(this, value, offset, byteLength, maxBytes, 0)
4654   }
4655
4656   var mul = 1
4657   var i = 0
4658   this[offset] = value & 0xFF
4659   while (++i < byteLength && (mul *= 0x100)) {
4660     this[offset + i] = (value / mul) & 0xFF
4661   }
4662
4663   return offset + byteLength
4664 }
4665
4666 Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
4667   value = +value
4668   offset = offset >>> 0
4669   byteLength = byteLength >>> 0
4670   if (!noAssert) {
4671     var maxBytes = Math.pow(2, 8 * byteLength) - 1
4672     checkInt(this, value, offset, byteLength, maxBytes, 0)
4673   }
4674
4675   var i = byteLength - 1
4676   var mul = 1
4677   this[offset + i] = value & 0xFF
4678   while (--i >= 0 && (mul *= 0x100)) {
4679     this[offset + i] = (value / mul) & 0xFF
4680   }
4681
4682   return offset + byteLength
4683 }
4684
4685 Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
4686   value = +value
4687   offset = offset >>> 0
4688   if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
4689   this[offset] = (value & 0xff)
4690   return offset + 1
4691 }
4692
4693 Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
4694   value = +value
4695   offset = offset >>> 0
4696   if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
4697   this[offset] = (value & 0xff)
4698   this[offset + 1] = (value >>> 8)
4699   return offset + 2
4700 }
4701
4702 Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
4703   value = +value
4704   offset = offset >>> 0
4705   if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
4706   this[offset] = (value >>> 8)
4707   this[offset + 1] = (value & 0xff)
4708   return offset + 2
4709 }
4710
4711 Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
4712   value = +value
4713   offset = offset >>> 0
4714   if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
4715   this[offset + 3] = (value >>> 24)
4716   this[offset + 2] = (value >>> 16)
4717   this[offset + 1] = (value >>> 8)
4718   this[offset] = (value & 0xff)
4719   return offset + 4
4720 }
4721
4722 Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
4723   value = +value
4724   offset = offset >>> 0
4725   if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
4726   this[offset] = (value >>> 24)
4727   this[offset + 1] = (value >>> 16)
4728   this[offset + 2] = (value >>> 8)
4729   this[offset + 3] = (value & 0xff)
4730   return offset + 4
4731 }
4732
4733 Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
4734   value = +value
4735   offset = offset >>> 0
4736   if (!noAssert) {
4737     var limit = Math.pow(2, (8 * byteLength) - 1)
4738
4739     checkInt(this, value, offset, byteLength, limit - 1, -limit)
4740   }
4741
4742   var i = 0
4743   var mul = 1
4744   var sub = 0
4745   this[offset] = value & 0xFF
4746   while (++i < byteLength && (mul *= 0x100)) {
4747     if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
4748       sub = 1
4749     }
4750     this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
4751   }
4752
4753   return offset + byteLength
4754 }
4755
4756 Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
4757   value = +value
4758   offset = offset >>> 0
4759   if (!noAssert) {
4760     var limit = Math.pow(2, (8 * byteLength) - 1)
4761
4762     checkInt(this, value, offset, byteLength, limit - 1, -limit)
4763   }
4764
4765   var i = byteLength - 1
4766   var mul = 1
4767   var sub = 0
4768   this[offset + i] = value & 0xFF
4769   while (--i >= 0 && (mul *= 0x100)) {
4770     if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
4771       sub = 1
4772     }
4773     this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
4774   }
4775
4776   return offset + byteLength
4777 }
4778
4779 Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
4780   value = +value
4781   offset = offset >>> 0
4782   if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
4783   if (value < 0) value = 0xff + value + 1
4784   this[offset] = (value & 0xff)
4785   return offset + 1
4786 }
4787
4788 Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
4789   value = +value
4790   offset = offset >>> 0
4791   if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
4792   this[offset] = (value & 0xff)
4793   this[offset + 1] = (value >>> 8)
4794   return offset + 2
4795 }
4796
4797 Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
4798   value = +value
4799   offset = offset >>> 0
4800   if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
4801   this[offset] = (value >>> 8)
4802   this[offset + 1] = (value & 0xff)
4803   return offset + 2
4804 }
4805
4806 Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
4807   value = +value
4808   offset = offset >>> 0
4809   if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
4810   this[offset] = (value & 0xff)
4811   this[offset + 1] = (value >>> 8)
4812   this[offset + 2] = (value >>> 16)
4813   this[offset + 3] = (value >>> 24)
4814   return offset + 4
4815 }
4816
4817 Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
4818   value = +value
4819   offset = offset >>> 0
4820   if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
4821   if (value < 0) value = 0xffffffff + value + 1
4822   this[offset] = (value >>> 24)
4823   this[offset + 1] = (value >>> 16)
4824   this[offset + 2] = (value >>> 8)
4825   this[offset + 3] = (value & 0xff)
4826   return offset + 4
4827 }
4828
4829 function checkIEEE754 (buf, value, offset, ext, max, min) {
4830   if (offset + ext > buf.length) throw new RangeError('Index out of range')
4831   if (offset < 0) throw new RangeError('Index out of range')
4832 }
4833
4834 function writeFloat (buf, value, offset, littleEndian, noAssert) {
4835   value = +value
4836   offset = offset >>> 0
4837   if (!noAssert) {
4838     checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
4839   }
4840   ieee754.write(buf, value, offset, littleEndian, 23, 4)
4841   return offset + 4
4842 }
4843
4844 Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
4845   return writeFloat(this, value, offset, true, noAssert)
4846 }
4847
4848 Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
4849   return writeFloat(this, value, offset, false, noAssert)
4850 }
4851
4852 function writeDouble (buf, value, offset, littleEndian, noAssert) {
4853   value = +value
4854   offset = offset >>> 0
4855   if (!noAssert) {
4856     checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
4857   }
4858   ieee754.write(buf, value, offset, littleEndian, 52, 8)
4859   return offset + 8
4860 }
4861
4862 Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
4863   return writeDouble(this, value, offset, true, noAssert)
4864 }
4865
4866 Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
4867   return writeDouble(this, value, offset, false, noAssert)
4868 }
4869
4870 // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
4871 Buffer.prototype.copy = function copy (target, targetStart, start, end) {
4872   if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer')
4873   if (!start) start = 0
4874   if (!end && end !== 0) end = this.length
4875   if (targetStart >= target.length) targetStart = target.length
4876   if (!targetStart) targetStart = 0
4877   if (end > 0 && end < start) end = start
4878
4879   // Copy 0 bytes; we're done
4880   if (end === start) return 0
4881   if (target.length === 0 || this.length === 0) return 0
4882
4883   // Fatal error conditions
4884   if (targetStart < 0) {
4885     throw new RangeError('targetStart out of bounds')
4886   }
4887   if (start < 0 || start >= this.length) throw new RangeError('Index out of range')
4888   if (end < 0) throw new RangeError('sourceEnd out of bounds')
4889
4890   // Are we oob?
4891   if (end > this.length) end = this.length
4892   if (target.length - targetStart < end - start) {
4893     end = target.length - targetStart + start
4894   }
4895
4896   var len = end - start
4897
4898   if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
4899     // Use built-in when available, missing from IE11
4900     this.copyWithin(targetStart, start, end)
4901   } else if (this === target && start < targetStart && targetStart < end) {
4902     // descending copy from end
4903     for (var i = len - 1; i >= 0; --i) {
4904       target[i + targetStart] = this[i + start]
4905     }
4906   } else {
4907     Uint8Array.prototype.set.call(
4908       target,
4909       this.subarray(start, end),
4910       targetStart
4911     )
4912   }
4913
4914   return len
4915 }
4916
4917 // Usage:
4918 //    buffer.fill(number[, offset[, end]])
4919 //    buffer.fill(buffer[, offset[, end]])
4920 //    buffer.fill(string[, offset[, end]][, encoding])
4921 Buffer.prototype.fill = function fill (val, start, end, encoding) {
4922   // Handle string cases:
4923   if (typeof val === 'string') {
4924     if (typeof start === 'string') {
4925       encoding = start
4926       start = 0
4927       end = this.length
4928     } else if (typeof end === 'string') {
4929       encoding = end
4930       end = this.length
4931     }
4932     if (encoding !== undefined && typeof encoding !== 'string') {
4933       throw new TypeError('encoding must be a string')
4934     }
4935     if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
4936       throw new TypeError('Unknown encoding: ' + encoding)
4937     }
4938     if (val.length === 1) {
4939       var code = val.charCodeAt(0)
4940       if ((encoding === 'utf8' && code < 128) ||
4941           encoding === 'latin1') {
4942         // Fast path: If `val` fits into a single byte, use that numeric value.
4943         val = code
4944       }
4945     }
4946   } else if (typeof val === 'number') {
4947     val = val & 255
4948   } else if (typeof val === 'boolean') {
4949     val = Number(val)
4950   }
4951
4952   // Invalid ranges are not set to a default, so can range check early.
4953   if (start < 0 || this.length < start || this.length < end) {
4954     throw new RangeError('Out of range index')
4955   }
4956
4957   if (end <= start) {
4958     return this
4959   }
4960
4961   start = start >>> 0
4962   end = end === undefined ? this.length : end >>> 0
4963
4964   if (!val) val = 0
4965
4966   var i
4967   if (typeof val === 'number') {
4968     for (i = start; i < end; ++i) {
4969       this[i] = val
4970     }
4971   } else {
4972     var bytes = Buffer.isBuffer(val)
4973       ? val
4974       : Buffer.from(val, encoding)
4975     var len = bytes.length
4976     if (len === 0) {
4977       throw new TypeError('The value "' + val +
4978         '" is invalid for argument "value"')
4979     }
4980     for (i = 0; i < end - start; ++i) {
4981       this[i + start] = bytes[i % len]
4982     }
4983   }
4984
4985   return this
4986 }
4987
4988 // HELPER FUNCTIONS
4989 // ================
4990
4991 var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g
4992
4993 function base64clean (str) {
4994   // Node takes equal signs as end of the Base64 encoding
4995   str = str.split('=')[0]
4996   // Node strips out invalid characters like \n and \t from the string, base64-js does not
4997   str = str.trim().replace(INVALID_BASE64_RE, '')
4998   // Node converts strings with length < 2 to ''
4999   if (str.length < 2) return ''
5000   // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
5001   while (str.length % 4 !== 0) {
5002     str = str + '='
5003   }
5004   return str
5005 }
5006
5007 function utf8ToBytes (string, units) {
5008   units = units || Infinity
5009   var codePoint
5010   var length = string.length
5011   var leadSurrogate = null
5012   var bytes = []
5013
5014   for (var i = 0; i < length; ++i) {
5015     codePoint = string.charCodeAt(i)
5016
5017     // is surrogate component
5018     if (codePoint > 0xD7FF && codePoint < 0xE000) {
5019       // last char was a lead
5020       if (!leadSurrogate) {
5021         // no lead yet
5022         if (codePoint > 0xDBFF) {
5023           // unexpected trail
5024           if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
5025           continue
5026         } else if (i + 1 === length) {
5027           // unpaired lead
5028           if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
5029           continue
5030         }
5031
5032         // valid lead
5033         leadSurrogate = codePoint
5034
5035         continue
5036       }
5037
5038       // 2 leads in a row
5039       if (codePoint < 0xDC00) {
5040         if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
5041         leadSurrogate = codePoint
5042         continue
5043       }
5044
5045       // valid surrogate pair
5046       codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
5047     } else if (leadSurrogate) {
5048       // valid bmp char, but last char was a lead
5049       if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
5050     }
5051
5052     leadSurrogate = null
5053
5054     // encode utf8
5055     if (codePoint < 0x80) {
5056       if ((units -= 1) < 0) break
5057       bytes.push(codePoint)
5058     } else if (codePoint < 0x800) {
5059       if ((units -= 2) < 0) break
5060       bytes.push(
5061         codePoint >> 0x6 | 0xC0,
5062         codePoint & 0x3F | 0x80
5063       )
5064     } else if (codePoint < 0x10000) {
5065       if ((units -= 3) < 0) break
5066       bytes.push(
5067         codePoint >> 0xC | 0xE0,
5068         codePoint >> 0x6 & 0x3F | 0x80,
5069         codePoint & 0x3F | 0x80
5070       )
5071     } else if (codePoint < 0x110000) {
5072       if ((units -= 4) < 0) break
5073       bytes.push(
5074         codePoint >> 0x12 | 0xF0,
5075         codePoint >> 0xC & 0x3F | 0x80,
5076         codePoint >> 0x6 & 0x3F | 0x80,
5077         codePoint & 0x3F | 0x80
5078       )
5079     } else {
5080       throw new Error('Invalid code point')
5081     }
5082   }
5083
5084   return bytes
5085 }
5086
5087 function asciiToBytes (str) {
5088   var byteArray = []
5089   for (var i = 0; i < str.length; ++i) {
5090     // Node's code seems to be doing this and not & 0x7F..
5091     byteArray.push(str.charCodeAt(i) & 0xFF)
5092   }
5093   return byteArray
5094 }
5095
5096 function utf16leToBytes (str, units) {
5097   var c, hi, lo
5098   var byteArray = []
5099   for (var i = 0; i < str.length; ++i) {
5100     if ((units -= 2) < 0) break
5101
5102     c = str.charCodeAt(i)
5103     hi = c >> 8
5104     lo = c % 256
5105     byteArray.push(lo)
5106     byteArray.push(hi)
5107   }
5108
5109   return byteArray
5110 }
5111
5112 function base64ToBytes (str) {
5113   return base64.toByteArray(base64clean(str))
5114 }
5115
5116 function blitBuffer (src, dst, offset, length) {
5117   for (var i = 0; i < length; ++i) {
5118     if ((i + offset >= dst.length) || (i >= src.length)) break
5119     dst[i + offset] = src[i]
5120   }
5121   return i
5122 }
5123
5124 // ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
5125 // the `instanceof` check but they should be treated as of that type.
5126 // See: https://github.com/feross/buffer/issues/166
5127 function isInstance (obj, type) {
5128   return obj instanceof type ||
5129     (obj != null && obj.constructor != null && obj.constructor.name != null &&
5130       obj.constructor.name === type.name)
5131 }
5132 function numberIsNaN (obj) {
5133   // For IE11 support
5134   return obj !== obj // eslint-disable-line no-self-compare
5135 }
5136
5137 // Create lookup table for `toString('hex')`
5138 // See: https://github.com/feross/buffer/issues/219
5139 var hexSliceLookupTable = (function () {
5140   var alphabet = '0123456789abcdef'
5141   var table = new Array(256)
5142   for (var i = 0; i < 16; ++i) {
5143     var i16 = i * 16
5144     for (var j = 0; j < 16; ++j) {
5145       table[i16 + j] = alphabet[i] + alphabet[j]
5146     }
5147   }
5148   return table
5149 })()
5150
5151 },{"base64-js":29,"ieee754":32}],31:[function(require,module,exports){
5152 'use strict';
5153
5154 /******************************************************************************
5155  * Created 2008-08-19.
5156  *
5157  * Dijkstra path-finding functions. Adapted from the Dijkstar Python project.
5158  *
5159  * Copyright (C) 2008
5160  *   Wyatt Baldwin <self@wyattbaldwin.com>
5161  *   All rights reserved
5162  *
5163  * Licensed under the MIT license.
5164  *
5165  *   http://www.opensource.org/licenses/mit-license.php
5166  *
5167  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
5168  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
5169  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
5170  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
5171  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
5172  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
5173  * THE SOFTWARE.
5174  *****************************************************************************/
5175 var dijkstra = {
5176   single_source_shortest_paths: function(graph, s, d) {
5177     // Predecessor map for each node that has been encountered.
5178     // node ID => predecessor node ID
5179     var predecessors = {};
5180
5181     // Costs of shortest paths from s to all nodes encountered.
5182     // node ID => cost
5183     var costs = {};
5184     costs[s] = 0;
5185
5186     // Costs of shortest paths from s to all nodes encountered; differs from
5187     // `costs` in that it provides easy access to the node that currently has
5188     // the known shortest path from s.
5189     // XXX: Do we actually need both `costs` and `open`?
5190     var open = dijkstra.PriorityQueue.make();
5191     open.push(s, 0);
5192
5193     var closest,
5194         u, v,
5195         cost_of_s_to_u,
5196         adjacent_nodes,
5197         cost_of_e,
5198         cost_of_s_to_u_plus_cost_of_e,
5199         cost_of_s_to_v,
5200         first_visit;
5201     while (!open.empty()) {
5202       // In the nodes remaining in graph that have a known cost from s,
5203       // find the node, u, that currently has the shortest path from s.
5204       closest = open.pop();
5205       u = closest.value;
5206       cost_of_s_to_u = closest.cost;
5207
5208       // Get nodes adjacent to u...
5209       adjacent_nodes = graph[u] || {};
5210
5211       // ...and explore the edges that connect u to those nodes, updating
5212       // the cost of the shortest paths to any or all of those nodes as
5213       // necessary. v is the node across the current edge from u.
5214       for (v in adjacent_nodes) {
5215         if (adjacent_nodes.hasOwnProperty(v)) {
5216           // Get the cost of the edge running from u to v.
5217           cost_of_e = adjacent_nodes[v];
5218
5219           // Cost of s to u plus the cost of u to v across e--this is *a*
5220           // cost from s to v that may or may not be less than the current
5221           // known cost to v.
5222           cost_of_s_to_u_plus_cost_of_e = cost_of_s_to_u + cost_of_e;
5223
5224           // If we haven't visited v yet OR if the current known cost from s to
5225           // v is greater than the new cost we just found (cost of s to u plus
5226           // cost of u to v across e), update v's cost in the cost list and
5227           // update v's predecessor in the predecessor list (it's now u).
5228           cost_of_s_to_v = costs[v];
5229           first_visit = (typeof costs[v] === 'undefined');
5230           if (first_visit || cost_of_s_to_v > cost_of_s_to_u_plus_cost_of_e) {
5231             costs[v] = cost_of_s_to_u_plus_cost_of_e;
5232             open.push(v, cost_of_s_to_u_plus_cost_of_e);
5233             predecessors[v] = u;
5234           }
5235         }
5236       }
5237     }
5238
5239     if (typeof d !== 'undefined' && typeof costs[d] === 'undefined') {
5240       var msg = ['Could not find a path from ', s, ' to ', d, '.'].join('');
5241       throw new Error(msg);
5242     }
5243
5244     return predecessors;
5245   },
5246
5247   extract_shortest_path_from_predecessor_list: function(predecessors, d) {
5248     var nodes = [];
5249     var u = d;
5250     var predecessor;
5251     while (u) {
5252       nodes.push(u);
5253       predecessor = predecessors[u];
5254       u = predecessors[u];
5255     }
5256     nodes.reverse();
5257     return nodes;
5258   },
5259
5260   find_path: function(graph, s, d) {
5261     var predecessors = dijkstra.single_source_shortest_paths(graph, s, d);
5262     return dijkstra.extract_shortest_path_from_predecessor_list(
5263       predecessors, d);
5264   },
5265
5266   /**
5267    * A very naive priority queue implementation.
5268    */
5269   PriorityQueue: {
5270     make: function (opts) {
5271       var T = dijkstra.PriorityQueue,
5272           t = {},
5273           key;
5274       opts = opts || {};
5275       for (key in T) {
5276         if (T.hasOwnProperty(key)) {
5277           t[key] = T[key];
5278         }
5279       }
5280       t.queue = [];
5281       t.sorter = opts.sorter || T.default_sorter;
5282       return t;
5283     },
5284
5285     default_sorter: function (a, b) {
5286       return a.cost - b.cost;
5287     },
5288
5289     /**
5290      * Add a new item to the queue and ensure the highest priority element
5291      * is at the front of the queue.
5292      */
5293     push: function (value, cost) {
5294       var item = {value: value, cost: cost};
5295       this.queue.push(item);
5296       this.queue.sort(this.sorter);
5297     },
5298
5299     /**
5300      * Return the highest priority element in the queue.
5301      */
5302     pop: function () {
5303       return this.queue.shift();
5304     },
5305
5306     empty: function () {
5307       return this.queue.length === 0;
5308     }
5309   }
5310 };
5311
5312
5313 // node.js module exports
5314 if (typeof module !== 'undefined') {
5315   module.exports = dijkstra;
5316 }
5317
5318 },{}],32:[function(require,module,exports){
5319 exports.read = function (buffer, offset, isLE, mLen, nBytes) {
5320   var e, m
5321   var eLen = (nBytes * 8) - mLen - 1
5322   var eMax = (1 << eLen) - 1
5323   var eBias = eMax >> 1
5324   var nBits = -7
5325   var i = isLE ? (nBytes - 1) : 0
5326   var d = isLE ? -1 : 1
5327   var s = buffer[offset + i]
5328
5329   i += d
5330
5331   e = s & ((1 << (-nBits)) - 1)
5332   s >>= (-nBits)
5333   nBits += eLen
5334   for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
5335
5336   m = e & ((1 << (-nBits)) - 1)
5337   e >>= (-nBits)
5338   nBits += mLen
5339   for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
5340
5341   if (e === 0) {
5342     e = 1 - eBias
5343   } else if (e === eMax) {
5344     return m ? NaN : ((s ? -1 : 1) * Infinity)
5345   } else {
5346     m = m + Math.pow(2, mLen)
5347     e = e - eBias
5348   }
5349   return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
5350 }
5351
5352 exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
5353   var e, m, c
5354   var eLen = (nBytes * 8) - mLen - 1
5355   var eMax = (1 << eLen) - 1
5356   var eBias = eMax >> 1
5357   var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
5358   var i = isLE ? 0 : (nBytes - 1)
5359   var d = isLE ? 1 : -1
5360   var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
5361
5362   value = Math.abs(value)
5363
5364   if (isNaN(value) || value === Infinity) {
5365     m = isNaN(value) ? 1 : 0
5366     e = eMax
5367   } else {
5368     e = Math.floor(Math.log(value) / Math.LN2)
5369     if (value * (c = Math.pow(2, -e)) < 1) {
5370       e--
5371       c *= 2
5372     }
5373     if (e + eBias >= 1) {
5374       value += rt / c
5375     } else {
5376       value += rt * Math.pow(2, 1 - eBias)
5377     }
5378     if (value * c >= 2) {
5379       e++
5380       c /= 2
5381     }
5382
5383     if (e + eBias >= eMax) {
5384       m = 0
5385       e = eMax
5386     } else if (e + eBias >= 1) {
5387       m = ((value * c) - 1) * Math.pow(2, mLen)
5388       e = e + eBias
5389     } else {
5390       m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
5391       e = 0
5392     }
5393   }
5394
5395   for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
5396
5397   e = (e << mLen) | m
5398   eLen += mLen
5399   for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
5400
5401   buffer[offset + i - d] |= s * 128
5402 }
5403
5404 },{}],33:[function(require,module,exports){
5405 var toString = {}.toString;
5406
5407 module.exports = Array.isArray || function (arr) {
5408   return toString.call(arr) == '[object Array]';
5409 };
5410
5411 },{}]},{},[24])(24)
5412 });
5413
5414 //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCJsaWIvY2FuLXByb21pc2UuanMiLCJsaWIvY29yZS9hbGlnbm1lbnQtcGF0dGVybi5qcyIsImxpYi9jb3JlL2FscGhhbnVtZXJpYy1kYXRhLmpzIiwibGliL2NvcmUvYml0LWJ1ZmZl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Bjb2wtLVxuXG4gICAgd2hpbGUgKHRydWUpIHtcbiAgICAgIGZvciAodmFyIGMgPSAwOyBjIDwgMjsgYysrKSB7XG4gICAgICAgIGlmICghbWF0cml4LmlzUmVzZXJ2ZWQocm93LCBjb2wgLSBjKSkge1xuICAgICAgICAgIHZhciBkYXJrID0gZmFsc2VcblxuICAgICAgICAgIGlmIChieXRlSW5kZXggPCBkYXRhLmxlbmd0aCkge1xuICAgICAgICAgICAgZGFyayA9ICgoKGRhdGFbYnl0ZUluZGV4XSA+Pj4gYml0SW5kZXgpICYgMSkgPT09IDEpXG4gICAgICAgICAgfVxuXG4gICAgICAgICAgbWF0cml4LnNldChyb3csIGNvbCAtIGMsIGRhcmspXG4gICAgICAgICAgYml0SW5kZXgtLVxuXG4gICAgICAgICAgaWYgKGJpdEluZGV4ID09PSAtMSkge1xuICAgICAgICAgICAgYnl0ZUluZGV4KytcbiAgICAgICAgICAgIGJpdEluZGV4ID0gN1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgfVxuXG4gICAgICByb3cgKz0gaW5jXG5cbiAgICAgIGlmIChyb3cgPCAwIHx8IHNpemUgPD0gcm93KSB7XG4gICAgICAgIHJvdyAtPSBpbmNcbiAgICAgICAgaW5jID0gLWluY1xuICAgICAgICBicmVha1xuICAgICAgfVxuICAgIH1cbiAgfVxufVxuXG4vKipcbiAqIENyZWF0ZSBlbmNvZGVkIGNvZGV3b3JkcyBmcm9tIGRhdGEgaW5wdXRcbiAqXG4gKiBAcGFyYW0gIHtOdW1iZXJ9ICAgdmVyc2lvbiAgICAgICAgICAgICAgUVIgQ29kZSB2ZXJzaW9uXG4gKiBAcGFyYW0gIHtFcnJvckNvcnJlY3Rpb25MZXZlbH0gICBlcnJvckNvcnJlY3Rpb25MZXZlbCBFcnJvciBjb3JyZWN0aW9uIGxldmVsXG4gKiBAcGFyYW0gIHtCeXRlRGF0YX0gZGF0YSAgICAgICAgICAgICAgICAgRGF0YSBpbnB1dFxuICogQHJld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