Skip to content

Commit

Permalink
add tsc type checks
Browse files Browse the repository at this point in the history
  • Loading branch information
SkwalExe committed May 23, 2024
1 parent 8336433 commit f0c0c52
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ jobs:
- run: npm install --include=dev
- name: Check linting
run: npm run lint
- name: Check type errors
run: npm run check-types
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,9 @@ git checkout -b my-new-feature
- When you finished your changes, you must check your code's formatting and linting and fix all the errors.

```bash
npm run lint:fix
npm run format
npm run lint:fix # check for linting errors
npm run check-types # check for type errors
npm run format # comply with foramtting rules
```

- After that, add your changes to `CHANGELOG.md` and update the README if needed.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
},
"scripts": {
"lint": "eslint .",
"check-types": "tsc --noEmit",
"lint:fix": "eslint --fix .",
"format": "prettier ./src/**/*.ts --config prettier.config.mjs --write",
"clean": "shx rm -rf ./dist",
Expand Down
23 changes: 16 additions & 7 deletions src/winmb.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GetRandomInt, $$, playSound } from "./utils"
import {GetRandomInt, $$, playSound} from './utils'

// The name of the css file to import from the assets path
const cssFileName = 'winmb.css'
Expand Down Expand Up @@ -59,11 +59,15 @@ export default class WinMB {
position: string | Array<number> = 'default'
): Promise<boolean | string | number> => {
if (typeof position === 'string' && !['random', 'default'].includes(position))
throw new Error('Position must be either "random", "default", or an array of two numbers [x, y].')
throw new Error(
'Position must be either "random", "default", or an array of two numbers [x, y].'
)
if (!['info', 'error', 'warning'].includes(type))
throw new Error('Invalid message type : please use "info", "error" or "warning"')
if (!Array.isArray(buttons)) throw new Error('Invalid buttons : please use an array of [label, returnValue]')
if (!(buttons.length > 0)) throw new Error('Invalid button list : please specify at least one button')
if (!Array.isArray(buttons))
throw new Error('Invalid buttons : please use an array of [label, returnValue]')
if (!(buttons.length > 0))
throw new Error('Invalid button list : please specify at least one button')

return new Promise((resolve) => {
let startMouseX = 0
Expand All @@ -89,7 +93,8 @@ export default class WinMB {
if (position === 'random')
position = [GetRandomInt(0, window.innerWidth), GetRandomInt(0, window.innerHeight)]
else if (position === 'default')
messageBox.style.left = messageBox.style.top = 100 + (this.boxList.length + 1) * 15 + 'px'
messageBox.style.left = messageBox.style.top =
100 + (this.boxList.length + 1) * 15 + 'px'

messageBox.style.left = position[0] + 'px'
messageBox.style.top = position[1] + 'px'
Expand Down Expand Up @@ -142,8 +147,12 @@ export default class WinMB {
startMouseY = event.clientY
setZIndex()

startMessagePosX = parseInt(messageBox.style.left.substring(0, messageBox.style.left.length - 2))
startMessagePosY = parseInt(messageBox.style.top.substring(0, messageBox.style.top.length - 2))
startMessagePosX = parseInt(
messageBox.style.left.substring(0, messageBox.style.left.length - 2)
)
startMessagePosY = parseInt(
messageBox.style.top.substring(0, messageBox.style.top.length - 2)
)
}

titleBar.onmouseup = function () {
Expand Down

0 comments on commit f0c0c52

Please sign in to comment.