@inquirer/core 9.0.0 → 9.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,12 +6,29 @@ It aims to implements a lightweight API similar to React hooks - but without JSX
6
6
 
7
7
  # Installation
8
8
 
9
+ <table>
10
+ <tr>
11
+ <th>npm</th>
12
+ <th>yarn</th>
13
+ </tr>
14
+ <tr>
15
+ <td>
16
+
9
17
  ```sh
10
18
  npm install @inquirer/core
19
+ ```
20
+
21
+ </td>
22
+ <td>
11
23
 
24
+ ```sh
12
25
  yarn add @inquirer/core
13
26
  ```
14
27
 
28
+ </td>
29
+ </tr>
30
+ </table>
31
+
15
32
  # Usage
16
33
 
17
34
  ```ts
@@ -0,0 +1,13 @@
1
+ export * from './lib/key.js';
2
+ export * from './lib/errors.js';
3
+ export { usePrefix } from './lib/use-prefix.js';
4
+ export { useState } from './lib/use-state.js';
5
+ export { useEffect } from './lib/use-effect.js';
6
+ export { useMemo } from './lib/use-memo.js';
7
+ export { useRef } from './lib/use-ref.js';
8
+ export { useKeypress } from './lib/use-keypress.js';
9
+ export { makeTheme } from './lib/make-theme.js';
10
+ export type { Theme } from './lib/theme.js';
11
+ export { usePagination } from './lib/pagination/use-pagination.js';
12
+ export { createPrompt } from './lib/create-prompt.js';
13
+ export { Separator } from './lib/Separator.js';
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Separator object
3
+ * Used to space/separate choices group
4
+ */
5
+ export declare class Separator {
6
+ readonly separator: string;
7
+ readonly type = "separator";
8
+ constructor(separator?: string);
9
+ static isSeparator(choice: undefined | Separator | Record<string, unknown>): choice is Separator;
10
+ }
@@ -0,0 +1,4 @@
1
+ import { type Prompt, type Prettify } from '@inquirer/type';
2
+ type ViewFunction<Value, Config> = (config: Prettify<Config>, done: (value: Value) => void) => string | [string, string | undefined];
3
+ export declare function createPrompt<Value, Config>(view: ViewFunction<Value, Config>): Prompt<Value, Config>;
4
+ export {};
@@ -0,0 +1,9 @@
1
+ export declare class CancelPromptError extends Error {
2
+ message: string;
3
+ }
4
+ export declare class ExitPromptError extends Error {
5
+ }
6
+ export declare class HookError extends Error {
7
+ }
8
+ export declare class ValidationError extends Error {
9
+ }
@@ -0,0 +1,30 @@
1
+ import type { InquirerReadline } from '@inquirer/type';
2
+ type HookStore = {
3
+ rl: InquirerReadline;
4
+ hooks: any[];
5
+ hooksCleanup: Array<void | (() => void)>;
6
+ hooksEffect: Array<() => void>;
7
+ index: number;
8
+ handleChange: () => void;
9
+ };
10
+ export declare function withHooks(rl: InquirerReadline, cb: (store: HookStore) => void): void;
11
+ export declare function readline(): InquirerReadline;
12
+ export declare function withUpdates<T extends (...args: any) => any>(fn: T): (...args: Parameters<T>) => ReturnType<T>;
13
+ type SetPointer<Value> = {
14
+ get(): Value;
15
+ set(value: Value): void;
16
+ initialized: true;
17
+ };
18
+ type UnsetPointer<Value> = {
19
+ get(): void;
20
+ set(value: Value): void;
21
+ initialized: false;
22
+ };
23
+ type Pointer<Value> = SetPointer<Value> | UnsetPointer<Value>;
24
+ export declare function withPointer<Value, ReturnValue>(cb: (pointer: Pointer<Value>) => ReturnValue): ReturnValue;
25
+ export declare function handleChange(): void;
26
+ export declare const effectScheduler: {
27
+ queue(cb: (readline: InquirerReadline) => void): void;
28
+ run(): void;
29
+ };
30
+ export {};
@@ -0,0 +1,10 @@
1
+ export type KeypressEvent = {
2
+ name: string;
3
+ ctrl: boolean;
4
+ };
5
+ export declare const isUpKey: (key: KeypressEvent) => boolean;
6
+ export declare const isDownKey: (key: KeypressEvent) => boolean;
7
+ export declare const isSpaceKey: (key: KeypressEvent) => boolean;
8
+ export declare const isBackspaceKey: (key: KeypressEvent) => boolean;
9
+ export declare const isNumberKey: (key: KeypressEvent) => boolean;
10
+ export declare const isEnterKey: (key: KeypressEvent) => boolean;
@@ -0,0 +1,3 @@
1
+ import type { Prettify, PartialDeep } from '@inquirer/type';
2
+ import { type Theme } from './theme.js';
3
+ export declare function makeTheme<SpecificTheme extends object>(...themes: ReadonlyArray<undefined | PartialDeep<Theme<SpecificTheme>>>): Prettify<Theme<SpecificTheme>>;
@@ -0,0 +1,26 @@
1
+ import { type Prettify } from '@inquirer/type';
2
+ /** Represents an item that's part of a layout, about to be rendered */
3
+ export type Layout<T> = {
4
+ item: T;
5
+ index: number;
6
+ isActive: boolean;
7
+ };
8
+ /**
9
+ * Renders a page of items as lines that fit within the given width ensuring
10
+ * that the number of lines is not greater than the page size, and the active
11
+ * item renders at the provided position, while prioritizing that as many lines
12
+ * of the active item get rendered as possible.
13
+ */
14
+ export declare function lines<T>({ items, width, renderItem, active, position: requested, pageSize, }: {
15
+ items: ReadonlyArray<T>;
16
+ /** The width of a rendered line in characters. */
17
+ width: number;
18
+ /** Renders an item as part of a page. */
19
+ renderItem: (layout: Prettify<Layout<T>>) => string;
20
+ /** The index of the active item in the list of items. */
21
+ active: number;
22
+ /** The position on the page at which to render the active item. */
23
+ position: number;
24
+ /** The number of lines to render per page. */
25
+ pageSize: number;
26
+ }): string[];
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Creates the next position for the active item considering a finite list of
3
+ * items to be rendered on a page.
4
+ */
5
+ export declare function finite({ active, pageSize, total, }: {
6
+ active: number;
7
+ pageSize: number;
8
+ total: number;
9
+ }): number;
10
+ /**
11
+ * Creates the next position for the active item considering an infinitely
12
+ * looping list of items to be rendered on the page.
13
+ */
14
+ export declare function infinite({ active, lastActive, total, pageSize, pointer, }: {
15
+ active: number;
16
+ lastActive: number;
17
+ total: number;
18
+ pageSize: number;
19
+ pointer: number;
20
+ }): number;
@@ -0,0 +1,15 @@
1
+ import type { Prettify } from '@inquirer/type';
2
+ import { type Theme } from '../theme.js';
3
+ import { type Layout } from './lines.js';
4
+ export declare function usePagination<T>({ items, active, renderItem, pageSize, loop, }: {
5
+ items: ReadonlyArray<T>;
6
+ /** The index of the active item. */
7
+ active: number;
8
+ /** Renders an item as part of a page. */
9
+ renderItem: (layout: Prettify<Layout<T>>) => string;
10
+ /** The size of the page. */
11
+ pageSize: number;
12
+ /** Allows creating an infinitely looping list. `true` if unspecified. */
13
+ loop?: boolean;
14
+ theme?: Theme;
15
+ }): string;
@@ -0,0 +1,13 @@
1
+ import type { InquirerReadline } from '@inquirer/type';
2
+ export default class ScreenManager {
3
+ private readonly rl;
4
+ private height;
5
+ private extraLinesUnderPrompt;
6
+ private cursorPos;
7
+ constructor(rl: InquirerReadline);
8
+ render(content: string, bottomContent?: string): void;
9
+ checkCursorPos(): void;
10
+ clean(): void;
11
+ clearContent(): void;
12
+ done(): void;
13
+ }
@@ -0,0 +1,20 @@
1
+ import type { Prettify } from '@inquirer/type';
2
+ type DefaultTheme = {
3
+ prefix: string;
4
+ spinner: {
5
+ interval: number;
6
+ frames: string[];
7
+ };
8
+ style: {
9
+ answer: (text: string) => string;
10
+ message: (text: string) => string;
11
+ error: (text: string) => string;
12
+ defaultAnswer: (text: string) => string;
13
+ help: (text: string) => string;
14
+ highlight: (text: string) => string;
15
+ key: (text: string) => string;
16
+ };
17
+ };
18
+ export type Theme<Extension extends object = object> = Prettify<Extension & DefaultTheme>;
19
+ export declare const defaultTheme: DefaultTheme;
20
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { InquirerReadline } from '@inquirer/type';
2
+ export declare function useEffect(cb: (rl: InquirerReadline) => void | (() => void), depArray: ReadonlyArray<unknown>): void;
@@ -0,0 +1,3 @@
1
+ import { type InquirerReadline } from '@inquirer/type';
2
+ import { type KeypressEvent } from './key.js';
3
+ export declare function useKeypress(userHandler: (event: KeypressEvent, rl: InquirerReadline) => void): void;
@@ -0,0 +1 @@
1
+ export declare function useMemo<Value>(fn: () => Value, dependencies: ReadonlyArray<unknown>): Value;
@@ -0,0 +1,5 @@
1
+ import { type Theme } from './theme.js';
2
+ export declare function usePrefix({ isLoading, theme, }: {
3
+ isLoading?: boolean;
4
+ theme?: Theme;
5
+ }): string;
@@ -0,0 +1,6 @@
1
+ export declare function useRef<Value>(val: Value): {
2
+ current: Value;
3
+ };
4
+ export declare function useRef<Value>(val?: Value): {
5
+ current: Value | undefined;
6
+ };
@@ -0,0 +1,4 @@
1
+ type NotFunction<T> = T extends Function ? never : T;
2
+ export declare function useState<Value>(defaultValue: NotFunction<Value> | (() => Value)): [Value, (newValue: Value) => void];
3
+ export declare function useState<Value>(defaultValue?: NotFunction<Value> | (() => Value)): [Value | undefined, (newValue?: Value | undefined) => void];
4
+ export {};
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Force line returns at specific width. This function is ANSI code friendly and it'll
3
+ * ignore invisible codes during width calculation.
4
+ * @param {string} content
5
+ * @param {number} width
6
+ * @return {string}
7
+ */
8
+ export declare function breakLines(content: string, width: number): string;
9
+ /**
10
+ * Returns the width of the active readline, or 80 as default value.
11
+ * @returns {number}
12
+ */
13
+ export declare function readlineWidth(): number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inquirer/core",
3
- "version": "9.0.0",
3
+ "version": "9.0.2",
4
4
  "engines": {
5
5
  "node": ">=18"
6
6
  },
@@ -69,10 +69,10 @@
69
69
  "signal-exit": "^4.1.0",
70
70
  "strip-ansi": "^6.0.1",
71
71
  "wrap-ansi": "^6.2.0",
72
- "yoctocolors-cjs": "^2.1.1"
72
+ "yoctocolors-cjs": "^2.1.2"
73
73
  },
74
74
  "devDependencies": {
75
- "@inquirer/testing": "^2.1.24"
75
+ "@inquirer/testing": "^2.1.25"
76
76
  },
77
77
  "scripts": {
78
78
  "tsc": "yarn run tsc:esm && yarn run tsc:cjs",
@@ -97,5 +97,5 @@
97
97
  }
98
98
  },
99
99
  "sideEffects": false,
100
- "gitHead": "fc27d575bceb96466cb8da8524c26d4eb2a77df0"
100
+ "gitHead": "95d2d65d3aca2c0fab66c7fd40b5dc413dfc894f"
101
101
  }