Gathering detailed insights and metrics for url-slug
Gathering detailed insights and metrics for url-slug
Gathering detailed insights and metrics for url-slug
Gathering detailed insights and metrics for url-slug
Slug generator with less than 1 KB and no dependencies, RFC 3986 compliant
npm install url-slug
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99.3
Supply Chain
99.5
Quality
76
Maintenance
100
Vulnerability
100
License
TypeScript (98.68%)
Shell (1.32%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
89 Stars
103 Commits
8 Forks
3 Watchers
4 Branches
4 Contributors
Updated on Mar 23, 2025
Latest Version
4.0.1
Package Id
url-slug@4.0.1
Unpacked Size
33.24 kB
Size
7.94 kB
File Count
9
NPM Version
9.5.1
Node Version
18.16.0
Published on
Jun 18, 2023
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
20
1npm install url-slug
1import urlSlug from 'url-slug' 2 3urlSlug('Sir James Paul McCartney MBE is an English singer-songwriter') 4// sir-james-paul-mc-cartney-mbe-is-an-english-singer-songwriter
⚠️ Only named exports are available in Node.js.
1import { convert } from 'url-slug' 2 3urlSlug('Sir James Paul McCartney MBE is an English singer-songwriter') 4// sir-james-paul-mc-cartney-mbe-is-an-english-singer-songwriter
1const { convert } = require('url-slug') 2 3urlSlug('Sir James Paul McCartney MBE is an English singer-songwriter') 4// sir-james-paul-mc-cartney-mbe-is-an-english-singer-songwriter
Returns value
value converted to a slug.
A string to be slugified.
Name | Description | Default |
---|---|---|
camelCase | Split on camel case occurrences | true |
dictionary | Chars to be replaced | {} |
separator | Character or string used to separate the slug fragments | '-' |
transformer | A built-in transformer or a custom function (null to keep the string unchanged) | LOWERCASE_TRANSFORMER |
1import * as urlSlug from 'url-slug' 2 3urlSlug.convert('Comfortably Numb', { 4 transformer: urlSlug.UPPERCASE_TRANSFORMER, 5}) 6// COMFORTABLY-NUMB 7 8urlSlug.convert('á é í ó ú Á É Í Ó Ú ç Ç ª º ¹ ² ½ ¼', { 9 separator: '_', 10 transformer: false, 11}) 12// a_e_i_o_u_A_E_I_O_U_c_C_a_o_1_2_1_2_1_4 13 14urlSlug.convert('Red, red wine, stay close to me…', { 15 separator: '', 16 transformer: urlSlug.TITLECASE_TRANSFORMER, 17}) 18// RedRedWineStayCloseToMe 19 20urlSlug.convert('Schwarzweiß', { 21 dictionary: { ß: 'ss', z: 'z ' }, 22}) 23// schwarz-weiss
Returns the value
value converted to a regular sentence.
A slug to be reverted to a sentence.
Name | Description | Default |
---|---|---|
camelCase | Split on camel case occurrences | false |
separator | Character or string to split the slug (null for automatic splitting) | null |
transformer | A built-in transformer or a custom function (null to keep the string unchanged) | false |
1import { revert, TITLECASE_TRANSFORMER } from 'url-slug' 2 3revert('Replace-every_separator.allowed~andSplitCamelCaseToo', { 4 camelCase: true, 5}) 6// Replace every separator allowed and Split Camel Case Too 7 8revert('this-slug-needs-a-title_case', { 9 separator: '-', 10 transformer: TITLECASE_TRANSFORMER, 11}) 12// This Slug Needs A Title_case
Custom transformers are expressed by a function that receives two arguments:
fragments
, an array containing the words of a sentence or a slug, and
separator
, which is the separator string set in convert()
options. When
revert()
calls a transformer, the separator
argument will always be a space
character (' '
) — the separator
option will be used to split the slug.
Transformers should always return a string.
1import { convert, revert } from 'url-slug' 2 3convert('O’Neill is an American surfboard, surfwear and equipment brand', { 4 transformer: (fragments) => fragments.join('x').toUpperCase(), 5}) 6// OxNEILLxISxANxAMERICANxSURFBOARDxSURFWEARxANDxEQUIPMENTxBRAND 7 8revert('WEIrd_SNAke_CAse', { 9 separator: '_', 10 transformer: (fragments, separator) => 11 fragments 12 .map( 13 (fragment) => 14 fragment.slice(0, -2).toLowerCase() + fragment.slice(-2).toUpperCase() 15 ) 16 .join(separator), 17}) 18// weiRD snaKE caSE
Converts the result to lowercase. E.g.: // SOME WORDS >> some words
Converts the result to sentence case. E.g.: // sOME WORDS >> Some words
Converts the result to uppercase. E.g.: // some words >> SOME WORDS
Converts the result to title case. E.g.: // sOME wORDS >> Some Words
Any character or an empty string can be used in the separator
property. When
the separator
is an empty string, the revert()
method will split the slug
only on camel case occurrences if camelCase
option is set to true
,
or else it returns an untouched string. The following characters are valid
according to RFC 3986 — defined as unreserved or sub-delims —, and will be
used in revert()
function if automatic splitting is enabled — separator
is
set to null
:
-
, .
, _
, ~
, ^
, -
, .
, _
, ~
, !
, $
, &
, '
, (
, )
, *
,
+
, ,
, ;
or =
dictionary
optionIt must be an object, with keys set as single characters and values as strings of any length:
1import { convert } from 'url-slug' 2 3convert('♥øß', { 4 dictionary: { 5 '♥': 'love', 6 ø: 'o', 7 ß: 'ss', 8 //... 9 }, 10}) 11// loveoss
To add separators before or after a specific character, add a space before or after the dictionary definition:
1import { convert } from 'url-slug' 2 3convert('♥øß', { 4 dictionary: { 5 '♥': 'love', 6 ø: ' o', // A space was added before 7 ß: 'ss', 8 //... 9 }, 10}) 11// love-oss 12 13convert('♥øß', { 14 dictionary: { 15 '♥': 'love', 16 ø: ' o ', // A space was added before and after 17 ß: 'ss', 18 //... 19 }, 20}) 21// love-o-ss 22 23convert('♥øß', { 24 dictionary: { 25 '♥': 'love', 26 ø: 'o ', // A space was added after 27 ß: 'ss', 28 //... 29 }, 30}) 31// loveo-ss
Compatible with any environment with ES6 support.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
10 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More