FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
nodejs.dev/util-node/createSlug.js at main · nodejs/nodejs.dev · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
This repository was archived by the owner on Apr 26, 2024. It is now read-only.
nodejs
/
nodejs.dev
Public archive
Notifications
You must be signed in to change notification settings
Fork
1k
Star
2.3k
Code
Pull requests
0
Actions
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
nodejs.dev
/
util-node
/
createSlug.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
24 lines (20 loc) · 695 Bytes
Breadcrumbs
nodejs.dev
/
util-node
/
createSlug.js
Copy path
File metadata and controls
24 lines (20 loc) · 695 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function
createSlug
(
title
)
{
let
slug
=
title
.
toLowerCase
(
)
.
trim
(
)
;
const
sets
=
[
{
to
:
'nodejs'
,
from
:
/
n
o
d
e
.
j
s
/
}
,
// Replace node.js
{
to
:
'-and-'
,
from
:
/
&
/
}
,
// Replace &
{
to
:
'-'
,
from
:
/
[
/
_
,
:
;
\\
]
/
g
}
,
// Replace /_,:;\. and whitespace
]
;
sets
.
forEach
(
set
=>
{
slug
=
slug
.
replace
(
set
.
from
,
set
.
to
)
;
}
)
;
return
(
slug
// eslint-disable-next-line no-useless-escape
.
replace
(
/
[
^
\w
\-
]
+
/
g
,
''
)
// Remove any non word characters
.
replace
(
/
-
-
+
/
g
,
'-'
)
// Replace multiple hyphens with single
.
replace
(
/
^
-
/
,
''
)
// Remove any leading hyphen
.
replace
(
/
-
$
/
,
''
)
)
;
// Remove any trailing hyphen
}
module
.
exports
=
createSlug
;
Back
|
FazBrowse Home
|
New Git URL