Default.js 4.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. "use strict";
  2. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  3. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  5. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  6. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  7. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  8. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  9. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  10. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  11. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  12. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  13. // Generated by CoffeeScript 2.5.1
  14. var DefaultLinePrependor, SpecialString, tools;
  15. tools = require('../../../tools');
  16. SpecialString = require('../../SpecialString');
  17. module.exports = DefaultLinePrependor = function () {
  18. var self;
  19. var DefaultLinePrependor = /*#__PURE__*/function (_require) {
  20. _inherits(DefaultLinePrependor, _require);
  21. var _super = _createSuper(DefaultLinePrependor);
  22. function DefaultLinePrependor() {
  23. _classCallCheck(this, DefaultLinePrependor);
  24. return _super.apply(this, arguments);
  25. }
  26. _createClass(DefaultLinePrependor, [{
  27. key: "_render",
  28. value: function _render(inherited, options) {
  29. var addToLeft, addToRight, alignment, bullet, char, charLen, diff, left, output, space, toWrite;
  30. if (this._lineNo === 0 && (bullet = this._config.bullet)) {
  31. char = bullet.char;
  32. charLen = new SpecialString(char).length;
  33. alignment = bullet.alignment;
  34. space = this._config.amount;
  35. toWrite = char;
  36. addToLeft = '';
  37. addToRight = '';
  38. if (space > charLen) {
  39. diff = space - charLen;
  40. if (alignment === 'right') {
  41. addToLeft = self.pad(diff);
  42. } else if (alignment === 'left') {
  43. addToRight = self.pad(diff);
  44. } else if (alignment === 'center') {
  45. left = Math.round(diff / 2);
  46. addToLeft = self.pad(left);
  47. addToRight = self.pad(diff - left);
  48. } else {
  49. throw Error("Unknown alignment `".concat(alignment, "`"));
  50. }
  51. }
  52. output = addToLeft + char + addToRight;
  53. } else {
  54. output = self.pad(this._config.amount);
  55. }
  56. return inherited + output;
  57. }
  58. }], [{
  59. key: "pad",
  60. value: function pad(howMuch) {
  61. return tools.repeatString(" ", howMuch);
  62. }
  63. }]);
  64. return DefaultLinePrependor;
  65. }(require('./_LinePrependor'));
  66. ;
  67. self = DefaultLinePrependor;
  68. return DefaultLinePrependor;
  69. }.call(void 0);