New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

new-inquirer-search-checkbox

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

new-inquirer-search-checkbox - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

172

dist/index.js
"use strict";
const Base = require("inquirer/lib/prompts/base");
const observe = require("inquirer/lib/utils/events");
const figures = require("figures");
const Paginator = require("inquirer/lib/utils/paginator");
const chalk_1 = require("chalk");
const fuzzy = require("fuzzy");
const ignoreKeys = ['up', 'down', 'space'];
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var Base = require("inquirer/lib/prompts/base");
var observe = require("inquirer/lib/utils/events");
var figures = require("figures");
var Paginator = require("inquirer/lib/utils/paginator");
var chalk_1 = require("chalk");
var fuzzy = require("fuzzy");
var ignoreKeys = ['up', 'down', 'space'];
function getCheckbox(checked) {

@@ -19,3 +45,3 @@ return checked ? chalk_1.default.green(figures.radioOn) : figures.radioOff;

if (choice.disabled) {
output = `${output} - ${choice.name} (Disabled)`;
output = "".concat(output, " - ").concat(choice.name, " (Disabled)");
}

@@ -31,27 +57,33 @@ else {

}
class SearchBox extends Base {
constructor(...params) {
super(...params);
this.pointer = 0;
this.selection = [];
this.done = () => { };
this.choices = [];
this.filterList = [];
this.paginator = new Paginator();
const { choices } = this.opt;
var SearchBox = (function (_super) {
__extends(SearchBox, _super);
function SearchBox() {
var params = [];
for (var _i = 0; _i < arguments.length; _i++) {
params[_i] = arguments[_i];
}
var _this = _super.apply(this, params) || this;
_this.pointer = 0;
_this.selection = [];
_this.done = function () { };
_this.choices = [];
_this.filterList = [];
_this.paginator = new Paginator();
var choices = _this.opt.choices;
if (!choices) {
this.throwParamError('choices');
_this.throwParamError('choices');
}
const item = choices.find(c => isSeparator(c));
var item = choices.find(function (c) { return isSeparator(c); });
if (item) {
throw new Error('Separator is not allowed in choices.');
}
this.filterList = this.choices = choices
.filter(() => true)
.map((item, id) => (Object.assign(Object.assign({}, item), { id })));
_this.filterList = _this.choices = choices
.filter(function () { return true; })
.map(function (item, id) { return (__assign(__assign({}, item), { id: id })); });
return _this;
}
render(error) {
SearchBox.prototype.render = function (error) {
var message = this.getQuestion();
var bottomContent = '';
const tip = chalk_1.default.dim('(Press <space> to select, <enter> to submit.)');
var tip = chalk_1.default.dim('(空格选择,回车提交,ctrl+a全选)');
if (this.status === 'answered') {

@@ -61,4 +93,4 @@ message += chalk_1.default.cyan(this.selection.join(', '));

else {
message += `${tip} ${this.rl.line}`;
const choicesStr = renderChoices(this.filterList, this.pointer);
message += "".concat(tip, " ").concat(this.rl.line);
var choicesStr = renderChoices(this.filterList, this.pointer);
bottomContent = this.paginator.paginate(choicesStr, this.pointer, this.opt.pageSize);

@@ -70,40 +102,41 @@ }

this.screen.render(message, bottomContent);
}
filterChoices() {
const options = {
extract: (el) => el.name,
};
SearchBox.prototype.filterChoices = function () {
var options = {
extract: function (el) { return el.name; },
};
this.filterList = fuzzy
.filter(this.rl.line, this.choices, options)
.map(el => el.original);
}
toggleChoice(index) {
const item = this.filterList[index];
.map(function (el) { return el.original; });
};
SearchBox.prototype.toggleChoice = function (index) {
var item = this.filterList[index];
if (item) {
this.choices[item.id].checked = !item.checked;
}
}
onSpaceKey() {
};
SearchBox.prototype.onSpaceKey = function () {
this.rl.line = this.rl.line.trim();
this.toggleChoice(this.pointer);
this.render();
}
onDownKey() {
const len = this.filterList.length;
};
SearchBox.prototype.onDownKey = function () {
var len = this.filterList.length;
this.pointer = this.pointer < len - 1 ? this.pointer + 1 : 0;
this.render();
}
onUpKey() {
const len = this.filterList.length;
};
SearchBox.prototype.onUpKey = function () {
var len = this.filterList.length;
this.pointer = this.pointer > 0 ? this.pointer - 1 : len - 1;
this.render();
}
onAllKey() {
const existCancel = this.filterList.find(item => !item.checked);
this.filterList.forEach(item => {
this.choices[item.id].checked = !!existCancel;
};
SearchBox.prototype.onAllKey = function () {
var _this = this;
var existCancel = this.filterList.find(function (item) { return !item.checked; });
this.filterList.forEach(function (item) {
_this.choices[item.id].checked = !!existCancel;
});
this.render();
}
onEnd(state) {
};
SearchBox.prototype.onEnd = function (state) {
this.status = 'answered';

@@ -113,23 +146,23 @@ this.render();

this.done(state.value);
}
onError(state) {
};
SearchBox.prototype.onError = function (state) {
this.render(state.isValid);
}
onKeyPress() {
};
SearchBox.prototype.onKeyPress = function () {
this.pointer = 0;
this.filterChoices();
this.render();
}
getCurrentValue() {
const choices = this.choices.filter(item => item.checked && !item.disabled);
this.selection = choices.map(item => item.short);
return choices.map(item => item.value);
}
_run(cb) {
};
SearchBox.prototype.getCurrentValue = function () {
var choices = this.choices.filter(function (item) { return item.checked && !item.disabled; });
this.selection = choices.map(function (item) { return item.short; });
return choices.map(function (item) { return item.value; });
};
SearchBox.prototype._run = function (cb) {
this.done = cb;
const events = observe(this.rl);
const upKey = events.keypress.filter((e) => e.key.name === 'up' || (e.key.name === 'p' && e.key.ctrl));
const downKey = events.keypress.filter((e) => e.key.name === 'down' || (e.key.name === 'n' && e.key.ctrl));
const allKey = events.keypress.filter((e) => e.key.name === 'o' && e.key.ctrl);
const validation = this.handleSubmitEvents(events.line.map(this.getCurrentValue.bind(this)));
var events = observe(this.rl);
var upKey = events.keypress.filter(function (e) { return e.key.name === 'up' || (e.key.name === 'p' && e.key.ctrl); });
var downKey = events.keypress.filter(function (e) { return e.key.name === 'down' || (e.key.name === 'n' && e.key.ctrl); });
var allKey = events.keypress.filter(function (e) { return e.key.name === 'a' && e.key.ctrl; });
var validation = this.handleSubmitEvents(events.line.map(this.getCurrentValue.bind(this)));
validation.success.forEach(this.onEnd.bind(this));

@@ -144,3 +177,3 @@ validation.error.forEach(this.onError.bind(this));

events.keypress
.filter((e) => !e.key.ctrl && !ignoreKeys.includes(e.key.name))
.filter(function (e) { return !e.key.ctrl && !ignoreKeys.includes(e.key.name); })
.takeUntil(validation.success)

@@ -150,4 +183,5 @@ .forEach(this.onKeyPress.bind(this));

return this;
}
}
};
return SearchBox;
}(Base));
module.exports = SearchBox;
{
"name": "new-inquirer-search-checkbox",
"version": "1.0.1",
"version": "1.0.2",
"description": "Searchable Inquirer checkbox",

@@ -10,5 +10,4 @@ "main": "dist/index.js",

},
"types": "./types/",
"keywords": [],
"author": "ben-lau <408736066@qq.com>",
"author": "",
"license": "MIT",

@@ -19,3 +18,3 @@ "devDependencies": {

"@types/node": "^8.0.47",
"typescript": "^4.5.4"
"typescript": "^4.5.5"
},

@@ -22,0 +21,0 @@ "dependencies": {

@@ -79,3 +79,3 @@ import Base = require('inquirer/lib/prompts/base');

var bottomContent = '';
const tip = chalk.dim('(Press <space> to select, <enter> to submit.)');
const tip = chalk.dim('(空格选择,回车提交,ctrl+a全选)');

@@ -183,3 +183,3 @@ // Render choices or answer depending on the state

const allKey = events.keypress.filter(
(e: Event) => e.key.name === 'o' && e.key.ctrl
(e: Event) => e.key.name === 'a' && e.key.ctrl
);

@@ -186,0 +186,0 @@ const validation = this.handleSubmitEvents(

@@ -7,3 +7,3 @@ {

"module": "CommonJS",
"target": "es6",
"target": "es5",
"moduleResolution": "node",

@@ -10,0 +10,0 @@ "removeComments": true,

/// <reference types="rx" />
declare module 'inquirer/lib/prompts/base' {
export = Base;
declare module "inquirer/lib/prompts/base" {
export = Base;
class Base {
opt: {
choices: Base.Choice[];
pageSize: number;
};
rl: {
line: string;
write(params: any): void;
moveCursor(dx: number): void;
};
status: string;
screen: {
render: (content: string, bottomContent: string) => void;
done: () => void;
};
class Base {
opt: {
choices: Base.Choice[];
pageSize: number;
};
rl: {
line: string;
write(params: any): void;
moveCursor(dx: number): void;
};
status: string;
screen: {
render: (content: string, bottomContent: string) => void;
done: () => void;
};
constructor(...params: any[]);
constructor(...params: any[]);
throwParamError(params: string): void;
getQuestion(): string;
handleSubmitEvents(submit: any): Base.Validation;
}
throwParamError(params: string): void;
getQuestion(): string;
handleSubmitEvents(submit: any): Base.Validation;
}
namespace Base {
export interface Validation {
success: any;
error: any;
}
namespace Base {
export interface Validation {
success: any;
error: any;
}
export interface Choice {
name: string;
type: string;
short: string;
value: string;
line: string;
disabled: boolean;
checked: boolean;
}
}
export interface Choice {
name: string;
type: string;
short: string;
value: string;
line: string;
disabled: boolean;
checked: boolean;
}
}
}
declare module 'inquirer/lib/utils/events' {
interface Events {
keypress: Rx.Observable<any>;
line: Rx.Observable<any>;
spaceKey: Rx.Observable<any>;
}
declare module "inquirer/lib/utils/events" {
interface Events {
keypress: Rx.Observable<any>;
line: Rx.Observable<any>;
spaceKey: Rx.Observable<any>;
}
function observe(params: any): Events;
export = observe;
function observe(params: any): Events;
export = observe;
}
declare module 'inquirer/lib/utils/paginator' {
class Paginator {
paginate(output: string, active: number, pageSize: number): string;
}
export = Paginator;
declare module "inquirer/lib/utils/paginator" {
class Paginator {
paginate(output: string, active: number, pageSize: number): string;
}
export = Paginator;
}
declare module 'cli-cursor';
declare module 'ansi-escapes';
declare module 'new-inquirer-search-checkbox' {
const SearchCheckbox: any;
export = SearchCheckbox;
}
declare module "cli-cursor";
declare module "ansi-escapes";
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