@inquirer/core 8.0.1 → 8.1.0

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.
@@ -16,7 +16,7 @@ class Separator {
16
16
  enumerable: true,
17
17
  configurable: true,
18
18
  writable: true,
19
- value: chalk_1.default.dim(new Array(15).join(figures_1.default.line))
19
+ value: chalk_1.default.dim(Array.from({ length: 15 }).join(figures_1.default.line))
20
20
  });
21
21
  Object.defineProperty(this, "type", {
22
22
  enumerable: true,
@@ -64,8 +64,8 @@ function createPrompt(view) {
64
64
  cleanFn === null || cleanFn === void 0 ? void 0 : cleanFn();
65
65
  });
66
66
  }
67
- catch (err) {
68
- reject(err);
67
+ catch (error) {
68
+ reject(error);
69
69
  }
70
70
  if (context === null || context === void 0 ? void 0 : context.clearPromptOnDone) {
71
71
  screen.clean();
@@ -98,9 +98,9 @@ function createPrompt(view) {
98
98
  screen.render(content, bottomContent);
99
99
  hook_engine_mjs_1.effectScheduler.run();
100
100
  }
101
- catch (err) {
101
+ catch (error) {
102
102
  onExit();
103
- reject(err);
103
+ reject(error);
104
104
  }
105
105
  }
106
106
  workLoop(config);
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ /* eslint @typescript-eslint/no-explicit-any: ["off"] */
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.effectScheduler = exports.handleChange = exports.withPointer = exports.withUpdates = exports.readline = exports.withHooks = void 0;
4
5
  const node_async_hooks_1 = require("node:async_hooks");
@@ -13,7 +13,7 @@ function split(content, width) {
13
13
  function rotate(count, items) {
14
14
  const max = items.length;
15
15
  const offset = ((count % max) + max) % max;
16
- return items.slice(offset).concat(items.slice(0, offset));
16
+ return [...items.slice(offset), ...items.slice(0, offset)];
17
17
  }
18
18
  /**
19
19
  * Renders a page of items as lines that fit within the given width ensuring
@@ -30,7 +30,7 @@ function lines({ items, width, renderItem, active, position: requested, pageSize
30
30
  const layoutsInPage = rotate(active - requested, layouts).slice(0, pageSize);
31
31
  const renderItemAt = (index) => split(renderItem(layoutsInPage[index]), width);
32
32
  // Create a blank array of lines for the page
33
- const pageBuffer = new Array(pageSize);
33
+ const pageBuffer = Array.from({ length: pageSize });
34
34
  // Render the active item to decide the position
35
35
  const activeItem = renderItemAt(requested).slice(0, pageSize);
36
36
  const position = requested + activeItem.length <= pageSize ? requested : pageSize - activeItem.length;
@@ -48,7 +48,7 @@ class ScreenManager {
48
48
  // rl.line (mainly because of the password prompt), so just rely on it's
49
49
  // length.
50
50
  let prompt = rawPromptLine;
51
- if (this.rl.line.length) {
51
+ if (this.rl.line.length > 0) {
52
52
  prompt = prompt.slice(0, -this.rl.line.length);
53
53
  }
54
54
  this.rl.setPrompt(prompt);
@@ -1,3 +1,3 @@
1
1
  import type { Prettify, PartialDeep } from '@inquirer/type';
2
2
  import { type Theme } from './theme.js';
3
- export declare function makeTheme<SpecificTheme extends {}>(...themes: ReadonlyArray<undefined | PartialDeep<Theme<SpecificTheme>>>): Prettify<Theme<SpecificTheme>>;
3
+ export declare function makeTheme<SpecificTheme extends object>(...themes: ReadonlyArray<undefined | PartialDeep<Theme<SpecificTheme>>>): Prettify<Theme<SpecificTheme>>;
@@ -15,6 +15,6 @@ type DefaultTheme = {
15
15
  key: (text: string) => string;
16
16
  };
17
17
  };
18
- export type Theme<Extension extends {} = {}> = Prettify<Extension & DefaultTheme>;
18
+ export type Theme<Extension extends object = object> = Prettify<Extension & DefaultTheme>;
19
19
  export declare const defaultTheme: DefaultTheme;
20
20
  export {};
@@ -1,3 +1,6 @@
1
1
  export declare function useRef<Value>(val: Value): {
2
2
  current: Value;
3
3
  };
4
+ export declare function useRef<Value>(val?: Value): {
5
+ current: Value | undefined;
6
+ };
@@ -1,3 +1,4 @@
1
1
  type NotFunction<T> = T extends Function ? never : T;
2
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];
3
4
  export {};
@@ -5,7 +5,7 @@ import figures from '@inquirer/figures';
5
5
  * Used to space/separate choices group
6
6
  */
7
7
  export class Separator {
8
- separator = chalk.dim(new Array(15).join(figures.line));
8
+ separator = chalk.dim(Array.from({ length: 15 }).join(figures.line));
9
9
  type = 'separator';
10
10
  constructor(separator) {
11
11
  if (separator) {
@@ -34,8 +34,8 @@ export function createPrompt(view) {
34
34
  cleanFn?.();
35
35
  });
36
36
  }
37
- catch (err) {
38
- reject(err);
37
+ catch (error) {
38
+ reject(error);
39
39
  }
40
40
  if (context?.clearPromptOnDone) {
41
41
  screen.clean();
@@ -68,9 +68,9 @@ export function createPrompt(view) {
68
68
  screen.render(content, bottomContent);
69
69
  effectScheduler.run();
70
70
  }
71
- catch (err) {
71
+ catch (error) {
72
72
  onExit();
73
- reject(err);
73
+ reject(error);
74
74
  }
75
75
  }
76
76
  workLoop(config);
@@ -1,3 +1,4 @@
1
+ /* eslint @typescript-eslint/no-explicit-any: ["off"] */
1
2
  import { AsyncLocalStorage, AsyncResource } from 'node:async_hooks';
2
3
  import { HookError, ValidationError } from './errors.mjs';
3
4
  const hookStorage = new AsyncLocalStorage();
@@ -10,7 +10,7 @@ function split(content, width) {
10
10
  function rotate(count, items) {
11
11
  const max = items.length;
12
12
  const offset = ((count % max) + max) % max;
13
- return items.slice(offset).concat(items.slice(0, offset));
13
+ return [...items.slice(offset), ...items.slice(0, offset)];
14
14
  }
15
15
  /**
16
16
  * Renders a page of items as lines that fit within the given width ensuring
@@ -27,7 +27,7 @@ export function lines({ items, width, renderItem, active, position: requested, p
27
27
  const layoutsInPage = rotate(active - requested, layouts).slice(0, pageSize);
28
28
  const renderItemAt = (index) => split(renderItem(layoutsInPage[index]), width);
29
29
  // Create a blank array of lines for the page
30
- const pageBuffer = new Array(pageSize);
30
+ const pageBuffer = Array.from({ length: pageSize });
31
31
  // Render the active item to decide the position
32
32
  const activeItem = renderItemAt(requested).slice(0, pageSize);
33
33
  const position = requested + activeItem.length <= pageSize ? requested : pageSize - activeItem.length;
@@ -24,7 +24,7 @@ export default class ScreenManager {
24
24
  // rl.line (mainly because of the password prompt), so just rely on it's
25
25
  // length.
26
26
  let prompt = rawPromptLine;
27
- if (this.rl.line.length) {
27
+ if (this.rl.line.length > 0) {
28
28
  prompt = prompt.slice(0, -this.rl.line.length);
29
29
  }
30
30
  this.rl.setPrompt(prompt);
@@ -1,3 +1,3 @@
1
1
  import type { Prettify, PartialDeep } from '@inquirer/type';
2
2
  import { type Theme } from './theme.mjs';
3
- export declare function makeTheme<SpecificTheme extends {}>(...themes: ReadonlyArray<undefined | PartialDeep<Theme<SpecificTheme>>>): Prettify<Theme<SpecificTheme>>;
3
+ export declare function makeTheme<SpecificTheme extends object>(...themes: ReadonlyArray<undefined | PartialDeep<Theme<SpecificTheme>>>): Prettify<Theme<SpecificTheme>>;
@@ -15,6 +15,6 @@ type DefaultTheme = {
15
15
  key: (text: string) => string;
16
16
  };
17
17
  };
18
- export type Theme<Extension extends {} = {}> = Prettify<Extension & DefaultTheme>;
18
+ export type Theme<Extension extends object = object> = Prettify<Extension & DefaultTheme>;
19
19
  export declare const defaultTheme: DefaultTheme;
20
20
  export {};
@@ -1,3 +1,6 @@
1
1
  export declare function useRef<Value>(val: Value): {
2
2
  current: Value;
3
3
  };
4
+ export declare function useRef<Value>(val?: Value): {
5
+ current: Value | undefined;
6
+ };
@@ -1,3 +1,4 @@
1
1
  type NotFunction<T> = T extends Function ? never : T;
2
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];
3
4
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inquirer/core",
3
- "version": "8.0.1",
3
+ "version": "8.1.0",
4
4
  "engines": {
5
5
  "node": ">=18"
6
6
  },
@@ -58,7 +58,7 @@
58
58
  "homepage": "https://github.com/SBoudrias/Inquirer.js/blob/master/packages/core/README.md",
59
59
  "dependencies": {
60
60
  "@inquirer/figures": "^1.0.1",
61
- "@inquirer/type": "^1.3.0",
61
+ "@inquirer/type": "^1.3.1",
62
62
  "@types/mute-stream": "^0.0.4",
63
63
  "@types/node": "^20.12.7",
64
64
  "@types/wrap-ansi": "^3.0.0",
@@ -72,7 +72,7 @@
72
72
  "wrap-ansi": "^6.2.0"
73
73
  },
74
74
  "devDependencies": {
75
- "@inquirer/testing": "^2.1.17"
75
+ "@inquirer/testing": "^2.1.18"
76
76
  },
77
77
  "scripts": {
78
78
  "tsc": "yarn run tsc:esm && yarn run tsc:cjs",
@@ -95,5 +95,5 @@
95
95
  }
96
96
  }
97
97
  },
98
- "gitHead": "e986c9afc26321c3448f87f55795f7d9b8a9d452"
98
+ "gitHead": "d0e92901ebb7eb77d027786a2e1ac41fc15326b6"
99
99
  }