Improve tag punctuation handling
This commit is contained in:
parent
22ecb16804
commit
b83c20ac3d
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
@ -18,6 +18,7 @@
|
|||||||
"Makernote",
|
"Makernote",
|
||||||
"nanoids",
|
"nanoids",
|
||||||
"nextjs",
|
"nextjs",
|
||||||
|
"parameterizes",
|
||||||
"presigner",
|
"presigner",
|
||||||
"Provia",
|
"Provia",
|
||||||
"qaub",
|
"qaub",
|
||||||
|
|||||||
11
__tests__/string.test.ts
Normal file
11
__tests__/string.test.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { parameterize } from '@/utility/string';
|
||||||
|
|
||||||
|
describe('String', () => {
|
||||||
|
it('parameterizes', () => {
|
||||||
|
expect(parameterize('my tag')).toBe('my-tag');
|
||||||
|
expect(parameterize('My Tag')).toBe('my-tag');
|
||||||
|
expect(parameterize('my_tag')).toBe('my-tag');
|
||||||
|
expect(parameterize('person\'s tag')).toBe('persons-tag');
|
||||||
|
expect(parameterize('"person\'s tag"')).toBe('persons-tag');
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -19,5 +19,8 @@ export const capitalizeWords = (string = '') =>
|
|||||||
export const parameterize = (string: string) =>
|
export const parameterize = (string: string) =>
|
||||||
string
|
string
|
||||||
.trim()
|
.trim()
|
||||||
.replaceAll(/\s+/g, '-')
|
// Replaces spaces, underscores, and dashes with dashes
|
||||||
|
.replaceAll(/[\s_–—]/gi, '-')
|
||||||
|
// Removes all non-alphanumeric characters
|
||||||
|
.replaceAll(/([^a-z0-9-])/gi, '')
|
||||||
.toLowerCase();
|
.toLowerCase();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user