Skip to content

Commit

Permalink
feat: allow config to be string or number
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Dec 4, 2020
1 parent 526ad3e commit 13f4275
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export interface GetPortOptions {
memoName: string
}

export type GetPortInput = Partial<GetPortOptions> | number | string

const defaults = {
name: 'default',
random: false,
Expand All @@ -18,7 +20,11 @@ const defaults = {
memoName: 'port'
}

export async function getPort (config?: Partial<GetPortOptions>): Promise<number> {
export async function getPort (config?: GetPortInput): Promise<number> {
if (typeof config === 'number' || typeof config === 'string') {
config = { port: parseInt(config + '') }
}

const options = { ...defaults, ...config } as GetPortOptions

const portsToCheck: number[] = []
Expand Down

0 comments on commit 13f4275

Please sign in to comment.