Socket
Socket
Sign inDemoInstall

@inquirer/core

Package Overview
Dependencies
Maintainers
3
Versions
82
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@inquirer/core - npm Package Compare versions

Comparing version 5.0.1 to 5.1.0

dist/cjs/lib/pagination/lines.js

6

./dist/cjs/index.js

@@ -17,3 +17,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.Separator = exports.createPrompt = exports.usePagination = exports.useKeypress = exports.useRef = exports.useEffect = exports.useState = exports.usePrefix = void 0;
exports.Separator = exports.createPrompt = exports.usePagination = exports.useKeypress = exports.useRef = exports.useMemo = exports.useEffect = exports.useState = exports.usePrefix = void 0;
__exportStar(require('./lib/key.js'), exports);

@@ -26,2 +26,4 @@ var use_prefix_mjs_1 = require('./lib/use-prefix.js');

Object.defineProperty(exports, "useEffect", { enumerable: true, get: function () { return use_effect_mjs_1.useEffect; } });
var use_memo_mjs_1 = require('./lib/use-memo.js');
Object.defineProperty(exports, "useMemo", { enumerable: true, get: function () { return use_memo_mjs_1.useMemo; } });
var use_ref_mjs_1 = require('./lib/use-ref.js');

@@ -31,3 +33,3 @@ Object.defineProperty(exports, "useRef", { enumerable: true, get: function () { return use_ref_mjs_1.useRef; } });

Object.defineProperty(exports, "useKeypress", { enumerable: true, get: function () { return use_keypress_mjs_1.useKeypress; } });
var use_pagination_mjs_1 = require('./lib/use-pagination.js');
var use_pagination_mjs_1 = require('./lib/pagination/use-pagination.js');
Object.defineProperty(exports, "usePagination", { enumerable: true, get: function () { return use_pagination_mjs_1.usePagination; } });

@@ -34,0 +36,0 @@ var create_prompt_mjs_1 = require('./lib/create-prompt.js');

@@ -17,3 +17,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.Separator = exports.createPrompt = exports.usePagination = exports.useKeypress = exports.useRef = exports.useEffect = exports.useState = exports.usePrefix = void 0;
exports.Separator = exports.createPrompt = exports.usePagination = exports.useKeypress = exports.useRef = exports.useMemo = exports.useEffect = exports.useState = exports.usePrefix = void 0;
__exportStar(require('./lib/key.js'), exports);

@@ -26,2 +26,4 @@ var use_prefix_mjs_1 = require('./lib/use-prefix.js');

Object.defineProperty(exports, "useEffect", { enumerable: true, get: function () { return use_effect_mjs_1.useEffect; } });
var use_memo_mjs_1 = require('./lib/use-memo.js');
Object.defineProperty(exports, "useMemo", { enumerable: true, get: function () { return use_memo_mjs_1.useMemo; } });
var use_ref_mjs_1 = require('./lib/use-ref.js');

@@ -31,3 +33,3 @@ Object.defineProperty(exports, "useRef", { enumerable: true, get: function () { return use_ref_mjs_1.useRef; } });

Object.defineProperty(exports, "useKeypress", { enumerable: true, get: function () { return use_keypress_mjs_1.useKeypress; } });
var use_pagination_mjs_1 = require('./lib/use-pagination.js');
var use_pagination_mjs_1 = require('./lib/pagination/use-pagination.js');
Object.defineProperty(exports, "usePagination", { enumerable: true, get: function () { return use_pagination_mjs_1.usePagination; } });

@@ -34,0 +36,0 @@ var create_prompt_mjs_1 = require('./lib/create-prompt.js');

@@ -7,23 +7,18 @@ "use strict";

return (0, hook_engine_mjs_1.withPointer)((pointer) => {
if (!pointer.initialized) {
if (typeof defaultValue === 'function') {
pointer.set(defaultValue());
const setFn = (newValue) => {
// Noop if the value is still the same.
if (pointer.get() !== newValue) {
pointer.set(newValue);
// Trigger re-render
(0, hook_engine_mjs_1.handleChange)();
}
else {
pointer.set(defaultValue);
}
};
if (pointer.initialized) {
return [pointer.get(), setFn];
}
return [
pointer.get(),
(newValue) => {
// Noop if the value is still the same.
if (pointer.get() !== newValue) {
pointer.set(newValue);
// Trigger re-render
(0, hook_engine_mjs_1.handleChange)();
}
},
];
const value = typeof defaultValue === 'function' ? defaultValue() : defaultValue;
pointer.set(value);
return [value, setFn];
});
}
exports.useState = useState;

@@ -5,7 +5,8 @@ export * from './lib/key.js';

export { useEffect } from './lib/use-effect.js';
export { useMemo } from './lib/use-memo.js';
export { useRef } from './lib/use-ref.js';
export { useKeypress } from './lib/use-keypress.js';
export { usePagination } from './lib/use-pagination.js';
export { usePagination } from './lib/pagination/use-pagination.js';
export { createPrompt, type PromptConfig, type AsyncPromptConfig, } from './lib/create-prompt.js';
export { Separator } from './lib/Separator.js';
export { type InquirerReadline } from './lib/read-line.type.js';

@@ -10,11 +10,17 @@ import type { InquirerReadline } from './read-line.type.js';

};
type Pointer = {
get(): any;
set(value: any): void;
initialized: boolean;
};
export declare function withHooks(rl: InquirerReadline, cb: (store: HookStore) => void): void;
export declare function readline(): InquirerReadline;
export declare function withUpdates<T extends (...args: any) => any>(fn: T): (...args: Parameters<T>) => ReturnType<T>;
export declare function withPointer<Value>(cb: (pointer: Pointer) => Value): Value;
type SetPointer<Value> = {
get(): Value;
set(value: Value): void;
initialized: true;
};
type UnsetPointer<Value> = {
get(): void;
set(value: Value): void;
initialized: false;
};
type Pointer<Value> = SetPointer<Value> | UnsetPointer<Value>;
export declare function withPointer<Value, ReturnValue>(cb: (pointer: Pointer<Value>) => ReturnValue): ReturnValue;
export declare function handleChange(): void;

@@ -21,0 +27,0 @@ export declare const effectScheduler: {

{
"name": "@inquirer/core",
"version": "5.0.1",
"version": "5.1.0",
"engines": {

@@ -61,4 +61,4 @@ "node": ">=14.18.0"

"@inquirer/type": "^1.1.5",
"@types/mute-stream": "^0.0.1",
"@types/node": "^20.6.5",
"@types/mute-stream": "^0.0.2",
"@types/node": "^20.8.2",
"@types/wrap-ansi": "^3.0.0",

@@ -77,3 +77,3 @@ "ansi-escapes": "^4.3.2",

"devDependencies": {
"@inquirer/testing": "^2.1.7"
"@inquirer/testing": "^2.1.8"
},

@@ -100,3 +100,3 @@ "scripts": {

},
"gitHead": "85784061d702778bc9dd48ca08f09ee9976b06ee"
"gitHead": "c88aaca660e58aa0fb079fe656c1004855e029da"
}

@@ -107,2 +107,3 @@ # `@inquirer/core`

- `useEffect`
- `useMemo`

@@ -128,16 +129,21 @@ And those are custom utilities from Inquirer:

When looping through a long list of options (like in the `select` prompt), paginating the results appearing on the screen at once can be necessary. The `usePagination` hook is the utility used within the `select` and `checkbox` prompt to cycle through the list of options.
When looping through a long list of options (like in the `select` prompt), paginating the results appearing on the screen at once can be necessary. The `usePagination` hook is the utility used within the `select` and `checkbox` prompts to cycle through the list of options.
Pagination works by taking in the list of options and returning a subset of the rendered items that fit within the page. The hook takes in a few options. It needs a list of options (`items`), and a `pageSize` which is the number of lines to be rendered. The `active` index is the index of the currently selected/selectable item. The `loop` option is a boolean that indicates if the list should loop around when reaching the end: this is the default behavior. The pagination hook renders items only as necessary, so it takes a function that can render an item at an index, including an `active` state, called `renderItem`.
```js
export default createPrompt((config, done) => {
const [cursorPosition, setCursorPosition] = useState(0);
const [active, setActive] = useState(0);
const allChoices = config.choices.map((choice) => choice.name);
const windowedChoices = usePagination(allChoices, {
active: cursorPosition,
const page = usePagination({
items: allChoices,
active: active,
renderItem: ({ item, index, isActive }) => `${isActive ? ">" : " "}${index}. ${item.toString()}`
pageSize: config.pageSize,
loop: config.loop,
});
return `... ${windowedChoices}`;
return `... ${page}`;
});

@@ -144,0 +150,0 @@ ```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc