[
  {
    "path": ".gitignore",
    "content": "*~\nnode_modules\ncoverage\n.nyc_output\nbuild\n"
  },
  {
    "path": ".travis.yml",
    "content": "language: node_js\ndist: bionic\nnode_js:\n  - '10.13.0'\n  - '10'\n  - '12'\n  - 'node'\n"
  },
  {
    "path": "CHANGELOG.md",
    "content": "## [1.3.3](https://github.com/soldair/node-qrcode/compare/v1.3.2...v1.3.3) (2019-01-16)\n\nfixing security vulnerabillities reported by users of snyk and `npm audit` major\nversions of deps were bumped and should only impact development of qrcode.\n\n\n## [1.3.2](https://github.com/soldair/node-qrcode/compare/v1.3.0...v1.3.2) (2019-01-16)\n\n\n### Bug Fixes\n\n* forgot can-promise replacement ([2514445](https://github.com/soldair/node-qrcode/commit/2514445))\n* replacing can-promise ([8197d78](https://github.com/soldair/node-qrcode/commit/8197d78))\n* security vulnerabillities and a ref to new Buffer ([a40c757](https://github.com/soldair/node-qrcode/commit/a40c757))\n\n\n\n# [1.3.0](https://github.com/soldair/node-qrcode/compare/v1.2.1...v1.3.0) (2018-10-01)\n\n\n\n## [1.2.1](https://github.com/soldair/node-qrcode/compare/v1.2.0...v1.2.1) (2018-06-06)\n\n\n\n# [1.2.0](https://github.com/soldair/node-qrcode/compare/v1.1.0...v1.2.0) (2017-12-28)\n\n\n\n# [1.1.0](https://github.com/soldair/node-qrcode/compare/v1.0.1...v1.1.0) (2017-12-28)\n\n\n\n## [1.0.1](https://github.com/soldair/node-qrcode/compare/v1.0.0...v1.0.1) (2017-12-27)\n\n\n\n# [1.0.0](https://github.com/soldair/node-qrcode/compare/v0.9.0...v1.0.0) (2017-11-08)\n\nno breaking changes. promoting to a stable semver\n\n# [0.9.0](https://github.com/soldair/node-qrcode/compare/v0.8.2...v0.9.0) (2017-07-22)\n\n\n\n## [0.8.2](https://github.com/soldair/node-qrcode/compare/v0.8.0...v0.8.2) (2017-05-23)\n\n\n\n# [0.8.0](https://github.com/soldair/node-qrcode/compare/v0.7.1...v0.8.0) (2017-03-30)\n\n\n\n## [0.7.1](https://github.com/soldair/node-qrcode/compare/v0.7.0...v0.7.1) (2017-03-17)\n\n\n\n# [0.7.0](https://github.com/soldair/node-qrcode/compare/v0.6.0...v0.7.0) (2017-02-27)\n\n\n\n# [0.6.0](https://github.com/soldair/node-qrcode/compare/v0.5.0...v0.6.0) (2017-02-24)\n\n\n\n# [0.5.0](https://github.com/soldair/node-qrcode/compare/v0.4.4...v0.5.0) (2016-09-19)\n\n\n\n## [0.4.4](https://github.com/soldair/node-qrcode/compare/v0.4.3...v0.4.4) (2016-08-25)\n\n\n\n## [0.4.3](https://github.com/soldair/node-qrcode/compare/v0.4.0...v0.4.3) (2016-08-16)\n\n\n\n# [0.4.0](https://github.com/soldair/node-qrcode/compare/0.2.10...v0.4.0) (2015-09-17)\n\n\n\n## [0.1.1](https://github.com/soldair/node-qrcode/compare/v0.1.0...v0.1.1) (2011-04-17)\n\n\n\n# [0.1.0](https://github.com/soldair/node-qrcode/compare/0.0.3...v0.1.0) (2011-04-17)\n\n\n\n## [0.0.3](https://github.com/soldair/node-qrcode/compare/0.0.2...0.0.3) (2011-02-27)\n\n\n\n## 0.0.2 (2010-12-27)\n\n\n\n"
  },
  {
    "path": "CODE_OF_CONDUCT.md",
    "content": "# Contributor Covenant Code of Conduct\n\n## Our Pledge\n\nIn the interest of fostering an open and welcoming environment, we as\ncontributors and maintainers pledge to making participation in our project and\nour community a harassment-free experience for everyone, regardless of age, body\nsize, disability, ethnicity, sex characteristics, gender identity and expression,\nlevel of experience, education, socio-economic status, nationality, personal\nappearance, race, religion, or sexual identity and orientation.\n\n## Our Standards\n\nExamples of behavior that contributes to creating a positive environment\ninclude:\n\n* Using welcoming and inclusive language\n* Being respectful of differing viewpoints and experiences\n* Gracefully accepting constructive criticism\n* Focusing on what is best for the community\n* Showing empathy towards other community members\n\nExamples of unacceptable behavior by participants include:\n\n* The use of sexualized language or imagery and unwelcome sexual attention or\n advances\n* Trolling, insulting/derogatory comments, and personal or political attacks\n* Public or private harassment\n* Publishing others' private information, such as a physical or electronic\n address, without explicit permission\n* Other conduct which could reasonably be considered inappropriate in a\n professional setting\n\n## Our Responsibilities\n\nProject maintainers are responsible for clarifying the standards of acceptable\nbehavior and are expected to take appropriate and fair corrective action in\nresponse to any instances of unacceptable behavior.\n\nProject maintainers have the right and responsibility to remove, edit, or\nreject comments, commits, code, wiki edits, issues, and other contributions\nthat are not aligned to this Code of Conduct, or to ban temporarily or\npermanently any contributor for other behaviors that they deem inappropriate,\nthreatening, offensive, or harmful.\n\n## Scope\n\nThis Code of Conduct applies both within project spaces and in public spaces\nwhen an individual is representing the project or its community. Examples of\nrepresenting a project or community include using an official project e-mail\naddress, posting via an official social media account, or acting as an appointed\nrepresentative at an online or offline event. Representation of a project may be\nfurther defined and clarified by project maintainers.\n\n## Enforcement\n\nInstances of abusive, harassing, or otherwise unacceptable behavior may be\nreported by contacting the project team at soldair+qrcode@gmail.com. All\ncomplaints will be reviewed and investigated and will result in a response that\nis deemed necessary and appropriate to the circumstances. The project team is\nobligated to maintain confidentiality with regard to the reporter of an incident.\nFurther details of specific enforcement policies may be posted separately.\n\nProject maintainers who do not follow or enforce the Code of Conduct in good\nfaith may face temporary or permanent repercussions as determined by other\nmembers of the project's leadership.\n\n## Attribution\n\nThis Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,\navailable at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html\n\n[homepage]: https://www.contributor-covenant.org\n\nFor answers to common questions about this code of conduct, see\nhttps://www.contributor-covenant.org/faq\n"
  },
  {
    "path": "CONTRIBUTING.md",
    "content": "# qrcode Contributing Guidelines\n\n- Always search for a related issue before starting a new issue.\n- Always choose a concise, helpful issue name.\n- Always stay on-topic. If you've got a new bug report or feature request, put it in its own issue.\n- Always be polite to other people.\n- Never post private information, such as torrent or tracker names, IP addresses, etc.\n\nIssues that break the rules may be deleted and locked without warning.\n\n## qrcode is an OPEN Open Source Project\n\nIndividuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project.\n\n## Rules\n\nThere are a few basic ground-rules for contributors:\n\n1. **No `--force` pushes** or modifying the Git history in any way.\n1. **External API changes and significant modifications** should be subject to a **pull request** to solicit feedback from other contributors.\n1. Pull requests to solicit feedback are *encouraged* for any other non-trivial contribution but left to the discretion of the contributor.\n1. Use a non-`master` branch for ongoing work.\n1. Contributors should attempt to adhere to the prevailing code style.\n1. Run `npm test` locally before submitting your PR to catch easy-to-miss style & testing issues\n\n## Releases\n\nDeclaring formal releases remains the prerogative of the project maintainer.\n\n## Changes to this arrangement\n\n*Thanks to [Rod Vagg](https://github.com/rvagg) and the [LevelUP](https://github.com/rvagg/node-levelup) project for coming up with this model of open source contribution.*\n"
  },
  {
    "path": "README.md",
    "content": "# node-qrcode\n> QR code/2d barcode generator.\n\n[![Travis](https://img.shields.io/travis/soldair/node-qrcode.svg?style=flat-square)](http://travis-ci.org/soldair/node-qrcode)\n[![npm](https://img.shields.io/npm/v/qrcode.svg?style=flat-square)](https://www.npmjs.com/package/qrcode)\n[![npm](https://img.shields.io/npm/dt/qrcode.svg?style=flat-square)](https://www.npmjs.com/package/qrcode)\n[![npm](https://img.shields.io/npm/l/qrcode.svg?style=flat-square)](https://github.com/soldair/node-qrcode/blob/master/license)\n\n- [Highlights](#highlights)\n- [Installation](#installation)\n- [Usage](#usage)\n- [Error correction level](#error-correction-level)\n- [QR Code capacity](#qr-code-capacity)\n- [Encoding Modes](#encoding-modes)\n- [Binary data](#binary-data)\n- [Multibyte characters](#multibyte-characters)\n- [API](#api)\n- [GS1 QR Codes](#gs1-qr-codes)\n- [Credits](#credits)\n- [License](#license)\n\n## Highlights\n- Works on server and client (and react native with svg)\n- CLI utility\n- Save QR code as image\n- Support for Numeric, Alphanumeric, Kanji and Byte mode\n- Support for mixed modes\n- Support for chinese, cyrillic, greek and japanese characters\n- Support for multibyte characters (like emojis :smile:)\n- Auto generates optimized segments for best data compression and smallest QR Code size\n- App agnostic readability, QR Codes by definition are app agnostic\n\n## Installation\nInside your project folder do:\n\n```shell\nnpm install --save qrcode\n```\n\nor, install it globally to use `qrcode` from the command line to save qrcode images or generate ones you can view in your terminal.\n\n```shell\nnpm install -g qrcode\n```\n\n## Usage\n### CLI\n\n```\nUsage: qrcode [options] <input string>\n\nQR Code options:\n  -v, --qversion  QR Code symbol version (1 - 40)                       [number]\n  -e, --error     Error correction level           [choices: \"L\", \"M\", \"Q\", \"H\"]\n  -m, --mask      Mask pattern (0 - 7)                                  [number]\n\nRenderer options:\n  -t, --type        Output type                  [choices: \"png\", \"svg\", \"utf8\"]\n  -w, --width       Image width (px)                                    [number]\n  -s, --scale       Scale factor                                        [number]\n  -q, --qzone       Quiet zone size                                     [number]\n  -l, --lightcolor  Light RGBA hex color\n  -d, --darkcolor   Dark RGBA hex color\n  --small  Output smaller QR code to terminal                          [boolean]\n\nOptions:\n  -o, --output  Output file\n  -h, --help    Show help                                              [boolean]\n  --version     Show version number                                    [boolean]\n\nExamples:\n  qrcode \"some text\"                    Draw in terminal window\n  qrcode -o out.png \"some text\"         Save as png image\n  qrcode -d F00 -o out.png \"some text\"  Use red as foreground color\n```\nIf not specified, output type is guessed from file extension.<br>\nRecognized extensions are `png`, `svg` and `txt`.\n\n### Browser\n`node-qrcode` can be used in browser through module bundlers like [Browserify](https://github.com/substack/node-browserify) and [Webpack](https://github.com/webpack/webpack) or by including the precompiled bundle present in `build/` folder.\n\n#### Module bundlers\n```html\n<!-- index.html -->\n<html>\n  <body>\n    <canvas id=\"canvas\"></canvas>\n    <script src=\"bundle.js\"></script>\n  </body>\n</html>\n```\n\n```javascript\n// index.js -> bundle.js\nvar QRCode = require('qrcode')\nvar canvas = document.getElementById('canvas')\n\nQRCode.toCanvas(canvas, 'sample text', function (error) {\n  if (error) console.error(error)\n  console.log('success!');\n})\n```\n\n#### Precompiled bundle\n```html\n<canvas id=\"canvas\"></canvas>\n\n<script src=\"/build/qrcode.js\"></script>\n<script>\n  QRCode.toCanvas(document.getElementById('canvas'), 'sample text', function (error) {\n    if (error) console.error(error)\n    console.log('success!');\n  })\n</script>\n```\n\nIf you install through `npm`, precompiled files will be available in `node_modules/qrcode/build/` folder.\n\nThe precompiled bundle have support for [Internet Explorer 10+, Safari 5.1+, and all evergreen browsers](https://browserl.ist/?q=defaults%2C+IE+%3E%3D+10%2C+Safari+%3E%3D+5.1).\n\n### NodeJS\nRequire the module `qrcode`\n\n```javascript\nvar QRCode = require('qrcode')\n\nQRCode.toDataURL('I am a pony!', function (err, url) {\n  console.log(url)\n})\n```\n\nrender a qrcode for the terminal\n```js\nvar QRCode = require('qrcode')\n\nQRCode.toString('I am a pony!',{type:'terminal'}, function (err, url) {\n  console.log(url)\n})\n```\n\n### ES6/ES7\nPromises and Async/Await can be used in place of callback function.\n\n```javascript\nimport QRCode from 'qrcode'\n\n// With promises\nQRCode.toDataURL('I am a pony!')\n  .then(url => {\n    console.log(url)\n  })\n  .catch(err => {\n    console.error(err)\n  })\n\n// With async/await\nconst generateQR = async text => {\n  try {\n    console.log(await QRCode.toDataURL(text))\n  } catch (err) {\n    console.error(err)\n  }\n}\n```\n\n## Error correction level\nError correction capability allows to successfully scan a QR Code even if the symbol is dirty or damaged.\nFour levels are available to choose according to the operating environment.\n\nHigher levels offer a better error resistance but reduce the symbol's capacity.<br>\nIf the chances that the QR Code symbol may be corrupted are low (for example if it is showed through a monitor)\nis possible to safely use a low error level such as `Low` or `Medium`.\n\nPossible levels are shown below:\n\n| Level            | Error resistance |\n|------------------|:----------------:|\n| **L** (Low)      | **~7%**          |\n| **M** (Medium)   | **~15%**         |\n| **Q** (Quartile) | **~25%**         |\n| **H** (High)     | **~30%**         |\n\nThe percentage indicates the maximum amount of damaged surface after which the symbol becomes unreadable.\n\nError level can be set through `options.errorCorrectionLevel` property.<br>\nIf not specified, the default value is `M`.\n\n```javascript\nQRCode.toDataURL('some text', { errorCorrectionLevel: 'H' }, function (err, url) {\n  console.log(url)\n})\n```\n\n## QR Code capacity\nCapacity depends on symbol version and error correction level. Also encoding modes may influence the amount of storable data.\n\nThe QR Code versions range from version **1** to version **40**.<br>\nEach version has a different number of modules (black and white dots), which define the symbol's size.\nFor version 1 they are `21x21`, for version 2 `25x25` e so on.\nHigher is the version, more are the storable data, and of course bigger will be the QR Code symbol.\n\nThe table below shows the maximum number of storable characters in each encoding mode and for each error correction level.\n\n| Mode         | L    | M    | Q    | H    |\n|--------------|------|------|------|------|\n| Numeric      | 7089 | 5596 | 3993 | 3057 |\n| Alphanumeric | 4296 | 3391 | 2420 | 1852 |\n| Byte         | 2953 | 2331 | 1663 | 1273 |\n| Kanji        | 1817 | 1435 | 1024 | 784  |\n\n**Note:** Maximum characters number can be different when using [Mixed modes](#mixed-modes).\n\nQR Code version can be set through `options.version` property.<br>\nIf no version is specified, the more suitable value will be used. Unless a specific version is required, this option is not needed.\n\n```javascript\nQRCode.toDataURL('some text', { version: 2 }, function (err, url) {\n  console.log(url)\n})\n```\n\n## Encoding modes\nModes can be used to encode a string in a more efficient way.<br>\nA mode may be more suitable than others depending on the string content.\nA list of supported modes are shown in the table below:\n\n| Mode         | Characters                                                | Compression                               |\n|--------------|-----------------------------------------------------------|-------------------------------------------|\n| Numeric      | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9                              | 3 characters are represented by 10 bits   |\n| Alphanumeric | 0–9, A–Z (upper-case only), space, $, %, *, +, -, ., /, : | 2 characters are represented by 11 bits   |\n| Kanji        | Characters from the Shift JIS system based on JIS X 0208  | 2 kanji are represented by 13 bits        |\n| Byte         | Characters from the ISO/IEC 8859-1 character set          | Each characters are represented by 8 bits |\n\nChoose the right mode may be tricky if the input text is unknown.<br>\nIn these cases **Byte** mode is the best choice since all characters can be encoded with it. (See [Multibyte characters](#multibyte-characters))<br>\nHowever, if the QR Code reader supports mixed modes, using [Auto mode](#auto-mode) may produce better results.\n\n### Mixed modes\nMixed modes are also possible. A QR code can be generated from a series of segments having different encoding modes to optimize the data compression.<br>\nHowever, switching from a mode to another has a cost which may lead to a worst result if it's not taken into account.\nSee [Manual mode](#manual-mode) for an example of how to specify segments with different encoding modes.\n\n### Auto mode\nBy **default**, automatic mode selection is used.<br>\nThe input string is automatically splitted in various segments optimized to produce the shortest possible bitstream using mixed modes.<br>\nThis is the preferred way to generate the QR Code.\n\nFor example, the string **ABCDE12345678?A1A** will be splitted in 3 segments with the following modes:\n\n| Segment  | Mode         |\n|----------|--------------|\n| ABCDE    | Alphanumeric |\n| 12345678 | Numeric      |\n| ?A1A     | Byte         |\n\nAny other combinations of segments and modes will result in a longer bitstream.<br>\nIf you need to keep the QR Code size small, this mode will produce the best results.\n\n### Manual mode\nIf auto mode doesn't work for you or you have specific needs, is also possible to manually specify each segment with the relative mode.\nIn this way no segment optimizations will be applied under the hood.<br>\nSegments list can be passed as an array of object:\n\n```javascript\n  var QRCode = require('qrcode')\n\n  var segs = [\n    { data: 'ABCDEFG', mode: 'alphanumeric' },\n    { data: '0123456', mode: 'numeric' }\n  ]\n\n  QRCode.toDataURL(segs, function (err, url) {\n    console.log(url)\n  })\n```\n\n### Kanji mode\nWith kanji mode is possible to encode characters from the Shift JIS system in an optimized way.<br>\nUnfortunately, there isn't a way to calculate a Shifted JIS values from, for example, a character encoded in UTF-8, for this reason a conversion table from the input characters to the SJIS values is needed.<br>\nThis table is not included by default in the bundle to keep the size as small as possible.\n\nIf your application requires kanji support, you will need to pass a function that will take care of converting the input characters to appropriate values.\n\nAn helper method is provided by the lib through an optional file that you can include as shown in the example below.\n\n**Note:** Support for Kanji mode is only needed if you want to benefit of the data compression, otherwise is still possible to encode kanji using Byte mode (See [Multibyte characters](#multibyte-characters)).\n\n```javascript\n  var QRCode = require('qrcode')\n  var toSJIS = require('qrcode/helper/to-sjis')\n\n  QRCode.toDataURL(kanjiString, { toSJISFunc: toSJIS }, function (err, url) {\n    console.log(url)\n  })\n```\n\nWith precompiled bundle:\n\n```html\n<canvas id=\"canvas\"></canvas>\n\n<script src=\"/build/qrcode.min.js\"></script>\n<script src=\"/build/qrcode.tosjis.min.js\"></script>\n<script>\n  QRCode.toCanvas(document.getElementById('canvas'),\n    'sample text', { toSJISFunc: QRCode.toSJIS }, function (error) {\n    if (error) console.error(error)\n    console.log('success!')\n  })\n</script>\n```\n\n## Binary data\nQR Codes can hold arbitrary byte-based binary data. If you attempt to create a binary QR Code by first converting the data to a JavaScript string, it will fail to encode propery because string encoding adds additional bytes. Instead, you must pass a [`Uint8ClampedArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray) or compatible array, or a Node [Buffer](https://nodejs.org/api/buffer.html), as follows:\n\n```javascript\n// Regular array example\n// WARNING: Element values will be clamped to 0-255 even if your data contains higher values.\nconst QRCode = require('qrcode')\nQRCode.toFile(\n  'foo.png',\n  [{ data: [253,254,255], mode: 'byte' }],\n  ...options...,\n  ...callback...\n)\n```\n\n```javascript\n// Uint8ClampedArray example\nconst QRCode = require('qrcode')\n\nQRCode.toFile(\n  'foo.png',\n  [{ data: new Uint8ClampedArray([253,254,255]), mode: 'byte' }],\n  ...options...,\n  ...callback...\n)\n```\n\n```javascript\n// Node Buffer example\n// WARNING: Element values will be clamped to 0-255 even if your data contains higher values.\nconst QRCode = require('qrcode')\n\nQRCode.toFile(\n  'foo.png',\n  [{ data: Buffer.from([253,254,255]), mode: 'byte' }],\n  ...options...,\n  ...callback...\n)\n```\n\nTypeScript users: if you are using [@types/qrcode](https://www.npmjs.com/package/@types/qrcode), you will need to add a `// @ts-ignore` above the data segment because it expects `data: string`.\n\n## Multibyte characters\nSupport for multibyte characters isn't present in the initial QR Code standard, but is possible to encode UTF-8 characters in Byte mode.\n\nQR Codes provide a way to specify a different type of character set through ECI (Extended Channel Interpretation), but it's not fully implemented in this lib yet.\n\nMost QR Code readers, however, are able to recognize multibyte characters even without ECI.\n\nNote that a single Kanji/Kana or Emoji can take up to 4 bytes.\n\n## API\nBrowser:\n- [create()](#createtext-options)\n- [toCanvas()](#tocanvascanvaselement-text-options-cberror)\n- [toDataURL()](#todataurltext-options-cberror-url)\n- [toString()](#tostringtext-options-cberror-string)\n\nServer:\n- [create()](#createtext-options)\n- [toCanvas()](#tocanvascanvas-text-options-cberror)\n- [toDataURL()](#todataurltext-options-cberror-url-1)\n- [toString()](#tostringtext-options-cberror-string-1)\n- [toFile()](#tofilepath-text-options-cberror)\n- [toFileStream()](#tofilestreamstream-text-options)\n\n### Browser API\n#### `create(text, [options])`\nCreates QR Code symbol and returns a qrcode object.\n\n##### `text`\nType: `String|Array`\n\nText to encode or a list of objects describing segments.\n\n##### `options`\nSee [QR Code options](#qr-code-options).\n\n##### `returns`\nType: `Object`\n\n```javascript\n// QRCode object\n{\n  modules,              // Bitmatrix class with modules data\n  version,              // Calculated QR Code version\n  errorCorrectionLevel, // Error Correction Level\n  maskPattern,          // Calculated Mask pattern\n  segments              // Generated segments\n}\n```\n\n<br>\n\n#### `toCanvas(canvasElement, text, [options], [cb(error)])`\n#### `toCanvas(text, [options], [cb(error, canvas)])`\nDraws qr code symbol to canvas.<br>\nIf `canvasElement` is omitted a new canvas is returned.\n\n##### `canvasElement`\nType: `DOMElement`\n\nCanvas where to draw QR Code.\n\n##### `text`\nType: `String|Array`\n\nText to encode or a list of objects describing segments.\n\n##### `options`\nSee [Options](#options).\n\n##### `cb`\nType: `Function`\n\nCallback function called on finish.\n\n##### Example\n```javascript\nQRCode.toCanvas('text', { errorCorrectionLevel: 'H' }, function (err, canvas) {\n  if (err) throw err\n\n  var container = document.getElementById('container')\n  container.appendChild(canvas)\n})\n```\n\n<br>\n\n#### `toDataURL(text, [options], [cb(error, url)])`\n#### `toDataURL(canvasElement, text, [options], [cb(error, url)])`\nReturns a Data URI containing a representation of the QR Code image.<br>\nIf provided, `canvasElement` will be used as canvas to generate the data URI.\n\n##### `canvasElement`\nType: `DOMElement`\n\nCanvas where to draw QR Code.\n\n##### `text`\nType: `String|Array`\n\nText to encode or a list of objects describing segments.\n\n##### `options`\n- ###### `type`\n  Type: `String`<br>\n  Default: `image/png`\n\n  Data URI format.<br>\n  Possible values are: `image/png`, `image/jpeg`, `image/webp`.<br>\n\n- ###### `rendererOpts.quality`\n  Type: `Number`<br>\n  Default: `0.92`\n\n  A Number between `0` and `1` indicating image quality if the requested type is `image/jpeg` or `image/webp`.\n\nSee [Options](#options) for other settings.\n\n##### `cb`\nType: `Function`\n\nCallback function called on finish.\n\n##### Example\n```javascript\nvar opts = {\n  errorCorrectionLevel: 'H',\n  type: 'image/jpeg',\n  quality: 0.3,\n  margin: 1,\n  color: {\n    dark:\"#010599FF\",\n    light:\"#FFBF60FF\"\n  }\n}\n\nQRCode.toDataURL('text', opts, function (err, url) {\n  if (err) throw err\n\n  var img = document.getElementById('image')\n  img.src = url\n})\n```\n<br>\n\n#### `toString(text, [options], [cb(error, string)])`\n\nReturns a string representation of the QR Code.<br>\n\n\n##### `text`\nType: `String|Array`\n\nText to encode or a list of objects describing segments.\n\n##### `options`\n- ###### `type`\n  Type: `String`<br>\n  Default: `utf8`\n\n  Output format.<br>\n  Possible values are: `terminal`,`utf8`, and `svg`.\n\nSee [Options](#options) for other settings.\n\n##### `cb`\nType: `Function`\n\nCallback function called on finish.\n\n##### Example\n```javascript\nQRCode.toString('http://www.google.com', function (err, string) {\n  if (err) throw err\n  console.log(string)\n})\n```\n\n<br>\n\n\n### Server API\n#### `create(text, [options])`\nSee [create](#createtext-options).\n\n<br>\n\n#### `toCanvas(canvas, text, [options], [cb(error)])`\nDraws qr code symbol to [node canvas](https://github.com/Automattic/node-canvas).\n\n##### `text`\nType: `String|Array`\n\nText to encode or a list of objects describing segments.\n\n##### `options`\nSee [Options](#options).\n\n##### `cb`\nType: `Function`\n\nCallback function called on finish.\n\n<br>\n\n#### `toDataURL(text, [options], [cb(error, url)])`\nReturns a Data URI containing a representation of the QR Code image.<br>\nOnly works with `image/png` type for now.\n\n##### `text`\nType: `String|Array`\n\nText to encode or a list of objects describing segments.\n\n##### `options`\nSee [Options](#options) for other settings.\n\n##### `cb`\nType: `Function`\n\nCallback function called on finish.\n\n<br>\n\n#### `toString(text, [options], [cb(error, string)])`\nReturns a string representation of the QR Code.<br>\nIf choosen output format is `svg` it will returns a string containing xml code.\n\n##### `text`\nType: `String|Array`\n\nText to encode or a list of objects describing segments.\n\n##### `options`\n- ###### `type`\n  Type: `String`<br>\n  Default: `utf8`\n\n  Output format.<br>\n  Possible values are: `utf8`, `svg`, `terminal`.\n\nSee [Options](#options) for other settings.\n\n##### `cb`\nType: `Function`\n\nCallback function called on finish.\n\n##### Example\n```javascript\nQRCode.toString('http://www.google.com', function (err, string) {\n  if (err) throw err\n  console.log(string)\n})\n```\n\n<br>\n\n#### `toFile(path, text, [options], [cb(error)])`\nSaves QR Code to image file.<br>\nIf `options.type` is not specified, the format will be guessed from file extension.<br>\nRecognized extensions are `png`, `svg`, `txt`.\n\n##### `path`\nType: `String`\n\nPath where to save the file.\n\n##### `text`\nType: `String|Array`\n\nText to encode or a list of objects describing segments.\n\n##### `options`\n- ###### `type`\n  Type: `String`<br>\n  Default: `png`\n\n  Output format.<br>\n  Possible values are: `png`, `svg`, `utf8`.\n\n- ###### `rendererOpts.deflateLevel` **(png only)**\n  Type: `Number`<br>\n  Default: `9`\n\n  Compression level for deflate.\n\n- ###### `rendererOpts.deflateStrategy` **(png only)**\n  Type: `Number`<br>\n  Default: `3`\n\n  Compression strategy for deflate.\n\nSee [Options](#options) for other settings.\n\n##### `cb`\nType: `Function`\n\nCallback function called on finish.\n\n##### Example\n```javascript\nQRCode.toFile('path/to/filename.png', 'Some text', {\n  color: {\n    dark: '#00F',  // Blue dots\n    light: '#0000' // Transparent background\n  }\n}, function (err) {\n  if (err) throw err\n  console.log('done')\n})\n```\n\n<br>\n\n#### `toFileStream(stream, text, [options])`\nWrites QR Code image to stream. Only works with `png` format for now.\n\n##### `stream`\nType: `stream.Writable`\n\nNode stream.\n\n##### `text`\nType: `String|Array`\n\nText to encode or a list of objects describing segments.\n\n##### `options`\nSee [Options](#options).\n\n<br>\n\n### Options\n\n#### QR Code options\n##### `version`\n  Type: `Number`<br>\n\n  QR Code version. If not specified the more suitable value will be calculated.\n\n##### `errorCorrectionLevel`\n  Type: `String`<br>\n  Default: `M`\n\n  Error correction level.<br>\n  Possible values are `low, medium, quartile, high` or `L, M, Q, H`.\n\n##### `maskPattern`\n  Type: `Number`<br>\n\n  Mask pattern used to mask the symbol.<br>\n  Possible values are `0`, `1`, `2`, `3`, `4`, `5`, `6`, `7`.<br>\n  If not specified the more suitable value will be calculated.\n\n##### `toSJISFunc`\n  Type: `Function`<br>\n\n  Helper function used internally to convert a kanji to its Shift JIS value.<br>\n  Provide this function if you need support for Kanji mode.\n\n#### Renderers options\n##### `margin`\n  Type: `Number`<br>\n  Default: `4`\n\n  Define how much wide the quiet zone should be.\n\n##### `scale`\n  Type: `Number`<br>\n  Default: `4`\n\n  Scale factor. A value of `1` means 1px per modules (black dots).\n\n##### `small`\n  Type: `Boolean`<br>\n  Default: `false`\n\n  Relevant only for terminal renderer. Outputs smaller QR code.\n\n##### `width`\n  Type: `Number`<br>\n\n  Forces a specific width for the output image.<br>\n  If width is too small to contain the qr symbol, this option will be ignored.<br>\n  Takes precedence over `scale`.\n\n##### `color.dark`\nType: `String`<br>\nDefault: `#000000ff`\n\nColor of dark module. Value must be in hex format (RGBA).<br>\nNote: dark color should always be darker than `color.light`.\n\n##### `color.light`\nType: `String`<br>\nDefault: `#ffffffff`\n\nColor of light module. Value must be in hex format (RGBA).<br>\n\n<br>\n\n## GS1 QR Codes\nThere was a real good discussion here about them. but in short any qrcode generator will make gs1 compatible qrcodes, but what defines a gs1 qrcode is a header with metadata that describes your gs1 information.\n\nhttps://github.com/soldair/node-qrcode/issues/45\n\n\n## Credits\nThis lib is based on \"QRCode for JavaScript\" which Kazuhiko Arase thankfully MIT licensed.\n\n## License\n[MIT](https://github.com/soldair/node-qrcode/blob/master/license)\n\nThe word \"QR Code\" is registered trademark of:<br>\nDENSO WAVE INCORPORATED\n"
  },
  {
    "path": "bin/qrcode",
    "content": "#!/usr/bin/env node\nvar yargs = require('yargs')\nvar qr = require('../lib')\n\nfunction save (file, text, options) {\n  qr.toFile(file, text, options, function (err, data) {\n    if (err) {\n      console.error('Error:', err.message)\n      process.exit(1)\n    }\n\n    console.log('saved qrcode to: ' + file + '\\n')\n  })\n}\n\nfunction print (text, options) {\n  options.type = 'terminal'\n  qr.toString(text, options, function (err, text) {\n    if (err) {\n      console.error('Error:', err.message)\n      process.exit(1)\n    }\n\n    console.log(text)\n  })\n}\n\nfunction parseOptions (args) {\n  return {\n    version: args.qversion,\n    errorCorrectionLevel: args.error,\n    type: args.type,\n    small: !!args.small,\n    inverse: !!args.inverse,\n    maskPattern: args.mask,\n    margin: args.qzone,\n    width: args.width,\n    scale: args.scale,\n    color: {\n      light: args.lightcolor,\n      dark: args.darkcolor\n    }\n  }\n}\n\nfunction processInputs (text, opts) {\n  if (!text.length) {\n    yargs.showHelp()\n    process.exit(1)\n  }\n\n  if (opts.output) {\n    save(opts.output, text, parseOptions(opts))\n  } else {\n    print(text, parseOptions(opts))\n  }\n}\n\nvar argv = yargs\n  .detectLocale(false)\n  .usage('Usage: $0 [options] <input string>')\n  .option('v', {\n    alias: 'qversion',\n    description: 'QR Code symbol version (1 - 40)',\n    group: 'QR Code options:',\n    type: 'number'\n  })\n  .option('e', {\n    alias: 'error',\n    description: 'Error correction level',\n    choices: ['L', 'M', 'Q', 'H'],\n    group: 'QR Code options:'\n  })\n  .option('m', {\n    alias: 'mask',\n    description: 'Mask pattern (0 - 7)',\n    group: 'QR Code options:',\n    type: 'number'\n  })\n  .option('t', {\n    alias: 'type',\n    description: 'Output type',\n    choices: ['png', 'svg', 'utf8'],\n    implies: 'output',\n    group: 'Renderer options:'\n  })\n  .option('i', {\n    alias: 'inverse',\n    type: 'boolean',\n    description: 'Invert colors',\n    group: 'Renderer options:'\n  })\n  .option('w', {\n    alias: 'width',\n    description: 'Image width (px)',\n    conflicts: 'scale',\n    group: 'Renderer options:',\n    type: 'number'\n  })\n  .option('s', {\n    alias: 'scale',\n    description: 'Scale factor',\n    conflicts: 'width',\n    group: 'Renderer options:',\n    type: 'number'\n  })\n  .option('q', {\n    alias: 'qzone',\n    description: 'Quiet zone size',\n    group: 'Renderer options:',\n    type: 'number'\n  })\n  .option('l', {\n    alias: 'lightcolor',\n    description: 'Light RGBA hex color',\n    group: 'Renderer options:'\n  })\n  .option('d', {\n    alias: 'darkcolor',\n    description: 'Dark RGBA hex color',\n    group: 'Renderer options:'\n  })\n  .option('small', {\n    type: 'boolean',\n    description: 'Output smaller QR code to terminal',\n    conflicts: 'type',\n    group: 'Renderer options:'\n  })\n  .option('o', {\n    alias: 'output',\n    description: 'Output file'\n  })\n  .help('h')\n  .alias('h', 'help')\n  .version()\n  .example('$0 \"some text\"', 'Draw in terminal window')\n  .example('$0 -o out.png \"some text\"', 'Save as png image')\n  .example('$0 -d F00 -o out.png \"some text\"', 'Use red as foreground color')\n  .parserConfiguration({'parse-numbers': false})\n  .argv\n\nif (process.stdin.isTTY) {\n  processInputs(argv._.join(' '), argv)\n} else {\n  var text = ''\n  process.stdin.setEncoding('utf8')\n  process.stdin.on('readable', function () {\n    var chunk = process.stdin.read()\n    if (chunk !== null) {\n      text += chunk\n    }\n  })\n\n  process.stdin.on('end', function () {\n    // this process can be run as a command outside of a tty so if there was no\n    // data on stdin read from argv\n    processInputs(text.length?text:argv._.join(' '), argv)\n  })\n}\n"
  },
  {
    "path": "examples/cli.js",
    "content": "const QRCode = require('../lib')\n\nQRCode.toString('yo yo yo', function (error, data) {\n  if (error) {\n    throw new Error(error)\n  }\n\n  console.log(data)\n})\n"
  },
  {
    "path": "examples/clientside.html",
    "content": "<!doctype html>\n<html>\n\n<head>\n  <meta charset=\"UTF-8\">\n  <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1\">\n  <title>client side test for node-qrcode</title>\n  <!--[if ie]><script type=\"text/javascript\" src=\"vendors/excanvas/excanvas.js\"></script><![endif]-->\n  <script src=\"qrcode.js\"></script> <!-- This doesn't exist in the examples, you'll need to supply this. -->\n  <script src=\"qrcode.tosjis.js\"></script> <!-- This doesn't exist in the examples, you'll need to supply. -->\n  <style>\n    * {\n      box-sizing: border-box;\n      font-family: Arial, Helvetica, sans-serif;\n    }\n\n    html,\n    body {\n      margin: 0;\n      background-color: ghostwhite;\n    }\n\n    input,\n    textarea {\n      font-size: 14px;\n      padding: 2px;\n    }\n\n    textarea {\n      resize: none;\n    }\n\n    .container {\n      display: flex;\n      margin: 0 auto;\n      padding: 16px;\n      justify-content: center;\n    }\n\n    .controls {\n      flex: 2;\n      display: flex;\n      flex-direction: column;\n      min-width: 400px;\n      max-width: 400px;\n    }\n\n    .qrcode-container {\n      display: flex;\n      justify-content: center;\n      align-items: center;\n    }\n\n    .qrcode-image {\n      border: 1px solid #ccc;\n    }\n\n    .container>*+* {\n      margin-left: 40px;\n    }\n\n    .title {\n      text-align: center;\n    }\n\n    .control-group {\n      display: flex;\n    }\n\n    .control-group+.control-group {\n      margin-top: 16px;\n    }\n\n    .control {\n      flex: 1;\n      display: flex;\n      flex-direction: column;\n    }\n\n    .control+.control {\n      margin-left: 16px;\n    }\n\n    .control>input {\n      width: 100%;\n    }\n\n    .control>textarea {\n      width: 100%;\n      flex-grow: 1;\n    }\n\n    .expand {\n      flex-grow: 1;\n    }\n  </style>\n</head>\n\n<body>\n  <h1 class=\"title\">node-qrcode</h1>\n  <div class=\"container\">\n    <div class=\"controls\">\n\n      <div class=\"control-group\">\n        <div class=\"control\">\n          <label for=\"version\">Version:</label>\n          <select id=\"version\" name=\"version\">\n            <option>Auto</option>\n          </select>\n        </div>\n        <div class=\"control\">\n          <label for=\"mode\">Mode:</label>\n          <select id=\"mode\" name=\"mode\">\n            <option>Auto</option>\n            <option>Numeric</option>\n            <option>Alphanumeric</option>\n            <option>Byte</option>\n            <option>Kanji</option>\n          </select>\n        </div>\n      </div>\n\n      <div class=\"control-group\">\n        <div class=\"control\">\n          <label for=\"margin\">Margin:</label>\n          <input id=\"margin\" type=\"number\" name=\"margin\" min=\"4\" value=\"4\" />\n        </div>\n        <div class=\"control\">\n          <label for=\"errorLevel\">Error Correction:</label>\n          <select id=\"errorLevel\" name=\"errorLevel\">\n            <option>Default (Medium)</option>\n            <option>Low</option>\n            <option>Medium</option>\n            <option>Quartile</option>\n            <option>High</option>\n          </select>\n        </div>\n      </div>\n\n      <div class=\"control-group\">\n        <div class=\"control color-control\">\n          <label for=\"lightColor\">Light color:</label>\n          <input id=\"lightColor\" type=\"color\" name=\"light\" value=\"#ffffff\" />\n        </div>\n        <div class=\"control color-control\">\n          <label for=\"darkColor\">Dark color:</label>\n          <input id=\"darkColor\" type=\"color\" name=\"dark\" value=\"#000000\" />\n        </div>\n      </div>\n\n      <div class=\"control-group expand\">\n        <div class=\"control\">\n          <label for=\"input-text\">Text:</label>\n          <textarea id=\"input-text\">https://github.com/soldair/node-qrcode</textarea>\n        </div>\n      </div>\n    </div>\n\n    <div class=\"qrcode-container\">\n      <p id=\"error\" class=\"error\"></p>\n      <canvas id=\"canvas\" class=\"qrcode-image\"></canvas>\n    </div>\n  </div>\n\n  <script>\n    var errorEl = document.getElementById('error')\n    var versionEl = document.getElementById('version')\n    var errorLevelEl = document.getElementById('errorLevel')\n    var modeEl = document.getElementById('mode')\n    var marginEl = document.getElementById('margin')\n    var lightColorEl = document.getElementById('lightColor')\n    var darkColorEl = document.getElementById('darkColor')\n    var canvasEl = document.getElementById('canvas')\n    var textEl = document.getElementById('input-text')\n\n    function debounce(func, wait, immediate) {\n      var timeout\n      return function () {\n        var context = this\n        var args = arguments\n        var later = function () {\n          timeout = null\n          if (!immediate) func.apply(context, args)\n        }\n\n        var callNow = immediate && !timeout\n        clearTimeout(timeout)\n        timeout = setTimeout(later, wait)\n        if (callNow) func.apply(context, args)\n      }\n    }\n\n    function drawQR(text) {\n      errorEl.style.display = 'none'\n      canvasEl.style.display = 'block'\n\n      QRCode.toCanvas(canvasEl, text, {\n        version: versionEl.value,\n        errorCorrectionLevel: errorLevelEl.options[errorLevelEl.selectedIndex].text,\n        margin: marginEl.value,\n        color: {\n          light: lightColorEl.value,\n          dark: darkColorEl.value\n        },\n        toSJISFunc: QRCode.toSJIS\n      }, function (error, canvas) {\n        if (error) {\n          canvasEl.style.display = 'none'\n          errorEl.style.display = 'inline'\n          errorEl.textContent = error\n        }\n      })\n    }\n\n    var updateQR = debounce(function () {\n      var mode = modeEl.options[modeEl.selectedIndex].text\n      if (mode !== 'Auto') {\n        drawQR([{ data: textEl.value, mode: mode }])\n      } else {\n        drawQR(textEl.value)\n      }\n    }, 250)\n\n    versionEl.addEventListener('change', updateQR, false)\n    errorLevelEl.addEventListener('change', updateQR, false)\n    modeEl.addEventListener('change', updateQR, false)\n    marginEl.addEventListener('change', updateQR, false)\n    lightColorEl.addEventListener('change', updateQR, false)\n    darkColorEl.addEventListener('change', updateQR, false)\n    textEl.addEventListener('keyup', updateQR, false)\n\n    for (var i = 1; i <= 40; i++) {\n      versionEl.options[versionEl.options.length] = new Option(i.toString(), i)\n    }\n\n    drawQR(textEl.value)\n  </script>\n\n</body>\n\n</html>"
  },
  {
    "path": "examples/clientsideserver.js",
    "content": "const express = require('express')\nconst app = express()// .createServer()\nconst http = require('http')\nconst fs = require('fs')\nconst QRCode = require('../lib')\nconst canvasutil = require('canvasutil')\nconst { createCanvas, loadImage } = require('canvas')\n\nconst path = require('path')\n\n// app.use(express.methodOverride())\n// app.use(express.bodyParser())\n// app.use(app.router)\n// app.use(express.static(path.resolve(__dirname, '..')))\n\napp.get('/qrcode.js', (req, res) => {\n  res.set('content-type', 'text/javascript')\n  fs.createReadStream(path.join(__dirname, '..', 'build', 'qrcode.js')).pipe(res)\n})\n\napp.get('/qrcode.tosjis.js', (req, res) => {\n  res.set('content-type', 'text/javascript')\n  fs.createReadStream(path.join(__dirname, '..', 'build', 'qrcode.tosjis.js')).pipe(res)\n})\n\napp.get('/', function (req, res) {\n  fs.readFile(path.join(__dirname, 'clientside.html'), function (err, data) {\n    res.send(data ? data.toString() : err)\n  })\n})\n\nconst effectHandlers = {}\n\napp.get('/generate', function (req, res) {\n  const q = req.query || {}\n\n  let effect = q.effect || 'plain'\n  if (!effectHandlers[effect]) {\n    effect = 'plain'\n  }\n\n  effectHandlers[effect](q, function (error, canvas) {\n    if (!error) {\n      canvas.toBuffer(function (err, buf) {\n        if (!err) {\n          res.header('Content-Type', 'image/png')\n          res.send(buf)\n        }\n      })\n    } else {\n      const msg = error.message + '\\n' + error.stack\n      res.header('Content-Type', 'text/plain')\n      res.send(msg)\n      console.error(msg)\n    }\n  })\n})\n\neffectHandlers.node = function (args, cb) {\n  args.src = path.join(__dirname, 'images', 'node_logo.png')\n  this.image(path.join(args, cb))\n}\n\neffectHandlers.npm = function (args, cb) {\n  args.src = path.join(__dirname, 'images', 'npm_logo.png')\n  this.image(args, cb)\n}\n\neffectHandlers.bacon = function (args, cb) {\n  args.src = path.join(__dirname, 'images', 'bacon-love.png')\n  this.image(args, cb)\n}\n\neffectHandlers.rounded = function (args, cb) {\n  const canvas = createCanvas(200, 200)\n  QRCode.toCanvas(canvas, args.text || '', function (err) {\n    if (err) {\n      cb(err, canvas)\n      return\n    }\n\n    const tpx = new canvasutil.PixelCore()\n    const luma709Only = canvasutil.conversionLib.luma709Only\n    const up = []\n    const down = []\n    const left = []\n    const right = []\n    let upPx\n    let downPx\n    let leftPx\n    let rightPx\n    let r\n    let t\n    let l\n    let d\n    let corner = 0\n\n    tpx.threshold = 100\n\n    tpx.iterate(canvas, function (px, i, len, pixels, w, h, pixelCore) {\n      corner = 0\n\n      // is dark\n      if (luma709Only(px.r, px.g, px.b) < pixelCore.threshold) {\n        if (i - w > 0) {\n          upPx = (i - w) * 4\n          up[0] = pixels[upPx + 0]\n          up[1] = pixels[upPx + 1]\n          up[2] = pixels[upPx + 2]\n          // console.log('up',up);\n        }\n\n        if (i + w <= len) {\n          downPx = (i + w) * 4\n          down[0] = pixels[downPx + 0]\n          down[1] = pixels[downPx + 1]\n          down[2] = pixels[downPx + 2]\n          // console.log('down',down);\n        }\n\n        // have left pixel but no wrapping\n        if (i % w !== 0) {\n          leftPx = (i - 1) * 4\n          left[0] = pixels[leftPx + 0]\n          left[1] = pixels[leftPx + 1]\n          left[2] = pixels[leftPx + 2]\n          // console.log('left',left);\n        }\n\n        if (i % w !== w - 1) {\n          rightPx = (i + 1) * 4\n          right[0] = pixels[rightPx + 0]\n          right[1] = pixels[rightPx + 1]\n          right[2] = pixels[rightPx + 2]\n          // console.log('right',right);\n        }\n\n        r = rightPx ? luma709Only(right[0], right[1], right[2]) : 0\n        t = upPx ? luma709Only(up[0], up[1], up[2]) : 0\n        l = leftPx ? luma709Only(left[0], left[1], left[2]) : 0\n        d = downPx ? luma709Only(down[0], down[1], down[2]) : 0\n\n        if (l > pixelCore.threshold) { // if left is light and i am dark\n          if (t > pixelCore.threshold) { // if top is light and i am dark\n            corner = 1\n            pixels[rightPx + 4] = 100\n          } else if (d > pixelCore.threshold) { // if bottom is light and i am dark\n            pixels[rightPx + 4] = 100\n            corner = 1\n          }\n        } else if (r > pixelCore.threshold) {\n          if (t > pixelCore.threshold) { // if top is light and i am dark\n            corner = 1\n          } else if (d > pixelCore.threshold) { // if bottom is light and i am dark\n            corner = 1\n          }\n        }\n\n        if (corner) {\n          px.a = 50\n        }\n      }\n    })\n    cb(null, canvas)\n  })\n}\n\neffectHandlers.remoteImage = function (args, cb) {\n  let src = args.src\n  let domain\n  let uri\n\n  if (!src) {\n    cb(new Error('src required'), null)\n  } else {\n    if (src.indexof('://') !== -1) {\n      src = src.split('://').unshift()\n      const parts = src.split('/')\n\n      domain = parts.shift()\n      uri = parts.join('/')\n    }\n  }\n\n  if (!domain || !uri) {\n    cb(new Error('missing domain or uri ' + args.src))\n    return\n  }\n\n  const options = {\n    host: domain,\n    port: 80,\n    path: uri,\n    method: 'GET'\n  }\n\n  const req = http.request(options, function (res) {\n    if (res.statusCode < 200 || res.statusCode > 299) {\n      cb(new Error('http ' + res.statusCode + ' response code'), null)\n      return\n    }\n\n    res.setEncoding('utf8')\n\n    let data = ''\n    res.on('data', function (chunk) {\n      data += chunk\n      console.log('BODY: ' + chunk)\n    })\n\n    res.on('complete', function () {\n      cb(null, data)\n    })\n\n    res.on('error', function (error) {\n      cb(error, null)\n      cb = function () {}\n    })\n  })\n\n  req.end()\n}\n\neffectHandlers.image = function (args, cb) {\n  loadImage(args.src || '').then((img) => {\n    const convert = canvasutil.conversionLib\n    const canvas = createCanvas(200, 200)\n    QRCode.toCanvas(canvas, args.text || '', function (err) {\n      if (err) {\n        cb(err, false)\n        return\n      }\n\n      const codeCtx = canvas.getContext('2d')\n      const frame = codeCtx.getImageData(0, 0, canvas.width, canvas.width)\n      const tpx = new canvasutil.PixelCore()\n      const baconCanvas = createCanvas(canvas.width, canvas.width)\n      const ctx = baconCanvas.getContext('2d')\n      const topThreshold = args.darkThreshold || 25\n      const bottomThreshold = args.lightThreshold || 75\n\n      tpx.threshold = 50\n\n      // scale image\n      let w = canvas.width\n      let h = canvas.height\n\n      if (img.width > img.height) {\n        w = w * (canvas.height / h)\n        h = canvas.height\n      } else {\n        h = h * (canvas.height / w)\n        w = canvas.width\n      }\n      ctx.drawImage(img, 0, 0, w, h)\n\n      try {\n        tpx.iterate(baconCanvas, function (px, i, l, pixels, w, h, pixelCore) {\n          const luma = (0.2125 * px.r + 0.7154 * px.g + 0.0721 * px.b)\n          const codeLuma = convert.luma709Only(frame.data[i * 4], frame.data[i * 4 + 1], frame.data[i * 4 + 2])\n          let yuv\n          let rgb\n\n          if (codeLuma > pixelCore.threshold) {\n            if (luma < bottomThreshold) {\n              yuv = convert.rgbToYuv(px.r, px.g, px.b)\n\n              rgb = convert.yuvToRgb(bottomThreshold, yuv[1], yuv[2])\n\n              px.r = rgb[0]\n              px.g = rgb[1]\n              px.b = rgb[2]\n              px.a = 255\n            }\n          } else {\n            if (luma > topThreshold) {\n              yuv = convert.rgbToYuv(px.r, px.g, px.b)\n\n              rgb = convert.yuvToRgb(topThreshold, yuv[1], yuv[2])\n\n              px.r = rgb[0]\n              px.g = rgb[1]\n              px.b = rgb[2]\n            }\n          }\n        })\n      } catch (e) {\n        cb(err, false)\n      }\n\n      cb(null, baconCanvas)\n    })\n  }, (error) => {\n    cb(error, null)\n  })\n}\n\neffectHandlers.plain = function (args, cb) {\n  const canvas = createCanvas(200, 200)\n  const text = args.text || ''\n  QRCode.toCanvas(canvas, text || '', function (err) {\n    cb(err, canvas)\n  })\n}\n\napp.listen(3031)\nconsole.log('listening on 3031')\n"
  },
  {
    "path": "examples/save.js",
    "content": "const QRCode = require('../lib')\n\nconst path = './tmp.png'\nQRCode.toFile(path, 'life of the party bros', {\n  color: {\n    dark: '#00F', // Blue modules\n    light: '#0000' // Transparent background\n  }\n}, function (err) {\n  if (err) throw err\n  console.log('saved.')\n})\n"
  },
  {
    "path": "examples/server.js",
    "content": "const QRCode = require('../lib')\nconst http = require('http')\n\nfunction testQRCode (req, res) {\n  res.writeHead(200, { 'Content-Type': 'text/html' })\n\n  const jungleBook = \"The moonlight was blocked out of the mouth of the cave, for Shere Khan's\\n\" +\n  'great square head and shoulders were thrust into the entrance. Tabaqui,\\n' +\n  'behind him, was squeaking: \"My lord, my lord, it went in here!\"\\n' +\n  '\\n' +\n  '\"Shere Khan does us great honor,\" said Father Wolf, but his eyes were\\n' +\n  'very angry. \"What does Shere Khan need?\"\\n' +\n  '\\n' +\n  \"\\\"My quarry. A man's cub went this way,\\\" said Shere Khan. \\\"Its parents\\n\" +\n  'have run off. Give it to me.\"\\n' +\n  '\\n' +\n  \"Shere Khan had jumped at a woodcutter's campfire, as Father Wolf had\\n\" +\n  'said, and was furious from the pain of his burned feet. But Father Wolf\\n' +\n  'knew that the mouth of the cave was too narrow for a tiger to come in\\n' +\n  \"by. Even where he was, Shere Khan's shoulders and forepaws were cramped\\n\" +\n  \"for want of room, as a man's would be if he tried to fight in a barrel.\\n\" +\n  '\\n' +\n  '\"The Wolves are a free people,\" said Father Wolf. \"They take orders from\\n' +\n  \"the Head of the Pack, and not from any striped cattle-killer. The man's\\n\" +\n  'cub is ours--to kill if we choose.\"'\n\n  // QRCode.QRCodeDraw.color.dark = '#d4d4d4';\n  QRCode.toDataURL(jungleBook, function (err, url) {\n    if (err) console.log('error: ' + err)\n    res.end(\"<!DOCTYPE html/><html><head><title>node-qrcode</title></head><body><img src='\" + url + \"'/></body></html>\")\n  })\n}\n\nhttp.createServer(testQRCode).listen(3030)\nconsole.log('test server started on port 3030')\n"
  },
  {
    "path": "examples/vendors/excanvas/README",
    "content": "ExplorerCanvas\r\nCopyright 2006 Google Inc.\r\n\r\n-------------------------------------------------------------------------------\r\nDESCRIPTION\r\n\r\nFirefox, Safari and Opera 9 support the canvas tag to allow 2D command-based \r\ndrawing operations. ExplorerCanvas brings the same functionality to Internet \r\nExplorer; web developers only need to include a single script tag in their \r\nexisting canvas webpages to enable this support.\r\n\r\n\r\n-------------------------------------------------------------------------------\r\nINSTALLATION\r\n\r\nInclude the ExplorerCanvas tag in the same directory as your HTML files, and \r\nadd the following code to your page, preferably in the <head> tag.\r\n\r\n<!--[if IE]><script type=\"text/javascript\" src=\"excanvas.js\"></script><![endif]-->\r\n\r\nIf you run into trouble, please look at the included example code to see how\r\nto best implement this"
  },
  {
    "path": "examples/vendors/excanvas/excanvas.compiled.js",
    "content": "// Copyright 2006 Google Inc.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//   http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\ndocument.createElement(\"canvas\").getContext||(function(){var s=Math,j=s.round,F=s.sin,G=s.cos,V=s.abs,W=s.sqrt,k=10,v=k/2;function X(){return this.context_||(this.context_=new H(this))}var L=Array.prototype.slice;function Y(b,a){var c=L.call(arguments,2);return function(){return b.apply(a,c.concat(L.call(arguments)))}}var M={init:function(b){if(/MSIE/.test(navigator.userAgent)&&!window.opera){var a=b||document;a.createElement(\"canvas\");a.attachEvent(\"onreadystatechange\",Y(this.init_,this,a))}},init_:function(b){b.namespaces.g_vml_||\nb.namespaces.add(\"g_vml_\",\"urn:schemas-microsoft-com:vml\",\"#default#VML\");b.namespaces.g_o_||b.namespaces.add(\"g_o_\",\"urn:schemas-microsoft-com:office:office\",\"#default#VML\");if(!b.styleSheets.ex_canvas_){var a=b.createStyleSheet();a.owningElement.id=\"ex_canvas_\";a.cssText=\"canvas{display:inline-block;overflow:hidden;text-align:left;width:300px;height:150px}g_vml_\\\\:*{behavior:url(#default#VML)}g_o_\\\\:*{behavior:url(#default#VML)}\"}var c=b.getElementsByTagName(\"canvas\"),d=0;for(;d<c.length;d++)this.initElement(c[d])},\ninitElement:function(b){if(!b.getContext){b.getContext=X;b.innerHTML=\"\";b.attachEvent(\"onpropertychange\",Z);b.attachEvent(\"onresize\",$);var a=b.attributes;if(a.width&&a.width.specified)b.style.width=a.width.nodeValue+\"px\";else b.width=b.clientWidth;if(a.height&&a.height.specified)b.style.height=a.height.nodeValue+\"px\";else b.height=b.clientHeight}return b}};function Z(b){var a=b.srcElement;switch(b.propertyName){case \"width\":a.style.width=a.attributes.width.nodeValue+\"px\";a.getContext().clearRect();\nbreak;case \"height\":a.style.height=a.attributes.height.nodeValue+\"px\";a.getContext().clearRect();break}}function $(b){var a=b.srcElement;if(a.firstChild){a.firstChild.style.width=a.clientWidth+\"px\";a.firstChild.style.height=a.clientHeight+\"px\"}}M.init();var N=[],B=0;for(;B<16;B++){var C=0;for(;C<16;C++)N[B*16+C]=B.toString(16)+C.toString(16)}function I(){return[[1,0,0],[0,1,0],[0,0,1]]}function y(b,a){var c=I(),d=0;for(;d<3;d++){var f=0;for(;f<3;f++){var h=0,g=0;for(;g<3;g++)h+=b[d][g]*a[g][f];c[d][f]=\nh}}return c}function O(b,a){a.fillStyle=b.fillStyle;a.lineCap=b.lineCap;a.lineJoin=b.lineJoin;a.lineWidth=b.lineWidth;a.miterLimit=b.miterLimit;a.shadowBlur=b.shadowBlur;a.shadowColor=b.shadowColor;a.shadowOffsetX=b.shadowOffsetX;a.shadowOffsetY=b.shadowOffsetY;a.strokeStyle=b.strokeStyle;a.globalAlpha=b.globalAlpha;a.arcScaleX_=b.arcScaleX_;a.arcScaleY_=b.arcScaleY_;a.lineScale_=b.lineScale_}function P(b){var a,c=1;b=String(b);if(b.substring(0,3)==\"rgb\"){var d=b.indexOf(\"(\",3),f=b.indexOf(\")\",d+\n1),h=b.substring(d+1,f).split(\",\");a=\"#\";var g=0;for(;g<3;g++)a+=N[Number(h[g])];if(h.length==4&&b.substr(3,1)==\"a\")c=h[3]}else a=b;return{color:a,alpha:c}}function aa(b){switch(b){case \"butt\":return\"flat\";case \"round\":return\"round\";case \"square\":default:return\"square\"}}function H(b){this.m_=I();this.mStack_=[];this.aStack_=[];this.currentPath_=[];this.fillStyle=this.strokeStyle=\"#000\";this.lineWidth=1;this.lineJoin=\"miter\";this.lineCap=\"butt\";this.miterLimit=k*1;this.globalAlpha=1;this.canvas=b;\nvar a=b.ownerDocument.createElement(\"div\");a.style.width=b.clientWidth+\"px\";a.style.height=b.clientHeight+\"px\";a.style.overflow=\"hidden\";a.style.position=\"absolute\";b.appendChild(a);this.element_=a;this.lineScale_=this.arcScaleY_=this.arcScaleX_=1}var i=H.prototype;i.clearRect=function(){this.element_.innerHTML=\"\"};i.beginPath=function(){this.currentPath_=[]};i.moveTo=function(b,a){var c=this.getCoords_(b,a);this.currentPath_.push({type:\"moveTo\",x:c.x,y:c.y});this.currentX_=c.x;this.currentY_=c.y};\ni.lineTo=function(b,a){var c=this.getCoords_(b,a);this.currentPath_.push({type:\"lineTo\",x:c.x,y:c.y});this.currentX_=c.x;this.currentY_=c.y};i.bezierCurveTo=function(b,a,c,d,f,h){var g=this.getCoords_(f,h),l=this.getCoords_(b,a),e=this.getCoords_(c,d);Q(this,l,e,g)};function Q(b,a,c,d){b.currentPath_.push({type:\"bezierCurveTo\",cp1x:a.x,cp1y:a.y,cp2x:c.x,cp2y:c.y,x:d.x,y:d.y});b.currentX_=d.x;b.currentY_=d.y}i.quadraticCurveTo=function(b,a,c,d){var f=this.getCoords_(b,a),h=this.getCoords_(c,d),g={x:this.currentX_+\n0.6666666666666666*(f.x-this.currentX_),y:this.currentY_+0.6666666666666666*(f.y-this.currentY_)};Q(this,g,{x:g.x+(h.x-this.currentX_)/3,y:g.y+(h.y-this.currentY_)/3},h)};i.arc=function(b,a,c,d,f,h){c*=k;var g=h?\"at\":\"wa\",l=b+G(d)*c-v,e=a+F(d)*c-v,m=b+G(f)*c-v,r=a+F(f)*c-v;if(l==m&&!h)l+=0.125;var n=this.getCoords_(b,a),o=this.getCoords_(l,e),q=this.getCoords_(m,r);this.currentPath_.push({type:g,x:n.x,y:n.y,radius:c,xStart:o.x,yStart:o.y,xEnd:q.x,yEnd:q.y})};i.rect=function(b,a,c,d){this.moveTo(b,\na);this.lineTo(b+c,a);this.lineTo(b+c,a+d);this.lineTo(b,a+d);this.closePath()};i.strokeRect=function(b,a,c,d){var f=this.currentPath_;this.beginPath();this.moveTo(b,a);this.lineTo(b+c,a);this.lineTo(b+c,a+d);this.lineTo(b,a+d);this.closePath();this.stroke();this.currentPath_=f};i.fillRect=function(b,a,c,d){var f=this.currentPath_;this.beginPath();this.moveTo(b,a);this.lineTo(b+c,a);this.lineTo(b+c,a+d);this.lineTo(b,a+d);this.closePath();this.fill();this.currentPath_=f};i.createLinearGradient=function(b,\na,c,d){var f=new D(\"gradient\");f.x0_=b;f.y0_=a;f.x1_=c;f.y1_=d;return f};i.createRadialGradient=function(b,a,c,d,f,h){var g=new D(\"gradientradial\");g.x0_=b;g.y0_=a;g.r0_=c;g.x1_=d;g.y1_=f;g.r1_=h;return g};i.drawImage=function(b){var a,c,d,f,h,g,l,e,m=b.runtimeStyle.width,r=b.runtimeStyle.height;b.runtimeStyle.width=\"auto\";b.runtimeStyle.height=\"auto\";var n=b.width,o=b.height;b.runtimeStyle.width=m;b.runtimeStyle.height=r;if(arguments.length==3){a=arguments[1];c=arguments[2];h=g=0;l=d=n;e=f=o}else if(arguments.length==\n5){a=arguments[1];c=arguments[2];d=arguments[3];f=arguments[4];h=g=0;l=n;e=o}else if(arguments.length==9){h=arguments[1];g=arguments[2];l=arguments[3];e=arguments[4];a=arguments[5];c=arguments[6];d=arguments[7];f=arguments[8]}else throw Error(\"Invalid number of arguments\");var q=this.getCoords_(a,c),t=[];t.push(\" <g_vml_:group\",' coordsize=\"',k*10,\",\",k*10,'\"',' coordorigin=\"0,0\"',' style=\"width:',10,\"px;height:\",10,\"px;position:absolute;\");if(this.m_[0][0]!=1||this.m_[0][1]){var E=[];E.push(\"M11=\",\nthis.m_[0][0],\",\",\"M12=\",this.m_[1][0],\",\",\"M21=\",this.m_[0][1],\",\",\"M22=\",this.m_[1][1],\",\",\"Dx=\",j(q.x/k),\",\",\"Dy=\",j(q.y/k),\"\");var p=q,z=this.getCoords_(a+d,c),w=this.getCoords_(a,c+f),x=this.getCoords_(a+d,c+f);p.x=s.max(p.x,z.x,w.x,x.x);p.y=s.max(p.y,z.y,w.y,x.y);t.push(\"padding:0 \",j(p.x/k),\"px \",j(p.y/k),\"px 0;filter:progid:DXImageTransform.Microsoft.Matrix(\",E.join(\"\"),\", sizingmethod='clip');\")}else t.push(\"top:\",j(q.y/k),\"px;left:\",j(q.x/k),\"px;\");t.push(' \">','<g_vml_:image src=\"',b.src,\n'\"',' style=\"width:',k*d,\"px;\",\" height:\",k*f,'px;\"',' cropleft=\"',h/n,'\"',' croptop=\"',g/o,'\"',' cropright=\"',(n-h-l)/n,'\"',' cropbottom=\"',(o-g-e)/o,'\"',\" />\",\"</g_vml_:group>\");this.element_.insertAdjacentHTML(\"BeforeEnd\",t.join(\"\"))};i.stroke=function(b){var a=[],c=P(b?this.fillStyle:this.strokeStyle),d=c.color,f=c.alpha*this.globalAlpha;a.push(\"<g_vml_:shape\",' filled=\"',!!b,'\"',' style=\"position:absolute;width:',10,\"px;height:\",10,'px;\"',' coordorigin=\"0 0\" coordsize=\"',k*10,\" \",k*10,'\"',' stroked=\"',\n!b,'\"',' path=\"');var h={x:null,y:null},g={x:null,y:null},l=0;for(;l<this.currentPath_.length;l++){var e=this.currentPath_[l];switch(e.type){case \"moveTo\":a.push(\" m \",j(e.x),\",\",j(e.y));break;case \"lineTo\":a.push(\" l \",j(e.x),\",\",j(e.y));break;case \"close\":a.push(\" x \");e=null;break;case \"bezierCurveTo\":a.push(\" c \",j(e.cp1x),\",\",j(e.cp1y),\",\",j(e.cp2x),\",\",j(e.cp2y),\",\",j(e.x),\",\",j(e.y));break;case \"at\":case \"wa\":a.push(\" \",e.type,\" \",j(e.x-this.arcScaleX_*e.radius),\",\",j(e.y-this.arcScaleY_*e.radius),\n\" \",j(e.x+this.arcScaleX_*e.radius),\",\",j(e.y+this.arcScaleY_*e.radius),\" \",j(e.xStart),\",\",j(e.yStart),\" \",j(e.xEnd),\",\",j(e.yEnd));break}if(e){if(h.x==null||e.x<h.x)h.x=e.x;if(g.x==null||e.x>g.x)g.x=e.x;if(h.y==null||e.y<h.y)h.y=e.y;if(g.y==null||e.y>g.y)g.y=e.y}}a.push(' \">');if(b)if(typeof this.fillStyle==\"object\"){var m=this.fillStyle,r=0,n={x:0,y:0},o=0,q=1;if(m.type_==\"gradient\"){var t=m.x1_/this.arcScaleX_,E=m.y1_/this.arcScaleY_,p=this.getCoords_(m.x0_/this.arcScaleX_,m.y0_/this.arcScaleY_),\nz=this.getCoords_(t,E);r=Math.atan2(z.x-p.x,z.y-p.y)*180/Math.PI;if(r<0)r+=360;if(r<1.0E-6)r=0}else{var p=this.getCoords_(m.x0_,m.y0_),w=g.x-h.x,x=g.y-h.y;n={x:(p.x-h.x)/w,y:(p.y-h.y)/x};w/=this.arcScaleX_*k;x/=this.arcScaleY_*k;var R=s.max(w,x);o=2*m.r0_/R;q=2*m.r1_/R-o}var u=m.colors_;u.sort(function(ba,ca){return ba.offset-ca.offset});var J=u.length,da=u[0].color,ea=u[J-1].color,fa=u[0].alpha*this.globalAlpha,ga=u[J-1].alpha*this.globalAlpha,S=[],l=0;for(;l<J;l++){var T=u[l];S.push(T.offset*q+\no+\" \"+T.color)}a.push('<g_vml_:fill type=\"',m.type_,'\"',' method=\"none\" focus=\"100%\"',' color=\"',da,'\"',' color2=\"',ea,'\"',' colors=\"',S.join(\",\"),'\"',' opacity=\"',ga,'\"',' g_o_:opacity2=\"',fa,'\"',' angle=\"',r,'\"',' focusposition=\"',n.x,\",\",n.y,'\" />')}else a.push('<g_vml_:fill color=\"',d,'\" opacity=\"',f,'\" />');else{var K=this.lineScale_*this.lineWidth;if(K<1)f*=K;a.push(\"<g_vml_:stroke\",' opacity=\"',f,'\"',' joinstyle=\"',this.lineJoin,'\"',' miterlimit=\"',this.miterLimit,'\"',' endcap=\"',aa(this.lineCap),\n'\"',' weight=\"',K,'px\"',' color=\"',d,'\" />')}a.push(\"</g_vml_:shape>\");this.element_.insertAdjacentHTML(\"beforeEnd\",a.join(\"\"))};i.fill=function(){this.stroke(true)};i.closePath=function(){this.currentPath_.push({type:\"close\"})};i.getCoords_=function(b,a){var c=this.m_;return{x:k*(b*c[0][0]+a*c[1][0]+c[2][0])-v,y:k*(b*c[0][1]+a*c[1][1]+c[2][1])-v}};i.save=function(){var b={};O(this,b);this.aStack_.push(b);this.mStack_.push(this.m_);this.m_=y(I(),this.m_)};i.restore=function(){O(this.aStack_.pop(),\nthis);this.m_=this.mStack_.pop()};function ha(b){var a=0;for(;a<3;a++){var c=0;for(;c<2;c++)if(!isFinite(b[a][c])||isNaN(b[a][c]))return false}return true}function A(b,a,c){if(!!ha(a)){b.m_=a;if(c)b.lineScale_=W(V(a[0][0]*a[1][1]-a[0][1]*a[1][0]))}}i.translate=function(b,a){A(this,y([[1,0,0],[0,1,0],[b,a,1]],this.m_),false)};i.rotate=function(b){var a=G(b),c=F(b);A(this,y([[a,c,0],[-c,a,0],[0,0,1]],this.m_),false)};i.scale=function(b,a){this.arcScaleX_*=b;this.arcScaleY_*=a;A(this,y([[b,0,0],[0,a,\n0],[0,0,1]],this.m_),true)};i.transform=function(b,a,c,d,f,h){A(this,y([[b,a,0],[c,d,0],[f,h,1]],this.m_),true)};i.setTransform=function(b,a,c,d,f,h){A(this,[[b,a,0],[c,d,0],[f,h,1]],true)};i.clip=function(){};i.arcTo=function(){};i.createPattern=function(){return new U};function D(b){this.type_=b;this.r1_=this.y1_=this.x1_=this.r0_=this.y0_=this.x0_=0;this.colors_=[]}D.prototype.addColorStop=function(b,a){a=P(a);this.colors_.push({offset:b,color:a.color,alpha:a.alpha})};function U(){}G_vmlCanvasManager=\nM;CanvasRenderingContext2D=H;CanvasGradient=D;CanvasPattern=U})();\n"
  },
  {
    "path": "examples/vendors/excanvas/excanvas.js",
    "content": "// Copyright 2006 Google Inc.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//   http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n\n// Known Issues:\n//\n// * Patterns are not implemented.\n// * Radial gradient are not implemented. The VML version of these look very\n//   different from the canvas one.\n// * Clipping paths are not implemented.\n// * Coordsize. The width and height attribute have higher priority than the\n//   width and height style values which isn't correct.\n// * Painting mode isn't implemented.\n// * Canvas width/height should is using content-box by default. IE in\n//   Quirks mode will draw the canvas using border-box. Either change your\n//   doctype to HTML5\n//   (http://www.whatwg.org/specs/web-apps/current-work/#the-doctype)\n//   or use Box Sizing Behavior from WebFX\n//   (http://webfx.eae.net/dhtml/boxsizing/boxsizing.html)\n// * Non uniform scaling does not correctly scale strokes.\n// * Optimize. There is always room for speed improvements.\n\n// Only add this code if we do not already have a canvas implementation\nif (!document.createElement('canvas').getContext) {\n\n(function() {\n\n  // alias some functions to make (compiled) code shorter\n  var m = Math;\n  var mr = m.round;\n  var ms = m.sin;\n  var mc = m.cos;\n  var abs = m.abs;\n  var sqrt = m.sqrt;\n\n  // this is used for sub pixel precision\n  var Z = 10;\n  var Z2 = Z / 2;\n\n  /**\n   * This funtion is assigned to the <canvas> elements as element.getContext().\n   * @this {HTMLElement}\n   * @return {CanvasRenderingContext2D_}\n   */\n  function getContext() {\n    return this.context_ ||\n        (this.context_ = new CanvasRenderingContext2D_(this));\n  }\n\n  var slice = Array.prototype.slice;\n\n  /**\n   * Binds a function to an object. The returned function will always use the\n   * passed in {@code obj} as {@code this}.\n   *\n   * Example:\n   *\n   *   g = bind(f, obj, a, b)\n   *   g(c, d) // will do f.call(obj, a, b, c, d)\n   *\n   * @param {Function} f The function to bind the object to\n   * @param {Object} obj The object that should act as this when the function\n   *     is called\n   * @param {*} var_args Rest arguments that will be used as the initial\n   *     arguments when the function is called\n   * @return {Function} A new function that has bound this\n   */\n  function bind(f, obj, var_args) {\n    var a = slice.call(arguments, 2);\n    return function() {\n      return f.apply(obj, a.concat(slice.call(arguments)));\n    };\n  }\n\n  var G_vmlCanvasManager_ = {\n    init: function(opt_doc) {\n      if (/MSIE/.test(navigator.userAgent) && !window.opera) {\n        var doc = opt_doc || document;\n        // Create a dummy element so that IE will allow canvas elements to be\n        // recognized.\n        doc.createElement('canvas');\n        doc.attachEvent('onreadystatechange', bind(this.init_, this, doc));\n      }\n    },\n\n    init_: function(doc) {\n      // create xmlns\n      if (!doc.namespaces['g_vml_']) {\n        doc.namespaces.add('g_vml_', 'urn:schemas-microsoft-com:vml',\n                           '#default#VML');\n\n      }\n      if (!doc.namespaces['g_o_']) {\n        doc.namespaces.add('g_o_', 'urn:schemas-microsoft-com:office:office',\n                           '#default#VML');\n      }\n\n      // Setup default CSS.  Only add one style sheet per document\n      if (!doc.styleSheets['ex_canvas_']) {\n        var ss = doc.createStyleSheet();\n        ss.owningElement.id = 'ex_canvas_';\n        ss.cssText = 'canvas{display:inline-block;overflow:hidden;' +\n            // default size is 300x150 in Gecko and Opera\n            'text-align:left;width:300px;height:150px}' +\n            'g_vml_\\\\:*{behavior:url(#default#VML)}' +\n            'g_o_\\\\:*{behavior:url(#default#VML)}';\n\n      }\n\n      // find all canvas elements\n      var els = doc.getElementsByTagName('canvas');\n      for (var i = 0; i < els.length; i++) {\n        this.initElement(els[i]);\n      }\n    },\n\n    /**\n     * Public initializes a canvas element so that it can be used as canvas\n     * element from now on. This is called automatically before the page is\n     * loaded but if you are creating elements using createElement you need to\n     * make sure this is called on the element.\n     * @param {HTMLElement} el The canvas element to initialize.\n     * @return {HTMLElement} the element that was created.\n     */\n    initElement: function(el) {\n      if (!el.getContext) {\n\n        el.getContext = getContext;\n\n        // Remove fallback content. There is no way to hide text nodes so we\n        // just remove all childNodes. We could hide all elements and remove\n        // text nodes but who really cares about the fallback content.\n        el.innerHTML = '';\n\n        // do not use inline function because that will leak memory\n        el.attachEvent('onpropertychange', onPropertyChange);\n        el.attachEvent('onresize', onResize);\n\n        var attrs = el.attributes;\n        if (attrs.width && attrs.width.specified) {\n          // TODO: use runtimeStyle and coordsize\n          // el.getContext().setWidth_(attrs.width.nodeValue);\n          el.style.width = attrs.width.nodeValue + 'px';\n        } else {\n          el.width = el.clientWidth;\n        }\n        if (attrs.height && attrs.height.specified) {\n          // TODO: use runtimeStyle and coordsize\n          // el.getContext().setHeight_(attrs.height.nodeValue);\n          el.style.height = attrs.height.nodeValue + 'px';\n        } else {\n          el.height = el.clientHeight;\n        }\n        //el.getContext().setCoordsize_()\n      }\n      return el;\n    }\n  };\n\n  function onPropertyChange(e) {\n    var el = e.srcElement;\n\n    switch (e.propertyName) {\n      case 'width':\n        el.style.width = el.attributes.width.nodeValue + 'px';\n        el.getContext().clearRect();\n        break;\n      case 'height':\n        el.style.height = el.attributes.height.nodeValue + 'px';\n        el.getContext().clearRect();\n        break;\n    }\n  }\n\n  function onResize(e) {\n    var el = e.srcElement;\n    if (el.firstChild) {\n      el.firstChild.style.width =  el.clientWidth + 'px';\n      el.firstChild.style.height = el.clientHeight + 'px';\n    }\n  }\n\n  G_vmlCanvasManager_.init();\n\n  // precompute \"00\" to \"FF\"\n  var dec2hex = [];\n  for (var i = 0; i < 16; i++) {\n    for (var j = 0; j < 16; j++) {\n      dec2hex[i * 16 + j] = i.toString(16) + j.toString(16);\n    }\n  }\n\n  function createMatrixIdentity() {\n    return [\n      [1, 0, 0],\n      [0, 1, 0],\n      [0, 0, 1]\n    ];\n  }\n\n  function matrixMultiply(m1, m2) {\n    var result = createMatrixIdentity();\n\n    for (var x = 0; x < 3; x++) {\n      for (var y = 0; y < 3; y++) {\n        var sum = 0;\n\n        for (var z = 0; z < 3; z++) {\n          sum += m1[x][z] * m2[z][y];\n        }\n\n        result[x][y] = sum;\n      }\n    }\n    return result;\n  }\n\n  function copyState(o1, o2) {\n    o2.fillStyle     = o1.fillStyle;\n    o2.lineCap       = o1.lineCap;\n    o2.lineJoin      = o1.lineJoin;\n    o2.lineWidth     = o1.lineWidth;\n    o2.miterLimit    = o1.miterLimit;\n    o2.shadowBlur    = o1.shadowBlur;\n    o2.shadowColor   = o1.shadowColor;\n    o2.shadowOffsetX = o1.shadowOffsetX;\n    o2.shadowOffsetY = o1.shadowOffsetY;\n    o2.strokeStyle   = o1.strokeStyle;\n    o2.globalAlpha   = o1.globalAlpha;\n    o2.arcScaleX_    = o1.arcScaleX_;\n    o2.arcScaleY_    = o1.arcScaleY_;\n    o2.lineScale_    = o1.lineScale_;\n  }\n\n  function processStyle(styleString) {\n    var str, alpha = 1;\n\n    styleString = String(styleString);\n    if (styleString.substring(0, 3) == 'rgb') {\n      var start = styleString.indexOf('(', 3);\n      var end = styleString.indexOf(')', start + 1);\n      var guts = styleString.substring(start + 1, end).split(',');\n\n      str = '#';\n      for (var i = 0; i < 3; i++) {\n        str += dec2hex[Number(guts[i])];\n      }\n\n      if (guts.length == 4 && styleString.substr(3, 1) == 'a') {\n        alpha = guts[3];\n      }\n    } else {\n      str = styleString;\n    }\n\n    return {color: str, alpha: alpha};\n  }\n\n  function processLineCap(lineCap) {\n    switch (lineCap) {\n      case 'butt':\n        return 'flat';\n      case 'round':\n        return 'round';\n      case 'square':\n      default:\n        return 'square';\n    }\n  }\n\n  /**\n   * This class implements CanvasRenderingContext2D interface as described by\n   * the WHATWG.\n   * @param {HTMLElement} surfaceElement The element that the 2D context should\n   * be associated with\n   */\n  function CanvasRenderingContext2D_(surfaceElement) {\n    this.m_ = createMatrixIdentity();\n\n    this.mStack_ = [];\n    this.aStack_ = [];\n    this.currentPath_ = [];\n\n    // Canvas context properties\n    this.strokeStyle = '#000';\n    this.fillStyle = '#000';\n\n    this.lineWidth = 1;\n    this.lineJoin = 'miter';\n    this.lineCap = 'butt';\n    this.miterLimit = Z * 1;\n    this.globalAlpha = 1;\n    this.canvas = surfaceElement;\n\n    var el = surfaceElement.ownerDocument.createElement('div');\n    el.style.width =  surfaceElement.clientWidth + 'px';\n    el.style.height = surfaceElement.clientHeight + 'px';\n    el.style.overflow = 'hidden';\n    el.style.position = 'absolute';\n    surfaceElement.appendChild(el);\n\n    this.element_ = el;\n    this.arcScaleX_ = 1;\n    this.arcScaleY_ = 1;\n    this.lineScale_ = 1;\n  }\n\n  var contextPrototype = CanvasRenderingContext2D_.prototype;\n  contextPrototype.clearRect = function() {\n    this.element_.innerHTML = '';\n  };\n\n  contextPrototype.beginPath = function() {\n    // TODO: Branch current matrix so that save/restore has no effect\n    //       as per safari docs.\n    this.currentPath_ = [];\n  };\n\n  contextPrototype.moveTo = function(aX, aY) {\n    var p = this.getCoords_(aX, aY);\n    this.currentPath_.push({type: 'moveTo', x: p.x, y: p.y});\n    this.currentX_ = p.x;\n    this.currentY_ = p.y;\n  };\n\n  contextPrototype.lineTo = function(aX, aY) {\n    var p = this.getCoords_(aX, aY);\n    this.currentPath_.push({type: 'lineTo', x: p.x, y: p.y});\n\n    this.currentX_ = p.x;\n    this.currentY_ = p.y;\n  };\n\n  contextPrototype.bezierCurveTo = function(aCP1x, aCP1y,\n                                            aCP2x, aCP2y,\n                                            aX, aY) {\n    var p = this.getCoords_(aX, aY);\n    var cp1 = this.getCoords_(aCP1x, aCP1y);\n    var cp2 = this.getCoords_(aCP2x, aCP2y);\n    bezierCurveTo(this, cp1, cp2, p);\n  };\n\n  // Helper function that takes the already fixed cordinates.\n  function bezierCurveTo(self, cp1, cp2, p) {\n    self.currentPath_.push({\n      type: 'bezierCurveTo',\n      cp1x: cp1.x,\n      cp1y: cp1.y,\n      cp2x: cp2.x,\n      cp2y: cp2.y,\n      x: p.x,\n      y: p.y\n    });\n    self.currentX_ = p.x;\n    self.currentY_ = p.y;\n  }\n\n  contextPrototype.quadraticCurveTo = function(aCPx, aCPy, aX, aY) {\n    // the following is lifted almost directly from\n    // http://developer.mozilla.org/en/docs/Canvas_tutorial:Drawing_shapes\n\n    var cp = this.getCoords_(aCPx, aCPy);\n    var p = this.getCoords_(aX, aY);\n\n    var cp1 = {\n      x: this.currentX_ + 2.0 / 3.0 * (cp.x - this.currentX_),\n      y: this.currentY_ + 2.0 / 3.0 * (cp.y - this.currentY_)\n    };\n    var cp2 = {\n      x: cp1.x + (p.x - this.currentX_) / 3.0,\n      y: cp1.y + (p.y - this.currentY_) / 3.0\n    };\n\n    bezierCurveTo(this, cp1, cp2, p);\n  };\n\n  contextPrototype.arc = function(aX, aY, aRadius,\n                                  aStartAngle, aEndAngle, aClockwise) {\n    aRadius *= Z;\n    var arcType = aClockwise ? 'at' : 'wa';\n\n    var xStart = aX + mc(aStartAngle) * aRadius - Z2;\n    var yStart = aY + ms(aStartAngle) * aRadius - Z2;\n\n    var xEnd = aX + mc(aEndAngle) * aRadius - Z2;\n    var yEnd = aY + ms(aEndAngle) * aRadius - Z2;\n\n    // IE won't render arches drawn counter clockwise if xStart == xEnd.\n    if (xStart == xEnd && !aClockwise) {\n      xStart += 0.125; // Offset xStart by 1/80 of a pixel. Use something\n                       // that can be represented in binary\n    }\n\n    var p = this.getCoords_(aX, aY);\n    var pStart = this.getCoords_(xStart, yStart);\n    var pEnd = this.getCoords_(xEnd, yEnd);\n\n    this.currentPath_.push({type: arcType,\n                           x: p.x,\n                           y: p.y,\n                           radius: aRadius,\n                           xStart: pStart.x,\n                           yStart: pStart.y,\n                           xEnd: pEnd.x,\n                           yEnd: pEnd.y});\n\n  };\n\n  contextPrototype.rect = function(aX, aY, aWidth, aHeight) {\n    this.moveTo(aX, aY);\n    this.lineTo(aX + aWidth, aY);\n    this.lineTo(aX + aWidth, aY + aHeight);\n    this.lineTo(aX, aY + aHeight);\n    this.closePath();\n  };\n\n  contextPrototype.strokeRect = function(aX, aY, aWidth, aHeight) {\n    var oldPath = this.currentPath_;\n    this.beginPath();\n\n    this.moveTo(aX, aY);\n    this.lineTo(aX + aWidth, aY);\n    this.lineTo(aX + aWidth, aY + aHeight);\n    this.lineTo(aX, aY + aHeight);\n    this.closePath();\n    this.stroke();\n\n    this.currentPath_ = oldPath;\n  };\n\n  contextPrototype.fillRect = function(aX, aY, aWidth, aHeight) {\n    var oldPath = this.currentPath_;\n    this.beginPath();\n\n    this.moveTo(aX, aY);\n    this.lineTo(aX + aWidth, aY);\n    this.lineTo(aX + aWidth, aY + aHeight);\n    this.lineTo(aX, aY + aHeight);\n    this.closePath();\n    this.fill();\n\n    this.currentPath_ = oldPath;\n  };\n\n  contextPrototype.createLinearGradient = function(aX0, aY0, aX1, aY1) {\n    var gradient = new CanvasGradient_('gradient');\n    gradient.x0_ = aX0;\n    gradient.y0_ = aY0;\n    gradient.x1_ = aX1;\n    gradient.y1_ = aY1;\n    return gradient;\n  };\n\n  contextPrototype.createRadialGradient = function(aX0, aY0, aR0,\n                                                   aX1, aY1, aR1) {\n    var gradient = new CanvasGradient_('gradientradial');\n    gradient.x0_ = aX0;\n    gradient.y0_ = aY0;\n    gradient.r0_ = aR0;\n    gradient.x1_ = aX1;\n    gradient.y1_ = aY1;\n    gradient.r1_ = aR1;\n    return gradient;\n  };\n\n  contextPrototype.drawImage = function(image, var_args) {\n    var dx, dy, dw, dh, sx, sy, sw, sh;\n\n    // to find the original width we overide the width and height\n    var oldRuntimeWidth = image.runtimeStyle.width;\n    var oldRuntimeHeight = image.runtimeStyle.height;\n    image.runtimeStyle.width = 'auto';\n    image.runtimeStyle.height = 'auto';\n\n    // get the original size\n    var w = image.width;\n    var h = image.height;\n\n    // and remove overides\n    image.runtimeStyle.width = oldRuntimeWidth;\n    image.runtimeStyle.height = oldRuntimeHeight;\n\n    if (arguments.length == 3) {\n      dx = arguments[1];\n      dy = arguments[2];\n      sx = sy = 0;\n      sw = dw = w;\n      sh = dh = h;\n    } else if (arguments.length == 5) {\n      dx = arguments[1];\n      dy = arguments[2];\n      dw = arguments[3];\n      dh = arguments[4];\n      sx = sy = 0;\n      sw = w;\n      sh = h;\n    } else if (arguments.length == 9) {\n      sx = arguments[1];\n      sy = arguments[2];\n      sw = arguments[3];\n      sh = arguments[4];\n      dx = arguments[5];\n      dy = arguments[6];\n      dw = arguments[7];\n      dh = arguments[8];\n    } else {\n      throw Error('Invalid number of arguments');\n    }\n\n    var d = this.getCoords_(dx, dy);\n\n    var w2 = sw / 2;\n    var h2 = sh / 2;\n\n    var vmlStr = [];\n\n    var W = 10;\n    var H = 10;\n\n    // For some reason that I've now forgotten, using divs didn't work\n    vmlStr.push(' <g_vml_:group',\n                ' coordsize=\"', Z * W, ',', Z * H, '\"',\n                ' coordorigin=\"0,0\"' ,\n                ' style=\"width:', W, 'px;height:', H, 'px;position:absolute;');\n\n    // If filters are necessary (rotation exists), create them\n    // filters are bog-slow, so only create them if abbsolutely necessary\n    // The following check doesn't account for skews (which don't exist\n    // in the canvas spec (yet) anyway.\n\n    if (this.m_[0][0] != 1 || this.m_[0][1]) {\n      var filter = [];\n\n      // Note the 12/21 reversal\n      filter.push('M11=', this.m_[0][0], ',',\n                  'M12=', this.m_[1][0], ',',\n                  'M21=', this.m_[0][1], ',',\n                  'M22=', this.m_[1][1], ',',\n                  'Dx=', mr(d.x / Z), ',',\n                  'Dy=', mr(d.y / Z), '');\n\n      // Bounding box calculation (need to minimize displayed area so that\n      // filters don't waste time on unused pixels.\n      var max = d;\n      var c2 = this.getCoords_(dx + dw, dy);\n      var c3 = this.getCoords_(dx, dy + dh);\n      var c4 = this.getCoords_(dx + dw, dy + dh);\n\n      max.x = m.max(max.x, c2.x, c3.x, c4.x);\n      max.y = m.max(max.y, c2.y, c3.y, c4.y);\n\n      vmlStr.push('padding:0 ', mr(max.x / Z), 'px ', mr(max.y / Z),\n                  'px 0;filter:progid:DXImageTransform.Microsoft.Matrix(',\n                  filter.join(''), \", sizingmethod='clip');\")\n    } else {\n      vmlStr.push('top:', mr(d.y / Z), 'px;left:', mr(d.x / Z), 'px;');\n    }\n\n    vmlStr.push(' \">' ,\n                '<g_vml_:image src=\"', image.src, '\"',\n                ' style=\"width:', Z * dw, 'px;',\n                ' height:', Z * dh, 'px;\"',\n                ' cropleft=\"', sx / w, '\"',\n                ' croptop=\"', sy / h, '\"',\n                ' cropright=\"', (w - sx - sw) / w, '\"',\n                ' cropbottom=\"', (h - sy - sh) / h, '\"',\n                ' />',\n                '</g_vml_:group>');\n\n    this.element_.insertAdjacentHTML('BeforeEnd',\n                                    vmlStr.join(''));\n  };\n\n  contextPrototype.stroke = function(aFill) {\n    var lineStr = [];\n    var lineOpen = false;\n    var a = processStyle(aFill ? this.fillStyle : this.strokeStyle);\n    var color = a.color;\n    var opacity = a.alpha * this.globalAlpha;\n\n    var W = 10;\n    var H = 10;\n\n    lineStr.push('<g_vml_:shape',\n                 ' filled=\"', !!aFill, '\"',\n                 ' style=\"position:absolute;width:', W, 'px;height:', H, 'px;\"',\n                 ' coordorigin=\"0 0\" coordsize=\"', Z * W, ' ', Z * H, '\"',\n                 ' stroked=\"', !aFill, '\"',\n                 ' path=\"');\n\n    var newSeq = false;\n    var min = {x: null, y: null};\n    var max = {x: null, y: null};\n\n    for (var i = 0; i < this.currentPath_.length; i++) {\n      var p = this.currentPath_[i];\n      var c;\n\n      switch (p.type) {\n        case 'moveTo':\n          c = p;\n          lineStr.push(' m ', mr(p.x), ',', mr(p.y));\n          break;\n        case 'lineTo':\n          lineStr.push(' l ', mr(p.x), ',', mr(p.y));\n          break;\n        case 'close':\n          lineStr.push(' x ');\n          p = null;\n          break;\n        case 'bezierCurveTo':\n          lineStr.push(' c ',\n                       mr(p.cp1x), ',', mr(p.cp1y), ',',\n                       mr(p.cp2x), ',', mr(p.cp2y), ',',\n                       mr(p.x), ',', mr(p.y));\n          break;\n        case 'at':\n        case 'wa':\n          lineStr.push(' ', p.type, ' ',\n                       mr(p.x - this.arcScaleX_ * p.radius), ',',\n                       mr(p.y - this.arcScaleY_ * p.radius), ' ',\n                       mr(p.x + this.arcScaleX_ * p.radius), ',',\n                       mr(p.y + this.arcScaleY_ * p.radius), ' ',\n                       mr(p.xStart), ',', mr(p.yStart), ' ',\n                       mr(p.xEnd), ',', mr(p.yEnd));\n          break;\n      }\n\n\n      // TODO: Following is broken for curves due to\n      //       move to proper paths.\n\n      // Figure out dimensions so we can do gradient fills\n      // properly\n      if (p) {\n        if (min.x == null || p.x < min.x) {\n          min.x = p.x;\n        }\n        if (max.x == null || p.x > max.x) {\n          max.x = p.x;\n        }\n        if (min.y == null || p.y < min.y) {\n          min.y = p.y;\n        }\n        if (max.y == null || p.y > max.y) {\n          max.y = p.y;\n        }\n      }\n    }\n    lineStr.push(' \">');\n\n    if (!aFill) {\n      var lineWidth = this.lineScale_ * this.lineWidth;\n\n      // VML cannot correctly render a line if the width is less than 1px.\n      // In that case, we dilute the color to make the line look thinner.\n      if (lineWidth < 1) {\n        opacity *= lineWidth;\n      }\n\n      lineStr.push(\n        '<g_vml_:stroke',\n        ' opacity=\"', opacity, '\"',\n        ' joinstyle=\"', this.lineJoin, '\"',\n        ' miterlimit=\"', this.miterLimit, '\"',\n        ' endcap=\"', processLineCap(this.lineCap), '\"',\n        ' weight=\"', lineWidth, 'px\"',\n        ' color=\"', color, '\" />'\n      );\n    } else if (typeof this.fillStyle == 'object') {\n      var fillStyle = this.fillStyle;\n      var angle = 0;\n      var focus = {x: 0, y: 0};\n\n      // additional offset\n      var shift = 0;\n      // scale factor for offset\n      var expansion = 1;\n\n      if (fillStyle.type_ == 'gradient') {\n        var x0 = fillStyle.x0_ / this.arcScaleX_;\n        var y0 = fillStyle.y0_ / this.arcScaleY_;\n        var x1 = fillStyle.x1_ / this.arcScaleX_;\n        var y1 = fillStyle.y1_ / this.arcScaleY_;\n        var p0 = this.getCoords_(x0, y0);\n        var p1 = this.getCoords_(x1, y1);\n        var dx = p1.x - p0.x;\n        var dy = p1.y - p0.y;\n        angle = Math.atan2(dx, dy) * 180 / Math.PI;\n\n        // The angle should be a non-negative number.\n        if (angle < 0) {\n          angle += 360;\n        }\n\n        // Very small angles produce an unexpected result because they are\n        // converted to a scientific notation string.\n        if (angle < 1e-6) {\n          angle = 0;\n        }\n      } else {\n        var p0 = this.getCoords_(fillStyle.x0_, fillStyle.y0_);\n        var width  = max.x - min.x;\n        var height = max.y - min.y;\n        focus = {\n          x: (p0.x - min.x) / width,\n          y: (p0.y - min.y) / height\n        };\n\n        width  /= this.arcScaleX_ * Z;\n        height /= this.arcScaleY_ * Z;\n        var dimension = m.max(width, height);\n        shift = 2 * fillStyle.r0_ / dimension;\n        expansion = 2 * fillStyle.r1_ / dimension - shift;\n      }\n\n      // We need to sort the color stops in ascending order by offset,\n      // otherwise IE won't interpret it correctly.\n      var stops = fillStyle.colors_;\n      stops.sort(function(cs1, cs2) {\n        return cs1.offset - cs2.offset;\n      });\n\n      var length = stops.length;\n      var color1 = stops[0].color;\n      var color2 = stops[length - 1].color;\n      var opacity1 = stops[0].alpha * this.globalAlpha;\n      var opacity2 = stops[length - 1].alpha * this.globalAlpha;\n\n      var colors = [];\n      for (var i = 0; i < length; i++) {\n        var stop = stops[i];\n        colors.push(stop.offset * expansion + shift + ' ' + stop.color);\n      }\n\n      // When colors attribute is used, the meanings of opacity and o:opacity2\n      // are reversed.\n      lineStr.push('<g_vml_:fill type=\"', fillStyle.type_, '\"',\n                   ' method=\"none\" focus=\"100%\"',\n                   ' color=\"', color1, '\"',\n                   ' color2=\"', color2, '\"',\n                   ' colors=\"', colors.join(','), '\"',\n                   ' opacity=\"', opacity2, '\"',\n                   ' g_o_:opacity2=\"', opacity1, '\"',\n                   ' angle=\"', angle, '\"',\n                   ' focusposition=\"', focus.x, ',', focus.y, '\" />');\n    } else {\n      lineStr.push('<g_vml_:fill color=\"', color, '\" opacity=\"', opacity,\n                   '\" />');\n    }\n\n    lineStr.push('</g_vml_:shape>');\n\n    this.element_.insertAdjacentHTML('beforeEnd', lineStr.join(''));\n  };\n\n  contextPrototype.fill = function() {\n    this.stroke(true);\n  }\n\n  contextPrototype.closePath = function() {\n    this.currentPath_.push({type: 'close'});\n  };\n\n  /**\n   * @private\n   */\n  contextPrototype.getCoords_ = function(aX, aY) {\n    var m = this.m_;\n    return {\n      x: Z * (aX * m[0][0] + aY * m[1][0] + m[2][0]) - Z2,\n      y: Z * (aX * m[0][1] + aY * m[1][1] + m[2][1]) - Z2\n    }\n  };\n\n  contextPrototype.save = function() {\n    var o = {};\n    copyState(this, o);\n    this.aStack_.push(o);\n    this.mStack_.push(this.m_);\n    this.m_ = matrixMultiply(createMatrixIdentity(), this.m_);\n  };\n\n  contextPrototype.restore = function() {\n    copyState(this.aStack_.pop(), this);\n    this.m_ = this.mStack_.pop();\n  };\n\n  function matrixIsFinite(m) {\n    for (var j = 0; j < 3; j++) {\n      for (var k = 0; k < 2; k++) {\n        if (!isFinite(m[j][k]) || isNaN(m[j][k])) {\n          return false;\n        }\n      }\n    }\n    return true;\n  }\n\n  function setM(ctx, m, updateLineScale) {\n    if (!matrixIsFinite(m)) {\n      return;\n    }\n    ctx.m_ = m;\n\n    if (updateLineScale) {\n      // Get the line scale.\n      // Determinant of this.m_ means how much the area is enlarged by the\n      // transformation. So its square root can be used as a scale factor\n      // for width.\n      var det = m[0][0] * m[1][1] - m[0][1] * m[1][0];\n      ctx.lineScale_ = sqrt(abs(det));\n    }\n  }\n\n  contextPrototype.translate = function(aX, aY) {\n    var m1 = [\n      [1,  0,  0],\n      [0,  1,  0],\n      [aX, aY, 1]\n    ];\n\n    setM(this, matrixMultiply(m1, this.m_), false);\n  };\n\n  contextPrototype.rotate = function(aRot) {\n    var c = mc(aRot);\n    var s = ms(aRot);\n\n    var m1 = [\n      [c,  s, 0],\n      [-s, c, 0],\n      [0,  0, 1]\n    ];\n\n    setM(this, matrixMultiply(m1, this.m_), false);\n  };\n\n  contextPrototype.scale = function(aX, aY) {\n    this.arcScaleX_ *= aX;\n    this.arcScaleY_ *= aY;\n    var m1 = [\n      [aX, 0,  0],\n      [0,  aY, 0],\n      [0,  0,  1]\n    ];\n\n    setM(this, matrixMultiply(m1, this.m_), true);\n  };\n\n  contextPrototype.transform = function(m11, m12, m21, m22, dx, dy) {\n    var m1 = [\n      [m11, m12, 0],\n      [m21, m22, 0],\n      [dx,  dy,  1]\n    ];\n\n    setM(this, matrixMultiply(m1, this.m_), true);\n  };\n\n  contextPrototype.setTransform = function(m11, m12, m21, m22, dx, dy) {\n    var m = [\n      [m11, m12, 0],\n      [m21, m22, 0],\n      [dx,  dy,  1]\n    ];\n\n    setM(this, m, true);\n  };\n\n  /******** STUBS ********/\n  contextPrototype.clip = function() {\n    // TODO: Implement\n  };\n\n  contextPrototype.arcTo = function() {\n    // TODO: Implement\n  };\n\n  contextPrototype.createPattern = function() {\n    return new CanvasPattern_;\n  };\n\n  // Gradient / Pattern Stubs\n  function CanvasGradient_(aType) {\n    this.type_ = aType;\n    this.x0_ = 0;\n    this.y0_ = 0;\n    this.r0_ = 0;\n    this.x1_ = 0;\n    this.y1_ = 0;\n    this.r1_ = 0;\n    this.colors_ = [];\n  }\n\n  CanvasGradient_.prototype.addColorStop = function(aOffset, aColor) {\n    aColor = processStyle(aColor);\n    this.colors_.push({offset: aOffset,\n                       color: aColor.color,\n                       alpha: aColor.alpha});\n  };\n\n  function CanvasPattern_() {}\n\n  // set up externs\n  G_vmlCanvasManager = G_vmlCanvasManager_;\n  CanvasRenderingContext2D = CanvasRenderingContext2D_;\n  CanvasGradient = CanvasGradient_;\n  CanvasPattern = CanvasPattern_;\n\n})();\n\n} // if\n"
  },
  {
    "path": "helper/to-sjis-browser.js",
    "content": "/* global QRCode */\nQRCode.toSJIS = require('./to-sjis')\n"
  },
  {
    "path": "helper/to-sjis.js",
    "content": "const SJIS_UTF8 = [\n  [0x8140, '　、。，．・：；？！゛゜´｀¨＾￣＿ヽヾゝゞ〃仝々〆〇ー―‐／＼～∥｜…‥‘’“”（）〔〕［］｛｝〈〉《》「」『』【】＋－±×'],\n  [0x8180, '÷＝≠＜＞≦≧∞∴♂♀°′″℃'],\n  [0x818f, '￥＄￠￡％＃＆＊＠§☆★○●◎◇◆□■△▲▽▼'],\n  [0x81a6, '※〒→←↑↓〓'],\n  [0x81b8, '∈∋⊆⊇⊂⊃∪∩'],\n  [0x81c8, '∧∨￢⇒⇔∀∃'],\n  [0x81da, '∠⊥⌒∂∇≡≒≪≫√∽∝∵∫∬'],\n  [0x81f0, 'Å‰♯♭♪†‡¶'],\n  [0x824f, '０１２３４５６７８９'],\n  [0x8260, 'ＡＢＣＤＥＦＧＨＩＪＫＬＭＮＯＰＱＲＳＴＵＶＷＸＹＺ'],\n  [0x8281, 'ａｂｃｄｅｆｇｈｉｊｋｌｍｎｏｐｑｒｓｔｕｖｗｘｙｚ'],\n  [0x829f, 'ぁあぃいぅうぇえぉおかがきぎくぐけげこごさざしじすずせぜそぞただちぢっつづてでとどなにぬねのはばぱひびぴふぶぷへべぺほぼぽまみむめもゃやゅゆょよらりるれろゎわゐゑをん'],\n  [0x8340, 'ァアィイゥウェエォオカガキギクグケゲコゴサザシジスズセゼソゾタダチヂッツヅテデトドナニヌネノハバパヒビピフブプヘベペホボポマミ'],\n  [0x8380, 'ムメモャヤュユョヨラリルレロヮワヰヱヲンヴヵヶ'],\n  [0x839f, 'ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ'],\n  [0x83bf, 'αβγδεζηθικλμνξοπρστυφχψω'],\n  [0x8440, 'АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ'],\n  [0x8470, 'абвгдеёжзийклмн'],\n  [0x8480, 'опрстуфхцчшщъыьэюя'],\n  [0x8780, '〝〟'],\n  [0x889f, '亜唖娃阿哀愛挨姶逢葵茜穐悪握渥旭葦芦鯵梓圧斡扱宛姐虻飴絢綾鮎或粟袷安庵按暗案闇鞍杏以伊位依偉囲夷委威尉惟意慰易椅為畏異移維緯胃萎衣'],\n  [0x88e0, '謂違遺医井亥域育郁磯一壱溢逸稲茨芋鰯允印咽員因姻引飲淫胤蔭'],\n  [0x8940, '院陰隠韻吋右宇烏羽迂雨卯鵜窺丑碓臼渦嘘唄欝蔚鰻姥厩浦瓜閏噂云運雲荏餌叡営嬰影映曳栄永泳洩瑛盈穎頴英衛詠鋭液疫益駅悦謁越閲榎厭円'],\n  [0x8980, '園堰奄宴延怨掩援沿演炎焔煙燕猿縁艶苑薗遠鉛鴛塩於汚甥凹央奥往応押旺横欧殴王翁襖鴬鴎黄岡沖荻億屋憶臆桶牡乙俺卸恩温穏音下化仮何伽価佳加可嘉夏嫁家寡科暇果架歌河火珂禍禾稼箇花苛茄荷華菓蝦課嘩貨迦過霞蚊俄峨我牙画臥芽蛾賀雅餓駕介会解回塊壊廻快怪悔恢懐戒拐改'],\n  [0x8a40, '魁晦械海灰界皆絵芥蟹開階貝凱劾外咳害崖慨概涯碍蓋街該鎧骸浬馨蛙垣柿蛎鈎劃嚇各廓拡撹格核殻獲確穫覚角赫較郭閣隔革学岳楽額顎掛笠樫'],\n  [0x8a80, '橿梶鰍潟割喝恰括活渇滑葛褐轄且鰹叶椛樺鞄株兜竃蒲釜鎌噛鴨栢茅萱粥刈苅瓦乾侃冠寒刊勘勧巻喚堪姦完官寛干幹患感慣憾換敢柑桓棺款歓汗漢澗潅環甘監看竿管簡緩缶翰肝艦莞観諌貫還鑑間閑関陥韓館舘丸含岸巌玩癌眼岩翫贋雁頑顔願企伎危喜器基奇嬉寄岐希幾忌揮机旗既期棋棄'],\n  [0x8b40, '機帰毅気汽畿祈季稀紀徽規記貴起軌輝飢騎鬼亀偽儀妓宜戯技擬欺犠疑祇義蟻誼議掬菊鞠吉吃喫桔橘詰砧杵黍却客脚虐逆丘久仇休及吸宮弓急救'],\n  [0x8b80, '朽求汲泣灸球究窮笈級糾給旧牛去居巨拒拠挙渠虚許距鋸漁禦魚亨享京供侠僑兇競共凶協匡卿叫喬境峡強彊怯恐恭挟教橋況狂狭矯胸脅興蕎郷鏡響饗驚仰凝尭暁業局曲極玉桐粁僅勤均巾錦斤欣欽琴禁禽筋緊芹菌衿襟謹近金吟銀九倶句区狗玖矩苦躯駆駈駒具愚虞喰空偶寓遇隅串櫛釧屑屈'],\n  [0x8c40, '掘窟沓靴轡窪熊隈粂栗繰桑鍬勲君薫訓群軍郡卦袈祁係傾刑兄啓圭珪型契形径恵慶慧憩掲携敬景桂渓畦稽系経継繋罫茎荊蛍計詣警軽頚鶏芸迎鯨'],\n  [0x8c80, '劇戟撃激隙桁傑欠決潔穴結血訣月件倹倦健兼券剣喧圏堅嫌建憲懸拳捲検権牽犬献研硯絹県肩見謙賢軒遣鍵険顕験鹸元原厳幻弦減源玄現絃舷言諺限乎個古呼固姑孤己庫弧戸故枯湖狐糊袴股胡菰虎誇跨鈷雇顧鼓五互伍午呉吾娯後御悟梧檎瑚碁語誤護醐乞鯉交佼侯候倖光公功効勾厚口向'],\n  [0x8d40, '后喉坑垢好孔孝宏工巧巷幸広庚康弘恒慌抗拘控攻昂晃更杭校梗構江洪浩港溝甲皇硬稿糠紅紘絞綱耕考肯肱腔膏航荒行衡講貢購郊酵鉱砿鋼閤降'],\n  [0x8d80, '項香高鴻剛劫号合壕拷濠豪轟麹克刻告国穀酷鵠黒獄漉腰甑忽惚骨狛込此頃今困坤墾婚恨懇昏昆根梱混痕紺艮魂些佐叉唆嵯左差査沙瑳砂詐鎖裟坐座挫債催再最哉塞妻宰彩才採栽歳済災采犀砕砦祭斎細菜裁載際剤在材罪財冴坂阪堺榊肴咲崎埼碕鷺作削咋搾昨朔柵窄策索錯桜鮭笹匙冊刷'],\n  [0x8e40, '察拶撮擦札殺薩雑皐鯖捌錆鮫皿晒三傘参山惨撒散桟燦珊産算纂蚕讃賛酸餐斬暫残仕仔伺使刺司史嗣四士始姉姿子屍市師志思指支孜斯施旨枝止'],\n  [0x8e80, '死氏獅祉私糸紙紫肢脂至視詞詩試誌諮資賜雌飼歯事似侍児字寺慈持時次滋治爾璽痔磁示而耳自蒔辞汐鹿式識鴫竺軸宍雫七叱執失嫉室悉湿漆疾質実蔀篠偲柴芝屡蕊縞舎写射捨赦斜煮社紗者謝車遮蛇邪借勺尺杓灼爵酌釈錫若寂弱惹主取守手朱殊狩珠種腫趣酒首儒受呪寿授樹綬需囚収周'],\n  [0x8f40, '宗就州修愁拾洲秀秋終繍習臭舟蒐衆襲讐蹴輯週酋酬集醜什住充十従戎柔汁渋獣縦重銃叔夙宿淑祝縮粛塾熟出術述俊峻春瞬竣舜駿准循旬楯殉淳'],\n  [0x8f80, '準潤盾純巡遵醇順処初所暑曙渚庶緒署書薯藷諸助叙女序徐恕鋤除傷償勝匠升召哨商唱嘗奨妾娼宵将小少尚庄床廠彰承抄招掌捷昇昌昭晶松梢樟樵沼消渉湘焼焦照症省硝礁祥称章笑粧紹肖菖蒋蕉衝裳訟証詔詳象賞醤鉦鍾鐘障鞘上丈丞乗冗剰城場壌嬢常情擾条杖浄状畳穣蒸譲醸錠嘱埴飾'],\n  [0x9040, '拭植殖燭織職色触食蝕辱尻伸信侵唇娠寝審心慎振新晋森榛浸深申疹真神秦紳臣芯薪親診身辛進針震人仁刃塵壬尋甚尽腎訊迅陣靭笥諏須酢図厨'],\n  [0x9080, '逗吹垂帥推水炊睡粋翠衰遂酔錐錘随瑞髄崇嵩数枢趨雛据杉椙菅頗雀裾澄摺寸世瀬畝是凄制勢姓征性成政整星晴棲栖正清牲生盛精聖声製西誠誓請逝醒青静斉税脆隻席惜戚斥昔析石積籍績脊責赤跡蹟碩切拙接摂折設窃節説雪絶舌蝉仙先千占宣専尖川戦扇撰栓栴泉浅洗染潜煎煽旋穿箭線'],\n  [0x9140, '繊羨腺舛船薦詮賎践選遷銭銑閃鮮前善漸然全禅繕膳糎噌塑岨措曾曽楚狙疏疎礎祖租粗素組蘇訴阻遡鼠僧創双叢倉喪壮奏爽宋層匝惣想捜掃挿掻'],\n  [0x9180, '操早曹巣槍槽漕燥争痩相窓糟総綜聡草荘葬蒼藻装走送遭鎗霜騒像増憎臓蔵贈造促側則即息捉束測足速俗属賊族続卒袖其揃存孫尊損村遜他多太汰詑唾堕妥惰打柁舵楕陀駄騨体堆対耐岱帯待怠態戴替泰滞胎腿苔袋貸退逮隊黛鯛代台大第醍題鷹滝瀧卓啄宅托択拓沢濯琢託鐸濁諾茸凧蛸只'],\n  [0x9240, '叩但達辰奪脱巽竪辿棚谷狸鱈樽誰丹単嘆坦担探旦歎淡湛炭短端箪綻耽胆蛋誕鍛団壇弾断暖檀段男談値知地弛恥智池痴稚置致蜘遅馳築畜竹筑蓄'],\n  [0x9280, '逐秩窒茶嫡着中仲宙忠抽昼柱注虫衷註酎鋳駐樗瀦猪苧著貯丁兆凋喋寵帖帳庁弔張彫徴懲挑暢朝潮牒町眺聴脹腸蝶調諜超跳銚長頂鳥勅捗直朕沈珍賃鎮陳津墜椎槌追鎚痛通塚栂掴槻佃漬柘辻蔦綴鍔椿潰坪壷嬬紬爪吊釣鶴亭低停偵剃貞呈堤定帝底庭廷弟悌抵挺提梯汀碇禎程締艇訂諦蹄逓'],\n  [0x9340, '邸鄭釘鼎泥摘擢敵滴的笛適鏑溺哲徹撤轍迭鉄典填天展店添纏甜貼転顛点伝殿澱田電兎吐堵塗妬屠徒斗杜渡登菟賭途都鍍砥砺努度土奴怒倒党冬'],\n  [0x9380, '凍刀唐塔塘套宕島嶋悼投搭東桃梼棟盗淘湯涛灯燈当痘祷等答筒糖統到董蕩藤討謄豆踏逃透鐙陶頭騰闘働動同堂導憧撞洞瞳童胴萄道銅峠鴇匿得徳涜特督禿篤毒独読栃橡凸突椴届鳶苫寅酉瀞噸屯惇敦沌豚遁頓呑曇鈍奈那内乍凪薙謎灘捺鍋楢馴縄畷南楠軟難汝二尼弐迩匂賑肉虹廿日乳入'],\n  [0x9440, '如尿韮任妊忍認濡禰祢寧葱猫熱年念捻撚燃粘乃廼之埜嚢悩濃納能脳膿農覗蚤巴把播覇杷波派琶破婆罵芭馬俳廃拝排敗杯盃牌背肺輩配倍培媒梅'],\n  [0x9480, '楳煤狽買売賠陪這蝿秤矧萩伯剥博拍柏泊白箔粕舶薄迫曝漠爆縛莫駁麦函箱硲箸肇筈櫨幡肌畑畠八鉢溌発醗髪伐罰抜筏閥鳩噺塙蛤隼伴判半反叛帆搬斑板氾汎版犯班畔繁般藩販範釆煩頒飯挽晩番盤磐蕃蛮匪卑否妃庇彼悲扉批披斐比泌疲皮碑秘緋罷肥被誹費避非飛樋簸備尾微枇毘琵眉美'],\n  [0x9540, '鼻柊稗匹疋髭彦膝菱肘弼必畢筆逼桧姫媛紐百謬俵彪標氷漂瓢票表評豹廟描病秒苗錨鋲蒜蛭鰭品彬斌浜瀕貧賓頻敏瓶不付埠夫婦富冨布府怖扶敷'],\n  [0x9580, '斧普浮父符腐膚芙譜負賦赴阜附侮撫武舞葡蕪部封楓風葺蕗伏副復幅服福腹複覆淵弗払沸仏物鮒分吻噴墳憤扮焚奮粉糞紛雰文聞丙併兵塀幣平弊柄並蔽閉陛米頁僻壁癖碧別瞥蔑箆偏変片篇編辺返遍便勉娩弁鞭保舗鋪圃捕歩甫補輔穂募墓慕戊暮母簿菩倣俸包呆報奉宝峰峯崩庖抱捧放方朋'],\n  [0x9640, '法泡烹砲縫胞芳萌蓬蜂褒訪豊邦鋒飽鳳鵬乏亡傍剖坊妨帽忘忙房暴望某棒冒紡肪膨謀貌貿鉾防吠頬北僕卜墨撲朴牧睦穆釦勃没殆堀幌奔本翻凡盆'],\n  [0x9680, '摩磨魔麻埋妹昧枚毎哩槙幕膜枕鮪柾鱒桝亦俣又抹末沫迄侭繭麿万慢満漫蔓味未魅巳箕岬密蜜湊蓑稔脈妙粍民眠務夢無牟矛霧鵡椋婿娘冥名命明盟迷銘鳴姪牝滅免棉綿緬面麺摸模茂妄孟毛猛盲網耗蒙儲木黙目杢勿餅尤戻籾貰問悶紋門匁也冶夜爺耶野弥矢厄役約薬訳躍靖柳薮鑓愉愈油癒'],\n  [0x9740, '諭輸唯佑優勇友宥幽悠憂揖有柚湧涌猶猷由祐裕誘遊邑郵雄融夕予余与誉輿預傭幼妖容庸揚揺擁曜楊様洋溶熔用窯羊耀葉蓉要謡踊遥陽養慾抑欲'],\n  [0x9780, '沃浴翌翼淀羅螺裸来莱頼雷洛絡落酪乱卵嵐欄濫藍蘭覧利吏履李梨理璃痢裏裡里離陸律率立葎掠略劉流溜琉留硫粒隆竜龍侶慮旅虜了亮僚両凌寮料梁涼猟療瞭稜糧良諒遼量陵領力緑倫厘林淋燐琳臨輪隣鱗麟瑠塁涙累類令伶例冷励嶺怜玲礼苓鈴隷零霊麗齢暦歴列劣烈裂廉恋憐漣煉簾練聯'],\n  [0x9840, '蓮連錬呂魯櫓炉賂路露労婁廊弄朗楼榔浪漏牢狼篭老聾蝋郎六麓禄肋録論倭和話歪賄脇惑枠鷲亙亘鰐詫藁蕨椀湾碗腕'],\n  [0x989f, '弌丐丕个丱丶丼丿乂乖乘亂亅豫亊舒弍于亞亟亠亢亰亳亶从仍仄仆仂仗仞仭仟价伉佚估佛佝佗佇佶侈侏侘佻佩佰侑佯來侖儘俔俟俎俘俛俑俚俐俤俥倚倨倔倪倥倅伜俶倡倩倬俾俯們倆偃假會偕偐偈做偖偬偸傀傚傅傴傲'],\n  [0x9940, '僉僊傳僂僖僞僥僭僣僮價僵儉儁儂儖儕儔儚儡儺儷儼儻儿兀兒兌兔兢竸兩兪兮冀冂囘册冉冏冑冓冕冖冤冦冢冩冪冫决冱冲冰况冽凅凉凛几處凩凭'],\n  [0x9980, '凰凵凾刄刋刔刎刧刪刮刳刹剏剄剋剌剞剔剪剴剩剳剿剽劍劔劒剱劈劑辨辧劬劭劼劵勁勍勗勞勣勦飭勠勳勵勸勹匆匈甸匍匐匏匕匚匣匯匱匳匸區卆卅丗卉卍凖卞卩卮夘卻卷厂厖厠厦厥厮厰厶參簒雙叟曼燮叮叨叭叺吁吽呀听吭吼吮吶吩吝呎咏呵咎呟呱呷呰咒呻咀呶咄咐咆哇咢咸咥咬哄哈咨'],\n  [0x9a40, '咫哂咤咾咼哘哥哦唏唔哽哮哭哺哢唹啀啣啌售啜啅啖啗唸唳啝喙喀咯喊喟啻啾喘喞單啼喃喩喇喨嗚嗅嗟嗄嗜嗤嗔嘔嗷嘖嗾嗽嘛嗹噎噐營嘴嘶嘲嘸'],\n  [0x9a80, '噫噤嘯噬噪嚆嚀嚊嚠嚔嚏嚥嚮嚶嚴囂嚼囁囃囀囈囎囑囓囗囮囹圀囿圄圉圈國圍圓團圖嗇圜圦圷圸坎圻址坏坩埀垈坡坿垉垓垠垳垤垪垰埃埆埔埒埓堊埖埣堋堙堝塲堡塢塋塰毀塒堽塹墅墹墟墫墺壞墻墸墮壅壓壑壗壙壘壥壜壤壟壯壺壹壻壼壽夂夊夐夛梦夥夬夭夲夸夾竒奕奐奎奚奘奢奠奧奬奩'],\n  [0x9b40, '奸妁妝佞侫妣妲姆姨姜妍姙姚娥娟娑娜娉娚婀婬婉娵娶婢婪媚媼媾嫋嫂媽嫣嫗嫦嫩嫖嫺嫻嬌嬋嬖嬲嫐嬪嬶嬾孃孅孀孑孕孚孛孥孩孰孳孵學斈孺宀'],\n  [0x9b80, '它宦宸寃寇寉寔寐寤實寢寞寥寫寰寶寳尅將專對尓尠尢尨尸尹屁屆屎屓屐屏孱屬屮乢屶屹岌岑岔妛岫岻岶岼岷峅岾峇峙峩峽峺峭嶌峪崋崕崗嵜崟崛崑崔崢崚崙崘嵌嵒嵎嵋嵬嵳嵶嶇嶄嶂嶢嶝嶬嶮嶽嶐嶷嶼巉巍巓巒巖巛巫已巵帋帚帙帑帛帶帷幄幃幀幎幗幔幟幢幤幇幵并幺麼广庠廁廂廈廐廏'],\n  [0x9c40, '廖廣廝廚廛廢廡廨廩廬廱廳廰廴廸廾弃弉彝彜弋弑弖弩弭弸彁彈彌彎弯彑彖彗彙彡彭彳彷徃徂彿徊很徑徇從徙徘徠徨徭徼忖忻忤忸忱忝悳忿怡恠'],\n  [0x9c80, '怙怐怩怎怱怛怕怫怦怏怺恚恁恪恷恟恊恆恍恣恃恤恂恬恫恙悁悍惧悃悚悄悛悖悗悒悧悋惡悸惠惓悴忰悽惆悵惘慍愕愆惶惷愀惴惺愃愡惻惱愍愎慇愾愨愧慊愿愼愬愴愽慂慄慳慷慘慙慚慫慴慯慥慱慟慝慓慵憙憖憇憬憔憚憊憑憫憮懌懊應懷懈懃懆憺懋罹懍懦懣懶懺懴懿懽懼懾戀戈戉戍戌戔戛'],\n  [0x9d40, '戞戡截戮戰戲戳扁扎扞扣扛扠扨扼抂抉找抒抓抖拔抃抔拗拑抻拏拿拆擔拈拜拌拊拂拇抛拉挌拮拱挧挂挈拯拵捐挾捍搜捏掖掎掀掫捶掣掏掉掟掵捫'],\n  [0x9d80, '捩掾揩揀揆揣揉插揶揄搖搴搆搓搦搶攝搗搨搏摧摯摶摎攪撕撓撥撩撈撼據擒擅擇撻擘擂擱擧舉擠擡抬擣擯攬擶擴擲擺攀擽攘攜攅攤攣攫攴攵攷收攸畋效敖敕敍敘敞敝敲數斂斃變斛斟斫斷旃旆旁旄旌旒旛旙无旡旱杲昊昃旻杳昵昶昴昜晏晄晉晁晞晝晤晧晨晟晢晰暃暈暎暉暄暘暝曁暹曉暾暼'],\n  [0x9e40, '曄暸曖曚曠昿曦曩曰曵曷朏朖朞朦朧霸朮朿朶杁朸朷杆杞杠杙杣杤枉杰枩杼杪枌枋枦枡枅枷柯枴柬枳柩枸柤柞柝柢柮枹柎柆柧檜栞框栩桀桍栲桎'],\n  [0x9e80, '梳栫桙档桷桿梟梏梭梔條梛梃檮梹桴梵梠梺椏梍桾椁棊椈棘椢椦棡椌棍棔棧棕椶椒椄棗棣椥棹棠棯椨椪椚椣椡棆楹楷楜楸楫楔楾楮椹楴椽楙椰楡楞楝榁楪榲榮槐榿槁槓榾槎寨槊槝榻槃榧樮榑榠榜榕榴槞槨樂樛槿權槹槲槧樅榱樞槭樔槫樊樒櫁樣樓橄樌橲樶橸橇橢橙橦橈樸樢檐檍檠檄檢檣'],\n  [0x9f40, '檗蘗檻櫃櫂檸檳檬櫞櫑櫟檪櫚櫪櫻欅蘖櫺欒欖鬱欟欸欷盜欹飮歇歃歉歐歙歔歛歟歡歸歹歿殀殄殃殍殘殕殞殤殪殫殯殲殱殳殷殼毆毋毓毟毬毫毳毯'],\n  [0x9f80, '麾氈氓气氛氤氣汞汕汢汪沂沍沚沁沛汾汨汳沒沐泄泱泓沽泗泅泝沮沱沾沺泛泯泙泪洟衍洶洫洽洸洙洵洳洒洌浣涓浤浚浹浙涎涕濤涅淹渕渊涵淇淦涸淆淬淞淌淨淒淅淺淙淤淕淪淮渭湮渮渙湲湟渾渣湫渫湶湍渟湃渺湎渤滿渝游溂溪溘滉溷滓溽溯滄溲滔滕溏溥滂溟潁漑灌滬滸滾漿滲漱滯漲滌'],\n  [0xe040, '漾漓滷澆潺潸澁澀潯潛濳潭澂潼潘澎澑濂潦澳澣澡澤澹濆澪濟濕濬濔濘濱濮濛瀉瀋濺瀑瀁瀏濾瀛瀚潴瀝瀘瀟瀰瀾瀲灑灣炙炒炯烱炬炸炳炮烟烋烝'],\n  [0xe080, '烙焉烽焜焙煥煕熈煦煢煌煖煬熏燻熄熕熨熬燗熹熾燒燉燔燎燠燬燧燵燼燹燿爍爐爛爨爭爬爰爲爻爼爿牀牆牋牘牴牾犂犁犇犒犖犢犧犹犲狃狆狄狎狒狢狠狡狹狷倏猗猊猜猖猝猴猯猩猥猾獎獏默獗獪獨獰獸獵獻獺珈玳珎玻珀珥珮珞璢琅瑯琥珸琲琺瑕琿瑟瑙瑁瑜瑩瑰瑣瑪瑶瑾璋璞璧瓊瓏瓔珱'],\n  [0xe140, '瓠瓣瓧瓩瓮瓲瓰瓱瓸瓷甄甃甅甌甎甍甕甓甞甦甬甼畄畍畊畉畛畆畚畩畤畧畫畭畸當疆疇畴疊疉疂疔疚疝疥疣痂疳痃疵疽疸疼疱痍痊痒痙痣痞痾痿'],\n  [0xe180, '痼瘁痰痺痲痳瘋瘍瘉瘟瘧瘠瘡瘢瘤瘴瘰瘻癇癈癆癜癘癡癢癨癩癪癧癬癰癲癶癸發皀皃皈皋皎皖皓皙皚皰皴皸皹皺盂盍盖盒盞盡盥盧盪蘯盻眈眇眄眩眤眞眥眦眛眷眸睇睚睨睫睛睥睿睾睹瞎瞋瞑瞠瞞瞰瞶瞹瞿瞼瞽瞻矇矍矗矚矜矣矮矼砌砒礦砠礪硅碎硴碆硼碚碌碣碵碪碯磑磆磋磔碾碼磅磊磬'],\n  [0xe240, '磧磚磽磴礇礒礑礙礬礫祀祠祗祟祚祕祓祺祿禊禝禧齋禪禮禳禹禺秉秕秧秬秡秣稈稍稘稙稠稟禀稱稻稾稷穃穗穉穡穢穩龝穰穹穽窈窗窕窘窖窩竈窰'],\n  [0xe280, '窶竅竄窿邃竇竊竍竏竕竓站竚竝竡竢竦竭竰笂笏笊笆笳笘笙笞笵笨笶筐筺笄筍笋筌筅筵筥筴筧筰筱筬筮箝箘箟箍箜箚箋箒箏筝箙篋篁篌篏箴篆篝篩簑簔篦篥籠簀簇簓篳篷簗簍篶簣簧簪簟簷簫簽籌籃籔籏籀籐籘籟籤籖籥籬籵粃粐粤粭粢粫粡粨粳粲粱粮粹粽糀糅糂糘糒糜糢鬻糯糲糴糶糺紆'],\n  [0xe340, '紂紜紕紊絅絋紮紲紿紵絆絳絖絎絲絨絮絏絣經綉絛綏絽綛綺綮綣綵緇綽綫總綢綯緜綸綟綰緘緝緤緞緻緲緡縅縊縣縡縒縱縟縉縋縢繆繦縻縵縹繃縷'],\n  [0xe380, '縲縺繧繝繖繞繙繚繹繪繩繼繻纃緕繽辮繿纈纉續纒纐纓纔纖纎纛纜缸缺罅罌罍罎罐网罕罔罘罟罠罨罩罧罸羂羆羃羈羇羌羔羞羝羚羣羯羲羹羮羶羸譱翅翆翊翕翔翡翦翩翳翹飜耆耄耋耒耘耙耜耡耨耿耻聊聆聒聘聚聟聢聨聳聲聰聶聹聽聿肄肆肅肛肓肚肭冐肬胛胥胙胝胄胚胖脉胯胱脛脩脣脯腋'],\n  [0xe440, '隋腆脾腓腑胼腱腮腥腦腴膃膈膊膀膂膠膕膤膣腟膓膩膰膵膾膸膽臀臂膺臉臍臑臙臘臈臚臟臠臧臺臻臾舁舂舅與舊舍舐舖舩舫舸舳艀艙艘艝艚艟艤'],\n  [0xe480, '艢艨艪艫舮艱艷艸艾芍芒芫芟芻芬苡苣苟苒苴苳苺莓范苻苹苞茆苜茉苙茵茴茖茲茱荀茹荐荅茯茫茗茘莅莚莪莟莢莖茣莎莇莊荼莵荳荵莠莉莨菴萓菫菎菽萃菘萋菁菷萇菠菲萍萢萠莽萸蔆菻葭萪萼蕚蒄葷葫蒭葮蒂葩葆萬葯葹萵蓊葢蒹蒿蒟蓙蓍蒻蓚蓐蓁蓆蓖蒡蔡蓿蓴蔗蔘蔬蔟蔕蔔蓼蕀蕣蕘蕈'],\n  [0xe540, '蕁蘂蕋蕕薀薤薈薑薊薨蕭薔薛藪薇薜蕷蕾薐藉薺藏薹藐藕藝藥藜藹蘊蘓蘋藾藺蘆蘢蘚蘰蘿虍乕虔號虧虱蚓蚣蚩蚪蚋蚌蚶蚯蛄蛆蚰蛉蠣蚫蛔蛞蛩蛬'],\n  [0xe580, '蛟蛛蛯蜒蜆蜈蜀蜃蛻蜑蜉蜍蛹蜊蜴蜿蜷蜻蜥蜩蜚蝠蝟蝸蝌蝎蝴蝗蝨蝮蝙蝓蝣蝪蠅螢螟螂螯蟋螽蟀蟐雖螫蟄螳蟇蟆螻蟯蟲蟠蠏蠍蟾蟶蟷蠎蟒蠑蠖蠕蠢蠡蠱蠶蠹蠧蠻衄衂衒衙衞衢衫袁衾袞衵衽袵衲袂袗袒袮袙袢袍袤袰袿袱裃裄裔裘裙裝裹褂裼裴裨裲褄褌褊褓襃褞褥褪褫襁襄褻褶褸襌褝襠襞'],\n  [0xe640, '襦襤襭襪襯襴襷襾覃覈覊覓覘覡覩覦覬覯覲覺覽覿觀觚觜觝觧觴觸訃訖訐訌訛訝訥訶詁詛詒詆詈詼詭詬詢誅誂誄誨誡誑誥誦誚誣諄諍諂諚諫諳諧'],\n  [0xe680, '諤諱謔諠諢諷諞諛謌謇謚諡謖謐謗謠謳鞫謦謫謾謨譁譌譏譎證譖譛譚譫譟譬譯譴譽讀讌讎讒讓讖讙讚谺豁谿豈豌豎豐豕豢豬豸豺貂貉貅貊貍貎貔豼貘戝貭貪貽貲貳貮貶賈賁賤賣賚賽賺賻贄贅贊贇贏贍贐齎贓賍贔贖赧赭赱赳趁趙跂趾趺跏跚跖跌跛跋跪跫跟跣跼踈踉跿踝踞踐踟蹂踵踰踴蹊'],\n  [0xe740, '蹇蹉蹌蹐蹈蹙蹤蹠踪蹣蹕蹶蹲蹼躁躇躅躄躋躊躓躑躔躙躪躡躬躰軆躱躾軅軈軋軛軣軼軻軫軾輊輅輕輒輙輓輜輟輛輌輦輳輻輹轅轂輾轌轉轆轎轗轜'],\n  [0xe780, '轢轣轤辜辟辣辭辯辷迚迥迢迪迯邇迴逅迹迺逑逕逡逍逞逖逋逧逶逵逹迸遏遐遑遒逎遉逾遖遘遞遨遯遶隨遲邂遽邁邀邊邉邏邨邯邱邵郢郤扈郛鄂鄒鄙鄲鄰酊酖酘酣酥酩酳酲醋醉醂醢醫醯醪醵醴醺釀釁釉釋釐釖釟釡釛釼釵釶鈞釿鈔鈬鈕鈑鉞鉗鉅鉉鉤鉈銕鈿鉋鉐銜銖銓銛鉚鋏銹銷鋩錏鋺鍄錮'],\n  [0xe840, '錙錢錚錣錺錵錻鍜鍠鍼鍮鍖鎰鎬鎭鎔鎹鏖鏗鏨鏥鏘鏃鏝鏐鏈鏤鐚鐔鐓鐃鐇鐐鐶鐫鐵鐡鐺鑁鑒鑄鑛鑠鑢鑞鑪鈩鑰鑵鑷鑽鑚鑼鑾钁鑿閂閇閊閔閖閘閙'],\n  [0xe880, '閠閨閧閭閼閻閹閾闊濶闃闍闌闕闔闖關闡闥闢阡阨阮阯陂陌陏陋陷陜陞陝陟陦陲陬隍隘隕隗險隧隱隲隰隴隶隸隹雎雋雉雍襍雜霍雕雹霄霆霈霓霎霑霏霖霙霤霪霰霹霽霾靄靆靈靂靉靜靠靤靦靨勒靫靱靹鞅靼鞁靺鞆鞋鞏鞐鞜鞨鞦鞣鞳鞴韃韆韈韋韜韭齏韲竟韶韵頏頌頸頤頡頷頽顆顏顋顫顯顰'],\n  [0xe940, '顱顴顳颪颯颱颶飄飃飆飩飫餃餉餒餔餘餡餝餞餤餠餬餮餽餾饂饉饅饐饋饑饒饌饕馗馘馥馭馮馼駟駛駝駘駑駭駮駱駲駻駸騁騏騅駢騙騫騷驅驂驀驃'],\n  [0xe980, '騾驕驍驛驗驟驢驥驤驩驫驪骭骰骼髀髏髑髓體髞髟髢髣髦髯髫髮髴髱髷髻鬆鬘鬚鬟鬢鬣鬥鬧鬨鬩鬪鬮鬯鬲魄魃魏魍魎魑魘魴鮓鮃鮑鮖鮗鮟鮠鮨鮴鯀鯊鮹鯆鯏鯑鯒鯣鯢鯤鯔鯡鰺鯲鯱鯰鰕鰔鰉鰓鰌鰆鰈鰒鰊鰄鰮鰛鰥鰤鰡鰰鱇鰲鱆鰾鱚鱠鱧鱶鱸鳧鳬鳰鴉鴈鳫鴃鴆鴪鴦鶯鴣鴟鵄鴕鴒鵁鴿鴾鵆鵈'],\n  [0xea40, '鵝鵞鵤鵑鵐鵙鵲鶉鶇鶫鵯鵺鶚鶤鶩鶲鷄鷁鶻鶸鶺鷆鷏鷂鷙鷓鷸鷦鷭鷯鷽鸚鸛鸞鹵鹹鹽麁麈麋麌麒麕麑麝麥麩麸麪麭靡黌黎黏黐黔黜點黝黠黥黨黯'],\n  [0xea80, '黴黶黷黹黻黼黽鼇鼈皷鼕鼡鼬鼾齊齒齔齣齟齠齡齦齧齬齪齷齲齶龕龜龠堯槇遙瑤凜熙']\n]\n\nmodule.exports = function toSJIS (utf8Char) {\n  if (!utf8Char || utf8Char === '') return\n\n  for (let i = 0; i < SJIS_UTF8.length; i++) {\n    const kanji = SJIS_UTF8[i][1]\n\n    const posIndex = kanji.indexOf(utf8Char)\n    if (posIndex >= 0) {\n      return SJIS_UTF8[i][0] + posIndex\n    }\n  }\n}\n"
  },
  {
    "path": "lib/browser.js",
    "content": "\nconst canPromise = require('./can-promise')\n\nconst QRCode = require('./core/qrcode')\nconst CanvasRenderer = require('./renderer/canvas')\nconst SvgRenderer = require('./renderer/svg-tag.js')\n\nfunction renderCanvas (renderFunc, canvas, text, opts, cb) {\n  const args = [].slice.call(arguments, 1)\n  const argsNum = args.length\n  const isLastArgCb = typeof args[argsNum - 1] === 'function'\n\n  if (!isLastArgCb && !canPromise()) {\n    throw new Error('Callback required as last argument')\n  }\n\n  if (isLastArgCb) {\n    if (argsNum < 2) {\n      throw new Error('Too few arguments provided')\n    }\n\n    if (argsNum === 2) {\n      cb = text\n      text = canvas\n      canvas = opts = undefined\n    } else if (argsNum === 3) {\n      if (canvas.getContext && typeof cb === 'undefined') {\n        cb = opts\n        opts = undefined\n      } else {\n        cb = opts\n        opts = text\n        text = canvas\n        canvas = undefined\n      }\n    }\n  } else {\n    if (argsNum < 1) {\n      throw new Error('Too few arguments provided')\n    }\n\n    if (argsNum === 1) {\n      text = canvas\n      canvas = opts = undefined\n    } else if (argsNum === 2 && !canvas.getContext) {\n      opts = text\n      text = canvas\n      canvas = undefined\n    }\n\n    return new Promise(function (resolve, reject) {\n      try {\n        const data = QRCode.create(text, opts)\n        resolve(renderFunc(data, canvas, opts))\n      } catch (e) {\n        reject(e)\n      }\n    })\n  }\n\n  try {\n    const data = QRCode.create(text, opts)\n    cb(null, renderFunc(data, canvas, opts))\n  } catch (e) {\n    cb(e)\n  }\n}\n\nexports.create = QRCode.create\nexports.toCanvas = renderCanvas.bind(null, CanvasRenderer.render)\nexports.toDataURL = renderCanvas.bind(null, CanvasRenderer.renderToDataURL)\n\n// only svg for now.\nexports.toString = renderCanvas.bind(null, function (data, _, opts) {\n  return SvgRenderer.render(data, opts)\n})\n"
  },
  {
    "path": "lib/can-promise.js",
    "content": "// can-promise has a crash in some versions of react native that dont have\n// standard global objects\n// https://github.com/soldair/node-qrcode/issues/157\n\nmodule.exports = function () {\n  return typeof Promise === 'function' && Promise.prototype && Promise.prototype.then\n}\n"
  },
  {
    "path": "lib/core/alignment-pattern.js",
    "content": "/**\n * Alignment pattern are fixed reference pattern in defined positions\n * in a matrix symbology, which enables the decode software to re-synchronise\n * the coordinate mapping of the image modules in the event of moderate amounts\n * of distortion of the image.\n *\n * Alignment patterns are present only in QR Code symbols of version 2 or larger\n * and their number depends on the symbol version.\n */\n\nconst getSymbolSize = require('./utils').getSymbolSize\n\n/**\n * Calculate the row/column coordinates of the center module of each alignment pattern\n * for the specified QR Code version.\n *\n * The alignment patterns are positioned symmetrically on either side of the diagonal\n * running from the top left corner of the symbol to the bottom right corner.\n *\n * Since positions are simmetrical only half of the coordinates are returned.\n * Each item of the array will represent in turn the x and y coordinate.\n * @see {@link getPositions}\n *\n * @param  {Number} version QR Code version\n * @return {Array}          Array of coordinate\n */\nexports.getRowColCoords = function getRowColCoords (version) {\n  if (version === 1) return []\n\n  const posCount = Math.floor(version / 7) + 2\n  const size = getSymbolSize(version)\n  const intervals = size === 145 ? 26 : Math.ceil((size - 13) / (2 * posCount - 2)) * 2\n  const positions = [size - 7] // Last coord is always (size - 7)\n\n  for (let i = 1; i < posCount - 1; i++) {\n    positions[i] = positions[i - 1] - intervals\n  }\n\n  positions.push(6) // First coord is always 6\n\n  return positions.reverse()\n}\n\n/**\n * Returns an array containing the positions of each alignment pattern.\n * Each array's element represent the center point of the pattern as (x, y) coordinates\n *\n * Coordinates are calculated expanding the row/column coordinates returned by {@link getRowColCoords}\n * and filtering out the items that overlaps with finder pattern\n *\n * @example\n * For a Version 7 symbol {@link getRowColCoords} returns values 6, 22 and 38.\n * The alignment patterns, therefore, are to be centered on (row, column)\n * positions (6,22), (22,6), (22,22), (22,38), (38,22), (38,38).\n * Note that the coordinates (6,6), (6,38), (38,6) are occupied by finder patterns\n * and are not therefore used for alignment patterns.\n *\n * let pos = getPositions(7)\n * // [[6,22], [22,6], [22,22], [22,38], [38,22], [38,38]]\n *\n * @param  {Number} version QR Code version\n * @return {Array}          Array of coordinates\n */\nexports.getPositions = function getPositions (version) {\n  const coords = []\n  const pos = exports.getRowColCoords(version)\n  const posLength = pos.length\n\n  for (let i = 0; i < posLength; i++) {\n    for (let j = 0; j < posLength; j++) {\n      // Skip if position is occupied by finder patterns\n      if ((i === 0 && j === 0) || // top-left\n          (i === 0 && j === posLength - 1) || // bottom-left\n          (i === posLength - 1 && j === 0)) { // top-right\n        continue\n      }\n\n      coords.push([pos[i], pos[j]])\n    }\n  }\n\n  return coords\n}\n"
  },
  {
    "path": "lib/core/alphanumeric-data.js",
    "content": "const Mode = require('./mode')\n\n/**\n * Array of characters available in alphanumeric mode\n *\n * As per QR Code specification, to each character\n * is assigned a value from 0 to 44 which in this case coincides\n * with the array index\n *\n * @type {Array}\n */\nconst ALPHA_NUM_CHARS = [\n  '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',\n  'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',\n  'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',\n  ' ', '$', '%', '*', '+', '-', '.', '/', ':'\n]\n\nfunction AlphanumericData (data) {\n  this.mode = Mode.ALPHANUMERIC\n  this.data = data\n}\n\nAlphanumericData.getBitsLength = function getBitsLength (length) {\n  return 11 * Math.floor(length / 2) + 6 * (length % 2)\n}\n\nAlphanumericData.prototype.getLength = function getLength () {\n  return this.data.length\n}\n\nAlphanumericData.prototype.getBitsLength = function getBitsLength () {\n  return AlphanumericData.getBitsLength(this.data.length)\n}\n\nAlphanumericData.prototype.write = function write (bitBuffer) {\n  let i\n\n  // Input data characters are divided into groups of two characters\n  // and encoded as 11-bit binary codes.\n  for (i = 0; i + 2 <= this.data.length; i += 2) {\n    // The character value of the first character is multiplied by 45\n    let value = ALPHA_NUM_CHARS.indexOf(this.data[i]) * 45\n\n    // The character value of the second digit is added to the product\n    value += ALPHA_NUM_CHARS.indexOf(this.data[i + 1])\n\n    // The sum is then stored as 11-bit binary number\n    bitBuffer.put(value, 11)\n  }\n\n  // If the number of input data characters is not a multiple of two,\n  // the character value of the final character is encoded as a 6-bit binary number.\n  if (this.data.length % 2) {\n    bitBuffer.put(ALPHA_NUM_CHARS.indexOf(this.data[i]), 6)\n  }\n}\n\nmodule.exports = AlphanumericData\n"
  },
  {
    "path": "lib/core/bit-buffer.js",
    "content": "function BitBuffer () {\n  this.buffer = []\n  this.length = 0\n}\n\nBitBuffer.prototype = {\n\n  get: function (index) {\n    const bufIndex = Math.floor(index / 8)\n    return ((this.buffer[bufIndex] >>> (7 - index % 8)) & 1) === 1\n  },\n\n  put: function (num, length) {\n    for (let i = 0; i < length; i++) {\n      this.putBit(((num >>> (length - i - 1)) & 1) === 1)\n    }\n  },\n\n  getLengthInBits: function () {\n    return this.length\n  },\n\n  putBit: function (bit) {\n    const bufIndex = Math.floor(this.length / 8)\n    if (this.buffer.length <= bufIndex) {\n      this.buffer.push(0)\n    }\n\n    if (bit) {\n      this.buffer[bufIndex] |= (0x80 >>> (this.length % 8))\n    }\n\n    this.length++\n  }\n}\n\nmodule.exports = BitBuffer\n"
  },
  {
    "path": "lib/core/bit-matrix.js",
    "content": "/**\n * Helper class to handle QR Code symbol modules\n *\n * @param {Number} size Symbol size\n */\nfunction BitMatrix (size) {\n  if (!size || size < 1) {\n    throw new Error('BitMatrix size must be defined and greater than 0')\n  }\n\n  this.size = size\n  this.data = new Uint8Array(size * size)\n  this.reservedBit = new Uint8Array(size * size)\n}\n\n/**\n * Set bit value at specified location\n * If reserved flag is set, this bit will be ignored during masking process\n *\n * @param {Number}  row\n * @param {Number}  col\n * @param {Boolean} value\n * @param {Boolean} reserved\n */\nBitMatrix.prototype.set = function (row, col, value, reserved) {\n  const index = row * this.size + col\n  this.data[index] = value\n  if (reserved) this.reservedBit[index] = true\n}\n\n/**\n * Returns bit value at specified location\n *\n * @param  {Number}  row\n * @param  {Number}  col\n * @return {Boolean}\n */\nBitMatrix.prototype.get = function (row, col) {\n  return this.data[row * this.size + col]\n}\n\n/**\n * Applies xor operator at specified location\n * (used during masking process)\n *\n * @param {Number}  row\n * @param {Number}  col\n * @param {Boolean} value\n */\nBitMatrix.prototype.xor = function (row, col, value) {\n  this.data[row * this.size + col] ^= value\n}\n\n/**\n * Check if bit at specified location is reserved\n *\n * @param {Number}   row\n * @param {Number}   col\n * @return {Boolean}\n */\nBitMatrix.prototype.isReserved = function (row, col) {\n  return this.reservedBit[row * this.size + col]\n}\n\nmodule.exports = BitMatrix\n"
  },
  {
    "path": "lib/core/byte-data.js",
    "content": "const Mode = require('./mode')\n\nfunction ByteData (data) {\n  this.mode = Mode.BYTE\n  if (typeof (data) === 'string') {\n    this.data = new TextEncoder().encode(data)\n  } else {\n    this.data = new Uint8Array(data)\n  }\n}\n\nByteData.getBitsLength = function getBitsLength (length) {\n  return length * 8\n}\n\nByteData.prototype.getLength = function getLength () {\n  return this.data.length\n}\n\nByteData.prototype.getBitsLength = function getBitsLength () {\n  return ByteData.getBitsLength(this.data.length)\n}\n\nByteData.prototype.write = function (bitBuffer) {\n  for (let i = 0, l = this.data.length; i < l; i++) {\n    bitBuffer.put(this.data[i], 8)\n  }\n}\n\nmodule.exports = ByteData\n"
  },
  {
    "path": "lib/core/error-correction-code.js",
    "content": "const ECLevel = require('./error-correction-level')\r\n\r\nconst EC_BLOCKS_TABLE = [\r\n// L  M  Q  H\r\n  1, 1, 1, 1,\r\n  1, 1, 1, 1,\r\n  1, 1, 2, 2,\r\n  1, 2, 2, 4,\r\n  1, 2, 4, 4,\r\n  2, 4, 4, 4,\r\n  2, 4, 6, 5,\r\n  2, 4, 6, 6,\r\n  2, 5, 8, 8,\r\n  4, 5, 8, 8,\r\n  4, 5, 8, 11,\r\n  4, 8, 10, 11,\r\n  4, 9, 12, 16,\r\n  4, 9, 16, 16,\r\n  6, 10, 12, 18,\r\n  6, 10, 17, 16,\r\n  6, 11, 16, 19,\r\n  6, 13, 18, 21,\r\n  7, 14, 21, 25,\r\n  8, 16, 20, 25,\r\n  8, 17, 23, 25,\r\n  9, 17, 23, 34,\r\n  9, 18, 25, 30,\r\n  10, 20, 27, 32,\r\n  12, 21, 29, 35,\r\n  12, 23, 34, 37,\r\n  12, 25, 34, 40,\r\n  13, 26, 35, 42,\r\n  14, 28, 38, 45,\r\n  15, 29, 40, 48,\r\n  16, 31, 43, 51,\r\n  17, 33, 45, 54,\r\n  18, 35, 48, 57,\r\n  19, 37, 51, 60,\r\n  19, 38, 53, 63,\r\n  20, 40, 56, 66,\r\n  21, 43, 59, 70,\r\n  22, 45, 62, 74,\r\n  24, 47, 65, 77,\r\n  25, 49, 68, 81\r\n]\r\n\r\nconst EC_CODEWORDS_TABLE = [\r\n// L  M  Q  H\r\n  7, 10, 13, 17,\r\n  10, 16, 22, 28,\r\n  15, 26, 36, 44,\r\n  20, 36, 52, 64,\r\n  26, 48, 72, 88,\r\n  36, 64, 96, 112,\r\n  40, 72, 108, 130,\r\n  48, 88, 132, 156,\r\n  60, 110, 160, 192,\r\n  72, 130, 192, 224,\r\n  80, 150, 224, 264,\r\n  96, 176, 260, 308,\r\n  104, 198, 288, 352,\r\n  120, 216, 320, 384,\r\n  132, 240, 360, 432,\r\n  144, 280, 408, 480,\r\n  168, 308, 448, 532,\r\n  180, 338, 504, 588,\r\n  196, 364, 546, 650,\r\n  224, 416, 600, 700,\r\n  224, 442, 644, 750,\r\n  252, 476, 690, 816,\r\n  270, 504, 750, 900,\r\n  300, 560, 810, 960,\r\n  312, 588, 870, 1050,\r\n  336, 644, 952, 1110,\r\n  360, 700, 1020, 1200,\r\n  390, 728, 1050, 1260,\r\n  420, 784, 1140, 1350,\r\n  450, 812, 1200, 1440,\r\n  480, 868, 1290, 1530,\r\n  510, 924, 1350, 1620,\r\n  540, 980, 1440, 1710,\r\n  570, 1036, 1530, 1800,\r\n  570, 1064, 1590, 1890,\r\n  600, 1120, 1680, 1980,\r\n  630, 1204, 1770, 2100,\r\n  660, 1260, 1860, 2220,\r\n  720, 1316, 1950, 2310,\r\n  750, 1372, 2040, 2430\r\n]\r\n\r\n/**\r\n * Returns the number of error correction block that the QR Code should contain\r\n * for the specified version and error correction level.\r\n *\r\n * @param  {Number} version              QR Code version\r\n * @param  {Number} errorCorrectionLevel Error correction level\r\n * @return {Number}                      Number of error correction blocks\r\n */\r\nexports.getBlocksCount = function getBlocksCount (version, errorCorrectionLevel) {\r\n  switch (errorCorrectionLevel) {\r\n    case ECLevel.L:\r\n      return EC_BLOCKS_TABLE[(version - 1) * 4 + 0]\r\n    case ECLevel.M:\r\n      return EC_BLOCKS_TABLE[(version - 1) * 4 + 1]\r\n    case ECLevel.Q:\r\n      return EC_BLOCKS_TABLE[(version - 1) * 4 + 2]\r\n    case ECLevel.H:\r\n      return EC_BLOCKS_TABLE[(version - 1) * 4 + 3]\r\n    default:\r\n      return undefined\r\n  }\r\n}\r\n\r\n/**\r\n * Returns the number of error correction codewords to use for the specified\r\n * version and error correction level.\r\n *\r\n * @param  {Number} version              QR Code version\r\n * @param  {Number} errorCorrectionLevel Error correction level\r\n * @return {Number}                      Number of error correction codewords\r\n */\r\nexports.getTotalCodewordsCount = function getTotalCodewordsCount (version, errorCorrectionLevel) {\r\n  switch (errorCorrectionLevel) {\r\n    case ECLevel.L:\r\n      return EC_CODEWORDS_TABLE[(version - 1) * 4 + 0]\r\n    case ECLevel.M:\r\n      return EC_CODEWORDS_TABLE[(version - 1) * 4 + 1]\r\n    case ECLevel.Q:\r\n      return EC_CODEWORDS_TABLE[(version - 1) * 4 + 2]\r\n    case ECLevel.H:\r\n      return EC_CODEWORDS_TABLE[(version - 1) * 4 + 3]\r\n    default:\r\n      return undefined\r\n  }\r\n}\r\n"
  },
  {
    "path": "lib/core/error-correction-level.js",
    "content": "exports.L = { bit: 1 }\nexports.M = { bit: 0 }\nexports.Q = { bit: 3 }\nexports.H = { bit: 2 }\n\nfunction fromString (string) {\n  if (typeof string !== 'string') {\n    throw new Error('Param is not a string')\n  }\n\n  const lcStr = string.toLowerCase()\n\n  switch (lcStr) {\n    case 'l':\n    case 'low':\n      return exports.L\n\n    case 'm':\n    case 'medium':\n      return exports.M\n\n    case 'q':\n    case 'quartile':\n      return exports.Q\n\n    case 'h':\n    case 'high':\n      return exports.H\n\n    default:\n      throw new Error('Unknown EC Level: ' + string)\n  }\n}\n\nexports.isValid = function isValid (level) {\n  return level && typeof level.bit !== 'undefined' &&\n    level.bit >= 0 && level.bit < 4\n}\n\nexports.from = function from (value, defaultValue) {\n  if (exports.isValid(value)) {\n    return value\n  }\n\n  try {\n    return fromString(value)\n  } catch (e) {\n    return defaultValue\n  }\n}\n"
  },
  {
    "path": "lib/core/finder-pattern.js",
    "content": "const getSymbolSize = require('./utils').getSymbolSize\nconst FINDER_PATTERN_SIZE = 7\n\n/**\n * Returns an array containing the positions of each finder pattern.\n * Each array's element represent the top-left point of the pattern as (x, y) coordinates\n *\n * @param  {Number} version QR Code version\n * @return {Array}          Array of coordinates\n */\nexports.getPositions = function getPositions (version) {\n  const size = getSymbolSize(version)\n\n  return [\n    // top-left\n    [0, 0],\n    // top-right\n    [size - FINDER_PATTERN_SIZE, 0],\n    // bottom-left\n    [0, size - FINDER_PATTERN_SIZE]\n  ]\n}\n"
  },
  {
    "path": "lib/core/format-info.js",
    "content": "const Utils = require('./utils')\n\nconst G15 = (1 << 10) | (1 << 8) | (1 << 5) | (1 << 4) | (1 << 2) | (1 << 1) | (1 << 0)\nconst G15_MASK = (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1)\nconst G15_BCH = Utils.getBCHDigit(G15)\n\n/**\n * Returns format information with relative error correction bits\n *\n * The format information is a 15-bit sequence containing 5 data bits,\n * with 10 error correction bits calculated using the (15, 5) BCH code.\n *\n * @param  {Number} errorCorrectionLevel Error correction level\n * @param  {Number} mask                 Mask pattern\n * @return {Number}                      Encoded format information bits\n */\nexports.getEncodedBits = function getEncodedBits (errorCorrectionLevel, mask) {\n  const data = ((errorCorrectionLevel.bit << 3) | mask)\n  let d = data << 10\n\n  while (Utils.getBCHDigit(d) - G15_BCH >= 0) {\n    d ^= (G15 << (Utils.getBCHDigit(d) - G15_BCH))\n  }\n\n  // xor final data with mask pattern in order to ensure that\n  // no combination of Error Correction Level and data mask pattern\n  // will result in an all-zero data string\n  return ((data << 10) | d) ^ G15_MASK\n}\n"
  },
  {
    "path": "lib/core/galois-field.js",
    "content": "const EXP_TABLE = new Uint8Array(512)\nconst LOG_TABLE = new Uint8Array(256)\n/**\n * Precompute the log and anti-log tables for faster computation later\n *\n * For each possible value in the galois field 2^8, we will pre-compute\n * the logarithm and anti-logarithm (exponential) of this value\n *\n * ref {@link https://en.wikiversity.org/wiki/Reed%E2%80%93Solomon_codes_for_coders#Introduction_to_mathematical_fields}\n */\n;(function initTables () {\n  let x = 1\n  for (let i = 0; i < 255; i++) {\n    EXP_TABLE[i] = x\n    LOG_TABLE[x] = i\n\n    x <<= 1 // multiply by 2\n\n    // The QR code specification says to use byte-wise modulo 100011101 arithmetic.\n    // This means that when a number is 256 or larger, it should be XORed with 0x11D.\n    if (x & 0x100) { // similar to x >= 256, but a lot faster (because 0x100 == 256)\n      x ^= 0x11D\n    }\n  }\n\n  // Optimization: double the size of the anti-log table so that we don't need to mod 255 to\n  // stay inside the bounds (because we will mainly use this table for the multiplication of\n  // two GF numbers, no more).\n  // @see {@link mul}\n  for (let i = 255; i < 512; i++) {\n    EXP_TABLE[i] = EXP_TABLE[i - 255]\n  }\n}())\n\n/**\n * Returns log value of n inside Galois Field\n *\n * @param  {Number} n\n * @return {Number}\n */\nexports.log = function log (n) {\n  if (n < 1) throw new Error('log(' + n + ')')\n  return LOG_TABLE[n]\n}\n\n/**\n * Returns anti-log value of n inside Galois Field\n *\n * @param  {Number} n\n * @return {Number}\n */\nexports.exp = function exp (n) {\n  return EXP_TABLE[n]\n}\n\n/**\n * Multiplies two number inside Galois Field\n *\n * @param  {Number} x\n * @param  {Number} y\n * @return {Number}\n */\nexports.mul = function mul (x, y) {\n  if (x === 0 || y === 0) return 0\n\n  // should be EXP_TABLE[(LOG_TABLE[x] + LOG_TABLE[y]) % 255] if EXP_TABLE wasn't oversized\n  // @see {@link initTables}\n  return EXP_TABLE[LOG_TABLE[x] + LOG_TABLE[y]]\n}\n"
  },
  {
    "path": "lib/core/kanji-data.js",
    "content": "const Mode = require('./mode')\nconst Utils = require('./utils')\n\nfunction KanjiData (data) {\n  this.mode = Mode.KANJI\n  this.data = data\n}\n\nKanjiData.getBitsLength = function getBitsLength (length) {\n  return length * 13\n}\n\nKanjiData.prototype.getLength = function getLength () {\n  return this.data.length\n}\n\nKanjiData.prototype.getBitsLength = function getBitsLength () {\n  return KanjiData.getBitsLength(this.data.length)\n}\n\nKanjiData.prototype.write = function (bitBuffer) {\n  let i\n\n  // In the Shift JIS system, Kanji characters are represented by a two byte combination.\n  // These byte values are shifted from the JIS X 0208 values.\n  // JIS X 0208 gives details of the shift coded representation.\n  for (i = 0; i < this.data.length; i++) {\n    let value = Utils.toSJIS(this.data[i])\n\n    // For characters with Shift JIS values from 0x8140 to 0x9FFC:\n    if (value >= 0x8140 && value <= 0x9FFC) {\n      // Subtract 0x8140 from Shift JIS value\n      value -= 0x8140\n\n    // For characters with Shift JIS values from 0xE040 to 0xEBBF\n    } else if (value >= 0xE040 && value <= 0xEBBF) {\n      // Subtract 0xC140 from Shift JIS value\n      value -= 0xC140\n    } else {\n      throw new Error(\n        'Invalid SJIS character: ' + this.data[i] + '\\n' +\n        'Make sure your charset is UTF-8')\n    }\n\n    // Multiply most significant byte of result by 0xC0\n    // and add least significant byte to product\n    value = (((value >>> 8) & 0xff) * 0xC0) + (value & 0xff)\n\n    // Convert result to a 13-bit binary string\n    bitBuffer.put(value, 13)\n  }\n}\n\nmodule.exports = KanjiData\n"
  },
  {
    "path": "lib/core/mask-pattern.js",
    "content": "/**\n * Data mask pattern reference\n * @type {Object}\n */\nexports.Patterns = {\n  PATTERN000: 0,\n  PATTERN001: 1,\n  PATTERN010: 2,\n  PATTERN011: 3,\n  PATTERN100: 4,\n  PATTERN101: 5,\n  PATTERN110: 6,\n  PATTERN111: 7\n}\n\n/**\n * Weighted penalty scores for the undesirable features\n * @type {Object}\n */\nconst PenaltyScores = {\n  N1: 3,\n  N2: 3,\n  N3: 40,\n  N4: 10\n}\n\n/**\n * Check if mask pattern value is valid\n *\n * @param  {Number}  mask    Mask pattern\n * @return {Boolean}         true if valid, false otherwise\n */\nexports.isValid = function isValid (mask) {\n  return mask != null && mask !== '' && !isNaN(mask) && mask >= 0 && mask <= 7\n}\n\n/**\n * Returns mask pattern from a value.\n * If value is not valid, returns undefined\n *\n * @param  {Number|String} value        Mask pattern value\n * @return {Number}                     Valid mask pattern or undefined\n */\nexports.from = function from (value) {\n  return exports.isValid(value) ? parseInt(value, 10) : undefined\n}\n\n/**\n* Find adjacent modules in row/column with the same color\n* and assign a penalty value.\n*\n* Points: N1 + i\n* i is the amount by which the number of adjacent modules of the same color exceeds 5\n*/\nexports.getPenaltyN1 = function getPenaltyN1 (data) {\n  const size = data.size\n  let points = 0\n  let sameCountCol = 0\n  let sameCountRow = 0\n  let lastCol = null\n  let lastRow = null\n\n  for (let row = 0; row < size; row++) {\n    sameCountCol = sameCountRow = 0\n    lastCol = lastRow = null\n\n    for (let col = 0; col < size; col++) {\n      let module = data.get(row, col)\n      if (module === lastCol) {\n        sameCountCol++\n      } else {\n        if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5)\n        lastCol = module\n        sameCountCol = 1\n      }\n\n      module = data.get(col, row)\n      if (module === lastRow) {\n        sameCountRow++\n      } else {\n        if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5)\n        lastRow = module\n        sameCountRow = 1\n      }\n    }\n\n    if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5)\n    if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5)\n  }\n\n  return points\n}\n\n/**\n * Find 2x2 blocks with the same color and assign a penalty value\n *\n * Points: N2 * (m - 1) * (n - 1)\n */\nexports.getPenaltyN2 = function getPenaltyN2 (data) {\n  const size = data.size\n  let points = 0\n\n  for (let row = 0; row < size - 1; row++) {\n    for (let col = 0; col < size - 1; col++) {\n      const last = data.get(row, col) +\n        data.get(row, col + 1) +\n        data.get(row + 1, col) +\n        data.get(row + 1, col + 1)\n\n      if (last === 4 || last === 0) points++\n    }\n  }\n\n  return points * PenaltyScores.N2\n}\n\n/**\n * Find 1:1:3:1:1 ratio (dark:light:dark:light:dark) pattern in row/column,\n * preceded or followed by light area 4 modules wide\n *\n * Points: N3 * number of pattern found\n */\nexports.getPenaltyN3 = function getPenaltyN3 (data) {\n  const size = data.size\n  let points = 0\n  let bitsCol = 0\n  let bitsRow = 0\n\n  for (let row = 0; row < size; row++) {\n    bitsCol = bitsRow = 0\n    for (let col = 0; col < size; col++) {\n      bitsCol = ((bitsCol << 1) & 0x7FF) | data.get(row, col)\n      if (col >= 10 && (bitsCol === 0x5D0 || bitsCol === 0x05D)) points++\n\n      bitsRow = ((bitsRow << 1) & 0x7FF) | data.get(col, row)\n      if (col >= 10 && (bitsRow === 0x5D0 || bitsRow === 0x05D)) points++\n    }\n  }\n\n  return points * PenaltyScores.N3\n}\n\n/**\n * Calculate proportion of dark modules in entire symbol\n *\n * Points: N4 * k\n *\n * k is the rating of the deviation of the proportion of dark modules\n * in the symbol from 50% in steps of 5%\n */\nexports.getPenaltyN4 = function getPenaltyN4 (data) {\n  let darkCount = 0\n  const modulesCount = data.data.length\n\n  for (let i = 0; i < modulesCount; i++) darkCount += data.data[i]\n\n  const k = Math.abs(Math.ceil((darkCount * 100 / modulesCount) / 5) - 10)\n\n  return k * PenaltyScores.N4\n}\n\n/**\n * Return mask value at given position\n *\n * @param  {Number} maskPattern Pattern reference value\n * @param  {Number} i           Row\n * @param  {Number} j           Column\n * @return {Boolean}            Mask value\n */\nfunction getMaskAt (maskPattern, i, j) {\n  switch (maskPattern) {\n    case exports.Patterns.PATTERN000: return (i + j) % 2 === 0\n    case exports.Patterns.PATTERN001: return i % 2 === 0\n    case exports.Patterns.PATTERN010: return j % 3 === 0\n    case exports.Patterns.PATTERN011: return (i + j) % 3 === 0\n    case exports.Patterns.PATTERN100: return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 === 0\n    case exports.Patterns.PATTERN101: return (i * j) % 2 + (i * j) % 3 === 0\n    case exports.Patterns.PATTERN110: return ((i * j) % 2 + (i * j) % 3) % 2 === 0\n    case exports.Patterns.PATTERN111: return ((i * j) % 3 + (i + j) % 2) % 2 === 0\n\n    default: throw new Error('bad maskPattern:' + maskPattern)\n  }\n}\n\n/**\n * Apply a mask pattern to a BitMatrix\n *\n * @param  {Number}    pattern Pattern reference number\n * @param  {BitMatrix} data    BitMatrix data\n */\nexports.applyMask = function applyMask (pattern, data) {\n  const size = data.size\n\n  for (let col = 0; col < size; col++) {\n    for (let row = 0; row < size; row++) {\n      if (data.isReserved(row, col)) continue\n      data.xor(row, col, getMaskAt(pattern, row, col))\n    }\n  }\n}\n\n/**\n * Returns the best mask pattern for data\n *\n * @param  {BitMatrix} data\n * @return {Number} Mask pattern reference number\n */\nexports.getBestMask = function getBestMask (data, setupFormatFunc) {\n  const numPatterns = Object.keys(exports.Patterns).length\n  let bestPattern = 0\n  let lowerPenalty = Infinity\n\n  for (let p = 0; p < numPatterns; p++) {\n    setupFormatFunc(p)\n    exports.applyMask(p, data)\n\n    // Calculate penalty\n    const penalty =\n      exports.getPenaltyN1(data) +\n      exports.getPenaltyN2(data) +\n      exports.getPenaltyN3(data) +\n      exports.getPenaltyN4(data)\n\n    // Undo previously applied mask\n    exports.applyMask(p, data)\n\n    if (penalty < lowerPenalty) {\n      lowerPenalty = penalty\n      bestPattern = p\n    }\n  }\n\n  return bestPattern\n}\n"
  },
  {
    "path": "lib/core/mode.js",
    "content": "const VersionCheck = require('./version-check')\nconst Regex = require('./regex')\n\n/**\n * Numeric mode encodes data from the decimal digit set (0 - 9)\n * (byte values 30HEX to 39HEX).\n * Normally, 3 data characters are represented by 10 bits.\n *\n * @type {Object}\n */\nexports.NUMERIC = {\n  id: 'Numeric',\n  bit: 1 << 0,\n  ccBits: [10, 12, 14]\n}\n\n/**\n * Alphanumeric mode encodes data from a set of 45 characters,\n * i.e. 10 numeric digits (0 - 9),\n *      26 alphabetic characters (A - Z),\n *   and 9 symbols (SP, $, %, *, +, -, ., /, :).\n * Normally, two input characters are represented by 11 bits.\n *\n * @type {Object}\n */\nexports.ALPHANUMERIC = {\n  id: 'Alphanumeric',\n  bit: 1 << 1,\n  ccBits: [9, 11, 13]\n}\n\n/**\n * In byte mode, data is encoded at 8 bits per character.\n *\n * @type {Object}\n */\nexports.BYTE = {\n  id: 'Byte',\n  bit: 1 << 2,\n  ccBits: [8, 16, 16]\n}\n\n/**\n * The Kanji mode efficiently encodes Kanji characters in accordance with\n * the Shift JIS system based on JIS X 0208.\n * The Shift JIS values are shifted from the JIS X 0208 values.\n * JIS X 0208 gives details of the shift coded representation.\n * Each two-byte character value is compacted to a 13-bit binary codeword.\n *\n * @type {Object}\n */\nexports.KANJI = {\n  id: 'Kanji',\n  bit: 1 << 3,\n  ccBits: [8, 10, 12]\n}\n\n/**\n * Mixed mode will contain a sequences of data in a combination of any of\n * the modes described above\n *\n * @type {Object}\n */\nexports.MIXED = {\n  bit: -1\n}\n\n/**\n * Returns the number of bits needed to store the data length\n * according to QR Code specifications.\n *\n * @param  {Mode}   mode    Data mode\n * @param  {Number} version QR Code version\n * @return {Number}         Number of bits\n */\nexports.getCharCountIndicator = function getCharCountIndicator (mode, version) {\n  if (!mode.ccBits) throw new Error('Invalid mode: ' + mode)\n\n  if (!VersionCheck.isValid(version)) {\n    throw new Error('Invalid version: ' + version)\n  }\n\n  if (version >= 1 && version < 10) return mode.ccBits[0]\n  else if (version < 27) return mode.ccBits[1]\n  return mode.ccBits[2]\n}\n\n/**\n * Returns the most efficient mode to store the specified data\n *\n * @param  {String} dataStr Input data string\n * @return {Mode}           Best mode\n */\nexports.getBestModeForData = function getBestModeForData (dataStr) {\n  if (Regex.testNumeric(dataStr)) return exports.NUMERIC\n  else if (Regex.testAlphanumeric(dataStr)) return exports.ALPHANUMERIC\n  else if (Regex.testKanji(dataStr)) return exports.KANJI\n  else return exports.BYTE\n}\n\n/**\n * Return mode name as string\n *\n * @param {Mode} mode Mode object\n * @returns {String}  Mode name\n */\nexports.toString = function toString (mode) {\n  if (mode && mode.id) return mode.id\n  throw new Error('Invalid mode')\n}\n\n/**\n * Check if input param is a valid mode object\n *\n * @param   {Mode}    mode Mode object\n * @returns {Boolean} True if valid mode, false otherwise\n */\nexports.isValid = function isValid (mode) {\n  return mode && mode.bit && mode.ccBits\n}\n\n/**\n * Get mode object from its name\n *\n * @param   {String} string Mode name\n * @returns {Mode}          Mode object\n */\nfunction fromString (string) {\n  if (typeof string !== 'string') {\n    throw new Error('Param is not a string')\n  }\n\n  const lcStr = string.toLowerCase()\n\n  switch (lcStr) {\n    case 'numeric':\n      return exports.NUMERIC\n    case 'alphanumeric':\n      return exports.ALPHANUMERIC\n    case 'kanji':\n      return exports.KANJI\n    case 'byte':\n      return exports.BYTE\n    default:\n      throw new Error('Unknown mode: ' + string)\n  }\n}\n\n/**\n * Returns mode from a value.\n * If value is not a valid mode, returns defaultValue\n *\n * @param  {Mode|String} value        Encoding mode\n * @param  {Mode}        defaultValue Fallback value\n * @return {Mode}                     Encoding mode\n */\nexports.from = function from (value, defaultValue) {\n  if (exports.isValid(value)) {\n    return value\n  }\n\n  try {\n    return fromString(value)\n  } catch (e) {\n    return defaultValue\n  }\n}\n"
  },
  {
    "path": "lib/core/numeric-data.js",
    "content": "const Mode = require('./mode')\n\nfunction NumericData (data) {\n  this.mode = Mode.NUMERIC\n  this.data = data.toString()\n}\n\nNumericData.getBitsLength = function getBitsLength (length) {\n  return 10 * Math.floor(length / 3) + ((length % 3) ? ((length % 3) * 3 + 1) : 0)\n}\n\nNumericData.prototype.getLength = function getLength () {\n  return this.data.length\n}\n\nNumericData.prototype.getBitsLength = function getBitsLength () {\n  return NumericData.getBitsLength(this.data.length)\n}\n\nNumericData.prototype.write = function write (bitBuffer) {\n  let i, group, value\n\n  // The input data string is divided into groups of three digits,\n  // and each group is converted to its 10-bit binary equivalent.\n  for (i = 0; i + 3 <= this.data.length; i += 3) {\n    group = this.data.substr(i, 3)\n    value = parseInt(group, 10)\n\n    bitBuffer.put(value, 10)\n  }\n\n  // If the number of input digits is not an exact multiple of three,\n  // the final one or two digits are converted to 4 or 7 bits respectively.\n  const remainingNum = this.data.length - i\n  if (remainingNum > 0) {\n    group = this.data.substr(i)\n    value = parseInt(group, 10)\n\n    bitBuffer.put(value, remainingNum * 3 + 1)\n  }\n}\n\nmodule.exports = NumericData\n"
  },
  {
    "path": "lib/core/polynomial.js",
    "content": "const GF = require('./galois-field')\n\n/**\n * Multiplies two polynomials inside Galois Field\n *\n * @param  {Uint8Array} p1 Polynomial\n * @param  {Uint8Array} p2 Polynomial\n * @return {Uint8Array}    Product of p1 and p2\n */\nexports.mul = function mul (p1, p2) {\n  const coeff = new Uint8Array(p1.length + p2.length - 1)\n\n  for (let i = 0; i < p1.length; i++) {\n    for (let j = 0; j < p2.length; j++) {\n      coeff[i + j] ^= GF.mul(p1[i], p2[j])\n    }\n  }\n\n  return coeff\n}\n\n/**\n * Calculate the remainder of polynomials division\n *\n * @param  {Uint8Array} divident Polynomial\n * @param  {Uint8Array} divisor  Polynomial\n * @return {Uint8Array}          Remainder\n */\nexports.mod = function mod (divident, divisor) {\n  let result = new Uint8Array(divident)\n\n  while ((result.length - divisor.length) >= 0) {\n    const coeff = result[0]\n\n    for (let i = 0; i < divisor.length; i++) {\n      result[i] ^= GF.mul(divisor[i], coeff)\n    }\n\n    // remove all zeros from buffer head\n    let offset = 0\n    while (offset < result.length && result[offset] === 0) offset++\n    result = result.slice(offset)\n  }\n\n  return result\n}\n\n/**\n * Generate an irreducible generator polynomial of specified degree\n * (used by Reed-Solomon encoder)\n *\n * @param  {Number} degree Degree of the generator polynomial\n * @return {Uint8Array}    Buffer containing polynomial coefficients\n */\nexports.generateECPolynomial = function generateECPolynomial (degree) {\n  let poly = new Uint8Array([1])\n  for (let i = 0; i < degree; i++) {\n    poly = exports.mul(poly, new Uint8Array([1, GF.exp(i)]))\n  }\n\n  return poly\n}\n"
  },
  {
    "path": "lib/core/qrcode.js",
    "content": "const Utils = require('./utils')\nconst ECLevel = require('./error-correction-level')\nconst BitBuffer = require('./bit-buffer')\nconst BitMatrix = require('./bit-matrix')\nconst AlignmentPattern = require('./alignment-pattern')\nconst FinderPattern = require('./finder-pattern')\nconst MaskPattern = require('./mask-pattern')\nconst ECCode = require('./error-correction-code')\nconst ReedSolomonEncoder = require('./reed-solomon-encoder')\nconst Version = require('./version')\nconst FormatInfo = require('./format-info')\nconst Mode = require('./mode')\nconst Segments = require('./segments')\n\n/**\n * QRCode for JavaScript\n *\n * modified by Ryan Day for nodejs support\n * Copyright (c) 2011 Ryan Day\n *\n * Licensed under the MIT license:\n *   http://www.opensource.org/licenses/mit-license.php\n *\n//---------------------------------------------------------------------\n// QRCode for JavaScript\n//\n// Copyright (c) 2009 Kazuhiko Arase\n//\n// URL: http://www.d-project.com/\n//\n// Licensed under the MIT license:\n//   http://www.opensource.org/licenses/mit-license.php\n//\n// The word \"QR Code\" is registered trademark of\n// DENSO WAVE INCORPORATED\n//   http://www.denso-wave.com/qrcode/faqpatent-e.html\n//\n//---------------------------------------------------------------------\n*/\n\n/**\n * Add finder patterns bits to matrix\n *\n * @param  {BitMatrix} matrix  Modules matrix\n * @param  {Number}    version QR Code version\n */\nfunction setupFinderPattern (matrix, version) {\n  const size = matrix.size\n  const pos = FinderPattern.getPositions(version)\n\n  for (let i = 0; i < pos.length; i++) {\n    const row = pos[i][0]\n    const col = pos[i][1]\n\n    for (let r = -1; r <= 7; r++) {\n      if (row + r <= -1 || size <= row + r) continue\n\n      for (let c = -1; c <= 7; c++) {\n        if (col + c <= -1 || size <= col + c) continue\n\n        if ((r >= 0 && r <= 6 && (c === 0 || c === 6)) ||\n          (c >= 0 && c <= 6 && (r === 0 || r === 6)) ||\n          (r >= 2 && r <= 4 && c >= 2 && c <= 4)) {\n          matrix.set(row + r, col + c, true, true)\n        } else {\n          matrix.set(row + r, col + c, false, true)\n        }\n      }\n    }\n  }\n}\n\n/**\n * Add timing pattern bits to matrix\n *\n * Note: this function must be called before {@link setupAlignmentPattern}\n *\n * @param  {BitMatrix} matrix Modules matrix\n */\nfunction setupTimingPattern (matrix) {\n  const size = matrix.size\n\n  for (let r = 8; r < size - 8; r++) {\n    const value = r % 2 === 0\n    matrix.set(r, 6, value, true)\n    matrix.set(6, r, value, true)\n  }\n}\n\n/**\n * Add alignment patterns bits to matrix\n *\n * Note: this function must be called after {@link setupTimingPattern}\n *\n * @param  {BitMatrix} matrix  Modules matrix\n * @param  {Number}    version QR Code version\n */\nfunction setupAlignmentPattern (matrix, version) {\n  const pos = AlignmentPattern.getPositions(version)\n\n  for (let i = 0; i < pos.length; i++) {\n    const row = pos[i][0]\n    const col = pos[i][1]\n\n    for (let r = -2; r <= 2; r++) {\n      for (let c = -2; c <= 2; c++) {\n        if (r === -2 || r === 2 || c === -2 || c === 2 ||\n          (r === 0 && c === 0)) {\n          matrix.set(row + r, col + c, true, true)\n        } else {\n          matrix.set(row + r, col + c, false, true)\n        }\n      }\n    }\n  }\n}\n\n/**\n * Add version info bits to matrix\n *\n * @param  {BitMatrix} matrix  Modules matrix\n * @param  {Number}    version QR Code version\n */\nfunction setupVersionInfo (matrix, version) {\n  const size = matrix.size\n  const bits = Version.getEncodedBits(version)\n  let row, col, mod\n\n  for (let i = 0; i < 18; i++) {\n    row = Math.floor(i / 3)\n    col = i % 3 + size - 8 - 3\n    mod = ((bits >> i) & 1) === 1\n\n    matrix.set(row, col, mod, true)\n    matrix.set(col, row, mod, true)\n  }\n}\n\n/**\n * Add format info bits to matrix\n *\n * @param  {BitMatrix} matrix               Modules matrix\n * @param  {ErrorCorrectionLevel}    errorCorrectionLevel Error correction level\n * @param  {Number}    maskPattern          Mask pattern reference value\n */\nfunction setupFormatInfo (matrix, errorCorrectionLevel, maskPattern) {\n  const size = matrix.size\n  const bits = FormatInfo.getEncodedBits(errorCorrectionLevel, maskPattern)\n  let i, mod\n\n  for (i = 0; i < 15; i++) {\n    mod = ((bits >> i) & 1) === 1\n\n    // vertical\n    if (i < 6) {\n      matrix.set(i, 8, mod, true)\n    } else if (i < 8) {\n      matrix.set(i + 1, 8, mod, true)\n    } else {\n      matrix.set(size - 15 + i, 8, mod, true)\n    }\n\n    // horizontal\n    if (i < 8) {\n      matrix.set(8, size - i - 1, mod, true)\n    } else if (i < 9) {\n      matrix.set(8, 15 - i - 1 + 1, mod, true)\n    } else {\n      matrix.set(8, 15 - i - 1, mod, true)\n    }\n  }\n\n  // fixed module\n  matrix.set(size - 8, 8, 1, true)\n}\n\n/**\n * Add encoded data bits to matrix\n *\n * @param  {BitMatrix}  matrix Modules matrix\n * @param  {Uint8Array} data   Data codewords\n */\nfunction setupData (matrix, data) {\n  const size = matrix.size\n  let inc = -1\n  let row = size - 1\n  let bitIndex = 7\n  let byteIndex = 0\n\n  for (let col = size - 1; col > 0; col -= 2) {\n    if (col === 6) col--\n\n    while (true) {\n      for (let c = 0; c < 2; c++) {\n        if (!matrix.isReserved(row, col - c)) {\n          let dark = false\n\n          if (byteIndex < data.length) {\n            dark = (((data[byteIndex] >>> bitIndex) & 1) === 1)\n          }\n\n          matrix.set(row, col - c, dark)\n          bitIndex--\n\n          if (bitIndex === -1) {\n            byteIndex++\n            bitIndex = 7\n          }\n        }\n      }\n\n      row += inc\n\n      if (row < 0 || size <= row) {\n        row -= inc\n        inc = -inc\n        break\n      }\n    }\n  }\n}\n\n/**\n * Create encoded codewords from data input\n *\n * @param  {Number}   version              QR Code version\n * @param  {ErrorCorrectionLevel}   errorCorrectionLevel Error correction level\n * @param  {ByteData} data                 Data input\n * @return {Uint8Array}                    Buffer containing encoded codewords\n */\nfunction createData (version, errorCorrectionLevel, segments) {\n  // Prepare data buffer\n  const buffer = new BitBuffer()\n\n  segments.forEach(function (data) {\n    // prefix data with mode indicator (4 bits)\n    buffer.put(data.mode.bit, 4)\n\n    // Prefix data with character count indicator.\n    // The character count indicator is a string of bits that represents the\n    // number of characters that are being encoded.\n    // The character count indicator must be placed after the mode indicator\n    // and must be a certain number of bits long, depending on the QR version\n    // and data mode\n    // @see {@link Mode.getCharCountIndicator}.\n    buffer.put(data.getLength(), Mode.getCharCountIndicator(data.mode, version))\n\n    // add binary data sequence to buffer\n    data.write(buffer)\n  })\n\n  // Calculate required number of bits\n  const totalCodewords = Utils.getSymbolTotalCodewords(version)\n  const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel)\n  const dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8\n\n  // Add a terminator.\n  // If the bit string is shorter than the total number of required bits,\n  // a terminator of up to four 0s must be added to the right side of the string.\n  // If the bit string is more than four bits shorter than the required number of bits,\n  // add four 0s to the end.\n  if (buffer.getLengthInBits() + 4 <= dataTotalCodewordsBits) {\n    buffer.put(0, 4)\n  }\n\n  // If the bit string is fewer than four bits shorter, add only the number of 0s that\n  // are needed to reach the required number of bits.\n\n  // After adding the terminator, if the number of bits in the string is not a multiple of 8,\n  // pad the string on the right with 0s to make the string's length a multiple of 8.\n  while (buffer.getLengthInBits() % 8 !== 0) {\n    buffer.putBit(0)\n  }\n\n  // Add pad bytes if the string is still shorter than the total number of required bits.\n  // Extend the buffer to fill the data capacity of the symbol corresponding to\n  // the Version and Error Correction Level by adding the Pad Codewords 11101100 (0xEC)\n  // and 00010001 (0x11) alternately.\n  const remainingByte = (dataTotalCodewordsBits - buffer.getLengthInBits()) / 8\n  for (let i = 0; i < remainingByte; i++) {\n    buffer.put(i % 2 ? 0x11 : 0xEC, 8)\n  }\n\n  return createCodewords(buffer, version, errorCorrectionLevel)\n}\n\n/**\n * Encode input data with Reed-Solomon and return codewords with\n * relative error correction bits\n *\n * @param  {BitBuffer} bitBuffer            Data to encode\n * @param  {Number}    version              QR Code version\n * @param  {ErrorCorrectionLevel} errorCorrectionLevel Error correction level\n * @return {Uint8Array}                     Buffer containing encoded codewords\n */\nfunction createCodewords (bitBuffer, version, errorCorrectionLevel) {\n  // Total codewords for this QR code version (Data + Error correction)\n  const totalCodewords = Utils.getSymbolTotalCodewords(version)\n\n  // Total number of error correction codewords\n  const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel)\n\n  // Total number of data codewords\n  const dataTotalCodewords = totalCodewords - ecTotalCodewords\n\n  // Total number of blocks\n  const ecTotalBlocks = ECCode.getBlocksCount(version, errorCorrectionLevel)\n\n  // Calculate how many blocks each group should contain\n  const blocksInGroup2 = totalCodewords % ecTotalBlocks\n  const blocksInGroup1 = ecTotalBlocks - blocksInGroup2\n\n  const totalCodewordsInGroup1 = Math.floor(totalCodewords / ecTotalBlocks)\n\n  const dataCodewordsInGroup1 = Math.floor(dataTotalCodewords / ecTotalBlocks)\n  const dataCodewordsInGroup2 = dataCodewordsInGroup1 + 1\n\n  // Number of EC codewords is the same for both groups\n  const ecCount = totalCodewordsInGroup1 - dataCodewordsInGroup1\n\n  // Initialize a Reed-Solomon encoder with a generator polynomial of degree ecCount\n  const rs = new ReedSolomonEncoder(ecCount)\n\n  let offset = 0\n  const dcData = new Array(ecTotalBlocks)\n  const ecData = new Array(ecTotalBlocks)\n  let maxDataSize = 0\n  const buffer = new Uint8Array(bitBuffer.buffer)\n\n  // Divide the buffer into the required number of blocks\n  for (let b = 0; b < ecTotalBlocks; b++) {\n    const dataSize = b < blocksInGroup1 ? dataCodewordsInGroup1 : dataCodewordsInGroup2\n\n    // extract a block of data from buffer\n    dcData[b] = buffer.slice(offset, offset + dataSize)\n\n    // Calculate EC codewords for this data block\n    ecData[b] = rs.encode(dcData[b])\n\n    offset += dataSize\n    maxDataSize = Math.max(maxDataSize, dataSize)\n  }\n\n  // Create final data\n  // Interleave the data and error correction codewords from each block\n  const data = new Uint8Array(totalCodewords)\n  let index = 0\n  let i, r\n\n  // Add data codewords\n  for (i = 0; i < maxDataSize; i++) {\n    for (r = 0; r < ecTotalBlocks; r++) {\n      if (i < dcData[r].length) {\n        data[index++] = dcData[r][i]\n      }\n    }\n  }\n\n  // Apped EC codewords\n  for (i = 0; i < ecCount; i++) {\n    for (r = 0; r < ecTotalBlocks; r++) {\n      data[index++] = ecData[r][i]\n    }\n  }\n\n  return data\n}\n\n/**\n * Build QR Code symbol\n *\n * @param  {String} data                 Input string\n * @param  {Number} version              QR Code version\n * @param  {ErrorCorretionLevel} errorCorrectionLevel Error level\n * @param  {MaskPattern} maskPattern     Mask pattern\n * @return {Object}                      Object containing symbol data\n */\nfunction createSymbol (data, version, errorCorrectionLevel, maskPattern) {\n  let segments\n\n  if (Array.isArray(data)) {\n    segments = Segments.fromArray(data)\n  } else if (typeof data === 'string') {\n    let estimatedVersion = version\n\n    if (!estimatedVersion) {\n      const rawSegments = Segments.rawSplit(data)\n\n      // Estimate best version that can contain raw splitted segments\n      estimatedVersion = Version.getBestVersionForData(rawSegments, errorCorrectionLevel)\n    }\n\n    // Build optimized segments\n    // If estimated version is undefined, try with the highest version\n    segments = Segments.fromString(data, estimatedVersion || 40)\n  } else {\n    throw new Error('Invalid data')\n  }\n\n  // Get the min version that can contain data\n  const bestVersion = Version.getBestVersionForData(segments, errorCorrectionLevel)\n\n  // If no version is found, data cannot be stored\n  if (!bestVersion) {\n    throw new Error('The amount of data is too big to be stored in a QR Code')\n  }\n\n  // If not specified, use min version as default\n  if (!version) {\n    version = bestVersion\n\n  // Check if the specified version can contain the data\n  } else if (version < bestVersion) {\n    throw new Error('\\n' +\n      'The chosen QR Code version cannot contain this amount of data.\\n' +\n      'Minimum version required to store current data is: ' + bestVersion + '.\\n'\n    )\n  }\n\n  const dataBits = createData(version, errorCorrectionLevel, segments)\n\n  // Allocate matrix buffer\n  const moduleCount = Utils.getSymbolSize(version)\n  const modules = new BitMatrix(moduleCount)\n\n  // Add function modules\n  setupFinderPattern(modules, version)\n  setupTimingPattern(modules)\n  setupAlignmentPattern(modules, version)\n\n  // Add temporary dummy bits for format info just to set them as reserved.\n  // This is needed to prevent these bits from being masked by {@link MaskPattern.applyMask}\n  // since the masking operation must be performed only on the encoding region.\n  // These blocks will be replaced with correct values later in code.\n  setupFormatInfo(modules, errorCorrectionLevel, 0)\n\n  if (version >= 7) {\n    setupVersionInfo(modules, version)\n  }\n\n  // Add data codewords\n  setupData(modules, dataBits)\n\n  if (isNaN(maskPattern)) {\n    // Find best mask pattern\n    maskPattern = MaskPattern.getBestMask(modules,\n      setupFormatInfo.bind(null, modules, errorCorrectionLevel))\n  }\n\n  // Apply mask pattern\n  MaskPattern.applyMask(maskPattern, modules)\n\n  // Replace format info bits with correct values\n  setupFormatInfo(modules, errorCorrectionLevel, maskPattern)\n\n  return {\n    modules: modules,\n    version: version,\n    errorCorrectionLevel: errorCorrectionLevel,\n    maskPattern: maskPattern,\n    segments: segments\n  }\n}\n\n/**\n * QR Code\n *\n * @param {String | Array} data                 Input data\n * @param {Object} options                      Optional configurations\n * @param {Number} options.version              QR Code version\n * @param {String} options.errorCorrectionLevel Error correction level\n * @param {Function} options.toSJISFunc         Helper func to convert utf8 to sjis\n */\nexports.create = function create (data, options) {\n  if (typeof data === 'undefined' || data === '') {\n    throw new Error('No input text')\n  }\n\n  let errorCorrectionLevel = ECLevel.M\n  let version\n  let mask\n\n  if (typeof options !== 'undefined') {\n    // Use higher error correction level as default\n    errorCorrectionLevel = ECLevel.from(options.errorCorrectionLevel, ECLevel.M)\n    version = Version.from(options.version)\n    mask = MaskPattern.from(options.maskPattern)\n\n    if (options.toSJISFunc) {\n      Utils.setToSJISFunction(options.toSJISFunc)\n    }\n  }\n\n  return createSymbol(data, version, errorCorrectionLevel, mask)\n}\n"
  },
  {
    "path": "lib/core/reed-solomon-encoder.js",
    "content": "const Polynomial = require('./polynomial')\n\nfunction ReedSolomonEncoder (degree) {\n  this.genPoly = undefined\n  this.degree = degree\n\n  if (this.degree) this.initialize(this.degree)\n}\n\n/**\n * Initialize the encoder.\n * The input param should correspond to the number of error correction codewords.\n *\n * @param  {Number} degree\n */\nReedSolomonEncoder.prototype.initialize = function initialize (degree) {\n  // create an irreducible generator polynomial\n  this.degree = degree\n  this.genPoly = Polynomial.generateECPolynomial(this.degree)\n}\n\n/**\n * Encodes a chunk of data\n *\n * @param  {Uint8Array} data Buffer containing input data\n * @return {Uint8Array}      Buffer containing encoded data\n */\nReedSolomonEncoder.prototype.encode = function encode (data) {\n  if (!this.genPoly) {\n    throw new Error('Encoder not initialized')\n  }\n\n  // Calculate EC for this data block\n  // extends data size to data+genPoly size\n  const paddedData = new Uint8Array(data.length + this.degree)\n  paddedData.set(data)\n\n  // The error correction codewords are the remainder after dividing the data codewords\n  // by a generator polynomial\n  const remainder = Polynomial.mod(paddedData, this.genPoly)\n\n  // return EC data blocks (last n byte, where n is the degree of genPoly)\n  // If coefficients number in remainder are less than genPoly degree,\n  // pad with 0s to the left to reach the needed number of coefficients\n  const start = this.degree - remainder.length\n  if (start > 0) {\n    const buff = new Uint8Array(this.degree)\n    buff.set(remainder, start)\n\n    return buff\n  }\n\n  return remainder\n}\n\nmodule.exports = ReedSolomonEncoder\n"
  },
  {
    "path": "lib/core/regex.js",
    "content": "const numeric = '[0-9]+'\nconst alphanumeric = '[A-Z $%*+\\\\-./:]+'\nlet kanji = '(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|' +\n  '[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|' +\n  '[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|' +\n  '[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+'\nkanji = kanji.replace(/u/g, '\\\\u')\n\nconst byte = '(?:(?![A-Z0-9 $%*+\\\\-./:]|' + kanji + ')(?:.|[\\r\\n]))+'\n\nexports.KANJI = new RegExp(kanji, 'g')\nexports.BYTE_KANJI = new RegExp('[^A-Z0-9 $%*+\\\\-./:]+', 'g')\nexports.BYTE = new RegExp(byte, 'g')\nexports.NUMERIC = new RegExp(numeric, 'g')\nexports.ALPHANUMERIC = new RegExp(alphanumeric, 'g')\n\nconst TEST_KANJI = new RegExp('^' + kanji + '$')\nconst TEST_NUMERIC = new RegExp('^' + numeric + '$')\nconst TEST_ALPHANUMERIC = new RegExp('^[A-Z0-9 $%*+\\\\-./:]+$')\n\nexports.testKanji = function testKanji (str) {\n  return TEST_KANJI.test(str)\n}\n\nexports.testNumeric = function testNumeric (str) {\n  return TEST_NUMERIC.test(str)\n}\n\nexports.testAlphanumeric = function testAlphanumeric (str) {\n  return TEST_ALPHANUMERIC.test(str)\n}\n"
  },
  {
    "path": "lib/core/segments.js",
    "content": "const Mode = require('./mode')\nconst NumericData = require('./numeric-data')\nconst AlphanumericData = require('./alphanumeric-data')\nconst ByteData = require('./byte-data')\nconst KanjiData = require('./kanji-data')\nconst Regex = require('./regex')\nconst Utils = require('./utils')\nconst dijkstra = require('dijkstrajs')\n\n/**\n * Returns UTF8 byte length\n *\n * @param  {String} str Input string\n * @return {Number}     Number of byte\n */\nfunction getStringByteLength (str) {\n  return unescape(encodeURIComponent(str)).length\n}\n\n/**\n * Get a list of segments of the specified mode\n * from a string\n *\n * @param  {Mode}   mode Segment mode\n * @param  {String} str  String to process\n * @return {Array}       Array of object with segments data\n */\nfunction getSegments (regex, mode, str) {\n  const segments = []\n  let result\n\n  while ((result = regex.exec(str)) !== null) {\n    segments.push({\n      data: result[0],\n      index: result.index,\n      mode: mode,\n      length: result[0].length\n    })\n  }\n\n  return segments\n}\n\n/**\n * Extracts a series of segments with the appropriate\n * modes from a string\n *\n * @param  {String} dataStr Input string\n * @return {Array}          Array of object with segments data\n */\nfunction getSegmentsFromString (dataStr) {\n  const numSegs = getSegments(Regex.NUMERIC, Mode.NUMERIC, dataStr)\n  const alphaNumSegs = getSegments(Regex.ALPHANUMERIC, Mode.ALPHANUMERIC, dataStr)\n  let byteSegs\n  let kanjiSegs\n\n  if (Utils.isKanjiModeEnabled()) {\n    byteSegs = getSegments(Regex.BYTE, Mode.BYTE, dataStr)\n    kanjiSegs = getSegments(Regex.KANJI, Mode.KANJI, dataStr)\n  } else {\n    byteSegs = getSegments(Regex.BYTE_KANJI, Mode.BYTE, dataStr)\n    kanjiSegs = []\n  }\n\n  const segs = numSegs.concat(alphaNumSegs, byteSegs, kanjiSegs)\n\n  return segs\n    .sort(function (s1, s2) {\n      return s1.index - s2.index\n    })\n    .map(function (obj) {\n      return {\n        data: obj.data,\n        mode: obj.mode,\n        length: obj.length\n      }\n    })\n}\n\n/**\n * Returns how many bits are needed to encode a string of\n * specified length with the specified mode\n *\n * @param  {Number} length String length\n * @param  {Mode} mode     Segment mode\n * @return {Number}        Bit length\n */\nfunction getSegmentBitsLength (length, mode) {\n  switch (mode) {\n    case Mode.NUMERIC:\n      return NumericData.getBitsLength(length)\n    case Mode.ALPHANUMERIC:\n      return AlphanumericData.getBitsLength(length)\n    case Mode.KANJI:\n      return KanjiData.getBitsLength(length)\n    case Mode.BYTE:\n      return ByteData.getBitsLength(length)\n  }\n}\n\n/**\n * Merges adjacent segments which have the same mode\n *\n * @param  {Array} segs Array of object with segments data\n * @return {Array}      Array of object with segments data\n */\nfunction mergeSegments (segs) {\n  return segs.reduce(function (acc, curr) {\n    const prevSeg = acc.length - 1 >= 0 ? acc[acc.length - 1] : null\n    if (prevSeg && prevSeg.mode === curr.mode) {\n      acc[acc.length - 1].data += curr.data\n      return acc\n    }\n\n    acc.push(curr)\n    return acc\n  }, [])\n}\n\n/**\n * Generates a list of all possible nodes combination which\n * will be used to build a segments graph.\n *\n * Nodes are divided by groups. Each group will contain a list of all the modes\n * in which is possible to encode the given text.\n *\n * For example the text '12345' can be encoded as Numeric, Alphanumeric or Byte.\n * The group for '12345' will contain then 3 objects, one for each\n * possible encoding mode.\n *\n * Each node represents a possible segment.\n *\n * @param  {Array} segs Array of object with segments data\n * @return {Array}      Array of object with segments data\n */\nfunction buildNodes (segs) {\n  const nodes = []\n  for (let i = 0; i < segs.length; i++) {\n    const seg = segs[i]\n\n    switch (seg.mode) {\n      case Mode.NUMERIC:\n        nodes.push([seg,\n          { data: seg.data, mode: Mode.ALPHANUMERIC, length: seg.length },\n          { data: seg.data, mode: Mode.BYTE, length: seg.length }\n        ])\n        break\n      case Mode.ALPHANUMERIC:\n        nodes.push([seg,\n          { data: seg.data, mode: Mode.BYTE, length: seg.length }\n        ])\n        break\n      case Mode.KANJI:\n        nodes.push([seg,\n          { data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) }\n        ])\n        break\n      case Mode.BYTE:\n        nodes.push([\n          { data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) }\n        ])\n    }\n  }\n\n  return nodes\n}\n\n/**\n * Builds a graph from a list of nodes.\n * All segments in each node group will be connected with all the segments of\n * the next group and so on.\n *\n * At each connection will be assigned a weight depending on the\n * segment's byte length.\n *\n * @param  {Array} nodes    Array of object with segments data\n * @param  {Number} version QR Code version\n * @return {Object}         Graph of all possible segments\n */\nfunction buildGraph (nodes, version) {\n  const table = {}\n  const graph = { start: {} }\n  let prevNodeIds = ['start']\n\n  for (let i = 0; i < nodes.length; i++) {\n    const nodeGroup = nodes[i]\n    const currentNodeIds = []\n\n    for (let j = 0; j < nodeGroup.length; j++) {\n      const node = nodeGroup[j]\n      const key = '' + i + j\n\n      currentNodeIds.push(key)\n      table[key] = { node: node, lastCount: 0 }\n      graph[key] = {}\n\n      for (let n = 0; n < prevNodeIds.length; n++) {\n        const prevNodeId = prevNodeIds[n]\n\n        if (table[prevNodeId] && table[prevNodeId].node.mode === node.mode) {\n          graph[prevNodeId][key] =\n            getSegmentBitsLength(table[prevNodeId].lastCount + node.length, node.mode) -\n            getSegmentBitsLength(table[prevNodeId].lastCount, node.mode)\n\n          table[prevNodeId].lastCount += node.length\n        } else {\n          if (table[prevNodeId]) table[prevNodeId].lastCount = node.length\n\n          graph[prevNodeId][key] = getSegmentBitsLength(node.length, node.mode) +\n            4 + Mode.getCharCountIndicator(node.mode, version) // switch cost\n        }\n      }\n    }\n\n    prevNodeIds = currentNodeIds\n  }\n\n  for (let n = 0; n < prevNodeIds.length; n++) {\n    graph[prevNodeIds[n]].end = 0\n  }\n\n  return { map: graph, table: table }\n}\n\n/**\n * Builds a segment from a specified data and mode.\n * If a mode is not specified, the more suitable will be used.\n *\n * @param  {String} data             Input data\n * @param  {Mode | String} modesHint Data mode\n * @return {Segment}                 Segment\n */\nfunction buildSingleSegment (data, modesHint) {\n  let mode\n  const bestMode = Mode.getBestModeForData(data)\n\n  mode = Mode.from(modesHint, bestMode)\n\n  // Make sure data can be encoded\n  if (mode !== Mode.BYTE && mode.bit < bestMode.bit) {\n    throw new Error('\"' + data + '\"' +\n      ' cannot be encoded with mode ' + Mode.toString(mode) +\n      '.\\n Suggested mode is: ' + Mode.toString(bestMode))\n  }\n\n  // Use Mode.BYTE if Kanji support is disabled\n  if (mode === Mode.KANJI && !Utils.isKanjiModeEnabled()) {\n    mode = Mode.BYTE\n  }\n\n  switch (mode) {\n    case Mode.NUMERIC:\n      return new NumericData(data)\n\n    case Mode.ALPHANUMERIC:\n      return new AlphanumericData(data)\n\n    case Mode.KANJI:\n      return new KanjiData(data)\n\n    case Mode.BYTE:\n      return new ByteData(data)\n  }\n}\n\n/**\n * Builds a list of segments from an array.\n * Array can contain Strings or Objects with segment's info.\n *\n * For each item which is a string, will be generated a segment with the given\n * string and the more appropriate encoding mode.\n *\n * For each item which is an object, will be generated a segment with the given\n * data and mode.\n * Objects must contain at least the property \"data\".\n * If property \"mode\" is not present, the more suitable mode will be used.\n *\n * @param  {Array} array Array of objects with segments data\n * @return {Array}       Array of Segments\n */\nexports.fromArray = function fromArray (array) {\n  return array.reduce(function (acc, seg) {\n    if (typeof seg === 'string') {\n      acc.push(buildSingleSegment(seg, null))\n    } else if (seg.data) {\n      acc.push(buildSingleSegment(seg.data, seg.mode))\n    }\n\n    return acc\n  }, [])\n}\n\n/**\n * Builds an optimized sequence of segments from a string,\n * which will produce the shortest possible bitstream.\n *\n * @param  {String} data    Input string\n * @param  {Number} version QR Code version\n * @return {Array}          Array of segments\n */\nexports.fromString = function fromString (data, version) {\n  const segs = getSegmentsFromString(data, Utils.isKanjiModeEnabled())\n\n  const nodes = buildNodes(segs)\n  const graph = buildGraph(nodes, version)\n  const path = dijkstra.find_path(graph.map, 'start', 'end')\n\n  const optimizedSegs = []\n  for (let i = 1; i < path.length - 1; i++) {\n    optimizedSegs.push(graph.table[path[i]].node)\n  }\n\n  return exports.fromArray(mergeSegments(optimizedSegs))\n}\n\n/**\n * Splits a string in various segments with the modes which\n * best represent their content.\n * The produced segments are far from being optimized.\n * The output of this function is only used to estimate a QR Code version\n * which may contain the data.\n *\n * @param  {string} data Input string\n * @return {Array}       Array of segments\n */\nexports.rawSplit = function rawSplit (data) {\n  return exports.fromArray(\n    getSegmentsFromString(data, Utils.isKanjiModeEnabled())\n  )\n}\n"
  },
  {
    "path": "lib/core/utils.js",
    "content": "let toSJISFunction\nconst CODEWORDS_COUNT = [\n  0, // Not used\n  26, 44, 70, 100, 134, 172, 196, 242, 292, 346,\n  404, 466, 532, 581, 655, 733, 815, 901, 991, 1085,\n  1156, 1258, 1364, 1474, 1588, 1706, 1828, 1921, 2051, 2185,\n  2323, 2465, 2611, 2761, 2876, 3034, 3196, 3362, 3532, 3706\n]\n\n/**\n * Returns the QR Code size for the specified version\n *\n * @param  {Number} version QR Code version\n * @return {Number}         size of QR code\n */\nexports.getSymbolSize = function getSymbolSize (version) {\n  if (!version) throw new Error('\"version\" cannot be null or undefined')\n  if (version < 1 || version > 40) throw new Error('\"version\" should be in range from 1 to 40')\n  return version * 4 + 17\n}\n\n/**\n * Returns the total number of codewords used to store data and EC information.\n *\n * @param  {Number} version QR Code version\n * @return {Number}         Data length in bits\n */\nexports.getSymbolTotalCodewords = function getSymbolTotalCodewords (version) {\n  return CODEWORDS_COUNT[version]\n}\n\n/**\n * Encode data with Bose-Chaudhuri-Hocquenghem\n *\n * @param  {Number} data Value to encode\n * @return {Number}      Encoded value\n */\nexports.getBCHDigit = function (data) {\n  let digit = 0\n\n  while (data !== 0) {\n    digit++\n    data >>>= 1\n  }\n\n  return digit\n}\n\nexports.setToSJISFunction = function setToSJISFunction (f) {\n  if (typeof f !== 'function') {\n    throw new Error('\"toSJISFunc\" is not a valid function.')\n  }\n\n  toSJISFunction = f\n}\n\nexports.isKanjiModeEnabled = function () {\n  return typeof toSJISFunction !== 'undefined'\n}\n\nexports.toSJIS = function toSJIS (kanji) {\n  return toSJISFunction(kanji)\n}\n"
  },
  {
    "path": "lib/core/version-check.js",
    "content": "/**\n * Check if QR Code version is valid\n *\n * @param  {Number}  version QR Code version\n * @return {Boolean}         true if valid version, false otherwise\n */\nexports.isValid = function isValid (version) {\n  return !isNaN(version) && version >= 1 && version <= 40\n}\n"
  },
  {
    "path": "lib/core/version.js",
    "content": "const Utils = require('./utils')\nconst ECCode = require('./error-correction-code')\nconst ECLevel = require('./error-correction-level')\nconst Mode = require('./mode')\nconst VersionCheck = require('./version-check')\n\n// Generator polynomial used to encode version information\nconst G18 = (1 << 12) | (1 << 11) | (1 << 10) | (1 << 9) | (1 << 8) | (1 << 5) | (1 << 2) | (1 << 0)\nconst G18_BCH = Utils.getBCHDigit(G18)\n\nfunction getBestVersionForDataLength (mode, length, errorCorrectionLevel) {\n  for (let currentVersion = 1; currentVersion <= 40; currentVersion++) {\n    if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, mode)) {\n      return currentVersion\n    }\n  }\n\n  return undefined\n}\n\nfunction getReservedBitsCount (mode, version) {\n  // Character count indicator + mode indicator bits\n  return Mode.getCharCountIndicator(mode, version) + 4\n}\n\nfunction getTotalBitsFromDataArray (segments, version) {\n  let totalBits = 0\n\n  segments.forEach(function (data) {\n    const reservedBits = getReservedBitsCount(data.mode, version)\n    totalBits += reservedBits + data.getBitsLength()\n  })\n\n  return totalBits\n}\n\nfunction getBestVersionForMixedData (segments, errorCorrectionLevel) {\n  for (let currentVersion = 1; currentVersion <= 40; currentVersion++) {\n    const length = getTotalBitsFromDataArray(segments, currentVersion)\n    if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, Mode.MIXED)) {\n      return currentVersion\n    }\n  }\n\n  return undefined\n}\n\n/**\n * Returns version number from a value.\n * If value is not a valid version, returns defaultValue\n *\n * @param  {Number|String} value        QR Code version\n * @param  {Number}        defaultValue Fallback value\n * @return {Number}                     QR Code version number\n */\nexports.from = function from (value, defaultValue) {\n  if (VersionCheck.isValid(value)) {\n    return parseInt(value, 10)\n  }\n\n  return defaultValue\n}\n\n/**\n * Returns how much data can be stored with the specified QR code version\n * and error correction level\n *\n * @param  {Number} version              QR Code version (1-40)\n * @param  {Number} errorCorrectionLevel Error correction level\n * @param  {Mode}   mode                 Data mode\n * @return {Number}                      Quantity of storable data\n */\nexports.getCapacity = function getCapacity (version, errorCorrectionLevel, mode) {\n  if (!VersionCheck.isValid(version)) {\n    throw new Error('Invalid QR Code version')\n  }\n\n  // Use Byte mode as default\n  if (typeof mode === 'undefined') mode = Mode.BYTE\n\n  // Total codewords for this QR code version (Data + Error correction)\n  const totalCodewords = Utils.getSymbolTotalCodewords(version)\n\n  // Total number of error correction codewords\n  const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel)\n\n  // Total number of data codewords\n  const dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8\n\n  if (mode === Mode.MIXED) return dataTotalCodewordsBits\n\n  const usableBits = dataTotalCodewordsBits - getReservedBitsCount(mode, version)\n\n  // Return max number of storable codewords\n  switch (mode) {\n    case Mode.NUMERIC:\n      return Math.floor((usableBits / 10) * 3)\n\n    case Mode.ALPHANUMERIC:\n      return Math.floor((usableBits / 11) * 2)\n\n    case Mode.KANJI:\n      return Math.floor(usableBits / 13)\n\n    case Mode.BYTE:\n    default:\n      return Math.floor(usableBits / 8)\n  }\n}\n\n/**\n * Returns the minimum version needed to contain the amount of data\n *\n * @param  {Segment} data                    Segment of data\n * @param  {Number} [errorCorrectionLevel=H] Error correction level\n * @param  {Mode} mode                       Data mode\n * @return {Number}                          QR Code version\n */\nexports.getBestVersionForData = function getBestVersionForData (data, errorCorrectionLevel) {\n  let seg\n\n  const ecl = ECLevel.from(errorCorrectionLevel, ECLevel.M)\n\n  if (Array.isArray(data)) {\n    if (data.length > 1) {\n      return getBestVersionForMixedData(data, ecl)\n    }\n\n    if (data.length === 0) {\n      return 1\n    }\n\n    seg = data[0]\n  } else {\n    seg = data\n  }\n\n  return getBestVersionForDataLength(seg.mode, seg.getLength(), ecl)\n}\n\n/**\n * Returns version information with relative error correction bits\n *\n * The version information is included in QR Code symbols of version 7 or larger.\n * It consists of an 18-bit sequence containing 6 data bits,\n * with 12 error correction bits calculated using the (18, 6) Golay code.\n *\n * @param  {Number} version QR Code version\n * @return {Number}         Encoded version info bits\n */\nexports.getEncodedBits = function getEncodedBits (version) {\n  if (!VersionCheck.isValid(version) || version < 7) {\n    throw new Error('Invalid QR Code version')\n  }\n\n  let d = version << 12\n\n  while (Utils.getBCHDigit(d) - G18_BCH >= 0) {\n    d ^= (G18 << (Utils.getBCHDigit(d) - G18_BCH))\n  }\n\n  return (version << 12) | d\n}\n"
  },
  {
    "path": "lib/index.js",
    "content": "/*\n*copyright Ryan Day 2012\n*\n* Licensed under the MIT license:\n*   http://www.opensource.org/licenses/mit-license.php\n*\n* this is the main server side application file for node-qrcode.\n* these exports use serverside canvas api methods for file IO and buffers\n*\n*/\n\nmodule.exports = require('./server')\n"
  },
  {
    "path": "lib/renderer/canvas.js",
    "content": "const Utils = require('./utils')\n\nfunction clearCanvas (ctx, canvas, size) {\n  ctx.clearRect(0, 0, canvas.width, canvas.height)\n\n  if (!canvas.style) canvas.style = {}\n  canvas.height = size\n  canvas.width = size\n  canvas.style.height = size + 'px'\n  canvas.style.width = size + 'px'\n}\n\nfunction getCanvasElement () {\n  try {\n    return document.createElement('canvas')\n  } catch (e) {\n    throw new Error('You need to specify a canvas element')\n  }\n}\n\nexports.render = function render (qrData, canvas, options) {\n  let opts = options\n  let canvasEl = canvas\n\n  if (typeof opts === 'undefined' && (!canvas || !canvas.getContext)) {\n    opts = canvas\n    canvas = undefined\n  }\n\n  if (!canvas) {\n    canvasEl = getCanvasElement()\n  }\n\n  opts = Utils.getOptions(opts)\n  const size = Utils.getImageWidth(qrData.modules.size, opts)\n\n  const ctx = canvasEl.getContext('2d')\n  const image = ctx.createImageData(size, size)\n  Utils.qrToImageData(image.data, qrData, opts)\n\n  clearCanvas(ctx, canvasEl, size)\n  ctx.putImageData(image, 0, 0)\n\n  return canvasEl\n}\n\nexports.renderToDataURL = function renderToDataURL (qrData, canvas, options) {\n  let opts = options\n\n  if (typeof opts === 'undefined' && (!canvas || !canvas.getContext)) {\n    opts = canvas\n    canvas = undefined\n  }\n\n  if (!opts) opts = {}\n\n  const canvasEl = exports.render(qrData, canvas, opts)\n\n  const type = opts.type || 'image/png'\n  const rendererOpts = opts.rendererOpts || {}\n\n  return canvasEl.toDataURL(type, rendererOpts.quality)\n}\n"
  },
  {
    "path": "lib/renderer/png.js",
    "content": "const fs = require('fs')\nconst PNG = require('pngjs').PNG\nconst Utils = require('./utils')\n\nexports.render = function render (qrData, options) {\n  const opts = Utils.getOptions(options)\n  const pngOpts = opts.rendererOpts\n  const size = Utils.getImageWidth(qrData.modules.size, opts)\n\n  pngOpts.width = size\n  pngOpts.height = size\n\n  const pngImage = new PNG(pngOpts)\n  Utils.qrToImageData(pngImage.data, qrData, opts)\n\n  return pngImage\n}\n\nexports.renderToDataURL = function renderToDataURL (qrData, options, cb) {\n  if (typeof cb === 'undefined') {\n    cb = options\n    options = undefined\n  }\n\n  exports.renderToBuffer(qrData, options, function (err, output) {\n    if (err) cb(err)\n    let url = 'data:image/png;base64,'\n    url += output.toString('base64')\n    cb(null, url)\n  })\n}\n\nexports.renderToBuffer = function renderToBuffer (qrData, options, cb) {\n  if (typeof cb === 'undefined') {\n    cb = options\n    options = undefined\n  }\n\n  const png = exports.render(qrData, options)\n  const buffer = []\n\n  png.on('error', cb)\n\n  png.on('data', function (data) {\n    buffer.push(data)\n  })\n\n  png.on('end', function () {\n    cb(null, Buffer.concat(buffer))\n  })\n\n  png.pack()\n}\n\nexports.renderToFile = function renderToFile (path, qrData, options, cb) {\n  if (typeof cb === 'undefined') {\n    cb = options\n    options = undefined\n  }\n\n  let called = false\n  const done = (...args) => {\n    if (called) return\n    called = true\n    cb.apply(null, args)\n  }\n  const stream = fs.createWriteStream(path)\n\n  stream.on('error', done)\n  stream.on('close', done)\n\n  exports.renderToFileStream(stream, qrData, options)\n}\n\nexports.renderToFileStream = function renderToFileStream (stream, qrData, options) {\n  const png = exports.render(qrData, options)\n  png.pack().pipe(stream)\n}\n"
  },
  {
    "path": "lib/renderer/svg-tag.js",
    "content": "const Utils = require('./utils')\n\nfunction getColorAttrib (color, attrib) {\n  const alpha = color.a / 255\n  const str = attrib + '=\"' + color.hex + '\"'\n\n  return alpha < 1\n    ? str + ' ' + attrib + '-opacity=\"' + alpha.toFixed(2).slice(1) + '\"'\n    : str\n}\n\nfunction svgCmd (cmd, x, y) {\n  let str = cmd + x\n  if (typeof y !== 'undefined') str += ' ' + y\n\n  return str\n}\n\nfunction qrToPath (data, size, margin) {\n  let path = ''\n  let moveBy = 0\n  let newRow = false\n  let lineLength = 0\n\n  for (let i = 0; i < data.length; i++) {\n    const col = Math.floor(i % size)\n    const row = Math.floor(i / size)\n\n    if (!col && !newRow) newRow = true\n\n    if (data[i]) {\n      lineLength++\n\n      if (!(i > 0 && col > 0 && data[i - 1])) {\n        path += newRow\n          ? svgCmd('M', col + margin, 0.5 + row + margin)\n          : svgCmd('m', moveBy, 0)\n\n        moveBy = 0\n        newRow = false\n      }\n\n      if (!(col + 1 < size && data[i + 1])) {\n        path += svgCmd('h', lineLength)\n        lineLength = 0\n      }\n    } else {\n      moveBy++\n    }\n  }\n\n  return path\n}\n\nexports.render = function render (qrData, options, cb) {\n  const opts = Utils.getOptions(options)\n  const size = qrData.modules.size\n  const data = qrData.modules.data\n  const qrcodesize = size + opts.margin * 2\n\n  const bg = !opts.color.light.a\n    ? ''\n    : '<path ' + getColorAttrib(opts.color.light, 'fill') +\n      ' d=\"M0 0h' + qrcodesize + 'v' + qrcodesize + 'H0z\"/>'\n\n  const path =\n    '<path ' + getColorAttrib(opts.color.dark, 'stroke') +\n    ' d=\"' + qrToPath(data, size, opts.margin) + '\"/>'\n\n  const viewBox = 'viewBox=\"' + '0 0 ' + qrcodesize + ' ' + qrcodesize + '\"'\n\n  const width = !opts.width ? '' : 'width=\"' + opts.width + '\" height=\"' + opts.width + '\" '\n\n  const svgTag = '<svg xmlns=\"http://www.w3.org/2000/svg\" ' + width + viewBox + ' shape-rendering=\"crispEdges\">' + bg + path + '</svg>\\n'\n\n  if (typeof cb === 'function') {\n    cb(null, svgTag)\n  }\n\n  return svgTag\n}\n"
  },
  {
    "path": "lib/renderer/svg.js",
    "content": "const svgTagRenderer = require('./svg-tag')\n\nexports.render = svgTagRenderer.render\n\nexports.renderToFile = function renderToFile (path, qrData, options, cb) {\n  if (typeof cb === 'undefined') {\n    cb = options\n    options = undefined\n  }\n\n  const fs = require('fs')\n  const svgTag = exports.render(qrData, options)\n\n  const xmlStr = '<?xml version=\"1.0\" encoding=\"utf-8\"?>' +\n    '<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">' +\n    svgTag\n\n  fs.writeFile(path, xmlStr, cb)\n}\n"
  },
  {
    "path": "lib/renderer/terminal/terminal-small.js",
    "content": "const backgroundWhite = '\\x1b[47m'\nconst backgroundBlack = '\\x1b[40m'\nconst foregroundWhite = '\\x1b[37m'\nconst foregroundBlack = '\\x1b[30m'\nconst reset = '\\x1b[0m'\nconst lineSetupNormal = backgroundWhite + foregroundBlack // setup colors\nconst lineSetupInverse = backgroundBlack + foregroundWhite // setup colors\n\nconst createPalette = function (lineSetup, foregroundWhite, foregroundBlack) {\n  return {\n    // 1 ... white, 2 ... black, 0 ... transparent (default)\n\n    '00': reset + ' ' + lineSetup,\n    '01': reset + foregroundWhite + '▄' + lineSetup,\n    '02': reset + foregroundBlack + '▄' + lineSetup,\n    10: reset + foregroundWhite + '▀' + lineSetup,\n    11: ' ',\n    12: '▄',\n    20: reset + foregroundBlack + '▀' + lineSetup,\n    21: '▀',\n    22: '█'\n  }\n}\n\n/**\n * Returns code for QR pixel\n * @param {boolean[][]} modules\n * @param {number} size\n * @param {number} x\n * @param {number} y\n * @return {'0' | '1' | '2'}\n */\nconst mkCodePixel = function (modules, size, x, y) {\n  const sizePlus = size + 1\n  if ((x >= sizePlus) || (y >= sizePlus) || (y < -1) || (x < -1)) return '0'\n  if ((x >= size) || (y >= size) || (y < 0) || (x < 0)) return '1'\n  const idx = (y * size) + x\n  return modules[idx] ? '2' : '1'\n}\n\n/**\n * Returns code for four QR pixels. Suitable as key in palette.\n * @param {boolean[][]} modules\n * @param {number} size\n * @param {number} x\n * @param {number} y\n * @return {keyof palette}\n */\nconst mkCode = function (modules, size, x, y) {\n  return (\n    mkCodePixel(modules, size, x, y) +\n    mkCodePixel(modules, size, x, y + 1)\n  )\n}\n\nexports.render = function (qrData, options, cb) {\n  const size = qrData.modules.size\n  const data = qrData.modules.data\n\n  const inverse = !!(options && options.inverse)\n  const lineSetup = options && options.inverse ? lineSetupInverse : lineSetupNormal\n  const white = inverse ? foregroundBlack : foregroundWhite\n  const black = inverse ? foregroundWhite : foregroundBlack\n\n  const palette = createPalette(lineSetup, white, black)\n  const newLine = reset + '\\n' + lineSetup\n\n  let output = lineSetup // setup colors\n\n  for (let y = -1; y < size + 1; y += 2) {\n    for (let x = -1; x < size; x++) {\n      output += palette[mkCode(data, size, x, y)]\n    }\n\n    output += palette[mkCode(data, size, size, y)] + newLine\n  }\n\n  output += reset\n\n  if (typeof cb === 'function') {\n    cb(null, output)\n  }\n\n  return output\n}\n"
  },
  {
    "path": "lib/renderer/terminal/terminal.js",
    "content": "// let Utils = require('./utils')\n\nexports.render = function (qrData, options, cb) {\n  const size = qrData.modules.size\n  const data = qrData.modules.data\n\n  // let opts = Utils.getOptions(options)\n\n  // use same scheme as https://github.com/gtanner/qrcode-terminal because it actually works! =)\n  const black = '\\x1b[40m  \\x1b[0m'\n  const white = '\\x1b[47m  \\x1b[0m'\n\n  let output = ''\n  const hMargin = Array(size + 3).join(white)\n  const vMargin = Array(2).join(white)\n\n  output += hMargin + '\\n'\n  for (let i = 0; i < size; ++i) {\n    output += white\n    for (let j = 0; j < size; j++) {\n      // let topModule = data[i * size + j]\n      // let bottomModule = data[(i + 1) * size + j]\n\n      output += data[i * size + j] ? black : white// getBlockChar(topModule, bottomModule)\n    }\n    // output += white+'\\n'\n    output += vMargin + '\\n'\n  }\n\n  output += hMargin + '\\n'\n\n  if (typeof cb === 'function') {\n    cb(null, output)\n  }\n\n  return output\n}\n/*\nexports.renderToFile = function renderToFile (path, qrData, options, cb) {\n  if (typeof cb === 'undefined') {\n    cb = options\n    options = undefined\n  }\n\n  let fs = require('fs')\n  let utf8 = exports.render(qrData, options)\n  fs.writeFile(path, utf8, cb)\n}\n*/\n"
  },
  {
    "path": "lib/renderer/terminal.js",
    "content": "const big = require('./terminal/terminal')\nconst small = require('./terminal/terminal-small')\n\nexports.render = function (qrData, options, cb) {\n  if (options && options.small) {\n    return small.render(qrData, options, cb)\n  }\n  return big.render(qrData, options, cb)\n}\n"
  },
  {
    "path": "lib/renderer/utf8.js",
    "content": "const Utils = require('./utils')\n\nconst BLOCK_CHAR = {\n  WW: ' ',\n  WB: '▄',\n  BB: '█',\n  BW: '▀'\n}\n\nconst INVERTED_BLOCK_CHAR = {\n  BB: ' ',\n  BW: '▄',\n  WW: '█',\n  WB: '▀'\n}\n\nfunction getBlockChar (top, bottom, blocks) {\n  if (top && bottom) return blocks.BB\n  if (top && !bottom) return blocks.BW\n  if (!top && bottom) return blocks.WB\n  return blocks.WW\n}\n\nexports.render = function (qrData, options, cb) {\n  const opts = Utils.getOptions(options)\n  let blocks = BLOCK_CHAR\n  if (opts.color.dark.hex === '#ffffff' || opts.color.light.hex === '#000000') {\n    blocks = INVERTED_BLOCK_CHAR\n  }\n\n  const size = qrData.modules.size\n  const data = qrData.modules.data\n\n  let output = ''\n  let hMargin = Array(size + (opts.margin * 2) + 1).join(blocks.WW)\n  hMargin = Array((opts.margin / 2) + 1).join(hMargin + '\\n')\n\n  const vMargin = Array(opts.margin + 1).join(blocks.WW)\n\n  output += hMargin\n  for (let i = 0; i < size; i += 2) {\n    output += vMargin\n    for (let j = 0; j < size; j++) {\n      const topModule = data[i * size + j]\n      const bottomModule = data[(i + 1) * size + j]\n\n      output += getBlockChar(topModule, bottomModule, blocks)\n    }\n\n    output += vMargin + '\\n'\n  }\n\n  output += hMargin.slice(0, -1)\n\n  if (typeof cb === 'function') {\n    cb(null, output)\n  }\n\n  return output\n}\n\nexports.renderToFile = function renderToFile (path, qrData, options, cb) {\n  if (typeof cb === 'undefined') {\n    cb = options\n    options = undefined\n  }\n\n  const fs = require('fs')\n  const utf8 = exports.render(qrData, options)\n  fs.writeFile(path, utf8, cb)\n}\n"
  },
  {
    "path": "lib/renderer/utils.js",
    "content": "function hex2rgba (hex) {\n  if (typeof hex === 'number') {\n    hex = hex.toString()\n  }\n\n  if (typeof hex !== 'string') {\n    throw new Error('Color should be defined as hex string')\n  }\n\n  let hexCode = hex.slice().replace('#', '').split('')\n  if (hexCode.length < 3 || hexCode.length === 5 || hexCode.length > 8) {\n    throw new Error('Invalid hex color: ' + hex)\n  }\n\n  // Convert from short to long form (fff -> ffffff)\n  if (hexCode.length === 3 || hexCode.length === 4) {\n    hexCode = Array.prototype.concat.apply([], hexCode.map(function (c) {\n      return [c, c]\n    }))\n  }\n\n  // Add default alpha value\n  if (hexCode.length === 6) hexCode.push('F', 'F')\n\n  const hexValue = parseInt(hexCode.join(''), 16)\n\n  return {\n    r: (hexValue >> 24) & 255,\n    g: (hexValue >> 16) & 255,\n    b: (hexValue >> 8) & 255,\n    a: hexValue & 255,\n    hex: '#' + hexCode.slice(0, 6).join('')\n  }\n}\n\nexports.getOptions = function getOptions (options) {\n  if (!options) options = {}\n  if (!options.color) options.color = {}\n\n  const margin = typeof options.margin === 'undefined' ||\n    options.margin === null ||\n    options.margin < 0\n    ? 4\n    : options.margin\n\n  const width = options.width && options.width >= 21 ? options.width : undefined\n  const scale = options.scale || 4\n\n  return {\n    width: width,\n    scale: width ? 4 : scale,\n    margin: margin,\n    color: {\n      dark: hex2rgba(options.color.dark || '#000000ff'),\n      light: hex2rgba(options.color.light || '#ffffffff')\n    },\n    type: options.type,\n    rendererOpts: options.rendererOpts || {}\n  }\n}\n\nexports.getScale = function getScale (qrSize, opts) {\n  return opts.width && opts.width >= qrSize + opts.margin * 2\n    ? opts.width / (qrSize + opts.margin * 2)\n    : opts.scale\n}\n\nexports.getImageWidth = function getImageWidth (qrSize, opts) {\n  const scale = exports.getScale(qrSize, opts)\n  return Math.floor((qrSize + opts.margin * 2) * scale)\n}\n\nexports.qrToImageData = function qrToImageData (imgData, qr, opts) {\n  const size = qr.modules.size\n  const data = qr.modules.data\n  const scale = exports.getScale(size, opts)\n  const symbolSize = Math.floor((size + opts.margin * 2) * scale)\n  const scaledMargin = opts.margin * scale\n  const palette = [opts.color.light, opts.color.dark]\n\n  for (let i = 0; i < symbolSize; i++) {\n    for (let j = 0; j < symbolSize; j++) {\n      let posDst = (i * symbolSize + j) * 4\n      let pxColor = opts.color.light\n\n      if (i >= scaledMargin && j >= scaledMargin &&\n        i < symbolSize - scaledMargin && j < symbolSize - scaledMargin) {\n        const iSrc = Math.floor((i - scaledMargin) / scale)\n        const jSrc = Math.floor((j - scaledMargin) / scale)\n        pxColor = palette[data[iSrc * size + jSrc] ? 1 : 0]\n      }\n\n      imgData[posDst++] = pxColor.r\n      imgData[posDst++] = pxColor.g\n      imgData[posDst++] = pxColor.b\n      imgData[posDst] = pxColor.a\n    }\n  }\n}\n"
  },
  {
    "path": "lib/server.js",
    "content": "const canPromise = require('./can-promise')\nconst QRCode = require('./core/qrcode')\nconst PngRenderer = require('./renderer/png')\nconst Utf8Renderer = require('./renderer/utf8')\nconst TerminalRenderer = require('./renderer/terminal')\nconst SvgRenderer = require('./renderer/svg')\n\nfunction checkParams (text, opts, cb) {\n  if (typeof text === 'undefined') {\n    throw new Error('String required as first argument')\n  }\n\n  if (typeof cb === 'undefined') {\n    cb = opts\n    opts = {}\n  }\n\n  if (typeof cb !== 'function') {\n    if (!canPromise()) {\n      throw new Error('Callback required as last argument')\n    } else {\n      opts = cb || {}\n      cb = null\n    }\n  }\n\n  return {\n    opts: opts,\n    cb: cb\n  }\n}\n\nfunction getTypeFromFilename (path) {\n  return path.slice((path.lastIndexOf('.') - 1 >>> 0) + 2).toLowerCase()\n}\n\nfunction getRendererFromType (type) {\n  switch (type) {\n    case 'svg':\n      return SvgRenderer\n\n    case 'txt':\n    case 'utf8':\n      return Utf8Renderer\n\n    case 'png':\n    case 'image/png':\n    default:\n      return PngRenderer\n  }\n}\n\nfunction getStringRendererFromType (type) {\n  switch (type) {\n    case 'svg':\n      return SvgRenderer\n\n    case 'terminal':\n      return TerminalRenderer\n\n    case 'utf8':\n    default:\n      return Utf8Renderer\n  }\n}\n\nfunction render (renderFunc, text, params) {\n  if (!params.cb) {\n    return new Promise(function (resolve, reject) {\n      try {\n        const data = QRCode.create(text, params.opts)\n        return renderFunc(data, params.opts, function (err, data) {\n          return err ? reject(err) : resolve(data)\n        })\n      } catch (e) {\n        reject(e)\n      }\n    })\n  }\n\n  try {\n    const data = QRCode.create(text, params.opts)\n    return renderFunc(data, params.opts, params.cb)\n  } catch (e) {\n    params.cb(e)\n  }\n}\n\nexports.create = QRCode.create\n\nexports.toCanvas = require('./browser').toCanvas\n\nexports.toString = function toString (text, opts, cb) {\n  const params = checkParams(text, opts, cb)\n  const type = params.opts ? params.opts.type : undefined\n  const renderer = getStringRendererFromType(type)\n  return render(renderer.render, text, params)\n}\n\nexports.toDataURL = function toDataURL (text, opts, cb) {\n  const params = checkParams(text, opts, cb)\n  const renderer = getRendererFromType(params.opts.type)\n  return render(renderer.renderToDataURL, text, params)\n}\n\nexports.toBuffer = function toBuffer (text, opts, cb) {\n  const params = checkParams(text, opts, cb)\n  const renderer = getRendererFromType(params.opts.type)\n  return render(renderer.renderToBuffer, text, params)\n}\n\nexports.toFile = function toFile (path, text, opts, cb) {\n  if (typeof path !== 'string' || !(typeof text === 'string' || typeof text === 'object')) {\n    throw new Error('Invalid argument')\n  }\n\n  if ((arguments.length < 3) && !canPromise()) {\n    throw new Error('Too few arguments provided')\n  }\n\n  const params = checkParams(text, opts, cb)\n  const type = params.opts.type || getTypeFromFilename(path)\n  const renderer = getRendererFromType(type)\n  const renderToFile = renderer.renderToFile.bind(null, path)\n\n  return render(renderToFile, text, params)\n}\n\nexports.toFileStream = function toFileStream (stream, text, opts) {\n  if (arguments.length < 2) {\n    throw new Error('Too few arguments provided')\n  }\n\n  const params = checkParams(text, opts, stream.emit.bind(stream, 'error'))\n  const renderer = getRendererFromType('png') // Only png support for now\n  const renderToFileStream = renderer.renderToFileStream.bind(null, stream)\n  render(renderToFileStream, text, params)\n}\n"
  },
  {
    "path": "license",
    "content": "The MIT License (MIT)\n\nCopyright (c) 2012 Ryan Day\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"qrcode\",\n  \"description\": \"QRCode / 2d Barcode api with both server side and client side support using canvas\",\n  \"version\": \"1.5.4\",\n  \"author\": \"Ryan Day <soldair@gmail.com>\",\n  \"contributors\": [\n    \"Vincenzo Greco <greco.vincenzo@gmail.com>\",\n    \"Linus Unnebäck <linus@folkdatorn.se>\"\n  ],\n  \"keywords\": [\n    \"qr\",\n    \"code\",\n    \"canvas\",\n    \"qrcode\"\n  ],\n  \"main\": \"./lib/index.js\",\n  \"browser\": {\n    \"./lib/index.js\": \"./lib/browser.js\",\n    \"fs\": false\n  },\n  \"files\": [\n    \"bin\",\n    \"build\",\n    \"lib\",\n    \"helper\"\n  ],\n  \"homepage\": \"http://github.com/soldair/node-qrcode\",\n  \"license\": \"MIT\",\n  \"scripts\": {\n    \"lint\": \"standard\",\n    \"pretest\": \"npm run lint\",\n    \"test\": \"node --throw-deprecation test.js\",\n    \"build\": \"rollup -c\",\n    \"prepublish\": \"npm run build\",\n    \"browser\": \"node examples/clientsideserver.js\"\n  },\n  \"bin\": {\n    \"qrcode\": \"./bin/qrcode\"\n  },\n  \"dependencies\": {\n    \"dijkstrajs\": \"^1.0.1\",\n    \"pngjs\": \"^5.0.0\",\n    \"yargs\": \"^15.3.1\"\n  },\n  \"devDependencies\": {\n    \"@babel/core\": \"^7.9.0\",\n    \"@babel/preset-env\": \"^7.9.5\",\n    \"@rollup/plugin-commonjs\": \"^11.1.0\",\n    \"@rollup/plugin-node-resolve\": \"^7.1.3\",\n    \"browserify\": \"^16.5.1\",\n    \"canvas\": \"^2.8.0\",\n    \"canvasutil\": \"0.0.4\",\n    \"colors\": \"^1.4.0\",\n    \"express\": \"^4.17.1\",\n    \"htmlparser2\": \"^4.1.0\",\n    \"rollup\": \"^2.6.1\",\n    \"rollup-plugin-babel\": \"^4.4.0\",\n    \"rollup-plugin-terser\": \"^5.3.0\",\n    \"sinon\": \"^9.0.2\",\n    \"standard\": \"^16.0.4\",\n    \"tap\": \"^16.2.0\"\n  },\n  \"repository\": {\n    \"type\": \"git\",\n    \"url\": \"git://github.com/soldair/node-qrcode.git\"\n  },\n  \"engines\": {\n    \"node\": \">=10.13.0\"\n  },\n  \"standard\": {\n    \"ignore\": [\n      \"build/\",\n      \"examples/vendors/\",\n      \"lib/core/regex.js\"\n    ]\n  }\n}\n"
  },
  {
    "path": "rollup.config.js",
    "content": "import babel from 'rollup-plugin-babel'\nimport { terser } from 'rollup-plugin-terser'\nimport commonjs from '@rollup/plugin-commonjs'\nimport resolve from '@rollup/plugin-node-resolve'\n\nconst babelConfig = {\n  babelrc: false,\n  presets: [['@babel/preset-env', { targets: 'defaults, IE >= 10, Safari >= 5.1' }]]\n}\n\nexport default [{\n  input: 'lib/browser.js',\n  output: { file: 'build/qrcode.js', format: 'iife', name: 'QRCode', exports: 'named' },\n  plugins: [commonjs(), resolve(), babel(babelConfig), terser()]\n}, {\n  input: 'helper/to-sjis-browser.js',\n  output: { file: 'build/qrcode.tosjis.js', format: 'iife', exports: 'none' },\n  plugins: [commonjs(), resolve(), babel(babelConfig), terser()]\n}]\n"
  },
  {
    "path": "test/e2e/svg.expected.out",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\"><svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 37 37\" shape-rendering=\"crispEdges\"><path fill=\"#ffffff\" d=\"M0 0h37v37H0z\"/><path stroke=\"#000000\" d=\"M4 4.5h7m1 0h2m1 0h2m1 0h1m1 0h2m2 0h1m1 0h7M4 5.5h1m5 0h1m2 0h1m1 0h1m2 0h1m3 0h3m1 0h1m5 0h1M4 6.5h1m1 0h3m1 0h1m2 0h5m4 0h1m1 0h1m1 0h1m1 0h3m1 0h1M4 7.5h1m1 0h3m1 0h1m1 0h1m1 0h1m2 0h1m1 0h2m1 0h2m2 0h1m1 0h3m1 0h1M4 8.5h1m1 0h3m1 0h1m2 0h1m1 0h2m3 0h5m1 0h1m1 0h3m1 0h1M4 9.5h1m5 0h1m3 0h2m2 0h2m2 0h3m1 0h1m5 0h1M4 10.5h7m1 0h1m1 0h1m1 0h1m1 0h1m1 0h1m1 0h1m1 0h1m1 0h7M14 11.5h5m1 0h1m3 0h1M6 12.5h1m1 0h3m1 0h3m2 0h1m1 0h1m4 0h2m3 0h1m2 0h1M4 13.5h4m1 0h1m2 0h5m1 0h1m1 0h2m1 0h4m3 0h1m1 0h1M7 14.5h6m1 0h1m1 0h4m1 0h1m1 0h3m3 0h1m1 0h2M4 15.5h2m2 0h2m9 0h1m1 0h1m2 0h1m1 0h1m1 0h1m2 0h1M4 16.5h1m2 0h2m1 0h1m1 0h6m1 0h1m3 0h1m2 0h1M5 17.5h1m7 0h1m1 0h2m1 0h1m1 0h2m2 0h4m3 0h2M7 18.5h7m1 0h1m1 0h1m1 0h1m6 0h1m3 0h3M4 19.5h1m1 0h2m1 0h1m10 0h3m1 0h1m1 0h3m3 0h1M4 20.5h1m1 0h2m1 0h3m2 0h1m1 0h1m1 0h5m1 0h3m2 0h1m1 0h1M5 21.5h2m2 0h1m1 0h2m1 0h1m1 0h2m1 0h1m1 0h3m1 0h3m3 0h2M4 22.5h1m1 0h1m3 0h1m1 0h6m2 0h1m1 0h1m2 0h1m1 0h3m1 0h2M5 23.5h1m2 0h2m1 0h2m4 0h1m2 0h1m2 0h2m1 0h1M4 24.5h1m2 0h1m1 0h2m1 0h2m1 0h2m1 0h1m1 0h1m1 0h7m2 0h2M12 25.5h1m2 0h2m1 0h3m3 0h1m3 0h1m2 0h2M4 26.5h7m4 0h1m2 0h4m1 0h2m1 0h1m1 0h1m1 0h3M4 27.5h1m5 0h1m1 0h2m2 0h1m1 0h2m2 0h1m1 0h1m3 0h1m3 0h1M4 28.5h1m1 0h3m1 0h1m1 0h2m5 0h1m4 0h6m1 0h2M4 29.5h1m1 0h3m1 0h1m2 0h1m3 0h2m1 0h1m1 0h1m1 0h1m3 0h1m1 0h1M4 30.5h1m1 0h3m1 0h1m1 0h2m2 0h1m1 0h2m1 0h1m1 0h3m2 0h1m1 0h1m1 0h1M4 31.5h1m5 0h1m2 0h1m1 0h6m2 0h2m1 0h2m3 0h1M4 32.5h7m3 0h1m1 0h1m1 0h2m2 0h4m2 0h1m2 0h2\"/></svg>\n"
  },
  {
    "path": "test/e2e/svgtag.expected.out",
    "content": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 37 37\" shape-rendering=\"crispEdges\"><path fill=\"#ffffff\" d=\"M0 0h37v37H0z\"/><path stroke=\"#000000\" d=\"M4 4.5h7m1 0h2m1 0h2m1 0h1m1 0h2m2 0h1m1 0h7M4 5.5h1m5 0h1m2 0h1m1 0h1m2 0h1m3 0h3m1 0h1m5 0h1M4 6.5h1m1 0h3m1 0h1m2 0h5m4 0h1m1 0h1m1 0h1m1 0h3m1 0h1M4 7.5h1m1 0h3m1 0h1m1 0h1m1 0h1m2 0h1m1 0h2m1 0h2m2 0h1m1 0h3m1 0h1M4 8.5h1m1 0h3m1 0h1m2 0h1m1 0h2m3 0h5m1 0h1m1 0h3m1 0h1M4 9.5h1m5 0h1m3 0h2m2 0h2m2 0h3m1 0h1m5 0h1M4 10.5h7m1 0h1m1 0h1m1 0h1m1 0h1m1 0h1m1 0h1m1 0h1m1 0h7M14 11.5h5m1 0h1m3 0h1M6 12.5h1m1 0h3m1 0h3m2 0h1m1 0h1m4 0h2m3 0h1m2 0h1M4 13.5h4m1 0h1m2 0h5m1 0h1m1 0h2m1 0h4m3 0h1m1 0h1M7 14.5h6m1 0h1m1 0h4m1 0h1m1 0h3m3 0h1m1 0h2M4 15.5h2m2 0h2m9 0h1m1 0h1m2 0h1m1 0h1m1 0h1m2 0h1M4 16.5h1m2 0h2m1 0h1m1 0h6m1 0h1m3 0h1m2 0h1M5 17.5h1m7 0h1m1 0h2m1 0h1m1 0h2m2 0h4m3 0h2M7 18.5h7m1 0h1m1 0h1m1 0h1m6 0h1m3 0h3M4 19.5h1m1 0h2m1 0h1m10 0h3m1 0h1m1 0h3m3 0h1M4 20.5h1m1 0h2m1 0h3m2 0h1m1 0h1m1 0h5m1 0h3m2 0h1m1 0h1M5 21.5h2m2 0h1m1 0h2m1 0h1m1 0h2m1 0h1m1 0h3m1 0h3m3 0h2M4 22.5h1m1 0h1m3 0h1m1 0h6m2 0h1m1 0h1m2 0h1m1 0h3m1 0h2M5 23.5h1m2 0h2m1 0h2m4 0h1m2 0h1m2 0h2m1 0h1M4 24.5h1m2 0h1m1 0h2m1 0h2m1 0h2m1 0h1m1 0h1m1 0h7m2 0h2M12 25.5h1m2 0h2m1 0h3m3 0h1m3 0h1m2 0h2M4 26.5h7m4 0h1m2 0h4m1 0h2m1 0h1m1 0h1m1 0h3M4 27.5h1m5 0h1m1 0h2m2 0h1m1 0h2m2 0h1m1 0h1m3 0h1m3 0h1M4 28.5h1m1 0h3m1 0h1m1 0h2m5 0h1m4 0h6m1 0h2M4 29.5h1m1 0h3m1 0h1m2 0h1m3 0h2m1 0h1m1 0h1m1 0h1m3 0h1m1 0h1M4 30.5h1m1 0h3m1 0h1m1 0h2m2 0h1m1 0h2m1 0h1m1 0h3m2 0h1m1 0h1m1 0h1M4 31.5h1m5 0h1m2 0h1m1 0h6m2 0h2m1 0h2m3 0h1M4 32.5h7m3 0h1m1 0h1m1 0h2m2 0h4m2 0h1m2 0h2\"/></svg>\n"
  },
  {
    "path": "test/e2e/terminal.expected.out",
    "content": "\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\n\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\n\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\n\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\n\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\n\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\n\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\n\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\n\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\n\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\n\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\n\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\n\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\n\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\n\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\n\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\n\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\n\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\n\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\n\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\n\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\n\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\n\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\n\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\n\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\n\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[40m  \u001b[0m\u001b[47m  \u001b[0m\n\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\u001b[47m  \u001b[0m\n\n"
  },
  {
    "path": "test/e2e/toCanvas.test.js",
    "content": "const test = require('tap').test\nconst { Canvas, createCanvas } = require('canvas')\nconst QRCode = require('lib')\nconst Helpers = require('test/helpers')\n\ntest('toCanvas - no promise available', function (t) {\n  Helpers.removeNativePromise()\n\n  // Mock document object\n  global.document = {\n    createElement: function (el) {\n      if (el === 'canvas') {\n        return createCanvas(200, 200)\n      }\n    }\n  }\n  const canvasEl = createCanvas(200, 200)\n\n  t.throw(function () { QRCode.toCanvas() },\n    'Should throw if no arguments are provided')\n\n  t.throw(function () { QRCode.toCanvas('some text') },\n    'Should throw if a callback is not provided')\n\n  t.throw(function () { QRCode.toCanvas(canvasEl, 'some text') },\n    'Should throw if a callback is not provided')\n\n  t.throw(function () { QRCode.toCanvas(canvasEl, 'some text', {}) },\n    'Should throw if callback is not a function')\n\n  t.end()\n\n  global.document = undefined\n  Helpers.restoreNativePromise()\n})\n\ntest('toCanvas', function (t) {\n  // Mock document object\n  global.document = {\n    createElement: function (el) {\n      if (el === 'canvas') {\n        return createCanvas(200, 200)\n      }\n    }\n  }\n\n  t.plan(7)\n\n  t.throw(function () { QRCode.toCanvas() },\n    'Should throw if no arguments are provided')\n\n  QRCode.toCanvas('some text', function (err, canvasEl) {\n    t.ok(!err, 'There should be no error')\n    t.ok(canvasEl instanceof Canvas,\n      'Should return a new canvas object')\n  })\n\n  QRCode.toCanvas('some text', {\n    errorCorrectionLevel: 'H'\n  }, function (err, canvasEl) {\n    t.ok(!err, 'There should be no error')\n    t.ok(canvasEl instanceof Canvas,\n      'Should return a new canvas object')\n  })\n\n  QRCode.toCanvas('some text').then(function (canvasEl) {\n    t.ok(canvasEl instanceof Canvas,\n      'Should return a new canvas object (promise)')\n  })\n\n  QRCode.toCanvas('some text', {\n    errorCorrectionLevel: 'H'\n  }).then(function (canvasEl) {\n    t.ok(canvasEl instanceof Canvas,\n      'Should return a new canvas object (promise)')\n  })\n\n  global.document = undefined\n})\n\ntest('toCanvas with specified canvas element', function (t) {\n  const canvasEl = createCanvas(200, 200)\n\n  t.plan(6)\n\n  QRCode.toCanvas(canvasEl, 'some text', function (err, canvasEl) {\n    t.ok(!err, 'There should be no error')\n    t.ok(canvasEl instanceof Canvas,\n      'Should return a new canvas object')\n  })\n\n  QRCode.toCanvas(canvasEl, 'some text', {\n    errorCorrectionLevel: 'H'\n  }, function (err, canvasEl) {\n    t.ok(!err, 'There should be no error')\n    t.ok(canvasEl instanceof Canvas,\n      'Should return a new canvas object')\n  })\n\n  QRCode.toCanvas(canvasEl, 'some text').then(function (canvasEl) {\n    t.ok(canvasEl instanceof Canvas,\n      'Should return a new canvas object (promise)')\n  })\n\n  QRCode.toCanvas(canvasEl, 'some text', {\n    errorCorrectionLevel: 'H'\n  }).then(function (canvasEl) {\n    t.ok(canvasEl instanceof Canvas,\n      'Should return a new canvas object (promise)')\n  })\n})\n"
  },
  {
    "path": "test/e2e/toDataURL.test.js",
    "content": "const test = require('tap').test\nconst QRCode = require('lib')\nconst QRCodeBrowser = require('lib/browser')\nconst { createCanvas } = require('canvas')\nconst Helpers = require('test/helpers')\n\ntest('toDataURL - no promise available', function (t) {\n  Helpers.removeNativePromise()\n\n  t.throw(function () { QRCode.toDataURL() },\n    'Should throw if no arguments are provided')\n\n  t.throw(function () { QRCode.toDataURL(function () {}) },\n    'Should throw if text is not provided')\n\n  t.throw(function () { QRCode.toDataURL('some text') },\n    'Should throw if a callback is not provided')\n\n  t.throw(function () { QRCode.toDataURL('some text', {}) },\n    'Should throw if a callback is not a function')\n\n  t.throw(function () { QRCodeBrowser.toDataURL() },\n    'Should throw if no arguments are provided (browser)')\n\n  t.throw(function () { QRCodeBrowser.toDataURL(function () {}) },\n    'Should throw if text is not provided (browser)')\n\n  t.throw(function () { QRCodeBrowser.toDataURL('some text') },\n    'Should throw if a callback is not provided (browser)')\n\n  t.throw(function () { QRCodeBrowser.toDataURL('some text', {}) },\n    'Should throw if a callback is not a function (browser)')\n\n  t.end()\n\n  Helpers.restoreNativePromise()\n})\n\ntest('toDataURL - image/png', function (t) {\n  const expectedDataURL = [\n    'data:image/png;base64,',\n    'iVBORw0KGgoAAAANSUhEUgAAAHQAAAB0CAYAAABUmhYnAAAAAklEQVR4AewaftIAAAKzSU',\n    'RBVO3BQW7kQAwEwSxC//9y7h55akCQxvYQjIj/scYo1ijFGqVYoxRrlGKNUqxRijVKsUYp',\n    '1ijFGqVYoxRrlGKNUqxRijXKxUNJ+EkqdyShU+mS0Kl0SfhJKk8Ua5RijVKsUS5epvKmJD',\n    'yh8iaVNyXhTcUapVijFGuUiw9Lwh0qdyShU+mS0Kl0Kk8k4Q6VTyrWKMUapVijXHw5lROV',\n    'kyR0Kt+sWKMUa5RijXIxTBI6lS4JkxVrlGKNUqxRLj5M5Tcl4UTlCZW/pFijFGuUYo1y8b',\n    'Ik/KQkdCpdEjqVLgmdykkS/rJijVKsUYo1ysVDKt9M5UTlmxRrlGKNUqxRLh5Kwh0qXRJ+',\n    'UxLuULkjCZ3KJxVrlGKNUqxRLh5S6ZLQqXRJ6FS6JHQqXRKeSEKn0iWhUzlJwolKl4QTlS',\n    'eKNUqxRinWKBe/LAmdSpeETuUkCZ1Kl4QTlS4Jd6h0SehUuiS8qVijFGuUYo1y8WFJ6FS6',\n    'JJyofFISOpVOpUtCp3KicqLypmKNUqxRijXKxYep3JGEE5UuCZ3KHSp3qHRJ6FR+U7FGKd',\n    'YoxRol/scXS8ITKidJeEKlS8KJyhPFGqVYoxRrlIuHkvCTVE5U7kjCicpJEk6S8JOKNUqx',\n    'RinWKBcvU3lTEu5IwolKp/KEyh1J6FTeVKxRijVKsUa5+LAk3KHyJpWTJHQqdyShU/lNxR',\n    'qlWKMUa5SLL6fSJaFLwhNJeCIJP6lYoxRrlGKNcvHlknCicpKEE5UuCSdJOFHpktCpPFGs',\n    'UYo1SrFGufgwlZ+k0iWhU+lUnlDpktCpdEnoVN5UrFGKNUqxRrl4WRL+EpU7ktCpdCpdEj',\n    'qVO5LQqTxRrFGKNUqxRon/scYo1ijFGqVYoxRrlGKNUqxRijVKsUYp1ijFGqVYoxRrlGKN',\n    'UqxRijXKP0OHEepgrecVAAAAAElFTkSuQmCC'].join('')\n\n  t.plan(8)\n\n  t.throw(function () { QRCode.toDataURL() },\n    'Should throw if no arguments are provided')\n\n  QRCode.toDataURL('i am a pony!', {\n    errorCorrectionLevel: 'L',\n    type: 'image/png'\n  }, function (err, url) {\n    t.ok(!err, 'there should be no error ' + err)\n    t.equals(url, expectedDataURL,\n      'url should match expected value for error correction L')\n  })\n\n  QRCode.toDataURL('i am a pony!', {\n    version: 1, // force version=1 to trigger an error\n    errorCorrectionLevel: 'H',\n    type: 'image/png'\n  }, function (err, url) {\n    t.ok(err, 'there should be an error ')\n    t.notOk(url, 'url should be null')\n  })\n\n  t.equals(typeof QRCode.toDataURL('i am a pony!').then, 'function',\n    'Should return a promise')\n\n  QRCode.toDataURL('i am a pony!', {\n    errorCorrectionLevel: 'L',\n    type: 'image/png'\n  }).then(function (url) {\n    t.equals(url, expectedDataURL,\n      'url should match expected value for error correction L (promise)')\n  })\n\n  QRCode.toDataURL('i am a pony!', {\n    version: 1, // force version=1 to trigger an error\n    errorCorrectionLevel: 'H',\n    type: 'image/png'\n  }).catch(function (err) {\n    t.ok(err, 'there should be an error (promise)')\n  })\n})\n\ntest('Canvas toDataURL - image/png', function (t) {\n  const expectedDataURL = [\n    'data:image/png;base64,',\n    'iVBORw0KGgoAAAANSUhEUgAAAIQAAACECAYAAABRRIOnAAAABmJLR0QA/wD/AP+gvaeTAA',\n    'AC20lEQVR4nO3dQY7jMAwEwM1i///lzGUurYtWEEknQNV1EidjNGhFpuTX+/1+/4Fff5/+',\n    'AnwWgSAIBEEgCAJBEAiCQBAEgiAQBIEgCARBIAgCQRAIgkAQ/t0e4PV6VXyP/7a2b6yff9',\n    'vecXq83eufPj+nVAiCQBAEgnA9hlhVt2jursGn1/hbt2OW6fNzSoUgCARBIAjlY4jV6TWu',\n    'ex7hdt7g6TFA9zIaFYIgEASBILSPIbrdjhlWt/civn2prApBEAiCQBC+fgzR3R8xfa/kaS',\n    'oEQSAIAkFoH0N82u/y03sVuzFJ9xhlmgpBEAiCQBDKxxDTv8u7+x9uP3/3+k+jQhAEgiAQ',\n    'hOsxxNO/o0/7G07/fuvp83NKhSAIBEEgCK/u52VUzwNUr6Ponkc4Pb3V+1OcUiEIAkEQCE',\n    'L5HlPT17zuPZ1ux0Dde2BVUyEIAkEQCEL5vYzTa271NfF2nUb1vMj097mlQhAEgiAQhPG1',\n    'nbf3IqbnBXZjnuq9sKfncVYqBEEgCAJBGL+XsTqdp6g+/qr7Gr2q/n/0Q1BKIAgCQSjvqa',\n    'z+3b07/qq6h3G6Z3P3/h1jCEoJBEEgCO3zEJ/ej3Cq+hlb3etSTqkQBIEgCATh4+YhqucF',\n    'nu5fmD7+LRWCIBAEgSA83g+xmu45nH4m1+3nd1MhCAJBEAhC+x5T3br7I05193d0P5tchS',\n    'AIBEEgCOXzEN1un3lV/Qyt6nUe3f0OOyoEQSAIAkEo3x+ielrj9Bq96h5z7Dx9b+eUCkEQ',\n    'CIJAENr3mJpemzjdU7l7/7dRIQgCQRAIwvg+ldWm13Wc6t4Hs5oKQRAIgkAQvn4MUb1WdP',\n    'q5nKevt08lowSCIBCE9jHE9F7R0/MGu7/f9lDqh+BRAkEQCML12s6n12Wcqp5n6N5X8/Tz',\n    'zENQSiAIAkH4+v0hqKVCEASCIBAEgSAIBEEgCAJBEAiCQBAEgiAQBIEgCARBIAgCQfgBlZ',\n    '7HAm5AupgAAAAASUVORK5CYII='].join('')\n\n  t.plan(11)\n\n  t.throw(function () { QRCodeBrowser.toDataURL() },\n    'Should throw if no arguments are provided')\n\n  t.throw(function () { QRCodeBrowser.toDataURL(function () {}) },\n    'Should throw if text is not provided')\n\n  const canvas = createCanvas(200, 200)\n  QRCodeBrowser.toDataURL(canvas, 'i am a pony!', {\n    errorCorrectionLevel: 'H',\n    type: 'image/png'\n  }, function (err, url) {\n    t.ok(!err, 'there should be no error ' + err)\n    t.equals(url, expectedDataURL, 'url generated should match expected value')\n  })\n\n  QRCodeBrowser.toDataURL(canvas, 'i am a pony!', {\n    version: 1, // force version=1 to trigger an error\n    errorCorrectionLevel: 'H',\n    type: 'image/png'\n  }, function (err, url) {\n    t.ok(err, 'there should be an error ')\n    t.notOk(url, 'url should be null')\n  })\n\n  QRCodeBrowser.toDataURL(canvas, 'i am a pony!', {\n    errorCorrectionLevel: 'H',\n    type: 'image/png'\n  }).then(function (url) {\n    t.equals(url, expectedDataURL, 'url generated should match expected value (promise)')\n  })\n\n  QRCodeBrowser.toDataURL(canvas, 'i am a pony!', {\n    version: 1, // force version=1 to trigger an error\n    errorCorrectionLevel: 'H',\n    type: 'image/png'\n  }).catch(function (err) {\n    t.ok(err, 'there should be an error (promise)')\n  })\n\n  // Mock document object\n  global.document = {\n    createElement: function (el) {\n      if (el === 'canvas') {\n        return createCanvas(200, 200)\n      }\n    }\n  }\n\n  QRCodeBrowser.toDataURL('i am a pony!', {\n    errorCorrectionLevel: 'H',\n    type: 'image/png'\n  }, function (err, url) {\n    t.ok(!err, 'there should be no error ' + err)\n    t.equals(url, expectedDataURL, 'url generated should match expected value')\n  })\n\n  QRCodeBrowser.toDataURL('i am a pony!', {\n    errorCorrectionLevel: 'H',\n    type: 'image/png'\n  }).then(function (url) {\n    t.equals(url, expectedDataURL, 'url generated should match expected value (promise)')\n  })\n})\n"
  },
  {
    "path": "test/e2e/toFile.test.js",
    "content": "const test = require('tap').test\nconst fs = require('fs')\nconst path = require('path')\nconst os = require('os')\nconst sinon = require('sinon')\nconst QRCode = require('lib')\nconst Helpers = require('test/helpers')\nconst StreamMock = require('test/mocks/writable-stream')\n\ntest('toFile - no promise available', function (t) {\n  Helpers.removeNativePromise()\n  const fileName = path.join(os.tmpdir(), 'qrimage.png')\n\n  t.throw(function () { QRCode.toFile(fileName, 'some text') },\n    'Should throw if a callback is not provided')\n\n  t.throw(function () { QRCode.toFile(fileName, 'some text', {}) },\n    'Should throw if a callback is not a function')\n\n  t.end()\n\n  Helpers.restoreNativePromise()\n})\n\ntest('toFile', function (t) {\n  const fileName = path.join(os.tmpdir(), 'qrimage.png')\n\n  t.throw(function () { QRCode.toFile('some text', function () {}) },\n    'Should throw if path is not provided')\n\n  t.throw(function () { QRCode.toFile(fileName) },\n    'Should throw if text is not provided')\n\n  t.equal(typeof QRCode.toFile(fileName, 'some text').then, 'function',\n    'Should return a promise')\n\n  t.end()\n})\n\ntest('toFile png', function (t) {\n  const fileName = path.join(os.tmpdir(), 'qrimage.png')\n  const expectedBase64Output = [\n    'iVBORw0KGgoAAAANSUhEUgAAAHQAAAB0CAYAAABUmhYnAAAAAklEQVR4AewaftIAAAKzSU',\n    'RBVO3BQW7kQAwEwSxC//9y7h55akCQxvYQjIj/scYo1ijFGqVYoxRrlGKNUqxRijVKsUYp',\n    '1ijFGqVYoxRrlGKNUqxRijXKxUNJ+EkqdyShU+mS0Kl0SfhJKk8Ua5RijVKsUS5epvKmJD',\n    'yh8iaVNyXhTcUapVijFGuUiw9Lwh0qdyShU+mS0Kl0Kk8k4Q6VTyrWKMUapVijXHw5lROV',\n    'kyR0Kt+sWKMUa5RijXIxTBI6lS4JkxVrlGKNUqxRLj5M5Tcl4UTlCZW/pFijFGuUYo1y8b',\n    'Ik/KQkdCpdEjqVLgmdykkS/rJijVKsUYo1ysVDKt9M5UTlmxRrlGKNUqxRLh5Kwh0qXRJ+',\n    'UxLuULkjCZ3KJxVrlGKNUqxRLh5S6ZLQqXRJ6FS6JHQqXRKeSEKn0iWhUzlJwolKl4QTlS',\n    'eKNUqxRinWKBe/LAmdSpeETuUkCZ1Kl4QTlS4Jd6h0SehUuiS8qVijFGuUYo1y8WFJ6FS6',\n    'JJyofFISOpVOpUtCp3KicqLypmKNUqxRijXKxYep3JGEE5UuCZ3KHSp3qHRJ6FR+U7FGKd',\n    'YoxRol/scXS8ITKidJeEKlS8KJyhPFGqVYoxRrlIuHkvCTVE5U7kjCicpJEk6S8JOKNUqx',\n    'RinWKBcvU3lTEu5IwolKp/KEyh1J6FTeVKxRijVKsUa5+LAk3KHyJpWTJHQqdyShU/lNxR',\n    'qlWKMUa5SLL6fSJaFLwhNJeCIJP6lYoxRrlGKNcvHlknCicpKEE5UuCSdJOFHpktCpPFGs',\n    'UYo1SrFGufgwlZ+k0iWhU+lUnlDpktCpdEnoVN5UrFGKNUqxRrl4WRL+EpU7ktCpdCpdEj',\n    'qVO5LQqTxRrFGKNUqxRon/scYo1ijFGqVYoxRrlGKNUqxRijVKsUYp1ijFGqVYoxRrlGKN',\n    'UqxRijXKP0OHEepgrecVAAAAAElFTkSuQmCC'].join('')\n\n  t.plan(8)\n\n  QRCode.toFile(fileName, 'i am a pony!', {\n    errorCorrectionLevel: 'L'\n  }, function (err) {\n    t.ok(!err, 'There should be no error')\n\n    fs.stat(fileName, function (err) {\n      t.ok(!err,\n        'Should save file with correct file name')\n    })\n\n    fs.readFile(fileName, function (err, buffer) {\n      if (err) throw err\n\n      t.equal(buffer.toString('base64'), expectedBase64Output,\n        'Should write correct content')\n    })\n  })\n\n  QRCode.toFile(fileName, 'i am a pony!', {\n    errorCorrectionLevel: 'L',\n    type: 'png'\n  }, function (err) {\n    t.ok(!err, 'There should be no errors if file type is specified')\n  })\n\n  QRCode.toFile(fileName, 'i am a pony!', {\n    errorCorrectionLevel: 'L'\n  }).then(function () {\n    fs.stat(fileName, function (err) {\n      t.ok(!err,\n        'Should save file with correct file name (promise)')\n    })\n\n    fs.readFile(fileName, function (err, buffer) {\n      if (err) throw err\n\n      t.equal(buffer.toString('base64'), expectedBase64Output,\n        'Should write correct content (promise)')\n    })\n  })\n\n  const fsStub = sinon.stub(fs, 'createWriteStream')\n  fsStub.returns(new StreamMock().forceErrorOnWrite())\n\n  QRCode.toFile(fileName, 'i am a pony!', {\n    errorCorrectionLevel: 'L'\n  }, function (err) {\n    t.ok(err, 'There should be an error')\n  })\n\n  QRCode.toFile(fileName, 'i am a pony!', {\n    errorCorrectionLevel: 'L'\n  }).catch(function (err) {\n    t.ok(err, 'Should catch an error (promise)')\n  })\n\n  fsStub.restore()\n})\n\ntest('toFile svg', function (t) {\n  const fileName = path.join(os.tmpdir(), 'qrimage.svg')\n  const expectedOutput = fs.readFileSync(\n    path.join(__dirname, '/svg.expected.out'), 'UTF-8')\n\n  t.plan(6)\n\n  QRCode.toFile(fileName, 'http://www.google.com', {\n    errorCorrectionLevel: 'H'\n  }, function (err) {\n    t.ok(!err, 'There should be no error')\n\n    fs.stat(fileName, function (err) {\n      t.ok(!err,\n        'Should save file with correct file name')\n    })\n\n    fs.readFile(fileName, 'utf8', function (err, content) {\n      if (err) throw err\n      t.equal(content, expectedOutput,\n        'Should write correct content')\n    })\n  })\n\n  QRCode.toFile(fileName, 'http://www.google.com', {\n    errorCorrectionLevel: 'H',\n    type: 'svg'\n  }, function (err) {\n    t.ok(!err, 'There should be no errors if file type is specified')\n  })\n\n  QRCode.toFile(fileName, 'http://www.google.com', {\n    errorCorrectionLevel: 'H'\n  }).then(function () {\n    fs.stat(fileName, function (err) {\n      t.ok(!err,\n        'Should save file with correct file name (promise)')\n    })\n\n    fs.readFile(fileName, 'utf8', function (err, content) {\n      if (err) throw err\n      t.equal(content, expectedOutput,\n        'Should write correct content (promise)')\n    })\n  })\n})\n\ntest('toFile utf8', function (t) {\n  const fileName = path.join(os.tmpdir(), 'qrimage.txt')\n  const expectedOutput = [\n    '                                 ',\n    '                                 ',\n    '    █▀▀▀▀▀█ █ ▄█  ▀ █ █▀▀▀▀▀█    ',\n    '    █ ███ █ ▀█▄▀▄█ ▀▄ █ ███ █    ',\n    '    █ ▀▀▀ █ ▀▄ ▄ ▄▀ █ █ ▀▀▀ █    ',\n    '    ▀▀▀▀▀▀▀ ▀ ▀ █▄▀ █ ▀▀▀▀▀▀▀    ',\n    '    ▀▄ ▀▀▀▀█▀▀█▄ ▄█▄▀█ ▄█▄██▀    ',\n    '    █▄ ▄▀▀▀▄▄█ █▀▀▄█▀ ▀█ █▄▄█    ',\n    '    █▄ ▄█▄▀█▄▄  ▀ ▄██▀▀ ▄  ▄▀    ',\n    '    █▀▄▄▄▄▀▀█▀▀█▀▀▀█ ▀ ▄█▀█▀█    ',\n    '    ▀ ▀▀▀▀▀▀███▄▄▄▀ █▀▀▀█ ▀█     ',\n    '    █▀▀▀▀▀█ █▀█▀▄ ▄▄█ ▀ █▀ ▄█    ',\n    '    █ ███ █ █ █ ▀▀██▀███▀█ ██    ',\n    '    █ ▀▀▀ █  █▀ ▀ █ ▀▀▄██ ███    ',\n    '    ▀▀▀▀▀▀▀ ▀▀▀  ▀▀ ▀    ▀  ▀    ',\n    '                                 ',\n    '                                 '].join('\\n')\n\n  t.plan(6)\n\n  QRCode.toFile(fileName, 'http://www.google.com', function (err) {\n    t.ok(!err, 'There should be no error')\n\n    fs.stat(fileName, function (err) {\n      t.ok(!err,\n        'Should save file with correct file name')\n    })\n\n    fs.readFile(fileName, 'utf8', function (err, content) {\n      if (err) throw err\n      t.equal(content, expectedOutput,\n        'Should write correct content')\n    })\n  })\n\n  QRCode.toFile(fileName, 'http://www.google.com', {\n    errorCorrectionLevel: 'M',\n    type: 'utf8'\n  }, function (err) {\n    t.ok(!err, 'There should be no errors if file type is specified')\n  })\n\n  QRCode.toFile(fileName, 'http://www.google.com')\n    .then(function () {\n      fs.stat(fileName, function (err) {\n        t.ok(!err,\n          'Should save file with correct file name (promise)')\n      })\n\n      fs.readFile(fileName, 'utf8', function (err, content) {\n        if (err) throw err\n        t.equal(content, expectedOutput,\n          'Should write correct content (promise)')\n      })\n    })\n})\n\ntest('toFile manual segments', function (t) {\n  const fileName = path.join(os.tmpdir(), 'qrimage.txt')\n  const segs = [\n    { data: 'ABCDEFG', mode: 'alphanumeric' },\n    { data: '0123456', mode: 'numeric' }\n  ]\n  const expectedOutput = [\n    '                             ',\n    '                             ',\n    '    █▀▀▀▀▀█ ██▀██ █▀▀▀▀▀█    ',\n    '    █ ███ █  █▀█▄ █ ███ █    ',\n    '    █ ▀▀▀ █ █ ▄ ▀ █ ▀▀▀ █    ',\n    '    ▀▀▀▀▀▀▀ █▄█▄▀ ▀▀▀▀▀▀▀    ',\n    '    ▀██ ▄▀▀▄█▀▀▀▀██▀▀▄ █▀    ',\n    '     ▀█▀▀█▀█▄ ▄ ▄█▀▀▀█▀      ',\n    '    ▀ ▀▀▀ ▀ ▄▀ ▄ ▄▀▄  ▀▄     ',\n    '    █▀▀▀▀▀█ ▄  █▀█ ▀▀▀▄█▄    ',\n    '    █ ███ █  █▀▀▀ ██▀▀ ▀▀    ',\n    '    █ ▀▀▀ █ ██  ▄▀▀▀▀▄▀▀█    ',\n    '    ▀▀▀▀▀▀▀ ▀    ▀▀▀▀ ▀▀▀    ',\n    '                             ',\n    '                             '].join('\\n')\n  t.plan(3)\n\n  QRCode.toFile(fileName, segs, {\n    errorCorrectionLevel: 'L'\n  }, function (err) {\n    t.ok(!err, 'There should be no errors if text is not string')\n\n    fs.stat(fileName, function (err) {\n      t.ok(!err,\n        'Should save file with correct file name')\n    })\n\n    fs.readFile(fileName, 'utf8', function (err, content) {\n      if (err) throw err\n      t.equal(content, expectedOutput,\n        'Should write correct content')\n    })\n  })\n})\n"
  },
  {
    "path": "test/e2e/toFileStream.test.js",
    "content": "const test = require('tap').test\nconst sinon = require('sinon')\nconst QRCode = require('lib')\nconst StreamMock = require('../mocks/writable-stream')\n\ntest('toFileStream png', function (t) {\n  t.throw(function () { QRCode.toFileStream('some text') },\n    'Should throw if stream is not provided')\n\n  t.throw(function () { QRCode.toFileStream(new StreamMock()) },\n    'Should throw if text is not provided')\n\n  const fstream = new StreamMock()\n  const spy = sinon.spy(fstream, 'emit')\n\n  QRCode.toFileStream(fstream, 'i am a pony!')\n\n  QRCode.toFileStream(fstream, 'i am a pony!', {\n    type: 'image/png'\n  })\n\n  t.ok(spy.neverCalledWith('error'),\n    'There should be no error')\n\n  spy.restore()\n  t.end()\n})\n\ntest('toFileStream png with write error', function (t) {\n  const fstreamErr = new StreamMock().forceErrorOnWrite()\n  QRCode.toFileStream(fstreamErr, 'i am a pony!')\n\n  t.plan(2)\n\n  fstreamErr.on('error', function (e) {\n    t.ok(e, 'Should return an error')\n  })\n})\n\ntest('toFileStream png with qrcode error', function (t) {\n  const fstreamErr = new StreamMock()\n  const bigString = Array(200).join('i am a pony!')\n\n  t.plan(2)\n\n  fstreamErr.on('error', function (e) {\n    t.ok(e, 'Should return an error')\n  })\n\n  QRCode.toFileStream(fstreamErr, bigString)\n  QRCode.toFileStream(fstreamErr, 'i am a pony!', {\n    version: 1, // force version=1 to trigger an error\n    errorCorrectionLevel: 'H'\n  })\n})\n"
  },
  {
    "path": "test/e2e/toString.test.js",
    "content": "const test = require('tap').test\nconst fs = require('fs')\nconst path = require('path')\nconst QRCode = require('lib')\nconst browser = require('lib/browser')\nconst Helpers = require('test/helpers')\n\ntest('toString - no promise available', function (t) {\n  Helpers.removeNativePromise()\n\n  t.throw(function () { QRCode.toString() },\n    'Should throw if text is not provided')\n\n  t.throw(function () { QRCode.toString('some text') },\n    'Should throw if a callback is not provided')\n\n  t.throw(function () { QRCode.toString('some text', {}) },\n    'Should throw if a callback is not a function')\n\n  t.throw(function () { QRCode.toString() },\n    'Should throw if text is not provided (browser)')\n\n  t.throw(function () { browser.toString('some text') },\n    'Should throw if a callback is not provided (browser)')\n\n  t.throw(function () { browser.toString('some text', {}) },\n    'Should throw if a callback is not a function (browser)')\n\n  t.end()\n\n  Helpers.restoreNativePromise()\n})\n\ntest('toString', function (t) {\n  t.plan(5)\n\n  t.throw(function () { QRCode.toString() },\n    'Should throw if text is not provided')\n\n  QRCode.toString('some text', function (err, str) {\n    t.ok(!err, 'There should be no error')\n    t.equals(typeof str, 'string',\n      'Should return a string')\n  })\n\n  t.equals(typeof QRCode.toString('some text').then, 'function',\n    'Should return a promise')\n\n  QRCode.toString('some text', { errorCorrectionLevel: 'L' })\n    .then(function (str) {\n      t.equals(typeof str, 'string',\n        'Should return a string')\n    })\n})\n\ntest('toString (browser)', function (t) {\n  t.plan(5)\n\n  t.throw(function () { browser.toString() },\n    'Should throw if text is not provided')\n\n  browser.toString('some text', function (err, str) {\n    t.ok(!err, 'There should be no error (browser)')\n    t.equals(typeof str, 'string',\n      'Should return a string (browser)')\n  })\n\n  t.equals(typeof browser.toString('some text').then, 'function',\n    'Should return a promise')\n\n  browser.toString('some text', { errorCorrectionLevel: 'L' })\n    .then(function (str) {\n      t.equals(typeof str, 'string',\n        'Should return a string')\n    })\n})\n\ntest('toString svg', function (t) {\n  const file = path.join(__dirname, '/svgtag.expected.out')\n  t.plan(6)\n\n  QRCode.toString('http://www.google.com', {\n    version: 1, // force version=1 to trigger an error\n    errorCorrectionLevel: 'H',\n    type: 'svg'\n  }, function (err, code) {\n    t.ok(err, 'there should be an error ')\n    t.notOk(code, 'string should be null')\n  })\n\n  fs.readFile(file, 'utf8', function (err, expectedSvg) {\n    if (err) throw err\n\n    QRCode.toString('http://www.google.com', {\n      errorCorrectionLevel: 'H',\n      type: 'svg'\n    }, function (err, code) {\n      t.ok(!err, 'There should be no error')\n      t.equal(code, expectedSvg, 'should output a valid svg')\n    })\n  })\n\n  QRCode.toString('http://www.google.com', {\n    version: 1, // force version=1 to trigger an error\n    errorCorrectionLevel: 'H',\n    type: 'svg'\n  }).catch(function (err) {\n    t.ok(err, 'there should be an error (promise)')\n  })\n\n  fs.readFile(file, 'utf8', function (err, expectedSvg) {\n    if (err) throw err\n\n    QRCode.toString('http://www.google.com', {\n      errorCorrectionLevel: 'H',\n      type: 'svg'\n    }).then(function (code) {\n      t.equal(code, expectedSvg, 'should output a valid svg (promise)')\n    })\n  })\n})\n\ntest('toString browser svg', function (t) {\n  const file = path.join(__dirname, '/svgtag.expected.out')\n\n  t.plan(3)\n\n  fs.readFile(file, 'utf8', function (err, expectedSvg) {\n    if (err) throw err\n\n    browser.toString('http://www.google.com', {\n      errorCorrectionLevel: 'H',\n      type: 'svg'\n    }, function (err, code) {\n      t.ok(!err, 'There should be no error')\n      t.equal(code, expectedSvg, 'should output a valid svg')\n    })\n\n    browser.toString('http://www.google.com', {\n      errorCorrectionLevel: 'H',\n      type: 'svg'\n    }).then(function (code) {\n      t.equal(code, expectedSvg, 'should output a valid svg (promise)')\n    })\n  })\n})\n\ntest('toString utf8', function (t) {\n  const expectedUtf8 = [\n    '                                 ',\n    '                                 ',\n    '    █▀▀▀▀▀█ █ ▄█  ▀ █ █▀▀▀▀▀█    ',\n    '    █ ███ █ ▀█▄▀▄█ ▀▄ █ ███ █    ',\n    '    █ ▀▀▀ █ ▀▄ ▄ ▄▀ █ █ ▀▀▀ █    ',\n    '    ▀▀▀▀▀▀▀ ▀ ▀ █▄▀ █ ▀▀▀▀▀▀▀    ',\n    '    ▀▄ ▀▀▀▀█▀▀█▄ ▄█▄▀█ ▄█▄██▀    ',\n    '    █▄ ▄▀▀▀▄▄█ █▀▀▄█▀ ▀█ █▄▄█    ',\n    '    █▄ ▄█▄▀█▄▄  ▀ ▄██▀▀ ▄  ▄▀    ',\n    '    █▀▄▄▄▄▀▀█▀▀█▀▀▀█ ▀ ▄█▀█▀█    ',\n    '    ▀ ▀▀▀▀▀▀███▄▄▄▀ █▀▀▀█ ▀█     ',\n    '    █▀▀▀▀▀█ █▀█▀▄ ▄▄█ ▀ █▀ ▄█    ',\n    '    █ ███ █ █ █ ▀▀██▀███▀█ ██    ',\n    '    █ ▀▀▀ █  █▀ ▀ █ ▀▀▄██ ███    ',\n    '    ▀▀▀▀▀▀▀ ▀▀▀  ▀▀ ▀    ▀  ▀    ',\n    '                                 ',\n    '                                 '].join('\\n')\n\n  t.plan(9)\n\n  QRCode.toString('http://www.google.com', {\n    version: 1, // force version=1 to trigger an error\n    errorCorrectionLevel: 'H',\n    type: 'utf8'\n  }, function (err, code) {\n    t.ok(err, 'there should be an error ')\n    t.notOk(code, 'string should be null')\n  })\n\n  QRCode.toString('http://www.google.com', {\n    errorCorrectionLevel: 'M',\n    type: 'utf8'\n  }, function (err, code) {\n    t.ok(!err, 'There should be no error')\n    t.equal(code, expectedUtf8, 'should output a valid symbol')\n  })\n\n  QRCode.toString('http://www.google.com', function (err, code) {\n    t.ok(!err, 'There should be no error')\n    t.equal(code, expectedUtf8,\n      'Should output a valid symbol with default options')\n  })\n\n  QRCode.toString('http://www.google.com', {\n    version: 1, // force version=1 to trigger an error\n    errorCorrectionLevel: 'H',\n    type: 'utf8'\n  }).catch(function (err) {\n    t.ok(err, 'there should be an error (promise)')\n  })\n\n  QRCode.toString('http://www.google.com', {\n    errorCorrectionLevel: 'M',\n    type: 'utf8'\n  }).then(function (code) {\n    t.equal(code, expectedUtf8, 'should output a valid symbol (promise)')\n  })\n\n  QRCode.toString('http://www.google.com').then(function (code) {\n    t.equal(code, expectedUtf8,\n      'Should output a valid symbol with default options (promise)')\n  })\n})\n\ntest('toString terminal', function (t) {\n  const expectedTerminal = fs.readFileSync(path.join(__dirname, '/terminal.expected.out')) + ''\n\n  t.plan(3)\n\n  QRCode.toString('http://www.google.com', {\n    errorCorrectionLevel: 'M',\n    type: 'terminal'\n  }, function (err, code) {\n    t.ok(!err, 'There should be no error')\n    t.equal(code + '\\n', expectedTerminal, 'should output a valid symbol')\n  })\n\n  QRCode.toString('http://www.google.com', {\n    errorCorrectionLevel: 'M',\n    type: 'terminal'\n  }).then(function (code) {\n    t.equal(code + '\\n', expectedTerminal, 'should output a valid symbol (promise)')\n  })\n})\n\ntest('toString byte-input', function (t) {\n  const expectedOutput = [\n    '                             ',\n    '                             ',\n    '    █▀▀▀▀▀█  █▄█▀ █▀▀▀▀▀█    ',\n    '    █ ███ █ ▀█ █▀ █ ███ █    ',\n    '    █ ▀▀▀ █   ▀ █ █ ▀▀▀ █    ',\n    '    ▀▀▀▀▀▀▀ █▄▀▄█ ▀▀▀▀▀▀▀    ',\n    '    ▀██▄██▀▀▀█▀▀ ▀█  ▄▀▄     ',\n    '    ▀█▀▄█▄▀▄ ██ ▀ ▄ ▀▄  ▀    ',\n    '    ▀ ▀ ▀▀▀▀█▄ ▄▀▄▀▄▀▄▀▄▀    ',\n    '    █▀▀▀▀▀█ █  █▄█▀█▄█  ▀    ',\n    '    █ ███ █ ▀█▀▀ ▀██  ▀█▀    ',\n    '    █ ▀▀▀ █ ██▀ ▀ ▄ ▀▄▀▄▀    ',\n    '    ▀▀▀▀▀▀▀ ▀▀▀ ▀ ▀▀▀ ▀▀▀    ',\n    '                             ',\n    '                             '\n  ].join('\\n')\n  const byteInput = new Uint8ClampedArray([1, 2, 3, 4, 5])\n\n  t.plan(2)\n\n  QRCode.toString([{ data: byteInput, mode: 'byte' }], { errorCorrectionLevel: 'L' }, (err, code) => {\n    t.ok(!err, 'there should be no error')\n    t.equal(code, expectedOutput, 'should output the correct code')\n  })\n})\n"
  },
  {
    "path": "test/helpers.js",
    "content": "const nativePromise = global.Promise\n\nexports.removeNativePromise = function () {\n  if (global.Promise) {\n    delete global.Promise\n  }\n}\n\nexports.restoreNativePromise = function () {\n  if (!global.Promise) {\n    global.Promise = nativePromise\n  }\n}\n"
  },
  {
    "path": "test/mocks/writable-stream.js",
    "content": "const stream = require('stream')\nconst util = require('util')\n\nfunction WritableStream () {\n  stream.Writable.call(this)\n  this.forceError = false\n\n  this.once('finish', function () {\n    this.close()\n  })\n}\n\nutil.inherits(WritableStream, stream.Writable)\n\nWritableStream.prototype._write = function (data, encoding, cb) {\n  if (this.forceError) this.emit('error', new Error('Fake error'))\n  cb(this.forceError || null)\n}\n\nWritableStream.prototype.close = function (cb) {\n  this.emit('close')\n  if (cb) cb()\n}\n\nWritableStream.prototype.forceErrorOnWrite = function () {\n  this.forceError = true\n  return this\n}\n\nmodule.exports = WritableStream\n"
  },
  {
    "path": "test/unit/core/alignment-pattern.test.js",
    "content": "const test = require('tap').test\nconst pattern = require('core/alignment-pattern')\n\n/**\n * Row/column coordinates of the center module of each alignment pattern.\n * Each sub-array refers to a qr code version.\n *\n * @type {Array}\n */\nconst EXPECTED_POSITION_TABLE = [\n  [],\n  [6, 18],\n  [6, 22],\n  [6, 26],\n  [6, 30],\n  [6, 34],\n  [6, 22, 38],\n  [6, 24, 42],\n  [6, 26, 46],\n  [6, 28, 50],\n  [6, 30, 54],\n  [6, 32, 58],\n  [6, 34, 62],\n  [6, 26, 46, 66],\n  [6, 26, 48, 70],\n  [6, 26, 50, 74],\n  [6, 30, 54, 78],\n  [6, 30, 56, 82],\n  [6, 30, 58, 86],\n  [6, 34, 62, 90],\n  [6, 28, 50, 72, 94],\n  [6, 26, 50, 74, 98],\n  [6, 30, 54, 78, 102],\n  [6, 28, 54, 80, 106],\n  [6, 32, 58, 84, 110],\n  [6, 30, 58, 86, 114],\n  [6, 34, 62, 90, 118],\n  [6, 26, 50, 74, 98, 122],\n  [6, 30, 54, 78, 102, 126],\n  [6, 26, 52, 78, 104, 130],\n  [6, 30, 56, 82, 108, 134],\n  [6, 34, 60, 86, 112, 138],\n  [6, 30, 58, 86, 114, 142],\n  [6, 34, 62, 90, 118, 146],\n  [6, 30, 54, 78, 102, 126, 150],\n  [6, 24, 50, 76, 102, 128, 154],\n  [6, 28, 54, 80, 106, 132, 158],\n  [6, 32, 58, 84, 110, 136, 162],\n  [6, 26, 54, 82, 110, 138, 166],\n  [6, 30, 58, 86, 114, 142, 170]\n]\n\ntest('Alignment pattern - Row/Col coords', function (t) {\n  t.plan(40)\n\n  for (let i = 1; i <= 40; i++) {\n    const pos = pattern.getRowColCoords(i)\n    t.deepEqual(pos, EXPECTED_POSITION_TABLE[i - 1], 'Should return correct coords')\n  }\n})\n\ntest('Alignment pattern - Positions', function (t) {\n  for (let i = 1; i <= 40; i++) {\n    const pos = pattern.getPositions(i)\n    const expectedPos = EXPECTED_POSITION_TABLE[i - 1]\n    const expectedLength = (Math.pow(expectedPos.length, 2) || 3) - 3\n\n    t.equal(pos.length, expectedLength, 'Should return correct number of positions')\n\n    // For each coord value check if it's present in the expected coords table\n    pos.forEach(function (position) {\n      position.forEach(function (coord) {\n        t.notEqual(expectedPos.indexOf(coord), -1, 'Should return valid coord value')\n      })\n    })\n  }\n\n  t.end()\n})\n"
  },
  {
    "path": "test/unit/core/alphanumeric-data.test.js",
    "content": "const test = require('tap').test\nconst BitBuffer = require('core/bit-buffer')\nconst AlphanumericData = require('core/alphanumeric-data')\nconst Mode = require('core/mode')\n\nconst testData = [\n  {\n    data: 'A',\n    length: 1,\n    bitLength: 6,\n    dataBit: [40]\n  },\n  {\n    data: 'AB',\n    length: 2,\n    bitLength: 11,\n    dataBit: [57, 160]\n  },\n  {\n    data: 'ABC12',\n    length: 5,\n    bitLength: 28,\n    dataBit: [57, 168, 116, 32]\n  }\n]\n\ntest('Alphanumeric Data', function (t) {\n  testData.forEach(function (data) {\n    const alphanumericData = new AlphanumericData(data.data)\n\n    t.equal(alphanumericData.mode, Mode.ALPHANUMERIC, 'Mode should be ALPHANUMERIC')\n    t.equal(alphanumericData.getLength(), data.length, 'Should return correct length')\n    t.equal(alphanumericData.getBitsLength(), data.bitLength, 'Should return correct bit length')\n\n    const bitBuffer = new BitBuffer()\n    alphanumericData.write(bitBuffer)\n    t.deepEqual(bitBuffer.buffer, data.dataBit, 'Should write correct data to buffer')\n  })\n\n  t.end()\n})\n"
  },
  {
    "path": "test/unit/core/bit-buffer.test.js",
    "content": "const test = require('tap').test\nconst BitBuffer = require('core/bit-buffer')\n\ntest('Bit Buffer', function (t) {\n  const testData = 0x41 // 'A'\n  const expectedDataBits = [false, true, false, false, false, false, false, true]\n\n  const bitBuffer = new BitBuffer()\n\n  t.equal(bitBuffer.getLengthInBits(), 0, 'Initial length should be 0')\n\n  bitBuffer.put(testData, 8)\n  t.equal(bitBuffer.getLengthInBits(), 8, 'Length should be 8')\n\n  for (let i = 0; i < 8; i++) {\n    t.deepEqual(bitBuffer.get(i), expectedDataBits[i], 'Should return correct bit value')\n  }\n\n  t.end()\n})\n"
  },
  {
    "path": "test/unit/core/bit-matrix.test.js",
    "content": "const test = require('tap').test\nconst BitMatrix = require('core/bit-matrix')\n\ntest('Bit Matrix', function (t) {\n  t.throw(function () { BitMatrix(0) }, 'Should throw if size is 0')\n  t.throw(function () { BitMatrix(-1) }, 'Should throw if size less than 0')\n\n  const bm = new BitMatrix(2)\n\n  t.equal(bm.size, 2, 'Should have correct size')\n  t.equal(bm.data.length, 4, 'Should correctly set buffer size')\n\n  bm.set(0, 1, true, true)\n  t.ok(bm.get(0, 1), 'Should correctly set bit to true')\n  t.ok(bm.isReserved(0, 1), 'Should correctly set bit as reserved')\n\n  bm.xor(0, 1, 1)\n  t.ok(!bm.get(0, 1), 'Should correctly xor bit')\n\n  bm.set(0, 1, false)\n  t.notOk(bm.get(0, 1), 'Should correctly set bit to false')\n\n  t.end()\n})\n"
  },
  {
    "path": "test/unit/core/byte-data.test.js",
    "content": "const test = require('tap').test\nconst BitBuffer = require('core/bit-buffer')\nconst ByteData = require('core/byte-data')\nconst Mode = require('core/mode')\n\ntest('Byte Data: String Input', function (t) {\n  const text = '1234'\n  const textBitLength = 32\n  const textByte = [49, 50, 51, 52] // 1, 2, 3, 4\n  const utf8Text = '\\u00bd + \\u00bc = \\u00be' // 9 char, 12 byte\n\n  const byteData = new ByteData(text)\n\n  t.equal(byteData.mode, Mode.BYTE, 'Mode should be BYTE')\n  t.equal(byteData.getLength(), text.length, 'Should return correct length')\n  t.equal(byteData.getBitsLength(), textBitLength, 'Should return correct bit length')\n\n  const bitBuffer = new BitBuffer()\n  byteData.write(bitBuffer)\n  t.deepEqual(bitBuffer.buffer, textByte, 'Should write correct data to buffer')\n\n  const byteDataUtf8 = new ByteData(utf8Text)\n  t.equal(byteDataUtf8.getLength(), 12, 'Should return correct length for utf8 chars')\n\n  t.end()\n})\n\ntest('Byte Data: Byte Input', function (t) {\n  const bytes = new Uint8ClampedArray([1, 231, 32, 22])\n\n  const byteData = new ByteData(bytes)\n  t.equal(byteData.getLength(), bytes.length, 'Should return correct length')\n  t.equal(byteData.getBitsLength(), bytes.length * 8, 'Should return correct bit length')\n\n  const bitBuffer = new BitBuffer()\n  byteData.write(bitBuffer)\n  t.deepEqual(bitBuffer.buffer, bytes, 'Should write correct data to buffer')\n\n  t.end()\n})\n"
  },
  {
    "path": "test/unit/core/error-correction-code.test.js",
    "content": "const test = require('tap').test\nconst Utils = require('core/utils')\nconst Version = require('core/version')\nconst ECLevel = require('core/error-correction-level')\nconst ECCode = require('core/error-correction-code')\nconst Mode = require('core/mode')\n\ntest('Error correction codewords', function (t) {\n  const levels = [ECLevel.L, ECLevel.M, ECLevel.Q, ECLevel.H]\n\n  for (let v = 1; v <= 40; v++) {\n    const totalCodewords = Utils.getSymbolTotalCodewords(v)\n    const reservedByte = Math.ceil((Mode.getCharCountIndicator(Mode.BYTE, v) + 4) / 8)\n\n    for (let l = 0; l < levels.length; l++) {\n      const dataCodewords = Version.getCapacity(v, levels[l], Mode.BYTE) + reservedByte\n\n      const expectedCodewords = totalCodewords - dataCodewords\n\n      t.equal(ECCode.getTotalCodewordsCount(v, levels[l]), expectedCodewords,\n        'Should return correct codewords number')\n    }\n  }\n\n  t.equal(ECCode.getTotalCodewordsCount(1), undefined,\n    'Should return undefined if EC level is not specified')\n\n  t.end()\n})\n\ntest('Error correction blocks', function (t) {\n  const levels = [ECLevel.L, ECLevel.M, ECLevel.Q, ECLevel.H]\n\n  for (let v = 1; v <= 40; v++) {\n    for (let l = 0; l < levels.length; l++) {\n      t.ok(ECCode.getBlocksCount(v, levels[l]), 'Should return a positive number')\n    }\n  }\n\n  t.equal(ECCode.getBlocksCount(1), undefined,\n    'Should return undefined if EC level is not specified')\n\n  t.end()\n})\n"
  },
  {
    "path": "test/unit/core/error-correction-level.test.js",
    "content": "const test = require('tap').test\nconst ECLevel = require('core/error-correction-level')\n\nconst EC_LEVELS = [ECLevel.L, ECLevel.M, ECLevel.Q, ECLevel.H]\n\ntest('Error level from input value', function (t) {\n  const values = [['l', 'low'], ['m', 'medium'], ['q', 'quartile'], ['h', 'high']]\n\n  for (let l = 0; l < values.length; l++) {\n    for (let i = 0; i < values[l].length; i++) {\n      t.equal(ECLevel.from(values[l][i]), EC_LEVELS[l])\n      t.equal(ECLevel.from(values[l][i].toUpperCase()), EC_LEVELS[l])\n    }\n  }\n\n  t.equal(ECLevel.from(ECLevel.L), ECLevel.L, 'Should return passed level if value is valid')\n  t.equal(ECLevel.from(undefined, ECLevel.M), ECLevel.M, 'Should return default level if value is undefined')\n  t.equal(ECLevel.from('', ECLevel.Q), ECLevel.Q, 'Should return default level if value is invalid')\n\n  t.end()\n})\n\ntest('Error level validity', function (t) {\n  for (let l = 0; l < EC_LEVELS.length; l++) {\n    t.ok(ECLevel.isValid(EC_LEVELS[l]), 'Should return true if error level is valid')\n  }\n\n  t.notOk(ECLevel.isValid(undefined), 'Should return false if level is undefined')\n  t.notOk(ECLevel.isValid({}), 'Should return false if bit property is undefined')\n  t.notOk(ECLevel.isValid({ bit: -1 }), 'Should return false if bit property value is < 0')\n  t.notOk(ECLevel.isValid({ bit: 4 }), 'Should return false if bit property value is > 3')\n\n  t.end()\n})\n"
  },
  {
    "path": "test/unit/core/finder-pattern.test.js",
    "content": "const test = require('tap').test\nconst pattern = require('core/finder-pattern')\n\ntest('Finder pattern', function (t) {\n  for (let i = 1; i <= 40; i++) {\n    t.equal(pattern.getPositions(i).length, 3, 'Should always return 3 pattern positions')\n  }\n\n  t.end()\n})\n"
  },
  {
    "path": "test/unit/core/format-info.test.js",
    "content": "const test = require('tap').test\nconst FormatInfo = require('core/format-info')\nconst ECLevel = require('core/error-correction-level')\nconst MaskPattern = require('core/mask-pattern')\n\nconst EXPECTED_FORMAT_BITS = [\n  [0x77c4, 0x72f3, 0x7daa, 0x789d, 0x662f, 0x6318, 0x6c41, 0x6976],\n  [0x5412, 0x5125, 0x5e7c, 0x5b4b, 0x45f9, 0x40ce, 0x4f97, 0x4aa0],\n  [0x355f, 0x3068, 0x3f31, 0x3a06, 0x24b4, 0x2183, 0x2eda, 0x2bed],\n  [0x1689, 0x13be, 0x1ce7, 0x19d0, 0x0762, 0x0255, 0x0d0c, 0x083b]\n]\n\ntest('Format encoded info', function (t) {\n  const levels = [ECLevel.L, ECLevel.M, ECLevel.Q, ECLevel.H]\n  const patterns = Object.keys(MaskPattern.Patterns).length\n\n  for (let l = 0; l < levels.length; l++) {\n    for (let p = 0; p < patterns; p++) {\n      const bch = FormatInfo.getEncodedBits(levels[l], p)\n      t.equal(bch, EXPECTED_FORMAT_BITS[l][p], 'Should return correct bits')\n    }\n  }\n\n  t.end()\n})\n"
  },
  {
    "path": "test/unit/core/galois-field.test.js",
    "content": "const test = require('tap').test\nconst GF = require('core/galois-field')\n\ntest('Galois Field', function (t) {\n  t.throw(function () { GF.log(0) }, 'Should throw for log(n) with n < 1')\n\n  for (let i = 1; i < 255; i++) {\n    t.equal(GF.log(GF.exp(i)), i, 'log and exp should be one the inverse of the other')\n    t.equal(GF.exp(GF.log(i)), i, 'exp and log should be one the inverse of the other')\n  }\n\n  t.equal(GF.mul(0, 1), 0, 'Should return 0 if first param is 0')\n  t.equal(GF.mul(1, 0), 0, 'Should return 0 if second param is 0')\n  t.equal(GF.mul(0, 0), 0, 'Should return 0 if both params are 0')\n\n  for (let j = 1; j < 255; j++) {\n    t.equal(GF.mul(j, 255 - j), GF.mul(255 - j, j), 'Multiplication should be commutative')\n  }\n\n  t.end()\n})\n"
  },
  {
    "path": "test/unit/core/kanji-data.test.js",
    "content": "const test = require('tap').test\nconst BitBuffer = require('core/bit-buffer')\nconst KanjiData = require('core/kanji-data')\nconst Mode = require('core/mode')\nconst toSJIS = require('helper/to-sjis')\nrequire('core/utils').setToSJISFunction(toSJIS)\n\ntest('Kanji Data', function (t) {\n  const data = '漢字漾癶'\n  const length = 4\n  const bitLength = 52 // length * 13\n\n  const dataBit = [57, 250, 134, 174, 129, 134, 0]\n\n  let kanjiData = new KanjiData(data)\n\n  t.equal(kanjiData.mode, Mode.KANJI, 'Mode should be KANJI')\n  t.equal(kanjiData.getLength(), length, 'Should return correct length')\n  t.equal(kanjiData.getBitsLength(), bitLength, 'Should return correct bit length')\n\n  let bitBuffer = new BitBuffer()\n  kanjiData.write(bitBuffer)\n  t.deepEqual(bitBuffer.buffer, dataBit, 'Should write correct data to buffer')\n\n  kanjiData = new KanjiData('abc')\n  bitBuffer = new BitBuffer()\n  t.throw(function () { kanjiData.write(bitBuffer) }, 'Should throw if data is invalid')\n\n  t.end()\n})\n"
  },
  {
    "path": "test/unit/core/mask-pattern.test.js",
    "content": "const test = require('tap').test\r\nconst BitMatrix = require('core/bit-matrix')\r\nconst MaskPattern = require('core/mask-pattern')\r\n\r\ntest('Mask pattern - Pattern references', function (t) {\r\n  const patternsCount = Object.keys(MaskPattern.Patterns).length\r\n  t.equals(patternsCount, 8, 'Should return 8 patterns')\r\n\r\n  t.end()\r\n})\r\n\r\nconst expectedPattern000 = [\r\n  1, 0, 1, 0, 1, 0,\r\n  0, 1, 0, 1, 0, 1,\r\n  1, 0, 1, 0, 1, 0,\r\n  0, 1, 0, 1, 0, 1,\r\n  1, 0, 1, 0, 1, 0,\r\n  0, 1, 0, 1, 0, 1\r\n]\r\n\r\nconst expectedPattern001 = [\r\n  1, 1, 1, 1, 1, 1,\r\n  0, 0, 0, 0, 0, 0,\r\n  1, 1, 1, 1, 1, 1,\r\n  0, 0, 0, 0, 0, 0,\r\n  1, 1, 1, 1, 1, 1,\r\n  0, 0, 0, 0, 0, 0\r\n]\r\n\r\nconst expectedPattern010 = [\r\n  1, 0, 0, 1, 0, 0,\r\n  1, 0, 0, 1, 0, 0,\r\n  1, 0, 0, 1, 0, 0,\r\n  1, 0, 0, 1, 0, 0,\r\n  1, 0, 0, 1, 0, 0,\r\n  1, 0, 0, 1, 0, 0\r\n]\r\n\r\nconst expectedPattern011 = [\r\n  1, 0, 0, 1, 0, 0,\r\n  0, 0, 1, 0, 0, 1,\r\n  0, 1, 0, 0, 1, 0,\r\n  1, 0, 0, 1, 0, 0,\r\n  0, 0, 1, 0, 0, 1,\r\n  0, 1, 0, 0, 1, 0\r\n]\r\n\r\nconst expectedPattern100 = [\r\n  1, 1, 1, 0, 0, 0,\r\n  1, 1, 1, 0, 0, 0,\r\n  0, 0, 0, 1, 1, 1,\r\n  0, 0, 0, 1, 1, 1,\r\n  1, 1, 1, 0, 0, 0,\r\n  1, 1, 1, 0, 0, 0\r\n]\r\n\r\nconst expectedPattern101 = [\r\n  1, 1, 1, 1, 1, 1,\r\n  1, 0, 0, 0, 0, 0,\r\n  1, 0, 0, 1, 0, 0,\r\n  1, 0, 1, 0, 1, 0,\r\n  1, 0, 0, 1, 0, 0,\r\n  1, 0, 0, 0, 0, 0\r\n]\r\n\r\nconst expectedPattern110 = [\r\n  1, 1, 1, 1, 1, 1,\r\n  1, 1, 1, 0, 0, 0,\r\n  1, 1, 0, 1, 1, 0,\r\n  1, 0, 1, 0, 1, 0,\r\n  1, 0, 1, 1, 0, 1,\r\n  1, 0, 0, 0, 1, 1\r\n]\r\n\r\nconst expectedPattern111 = [\r\n  1, 0, 1, 0, 1, 0,\r\n  0, 0, 0, 1, 1, 1,\r\n  1, 0, 0, 0, 1, 1,\r\n  0, 1, 0, 1, 0, 1,\r\n  1, 1, 1, 0, 0, 0,\r\n  0, 1, 1, 1, 0, 0\r\n]\r\n\r\ntest('MaskPattern validity', function (t) {\r\n  t.notOk(MaskPattern.isValid(), 'Should return false if no input')\r\n  t.notOk(MaskPattern.isValid(''), 'Should return false if value is not a number')\r\n  t.notOk(MaskPattern.isValid(-1), 'Should return false if value is not in range')\r\n  t.notOk(MaskPattern.isValid(8), 'Should return false if value is not in range')\r\n\r\n  t.end()\r\n})\r\n\r\ntest('MaskPattern from value', function (t) {\r\n  t.equal(MaskPattern.from(5), 5, 'Should return correct mask pattern from a number')\r\n  t.equal(MaskPattern.from('5'), 5, 'Should return correct mask pattern from a string')\r\n  t.equal(MaskPattern.from(-1), undefined, 'Should return undefined if value is invalid')\r\n  t.equal(MaskPattern.from(null), undefined, 'Should return undefined if value is null')\r\n\r\n  t.end()\r\n})\r\n\r\ntest('Mask pattern - Apply mask', function (t) {\r\n  const patterns = Object.keys(MaskPattern.Patterns).length\r\n  const expectedPatterns = [\r\n    expectedPattern000, expectedPattern001, expectedPattern010, expectedPattern011,\r\n    expectedPattern100, expectedPattern101, expectedPattern110, expectedPattern111\r\n  ]\r\n\r\n  for (let p = 0; p < patterns; p++) {\r\n    const matrix = new BitMatrix(6)\r\n    MaskPattern.applyMask(p, matrix)\r\n    t.deepEqual(matrix.data, new Uint8Array(expectedPatterns[p]), 'Should return correct pattern')\r\n  }\r\n\r\n  const matrix = new BitMatrix(2)\r\n  matrix.set(0, 0, false, true)\r\n  matrix.set(0, 1, false, true)\r\n  matrix.set(1, 0, false, true)\r\n  matrix.set(1, 1, false, true)\r\n  MaskPattern.applyMask(0, matrix)\r\n\r\n  t.deepEqual(matrix.data, new Uint8Array([false, false, false, false]), 'Should leave reserved bit unchanged')\r\n\r\n  t.throws(function () { MaskPattern.applyMask(-1, new BitMatrix(1)) }, 'Should throw if pattern is invalid')\r\n\r\n  t.end()\r\n})\r\n\r\ntest('Mask pattern - Penalty N1', function (t) {\r\n  let matrix = new BitMatrix(11)\r\n  matrix.data = [\r\n    1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1,\r\n    1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1,\r\n    0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1,\r\n    1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,\r\n    0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1,\r\n    1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0,\r\n    1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,\r\n    1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,\r\n    1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1,\r\n    1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1,\r\n    0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1\r\n  ]\r\n\r\n  t.equals(MaskPattern.getPenaltyN1(matrix), 59,\r\n    'Should return correct penalty points')\r\n\r\n  matrix = new BitMatrix(6)\r\n  matrix.data = expectedPattern000\r\n\r\n  t.equals(MaskPattern.getPenaltyN1(matrix), 0,\r\n    'Should return correct penalty points')\r\n\r\n  matrix.data = expectedPattern001\r\n\r\n  t.equals(MaskPattern.getPenaltyN1(matrix), 24,\r\n    'Should return correct penalty points')\r\n\r\n  matrix.data = expectedPattern010\r\n\r\n  t.equals(MaskPattern.getPenaltyN1(matrix), 24,\r\n    'Should return correct penalty points')\r\n\r\n  matrix.data = expectedPattern101\r\n\r\n  t.equals(MaskPattern.getPenaltyN1(matrix), 20,\r\n    'Should return correct penalty points')\r\n\r\n  t.end()\r\n})\r\n\r\ntest('Mask pattern - Penalty N2', function (t) {\r\n  let matrix = new BitMatrix(8)\r\n  matrix.data = [\r\n    1, 1, 1, 1, 1, 1, 1, 1,\r\n    1, 1, 1, 0, 0, 0, 1, 1,\r\n    0, 1, 1, 1, 0, 0, 1, 1,\r\n    1, 0, 0, 0, 1, 1, 0, 1,\r\n    0, 0, 0, 0, 0, 0, 0, 0,\r\n    1, 0, 1, 1, 0, 0, 0, 0,\r\n    1, 1, 1, 1, 1, 0, 0, 0,\r\n    1, 1, 0, 0, 1, 0, 1, 1\r\n  ]\r\n\r\n  t.equals(MaskPattern.getPenaltyN2(matrix), 45,\r\n    'Should return correct penalty points')\r\n\r\n  matrix = new BitMatrix(6)\r\n  matrix.data = expectedPattern000\r\n\r\n  t.equals(MaskPattern.getPenaltyN2(matrix), 0,\r\n    'Should return correct penalty points')\r\n\r\n  matrix.data = expectedPattern010\r\n\r\n  t.equals(MaskPattern.getPenaltyN2(matrix), 30,\r\n    'Should return correct penalty points')\r\n\r\n  matrix.data = expectedPattern100\r\n\r\n  t.equals(MaskPattern.getPenaltyN2(matrix), 36,\r\n    'Should return correct penalty points')\r\n\r\n  t.end()\r\n})\r\n\r\ntest('Mask pattern - Penalty N3', function (t) {\r\n  const matrix = new BitMatrix(11)\r\n  matrix.data = [\r\n    0, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1,\r\n    0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1,\r\n    0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1,\r\n    0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1,\r\n    1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,\r\n    1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1,\r\n    0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1,\r\n    1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0,\r\n    0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1,\r\n    1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0,\r\n    1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0\r\n  ]\r\n\r\n  t.equals(MaskPattern.getPenaltyN3(matrix), 160,\r\n    'Should return correct penalty points')\r\n\r\n  matrix.data = [\r\n    1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0,\r\n    1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0,\r\n    1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0,\r\n    1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0,\r\n    1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1,\r\n    1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0,\r\n    0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1,\r\n    1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1,\r\n    0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1,\r\n    1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0,\r\n    1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1\r\n  ]\r\n\r\n  t.equals(MaskPattern.getPenaltyN3(matrix), 280,\r\n    'Should return correct penalty points')\r\n\r\n  t.end()\r\n})\r\n\r\ntest('Mask pattern - Penalty N4', function (t) {\r\n  const matrix = new BitMatrix(10)\r\n  matrix.data = new Array(50).fill(1).concat(new Array(50).fill(0))\r\n\r\n  t.equals(MaskPattern.getPenaltyN4(matrix), 0,\r\n    'Should return correct penalty points')\r\n\r\n  const matrix2 = new BitMatrix(21)\r\n  matrix2.data = new Array(190).fill(1).concat(new Array(251).fill(0))\r\n\r\n  t.equals(MaskPattern.getPenaltyN4(matrix2), 10,\r\n    'Should return correct penalty points')\r\n\r\n  const matrix3 = new BitMatrix(10)\r\n  matrix3.data = new Array(22).fill(1).concat(new Array(78).fill(0))\r\n\r\n  t.equals(MaskPattern.getPenaltyN4(matrix3), 50,\r\n    'Should return correct penalty points')\r\n\r\n  t.end()\r\n})\r\n\r\ntest('Mask pattern - Best mask', function (t) {\r\n  const matrix = new BitMatrix(11)\r\n  matrix.data = [\r\n    0, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1,\r\n    0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1,\r\n    0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1,\r\n    0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1,\r\n    1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,\r\n    1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1,\r\n    0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1,\r\n    1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0,\r\n    0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1,\r\n    1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0,\r\n    1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0\r\n  ]\r\n\r\n  const mask = MaskPattern.getBestMask(matrix, function () {})\r\n  t.ok(!isNaN(mask), 'Should return a number')\r\n\r\n  t.ok(mask >= 0 && mask < 8,\r\n    'Should return a number in range 0,7')\r\n\r\n  t.end()\r\n})\r\n"
  },
  {
    "path": "test/unit/core/mode.test.js",
    "content": "const test = require('tap').test\nconst Mode = require('core/mode')\n\ntest('Mode bits', function (t) {\n  const EXPECTED_BITS = {\n    numeric: 1,\n    alphanumeric: 2,\n    byte: 4,\n    kanji: 8,\n    mixed: -1\n  }\n\n  t.equal(Mode.NUMERIC.bit, EXPECTED_BITS.numeric)\n  t.equal(Mode.ALPHANUMERIC.bit, EXPECTED_BITS.alphanumeric)\n  t.equal(Mode.BYTE.bit, EXPECTED_BITS.byte)\n  t.equal(Mode.KANJI.bit, EXPECTED_BITS.kanji)\n  t.equal(Mode.MIXED.bit, EXPECTED_BITS.mixed)\n\n  t.end()\n})\n\ntest('Char count bits', function (t) {\n  const EXPECTED_BITS = {\n    numeric: [10, 12, 14],\n    alphanumeric: [9, 11, 13],\n    byte: [8, 16, 16],\n    kanji: [8, 10, 12]\n  }\n\n  let v\n  for (v = 1; v < 10; v++) {\n    t.equal(Mode.getCharCountIndicator(Mode.NUMERIC, v), EXPECTED_BITS.numeric[0])\n    t.equal(Mode.getCharCountIndicator(Mode.ALPHANUMERIC, v), EXPECTED_BITS.alphanumeric[0])\n    t.equal(Mode.getCharCountIndicator(Mode.BYTE, v), EXPECTED_BITS.byte[0])\n    t.equal(Mode.getCharCountIndicator(Mode.KANJI, v), EXPECTED_BITS.kanji[0])\n  }\n\n  for (v = 10; v < 27; v++) {\n    t.equal(Mode.getCharCountIndicator(Mode.NUMERIC, v), EXPECTED_BITS.numeric[1])\n    t.equal(Mode.getCharCountIndicator(Mode.ALPHANUMERIC, v), EXPECTED_BITS.alphanumeric[1])\n    t.equal(Mode.getCharCountIndicator(Mode.BYTE, v), EXPECTED_BITS.byte[1])\n    t.equal(Mode.getCharCountIndicator(Mode.KANJI, v), EXPECTED_BITS.kanji[1])\n  }\n\n  for (v = 27; v <= 40; v++) {\n    t.equal(Mode.getCharCountIndicator(Mode.NUMERIC, v), EXPECTED_BITS.numeric[2])\n    t.equal(Mode.getCharCountIndicator(Mode.ALPHANUMERIC, v), EXPECTED_BITS.alphanumeric[2])\n    t.equal(Mode.getCharCountIndicator(Mode.BYTE, v), EXPECTED_BITS.byte[2])\n    t.equal(Mode.getCharCountIndicator(Mode.KANJI, v), EXPECTED_BITS.kanji[2])\n  }\n\n  t.throw(function () { Mode.getCharCountIndicator({}, 1) },\n    'Should throw if mode is invalid')\n\n  t.throw(function () { Mode.getCharCountIndicator(Mode.BYTE, 0) },\n    'Should throw if version is invalid')\n\n  t.end()\n})\n\ntest('Best mode', function (t) {\n  /* eslint-disable quote-props */\n  const EXPECTED_MODE = {\n    '12345': Mode.NUMERIC,\n    'abcde': Mode.BYTE,\n    '1234a': Mode.BYTE,\n    'ABCDa': Mode.BYTE,\n    'ABCDE': Mode.ALPHANUMERIC,\n    '12ABC': Mode.ALPHANUMERIC,\n    '乂ЁЖぞβ': Mode.KANJI,\n    'ΑΒΓψωЮЯабв': Mode.KANJI,\n    '皿a晒三': Mode.BYTE\n  }\n\n  Object.keys(EXPECTED_MODE).forEach(function (data) {\n    t.equal(Mode.getBestModeForData(data), EXPECTED_MODE[data],\n      'Should return mode ' + Mode.toString(EXPECTED_MODE[data]) + ' for data: ' + data)\n  })\n\n  t.end()\n})\n\ntest('Is valid', function (t) {\n  t.ok(Mode.isValid(Mode.NUMERIC))\n  t.ok(Mode.isValid(Mode.ALPHANUMERIC))\n  t.ok(Mode.isValid(Mode.BYTE))\n  t.ok(Mode.isValid(Mode.KANJI))\n\n  t.notOk(Mode.isValid(undefined))\n  t.notOk(Mode.isValid({ bit: 1 }))\n  t.notOk(Mode.isValid({ ccBits: [] }))\n\n  t.end()\n})\n\ntest('From value', function (t) {\n  const modes = [\n    { name: 'numeric', mode: Mode.NUMERIC },\n    { name: 'alphanumeric', mode: Mode.ALPHANUMERIC },\n    { name: 'kanji', mode: Mode.KANJI },\n    { name: 'byte', mode: Mode.BYTE }\n  ]\n\n  for (let m = 0; m < modes.length; m++) {\n    t.equal(Mode.from(modes[m].name), modes[m].mode)\n    t.equal(Mode.from(modes[m].name.toUpperCase()), modes[m].mode)\n    t.equal(Mode.from(modes[m].mode), modes[m].mode)\n  }\n\n  t.equal(Mode.from('', Mode.NUMERIC), Mode.NUMERIC,\n    'Should return default value if mode is invalid')\n\n  t.equal(Mode.from(null, Mode.NUMERIC), Mode.NUMERIC,\n    'Should return default value if mode undefined')\n\n  t.end()\n})\n\ntest('To string', function (t) {\n  t.equal(Mode.toString(Mode.NUMERIC), 'Numeric')\n  t.equal(Mode.toString(Mode.ALPHANUMERIC), 'Alphanumeric')\n  t.equal(Mode.toString(Mode.BYTE), 'Byte')\n  t.equal(Mode.toString(Mode.KANJI), 'Kanji')\n\n  t.throw(function () { Mode.toString({}) }, 'Should throw if mode is invalid')\n\n  t.end()\n})\n"
  },
  {
    "path": "test/unit/core/numeric-data.test.js",
    "content": "const test = require('tap').test\nconst BitBuffer = require('core/bit-buffer')\nconst NumericData = require('core/numeric-data')\nconst Mode = require('core/mode')\n\nconst testData = [\n  {\n    data: 8,\n    length: 1,\n    bitLength: 4,\n    dataBit: [128]\n  },\n  {\n    data: 16,\n    length: 2,\n    bitLength: 7,\n    dataBit: [32]\n  },\n  {\n    data: 128,\n    length: 3,\n    bitLength: 10,\n    dataBit: [32, 0]\n  },\n  {\n    data: 12345,\n    length: 5,\n    bitLength: 17,\n\n    // (123)d -> (0001111011)b 10bit\n    //  (45)d ->    (0101101)b  7bit\n    //\n    //  (00011110)b -> (30)d\n    //  (11010110)b -> (214)d\n    //  (10000000)b -> (128)d\n    dataBit: [30, 214, 128]\n  }\n]\n\ntest('Numeric Data', function (t) {\n  testData.forEach(function (data) {\n    const numericData = new NumericData(data.data)\n\n    t.equal(numericData.mode, Mode.NUMERIC, 'Mode should be NUMERIC')\n    t.equal(numericData.getLength(), data.length, 'Should return correct length')\n    t.equal(numericData.getBitsLength(), data.bitLength, 'Should return correct bit length')\n\n    const bitBuffer = new BitBuffer()\n    numericData.write(bitBuffer)\n    t.deepEqual(bitBuffer.buffer, data.dataBit, 'Should write correct data to buffer')\n  })\n\n  t.end()\n})\n"
  },
  {
    "path": "test/unit/core/polynomial.test.js",
    "content": "const test = require('tap').test\nconst Poly = require('core/polynomial')\n\ntest('Generator polynomial', function (t) {\n  const result = Poly.generateECPolynomial(0)\n  t.ok(result instanceof Uint8Array, 'Should return an Uint8Array')\n  t.deepEqual(result, new Uint8Array([1]), 'Should return coeff [1] for polynomial of degree 0')\n\n  for (let e = 2; e <= 68; e++) {\n    t.equal(Poly.generateECPolynomial(e).length, e + 1, 'Should return a number of coefficients equal to (degree + 1)')\n  }\n\n  t.end()\n})\n\ntest('Polynomial', function (t) {\n  const p1 = [0, 1, 2, 3, 4]\n  const p2 = [5, 6]\n\n  let result = Poly.mul(p1, p2)\n  t.ok(result instanceof Uint8Array, 'Should return an Uint8Array')\n  t.equal(result.length, 6, 'Should return correct number of coefficients')\n\n  result = Poly.mod(p1, Poly.generateECPolynomial(2))\n  t.ok(result instanceof Uint8Array, 'Should return an Uint8Array')\n  t.equal(result.length, 2, 'Should return correct number of coefficients')\n\n  t.end()\n})\n"
  },
  {
    "path": "test/unit/core/qrcode.test.js",
    "content": "const test = require('tap').test\nconst ECLevel = require('core/error-correction-level')\nconst Version = require('core/version')\nconst QRCode = require('core/qrcode')\nconst toSJIS = require('helper/to-sjis')\n\ntest('QRCode interface', function (t) {\n  t.type(QRCode.create, 'function', 'Should have \"create\" function')\n  t.throw(function () { QRCode.create() }, 'Should throw if no data is provided')\n  t.notThrow(function () { QRCode.create('1234567') }, 'Should not throw')\n\n  let qr = QRCode.create('a123456A', {\n    version: 1,\n    maskPattern: 1,\n    errorCorrectionLevel: 'H'\n  })\n  t.equal(qr.modules.size, 21, 'Should return correct modules count')\n  t.equal(qr.maskPattern, 1, 'Should return correct mask pattern')\n\n  const darkModule = qr.modules.get(qr.modules.size - 8, 8)\n  t.ok(darkModule, 'Should have a dark module at coords [size-8][8]')\n\n  t.throw(function () {\n    qr = QRCode.create({})\n  }, 'Should throw if invalid data is passed')\n\n  t.notThrow(function () {\n    qr = QRCode.create('AAAAA00000', { version: 5 })\n  }, 'Should accept data as string')\n\n  t.notThrow(function () {\n    qr = QRCode.create([\n      { data: 'ABCDEFG', mode: 'alphanumeric' },\n      { data: 'abcdefg' },\n      { data: '晒三', mode: 'kanji' },\n      { data: '0123456', mode: 'numeric' }\n    ], { toSJISFunc: toSJIS })\n  }, 'Should accept data as array of objects')\n\n  t.notThrow(function () {\n    qr = QRCode.create('AAAAA00000', { errorCorrectionLevel: 'quartile' })\n    qr = QRCode.create('AAAAA00000', { errorCorrectionLevel: 'q' })\n  }, 'Should accept errorCorrectionLevel as string')\n\n  t.end()\n})\n\ntest('QRCode error correction', function (t) {\n  let qr\n  const ecValues = [\n    { name: ['l', 'low'], level: ECLevel.L },\n    { name: ['m', 'medium'], level: ECLevel.M },\n    { name: ['q', 'quartile'], level: ECLevel.Q },\n    { name: ['h', 'high'], level: ECLevel.H }\n  ]\n\n  for (let l = 0; l < ecValues.length; l++) {\n    for (let i = 0; i < ecValues[l].name.length; i++) {\n      t.notThrow(function () {\n        qr = QRCode.create('ABCDEFG', { errorCorrectionLevel: ecValues[l].name[i] })\n      }, 'Should accept errorCorrectionLevel value: ' + ecValues[l].name[i])\n\n      t.deepEqual(qr.errorCorrectionLevel, ecValues[l].level,\n        'Should have correct errorCorrectionLevel value')\n\n      t.notThrow(function () {\n        qr = QRCode.create('ABCDEFG', { errorCorrectionLevel: ecValues[l].name[i].toUpperCase() })\n      }, 'Should accept errorCorrectionLevel value: ' + ecValues[l].name[i].toUpperCase())\n\n      t.deepEqual(qr.errorCorrectionLevel, ecValues[l].level,\n        'Should have correct errorCorrectionLevel value')\n    }\n  }\n\n  qr = QRCode.create('ABCDEFG')\n  t.equal(qr.errorCorrectionLevel, ECLevel.M, 'Should set default EC level to M')\n\n  t.end()\n})\n\ntest('QRCode version', function (t) {\n  let qr = QRCode.create('data', { version: 9, errorCorrectionLevel: ECLevel.M })\n\n  t.equal(qr.version, 9, 'Should create qrcode with correct version')\n  t.equal(qr.errorCorrectionLevel, ECLevel.M, 'Should set correct EC level')\n\n  t.throw(function () {\n    qr = QRCode.create(new Array(Version.getCapacity(2, ECLevel.H)).join('a'),\n      { version: 1, errorCorrectionLevel: ECLevel.H })\n  }, 'Should throw if data cannot be contained with chosen version')\n\n  t.throw(function () {\n    qr = QRCode.create(new Array(Version.getCapacity(40, ECLevel.H) + 2).join('a'),\n      { version: 40, errorCorrectionLevel: ECLevel.H })\n  }, 'Should throw if data cannot be contained in a qr code')\n\n  t.notThrow(function () {\n    qr = QRCode.create('abcdefg', { version: 'invalid' })\n  }, 'Should use best version if the one provided is invalid')\n\n  t.end()\n})\n\ntest('QRCode capacity', function (t) {\n  let qr\n\n  qr = QRCode.create([{ data: 'abcdefg', mode: 'byte' }])\n  t.equal(qr.version, 1, 'Should contain 7 byte characters')\n\n  qr = QRCode.create([{ data: '12345678901234567', mode: 'numeric' }])\n  t.equal(qr.version, 1, 'Should contain 17 numeric characters')\n\n  qr = QRCode.create([{ data: 'ABCDEFGHIL', mode: 'alphanumeric' }])\n  t.equal(qr.version, 1, 'Should contain 10 alphanumeric characters')\n\n  qr = QRCode.create([{ data: 'ＡＩぐサ', mode: 'kanji' }],\n    { toSJISFunc: toSJIS })\n  t.equal(qr.version, 1, 'Should contain 4 kanji characters')\n\n  t.end()\n})\n"
  },
  {
    "path": "test/unit/core/reed-solomon-encoder.test.js",
    "content": "const test = require('tap').test\nconst RS = require('core/reed-solomon-encoder')\n\ntest('Reed-Solomon encoder', function (t) {\n  let enc = new RS()\n\n  t.notOk(enc.genPoly, 'Should have an undefined generator polynomial')\n  t.throw(function () { enc.encode([]) }, 'Should throw if generator polynomial is undefined')\n\n  enc.initialize(2)\n  t.equal(enc.degree, 2, 'Should set correct degree value')\n  t.ok(enc.genPoly, 'Generator polynomial should be defined')\n\n  const result = enc.encode(new Uint8Array([48, 49, 50, 51, 52]))\n  t.equal(result.length, 2, 'Should return a number of codewords equal to gen poly degree')\n\n  enc = new RS(2)\n  const genPoly = enc.genPoly\n  t.equal(enc.degree, 2, 'Should set correct degree value')\n  t.ok(genPoly, 'Generator polynomial should be defined')\n\n  enc.initialize(3)\n  t.notEqual(enc.genPoly, genPoly, 'Should reinitialize the generator polynomial')\n\n  enc = new RS(0)\n  t.notOk(enc.genPoly, 'Should not create a generator polynomial if degree is 0')\n\n  enc = new RS(1)\n  t.deepEqual(enc.encode(new Uint8Array([0])), new Uint8Array([0]),\n    'Should return correct buffer')\n\n  t.end()\n})\n"
  },
  {
    "path": "test/unit/core/regex.test.js",
    "content": "const test = require('tap').test\nconst Regex = require('core/regex')\n\ntest('Regex', function (t) {\n  t.ok(Regex.NUMERIC instanceof RegExp,\n    'Should export a regex for NUMERIC')\n\n  t.ok(Regex.ALPHANUMERIC instanceof RegExp,\n    'Should export a regex for ALPHANUMERIC')\n\n  t.ok(Regex.BYTE instanceof RegExp,\n    'Should export a regex for BYTE')\n\n  t.ok(Regex.KANJI instanceof RegExp,\n    'Should export a regex for KANJI')\n\n  t.ok(Regex.BYTE_KANJI instanceof RegExp,\n    'Should export a regex for BYTE_KANJI')\n\n  t.end()\n})\n\ntest('Regex test', function (t) {\n  t.ok(Regex.testNumeric('123456'), 'Should return true if is a number')\n  t.notOk(Regex.testNumeric('a12345'), 'Should return false if is not a number')\n  t.notOk(Regex.testNumeric('ABC123'), 'Should return false if is not a number')\n\n  t.ok(Regex.testAlphanumeric('123ABC'), 'Should return true if is alphanumeric')\n  t.ok(Regex.testAlphanumeric('123456'), 'Should return true if is alphanumeric')\n  t.notOk(Regex.testAlphanumeric('ABCabc'), 'Should return false if is not alphanumeric')\n\n  t.ok(Regex.testKanji('乂ЁЖぞβ'), 'Should return true if is a kanji')\n  t.notOk(Regex.testKanji('皿a晒三A'), 'Should return false if is not a kanji')\n  t.notOk(Regex.testKanji('123456'), 'Should return false if is not a kanji')\n  t.notOk(Regex.testKanji('ABC123'), 'Should return false if is not a kanji')\n  t.notOk(Regex.testKanji('abcdef'), 'Should return false if is not a kanji')\n\n  t.end()\n})\n"
  },
  {
    "path": "test/unit/core/segments.test.js",
    "content": "const test = require('tap').test\nconst Mode = require('core/mode')\nconst Segments = require('core/segments')\nconst NumericData = require('core/numeric-data')\nconst AlphanumericData = require('core/alphanumeric-data')\nconst ByteData = require('core/byte-data')\nconst toSJIS = require('helper/to-sjis')\nconst Utils = require('core/utils')\n\nlet testData = [\n  {\n    input: '1A1',\n    result: [{ data: '1A1', mode: Mode.ALPHANUMERIC }]\n  },\n  {\n    input: 'a-1-b-2?',\n    result: [{ data: 'a-1-b-2?', mode: Mode.BYTE }]\n  },\n  {\n    input: 'AB123456CDF',\n    result: [{ data: 'AB123456CDF', mode: Mode.ALPHANUMERIC }]\n  },\n  {\n    input: 'aABC000000-?-----a',\n    result: [\n      { data: 'aABC', mode: Mode.BYTE },\n      { data: '000000', mode: Mode.NUMERIC },\n      { data: '-?-----a', mode: Mode.BYTE }\n    ]\n  },\n  {\n    input: 'aABC000000A?',\n    result: [\n      { data: 'aABC', mode: Mode.BYTE },\n      { data: '000000', mode: Mode.NUMERIC },\n      { data: 'A?', mode: Mode.BYTE }\n    ]\n  },\n  {\n    input: 'a1234ABCDEF?',\n    result: [\n      { data: 'a', mode: Mode.BYTE },\n      { data: '1234ABCDEF', mode: Mode.ALPHANUMERIC },\n      { data: '?', mode: Mode.BYTE }\n    ]\n  },\n  {\n    input: '12345A12345',\n    result: [\n      { data: '12345A12345', mode: Mode.ALPHANUMERIC }\n    ]\n  },\n  {\n    input: 'aABCDEFGHILMNa',\n    result: [\n      { data: 'a', mode: Mode.BYTE },\n      { data: 'ABCDEFGHILMN', mode: Mode.ALPHANUMERIC },\n      { data: 'a', mode: Mode.BYTE }\n    ]\n  },\n  {\n    input: 'Aa12345',\n    result: [\n      { data: 'Aa', mode: Mode.BYTE },\n      { data: '12345', mode: Mode.NUMERIC }\n    ]\n  },\n  {\n    input: 'a1A2B3C4D5E6F4G7',\n    result: [\n      { data: 'a', mode: Mode.BYTE },\n      { data: '1A2B3C4D5E6F4G7', mode: Mode.ALPHANUMERIC }\n    ]\n  },\n  {\n    input: '123456789QWERTYUIOPASD',\n    result: [\n      { data: '123456789', mode: Mode.NUMERIC },\n      { data: 'QWERTYUIOPASD', mode: Mode.ALPHANUMERIC }\n    ]\n  },\n  {\n    input: 'QWERTYUIOPASD123456789',\n    result: [\n      { data: 'QWERTYUIOPASD', mode: Mode.ALPHANUMERIC },\n      { data: '123456789', mode: Mode.NUMERIC }\n    ]\n  },\n  {\n    input: 'ABCDEF123456a',\n    result: [\n      { data: 'ABCDEF123456', mode: Mode.ALPHANUMERIC },\n      { data: 'a', mode: Mode.BYTE }\n    ]\n  },\n  {\n    input: 'abcdefABCDEF',\n    result: [\n      { data: 'abcdef', mode: Mode.BYTE },\n      { data: 'ABCDEF', mode: Mode.ALPHANUMERIC }\n    ]\n  },\n  {\n    input: 'a123456ABCDEa',\n    result: [\n      { data: 'a', mode: Mode.BYTE },\n      { data: '123456ABCDE', mode: Mode.ALPHANUMERIC },\n      { data: 'a', mode: Mode.BYTE }\n    ]\n  },\n  {\n    input: 'AAAAA12345678?A1A',\n    result: [\n      { data: 'AAAAA', mode: Mode.ALPHANUMERIC },\n      { data: '12345678', mode: Mode.NUMERIC },\n      { data: '?A1A', mode: Mode.BYTE }\n    ]\n  },\n  {\n    input: 'Aaa',\n    result: [{ data: 'Aaa', mode: Mode.BYTE }]\n  },\n  {\n    input: 'Aa12345A',\n    result: [\n      { data: 'Aa', mode: Mode.BYTE },\n      { data: '12345A', mode: Mode.ALPHANUMERIC }\n    ]\n  },\n  {\n    input: 'ABC\\nDEF',\n    result: [\n      { data: 'ABC\\nDEF', mode: Mode.BYTE }\n    ]\n  }\n]\n\nconst kanjiTestData = [\n  {\n    input: '乂ЁЖぞβ',\n    result: [{ data: '乂ЁЖぞβ', mode: Mode.KANJI }]\n  },\n  {\n    input: 'ΑΒΓψωЮЯабв',\n    result: [{ data: 'ΑΒΓψωЮЯабв', mode: Mode.KANJI }]\n  },\n  {\n    input: '皿a晒三',\n    result: [\n      { data: '皿a', mode: Mode.BYTE },\n      { data: '晒三', mode: Mode.KANJI }\n    ]\n  },\n  {\n    input: '皿a\\n晒三',\n    result: [\n      { data: '皿a\\n', mode: Mode.BYTE },\n      { data: '晒三', mode: Mode.KANJI }\n    ]\n  }\n]\n\ntestData = testData.concat(kanjiTestData)\n\ntest('Segments from array', function (t) {\n  t.deepEqual(\n    Segments.fromArray(['abcdef', '12345']),\n    [new ByteData('abcdef'), new NumericData('12345')],\n    'Should return correct segment from array of string')\n\n  t.deepEqual(\n    Segments.fromArray([{ data: 'abcdef', mode: Mode.BYTE }, { data: '12345', mode: Mode.NUMERIC }]),\n    [new ByteData('abcdef'), new NumericData('12345')],\n    'Should return correct segment from array of objects')\n\n  t.deepEqual(\n    Segments.fromArray([{ data: 'abcdef', mode: 'byte' }, { data: '12345', mode: 'numeric' }]),\n    [new ByteData('abcdef'), new NumericData('12345')],\n    'Should return correct segment from array of objects if mode is specified as string')\n\n  t.deepEqual(\n    Segments.fromArray([{ data: 'abcdef' }, { data: '12345' }]),\n    [new ByteData('abcdef'), new NumericData('12345')],\n    'Should return correct segment from array of objects if mode is not specified')\n\n  t.deepEqual(Segments.fromArray([{}]), [],\n    'Should return an empty array')\n\n  t.throw(function () { Segments.fromArray([{ data: 'ABCDE', mode: 'numeric' }]) },\n    'Should throw if segment cannot be encoded with specified mode')\n\n  t.deepEqual(\n    Segments.fromArray([{ data: '０１２３', mode: Mode.KANJI }]), [new ByteData('０１２３')],\n    'Should use Byte mode if kanji support is disabled')\n\n  t.end()\n})\n\ntest('Segments optimization', function (t) {\n  t.deepEqual(Segments.fromString('乂ЁЖ', 1), Segments.fromArray([{ data: '乂ЁЖ', mode: 'byte' }]),\n    'Should use Byte mode if Kanji support is disabled')\n\n  Utils.setToSJISFunction(toSJIS)\n  testData.forEach(function (data) {\n    t.deepEqual(Segments.fromString(data.input, 1), Segments.fromArray(data.result))\n  })\n\n  t.end()\n})\n\ntest('Segments raw split', function (t) {\n  const splitted = [\n    new ByteData('abc'),\n    new AlphanumericData('DEF'),\n    new NumericData('123')\n  ]\n\n  t.deepEqual(Segments.rawSplit('abcDEF123'), splitted)\n\n  t.end()\n})\n"
  },
  {
    "path": "test/unit/core/utils.test.js",
    "content": "const test = require('tap').test\nconst Utils = require('core/utils')\n\n/**\n * QR Code sizes. Each element refers to a version\n * @type {Array}\n */\nconst EXPECTED_SYMBOL_SIZES = [\n  21, 25, 29, 33, 37, 41, 45,\n  49, 53, 57, 61, 65, 69, 73,\n  77, 81, 85, 89, 93, 97, 101,\n  105, 109, 113, 117, 121, 125,\n  129, 133, 137, 141, 145, 149,\n  153, 157, 161, 165, 169, 173, 177]\n\ntest('Symbol size', function (t) {\n  t.throws(function () { Utils.getSymbolSize() }, 'Should throw if version is undefined')\n  t.throws(function () { Utils.getSymbolSize(0) }, 'Should throw if version is not in range')\n  t.throws(function () { Utils.getSymbolSize(41) }, 'Should throw if version is not in range')\n\n  for (let i = 1; i <= 40; i++) {\n    t.equal(Utils.getSymbolSize(i), EXPECTED_SYMBOL_SIZES[i - 1], 'Should return correct symbol size')\n  }\n\n  t.end()\n})\n\ntest('Symbol codewords', function (t) {\n  for (let i = 1; i <= 40; i++) {\n    t.ok(Utils.getSymbolTotalCodewords(i), 'Should return positive number')\n  }\n\n  t.end()\n})\n\ntest('BCH Digit', function (t) {\n  const testData = [\n    { data: 0, bch: 0 },\n    { data: 1, bch: 1 },\n    { data: 2, bch: 2 },\n    { data: 4, bch: 3 },\n    { data: 8, bch: 4 }\n  ]\n\n  testData.forEach(function (d) {\n    t.equal(Utils.getBCHDigit(d.data), d.bch,\n      'Should return correct BCH for value: ' + d.data)\n  })\n\n  t.end()\n})\n\ntest('Set/Get SJIS function', function (t) {\n  t.throw(function () { Utils.setToSJISFunction() },\n    'Should throw if param is not a function')\n\n  t.notOk(Utils.isKanjiModeEnabled(),\n    'Kanji mode should be disabled if \"toSJIS\" function is not set')\n\n  const testFunc = function testFunc (c) {\n    return 'test_' + c\n  }\n\n  Utils.setToSJISFunction(testFunc)\n\n  t.ok(Utils.isKanjiModeEnabled(),\n    'Kanji mode should be enabled if \"toSJIS\" function is set')\n\n  t.equal(Utils.toSJIS('a'), 'test_a',\n    'Should correctly call \"toSJIS\" function')\n\n  t.end()\n})\n"
  },
  {
    "path": "test/unit/core/version.test.js",
    "content": "const test = require('tap').test\nconst Version = require('core/version')\nconst VersionCheck = require('core/version-check')\nconst ECLevel = require('core/error-correction-level')\nconst Mode = require('core/mode')\nconst NumericData = require('core/numeric-data')\nconst AlphanumericData = require('core/alphanumeric-data')\nconst KanjiData = require('core/kanji-data')\nconst ByteData = require('core/byte-data')\n\nconst EC_LEVELS = [ECLevel.L, ECLevel.M, ECLevel.Q, ECLevel.H]\n\nconst EXPECTED_NUMERIC_CAPACITY = [\n  [41, 34, 27, 17], [77, 63, 48, 34], [127, 101, 77, 58], [187, 149, 111, 82],\n  [255, 202, 144, 106], [322, 255, 178, 139], [370, 293, 207, 154], [461, 365, 259, 202],\n  [552, 432, 312, 235], [652, 513, 364, 288], [772, 604, 427, 331], [883, 691, 489, 374],\n  [1022, 796, 580, 427], [1101, 871, 621, 468], [1250, 991, 703, 530], [1408, 1082, 775, 602],\n  [1548, 1212, 876, 674], [1725, 1346, 948, 746], [1903, 1500, 1063, 813], [2061, 1600, 1159, 919],\n  [2232, 1708, 1224, 969], [2409, 1872, 1358, 1056], [2620, 2059, 1468, 1108], [2812, 2188, 1588, 1228],\n  [3057, 2395, 1718, 1286], [3283, 2544, 1804, 1425], [3517, 2701, 1933, 1501], [3669, 2857, 2085, 1581],\n  [3909, 3035, 2181, 1677], [4158, 3289, 2358, 1782], [4417, 3486, 2473, 1897], [4686, 3693, 2670, 2022],\n  [4965, 3909, 2805, 2157], [5253, 4134, 2949, 2301], [5529, 4343, 3081, 2361], [5836, 4588, 3244, 2524],\n  [6153, 4775, 3417, 2625], [6479, 5039, 3599, 2735], [6743, 5313, 3791, 2927], [7089, 5596, 3993, 3057]\n]\n\nconst EXPECTED_ALPHANUMERIC_CAPACITY = [\n  [25, 20, 16, 10], [47, 38, 29, 20], [77, 61, 47, 35], [114, 90, 67, 50],\n  [154, 122, 87, 64], [195, 154, 108, 84], [224, 178, 125, 93], [279, 221, 157, 122],\n  [335, 262, 189, 143], [395, 311, 221, 174], [468, 366, 259, 200], [535, 419, 296, 227],\n  [619, 483, 352, 259], [667, 528, 376, 283], [758, 600, 426, 321], [854, 656, 470, 365],\n  [938, 734, 531, 408], [1046, 816, 574, 452], [1153, 909, 644, 493], [1249, 970, 702, 557],\n  [1352, 1035, 742, 587], [1460, 1134, 823, 640], [1588, 1248, 890, 672], [1704, 1326, 963, 744],\n  [1853, 1451, 1041, 779], [1990, 1542, 1094, 864], [2132, 1637, 1172, 910], [2223, 1732, 1263, 958],\n  [2369, 1839, 1322, 1016], [2520, 1994, 1429, 1080], [2677, 2113, 1499, 1150], [2840, 2238, 1618, 1226],\n  [3009, 2369, 1700, 1307], [3183, 2506, 1787, 1394], [3351, 2632, 1867, 1431], [3537, 2780, 1966, 1530],\n  [3729, 2894, 2071, 1591], [3927, 3054, 2181, 1658], [4087, 3220, 2298, 1774], [4296, 3391, 2420, 1852]\n]\n\nconst EXPECTED_KANJI_CAPACITY = [\n  [10, 8, 7, 4], [20, 16, 12, 8], [32, 26, 20, 15], [48, 38, 28, 21],\n  [65, 52, 37, 27], [82, 65, 45, 36], [95, 75, 53, 39], [118, 93, 66, 52],\n  [141, 111, 80, 60], [167, 131, 93, 74], [198, 155, 109, 85], [226, 177, 125, 96],\n  [262, 204, 149, 109], [282, 223, 159, 120], [320, 254, 180, 136], [361, 277, 198, 154],\n  [397, 310, 224, 173], [442, 345, 243, 191], [488, 384, 272, 208], [528, 410, 297, 235],\n  [572, 438, 314, 248], [618, 480, 348, 270], [672, 528, 376, 284], [721, 561, 407, 315],\n  [784, 614, 440, 330], [842, 652, 462, 365], [902, 692, 496, 385], [940, 732, 534, 405],\n  [1002, 778, 559, 430], [1066, 843, 604, 457], [1132, 894, 634, 486], [1201, 947, 684, 518],\n  [1273, 1002, 719, 553], [1347, 1060, 756, 590], [1417, 1113, 790, 605], [1496, 1176, 832, 647],\n  [1577, 1224, 876, 673], [1661, 1292, 923, 701], [1729, 1362, 972, 750], [1817, 1435, 1024, 784]\n]\n\nconst EXPECTED_BYTE_CAPACITY = [\n  [17, 14, 11, 7], [32, 26, 20, 14], [53, 42, 32, 24], [78, 62, 46, 34],\n  [106, 84, 60, 44], [134, 106, 74, 58], [154, 122, 86, 64], [192, 152, 108, 84],\n  [230, 180, 130, 98], [271, 213, 151, 119], [321, 251, 177, 137], [367, 287, 203, 155],\n  [425, 331, 241, 177], [458, 362, 258, 194], [520, 412, 292, 220], [586, 450, 322, 250],\n  [644, 504, 364, 280], [718, 560, 394, 310], [792, 624, 442, 338], [858, 666, 482, 382],\n  [929, 711, 509, 403], [1003, 779, 565, 439], [1091, 857, 611, 461], [1171, 911, 661, 511],\n  [1273, 997, 715, 535], [1367, 1059, 751, 593], [1465, 1125, 805, 625], [1528, 1190, 868, 658],\n  [1628, 1264, 908, 698], [1732, 1370, 982, 742], [1840, 1452, 1030, 790], [1952, 1538, 1112, 842],\n  [2068, 1628, 1168, 898], [2188, 1722, 1228, 958], [2303, 1809, 1283, 983], [2431, 1911, 1351, 1051],\n  [2563, 1989, 1423, 1093], [2699, 2099, 1499, 1139], [2809, 2213, 1579, 1219], [2953, 2331, 1663, 1273]\n]\n\nconst EXPECTED_VERSION_BITS = [\n  0x07C94, 0x085BC, 0x09A99, 0x0A4D3, 0x0BBF6, 0x0C762, 0x0D847, 0x0E60D,\n  0x0F928, 0x10B78, 0x1145D, 0x12A17, 0x13532, 0x149A6, 0x15683, 0x168C9,\n  0x177EC, 0x18EC4, 0x191E1, 0x1AFAB, 0x1B08E, 0x1CC1A, 0x1D33F, 0x1ED75,\n  0x1F250, 0x209D5, 0x216F0, 0x228BA, 0x2379F, 0x24B0B, 0x2542E, 0x26A64,\n  0x27541, 0x28C69\n]\n\ntest('Version validity', function (t) {\n  t.notOk(VersionCheck.isValid(), 'Should return false if no input')\n  t.notOk(VersionCheck.isValid(''), 'Should return false if version is not a number')\n  t.notOk(VersionCheck.isValid(0), 'Should return false if version is not in range')\n  t.notOk(VersionCheck.isValid(41), 'Should return false if version is not in range')\n\n  t.end()\n})\n\ntest('Version from value', function (t) {\n  t.equal(Version.from(5), 5, 'Should return correct version from a number')\n  t.equal(Version.from('5'), 5, 'Should return correct version from a string')\n  t.equal(Version.from(0, 1), 1, 'Should return default value if version is invalid')\n  t.equal(Version.from(null, 1), 1, 'Should return default value if version is undefined')\n\n  t.end()\n})\n\ntest('Version capacity', function (t) {\n  t.throws(function () { Version.getCapacity() }, 'Should throw if version is undefined')\n  t.throws(function () { Version.getCapacity('') }, 'Should throw if version is not a number')\n  t.throws(function () { Version.getCapacity(0) }, 'Should throw if version is not in range')\n  t.throws(function () { Version.getCapacity(41) }, 'Should throw if version is not in range')\n\n  for (let l = 0; l < EC_LEVELS.length; l++) {\n    for (let i = 1; i <= 40; i++) {\n      t.equal(Version.getCapacity(i, EC_LEVELS[l], Mode.NUMERIC),\n        EXPECTED_NUMERIC_CAPACITY[i - 1][l], 'Should return correct numeric mode capacity')\n\n      t.equal(Version.getCapacity(i, EC_LEVELS[l], Mode.ALPHANUMERIC),\n        EXPECTED_ALPHANUMERIC_CAPACITY[i - 1][l], 'Should return correct alphanumeric mode capacity')\n\n      t.equal(Version.getCapacity(i, EC_LEVELS[l], Mode.KANJI),\n        EXPECTED_KANJI_CAPACITY[i - 1][l], 'Should return correct kanji mode capacity')\n\n      t.equal(Version.getCapacity(i, EC_LEVELS[l], Mode.BYTE),\n        EXPECTED_BYTE_CAPACITY[i - 1][l], 'Should return correct byte mode capacity')\n\n      t.equal(Version.getCapacity(i, EC_LEVELS[l]),\n        EXPECTED_BYTE_CAPACITY[i - 1][l], 'Should return correct byte mode capacity')\n    }\n  }\n\n  t.end()\n})\n\ntest('Version best match', function (t) {\n  function testBestVersionForCapacity (expectedCapacity, DataCtor) {\n    for (let v = 0; v < 40; v++) {\n      for (let l = 0; l < EC_LEVELS.length; l++) {\n        const capacity = expectedCapacity[v][l]\n        const data = new DataCtor(new Array(capacity + 1).join('-'))\n\n        t.equal(Version.getBestVersionForData(data, EC_LEVELS[l]), v + 1, 'Should return best version')\n        t.equal(Version.getBestVersionForData([data], EC_LEVELS[l]), v + 1, 'Should return best version')\n\n        if (l === 1) {\n          t.equal(Version.getBestVersionForData(data, null), v + 1,\n            'Should return best version for ECLevel.M if error level is undefined')\n          t.equal(Version.getBestVersionForData([data], null), v + 1,\n            'Should return best version for ECLevel.M if error level is undefined')\n        }\n      }\n    }\n\n    for (let i = 0; i < EC_LEVELS.length; i++) {\n      const exceededCapacity = expectedCapacity[39][i] + 1\n      const tooBigData = new DataCtor(new Array(exceededCapacity + 1).join('-'))\n      const tooBigDataArray = [\n        new DataCtor(new Array(Math.floor(exceededCapacity / 2)).join('-')),\n        new DataCtor(new Array(Math.floor(exceededCapacity / 2) + 1).join('-'))\n      ]\n\n      t.notOk(Version.getBestVersionForData(tooBigData, EC_LEVELS[i]),\n        'Should return undefined if data is too big')\n      t.notOk(Version.getBestVersionForData([tooBigData], EC_LEVELS[i]),\n        'Should return undefined if data is too big')\n      t.notOk(Version.getBestVersionForData(tooBigDataArray, EC_LEVELS[i]),\n        'Should return undefined if data is too big')\n    }\n  }\n\n  testBestVersionForCapacity(EXPECTED_NUMERIC_CAPACITY, NumericData)\n  testBestVersionForCapacity(EXPECTED_ALPHANUMERIC_CAPACITY, AlphanumericData)\n  testBestVersionForCapacity(EXPECTED_KANJI_CAPACITY, KanjiData)\n  testBestVersionForCapacity(EXPECTED_BYTE_CAPACITY, ByteData)\n\n  t.ok(Version.getBestVersionForData([new ByteData('abc'), new NumericData('1234')]),\n    'Should return a version number if input array is valid')\n\n  t.equal(Version.getBestVersionForData([]), 1,\n    'Should return 1 if array is empty')\n\n  t.end()\n})\n\ntest('Version encoded info', function (t) {\n  let v\n\n  for (v = 0; v < 7; v++) {\n    t.throws(function () { Version.getEncodedBits(v) },\n      'Should throw if version is invalid or less than 7')\n  }\n\n  for (v = 7; v <= 40; v++) {\n    const bch = Version.getEncodedBits(v)\n    t.equal(bch, EXPECTED_VERSION_BITS[v - 7], 'Should return correct bits')\n  }\n\n  t.end()\n})\n"
  },
  {
    "path": "test/unit/helper/sjis.test.js",
    "content": "const test = require('tap').test\nconst toSJIS = require('helper/to-sjis')\n\ntest('SJIS from char', function (t) {\n  t.notOk(toSJIS(''),\n    'Should return undefined if character is invalid')\n\n  t.notOk(toSJIS('A'),\n    'Should return undefined if character is not a kanji')\n\n  t.equal(toSJIS('襦'), 0xe640,\n    'Should return correct SJIS value')\n\n  t.equal(toSJIS('￢'), 0x81ca,\n    'Should return correct SJIS value')\n\n  t.equal(toSJIS('≧'), 0x8186,\n    'Should return correct SJIS value')\n\n  t.equal(toSJIS('⊥'), 0x81db,\n    'Should return correct SJIS value')\n\n  t.equal(toSJIS('愛'), 0x88a4,\n    'Should return correct SJIS value')\n\n  t.equal(toSJIS('衣'), 0x88df,\n    'Should return correct SJIS value')\n\n  t.equal(toSJIS('蔭'), 0x88fc,\n    'Should return correct SJIS value')\n\n  t.end()\n})\n"
  },
  {
    "path": "test/unit/renderer/canvas.test.js",
    "content": "const test = require('tap').test\nconst { Canvas, createCanvas } = require('canvas')\nconst QRCode = require('core/qrcode')\nconst CanvasRenderer = require('renderer/canvas')\n\ntest('CanvasRenderer interface', function (t) {\n  t.type(CanvasRenderer.render, 'function',\n    'Should have render function')\n\n  t.type(CanvasRenderer.renderToDataURL, 'function',\n    'Should have renderToDataURL function')\n\n  t.end()\n})\n\ntest('CanvasRenderer render', function (t) {\n  // Mock document object\n  global.document = {\n    createElement: function (el) {\n      if (el === 'canvas') {\n        return createCanvas(200, 200)\n      }\n    }\n  }\n\n  const sampleQrData = QRCode.create('sample text', { version: 2 })\n  let canvasEl\n\n  t.notThrow(function () { canvasEl = CanvasRenderer.render(sampleQrData) },\n    'Should not throw if canvas is not provided')\n\n  t.ok(canvasEl instanceof Canvas,\n    'Should return a new canvas object')\n\n  t.notThrow(function () {\n    canvasEl = CanvasRenderer.render(sampleQrData, {\n      margin: 10,\n      scale: 1\n    })\n  }, 'Should not throw with options param')\n\n  // modules: 25, margins: 10 * 2, scale: 1\n  t.equal(canvasEl.width, 25 + 10 * 2,\n    'Should have correct size')\n\n  t.equal(canvasEl.width, canvasEl.height,\n    'Should be a square image')\n\n  global.document = undefined\n\n  t.throw(function () { canvasEl = CanvasRenderer.render(sampleQrData) },\n    'Should throw if canvas cannot be created')\n\n  t.end()\n})\n\ntest('CanvasRenderer render to provided canvas', function (t) {\n  const sampleQrData = QRCode.create('sample text', { version: 2 })\n  const canvasEl = createCanvas(200, 200)\n\n  t.notThrow(function () { CanvasRenderer.render(sampleQrData, canvasEl) },\n    'Should not throw with only qrData and canvas param')\n\n  t.notThrow(function () {\n    CanvasRenderer.render(sampleQrData, canvasEl, {\n      margin: 10,\n      scale: 1\n    })\n  }, 'Should not throw with options param')\n\n  // modules: 25, margins: 10 * 2, scale: 1\n  t.equal(canvasEl.width, 25 + 10 * 2,\n    'Should have correct size')\n\n  t.equal(canvasEl.width, canvasEl.height,\n    'Should be a square image')\n\n  t.end()\n})\n\ntest('CanvasRenderer renderToDataURL', function (t) {\n  // Mock document object\n  global.document = {\n    createElement: function (el) {\n      if (el === 'canvas') {\n        return createCanvas(200, 200)\n      }\n    }\n  }\n\n  const sampleQrData = QRCode.create('sample text', { version: 2 })\n  let url\n\n  t.notThrow(function () { url = CanvasRenderer.renderToDataURL(sampleQrData) },\n    'Should not throw if canvas is not provided')\n\n  t.notThrow(function () {\n    url = CanvasRenderer.renderToDataURL(sampleQrData, {\n      margin: 10,\n      scale: 1,\n      type: 'image/png'\n    })\n  }, 'Should not throw with options param')\n\n  t.type(url, 'string',\n    'Should return a string')\n\n  t.equal(url.split(',')[0], 'data:image/png;base64',\n    'Should have correct header')\n\n  const b64png = url.split(',')[1]\n  t.equal(b64png.length % 4, 0,\n    'Should have a correct length')\n\n  global.document = undefined\n  t.end()\n})\n\ntest('CanvasRenderer renderToDataURL to provided canvas', function (t) {\n  const sampleQrData = QRCode.create('sample text', { version: 2 })\n  const canvasEl = createCanvas(200, 200)\n  let url\n\n  t.notThrow(function () {\n    url = CanvasRenderer.renderToDataURL(sampleQrData, canvasEl)\n  }, 'Should not throw with only qrData and canvas param')\n\n  t.notThrow(function () {\n    url = CanvasRenderer.renderToDataURL(sampleQrData, canvasEl, {\n      margin: 10,\n      scale: 1,\n      type: 'image/png'\n    })\n  }, 'Should not throw with options param')\n\n  t.type(url, 'string',\n    'Should return a string')\n\n  t.equal(url.split(',')[0], 'data:image/png;base64',\n    'Should have correct header')\n\n  const b64png = url.split(',')[1]\n  t.equal(b64png.length % 4, 0,\n    'Should have a correct length')\n\n  t.end()\n})\n"
  },
  {
    "path": "test/unit/renderer/png.test.js",
    "content": "const test = require('tap').test\nconst sinon = require('sinon')\nconst fs = require('fs')\nconst QRCode = require('core/qrcode')\nconst PngRenderer = require('renderer/png')\nconst PNG = require('pngjs').PNG\nconst StreamMock = require('../../mocks/writable-stream')\n\ntest('PNG renderer interface', function (t) {\n  t.type(PngRenderer.render, 'function',\n    'Should have render function')\n\n  t.type(PngRenderer.renderToDataURL, 'function',\n    'Should have renderToDataURL function')\n\n  t.type(PngRenderer.renderToFile, 'function',\n    'Should have renderToFile function')\n\n  t.type(PngRenderer.renderToFileStream, 'function',\n    'Should have renderToFileStream function')\n\n  t.end()\n})\n\ntest('PNG render', function (t) {\n  const sampleQrData = QRCode.create('sample text', { version: 2 })\n  let png\n\n  t.notThrow(function () { png = PngRenderer.render(sampleQrData) },\n    'Should not throw with only qrData param')\n\n  t.ok(png instanceof PNG,\n    'Should return an instance of PNG')\n\n  t.equal(png.width, png.height,\n    'Should be a square image')\n\n  // modules: 25, margins: 4 * 2, scale: 4\n  t.equal(png.width, (25 + 4 * 2) * 4,\n    'Should have correct size')\n\n  t.notThrow(function () {\n    png = PngRenderer.render(sampleQrData, {\n      margin: 10,\n      scale: 1\n    })\n  }, 'Should not throw with options param')\n\n  t.equal(png.width, png.height,\n    'Should be a square image')\n\n  // modules: 25, margins: 10 * 2, scale: 1\n  t.equal(png.width, 25 + 10 * 2,\n    'Should have correct size')\n\n  t.end()\n})\n\ntest('PNG renderToDataURL', function (t) {\n  const sampleQrData = QRCode.create('sample text', { version: 2 })\n\n  t.plan(6)\n\n  PngRenderer.renderToDataURL(sampleQrData, function (err, url) {\n    t.ok(!err,\n      'Should not generate errors with only qrData param')\n\n    t.type(url, 'string',\n      'Should return a string')\n  })\n\n  PngRenderer.renderToDataURL(sampleQrData, { margin: 10, scale: 1 },\n    function (err, url) {\n      t.ok(!err, 'Should not generate errors with options param')\n\n      t.type(url, 'string',\n        'Should return a string')\n\n      t.equal(url.split(',')[0], 'data:image/png;base64',\n        'Should have correct header')\n\n      const b64png = url.split(',')[1]\n      t.equal(b64png.length % 4, 0,\n        'Should have a correct length')\n    }\n  )\n})\n\ntest('PNG renderToFile', function (t) {\n  const sampleQrData = QRCode.create('sample text', { version: 2 })\n  const fileName = 'qrimage.png'\n  let fsStub = sinon.stub(fs, 'createWriteStream')\n  fsStub.returns(new StreamMock())\n\n  t.plan(5)\n\n  PngRenderer.renderToFile(fileName, sampleQrData, function (err) {\n    t.ok(!err,\n      'Should not generate errors with only qrData param')\n\n    t.equal(fsStub.getCall(0).args[0], fileName,\n      'Should save file with correct file name')\n  })\n\n  PngRenderer.renderToFile(fileName, sampleQrData, {\n    margin: 10,\n    scale: 1\n  }, function (err) {\n    t.ok(!err,\n      'Should not generate errors with options param')\n\n    t.equal(fsStub.getCall(0).args[0], fileName,\n      'Should save file with correct file name')\n  })\n\n  fsStub.restore()\n  fsStub = sinon.stub(fs, 'createWriteStream')\n  fsStub.returns(new StreamMock().forceErrorOnWrite())\n\n  PngRenderer.renderToFile(fileName, sampleQrData, function (err) {\n    t.ok(err,\n      'Should fail if error occurs during save')\n  })\n\n  fsStub.restore()\n})\n\ntest('PNG renderToFileStream', function (t) {\n  const sampleQrData = QRCode.create('sample text', { version: 2 })\n\n  t.notThrow(function () {\n    PngRenderer.renderToFileStream(new StreamMock(), sampleQrData)\n  }, 'Should not throw with only qrData param')\n\n  t.notThrow(function () {\n    PngRenderer.renderToFileStream(new StreamMock(), sampleQrData, {\n      margin: 10,\n      scale: 1\n    })\n  }, 'Should not throw with options param')\n\n  t.end()\n})\n"
  },
  {
    "path": "test/unit/renderer/svg.test.js",
    "content": "const test = require('tap').test\nconst sinon = require('sinon')\nconst fs = require('fs')\nconst htmlparser = require('htmlparser2')\nconst QRCode = require('core/qrcode')\nconst SvgRenderer = require('renderer/svg')\n\nfunction getExpectedViewbox (size, margin) {\n  const expectedQrCodeSize = size + margin * 2\n  return '0 0 ' + expectedQrCodeSize + ' ' + expectedQrCodeSize\n}\n\nfunction testSvgFragment (t, svgFragment, expectedTags) {\n  return new Promise(function (resolve, reject) {\n    const parser = new htmlparser.Parser({\n      onopentag: function (name, attribs) {\n        const tag = expectedTags.shift()\n\n        t.equal(tag.name, name,\n          'Should have a ' + tag.name + ' tag')\n\n        tag.attribs.forEach(function (attr) {\n          t.equal(attribs[attr.name], attr.value.toString(),\n            'Should have attrib ' + attr.name + ' with value ' + attr.value)\n        })\n      },\n\n      onend: function () {\n        resolve()\n      },\n\n      onerror: function (e) {\n        reject(e)\n      }\n    }, { decodeEntities: true })\n\n    parser.write(svgFragment)\n    parser.end()\n  })\n}\n\nfunction buildTest (t, data, opts, expectedTags) {\n  const svg = SvgRenderer.render(data, opts)\n  return testSvgFragment(t, svg, expectedTags.slice())\n}\n\ntest('svgrender interface', function (t) {\n  t.type(SvgRenderer.render, 'function',\n    'Should have render function')\n\n  t.type(SvgRenderer.renderToFile, 'function',\n    'Should have renderToFile function')\n\n  t.end()\n})\n\ntest('Svg render', function (t) {\n  const tests = []\n\n  const data = QRCode.create('sample text', { version: 2 })\n  const size = data.modules.size\n\n  tests.push(buildTest(t, data, {\n    scale: 4,\n    margin: 4,\n    color: {\n      light: '#ffffff80'\n    }\n  }, [\n    {\n      name: 'svg',\n      attribs: [\n        { name: 'viewbox', value: getExpectedViewbox(size, 4) }\n      ]\n    },\n    {\n      name: 'path',\n      attribs: [\n        { name: 'fill', value: '#ffffff' },\n        { name: 'fill-opacity', value: '.50' }\n      ]\n    },\n    {\n      name: 'path',\n      attribs: [\n        { name: 'stroke', value: '#000000' }\n      ]\n    }\n  ]))\n\n  tests.push(buildTest(t, data, {\n    scale: 0,\n    margin: 8,\n    color: {\n      light: '#0000',\n      dark: '#00000080'\n    }\n  }, [\n    {\n      name: 'svg',\n      attribs: [\n        { name: 'viewbox', value: getExpectedViewbox(size, 8) }\n      ]\n    },\n    {\n      name: 'path',\n      attribs: [\n        { name: 'stroke', value: '#000000' },\n        { name: 'stroke-opacity', value: '.50' }\n      ]\n    }\n  ]))\n\n  tests.push(buildTest(t, data, {}, [\n    {\n      name: 'svg',\n      attribs: [\n        { name: 'viewbox', value: getExpectedViewbox(size, 4) }\n      ]\n    },\n    { name: 'path', attribs: [{ name: 'fill', value: '#ffffff' }] },\n    { name: 'path', attribs: [{ name: 'stroke', value: '#000000' }] }\n  ]))\n\n  tests.push(buildTest(t, data, { width: 250 }, [\n    {\n      name: 'svg',\n      attribs: [\n        { name: 'width', value: '250' },\n        { name: 'height', value: '250' },\n        { name: 'viewbox', value: getExpectedViewbox(size, 4) }\n      ]\n    },\n    { name: 'path', attribs: [{ name: 'fill', value: '#ffffff' }] },\n    { name: 'path', attribs: [{ name: 'stroke', value: '#000000' }] }\n  ]))\n\n  Promise.all(tests).then(function () {\n    t.end()\n  })\n})\n\ntest('Svg renderToFile', function (t) {\n  const sampleQrData = QRCode.create('sample text', { version: 2 })\n  const fileName = 'qrimage.svg'\n  let fsStub = sinon.stub(fs, 'writeFile').callsArg(2)\n\n  t.plan(5)\n\n  SvgRenderer.renderToFile(fileName, sampleQrData, function (err) {\n    t.ok(!err,\n      'Should not generate errors with only qrData param')\n\n    t.equal(fsStub.getCall(0).args[0], fileName,\n      'Should save file with correct file name')\n  })\n\n  SvgRenderer.renderToFile(fileName, sampleQrData, {\n    margin: 10,\n    scale: 1\n  }, function (err) {\n    t.ok(!err,\n      'Should not generate errors with options param')\n\n    t.equal(fsStub.getCall(0).args[0], fileName,\n      'Should save file with correct file name')\n  })\n\n  fsStub.restore()\n  fsStub = sinon.stub(fs, 'writeFile').callsArgWith(2, new Error())\n\n  SvgRenderer.renderToFile(fileName, sampleQrData, function (err) {\n    t.ok(err,\n      'Should fail if error occurs during save')\n  })\n\n  fsStub.restore()\n})\n"
  },
  {
    "path": "test/unit/renderer/terminal.test.js",
    "content": "const test = require('tap').test\nconst QRCode = require('core/qrcode')\nconst TerminalRenderer = require('renderer/terminal')\n\ntest('TerminalRenderer interface', function (t) {\n  t.type(TerminalRenderer.render, 'function',\n    'Should have render function')\n\n  t.end()\n})\n\ntest('TerminalRenderer render big', function (t) {\n  const sampleQrData = QRCode.create('sample text', { version: 2 })\n  let str\n\n  t.notThrow(function () { str = TerminalRenderer.render(sampleQrData) },\n    'Should not throw with only qrData param')\n\n  t.notThrow(function () {\n    str = TerminalRenderer.render(sampleQrData, {\n      margin: 10,\n      scale: 1\n    })\n  }, 'Should not throw with options param')\n\n  t.type(str, 'string',\n    'Should return a string')\n\n  t.notThrow(function () {\n    str = TerminalRenderer.render(sampleQrData, { inverse: true })\n  }, 'Should not throw with inverse options')\n\n  t.type(str, 'string',\n    'Should return a string if inverse option is set')\n\n  t.end()\n})\n\ntest('TerminalRenderer render small', function (t) {\n  const sampleQrData = QRCode.create('sample text', { version: 2 })\n  let str\n  let calledCallback = false\n  const callback = function () { calledCallback = true }\n\n  t.notThrow(function () { str = TerminalRenderer.render(sampleQrData) },\n    'Should not throw with only qrData param')\n\n  t.notThrow(function () {\n    str = TerminalRenderer.render(sampleQrData, {\n      margin: 10,\n      scale: 1,\n      small: true\n    })\n  }, 'Should not throw with options param and without callback')\n\n  t.notThrow(function () {\n    str = TerminalRenderer.render(sampleQrData, {\n      margin: 10,\n      scale: 1,\n      small: true\n    },\n    callback)\n  }, 'Should not throw with options param and callback')\n\n  t.type(str, 'string',\n    'Should return a string')\n\n  t.equal(calledCallback, true, 'string',\n    'Should call a callback')\n\n  t.notThrow(function () {\n    str = TerminalRenderer.render(sampleQrData, { small: true, inverse: true })\n  }, 'Should not throw with inverse options')\n\n  t.type(str, 'string',\n    'Should return a string if inverse option is set')\n\n  t.end()\n})\n"
  },
  {
    "path": "test/unit/renderer/utf8.test.js",
    "content": "const test = require('tap').test\nconst sinon = require('sinon')\nconst fs = require('fs')\nconst QRCode = require('core/qrcode')\nconst Utf8Renderer = require('renderer/utf8')\n\ntest('Utf8Renderer interface', function (t) {\n  t.type(Utf8Renderer.render, 'function',\n    'Should have render function')\n\n  t.end()\n})\n\ntest('Utf8Renderer render', function (t) {\n  const sampleQrData = QRCode.create('sample text', { version: 2 })\n  let str\n\n  t.notThrow(function () { str = Utf8Renderer.render(sampleQrData) },\n    'Should not throw with only qrData param')\n\n  t.notThrow(function () {\n    str = Utf8Renderer.render(sampleQrData, {\n      margin: 10,\n      scale: 1\n    })\n  }, 'Should not throw with options param')\n\n  t.type(str, 'string',\n    'Should return a string')\n\n  t.end()\n})\n\ntest('Utf8 renderToFile', function (t) {\n  const sampleQrData = QRCode.create('sample text', { version: 2 })\n  const fileName = 'qrimage.txt'\n  let fsStub = sinon.stub(fs, 'writeFile').callsArg(2)\n\n  t.plan(5)\n\n  Utf8Renderer.renderToFile(fileName, sampleQrData, function (err) {\n    t.ok(!err,\n      'Should not generate errors with only qrData param')\n\n    t.equal(fsStub.getCall(0).args[0], fileName,\n      'Should save file with correct file name')\n  })\n\n  Utf8Renderer.renderToFile(fileName, sampleQrData, {\n    margin: 10,\n    scale: 1\n  }, function (err) {\n    t.ok(!err,\n      'Should not generate errors with options param')\n\n    t.equal(fsStub.getCall(0).args[0], fileName,\n      'Should save file with correct file name')\n  })\n\n  fsStub.restore()\n  fsStub = sinon.stub(fs, 'writeFile').callsArgWith(2, new Error())\n\n  Utf8Renderer.renderToFile(fileName, sampleQrData, function (err) {\n    t.ok(err,\n      'Should fail if error occurs during save')\n  })\n\n  fsStub.restore()\n})\n"
  },
  {
    "path": "test/unit/renderer/utils.test.js",
    "content": "const test = require('tap').test\nconst Utils = require('renderer/utils')\n\ntest('Utils getOptions', function (t) {\n  const defaultOptions = {\n    width: undefined,\n    scale: 4,\n    margin: 4,\n    color: {\n      dark: { r: 0, g: 0, b: 0, a: 255, hex: '#000000' },\n      light: { r: 255, g: 255, b: 255, a: 255, hex: '#ffffff' }\n    },\n    type: undefined,\n    rendererOpts: {}\n  }\n\n  t.ok(Utils.getOptions,\n    'getOptions should be defined')\n\n  t.deepEqual(Utils.getOptions(), defaultOptions,\n    'Should return default options if called without param')\n\n  t.equal(Utils.getOptions({ scale: 8 }).scale, 8,\n    'Should return correct scale value')\n\n  t.equal(Utils.getOptions({ width: 300 }).scale, 4,\n    'Should reset scale value to default if width is set')\n\n  t.equal(Utils.getOptions({ margin: null }).margin, 4,\n    'Should return default margin if specified value is null')\n\n  t.equal(Utils.getOptions({ margin: -1 }).margin, 4,\n    'Should return default margin if specified value is < 0')\n\n  t.equal(Utils.getOptions({ margin: 20 }).margin, 20,\n    'Should return correct margin value')\n\n  t.deepEqual(Utils.getOptions({ color: { dark: '#fff', light: '#000000' } }).color,\n    {\n      dark: { r: 255, g: 255, b: 255, a: 255, hex: '#ffffff' },\n      light: { r: 0, g: 0, b: 0, a: 255, hex: '#000000' }\n    },\n    'Should return correct colors value from strings')\n\n  t.deepEqual(Utils.getOptions({ color: { dark: 111, light: 999 } }).color,\n    {\n      dark: { r: 17, g: 17, b: 17, a: 255, hex: '#111111' },\n      light: { r: 153, g: 153, b: 153, a: 255, hex: '#999999' }\n    },\n    'Should return correct colors value from numbers')\n\n  t.throw(function () { Utils.getOptions({ color: { dark: true } }) },\n    'Should throw if color is not a string')\n\n  t.throw(function () { Utils.getOptions({ color: { dark: '#aa' } }) },\n    'Should throw if color is not in a valid hex format')\n\n  t.end()\n})\n\ntest('Utils getScale', function (t) {\n  const symbolSize = 21\n\n  t.equal(Utils.getScale(symbolSize, { scale: 5 }), 5,\n    'Should return correct scale value')\n\n  t.equal(Utils.getScale(symbolSize, { width: 50, margin: 2 }), 2,\n    'Should calculate correct scale from width and margin')\n\n  t.equal(Utils.getScale(symbolSize, { width: 21, margin: 2, scale: 4 }), 4,\n    'Should return default scale if width is too small to contain the symbol')\n\n  t.end()\n})\n\ntest('Utils getImageWidth', function (t) {\n  const symbolSize = 21\n\n  t.equal(Utils.getImageWidth(symbolSize, { scale: 5, margin: 0 }), 105,\n    'Should return correct width value')\n\n  t.equal(Utils.getImageWidth(symbolSize, { width: 250, margin: 2 }), 250,\n    'Should return specified width value')\n\n  t.equal(Utils.getImageWidth(symbolSize, { width: 10, margin: 4, scale: 4 }), 116,\n    'Should ignore width option if too small to contain the symbol')\n\n  t.end()\n})\n\ntest('Utils qrToImageData', function (t) {\n  t.ok(Utils.qrToImageData,\n    'qrToImageData should be defined')\n\n  const sampleQrData = {\n    modules: {\n      data: [\n        1, 0, 1, 0,\n        0, 1, 0, 1,\n        1, 0, 1, 0,\n        0, 1, 0, 1\n      ],\n      size: 4\n    }\n  }\n\n  const margin = 4\n  const scale = 2\n  const width = 100\n\n  const color = {\n    dark: { r: 255, g: 255, b: 255, a: 255 },\n    light: { r: 0, g: 0, b: 0, a: 255 }\n  }\n\n  const opts = {\n    margin: margin,\n    scale: scale,\n    color: color\n  }\n\n  let imageData = []\n  const expectedImageSize = (sampleQrData.modules.size + margin * 2) * scale\n  let expectedImageDataLength = Math.pow(expectedImageSize, 2) * 4\n\n  Utils.qrToImageData(imageData, sampleQrData, opts)\n\n  t.equal(imageData.length, expectedImageDataLength,\n    'Should return correct imageData length')\n\n  imageData = []\n  opts.width = width\n  expectedImageDataLength = Math.pow(width, 2) * 4\n\n  Utils.qrToImageData(imageData, sampleQrData, opts)\n\n  t.equal(imageData.length, expectedImageDataLength,\n    'Should return correct imageData length')\n\n  t.end()\n})\n"
  },
  {
    "path": "test.js",
    "content": "const spawn = require('child_process').spawn\nconst path = require('path')\n\nconst opt = {\n  cwd: __dirname,\n  env: (function () {\n    process.env.NODE_PATH = './' + path.delimiter + './lib'\n    return process.env\n  }()),\n  stdio: [process.stdin, process.stdout, process.stderr]\n}\n\nspawn('node', [\n  'node_modules/.bin/tap',\n  '--cov', '--100',\n  process.argv[2] || 'test/**/*.test.js'\n], opt)\n"
  }
]