@wocker/utils 1.0.11-beta.0 → 2.0.0-beta.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.
- package/README.md +73 -2
- package/lib/index.d.ts +3 -8
- package/lib/index.js +3 -8
- package/lib/messages.d.ts +15 -0
- package/lib/messages.js +18 -0
- package/lib/prompts/index.d.ts +3 -0
- package/lib/prompts/index.js +19 -0
- package/lib/prompts/promptConfirm.d.ts +4 -0
- package/lib/prompts/promptConfirm.js +75 -0
- package/lib/prompts/promptInput.d.ts +15 -0
- package/lib/prompts/promptInput.js +179 -0
- package/lib/prompts/promptSelect.d.ts +15 -0
- package/lib/prompts/promptSelect.js +162 -0
- package/lib/tools/index.d.ts +4 -0
- package/lib/tools/index.js +20 -0
- package/lib/{normalizeOptions.d.ts → tools/normalizeOptions.d.ts} +6 -8
- package/lib/tools/normalizeOptions.js +26 -0
- package/lib/{volumeFormat.js → tools/volumeFormat.js} +1 -1
- package/lib/types/KeypressEvent.d.ts +5 -0
- package/lib/types/KeypressEvent.js +2 -0
- package/lib/types/PromptConfig.d.ts +8 -0
- package/lib/types/PromptConfig.js +2 -0
- package/lib/types/PromptValidationConfig.d.ts +10 -0
- package/lib/types/PromptValidationConfig.js +2 -0
- package/lib/types/Theme.d.ts +6 -0
- package/lib/types/Theme.js +2 -0
- package/lib/types/Validation.d.ts +2 -0
- package/lib/types/Validation.js +2 -0
- package/lib/types/ValidationError.d.ts +4 -0
- package/lib/types/ValidationError.js +2 -0
- package/lib/types/ValidationResult.d.ts +1 -0
- package/lib/types/ValidationResult.js +2 -0
- package/lib/types/ValidationRule.d.ts +3 -0
- package/lib/types/ValidationRule.js +2 -0
- package/lib/types/ValidationValue.d.ts +1 -0
- package/lib/types/ValidationValue.js +2 -0
- package/lib/types/ValidationValueMessage.d.ts +5 -0
- package/lib/types/ValidationValueMessage.js +2 -0
- package/lib/validation/normalizeRule.d.ts +3 -0
- package/lib/validation/normalizeRule.js +16 -0
- package/lib/validation/validatePrompt.d.ts +3 -0
- package/lib/validation/validatePrompt.js +101 -0
- package/lib/validators/index.d.ts +1 -0
- package/lib/validators/index.js +17 -0
- package/lib/validators/validateVolume.d.ts +2 -0
- package/lib/validators/validateVolume.js +20 -0
- package/package.json +18 -7
- package/test/makes/CustomMuteStream.ts +116 -0
- package/test/makes/PromptSimulator.ts +55 -0
- package/test/tools/render.ts +32 -0
- package/lib/normalizeOptions.js +0 -23
- package/lib/promptConfig.d.ts +0 -14
- package/lib/promptConfig.js +0 -76
- package/lib/promptConfirm.d.ts +0 -6
- package/lib/promptConfirm.js +0 -27
- package/lib/promptGroup.d.ts +0 -14
- package/lib/promptGroup.js +0 -55
- package/lib/promptSelect.d.ts +0 -14
- package/lib/promptSelect.js +0 -58
- package/lib/promptText.d.ts +0 -11
- package/lib/promptText.js +0 -62
- /package/lib/{demuxOutput.d.ts → tools/demuxOutput.d.ts} +0 -0
- /package/lib/{demuxOutput.js → tools/demuxOutput.js} +0 -0
- /package/lib/{volumeFormat.d.ts → tools/volumeFormat.d.ts} +0 -0
- /package/lib/{volumeParse.d.ts → tools/volumeParse.d.ts} +0 -0
- /package/lib/{volumeParse.js → tools/volumeParse.js} +0 -0
package/lib/promptConfig.js
DELETED
|
@@ -1,76 +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 __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
-
var t = {};
|
|
13
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
-
t[p] = s[p];
|
|
15
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
-
t[p[i]] = s[p[i]];
|
|
19
|
-
}
|
|
20
|
-
return t;
|
|
21
|
-
};
|
|
22
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.promptConfig = void 0;
|
|
24
|
-
const normalizeOptions_1 = require("./normalizeOptions");
|
|
25
|
-
const promptConfirm_1 = require("./promptConfirm");
|
|
26
|
-
const promptSelect_1 = require("./promptSelect");
|
|
27
|
-
const promptText_1 = require("./promptText");
|
|
28
|
-
const promptConfig = (options_1, ...args_1) => __awaiter(void 0, [options_1, ...args_1], void 0, function* (options, values = {}) {
|
|
29
|
-
for (const key in options) {
|
|
30
|
-
const params = options[key];
|
|
31
|
-
switch (params.type) {
|
|
32
|
-
case "boolean": {
|
|
33
|
-
const { type } = params, rest = __rest(params, ["type"]);
|
|
34
|
-
values[key] = yield (0, promptConfirm_1.promptConfirm)(Object.assign(Object.assign({}, rest), { default: typeof values[key] === "boolean"
|
|
35
|
-
? values[key]
|
|
36
|
-
: typeof values[key] !== "undefined"
|
|
37
|
-
? values[key] === "true"
|
|
38
|
-
: params.default }));
|
|
39
|
-
break;
|
|
40
|
-
}
|
|
41
|
-
case "select": {
|
|
42
|
-
if (params.multiple) {
|
|
43
|
-
const { type, multiple } = params, rest = __rest(params, ["type", "multiple"]);
|
|
44
|
-
const options = (0, normalizeOptions_1.normalizeOptions)(params.options);
|
|
45
|
-
const selected = yield (0, promptSelect_1.promptSelect)(Object.assign(Object.assign({}, rest), { multiple: true, default: options.map((option) => {
|
|
46
|
-
return option.value;
|
|
47
|
-
}).filter((name) => {
|
|
48
|
-
return values[name];
|
|
49
|
-
}) }));
|
|
50
|
-
for (const option of options) {
|
|
51
|
-
if (selected.includes(option.value)) {
|
|
52
|
-
values[option.value] = true;
|
|
53
|
-
}
|
|
54
|
-
else if (option.value in values) {
|
|
55
|
-
delete values[option.value];
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
const { type, multiple } = params, rest = __rest(params, ["type", "multiple"]);
|
|
61
|
-
values[key] = yield (0, promptSelect_1.promptSelect)(Object.assign(Object.assign({}, rest), { multiple: false, default: values[key] || params.default }));
|
|
62
|
-
}
|
|
63
|
-
break;
|
|
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
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return values;
|
|
75
|
-
});
|
|
76
|
-
exports.promptConfig = promptConfig;
|
package/lib/promptConfirm.d.ts
DELETED
package/lib/promptConfirm.js
DELETED
|
@@ -1,27 +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.promptConfirm = void 0;
|
|
16
|
-
const inquirer_1 = __importDefault(require("inquirer"));
|
|
17
|
-
const promptConfirm = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
-
const { message, default: defaultValue = true } = options;
|
|
19
|
-
const { confirm } = yield inquirer_1.default.prompt({
|
|
20
|
-
type: "confirm",
|
|
21
|
-
name: "confirm",
|
|
22
|
-
message,
|
|
23
|
-
default: defaultValue
|
|
24
|
-
});
|
|
25
|
-
return confirm;
|
|
26
|
-
});
|
|
27
|
-
exports.promptConfirm = promptConfirm;
|
package/lib/promptGroup.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { PromptConfirmOptions } from "./promptConfirm";
|
|
2
|
-
import { PromptSelectOptions } from "./promptSelect";
|
|
3
|
-
import { PromptTextOptions } from "./promptText";
|
|
4
|
-
type ConfirmOptions = PromptConfirmOptions & {
|
|
5
|
-
type: "boolean";
|
|
6
|
-
};
|
|
7
|
-
type SelectOptions = PromptSelectOptions & {
|
|
8
|
-
type: "select";
|
|
9
|
-
};
|
|
10
|
-
type Options = {
|
|
11
|
-
[key: string]: PromptTextOptions | ConfirmOptions | SelectOptions;
|
|
12
|
-
};
|
|
13
|
-
export declare const promptGroup: (options: Options, values?: any) => Promise<any>;
|
|
14
|
-
export {};
|
package/lib/promptGroup.js
DELETED
|
@@ -1,55 +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 __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
-
var t = {};
|
|
13
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
-
t[p] = s[p];
|
|
15
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
-
t[p[i]] = s[p[i]];
|
|
19
|
-
}
|
|
20
|
-
return t;
|
|
21
|
-
};
|
|
22
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.promptGroup = void 0;
|
|
24
|
-
const promptConfirm_1 = require("./promptConfirm");
|
|
25
|
-
const promptSelect_1 = require("./promptSelect");
|
|
26
|
-
const promptText_1 = require("./promptText");
|
|
27
|
-
const promptGroup = (options_1, ...args_1) => __awaiter(void 0, [options_1, ...args_1], void 0, function* (options, values = {}) {
|
|
28
|
-
const res = {};
|
|
29
|
-
for (const key in options) {
|
|
30
|
-
const params = options[key];
|
|
31
|
-
switch (params.type) {
|
|
32
|
-
case "boolean": {
|
|
33
|
-
const { type } = params, rest = __rest(params, ["type"]);
|
|
34
|
-
res[key] = yield (0, promptConfirm_1.promptConfirm)(Object.assign(Object.assign({}, rest), { default: typeof values[key] !== "undefined"
|
|
35
|
-
? values[key] === "true"
|
|
36
|
-
: params.default }));
|
|
37
|
-
break;
|
|
38
|
-
}
|
|
39
|
-
case "select": {
|
|
40
|
-
const { type } = params, rest = __rest(params, ["type"]);
|
|
41
|
-
res[key] = yield (0, promptSelect_1.promptSelect)(Object.assign(Object.assign({}, rest), { default: values[key] || params.default }));
|
|
42
|
-
break;
|
|
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
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return res;
|
|
54
|
-
});
|
|
55
|
-
exports.promptGroup = promptGroup;
|
package/lib/promptSelect.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { RawOptions } from "./normalizeOptions";
|
|
2
|
-
type Options = {
|
|
3
|
-
message?: string;
|
|
4
|
-
options: RawOptions;
|
|
5
|
-
} & ({
|
|
6
|
-
multiple?: false;
|
|
7
|
-
default?: string;
|
|
8
|
-
} | {
|
|
9
|
-
multiple: true;
|
|
10
|
-
default?: string[];
|
|
11
|
-
});
|
|
12
|
-
type ResultType<T extends Options> = T['multiple'] extends true ? string[] : string;
|
|
13
|
-
export declare const promptSelect: <R extends ResultType<T>, T extends Options = any>(props: T) => Promise<R>;
|
|
14
|
-
export { Options as PromptSelectOptions };
|
package/lib/promptSelect.js
DELETED
|
@@ -1,58 +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.promptSelect = void 0;
|
|
16
|
-
const inquirer_1 = __importDefault(require("inquirer"));
|
|
17
|
-
const normalizeOptions_1 = require("./normalizeOptions");
|
|
18
|
-
const promptSelect = (props) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
-
const { message, options: rawOptions, } = props;
|
|
20
|
-
const options = (0, normalizeOptions_1.normalizeOptions)(rawOptions);
|
|
21
|
-
if (props.multiple) {
|
|
22
|
-
const { value } = yield inquirer_1.default.prompt({
|
|
23
|
-
message,
|
|
24
|
-
name: "value",
|
|
25
|
-
type: "checkbox",
|
|
26
|
-
choices: options.map((option) => {
|
|
27
|
-
return {
|
|
28
|
-
name: option.label,
|
|
29
|
-
value: option.value,
|
|
30
|
-
checked: Array.isArray(props.default)
|
|
31
|
-
? props.default.includes(option.value)
|
|
32
|
-
: false
|
|
33
|
-
};
|
|
34
|
-
})
|
|
35
|
-
});
|
|
36
|
-
return value;
|
|
37
|
-
}
|
|
38
|
-
const defaultOption = options.find((option) => {
|
|
39
|
-
return option.value === props.default;
|
|
40
|
-
});
|
|
41
|
-
const { value } = yield inquirer_1.default.prompt({
|
|
42
|
-
choices: options.map((option) => {
|
|
43
|
-
return option.label;
|
|
44
|
-
}),
|
|
45
|
-
message,
|
|
46
|
-
name: "value",
|
|
47
|
-
type: "list",
|
|
48
|
-
default: defaultOption ? (defaultOption.label || defaultOption.value) : ""
|
|
49
|
-
});
|
|
50
|
-
const selected = options.find((option) => {
|
|
51
|
-
return option.label === value;
|
|
52
|
-
});
|
|
53
|
-
if (selected) {
|
|
54
|
-
return selected.value;
|
|
55
|
-
}
|
|
56
|
-
return "";
|
|
57
|
-
});
|
|
58
|
-
exports.promptSelect = promptSelect;
|
package/lib/promptText.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
type Options = {
|
|
2
|
-
required?: boolean;
|
|
3
|
-
message?: string;
|
|
4
|
-
prefix?: string;
|
|
5
|
-
suffix?: string;
|
|
6
|
-
type?: "string" | "number" | "int" | "password";
|
|
7
|
-
default?: number | string;
|
|
8
|
-
validate?: (value?: string) => boolean | string | Promise<boolean | string>;
|
|
9
|
-
};
|
|
10
|
-
export declare const promptText: (options: Options) => Promise<any>;
|
|
11
|
-
export { Options as PromptTextOptions };
|
package/lib/promptText.js
DELETED
|
@@ -1,62 +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.promptText = void 0;
|
|
16
|
-
const inquirer_1 = __importDefault(require("inquirer"));
|
|
17
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
18
|
-
const promptText = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
-
const { required, message, prefix = "", suffix = "", type, default: defaultValue, validate } = options;
|
|
20
|
-
const { value } = yield inquirer_1.default.prompt({
|
|
21
|
-
name: "value",
|
|
22
|
-
type: (() => {
|
|
23
|
-
switch (type) {
|
|
24
|
-
case "password":
|
|
25
|
-
return type;
|
|
26
|
-
default:
|
|
27
|
-
return "input";
|
|
28
|
-
}
|
|
29
|
-
})(),
|
|
30
|
-
message,
|
|
31
|
-
default: defaultValue,
|
|
32
|
-
validate(value) {
|
|
33
|
-
if (required) {
|
|
34
|
-
if (typeof value === "undefined" || value === "") {
|
|
35
|
-
return "Mandatory value";
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
if (type === "int" || type === "number") {
|
|
39
|
-
if (isNaN(parseInt(value)) || parseInt(value).toString() !== value) {
|
|
40
|
-
return "Should be integer";
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
if (validate) {
|
|
44
|
-
return validate(value);
|
|
45
|
-
}
|
|
46
|
-
return true;
|
|
47
|
-
},
|
|
48
|
-
transformer(value) {
|
|
49
|
-
if (!prefix && !suffix) {
|
|
50
|
-
return value;
|
|
51
|
-
}
|
|
52
|
-
if (suffix) {
|
|
53
|
-
setTimeout(() => {
|
|
54
|
-
process.stdout.write(`\x1b[${suffix.length}D`);
|
|
55
|
-
}, 0);
|
|
56
|
-
}
|
|
57
|
-
return `${chalk_1.default.gray(prefix)}${value}${chalk_1.default.gray(suffix)}`;
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
return value;
|
|
61
|
-
});
|
|
62
|
-
exports.promptText = promptText;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|