Skip to content

Commit 2716260

Browse files
committed
chore: wip
1 parent d1ca98c commit 2716260

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

.stacks/core/strings/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"@types/validator": "^13.7.12",
6161
"change-case": "^4.1.2",
6262
"pluralize": "^8.0.0",
63+
"slugify": "^1.6.5",
6364
"validator": "^13.9.0"
6465
},
6566
"devDependencies": {

.stacks/core/strings/src/utils.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
import slugify from 'slugify'
2+
3+
interface SlugOptions {
4+
replacement?: string
5+
remove?: RegExp
6+
lower?: boolean
7+
strict?: boolean
8+
locale?: string
9+
trim?: boolean
10+
}
11+
112
/**
213
* Replace backslash to slash
314
*
@@ -78,3 +89,13 @@ export function randomStr(size = 16, dict = urlAlphabet) {
7889
export function capitalize(str: string): string {
7990
return str[0].toUpperCase() + str.slice(1).toLowerCase()
8091
}
92+
93+
export function slug(str: string, options?: SlugOptions): string {
94+
if (options)
95+
return slugify(str, options)
96+
97+
return slugify(str, {
98+
lower: true,
99+
strict: true,
100+
})
101+
}

0 commit comments

Comments
 (0)