Skip to content

Commit 117cbba

Browse files
committed
Convert to TypeScript (#1)
1 parent 9a5dd9d commit 117cbba

File tree

8 files changed

+397
-168
lines changed

8 files changed

+397
-168
lines changed

.babelrc

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
11
{
2-
"presets": ["@babel/env"],
3-
"env": {
4-
"production-esm": {
5-
"presets": [["@babel/env", { "modules": false }]]
6-
}
7-
}
2+
"presets": ["@babel/typescript", "@babel/env"]
83
}

.eslintrc.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
{
2-
"extends": "wojtekmaj"
2+
"extends": [
3+
"wojtekmaj",
4+
"plugin:@typescript-eslint/eslint-recommended",
5+
"plugin:@typescript-eslint/recommended"
6+
],
7+
"parser": "@typescript-eslint/parser",
8+
"plugins": ["@typescript-eslint"]
39
}

package.json

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,25 @@
44
"description": "Check if a number is a valid Numer Identyfikacji Podatkowej (NIP)",
55
"main": "dist/cjs/index.js",
66
"module": "dist/esm/index.js",
7-
"source": "src/index.js",
7+
"source": "src/index.ts",
8+
"types": "src/index.ts",
89
"sideEffects": false,
910
"type": "module",
1011
"exports": {
1112
"default": "./dist/esm/index.js"
1213
},
1314
"scripts": {
1415
"build": "yarn build-esm && yarn build-cjs",
15-
"build-esm": "BABEL_ENV=production-esm babel src -d dist/esm --ignore **/*.spec.js",
16-
"build-cjs": "BABEL_ENV=production-cjs babel src -d dist/cjs --ignore **/*.spec.js",
16+
"build-esm": "tsc --project tsconfig.build.json --outDir dist/esm --module esnext",
17+
"build-cjs": "tsc --project tsconfig.build.json --outDir dist/cjs --module commonjs",
1718
"clean": "rimraf dist",
1819
"jest": "jest",
19-
"lint": "eslint src",
20+
"lint": "eslint src --ext .js,.ts",
2021
"postinstall": "husky install",
2122
"prepack": "yarn clean && yarn build",
2223
"prettier": "prettier --check . --cache",
23-
"test": "yarn lint && yarn prettier && yarn jest"
24+
"test": "yarn lint && yarn tsc && yarn prettier && yarn jest",
25+
"tsc": "tsc --noEmit"
2426
},
2527
"keywords": [
2628
"validation",
@@ -32,16 +34,20 @@
3234
},
3335
"license": "MIT",
3436
"devDependencies": {
35-
"@babel/cli": "^7.15.0",
3637
"@babel/core": "^7.15.0",
3738
"@babel/preset-env": "^7.15.0",
39+
"@babel/preset-typescript": "^7.18.6",
40+
"@types/jest": "^29.0.0",
41+
"@typescript-eslint/eslint-plugin": "^5.41.0",
42+
"@typescript-eslint/parser": "^5.44.0",
3843
"eslint": "^8.26.0",
3944
"eslint-config-wojtekmaj": "^0.7.1",
4045
"husky": "^8.0.0",
4146
"jest": "^29.0.0",
4247
"prettier": "^2.7.0",
4348
"pretty-quick": "^3.1.0",
44-
"rimraf": "^3.0.0"
49+
"rimraf": "^3.0.0",
50+
"typescript": "^4.9.4"
4551
},
4652
"resolutions": {
4753
"semver@7.0.0": "^7.0.0"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import isValidNIP from './index';
22

33
describe('isValidNIP', () => {
44
it('returns false for no input', () => {
5+
// @ts-expect-error-next-line
56
const result = isValidNIP();
67

78
expect(result).toBe(false);

src/index.js renamed to src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const weights = [6, 5, 7, 2, 3, 4, 5, 6, 7];
22

3-
export default function isValidNIP(rawNip) {
3+
export default function isValidNIP(rawNip: string | number): boolean {
44
if (!rawNip) {
55
return false;
66
}

tsconfig.build.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"exclude": ["src/**/*.spec.ts"]
4+
}

tsconfig.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"compilerOptions": {
3+
"declaration": true,
4+
"esModuleInterop": true,
5+
"isolatedModules": true,
6+
"moduleResolution": "node",
7+
"outDir": "dist",
8+
"strict": true
9+
},
10+
"include": ["src"]
11+
}

0 commit comments

Comments
 (0)