Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

wrapWord.js 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _sliceAnsi = _interopRequireDefault(require("slice-ansi"));
  7. var _stringWidth = _interopRequireDefault(require("string-width"));
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  9. /**
  10. * @param {string} input
  11. * @param {number} size
  12. * @returns {Array}
  13. */
  14. const wrapWord = (input, size) => {
  15. let subject;
  16. subject = input;
  17. const chunks = []; // https://regex101.com/r/gY5kZ1/1
  18. const re = new RegExp('(^.{1,' + size + '}(\\s+|$))|(^.{1,' + (size - 1) + '}(\\\\|/|_|\\.|,|;|-))');
  19. do {
  20. let chunk;
  21. chunk = subject.match(re);
  22. if (chunk) {
  23. chunk = chunk[0];
  24. subject = (0, _sliceAnsi.default)(subject, (0, _stringWidth.default)(chunk));
  25. chunk = chunk.trim();
  26. } else {
  27. chunk = (0, _sliceAnsi.default)(subject, 0, size);
  28. subject = (0, _sliceAnsi.default)(subject, size);
  29. }
  30. chunks.push(chunk);
  31. } while ((0, _stringWidth.default)(subject));
  32. return chunks;
  33. };
  34. var _default = wrapWord;
  35. exports.default = _default;
  36. //# sourceMappingURL=wrapWord.js.map