Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dlindenkreuz/a439ec4b939f0561d6d9 to your computer and use it in GitHub Desktop.
Save dlindenkreuz/a439ec4b939f0561d6d9 to your computer and use it in GitHub Desktop.
Shopify handleize function in JavaScript
// one-liner version
// retains latin-1 supplement chars as well as latin extended-a and latin extended-b
Shopify.handleize = function (str) {
return str.toLowerCase().replace(/[^\w\u00C0-\u024f]+/g, "-").replace(/^-+|-+$/g, "");
};
@robtry
Copy link

robtry commented Aug 12, 2020

Also problem with accents

return str.toLowerCase().replace(''', '').replace(/[^\w\u00C0-\u024f]+/g, "-").replace(/^-+|-+$/g, "").normalize("NFD").replace(/[\u0300-\u036f]/g, "")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment