Skip to content

Commit

Permalink
Add type definitions for TypeScript (#70)
Browse files Browse the repository at this point in the history
Closes #48

Signed-off-by: Jon Koops <[email protected]>
  • Loading branch information
jonkoops authored Jul 9, 2024
1 parent 6487591 commit dc74ac5
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ npm i [email protected] -g
## Usage

```js
import why from 'why-is-node-running' // should be your first import
import whyIsNodeRunning from 'why-is-node-running' // should be your first import
import net from 'node:net'

function createServer () {
Expand All @@ -32,7 +32,7 @@ createServer()
createServer()

setTimeout(function () {
why() // logs out active handles that are keeping node running
whyIsNodeRunning() // logs out active handles that are keeping node running
}, 100)
```

Expand Down
4 changes: 2 additions & 2 deletions example.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import why from './index.js'
import whyIsNodeRunning from './index.js'
import net from 'node:net'

function createServer () {
Expand All @@ -11,5 +11,5 @@ createServer()
createServer()

setTimeout(function () {
why()
whyIsNodeRunning()
}, 100)
4 changes: 2 additions & 2 deletions include.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import why from './index.js'
import whyIsNodeRunning from './index.js'
import siginfo from 'siginfo'

siginfo(why, true)
siginfo(whyIsNodeRunning, true)
25 changes: 25 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* An interface that can be implemented to customize how information is logged. For example:
*
* ```ts
* import whyIsNodeRunning, { type Logger } from 'why-is-node-running'
*
* const logger: Logger = {
* error(message) {
* console.error(message)
* }
* }
*
* whyIsNodeRunning(logger)
* ```
*/
export interface Logger {
error(message: string): void
}

/**
* Logs the locations of all the active handles that prevent Node.js from exiting.
*
* @param logger An optional {@link Logger} to use for logging messages. If not provided, the console will be used.
*/
export default function whyIsNodeRunning(logger?: Logger): void
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"version": "3.0.0",
"description": "Node is running but you don't know why? why-is-node-running is here to help you.",
"exports": {
".": "./index.js",
".": {
"types": "./index.d.ts",
"default": "./index.js"
},
"./include": "./include.js"
},
"dependencies": {
Expand Down

0 comments on commit dc74ac5

Please sign in to comment.