@wocker/utils 1.0.10-beta.0 → 1.0.10-beta.1
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/lib/index.d.ts +3 -3
- package/lib/index.js +3 -3
- package/lib/promptConfig.d.ts +1 -1
- package/lib/promptConfig.js +9 -8
- package/lib/promptGroup.d.ts +1 -1
- package/lib/promptGroup.js +8 -7
- package/lib/promptSelect.d.ts +1 -1
- package/lib/promptSelect.js +1 -1
- package/lib/{prompts/promptText.d.ts → promptText.d.ts} +0 -4
- package/lib/{prompts/promptText.js → promptText.js} +0 -4
- package/lib/{tools/volumeFormat.js → volumeFormat.js} +1 -1
- package/package.json +5 -16
- package/lib/messages.d.ts +0 -15
- package/lib/messages.js +0 -18
- package/lib/prompts/index.d.ts +0 -2
- package/lib/prompts/index.js +0 -18
- package/lib/prompts/promptInput.d.ts +0 -16
- package/lib/prompts/promptInput.js +0 -184
- package/lib/tools/index.d.ts +0 -2
- package/lib/tools/index.js +0 -18
- package/lib/types/PromptConfig.d.ts +0 -15
- package/lib/types/PromptConfig.js +0 -2
- package/lib/types/Theme.d.ts +0 -6
- package/lib/types/Theme.js +0 -2
- package/lib/types/Validation.d.ts +0 -2
- package/lib/types/Validation.js +0 -2
- package/lib/types/ValidationError.d.ts +0 -4
- package/lib/types/ValidationError.js +0 -2
- package/lib/types/ValidationResult.d.ts +0 -1
- package/lib/types/ValidationResult.js +0 -2
- package/lib/types/ValidationRule.d.ts +0 -3
- package/lib/types/ValidationRule.js +0 -2
- package/lib/types/ValidationValue.d.ts +0 -1
- package/lib/types/ValidationValue.js +0 -2
- package/lib/types/ValidationValueMessage.d.ts +0 -5
- package/lib/types/ValidationValueMessage.js +0 -2
- package/lib/validation/normalizeRule.d.ts +0 -3
- package/lib/validation/normalizeRule.js +0 -16
- package/lib/validation/validatePrompt.d.ts +0 -3
- package/lib/validation/validatePrompt.js +0 -99
- package/lib/validators/index.d.ts +0 -1
- package/lib/validators/index.js +0 -17
- package/lib/validators/validateVolume.d.ts +0 -2
- package/lib/validators/validateVolume.js +0 -20
- package/test/makes/CustomMuteStream.ts +0 -116
- package/test/tools/render.ts +0 -44
- /package/lib/{tools/normalizeOptions.d.ts → normalizeOptions.d.ts} +0 -0
- /package/lib/{tools/normalizeOptions.js → normalizeOptions.js} +0 -0
- /package/lib/{tools/volumeFormat.d.ts → volumeFormat.d.ts} +0 -0
- /package/lib/{tools/volumeParse.d.ts → volumeParse.d.ts} +0 -0
- /package/lib/{tools/volumeParse.js → volumeParse.js} +0 -0
package/lib/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from "./prompts";
|
|
2
|
-
export * from "./tools";
|
|
3
|
-
export * from "./validators";
|
|
4
1
|
export * from "./demuxOutput";
|
|
5
2
|
export * from "./promptConfig";
|
|
6
3
|
export * from "./promptConfirm";
|
|
7
4
|
export * from "./promptGroup";
|
|
8
5
|
export * from "./promptSelect";
|
|
6
|
+
export * from "./promptText";
|
|
7
|
+
export * from "./volumeFormat";
|
|
8
|
+
export * from "./volumeParse";
|
package/lib/index.js
CHANGED
|
@@ -14,11 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./prompts"), exports);
|
|
18
|
-
__exportStar(require("./tools"), exports);
|
|
19
|
-
__exportStar(require("./validators"), exports);
|
|
20
17
|
__exportStar(require("./demuxOutput"), exports);
|
|
21
18
|
__exportStar(require("./promptConfig"), exports);
|
|
22
19
|
__exportStar(require("./promptConfirm"), exports);
|
|
23
20
|
__exportStar(require("./promptGroup"), exports);
|
|
24
21
|
__exportStar(require("./promptSelect"), exports);
|
|
22
|
+
__exportStar(require("./promptText"), exports);
|
|
23
|
+
__exportStar(require("./volumeFormat"), exports);
|
|
24
|
+
__exportStar(require("./volumeParse"), exports);
|
package/lib/promptConfig.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PromptConfirmOptions } from "./promptConfirm";
|
|
2
2
|
import { PromptSelectOptions } from "./promptSelect";
|
|
3
|
-
import { PromptTextOptions } from "./
|
|
3
|
+
import { PromptTextOptions } from "./promptText";
|
|
4
4
|
type ConfirmOptions = PromptConfirmOptions & {
|
|
5
5
|
type: "boolean";
|
|
6
6
|
};
|
package/lib/promptConfig.js
CHANGED
|
@@ -21,20 +21,14 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
23
|
exports.promptConfig = void 0;
|
|
24
|
-
const normalizeOptions_1 = require("./
|
|
24
|
+
const normalizeOptions_1 = require("./normalizeOptions");
|
|
25
25
|
const promptConfirm_1 = require("./promptConfirm");
|
|
26
26
|
const promptSelect_1 = require("./promptSelect");
|
|
27
|
-
const promptText_1 = require("./
|
|
27
|
+
const promptText_1 = require("./promptText");
|
|
28
28
|
const promptConfig = (options_1, ...args_1) => __awaiter(void 0, [options_1, ...args_1], void 0, function* (options, values = {}) {
|
|
29
29
|
for (const key in options) {
|
|
30
30
|
const params = options[key];
|
|
31
31
|
switch (params.type) {
|
|
32
|
-
case "number":
|
|
33
|
-
case "int":
|
|
34
|
-
case "string": {
|
|
35
|
-
values[key] = yield (0, promptText_1.promptText)(Object.assign(Object.assign({}, params), { default: values[key] || params.default }));
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
32
|
case "boolean": {
|
|
39
33
|
const { type } = params, rest = __rest(params, ["type"]);
|
|
40
34
|
values[key] = yield (0, promptConfirm_1.promptConfirm)(Object.assign(Object.assign({}, rest), { default: typeof values[key] === "boolean"
|
|
@@ -68,6 +62,13 @@ const promptConfig = (options_1, ...args_1) => __awaiter(void 0, [options_1, ...
|
|
|
68
62
|
}
|
|
69
63
|
break;
|
|
70
64
|
}
|
|
65
|
+
case "number":
|
|
66
|
+
case "int":
|
|
67
|
+
case "string":
|
|
68
|
+
default: {
|
|
69
|
+
values[key] = yield (0, promptText_1.promptText)(Object.assign(Object.assign({}, params), { default: values[key] || params.default }));
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
71
72
|
}
|
|
72
73
|
}
|
|
73
74
|
return values;
|
package/lib/promptGroup.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PromptConfirmOptions } from "./promptConfirm";
|
|
2
2
|
import { PromptSelectOptions } from "./promptSelect";
|
|
3
|
-
import { PromptTextOptions } from "./
|
|
3
|
+
import { PromptTextOptions } from "./promptText";
|
|
4
4
|
type ConfirmOptions = PromptConfirmOptions & {
|
|
5
5
|
type: "boolean";
|
|
6
6
|
};
|
package/lib/promptGroup.js
CHANGED
|
@@ -23,18 +23,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
23
23
|
exports.promptGroup = void 0;
|
|
24
24
|
const promptConfirm_1 = require("./promptConfirm");
|
|
25
25
|
const promptSelect_1 = require("./promptSelect");
|
|
26
|
-
const promptText_1 = require("./
|
|
26
|
+
const promptText_1 = require("./promptText");
|
|
27
27
|
const promptGroup = (options_1, ...args_1) => __awaiter(void 0, [options_1, ...args_1], void 0, function* (options, values = {}) {
|
|
28
28
|
const res = {};
|
|
29
29
|
for (const key in options) {
|
|
30
30
|
const params = options[key];
|
|
31
31
|
switch (params.type) {
|
|
32
|
-
case "number":
|
|
33
|
-
case "int":
|
|
34
|
-
case "string": {
|
|
35
|
-
res[key] = yield (0, promptText_1.promptText)(Object.assign(Object.assign({}, params), { default: values[key] || params.default }));
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
32
|
case "boolean": {
|
|
39
33
|
const { type } = params, rest = __rest(params, ["type"]);
|
|
40
34
|
res[key] = yield (0, promptConfirm_1.promptConfirm)(Object.assign(Object.assign({}, rest), { default: typeof values[key] !== "undefined"
|
|
@@ -47,6 +41,13 @@ const promptGroup = (options_1, ...args_1) => __awaiter(void 0, [options_1, ...a
|
|
|
47
41
|
res[key] = yield (0, promptSelect_1.promptSelect)(Object.assign(Object.assign({}, rest), { default: values[key] || params.default }));
|
|
48
42
|
break;
|
|
49
43
|
}
|
|
44
|
+
case "number":
|
|
45
|
+
case "int":
|
|
46
|
+
case "string":
|
|
47
|
+
default: {
|
|
48
|
+
res[key] = yield (0, promptText_1.promptText)(Object.assign(Object.assign({}, params), { default: values[key] || params.default }));
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
53
|
return res;
|
package/lib/promptSelect.d.ts
CHANGED
package/lib/promptSelect.js
CHANGED
|
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.promptSelect = void 0;
|
|
16
16
|
const inquirer_1 = __importDefault(require("inquirer"));
|
|
17
|
-
const normalizeOptions_1 = require("./
|
|
17
|
+
const normalizeOptions_1 = require("./normalizeOptions");
|
|
18
18
|
const promptSelect = (props) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
19
|
const { message, options: rawOptions, } = props;
|
|
20
20
|
const options = (0, normalizeOptions_1.normalizeOptions)(rawOptions);
|
|
@@ -7,9 +7,5 @@ type Options = {
|
|
|
7
7
|
default?: number | string;
|
|
8
8
|
validate?: (value?: string) => boolean | string | Promise<boolean | string>;
|
|
9
9
|
};
|
|
10
|
-
/**
|
|
11
|
-
* @deprecated
|
|
12
|
-
* @see promptInput
|
|
13
|
-
*/
|
|
14
10
|
export declare const promptText: (options: Options) => Promise<any>;
|
|
15
11
|
export { Options as PromptTextOptions };
|
|
@@ -15,10 +15,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.promptText = void 0;
|
|
16
16
|
const inquirer_1 = __importDefault(require("inquirer"));
|
|
17
17
|
const chalk_1 = __importDefault(require("chalk"));
|
|
18
|
-
/**
|
|
19
|
-
* @deprecated
|
|
20
|
-
* @see promptInput
|
|
21
|
-
*/
|
|
22
18
|
const promptText = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
19
|
const { required, message, prefix = "", suffix = "", type, default: defaultValue, validate } = options;
|
|
24
20
|
const { value } = yield inquirer_1.default.prompt({
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.volumeFormat = void 0;
|
|
4
4
|
const volumeFormat = (volume) => {
|
|
5
|
-
const { source
|
|
5
|
+
const { source, destination, options } = volume;
|
|
6
6
|
return `${source}:${destination}` + (options ? `:${options}` : "");
|
|
7
7
|
};
|
|
8
8
|
exports.volumeFormat = volumeFormat;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wocker/utils",
|
|
3
|
-
"version": "1.0.10-beta.
|
|
3
|
+
"version": "1.0.10-beta.1",
|
|
4
4
|
"author": "Kris Papercut <krispcut@gmail.com>",
|
|
5
5
|
"description": "Utils for @wocker",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,27 +20,16 @@
|
|
|
20
20
|
"url": "https://github.com/kearisp/wocker-utils/issues"
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"test": "
|
|
27
|
-
"test-watch": "jest --watchAll"
|
|
23
|
+
"prepare": "npm run build",
|
|
24
|
+
"watch": "tsc -w",
|
|
25
|
+
"build": "tsc",
|
|
26
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
28
27
|
},
|
|
29
28
|
"dependencies": {
|
|
30
|
-
"@inquirer/core": "^10.1.10",
|
|
31
29
|
"inquirer": "^7.3.3"
|
|
32
30
|
},
|
|
33
31
|
"devDependencies": {
|
|
34
|
-
"@inquirer/testing": "^2.1.46",
|
|
35
|
-
"@inquirer/type": "^3.0.6",
|
|
36
32
|
"@types/inquirer": "^7.3.3",
|
|
37
|
-
"@types/jest": "^29.5.14",
|
|
38
|
-
"@types/mute-stream": "^0.0.4",
|
|
39
|
-
"@types/node": "^22.14.1",
|
|
40
|
-
"jest": "^29.7.0",
|
|
41
|
-
"mute-stream": "^2.0.0",
|
|
42
|
-
"ts-jest": "^29.3.1",
|
|
43
|
-
"ts-node": "^10.9.2",
|
|
44
33
|
"typescript": "^5.8.3"
|
|
45
34
|
}
|
|
46
35
|
}
|
package/lib/messages.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export declare const messages: {
|
|
2
|
-
required: string;
|
|
3
|
-
min: (min: number) => string;
|
|
4
|
-
max: (max: number) => string;
|
|
5
|
-
minLength: (min: number) => string;
|
|
6
|
-
maxLength: (max: number) => string;
|
|
7
|
-
minArrayLength: (min: number) => string;
|
|
8
|
-
maxArrayLength: (max: number) => string;
|
|
9
|
-
custom: string;
|
|
10
|
-
volume: {
|
|
11
|
-
notAString: string;
|
|
12
|
-
tooLong: string;
|
|
13
|
-
invalidCharacters: string;
|
|
14
|
-
};
|
|
15
|
-
};
|
package/lib/messages.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.messages = void 0;
|
|
4
|
-
exports.messages = {
|
|
5
|
-
required: "Mandatory value",
|
|
6
|
-
min: (min) => `The value must be greater that ${min}`,
|
|
7
|
-
max: (max) => `The value must be less than ${max}`,
|
|
8
|
-
minLength: (min) => `The value must have at least ${min} characters.`,
|
|
9
|
-
maxLength: (max) => `The value must not exceed ${max} characters.`,
|
|
10
|
-
minArrayLength: (min) => `The value must have at least ${min} items.`,
|
|
11
|
-
maxArrayLength: (max) => `The value must not exceed ${max} items.`,
|
|
12
|
-
custom: "Invalid value",
|
|
13
|
-
volume: {
|
|
14
|
-
notAString: "Volume name should be string.",
|
|
15
|
-
tooLong: "Volume name must not exceed 255 characters.",
|
|
16
|
-
invalidCharacters: "Invalid volume name. Only alphanumeric characters, single hyphens (-), and underscores (_) are allowed. The name must not start or end with a hyphen or underscore."
|
|
17
|
-
}
|
|
18
|
-
};
|
package/lib/prompts/index.d.ts
DELETED
package/lib/prompts/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./promptInput"), exports);
|
|
18
|
-
__exportStar(require("./promptText"), exports);
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Context } from "@inquirer/type";
|
|
2
|
-
import { PromptConfig } from "../types/PromptConfig";
|
|
3
|
-
type InputValue = string | number;
|
|
4
|
-
type ValueType<T extends Config["type"] = "text"> = T extends "text" | "password" ? string : T extends "number" ? number : string;
|
|
5
|
-
type PromptFn = <V extends ValueType<C["type"]>, C extends Config<V> = Config<V>>(config: C, context?: Context) => Promise<V> & {
|
|
6
|
-
cancel: () => void;
|
|
7
|
-
};
|
|
8
|
-
type Config<V extends InputValue = InputValue> = PromptConfig<V, {
|
|
9
|
-
type?: "text" | "password" | "number";
|
|
10
|
-
step?: number;
|
|
11
|
-
prefix?: string;
|
|
12
|
-
suffix?: string;
|
|
13
|
-
afterKeypress?: () => void;
|
|
14
|
-
}>;
|
|
15
|
-
export declare const promptInput: PromptFn;
|
|
16
|
-
export { Config as PromptInputConfig };
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.promptInput = void 0;
|
|
16
|
-
const core_1 = require("@inquirer/core");
|
|
17
|
-
const yoctocolors_cjs_1 = __importDefault(require("yoctocolors-cjs"));
|
|
18
|
-
const validatePrompt_1 = require("../validation/validatePrompt");
|
|
19
|
-
exports.promptInput = (0, core_1.createPrompt)((config, done) => {
|
|
20
|
-
const { message = "Value", type = "text", step = 1, prefix = "", suffix = "", default: defaultValue, afterKeypress } = config;
|
|
21
|
-
const theme = (0, core_1.makeTheme)({
|
|
22
|
-
style: {
|
|
23
|
-
message: (message) => `${theme.style.highlight(message + ": ")}`,
|
|
24
|
-
value: (value, status) => {
|
|
25
|
-
switch (status) {
|
|
26
|
-
case "error":
|
|
27
|
-
return yoctocolors_cjs_1.default.red(value);
|
|
28
|
-
default:
|
|
29
|
-
return value;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}, config.theme);
|
|
34
|
-
const [inputValue = "", setInputValue] = (0, core_1.useState)(typeof defaultValue === "number" ? defaultValue.toString() : defaultValue), [status, setStatus] = (0, core_1.useState)("idle"), [error, setError] = (0, core_1.useState)("");
|
|
35
|
-
const value = (0, core_1.useMemo)(() => {
|
|
36
|
-
switch (config.type) {
|
|
37
|
-
case "number":
|
|
38
|
-
return parseFloat(inputValue);
|
|
39
|
-
default:
|
|
40
|
-
return inputValue;
|
|
41
|
-
}
|
|
42
|
-
}, [inputValue, type]);
|
|
43
|
-
const displayValue = (0, core_1.useMemo)(() => {
|
|
44
|
-
switch (type) {
|
|
45
|
-
case "password":
|
|
46
|
-
return "*".repeat(inputValue.length);
|
|
47
|
-
default:
|
|
48
|
-
return inputValue;
|
|
49
|
-
}
|
|
50
|
-
}, [inputValue, type]);
|
|
51
|
-
const decimalPlaces = (0, core_1.useMemo)(() => {
|
|
52
|
-
if (type !== "number") {
|
|
53
|
-
return 0;
|
|
54
|
-
}
|
|
55
|
-
const [, inputValueDecimal = ""] = inputValue.split("."), [, stepDecimal = ""] = step.toString().split(".");
|
|
56
|
-
return Math.max(inputValueDecimal.length, stepDecimal.length);
|
|
57
|
-
}, [type, step, inputValue]);
|
|
58
|
-
const icon = (0, core_1.usePrefix)({
|
|
59
|
-
theme,
|
|
60
|
-
status
|
|
61
|
-
});
|
|
62
|
-
const handleUp = (readline) => {
|
|
63
|
-
switch (type) {
|
|
64
|
-
case "number": {
|
|
65
|
-
if (typeof value !== "number" || isNaN(value)) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
const inputValue = (value + step).toFixed(decimalPlaces);
|
|
69
|
-
readline.clearLine(-1);
|
|
70
|
-
readline.write(inputValue);
|
|
71
|
-
setInputValue(inputValue);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
const handleDown = (readline) => {
|
|
76
|
-
switch (type) {
|
|
77
|
-
case "number": {
|
|
78
|
-
if (typeof value !== "number" || isNaN(value)) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
const inputValue = (value - step).toFixed(decimalPlaces);
|
|
82
|
-
readline.clearLine(-1);
|
|
83
|
-
readline.write(inputValue);
|
|
84
|
-
setInputValue(inputValue);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
const handleChange = (readline) => {
|
|
89
|
-
switch (type) {
|
|
90
|
-
case "number": {
|
|
91
|
-
let [, minus = "", firstPart = "", dot = "", secondPart = ""] = /^(-)?([^.]*)(?:([.,])(.*))?$/.exec(readline.line) || [];
|
|
92
|
-
firstPart = firstPart.replace(/[^0-9]/g, "");
|
|
93
|
-
secondPart = secondPart.replace(/[^0-9]/g, "");
|
|
94
|
-
const inputValue = minus + firstPart + (dot ? "." : "") + secondPart;
|
|
95
|
-
if (inputValue !== readline.line) {
|
|
96
|
-
readline.clearLine(-1);
|
|
97
|
-
readline.write(inputValue);
|
|
98
|
-
}
|
|
99
|
-
setInputValue(inputValue);
|
|
100
|
-
break;
|
|
101
|
-
}
|
|
102
|
-
default:
|
|
103
|
-
setInputValue(readline.line);
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
setStatus("idle");
|
|
107
|
-
setError("");
|
|
108
|
-
};
|
|
109
|
-
const handleSubmit = (readline) => __awaiter(void 0, void 0, void 0, function* () {
|
|
110
|
-
setStatus("loading");
|
|
111
|
-
const error = yield (0, validatePrompt_1.validatePrompt)(value, config);
|
|
112
|
-
if (error) {
|
|
113
|
-
readline.write(inputValue);
|
|
114
|
-
setStatus("error");
|
|
115
|
-
setError(error.message);
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
setStatus("done");
|
|
119
|
-
setError("");
|
|
120
|
-
done(value);
|
|
121
|
-
});
|
|
122
|
-
(0, core_1.useEffect)((readline) => {
|
|
123
|
-
if (!suffix) {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
const moveCursor = () => {
|
|
127
|
-
const { cols } = readline.getCursorPos();
|
|
128
|
-
readline.output.unmute();
|
|
129
|
-
readline.output.write(`\x1b[${cols + 1 - suffix.length}G`);
|
|
130
|
-
readline.output.mute();
|
|
131
|
-
};
|
|
132
|
-
const handleKeypress = (_, key) => {
|
|
133
|
-
const keys = [
|
|
134
|
-
"up",
|
|
135
|
-
"left",
|
|
136
|
-
"right",
|
|
137
|
-
"down",
|
|
138
|
-
"home",
|
|
139
|
-
"end",
|
|
140
|
-
"pageup",
|
|
141
|
-
"pagedown",
|
|
142
|
-
"return"
|
|
143
|
-
];
|
|
144
|
-
if (keys.includes(key.name)) {
|
|
145
|
-
moveCursor();
|
|
146
|
-
setTimeout(moveCursor, 0);
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
readline.input.on("keypress", handleKeypress);
|
|
150
|
-
moveCursor();
|
|
151
|
-
return () => {
|
|
152
|
-
readline.input.removeListener("keypress", handleKeypress);
|
|
153
|
-
};
|
|
154
|
-
}, [displayValue, icon, status, suffix]);
|
|
155
|
-
(0, core_1.useKeypress)((key, readline) => __awaiter(void 0, void 0, void 0, function* () {
|
|
156
|
-
try {
|
|
157
|
-
if ((0, core_1.isEnterKey)(key)) {
|
|
158
|
-
return yield handleSubmit(readline);
|
|
159
|
-
}
|
|
160
|
-
if ((0, core_1.isUpKey)(key)) {
|
|
161
|
-
return handleUp(readline);
|
|
162
|
-
}
|
|
163
|
-
if ((0, core_1.isDownKey)(key)) {
|
|
164
|
-
return handleDown(readline);
|
|
165
|
-
}
|
|
166
|
-
handleChange(readline);
|
|
167
|
-
}
|
|
168
|
-
finally {
|
|
169
|
-
afterKeypress && afterKeypress();
|
|
170
|
-
}
|
|
171
|
-
}));
|
|
172
|
-
return [
|
|
173
|
-
[
|
|
174
|
-
`${icon} `,
|
|
175
|
-
theme.style.message(message, status),
|
|
176
|
-
theme.style.help(prefix),
|
|
177
|
-
theme.style.value(displayValue, status),
|
|
178
|
-
theme.style.help(suffix)
|
|
179
|
-
].join(""),
|
|
180
|
-
[
|
|
181
|
-
error ? `${theme.style.error(error)}` : ""
|
|
182
|
-
].join("")
|
|
183
|
-
];
|
|
184
|
-
});
|
package/lib/tools/index.d.ts
DELETED
package/lib/tools/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./volumeFormat"), exports);
|
|
18
|
-
__exportStar(require("./volumeParse"), exports);
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { PartialDeep } from "@inquirer/type";
|
|
2
|
-
import { Theme } from "./Theme";
|
|
3
|
-
import { Validation } from "./Validation";
|
|
4
|
-
import { ValidationRule } from "./ValidationRule";
|
|
5
|
-
export type PromptConfig<V, T = {}> = T & {
|
|
6
|
-
message: string;
|
|
7
|
-
required?: ValidationRule<boolean>;
|
|
8
|
-
min?: ValidationRule<number>;
|
|
9
|
-
max?: ValidationRule<number>;
|
|
10
|
-
minLength?: ValidationRule<number>;
|
|
11
|
-
maxLength?: ValidationRule<number>;
|
|
12
|
-
validate?: Validation<V> | Record<string, Validation<V>>;
|
|
13
|
-
default?: V;
|
|
14
|
-
theme?: PartialDeep<Theme>;
|
|
15
|
-
};
|
package/lib/types/Theme.d.ts
DELETED
package/lib/types/Theme.js
DELETED
package/lib/types/Validation.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type ValidationResult = string | string[] | boolean | undefined;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type ValidationValue = boolean | number | string | RegExp;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.normalizeRule = void 0;
|
|
4
|
-
const normalizeRule = (rule) => {
|
|
5
|
-
if (typeof rule === "undefined") {
|
|
6
|
-
return [undefined, undefined];
|
|
7
|
-
}
|
|
8
|
-
if (typeof rule === "object" && rule !== null && !(rule instanceof RegExp)) {
|
|
9
|
-
return [rule.value, rule.message];
|
|
10
|
-
}
|
|
11
|
-
return [
|
|
12
|
-
rule,
|
|
13
|
-
undefined
|
|
14
|
-
];
|
|
15
|
-
};
|
|
16
|
-
exports.normalizeRule = normalizeRule;
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.validatePrompt = void 0;
|
|
13
|
-
const normalizeRule_1 = require("./normalizeRule");
|
|
14
|
-
const messages_1 = require("../messages");
|
|
15
|
-
const validatePrompt = (value, config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
-
const { required, min, max, minLength, maxLength, validate } = config;
|
|
17
|
-
const isEmpty = typeof value === "undefined" ||
|
|
18
|
-
(typeof value === "string" && value === "") ||
|
|
19
|
-
(typeof value === "object" && value === null) ||
|
|
20
|
-
(typeof value === "number" && isNaN(value)) ||
|
|
21
|
-
(Array.isArray(value) && value.length === 0);
|
|
22
|
-
const [isRequired, requiredMessage] = (0, normalizeRule_1.normalizeRule)(required);
|
|
23
|
-
if (isRequired && isEmpty) {
|
|
24
|
-
return {
|
|
25
|
-
type: "required",
|
|
26
|
-
message: requiredMessage || messages_1.messages.required
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
const [minValue, minMessage] = (0, normalizeRule_1.normalizeRule)(min);
|
|
30
|
-
if (!isEmpty && typeof minValue !== "undefined") {
|
|
31
|
-
if (typeof value === "number" && value < minValue) {
|
|
32
|
-
return {
|
|
33
|
-
type: "min",
|
|
34
|
-
message: minMessage || messages_1.messages.min(minValue)
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
const [maxValue, maxMessage] = (0, normalizeRule_1.normalizeRule)(max);
|
|
39
|
-
if (!isEmpty && typeof maxValue !== "undefined") {
|
|
40
|
-
if (typeof value === "number" && value > maxValue) {
|
|
41
|
-
return {
|
|
42
|
-
type: "max",
|
|
43
|
-
message: maxMessage || messages_1.messages.max(maxValue)
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
const [minLengthValue, minLengthMessage] = (0, normalizeRule_1.normalizeRule)(minLength);
|
|
48
|
-
if (!isEmpty && typeof minLengthValue !== "undefined") {
|
|
49
|
-
const validateValue = typeof value === "number"
|
|
50
|
-
? value.toString()
|
|
51
|
-
: value;
|
|
52
|
-
if (typeof validateValue === "string" && validateValue.length < minLengthValue) {
|
|
53
|
-
return {
|
|
54
|
-
type: "minLength",
|
|
55
|
-
message: minLengthMessage || messages_1.messages.minLength(minLengthValue)
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
if (Array.isArray(value) && value.length < minLengthValue) {
|
|
59
|
-
return {
|
|
60
|
-
type: "minLength",
|
|
61
|
-
message: minLengthMessage || messages_1.messages.minArrayLength(minLengthValue)
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
const [maxLengthValue, maxLengthMessage = ""] = (0, normalizeRule_1.normalizeRule)(maxLength);
|
|
66
|
-
if (!isEmpty && typeof maxLengthValue === "number") {
|
|
67
|
-
const validateValue = typeof value === "number"
|
|
68
|
-
? value.toString()
|
|
69
|
-
: value;
|
|
70
|
-
if (typeof validateValue === "string" && validateValue.length > maxLengthValue) {
|
|
71
|
-
return {
|
|
72
|
-
type: "maxLength",
|
|
73
|
-
message: maxLengthMessage || messages_1.messages.maxLength(maxLengthValue)
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
if (Array.isArray(value) && value.length > maxLengthValue) {
|
|
77
|
-
return {
|
|
78
|
-
type: "maxLength",
|
|
79
|
-
message: maxLengthMessage || messages_1.messages.maxArrayLength(maxLengthValue)
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
if (validate) {
|
|
84
|
-
const rules = typeof validate === "function"
|
|
85
|
-
? { validate }
|
|
86
|
-
: validate;
|
|
87
|
-
for (const name in rules) {
|
|
88
|
-
const result = yield rules[name](value);
|
|
89
|
-
if (result === false || typeof result === "string") {
|
|
90
|
-
return {
|
|
91
|
-
message: typeof result === "string" ? result : messages_1.messages.custom,
|
|
92
|
-
type: "custom"
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return undefined;
|
|
98
|
-
});
|
|
99
|
-
exports.validatePrompt = validatePrompt;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./validateVolume";
|
package/lib/validators/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./validateVolume"), exports);
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateVolume = void 0;
|
|
4
|
-
const messages_1 = require("../messages");
|
|
5
|
-
const validateVolume = (value) => {
|
|
6
|
-
if (typeof value === "undefined" || value === null || value === "") {
|
|
7
|
-
return true;
|
|
8
|
-
}
|
|
9
|
-
if (typeof value !== "string") {
|
|
10
|
-
return messages_1.messages.volume.notAString;
|
|
11
|
-
}
|
|
12
|
-
if (value.length > 255) {
|
|
13
|
-
return messages_1.messages.volume.tooLong;
|
|
14
|
-
}
|
|
15
|
-
if (!/^[A-Za-z0-9]+(?:[-_]+[A-Za-z0-9]+)*$/.test(value)) {
|
|
16
|
-
return messages_1.messages.volume.invalidCharacters;
|
|
17
|
-
}
|
|
18
|
-
return true;
|
|
19
|
-
};
|
|
20
|
-
exports.validateVolume = validateVolume;
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import MuteStream from "mute-stream";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export class CustomMuteStream extends MuteStream {
|
|
5
|
-
protected _listeners: {
|
|
6
|
-
[event: string]: Map<any, any>;
|
|
7
|
-
} = {};
|
|
8
|
-
protected _waiters: {
|
|
9
|
-
[event: string]: {
|
|
10
|
-
completed: number;
|
|
11
|
-
resolve: (value: void | PromiseLike<void>) => void;
|
|
12
|
-
};
|
|
13
|
-
} = {};
|
|
14
|
-
|
|
15
|
-
protected getOverride(event: string, listener: any) {
|
|
16
|
-
if(!this._listeners) {
|
|
17
|
-
this._listeners = {};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if(!this._listeners[event]) {
|
|
21
|
-
this._listeners[event] = new Map();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
let override = this._listeners[event].get(listener);
|
|
25
|
-
|
|
26
|
-
if(!override) {
|
|
27
|
-
override = async (...args: any[]) => {
|
|
28
|
-
const result = await listener(...args);
|
|
29
|
-
|
|
30
|
-
if(!this._waiters) {
|
|
31
|
-
this._waiters = {};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if(this._waiters[event]) {
|
|
35
|
-
this._waiters[event].completed++;
|
|
36
|
-
|
|
37
|
-
if(this._waiters[event].completed === this._listeners[event].size) {
|
|
38
|
-
this._waiters[event].resolve();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return result;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
this._listeners[event].set(listener, override);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return override;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
protected hasOverride(event: string, listener: any) {
|
|
52
|
-
return this._listeners && this._listeners[event] && this._listeners[event].has(listener);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
protected removeOverride(event: string, listener: any) {
|
|
56
|
-
if(!this.hasOverride(event, listener)) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
this._listeners[event].delete(listener);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
public on(event: any, listener: any): this {
|
|
64
|
-
const override = this.getOverride(event, listener);
|
|
65
|
-
|
|
66
|
-
super.on(event, override);
|
|
67
|
-
|
|
68
|
-
return this;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
public addListener(event: any, listener: any): this {
|
|
72
|
-
const override = this.getOverride(event, listener);
|
|
73
|
-
|
|
74
|
-
super.addListener(event, override);
|
|
75
|
-
|
|
76
|
-
return this;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
public off(event: any, listener: any): this {
|
|
80
|
-
if(this.hasOverride(event, listener)) {
|
|
81
|
-
const override = this.getOverride(event, listener);
|
|
82
|
-
super.off(event, override);
|
|
83
|
-
this.removeOverride(event, listener);
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
super.off(event, listener);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return this;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
public removeListener(event: any, listener: any): this {
|
|
93
|
-
if(this.hasOverride(event, listener)) {
|
|
94
|
-
const override = this.getOverride(event, listener);
|
|
95
|
-
|
|
96
|
-
super.removeListener(event, override);
|
|
97
|
-
this.removeOverride(event, listener);
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
super.removeListener(event, listener);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return this;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
public async wait(event: string, data: any, key: any): Promise<void> {
|
|
107
|
-
return new Promise<void>((resolve) => {
|
|
108
|
-
this._waiters[event] = {
|
|
109
|
-
resolve,
|
|
110
|
-
completed: 0
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
this.emit(event, data, key);
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
}
|
package/test/tools/render.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import {render} from "@inquirer/testing";
|
|
2
|
-
import {Prompt, Context} from "@inquirer/type";
|
|
3
|
-
import {CustomMuteStream} from "../makes/CustomMuteStream";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export const customRender = async <const C, const V>(
|
|
7
|
-
prompt: Prompt<V, C>,
|
|
8
|
-
config: C,
|
|
9
|
-
options?: Omit<Context, "signal" | "input">
|
|
10
|
-
) => {
|
|
11
|
-
const input = new CustomMuteStream(),
|
|
12
|
-
abortController = new AbortController();
|
|
13
|
-
|
|
14
|
-
const data = await render(prompt, config, {
|
|
15
|
-
...options || {},
|
|
16
|
-
input,
|
|
17
|
-
signal: abortController.signal
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
return {
|
|
21
|
-
...data,
|
|
22
|
-
input,
|
|
23
|
-
events: {
|
|
24
|
-
keypress: (key: string) => {
|
|
25
|
-
return input.wait("keypress", null, {
|
|
26
|
-
name: key
|
|
27
|
-
});
|
|
28
|
-
},
|
|
29
|
-
type: async (text: string) => {
|
|
30
|
-
input.write(text);
|
|
31
|
-
|
|
32
|
-
for(const char of text) {
|
|
33
|
-
await input.wait("keypress", null, {
|
|
34
|
-
name: char
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
abort: () => {
|
|
40
|
-
data.answer.catch(() => undefined);
|
|
41
|
-
abortController.abort();
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|