• Stars
    star
    1,085
  • Rank 42,662 (Top 0.9 %)
  • Language
    CoffeeScript
  • License
    MIT License
  • Created about 13 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

slugifies even utf-8 chars!

slug

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 slug
bower install slug

example

var slug = require('slug')
var 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']);
slug.defaults.mode ='pretty';
slug.defaults.modes['rfc3986'] = {
    replacement: '-',      // replace spaces with replacement
    symbols: true,         // replace unicode symbols or not
    remove: null,          // (optional) regex to remove characters
    lower: true,           // result in lower case
    charmap: slug.charmap, // replace special characters
    multicharmap: slug.multicharmap // replace multi-characters
};
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

Build Status

Bitdeli Badge

More Repositories

1

node-raphael

using the beautiful SVG library Raphaël in Node.js to generate svg-data
JavaScript
70
star
2

node-bufferstream

painless stream buffering, cutting and piping
CoffeeScript
69
star
3

node-unicodetable

unicode lookup table
JavaScript
42
star
4

node-canvas-svg

drawing svg on a Canvas in Node.js
JavaScript
35
star
5

jquery-inputevent

Cross browser oninput event for jQuery
JavaScript
34
star
6

node-dynamictemplate

Δt - the dynamic templating engine
CoffeeScript
26
star
7

lua-mpris

mpris lua api
Lua
22
star
8

lua-dbus

convenient dbus api in lua
Lua
18
star
9

uzful

useful awesome library
Lua
17
star
10

node-animation

animation timing & handling
CoffeeScript
15
star
11

grindr

superfeedr messaging bot
Ruby
11
star
12

blain

Identi.ca Twitter client
Python
10
star
13

awesomerc

my awesomerc (too much for a gist)
Lua
9
star
14

chrome-xmpp

Add XMPP as Feature to your Browser
JavaScript
9
star
15

node-asyncxml

async xml builder and generator
CoffeeScript
9
star
16

node-lift

dual side templating, made easy
CoffeeScript
8
star
17

chrome-terminal

execute commands via native messaging in chrome
JavaScript
8
star
18

Lightstream

XMPP Framework
JavaScript
7
star
19

node-formatdate

a little bit more than just strftime
CoffeeScript
7
star
20

sawrocket-node

Nodejs Net Module with Raw Socket API
JavaScript
5
star
21

Columns

clone of old sega mastersystems II game
JavaScript
5
star
22

node-jsconfig

async configuration loader with cli support
CoffeeScript
5
star
23

it

muSchro0m it
Lua
5
star
24

node-tls-connect

nodejs tls.connect drop-in replacement / fallback
JavaScript
5
star
25

node-dt-jquery

Δt jquery adapter - async & dynamic templating engine
CoffeeScript
4
star
26

node-scopify

capsule browserify bundle in a scope
JavaScript
4
star
27

btrtime

Time Machine with Btrfs
Shell
4
star
28

xpath-parser

damn small xpath parser
CoffeeScript
4
star
29

jquery-autosuggestion

jQuery plugin for auto suggestion
JavaScript
3
star
30

node-dt-selector

Δt selector engine - async & dynamic templating engine
CoffeeScript
3
star
31

xmppfs

unix file system xmpp client
JavaScript
3
star
32

node-dt-compiler

Δt compiler - async & dynamic templating engine compiler
CoffeeScript
3
star
33

farbbomb

CoffeeScript
3
star
34

node-dt-browser

Δt browser render logic for adapters - async & dynamic templating engine
CoffeeScript
3
star
35

node-dt-list

Δt list controller - async & dynamic templating engine
CoffeeScript
2
star
36

ulatency

ulatencyd client
2
star
37

node-surrender-cube

surrender to the hypno cube!
CoffeeScript
2
star
38

node-dt-dom

Δt dom adapter - async & dynamic templating engine
CoffeeScript
2
star
39

node-dt-stream

Δt stream adapter - async & dynamic templating engine
CoffeeScript
2
star
40

zshrc

my zshrc (too much for a gist)
Ruby
2
star
41

node-valvestream

control data flow of a stream at a single point
CoffeeScript
2
star
42

node-domevents

node.js eventemitter api for dom events
CoffeeScript
2
star
43

lua-udev

lua udev bindings
C
2
star
44

node-tarball

creates tarballs with streams
CoffeeScript
1
star
45

xmpp-cert-info

retrieve ssl certificate information from xmpp server
JavaScript
1
star
46

node-order

handle callbacks in order no matter which one finish first and handle them as a list.
CoffeeScript
1
star
47

ltx-xpath

xpath matching for ltx
CoffeeScript
1
star
48

requestAnimationFrame.js

requestAnimationFrame shim
CoffeeScript
1
star
49

node-tarballify

wrap up server code in a tarball
CoffeeScript
1
star
50

sawrocket-xmpp

xmpp connection on raw socket api
JavaScript
1
star
51

requestFullscreen.js

requestFullscreen polyfill
CoffeeScript
1
star
52

hammer-and-sickle

It sucks on every cpu to generate on big (well … bigger) realtime raytraced live video.
CoffeeScript
1
star
53

bundesnetz

bundesgesetznetzwerkübersicht
JavaScript
1
star