string.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. "use strict";
  2. var __read = (this && this.__read) || function (o, n) {
  3. var m = typeof Symbol === "function" && o[Symbol.iterator];
  4. if (!m) return o;
  5. var i = m.call(o), r, ar = [], e;
  6. try {
  7. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  8. }
  9. catch (error) { e = { error: error }; }
  10. finally {
  11. try {
  12. if (r && !r.done && (m = i["return"])) m.call(i);
  13. }
  14. finally { if (e) throw e.error; }
  15. }
  16. return ar;
  17. };
  18. var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
  19. if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
  20. if (ar || !(i in from)) {
  21. if (!ar) ar = Array.prototype.slice.call(from, 0, i);
  22. ar[i] = from[i];
  23. }
  24. }
  25. return to.concat(ar || Array.prototype.slice.call(from));
  26. };
  27. Object.defineProperty(exports, "__esModule", { value: true });
  28. exports.split = exports.isPercent = exports.unicodeString = exports.unicodeChars = exports.quotePattern = exports.sortLength = void 0;
  29. function sortLength(a, b) {
  30. return a.length !== b.length ? b.length - a.length : a === b ? 0 : a < b ? -1 : 1;
  31. }
  32. exports.sortLength = sortLength;
  33. function quotePattern(text) {
  34. return text.replace(/([\^$(){}+*?\-|\[\]\:\\])/g, '\\$1');
  35. }
  36. exports.quotePattern = quotePattern;
  37. function unicodeChars(text) {
  38. return Array.from(text).map(function (c) { return c.codePointAt(0); });
  39. }
  40. exports.unicodeChars = unicodeChars;
  41. function unicodeString(data) {
  42. return String.fromCodePoint.apply(String, __spreadArray([], __read(data), false));
  43. }
  44. exports.unicodeString = unicodeString;
  45. function isPercent(x) {
  46. return !!x.match(/%\s*$/);
  47. }
  48. exports.isPercent = isPercent;
  49. function split(x) {
  50. return x.trim().split(/\s+/);
  51. }
  52. exports.split = split;
  53. //# sourceMappingURL=string.js.map