util.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.endsWith = endsWith;
  6. exports.limit = limit;
  7. exports.startsWith = startsWith;
  8. exports.trimAfterFirstMatch = trimAfterFirstMatch;
  9. /** Returns a regular expression quantifier with an upper and lower limit. */
  10. function limit(lower, upper) {
  11. if (lower < 0 || upper <= 0 || upper < lower) {
  12. throw new TypeError();
  13. }
  14. return "{".concat(lower, ",").concat(upper, "}");
  15. }
  16. /**
  17. * Trims away any characters after the first match of {@code pattern} in {@code candidate},
  18. * returning the trimmed version.
  19. */
  20. function trimAfterFirstMatch(regexp, string) {
  21. var index = string.search(regexp);
  22. if (index >= 0) {
  23. return string.slice(0, index);
  24. }
  25. return string;
  26. }
  27. function startsWith(string, substring) {
  28. return string.indexOf(substring) === 0;
  29. }
  30. function endsWith(string, substring) {
  31. return string.indexOf(substring, string.length - substring.length) === string.length - substring.length;
  32. }
  33. //# sourceMappingURL=util.js.map