util.js 840 B

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