Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add typescript declarations #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
!lib/**/*
!package.json
!index.js
!index.d.ts
!LICENSE
16 changes: 16 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Type definitions for portastic v1.0.1
// Project: portastic
// Definitions by: James Booth github.com/jabooth

export function test(port: number, interface?: string, callback?: Function): Promise<boolean>

export function find(options: {min?: number, max?: number, retrieve?: number},
interface?: string, callback?: Function): Promise<number[]>

export function filter(ports: number[], interface?: string, callback?: Function): Promise<number[]>

import { EventEmitter } from 'events'
export class Monitor extends EventEmitter {
constructor(ports: number[])
on(event: "open" | "close", listener: (port: number) => void): this
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.0.1",
"description": "Pure javascript swiss knife for port management",
"main": "index.js",
"types": "index.d.ts",
"scripts": {
"test": "mocha --tdd --bail test/**/*-test.js",
"travis": "./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha --report lcovonly -- -R spec test/**/*-test.js && cat ./coverage/lcov.info | ./node_modules/.bin/coveralls && rm -rf ./coverage"
Expand All @@ -28,6 +29,7 @@
},
"homepage": "https://github.com/alanhoff/node-portastic#readme",
"dependencies": {
"@types/node": "0.0.2",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that you expose an object that subclasses EventEmitter from node - a consumer of your API therefore needs the node typing information to fully understand your public API, hence the addition of the node types as dependency and not a devDependency (see Packaging dependent declarations)

"bluebird": "^2.9.34",
"commander": "^2.8.1",
"debug": "^2.2.0"
Expand Down