Skip to content

Instantly share code, notes, and snippets.

@ckhatton
Last active August 29, 2015 14:11
Show Gist options
  • Save ckhatton/d3bf50574f2bcd0d4106 to your computer and use it in GitHub Desktop.
Save ckhatton/d3bf50574f2bcd0d4106 to your computer and use it in GitHub Desktop.
Shopify JS helpers; for adding 'error' class; formatting a string to an URL or from an URL, or to a Shopify URL.
function addError(element) { $(element).addClass('error'); }
function removeError(element) { $(element).removeClass('error'); }
function formatForUrl(str) {
return str
.replace(/ /g, '%20')
.replace(/:/g, '%20')
.replace(/\\/g, '-')
.replace(/\//g, '-')
.replace(/-{2,}/g, '-');
}
function formatFromUrl(str) {
return str.replace(/%20/g, ' ');
}
function formatForShopify(str) {
return str.replace(/%20/g, '+');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment