UNPKG

url-slugify

Version:

Creates SEO friendly URL slugs with multiple language support

70 lines (47 loc) 1.81 kB
# url-slugify [![Build Status](https://travis-ci.com/s-barrah/url-slugify.svg?token=TiEWxM8gcPjsU61yH7kx&branch=master)](https://travis-ci.com/s-barrah/url-slugify) [![npm version](https://img.shields.io/npm/v/url-slugify.svg?style=flat)](https://www.npmjs.com/package/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 ```bash $ npm install --save url-slugify ``` ## Usage ```javascript 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 ```javascript 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](./LICENSE)