Skip to content

Instantly share code, notes, and snippets.

@vitalyrotari
Forked from mathewbyrne/slugify.js
Last active August 29, 2015 14:14
Show Gist options
  • Select an option

  • Save vitalyrotari/6ad12236251ca65dda0a to your computer and use it in GitHub Desktop.

Select an option

Save vitalyrotari/6ad12236251ca65dda0a 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
    }