Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • 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, "");
};
@georgebutter
Copy link

georgebutter commented Feb 1, 2018

' should be removed instead of replacing with -

@skillmatic-co
Copy link

' should be removed instead of replacing with -

This.

@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