QRCodeText.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = function (d, b) {
  4. extendStatics = Object.setPrototypeOf ||
  5. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. };
  9. return function (d, b) {
  10. if (typeof b !== "function" && b !== null)
  11. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  12. extendStatics(d, b);
  13. function __() { this.constructor = d; }
  14. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  15. };
  16. })();
  17. var __assign = (this && this.__assign) || function () {
  18. __assign = Object.assign || function(t) {
  19. for (var s, i = 1, n = arguments.length; i < n; i++) {
  20. s = arguments[i];
  21. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
  22. t[p] = s[p];
  23. }
  24. return t;
  25. };
  26. return __assign.apply(this, arguments);
  27. };
  28. Object.defineProperty(exports, "__esModule", { value: true });
  29. var QRCodeRaw_1 = require("./QRCodeRaw");
  30. var DEFAULT_OPTIONS = {
  31. blackSymbol: '▓▓',
  32. whiteSymbol: ' ',
  33. };
  34. var QRCodeText = /** @class */ (function (_super) {
  35. __extends(QRCodeText, _super);
  36. function QRCodeText(value, options) {
  37. if (options === void 0) { options = {}; }
  38. var _this = _super.call(this, value, options) || this;
  39. var params = __assign(__assign({}, DEFAULT_OPTIONS), options);
  40. _this.blackSymbol = params.blackSymbol;
  41. _this.whiteSymbol = params.whiteSymbol;
  42. return _this;
  43. }
  44. QRCodeText.prototype._clearCache = function () {
  45. _super.prototype._clearCache.call(this);
  46. this.qrCodeText = null;
  47. };
  48. QRCodeText.prototype.toString = function () {
  49. if (this.qrCodeText) {
  50. return this.qrCodeText;
  51. }
  52. var dataSize = this.getDataSize();
  53. if (!dataSize) {
  54. return null;
  55. }
  56. var data = this.getData();
  57. // FIXME eh?
  58. if (data === null) {
  59. return null;
  60. }
  61. var symbols = [];
  62. for (var y = 0; y < dataSize; y += 1) {
  63. for (var x = 0; x < dataSize; x += 1) {
  64. var isBlack = data[y][x];
  65. symbols.push(isBlack ? this.blackSymbol : this.whiteSymbol);
  66. }
  67. symbols.push('\n');
  68. }
  69. this.qrCodeText = symbols.join('');
  70. return this.qrCodeText;
  71. };
  72. return QRCodeText;
  73. }(QRCodeRaw_1.default));
  74. exports.default = QRCodeText;