New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

larvitslugify

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

larvitslugify

Slugifies even utf-8 chars!

  • 0.10.6
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
137
decreased by-8.05%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status

larvitslugify

Forked from slug and added some pull requests and options.

Slugifies every string, even when it contains unicode!

Make strings url-safe.

  • respecting RFC 3986
  • Comprehensive tests
  • No dependencies (except the unicode table)
  • Not in coffee-script (except the tests lol)
  • Coerces foreign symbols to their english equivalent
  • Works in browser (window.slug) and AMD/CommonJS-flavoured module loaders (except the unicode symbols unless you use browserify but who wants to download a ~2mb js file, right?)
npm install larvitslugify

Examples

var slug  = require('larvitslugify'),
    print = console.log.bind(console, '>')

print(slug('i ♥ unicode'))
// > i-love-unicode

print(slug('unicode ♥ is ☢')) // yes!
// > unicode-love-is-radioactive

print(slug('i ♥ unicode', '_')) // If you prefer something else then `-` as seperator
// > i_love_unicode

slug.charmap['♥'] = 'freaking love' // change default charmap or use option {charmap:{…}} as 2. argument
print(slug('I ♥ UNICODE'))
// > I-freaking-love-UNICODE

print(slug('☏-Number', {lower: true})) // If you prefer lower case
// > telephone-number

print(slug('i <3 unicode'))
// > i-love-unicode

Options

// Options is either object or replacement (sets options.replacement)
slug('string', [{options} || 'replacement']);

All options

slug('string', {
	'replacement':  '-',              // Replace spaces with replacement
	'symbols':      true,             // Replace unicode symbols or not
	'remove':       /[d]/g,           // Regex to remove characters
	'lower':        true,             // Result in lower case
	'charmap':      {'Ä': 'ae'},      // Replace special characters
	'multicharmap': {'ð': 'oi'},      // Replace multi-characters
	'save':         ['*', 'ð'],       // Do not replace these characters, also takes a string
	'wordLimit':    5                 // Limits the amount of words to this number
});

Option modes

slug.defaults.mode ='pretty';
slug.defaults.modes['rfc3986'] = {
	'replacement':  '-',
	'symbols':      true,
	'remove':       null,
	'lower':        true,
	'charmap':      slug.charmap,
	'multicharmap': slug.multicharmap
};
slug.defaults.modes['pretty'] = {
	'replacement':  '-',
	'symbols':      true,
	'remove':       /[.]/g,
	'lower':        false,
	'charmap':      slug.charmap,
	'multicharmap': slug.multicharmap
};

Browser

When using browserify you might want to remove the symbols table from your bundle by using --ignore similar to this:

# Generates a standalone slug browser bundle:
browserify slug.js --ignore unicode/category/So -s slug > slug-browser.js

When using webpack you can use:

externals: {
    'unicode/category/So': '{}',
}

In your webpack config to replace the require with an empty object stub.

Keywords

FAQs

Package last updated on 25 Nov 2015

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc