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 typings #2

Merged
merged 6 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
71 changes: 71 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import EventEmitter from 'bare-events'

export class Socket extends EventEmitter {
kasperisager marked this conversation as resolved.
Show resolved Hide resolved
constructor(opts?: { ipv6Only?: boolean; reuseAddress?: boolean })

address(): { address: string; family: string; port: number } | null

remoteAddress(): { address: string; family: string; port: number } | null

bind(port: number, address: string, cb?: Function): this
bind(opts: { port?: number; address?: string }, cb?: Function): this
bind(port: number, cb?: Function): this
bind(cb?: Function): this

connect(port: number, address: string, cb?: Function): void
connect(port: number, cb?: Function): void

close(cb?: Function): Promise<void>

send(
msg: unknown,
offset: number,
length: number,
port?: number,
address?: string,
cb?: Function
): Promise<void>

send(
msg: unknown,
offset: number,
length: number,
port: number,
cb: Function
): Promise<void>

send(
msg: unknown,
offset: number,
length: number,
address: string,
cb: Function
): Promise<void>

send(
msg: unknown,
offset: number,
address: string,
cb: Function
): Promise<void>

send(
msg: unknown,
offset: number,
length: number,
cb: Function
): Promise<void>

send(msg: unknown, port: number, address: string): Promise<void>

send(msg: unknown, port: number, cb?: Function): Promise<void>

send(msg: unknown, address: string): Promise<void>

send(msg: unknown, cb: Function): Promise<void>
}

export function createSocket(
opts?: { ipv6Only?: boolean; reuseAddress?: boolean } | string,
cb?: Function
): Socket
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
"version": "1.0.1",
"description": "Native UDP for JavaScript",
"exports": {
".": "./index.js",
".": {
"types": "./index.d.ts",
"default": "./index.js"
},
"./package": "./package.json"
},
"files": [
"index.js"
"index.js",
"./index.d.ts"
],
"scripts": {
"test": "prettier . --check && bare test.js"
Expand Down
Loading