Files
freeCodeCamp/utils/slugs.ts
palash-signoz 004c5b6fb6 chore(utils): ts-migration of utils/slugs (#44921)
* chore: utils is added in the tsconfig

* test(util): test and test function is updated to typescript

* chore: add tsconfig for utils

* fix: exclude files importing from client/

* fix: refactor to just export functions

* chore: add emitted files to prettierignore

* fix: add new tsconfig to eslint project

Co-authored-by: Shaun Hamilton <shauhami020@gmail.com>
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
2022-03-29 08:51:13 -07:00

25 lines
540 B
TypeScript

function dasherize(name: string): string {
return ('' + name)
.toLowerCase()
.trim()
.replace(/\s|\./g, '-')
.replace(/[^a-z\d\-.]/g, '');
}
function nameify(str: string): string {
return ('' + str).replace(/[^a-z\d\s]/gi, '');
}
function unDasherize(name: string): string {
return (
('' + name)
// replace dash with space
.replace(/-/g, ' ')
// strip nonalphanumarics chars except whitespace
.replace(/[^a-z\d\s]/gi, '')
.trim()
);
}
export { dasherize, nameify, unDasherize };