Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

util.js 990 B

3 lat temu
123456789101112131415161718192021222324252627282930313233343536373839404142
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.isNumeric = isNumeric;
  6. exports.hyphenToCamelCase = hyphenToCamelCase;
  7. exports.trimEnd = trimEnd;
  8. /**
  9. * Determines if the specified string consists entirely of numeric characters.
  10. *
  11. * @param {*} [value]
  12. * @returns {boolean}
  13. */
  14. function isNumeric(value) {
  15. return !Number.isNaN(value - parseFloat(value));
  16. }
  17. /**
  18. * Convert a hyphenated string to camelCase.
  19. *
  20. * @param {string} string
  21. * @returns {string}
  22. */
  23. function hyphenToCamelCase(string) {
  24. return string.replace(/-(.)/g, (match, chr) => chr.toUpperCase());
  25. }
  26. /**
  27. * Trim the specified substring off the string. If the string does not end
  28. * with the specified substring, this is a no-op.
  29. *
  30. * @param {string} haystack String to search in
  31. * @param {string} needle String to search for
  32. * @return {string}
  33. */
  34. function trimEnd(haystack, needle) {
  35. return haystack.endsWith(needle) ? haystack.slice(0, -needle.length) : haystack;
  36. }