url-slugify
v1.0.6
Published
Creates SEO friendly URL slugs with multiple language support
Downloads
545
Maintainers
Readme
url-slugify
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