Skip to content

Instantly share code, notes, and snippets.

@vanquyet94
Forked from khushalbokadey/slugify.js
Created June 22, 2021 15:59
Show Gist options
  • Save vanquyet94/ea4e9040ec732b06cef057c9ffa6febd to your computer and use it in GitHub Desktop.
Save vanquyet94/ea4e9040ec732b06cef057c9ffa6febd 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