Skip to content

Commit

Permalink
chore(utils): ts-migration of utils/slugs (freeCodeCamp#44921)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: Oliver Eyton-Williams <[email protected]>
  • Loading branch information
3 people authored Mar 29, 2022
1 parent 0a36905 commit 004c5b6
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 18 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"project": [
"./tsconfig.json",
"./config/tsconfig.json",
"./tools/ui-components/tsconfig.json"
"./tools/ui-components/tsconfig.json",
"./utils/tsconfig.json"
]
},
"extends": [
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ config/curriculum.json
config/i18n/all-langs.js
config/certification-settings.js

### Generated utils files ###
utils/slugs.js
utils/slugs.test.js

### vim ###
# Swap
Expand Down
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ config/i18n/all-langs.js
config/certification-settings.js
client/i18n/**/*.json
docs/i18n
utils/slugs.js
utils/slugs.test.js
**/package-lock.json
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
],
"scripts": {
"analyze-bundle": "webpack-bundle-analyzer",
"prebuild": "npm run create:config",
"prebuild": "npm-run-all create:*",
"build": "npm-run-all -p build:*",
"build-workers": "cd ./client && npm run prebuild",
"build:client": "cd ./client && npm run build",
Expand All @@ -46,6 +46,7 @@
"clean:packages": "rimraf ./**/node_modules",
"clean:server": "rimraf ./api-server/lib",
"create:config": "tsc -p config && npm run ensure-env",
"create:utils": "tsc -p utils",
"precypress": "node ./cypress-install.js",
"cypress": "cypress",
"cypress:dev:run": "npm run cypress -- run",
Expand All @@ -54,7 +55,7 @@
"cypress:install-build-tools": "sh ./cypress-install.sh",
"cypress:prd:run": "npm run cypress -- run",
"cypress:prd:watch": "npm run cypress -- open",
"predevelop": "npm run create:config",
"predevelop": "npm-run-all create:*",
"develop": "npm-run-all build:curriculum -p develop:*",
"develop:client": "npm run build:curriculum && cd ./client && npm run develop",
"develop:server": "npm run predevelop && cd ./api-server && npm run develop",
Expand All @@ -70,20 +71,20 @@
"format:prettier": "prettier --write .",
"hooks:install": "node node_modules/husky/husky.js install",
"hooks:uninstall": "node node_modules/husky/husky.js uninstall",
"lint": "npm-run-all create:config -p lint:*",
"lint": "npm-run-all create:* -p lint:*",
"lint:challenges": "cd ./curriculum && npm run lint",
"lint:js": "eslint --max-warnings 0 .",
"lint:ts": "tsc && tsc -p config && tsc -p tools/ui-components",
"lint:ts": "tsc && tsc -p config && tsc -p tools/ui-components && tsc -p utils",
"lint:prettier": "prettier --list-different .",
"seed": "cross-env DEBUG=fcc:* node ./tools/scripts/seed/seedAuthUser",
"seed:certified-user": "cross-env DEBUG=fcc:* node ./tools/scripts/seed/seedAuthUser certUser",
"serve:client": "cd ./client && npm run serve",
"serve:client-ci": "cd ./client && npm run serve-ci",
"start": "npm-run-all create:config -p develop:server serve:client",
"start-ci": "npm-run-all create:config -p start:server serve:client-ci",
"start": "npm-run-all create:* -p develop:server serve:client",
"start-ci": "npm-run-all create:* -p start:server serve:client-ci",
"start:server": "cd ./api-server && npm start",
"storybook": "cd ./tools/ui-components && npm run storybook",
"test": "run-s create:config build:curriculum build-workers test:*",
"test": "run-s create:* build:curriculum build-workers test:*",
"test:source": "jest",
"test:curriculum": "cd ./curriculum && npm test",
"test-curriculum-full-output": "cd ./curriculum && npm run test:full-output",
Expand Down
5 changes: 1 addition & 4 deletions utils/slugs.test.js → utils/slugs.test.ts
Original file line number Diff line number Diff line change
@@ -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('');
});
Expand All @@ -26,7 +25,6 @@ describe('dasherize', () => {
});

describe('nameify', () => {
const { nameify } = slugs;
it('returns a string', () => {
expect(nameify('')).toBe('');
});
Expand All @@ -36,7 +34,6 @@ describe('nameify', () => {
});

describe('unDasherize', () => {
const { unDasherize } = slugs;
it('returns a string', () => {
expect(unDasherize('')).toBe('');
});
Expand Down
14 changes: 8 additions & 6 deletions utils/slugs.js → utils/slugs.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -19,4 +19,6 @@ exports.unDasherize = function unDasherize(name) {
.replace(/[^a-z\d\s]/gi, '')
.trim()
);
};
}

export { dasherize, nameify, unDasherize };
9 changes: 9 additions & 0 deletions utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"include": ["**/*.ts", "**/*.test.ts"],
"exclude": ["./__fixtures__"],
"extends": "../tsconfig-base.json",
"compilerOptions": {
"noEmit": false,
"module": "CommonJS"
}
}

0 comments on commit 004c5b6

Please sign in to comment.