Skip to content

Commit f1c4926

Browse files
authored
Convert to TypeScript (#30)
1 parent b13298d commit f1c4926

File tree

7 files changed

+356
-29
lines changed

7 files changed

+356
-29
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/browser"
2+
"extends": [
3+
"wojtekmaj/browser",
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: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,20 @@
44
"description": "A function that tells you whether a given element is overflowing its container or not. Useful for creating dropdowns and tooltips.",
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
"scripts": {
1011
"build": "yarn build-esm && yarn build-cjs",
11-
"build-esm": "BABEL_ENV=production-esm babel src -d dist/esm --ignore \"**/*.spec.js\"",
12-
"build-cjs": "BABEL_ENV=production-cjs babel src -d dist/cjs --ignore \"**/*.spec.js\"",
12+
"build-esm": "tsc --project tsconfig.build.json --outDir dist/esm --module esnext",
13+
"build-cjs": "tsc --project tsconfig.build.json --outDir dist/cjs --module commonjs",
1314
"clean": "rimraf dist",
1415
"lint": "eslint src",
1516
"postinstall": "husky install",
1617
"prepack": "yarn clean && yarn build",
1718
"prettier": "prettier --check . --cache",
18-
"test": "yarn lint && yarn prettier"
19+
"test": "yarn lint && yarn tsc && yarn prettier",
20+
"tsc": "tsc --noEmit"
1921
},
2022
"keywords": [
2123
"collision",
@@ -31,12 +33,16 @@
3133
"@babel/cli": "^7.15.0",
3234
"@babel/core": "^7.15.0",
3335
"@babel/preset-env": "^7.15.0",
36+
"@babel/preset-typescript": "^7.18.6",
37+
"@typescript-eslint/eslint-plugin": "^5.41.0",
38+
"@typescript-eslint/parser": "^5.44.0",
3439
"eslint": "^8.26.0",
3540
"eslint-config-wojtekmaj": "^0.7.1",
3641
"husky": "^8.0.0",
3742
"prettier": "^2.7.0",
3843
"pretty-quick": "^3.1.0",
39-
"rimraf": "^3.0.0"
44+
"rimraf": "^3.0.0",
45+
"typescript": "^4.9.4"
4046
},
4147
"resolutions": {
4248
"[email protected]": "^7.0.0"

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
function getRect(element) {
1+
function getRect(element: HTMLElement) {
22
return element.getBoundingClientRect();
33
}
44

5-
export default function detectElementOverflow(element, container) {
5+
export default function detectElementOverflow(element: HTMLElement, container: HTMLElement) {
66
return {
77
get collidedTop() {
88
return getRect(element).top < getRect(container).top;

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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"compilerOptions": {
3+
"declaration": true,
4+
"esModuleInterop": true,
5+
"isolatedModules": true,
6+
"moduleResolution": "node",
7+
"outDir": "dist",
8+
"strict": true,
9+
"target": "es5"
10+
},
11+
"include": ["src"]
12+
}

0 commit comments

Comments
 (0)