string.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.stripHtmlTags = exports.removeHeadingSlash = exports.removeHeadingString = exports.addTrailingSlash = void 0;
  4. /**
  5. * 字符串`末尾`添加`/`
  6. */
  7. function addTrailingSlash(path) {
  8. return path.endsWith("/") ? path : path + "/";
  9. }
  10. exports.addTrailingSlash = addTrailingSlash;
  11. /**
  12. * 删除特定`开头`的`字符串`
  13. */
  14. function removeHeadingString(path, heading) {
  15. return path.startsWith(heading) ? path.slice(heading.length) : path;
  16. }
  17. exports.removeHeadingString = removeHeadingString;
  18. /**
  19. * 删除字符串`开头`的`/`
  20. */
  21. function removeHeadingSlash(path) {
  22. return removeHeadingString(path, "/");
  23. }
  24. exports.removeHeadingSlash = removeHeadingSlash;
  25. /**
  26. * 去除字符串中的 HTML 标签
  27. */
  28. function stripHtmlTags(input, maxLength) {
  29. const strippedText = input.replace(/<[^>]*>/g, "");
  30. if (strippedText.length > maxLength) {
  31. return strippedText.substring(0, maxLength) + "...";
  32. }
  33. return strippedText;
  34. }
  35. exports.stripHtmlTags = stripHtmlTags;