Skip to content

Instantly share code, notes, and snippets.

@khushalbokadey
Created December 1, 2016 09:31
Show Gist options
  • Save khushalbokadey/79ab7083b42c54e0f1568f00d3703c65 to your computer and use it in GitHub Desktop.
Save khushalbokadey/79ab7083b42c54e0f1568f00d3703c65 to your computer and use it in GitHub Desktop.
Code to slugify text. Mainly to use in google sheets.
function slugify(value) {
/*
* Convert the the vs in a range of cells into slugs.
*/
slug = '';
slug = value.substring(0, 30).toLowerCase();
slug = slug.replace(/[^\w\s-]/g, '');
slug = slug.replace(/\s+/g, '-');
Logger.log(slug);
return slug;
}
function test() {
Logger.log(slugify("This is a very very very long text.This is a very very very long text.This is a very very very long text.This is a very very very long text."));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment