@awsless/clui 0.0.2 → 0.0.4

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/dist/index.cjs CHANGED
@@ -33,13 +33,11 @@ __export(index_exports, {
33
33
  Cancelled: () => Cancelled,
34
34
  ansi: () => ansi_exports,
35
35
  color: () => color,
36
- isCancel: () => import_prompts4.isCancel,
37
36
  log: () => logs_exports,
38
37
  prompt: () => prompts_exports,
39
38
  symbol: () => symbols_exports
40
39
  });
41
40
  module.exports = __toCommonJS(index_exports);
42
- var import_prompts4 = require("@clack/prompts");
43
41
 
44
42
  // src/symbols.ts
45
43
  var symbols_exports = {};
@@ -60,6 +58,8 @@ var info = "\xB7";
60
58
  var prompts_exports = {};
61
59
  __export(prompts_exports, {
62
60
  confirm: () => confirm,
61
+ float: () => float,
62
+ integer: () => integer,
63
63
  multiSelect: () => multiSelect,
64
64
  password: () => password,
65
65
  select: () => select,
@@ -74,9 +74,9 @@ var Cancelled = class extends Error {
74
74
  super("cancelled");
75
75
  }
76
76
  };
77
- async function wrapPrompt(cb, { throwOnCancel = true } = {}) {
77
+ async function wrapPrompt(cb) {
78
78
  const result = await cb();
79
- if ((0, import_prompts.isCancel)(result) && throwOnCancel) {
79
+ if ((0, import_prompts.isCancel)(result)) {
80
80
  throw new Cancelled();
81
81
  }
82
82
  return result;
@@ -86,27 +86,55 @@ async function wrapPrompt(cb, { throwOnCancel = true } = {}) {
86
86
  var text = async (opts) => {
87
87
  return wrapPrompt(() => {
88
88
  return (0, import_prompts2.text)(opts);
89
- }, opts);
89
+ });
90
90
  };
91
91
  var password = async (opts) => {
92
92
  return wrapPrompt(() => {
93
93
  return (0, import_prompts2.password)({ mask: "*", ...opts });
94
- }, opts);
94
+ });
95
+ };
96
+ var integer = async (opts) => {
97
+ const result = await text({
98
+ ...opts,
99
+ defaultValue: opts.defaultValue?.toString(),
100
+ initialValue: opts.initialValue?.toString(),
101
+ validate(value) {
102
+ if (isNaN(Number(value)) || isNaN(parseInt(value, 10)) || value.includes(".")) {
103
+ return "Invalid integer";
104
+ }
105
+ return;
106
+ }
107
+ });
108
+ return parseInt(result, 10);
109
+ };
110
+ var float = async (opts) => {
111
+ const result = await text({
112
+ ...opts,
113
+ defaultValue: opts.defaultValue?.toString(),
114
+ initialValue: opts.initialValue?.toString(),
115
+ validate(value) {
116
+ if (isNaN(Number(value)) || isNaN(parseFloat(value))) {
117
+ return "Invalid float";
118
+ }
119
+ return;
120
+ }
121
+ });
122
+ return parseFloat(result);
95
123
  };
96
124
  var confirm = async (opts) => {
97
125
  return wrapPrompt(() => {
98
126
  return (0, import_prompts2.confirm)(opts);
99
- }, opts);
127
+ });
100
128
  };
101
129
  var select = async (opts) => {
102
130
  return wrapPrompt(() => {
103
131
  return (0, import_prompts2.select)(opts);
104
- }, opts);
132
+ });
105
133
  };
106
134
  var multiSelect = async (opts) => {
107
135
  return wrapPrompt(() => {
108
136
  return (0, import_prompts2.multiselect)(opts);
109
- }, opts);
137
+ });
110
138
  };
111
139
 
112
140
  // src/logs.ts
@@ -271,7 +299,6 @@ var table = (props) => {
271
299
  Cancelled,
272
300
  ansi,
273
301
  color,
274
- isCancel,
275
302
  log,
276
303
  prompt,
277
304
  symbol
package/dist/index.d.cts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { TextOptions, PasswordOptions, ConfirmOptions, SelectOptions, MultiSelectOptions } from '@clack/prompts';
2
- export { isCancel } from '@clack/prompts';
3
2
  import stringLength from 'string-length';
4
3
  import { Options } from 'wrap-ansi';
5
4
  import * as chalk from 'chalk';
@@ -14,26 +13,29 @@ declare namespace symbols {
14
13
  export { error$1 as error, info$1 as info, step$1 as step, success$1 as success, warning$1 as warning };
15
14
  }
16
15
 
17
- declare class Cancelled extends Error {
18
- constructor();
19
- }
20
- type WrapPromptOptions<T extends boolean | undefined = boolean> = {
21
- throwOnCancel?: T;
16
+ declare const text: (opts: TextOptions) => Promise<string>;
17
+ declare const password: (opts: PasswordOptions) => Promise<string>;
18
+ type NumberOptions = {
19
+ message: string;
20
+ placeholder?: string;
21
+ defaultValue?: number;
22
+ initialValue?: number;
22
23
  };
23
-
24
- declare const text: <T extends boolean | undefined = undefined>(opts: TextOptions & WrapPromptOptions<T>) => Promise<T extends false ? string | symbol : string>;
25
- declare const password: <T extends boolean | undefined = undefined>(opts: PasswordOptions & WrapPromptOptions<T>) => Promise<T extends false ? string | symbol : string>;
26
- declare const confirm: <T extends boolean | undefined = undefined>(opts: ConfirmOptions & WrapPromptOptions<T>) => Promise<T extends false ? boolean | symbol : boolean>;
27
- declare const select: <Value, T extends boolean | undefined = undefined>(opts: SelectOptions<Value> & WrapPromptOptions<T>) => Promise<T extends false ? symbol | Value : Exclude<Value, symbol>>;
28
- declare const multiSelect: <Value, T extends boolean | undefined = undefined>(opts: MultiSelectOptions<Value> & WrapPromptOptions<T>) => Promise<T extends false ? symbol | Value[] : Value[]>;
24
+ declare const integer: (opts: NumberOptions) => Promise<number>;
25
+ declare const float: (opts: NumberOptions) => Promise<number>;
26
+ declare const confirm: (opts: ConfirmOptions) => Promise<boolean>;
27
+ declare const select: <Value>(opts: SelectOptions<Value>) => Promise<Exclude<Value, symbol>>;
28
+ declare const multiSelect: <Value>(opts: MultiSelectOptions<Value>) => Promise<Value[]>;
29
29
 
30
30
  declare const prompts_confirm: typeof confirm;
31
+ declare const prompts_float: typeof float;
32
+ declare const prompts_integer: typeof integer;
31
33
  declare const prompts_multiSelect: typeof multiSelect;
32
34
  declare const prompts_password: typeof password;
33
35
  declare const prompts_select: typeof select;
34
36
  declare const prompts_text: typeof text;
35
37
  declare namespace prompts {
36
- export { prompts_confirm as confirm, prompts_multiSelect as multiSelect, prompts_password as password, prompts_select as select, prompts_text as text };
38
+ export { prompts_confirm as confirm, prompts_float as float, prompts_integer as integer, prompts_multiSelect as multiSelect, prompts_password as password, prompts_select as select, prompts_text as text };
37
39
  }
38
40
 
39
41
  declare const intro: (title?: string) => void;
@@ -88,4 +90,8 @@ declare namespace ansi {
88
90
 
89
91
  declare const color: chalk.ChalkInstance;
90
92
 
93
+ declare class Cancelled extends Error {
94
+ constructor();
95
+ }
96
+
91
97
  export { Cancelled, ansi, color, logs as log, prompts as prompt, symbols as symbol };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { TextOptions, PasswordOptions, ConfirmOptions, SelectOptions, MultiSelectOptions } from '@clack/prompts';
2
- export { isCancel } from '@clack/prompts';
3
2
  import stringLength from 'string-length';
4
3
  import { Options } from 'wrap-ansi';
5
4
  import * as chalk from 'chalk';
@@ -14,26 +13,29 @@ declare namespace symbols {
14
13
  export { error$1 as error, info$1 as info, step$1 as step, success$1 as success, warning$1 as warning };
15
14
  }
16
15
 
17
- declare class Cancelled extends Error {
18
- constructor();
19
- }
20
- type WrapPromptOptions<T extends boolean | undefined = boolean> = {
21
- throwOnCancel?: T;
16
+ declare const text: (opts: TextOptions) => Promise<string>;
17
+ declare const password: (opts: PasswordOptions) => Promise<string>;
18
+ type NumberOptions = {
19
+ message: string;
20
+ placeholder?: string;
21
+ defaultValue?: number;
22
+ initialValue?: number;
22
23
  };
23
-
24
- declare const text: <T extends boolean | undefined = undefined>(opts: TextOptions & WrapPromptOptions<T>) => Promise<T extends false ? string | symbol : string>;
25
- declare const password: <T extends boolean | undefined = undefined>(opts: PasswordOptions & WrapPromptOptions<T>) => Promise<T extends false ? string | symbol : string>;
26
- declare const confirm: <T extends boolean | undefined = undefined>(opts: ConfirmOptions & WrapPromptOptions<T>) => Promise<T extends false ? boolean | symbol : boolean>;
27
- declare const select: <Value, T extends boolean | undefined = undefined>(opts: SelectOptions<Value> & WrapPromptOptions<T>) => Promise<T extends false ? symbol | Value : Exclude<Value, symbol>>;
28
- declare const multiSelect: <Value, T extends boolean | undefined = undefined>(opts: MultiSelectOptions<Value> & WrapPromptOptions<T>) => Promise<T extends false ? symbol | Value[] : Value[]>;
24
+ declare const integer: (opts: NumberOptions) => Promise<number>;
25
+ declare const float: (opts: NumberOptions) => Promise<number>;
26
+ declare const confirm: (opts: ConfirmOptions) => Promise<boolean>;
27
+ declare const select: <Value>(opts: SelectOptions<Value>) => Promise<Exclude<Value, symbol>>;
28
+ declare const multiSelect: <Value>(opts: MultiSelectOptions<Value>) => Promise<Value[]>;
29
29
 
30
30
  declare const prompts_confirm: typeof confirm;
31
+ declare const prompts_float: typeof float;
32
+ declare const prompts_integer: typeof integer;
31
33
  declare const prompts_multiSelect: typeof multiSelect;
32
34
  declare const prompts_password: typeof password;
33
35
  declare const prompts_select: typeof select;
34
36
  declare const prompts_text: typeof text;
35
37
  declare namespace prompts {
36
- export { prompts_confirm as confirm, prompts_multiSelect as multiSelect, prompts_password as password, prompts_select as select, prompts_text as text };
38
+ export { prompts_confirm as confirm, prompts_float as float, prompts_integer as integer, prompts_multiSelect as multiSelect, prompts_password as password, prompts_select as select, prompts_text as text };
37
39
  }
38
40
 
39
41
  declare const intro: (title?: string) => void;
@@ -88,4 +90,8 @@ declare namespace ansi {
88
90
 
89
91
  declare const color: chalk.ChalkInstance;
90
92
 
93
+ declare class Cancelled extends Error {
94
+ constructor();
95
+ }
96
+
91
97
  export { Cancelled, ansi, color, logs as log, prompts as prompt, symbols as symbol };
package/dist/index.js CHANGED
@@ -4,9 +4,6 @@ var __export = (target, all) => {
4
4
  __defProp(target, name, { get: all[name], enumerable: true });
5
5
  };
6
6
 
7
- // src/index.ts
8
- import { isCancel as isCancel2 } from "@clack/prompts";
9
-
10
7
  // src/symbols.ts
11
8
  var symbols_exports = {};
12
9
  __export(symbols_exports, {
@@ -26,6 +23,8 @@ var info = "\xB7";
26
23
  var prompts_exports = {};
27
24
  __export(prompts_exports, {
28
25
  confirm: () => confirm,
26
+ float: () => float,
27
+ integer: () => integer,
29
28
  multiSelect: () => multiSelect,
30
29
  password: () => password,
31
30
  select: () => select,
@@ -46,9 +45,9 @@ var Cancelled = class extends Error {
46
45
  super("cancelled");
47
46
  }
48
47
  };
49
- async function wrapPrompt(cb, { throwOnCancel = true } = {}) {
48
+ async function wrapPrompt(cb) {
50
49
  const result = await cb();
51
- if (isCancel(result) && throwOnCancel) {
50
+ if (isCancel(result)) {
52
51
  throw new Cancelled();
53
52
  }
54
53
  return result;
@@ -58,27 +57,55 @@ async function wrapPrompt(cb, { throwOnCancel = true } = {}) {
58
57
  var text = async (opts) => {
59
58
  return wrapPrompt(() => {
60
59
  return p_text(opts);
61
- }, opts);
60
+ });
62
61
  };
63
62
  var password = async (opts) => {
64
63
  return wrapPrompt(() => {
65
64
  return p_password({ mask: "*", ...opts });
66
- }, opts);
65
+ });
66
+ };
67
+ var integer = async (opts) => {
68
+ const result = await text({
69
+ ...opts,
70
+ defaultValue: opts.defaultValue?.toString(),
71
+ initialValue: opts.initialValue?.toString(),
72
+ validate(value) {
73
+ if (isNaN(Number(value)) || isNaN(parseInt(value, 10)) || value.includes(".")) {
74
+ return "Invalid integer";
75
+ }
76
+ return;
77
+ }
78
+ });
79
+ return parseInt(result, 10);
80
+ };
81
+ var float = async (opts) => {
82
+ const result = await text({
83
+ ...opts,
84
+ defaultValue: opts.defaultValue?.toString(),
85
+ initialValue: opts.initialValue?.toString(),
86
+ validate(value) {
87
+ if (isNaN(Number(value)) || isNaN(parseFloat(value))) {
88
+ return "Invalid float";
89
+ }
90
+ return;
91
+ }
92
+ });
93
+ return parseFloat(result);
67
94
  };
68
95
  var confirm = async (opts) => {
69
96
  return wrapPrompt(() => {
70
97
  return p_confirm(opts);
71
- }, opts);
98
+ });
72
99
  };
73
100
  var select = async (opts) => {
74
101
  return wrapPrompt(() => {
75
102
  return p_select(opts);
76
- }, opts);
103
+ });
77
104
  };
78
105
  var multiSelect = async (opts) => {
79
106
  return wrapPrompt(() => {
80
107
  return p_multiselect(opts);
81
- }, opts);
108
+ });
82
109
  };
83
110
 
84
111
  // src/logs.ts
@@ -242,7 +269,6 @@ export {
242
269
  Cancelled,
243
270
  ansi_exports as ansi,
244
271
  color,
245
- isCancel2 as isCancel,
246
272
  logs_exports as log,
247
273
  prompts_exports as prompt,
248
274
  symbols_exports as symbol
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awsless/clui",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "repository": {