Skip to content

Instantly share code, notes, and snippets.

@manhnguyenv
Forked from mathewbyrne/slugify.js
Created July 26, 2018 04:00
Show Gist options
  • Save manhnguyenv/7cce433159e60b920a800f21a1feb09c to your computer and use it in GitHub Desktop.
Save manhnguyenv/7cce433159e60b920a800f21a1feb09c to your computer and use it in GitHub Desktop.

Revisions

  1. @mathewbyrne mathewbyrne revised this gist Oct 12, 2011. 1 changed file with 5 additions and 6 deletions.
    11 changes: 5 additions & 6 deletions slugify.js
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,9 @@

    function slugify(text)
    {
    return text.toString().toLowerCase()
    .replace(/(\w)\'/g, '$1') // Special case for apostrophes
    .replace(/[^a-z0-9_\-]+/g, '-') // Replace all non-word chars with -
    .replace(/\-\-+/g, '-') // Replace multiple - with single -
    .replace(/^-+/, '') // Trim - from start of text
    .replace(/-+$/, ''); // Trim - from end of text
    .replace(/\s+/g, '-') // Replace spaces with -
    .replace(/[^\w\-]+/g, '') // Remove all non-word chars
    .replace(/\-\-+/g, '-') // Replace multiple - with single -
    .replace(/^-+/, '') // Trim - from start of text
    .replace(/-+$/, ''); // Trim - from end of text
    }
  2. @mathewbyrne mathewbyrne created this gist Oct 12, 2011.
    10 changes: 10 additions & 0 deletions slugify.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@

    function slugify(text)
    {
    return text.toString().toLowerCase()
    .replace(/(\w)\'/g, '$1') // Special case for apostrophes
    .replace(/[^a-z0-9_\-]+/g, '-') // Replace all non-word chars with -
    .replace(/\-\-+/g, '-') // Replace multiple - with single -
    .replace(/^-+/, '') // Trim - from start of text
    .replace(/-+$/, ''); // Trim - from end of text
    }