@wocker/utils 1.0.3 → 1.0.5

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;
@@ -25,7 +25,7 @@ const normalizeOptions_1 = require("./normalizeOptions");
25
25
  const promptConfirm_1 = require("./promptConfirm");
26
26
  const promptSelect_1 = require("./promptSelect");
27
27
  const promptText_1 = require("./promptText");
28
- const promptConfig = (options, values = {}) => __awaiter(void 0, void 0, void 0, function* () {
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) {
@@ -37,17 +37,11 @@ const promptConfig = (options, values = {}) => __awaiter(void 0, void 0, void 0,
37
37
  }
38
38
  case "boolean": {
39
39
  const { type } = params, rest = __rest(params, ["type"]);
40
- const selected = yield (0, promptConfirm_1.promptConfirm)(Object.assign(Object.assign({}, rest), { default: typeof values[key] === "boolean"
40
+ values[key] = yield (0, promptConfirm_1.promptConfirm)(Object.assign(Object.assign({}, rest), { default: typeof values[key] === "boolean"
41
41
  ? values[key]
42
42
  : typeof values[key] !== "undefined"
43
43
  ? values[key] === "true"
44
44
  : params.default }));
45
- if (selected) {
46
- values[key] = true;
47
- }
48
- else if (key in values) {
49
- delete values[key];
50
- }
51
45
  break;
52
46
  }
53
47
  case "select": {
@@ -24,7 +24,7 @@ exports.promptGroup = void 0;
24
24
  const promptConfirm_1 = require("./promptConfirm");
25
25
  const promptSelect_1 = require("./promptSelect");
26
26
  const promptText_1 = require("./promptText");
27
- const promptGroup = (options, values = {}) => __awaiter(void 0, void 0, void 0, function* () {
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];
@@ -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.3",
3
+ "version": "1.0.5",
4
4
  "author": "Kris Papercut <krispcut@gmail.com>",
5
5
  "description": "Utils for @wocker",
6
6
  "license": "MIT",
@@ -9,7 +9,7 @@
9
9
  "keywords": [
10
10
  "wocker"
11
11
  ],
12
- "homepage": "https://github.com/kearisp/wocker-utils#readme",
12
+ "homepage": "https://kearisp.github.io/wocker",
13
13
  "repository": {
14
14
  "type": "git",
15
15
  "url": "git+https://github.com/kearisp/wocker-utils.git"
@@ -29,6 +29,6 @@
29
29
  "devDependencies": {
30
30
  "@types/inquirer": "^7.3.3",
31
31
  "jest": "^29.7.0",
32
- "typescript": "^5.2.2"
32
+ "typescript": "^5.4.5"
33
33
  }
34
34
  }