Socket
Socket
Sign inDemoInstall

slugg

Package Overview
Dependencies
0
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    slugg

Make strings url safe (with no dependencies)


Version published
Weekly downloads
18K
decreased by-39.39%
Maintainers
1
Install size
8.92 kB
Created
Weekly downloads
 

Readme

Source

Slugg

Make strings url-safe.

  • Comprehensive tests
  • No dependencies
  • Not in coffee-script (lol)
  • Coerces foreign symbols to their english equivalent
  • Doesn't try to do anything fancy with symbols (just removes them)
  • Works in browser (window.slugg) and AMD/CommonJS-flavoured module loaders
npm install slugg

Usage:

slug(string, [separator, toStrip])

var slug = require('slugg')

slug('My fantastic blog post')
//-> 'my-fantastic-blog-post'

slug('Today I found £5')
//-> 'today-i-found-5'

slug('I ♥ you')
//-> 'i-you'

If you want a separator other than '-', pass it in as the second argument:

slug('Kevin Spacey', ' ')
//-> 'kevin spacey'

By default, slugg will strip (i.e. remove and not replace) any sort of quotemark: '"’‘”“.

If you want to control which characters are stripped, pass a regex as the last option that will match the chars you want to replace, eg:

slug('Mum\'s cooking', /'/g)
//-> 'mums-cooking'

Remember to use the g flag if you want all the matches stripped (not just the first).

After version 1.1.0, a new syntax has been introduced:

slug(string, [options])

If you want a separator other than '-', pass it in as the separator option:

slug('Kevin Spacey', { separator: ' ' })
//-> 'kevin spacey'

If you want to control which characters are stripped, pass a regex as the toStrip option that will match the chars you want to replace, eg:

slug('Mum\'s cooking', { toStrip: /'/g })
//-> 'mums-cooking'

Remember to use the g flag if you want all the matches stripped (not just the first).

By default, slugg will convert your string to lower case. If you want to disable it just pass the toLowerCase option as false, eg:

slug('Slugg rocks!', { toLowerCase: false })
//-> 'Slugg-rocks'

Keywords

FAQs

Last updated on 31 May 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc