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>
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
const slugs = require('./slugs');
|
||||
import { dasherize, nameify, unDasherize } from './slugs';
|
||||
|
||||
describe('dasherize', () => {
|
||||
const { dasherize } = slugs;
|
||||
it('returns a string', () => {
|
||||
expect(dasherize('')).toBe('');
|
||||
});
|
||||
@ -26,7 +25,6 @@ describe('dasherize', () => {
|
||||
});
|
||||
|
||||
describe('nameify', () => {
|
||||
const { nameify } = slugs;
|
||||
it('returns a string', () => {
|
||||
expect(nameify('')).toBe('');
|
||||
});
|
||||
@ -36,7 +34,6 @@ describe('nameify', () => {
|
||||
});
|
||||
|
||||
describe('unDasherize', () => {
|
||||
const { unDasherize } = slugs;
|
||||
it('returns a string', () => {
|
||||
expect(unDasherize('')).toBe('');
|
||||
});
|
@ -1,16 +1,16 @@
|
||||
exports.dasherize = function dasherize(name) {
|
||||
function dasherize(name: string): string {
|
||||
return ('' + name)
|
||||
.toLowerCase()
|
||||
.trim()
|
||||
.replace(/\s|\./g, '-')
|
||||
.replace(/[^a-z\d\-.]/g, '');
|
||||
};
|
||||
}
|
||||
|
||||
exports.nameify = function nameify(str) {
|
||||
function nameify(str: string): string {
|
||||
return ('' + str).replace(/[^a-z\d\s]/gi, '');
|
||||
};
|
||||
}
|
||||
|
||||
exports.unDasherize = function unDasherize(name) {
|
||||
function unDasherize(name: string): string {
|
||||
return (
|
||||
('' + name)
|
||||
// replace dash with space
|
||||
@ -19,4 +19,6 @@ exports.unDasherize = function unDasherize(name) {
|
||||
.replace(/[^a-z\d\s]/gi, '')
|
||||
.trim()
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export { dasherize, nameify, unDasherize };
|
9
utils/tsconfig.json
Normal file
9
utils/tsconfig.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"include": ["**/*.ts", "**/*.test.ts"],
|
||||
"exclude": ["./__fixtures__"],
|
||||
"extends": "../tsconfig-base.json",
|
||||
"compilerOptions": {
|
||||
"noEmit": false,
|
||||
"module": "CommonJS"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user