slugify.js 927 B

12345678910111213141516171819202122232425
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.slugify = void 0;
  4. // string.js slugify drops non ascii chars so we have to
  5. // use a custom implementation here
  6. const removeDiacritics = require('diacritics').remove;
  7. // eslint-disable-next-line no-control-regex
  8. const rControl = /[\u0000-\u001f]/g;
  9. const rSpecial = /[\s~`!@#$%^&*()\-_+=[\]{}|\\;:"'<>,.?/]+/g;
  10. exports.slugify = (str) => {
  11. return (removeDiacritics(str)
  12. // Remove control characters
  13. .replace(rControl, '')
  14. // Replace special characters
  15. .replace(rSpecial, '-')
  16. // Remove continous separators
  17. .replace(/\-{2,}/g, '-')
  18. // Remove prefixing and trailing separtors
  19. .replace(/^\-+|\-+$/g, '')
  20. // ensure it doesn't start with a number (#121)
  21. .replace(/^(\d)/, '_$1')
  22. // lowercase
  23. .toLowerCase());
  24. };
  25. //# sourceMappingURL=slugify.js.map