@wocker/utils 1.0.4 → 1.0.6

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.
@@ -1,2 +1 @@
1
- /// <reference types="node" />
2
1
  export declare const demuxOutput: (buffer: Buffer) => Buffer;
@@ -10,5 +10,5 @@ type Options = {
10
10
  default?: string[];
11
11
  });
12
12
  type ResultType<T extends Options> = T['multiple'] extends true ? string[] : string;
13
- export declare const promptSelect: <T extends Options>(props: T) => Promise<ResultType<T>>;
13
+ export declare const promptSelect: <R extends ResultType<T>, T extends Options = any>(props: T) => Promise<R>;
14
14
  export { Options as PromptSelectOptions };
@@ -3,8 +3,9 @@ type Options = {
3
3
  message?: string;
4
4
  prefix?: string;
5
5
  suffix?: string;
6
- type?: "string" | "number" | "int";
6
+ type?: "string" | "number" | "int" | "password";
7
7
  default?: number | string;
8
+ validate?: (value?: string) => boolean | string | Promise<boolean | string>;
8
9
  };
9
10
  export declare const promptText: (options: Options) => Promise<any>;
10
11
  export { Options as PromptTextOptions };
package/lib/promptText.js CHANGED
@@ -16,10 +16,17 @@ exports.promptText = void 0;
16
16
  const inquirer_1 = __importDefault(require("inquirer"));
17
17
  const chalk_1 = __importDefault(require("chalk"));
18
18
  const promptText = (options) => __awaiter(void 0, void 0, void 0, function* () {
19
- const { required, message, prefix = "", suffix = "", type, default: defaultValue } = options;
19
+ const { required, message, prefix = "", suffix = "", type, default: defaultValue, validate } = options;
20
20
  const { value } = yield inquirer_1.default.prompt({
21
21
  name: "value",
22
- type: "input",
22
+ type: (() => {
23
+ switch (type) {
24
+ case "password":
25
+ return type;
26
+ default:
27
+ return "input";
28
+ }
29
+ })(),
23
30
  message,
24
31
  default: defaultValue,
25
32
  validate(value) {
@@ -33,6 +40,9 @@ const promptText = (options) => __awaiter(void 0, void 0, void 0, function* () {
33
40
  return "Should be integer";
34
41
  }
35
42
  }
43
+ if (validate) {
44
+ return validate(value);
45
+ }
36
46
  return true;
37
47
  },
38
48
  transformer(value) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wocker/utils",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "author": "Kris Papercut <krispcut@gmail.com>",
5
5
  "description": "Utils for @wocker",
6
6
  "license": "MIT",