From c9b773d0c09530fdf04c7fdd67889b49d92e122b Mon Sep 17 00:00:00 2001 From: Craigory Coppola Date: Thu, 28 Sep 2023 12:06:34 -0400 Subject: [PATCH] fix: update typings to accept zero arguments The default export for cliui is a function that takes 1 or 0 arguments, as indicated in the examples in the readme. This updates the typescript typings so that passing zero arguments is valid --- deno.ts | 2 +- lib/cjs.ts | 2 +- lib/index.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/deno.ts b/deno.ts index a94e49f3..e0108d46 100644 --- a/deno.ts +++ b/deno.ts @@ -3,7 +3,7 @@ import { cliui, UI } from './build/lib/index.js' import type { UIOptions } from './build/lib/index.d.ts' import { wrap, stripAnsi } from './build/lib/string-utils.js' -export default function ui (opts: UIOptions): UI { +export default function ui (opts?: UIOptions): UI { return cliui(opts, { stringWidth: (str: string) => { return [...str].length diff --git a/lib/cjs.ts b/lib/cjs.ts index bda4241a..dbe2ef39 100644 --- a/lib/cjs.ts +++ b/lib/cjs.ts @@ -3,7 +3,7 @@ import { cliui, UIOptions } from './index.js' const stringWidth = require('string-width') const stripAnsi = require('strip-ansi') const wrap = require('wrap-ansi') -export default function ui (opts: UIOptions) { +export default function ui (opts?: UIOptions) { return cliui(opts, { stringWidth, stripAnsi, diff --git a/lib/index.ts b/lib/index.ts index 0673c3a5..b082b2a1 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -380,7 +380,7 @@ function alignCenter (str: string, width: number): string { } let mixin: Mixin -export function cliui (opts: Partial, _mixin: Mixin) { +export function cliui (opts: Partial | undefined | null, _mixin: Mixin) { mixin = _mixin return new UI({ width: opts?.width || getWindowWidth(),