Miss any of our Open RFC calls?Watch the recordings here! »

url-slugify

1.0.6 • Public • Published

url-slugify Build Status npm version

URL Slug generator. It combines a page title and a unique id to create an SEO-friendly slug, safe for use in URL paths and queries.

Install

$ npm install --save url-slugify

Usage

const URLSlugify = require('url-slugify')
 
const urlSlugify = new URLSlugify();
 
urlSlugify.slugify('Hello world', '-')
// hello-world-6y6106gq

Documentation

urlSlugify(title: string, separator: string)

Returns the title value converted to a unique SEO-friendly slug.

title

Type: string - The title that will be converted.

separator

Type: string (optional) - The character used to separate the slug fragments, set to '-' by default. Can be set to '-', '_', '~' or ''.

Example

const URLSlugify = require('url-slugify')
 
const urlSlugify = new URLSlugify();
 
// Using default options
urlSlugify.slugify('Hello world')
// hello-world-b16lmdaeqdl
 
// Using optional separators
urlSlugify.slugify('Hello world', '_')
// hello_world_11vlkkpgyg3
 
urlSlugify.slugify('Hello world', '~')
// hello~world~jzbaroggg2
 
// Replaces not allowed characters
urlSlugify.slugify('Hello[%) [} world£!')
// hello-world-9gh134gk45
 
// Replaces characters with accents such as ã, í, é, ẽ, ì 
// with SEO-friendly characters
urlSlugify.slugify('thís îs ã tést tìtlẽ')
// this-is-a-test-title-q0zkkrpbzz
 
// Removes whitespaces with the separator ''
urlSlugify.slugify('Hello World', '\'\'')
// helloworldyl822qdy89
 

License

The MIT License

Install

npm i url-slugify

DownloadsWeekly Downloads

31

Version

1.0.6

License

MIT

Unpacked Size

203 kB

Total Files

11

Last publish

Collaborators

  • avatar