massarg 1.0.7-pre.1 → 2.0.0-pre.10
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 +126 -209
- package/command.d.ts +183 -0
- package/command.d.ts.map +1 -0
- package/command.js +410 -0
- package/command.js.map +1 -0
- package/error.d.ts +36 -0
- package/error.d.ts.map +1 -0
- package/error.js +37 -0
- package/error.js.map +1 -0
- package/example.d.ts +31 -0
- package/example.d.ts.map +1 -0
- package/example.js +41 -0
- package/example.js.map +1 -0
- package/help.d.ts +964 -0
- package/help.d.ts.map +1 -0
- package/help.js +345 -0
- package/help.js.map +1 -0
- package/index.d.ts +1 -70
- package/index.d.ts.map +1 -1
- package/index.js +13 -688
- package/index.js.map +1 -1
- package/massarg.d.ts +8 -0
- package/massarg.d.ts.map +1 -0
- package/massarg.js +23 -0
- package/massarg.js.map +1 -0
- package/option.d.ts +293 -0
- package/option.d.ts.map +1 -0
- package/option.js +308 -0
- package/option.js.map +1 -0
- package/package.json +22 -15
- package/style.d.ts +46 -0
- package/style.d.ts.map +1 -0
- package/style.js +55 -0
- package/style.js.map +1 -0
- package/utils.d.ts +35 -13
- package/utils.d.ts.map +1 -1
- package/utils.js +108 -110
- package/utils.js.map +1 -1
- package/assertions.d.ts +0 -8
- package/assertions.d.ts.map +0 -1
- package/assertions.js +0 -145
- package/assertions.js.map +0 -1
- package/errors.d.ts +0 -7
- package/errors.d.ts.map +0 -1
- package/errors.js +0 -33
- package/errors.js.map +0 -1
- package/types.d.ts +0 -224
- package/types.d.ts.map +0 -1
- package/types.js +0 -3
- package/types.js.map +0 -1
package/option.js
ADDED
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MassargHelpFlag = exports.MassargFlag = exports.MassargNumber = exports.MassargOption = exports.NEGATE_SHORT_PREFIX = exports.NEGATE_FULL_PREFIX = exports.OPT_SHORT_PREFIX = exports.OPT_FULL_PREFIX = exports.ArrayOptionConfig = exports.TypedOptionConfig = exports.FlagConfig = exports.OptionConfig = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const error_1 = require("./error");
|
|
6
|
+
const utils_1 = require("./utils");
|
|
7
|
+
const OptionConfig = (type) => zod_1.z.object({
|
|
8
|
+
/** Name of the option */
|
|
9
|
+
name: zod_1.z.string(),
|
|
10
|
+
/** Description of the option, displayed in the help output */
|
|
11
|
+
description: zod_1.z.string(),
|
|
12
|
+
/** Default value of the option */
|
|
13
|
+
defaultValue: zod_1.z.any().optional(),
|
|
14
|
+
/** Aliases for the option, which can be used with the shorthand option notation. */
|
|
15
|
+
aliases: zod_1.z.string().array(),
|
|
16
|
+
/**
|
|
17
|
+
* Parse the value of the option. You can return any type here, or throw an error if the value
|
|
18
|
+
* is invalid.
|
|
19
|
+
*/
|
|
20
|
+
parse: zod_1.z.function().args(zod_1.z.string(), zod_1.z.any()).returns(type).optional(),
|
|
21
|
+
/**
|
|
22
|
+
* Whether the option is an array.
|
|
23
|
+
*
|
|
24
|
+
* Array options can be specified multiple times, and the values will be collected into an array.
|
|
25
|
+
*
|
|
26
|
+
* Normally, specifying an option multiple times will override the previous value.
|
|
27
|
+
*/
|
|
28
|
+
array: zod_1.z.boolean().optional(),
|
|
29
|
+
/** Whether the option is required. If it is required, parsing will throw an error if it's not
|
|
30
|
+
* present.
|
|
31
|
+
*/
|
|
32
|
+
required: zod_1.z.boolean().optional(),
|
|
33
|
+
/** Whether the option is the default option. The default option is the option that is used if
|
|
34
|
+
* no other option is specified, e.g. a value is passed in without an option name.
|
|
35
|
+
*
|
|
36
|
+
* Note that if commands match the same argument first, they will be used instead of the default
|
|
37
|
+
* option.
|
|
38
|
+
*/
|
|
39
|
+
isDefault: zod_1.z.boolean().optional(),
|
|
40
|
+
/** Whether the option is hidden. Hidden options are not displayed in the help output. */
|
|
41
|
+
hidden: zod_1.z.boolean().optional(),
|
|
42
|
+
/** Specify a custom name for the output, which will be used when parsing the args. */
|
|
43
|
+
outputName: zod_1.z.string().optional(),
|
|
44
|
+
});
|
|
45
|
+
exports.OptionConfig = OptionConfig;
|
|
46
|
+
exports.FlagConfig = (0, exports.OptionConfig)(zod_1.z.any())
|
|
47
|
+
.omit({ parse: true, isDefault: true })
|
|
48
|
+
.merge(zod_1.z.object({
|
|
49
|
+
/** Whether the flag can be negated, e.g. `--no-verbose` */
|
|
50
|
+
negatable: zod_1.z.boolean().optional(),
|
|
51
|
+
}));
|
|
52
|
+
const TypedOptionConfig = (type) => (0, exports.OptionConfig)(type).merge(zod_1.z.object({
|
|
53
|
+
type: zod_1.z.enum(['number']).optional(),
|
|
54
|
+
}));
|
|
55
|
+
exports.TypedOptionConfig = TypedOptionConfig;
|
|
56
|
+
/**
|
|
57
|
+
* @see OptionConfig
|
|
58
|
+
* @see ArrayOptionConfig
|
|
59
|
+
*/
|
|
60
|
+
const ArrayOptionConfig = (type) => (0, exports.TypedOptionConfig)(zod_1.z.array(type)).merge(
|
|
61
|
+
// OptionConfig(z.array(type)).merge(
|
|
62
|
+
zod_1.z.object({
|
|
63
|
+
defaultValue: zod_1.z.array(type).optional(),
|
|
64
|
+
}));
|
|
65
|
+
exports.ArrayOptionConfig = ArrayOptionConfig;
|
|
66
|
+
// TODO turn to options
|
|
67
|
+
exports.OPT_FULL_PREFIX = '--';
|
|
68
|
+
exports.OPT_SHORT_PREFIX = '-';
|
|
69
|
+
exports.NEGATE_FULL_PREFIX = '--no-';
|
|
70
|
+
exports.NEGATE_SHORT_PREFIX = '^';
|
|
71
|
+
/**
|
|
72
|
+
* An option that can be passed to a command.
|
|
73
|
+
*
|
|
74
|
+
* Options can be specified in two ways:
|
|
75
|
+
*
|
|
76
|
+
* - Using the long form, e.g. `--option value`
|
|
77
|
+
* - Using the short form, e.g. `-o value`
|
|
78
|
+
*
|
|
79
|
+
* They can also have a parse function, which will be used to parse the value passed in from the
|
|
80
|
+
* original argument (string).
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* massarg(options).option({
|
|
85
|
+
* name: 'option',
|
|
86
|
+
* description: 'An option',
|
|
87
|
+
* defaultValue: 'default',
|
|
88
|
+
* aliases: ['o'],
|
|
89
|
+
* parse: (value) => value.toUpperCase(),
|
|
90
|
+
* })
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
class MassargOption {
|
|
94
|
+
constructor(options) {
|
|
95
|
+
(0, exports.OptionConfig)(zod_1.z.any()).parse(options);
|
|
96
|
+
this.name = options.name;
|
|
97
|
+
this.description = options.description;
|
|
98
|
+
this.defaultValue = options.defaultValue;
|
|
99
|
+
this.aliases = options.aliases;
|
|
100
|
+
this.parse = options.parse ?? ((x) => x);
|
|
101
|
+
this.isArray = options.array ?? false;
|
|
102
|
+
this.isDefault = options.isDefault ?? false;
|
|
103
|
+
this.isRequired = options.required ?? false;
|
|
104
|
+
this.outputName = options.outputName;
|
|
105
|
+
}
|
|
106
|
+
static fromTypedConfig(config) {
|
|
107
|
+
switch (config.type) {
|
|
108
|
+
case 'number':
|
|
109
|
+
return new MassargNumber(config);
|
|
110
|
+
}
|
|
111
|
+
return new MassargOption(config);
|
|
112
|
+
}
|
|
113
|
+
getOutputName() {
|
|
114
|
+
return this.outputName || (0, utils_1.toCamelCase)(this.name);
|
|
115
|
+
}
|
|
116
|
+
parseDetails(argv, options, prefixes) {
|
|
117
|
+
let input = '';
|
|
118
|
+
try {
|
|
119
|
+
if (!this.isMatch(argv[0], prefixes)) {
|
|
120
|
+
throw new error_1.ParseError({
|
|
121
|
+
path: [this.name],
|
|
122
|
+
code: 'invalid_option',
|
|
123
|
+
message: `Expected option ${this.name}`,
|
|
124
|
+
received: JSON.stringify(argv[0]),
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
argv.shift();
|
|
128
|
+
input = argv.shift();
|
|
129
|
+
const value = this.parse(input, options);
|
|
130
|
+
return { key: this.getOutputName(), value, argv };
|
|
131
|
+
}
|
|
132
|
+
catch (e) {
|
|
133
|
+
if ((0, error_1.isZodError)(e)) {
|
|
134
|
+
throw new error_1.ParseError({
|
|
135
|
+
path: [this.name, ...e.issues[0].path.map((p) => p.toString())],
|
|
136
|
+
code: e.issues[0].code,
|
|
137
|
+
message: e.issues[0].message,
|
|
138
|
+
received: JSON.stringify(input),
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
throw e;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
helpString() {
|
|
145
|
+
const aliases = this.aliases.length ? `|${this.aliases.join('|-')}` : '';
|
|
146
|
+
return `--${this.name}${aliases} ${this.description}`;
|
|
147
|
+
}
|
|
148
|
+
/** Returns true if the flag (including any prefixes) matches the name or aliases */
|
|
149
|
+
isMatch(arg, prefixes) {
|
|
150
|
+
const name = MassargOption.findNameInArg(arg, prefixes);
|
|
151
|
+
return name === this.name || this.aliases.includes(name);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Returns the name of the flag, removing any prefixes. It is discriminate of if the option
|
|
155
|
+
* exists, as it is a static method; it only returns the name of the flag if it matches the
|
|
156
|
+
* prefixes format.
|
|
157
|
+
*/
|
|
158
|
+
static findNameInArg(arg, prefixes) {
|
|
159
|
+
const { optionPrefix, aliasPrefix, negateFlagPrefix, negateAliasPrefix } = prefixes;
|
|
160
|
+
// negate full prefix
|
|
161
|
+
if (arg.startsWith(negateFlagPrefix)) {
|
|
162
|
+
return arg.slice(negateFlagPrefix.length);
|
|
163
|
+
}
|
|
164
|
+
if (arg.startsWith(optionPrefix)) {
|
|
165
|
+
return arg.slice(optionPrefix.length);
|
|
166
|
+
}
|
|
167
|
+
// negate short prefix
|
|
168
|
+
if (arg.startsWith(negateAliasPrefix)) {
|
|
169
|
+
return arg.slice(negateAliasPrefix.length);
|
|
170
|
+
}
|
|
171
|
+
// short prefix
|
|
172
|
+
if (arg.startsWith(aliasPrefix) || arg.startsWith(negateAliasPrefix)) {
|
|
173
|
+
return arg.slice(aliasPrefix.length);
|
|
174
|
+
}
|
|
175
|
+
return '<blank>';
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
exports.MassargOption = MassargOption;
|
|
179
|
+
/**
|
|
180
|
+
* An option that can be passed to a command.
|
|
181
|
+
*
|
|
182
|
+
* This type of option parses a number, and fails if it is not a valid number.
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```ts
|
|
186
|
+
* massarg(options).option({
|
|
187
|
+
* name: 'number',
|
|
188
|
+
* description: 'A number',
|
|
189
|
+
* defaultValue: 0,
|
|
190
|
+
* aliases: ['n'],
|
|
191
|
+
* type: 'number',
|
|
192
|
+
* })
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
class MassargNumber extends MassargOption {
|
|
196
|
+
constructor(options) {
|
|
197
|
+
super({
|
|
198
|
+
...options,
|
|
199
|
+
parse: (value) => Number(value),
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
parseDetails(argv, options, prefixes) {
|
|
203
|
+
try {
|
|
204
|
+
const { argv: _argv, value } = super.parseDetails(argv, options, prefixes);
|
|
205
|
+
if (isNaN(value)) {
|
|
206
|
+
throw new error_1.ParseError({
|
|
207
|
+
path: [this.name],
|
|
208
|
+
code: 'invalid_type',
|
|
209
|
+
message: 'Expected a number',
|
|
210
|
+
received: JSON.stringify(argv[0]),
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
return { key: this.name, value, argv: _argv };
|
|
214
|
+
}
|
|
215
|
+
catch (e) {
|
|
216
|
+
if ((0, error_1.isZodError)(e)) {
|
|
217
|
+
throw new error_1.ParseError({
|
|
218
|
+
path: [this.name, ...e.issues[0].path.map((p) => p.toString())],
|
|
219
|
+
code: e.issues[0].code,
|
|
220
|
+
message: e.issues[0].message,
|
|
221
|
+
received: JSON.stringify(argv[0]),
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
throw e;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
exports.MassargNumber = MassargNumber;
|
|
229
|
+
/**
|
|
230
|
+
* An option that can be passed to a command.
|
|
231
|
+
*
|
|
232
|
+
* A flag is an option that is either present or not. It can be used to toggle
|
|
233
|
+
* a boolean value, or to indicate that a command should be run in a different
|
|
234
|
+
* mode.
|
|
235
|
+
*
|
|
236
|
+
* A flag can be negated by prefixing it with `no-`. For example, `--no-verbose`,
|
|
237
|
+
* or by prefixing the alias with `^` instead of `-`. This is configurable via the command's
|
|
238
|
+
* configuration. To turn this behavior on, set `negatable: true` in the flag's configuration.
|
|
239
|
+
*
|
|
240
|
+
* @example
|
|
241
|
+
* ```ts
|
|
242
|
+
* massarg.flag({
|
|
243
|
+
* name: 'verbose',
|
|
244
|
+
* aliases: ['v'],
|
|
245
|
+
* description: 'Enable verbose logging',
|
|
246
|
+
* defaultValue: false,
|
|
247
|
+
* })
|
|
248
|
+
* ```
|
|
249
|
+
*/
|
|
250
|
+
class MassargFlag extends MassargOption {
|
|
251
|
+
constructor(options) {
|
|
252
|
+
super({
|
|
253
|
+
...options,
|
|
254
|
+
parse: () => true,
|
|
255
|
+
});
|
|
256
|
+
this.negatable = options.negatable ?? false;
|
|
257
|
+
}
|
|
258
|
+
parseDetails(argv, _options, prefixes) {
|
|
259
|
+
try {
|
|
260
|
+
const isNegation = argv[0]?.startsWith(prefixes.negateAliasPrefix) ||
|
|
261
|
+
argv[0]?.startsWith(prefixes.negateFlagPrefix);
|
|
262
|
+
if (!this.negatable && isNegation) {
|
|
263
|
+
throw new error_1.ParseError({
|
|
264
|
+
path: [this.name],
|
|
265
|
+
code: 'invalid_option',
|
|
266
|
+
message: `Option ${this.name} cannot be negated`,
|
|
267
|
+
received: JSON.stringify(argv[0]),
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
if (!this.isMatch(argv[0], prefixes)) {
|
|
271
|
+
throw new error_1.ParseError({
|
|
272
|
+
path: [this.name],
|
|
273
|
+
code: 'invalid_option',
|
|
274
|
+
message: `Expected option ${this.name}`,
|
|
275
|
+
received: JSON.stringify(argv[0]),
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
argv.shift();
|
|
279
|
+
if (isNegation) {
|
|
280
|
+
return { key: this.getOutputName(), value: false, argv };
|
|
281
|
+
}
|
|
282
|
+
return { key: this.getOutputName(), value: true, argv };
|
|
283
|
+
}
|
|
284
|
+
catch (e) {
|
|
285
|
+
if ((0, error_1.isZodError)(e)) {
|
|
286
|
+
throw new error_1.ParseError({
|
|
287
|
+
path: [this.name, ...e.issues[0].path.map((p) => p.toString())],
|
|
288
|
+
code: e.issues[0].code,
|
|
289
|
+
message: e.issues[0].message,
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
throw e;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
exports.MassargFlag = MassargFlag;
|
|
297
|
+
class MassargHelpFlag extends MassargFlag {
|
|
298
|
+
constructor(config = {}) {
|
|
299
|
+
super({
|
|
300
|
+
name: 'help',
|
|
301
|
+
description: 'Show this help message',
|
|
302
|
+
aliases: ['h'],
|
|
303
|
+
...config,
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
exports.MassargHelpFlag = MassargHelpFlag;
|
|
308
|
+
//# sourceMappingURL=option.js.map
|
package/option.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"option.js","sourceRoot":"","sources":["../src/option.ts"],"names":[],"mappings":";;;AAAA,6BAAuB;AACvB,mCAAgD;AAChD,mCAAqC;AAG9B,MAAM,YAAY,GAAG,CAC1B,IAA2B,EAC3B,EAAE,CACF,OAAC,CAAC,MAAM,CAAC;IACP,yBAAyB;IACzB,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;IAChB,8DAA8D;IAC9D,WAAW,EAAE,OAAC,CAAC,MAAM,EAAE;IACvB,kCAAkC;IAClC,YAAY,EAAE,OAAC,CAAC,GAAG,EAAE,C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CAAC,CAAC,CAAC,OAAO;iBAC7B,CAAC,CAAA;aACH;YACD,MAAM,CAAC,CAAA;SACR;IACH,CAAC;CACF;AAjDD,kCAiDC;AAED,MAAa,eAAgB,SAAQ,WAAW;IAC9C,YAAY,SAAwD,EAAE;QACpE,KAAK,CAAC;YACJ,IAAI,EAAE,MAAM;YACZ,WAAW,EAAE,wBAAwB;YACrC,OAAO,EAAE,CAAC,GAAG,CAAC;YACd,GAAG,MAAM;SACV,CAAC,CAAA;IACJ,CAAC;CACF;AATD,0CASC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "massarg",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-pre.10",
|
|
4
4
|
"description": "Flexible, powerful, and simple command/argument parser for CLI applications",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"shell",
|
|
@@ -15,23 +15,30 @@
|
|
|
15
15
|
"author": "Chen Asraf <chenasrafil@gmail.com>",
|
|
16
16
|
"license": "Apache",
|
|
17
17
|
"scripts": {
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
18
|
+
"build": "tsc -p tsconfig.build.json && cp package.json README.md build",
|
|
19
|
+
"dev": "tsc --watch",
|
|
20
|
+
"cmd": "ts-node src/sample.ts",
|
|
21
|
+
"test": "jest",
|
|
22
|
+
"doc": "typedoc",
|
|
23
|
+
"deploy-doc": "pnpm doc && gh-pages -d docs",
|
|
24
|
+
"semantic-release": "semantic-release"
|
|
23
25
|
},
|
|
24
26
|
"devDependencies": {
|
|
25
|
-
"@
|
|
26
|
-
"@
|
|
27
|
-
"@
|
|
28
|
-
"jest": "^
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
27
|
+
"@semantic-release/changelog": "^6.0.3",
|
|
28
|
+
"@semantic-release/exec": "^6.0.3",
|
|
29
|
+
"@semantic-release/git": "^10.0.1",
|
|
30
|
+
"@types/jest": "^29.5.8",
|
|
31
|
+
"@types/node": "^20.9.2",
|
|
32
|
+
"gh-pages": "^6.1.0",
|
|
33
|
+
"jest": "^29.7.0",
|
|
34
|
+
"semantic-release": "^22.0.8",
|
|
35
|
+
"ts-jest": "^29.1.1",
|
|
36
|
+
"ts-node": "^10.9.1",
|
|
37
|
+
"typedoc": "^0.25.3",
|
|
38
|
+
"typedoc-plugin-zod": "^1.1.0",
|
|
39
|
+
"typescript": "^5.2.2"
|
|
32
40
|
},
|
|
33
41
|
"dependencies": {
|
|
34
|
-
"
|
|
35
|
-
"lodash": "^4.17.21"
|
|
42
|
+
"zod": "^3.22.4"
|
|
36
43
|
}
|
|
37
44
|
}
|
package/style.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
export { strConcat, indent } from './utils';
|
|
3
|
+
export declare const ansiStyles: {
|
|
4
|
+
reset: string;
|
|
5
|
+
bold: string;
|
|
6
|
+
underline: string;
|
|
7
|
+
black: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const ansiColors: {
|
|
10
|
+
red: string;
|
|
11
|
+
green: string;
|
|
12
|
+
yellow: string;
|
|
13
|
+
blue: string;
|
|
14
|
+
magenta: string;
|
|
15
|
+
cyan: string;
|
|
16
|
+
white: string;
|
|
17
|
+
gray: string;
|
|
18
|
+
grey: string;
|
|
19
|
+
brightRed: string;
|
|
20
|
+
brightGreen: string;
|
|
21
|
+
brightYellow: string;
|
|
22
|
+
brightBlue: string;
|
|
23
|
+
brightMagenta: string;
|
|
24
|
+
brightCyan: string;
|
|
25
|
+
brightWhite: string;
|
|
26
|
+
};
|
|
27
|
+
export declare const StringStyle: z.ZodObject<{
|
|
28
|
+
bold: z.ZodOptional<z.ZodBoolean>;
|
|
29
|
+
underline: z.ZodOptional<z.ZodBoolean>;
|
|
30
|
+
color: z.ZodOptional<z.ZodEnum<["red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white" | "gray" | "grey" | "brightRed" | "brightGreen" | "brightYellow" | "brightBlue" | "brightMagenta" | "brightCyan" | "brightWhite", ...("red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white" | "gray" | "grey" | "brightRed" | "brightGreen" | "brightYellow" | "brightBlue" | "brightMagenta" | "brightCyan" | "brightWhite")[]]>>;
|
|
31
|
+
reset: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
32
|
+
}, "strip", z.ZodTypeAny, {
|
|
33
|
+
bold?: boolean | undefined;
|
|
34
|
+
underline?: boolean | undefined;
|
|
35
|
+
color?: "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white" | "gray" | "grey" | "brightRed" | "brightGreen" | "brightYellow" | "brightBlue" | "brightMagenta" | "brightCyan" | "brightWhite" | undefined;
|
|
36
|
+
reset?: boolean | undefined;
|
|
37
|
+
}, {
|
|
38
|
+
bold?: boolean | undefined;
|
|
39
|
+
underline?: boolean | undefined;
|
|
40
|
+
color?: "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white" | "gray" | "grey" | "brightRed" | "brightGreen" | "brightYellow" | "brightBlue" | "brightMagenta" | "brightCyan" | "brightWhite" | undefined;
|
|
41
|
+
reset?: boolean | undefined;
|
|
42
|
+
}>;
|
|
43
|
+
export type StringStyle = z.infer<typeof StringStyle>;
|
|
44
|
+
export declare function format(string: string, style?: StringStyle): string;
|
|
45
|
+
export declare function stripStyle(string: string): string;
|
|
46
|
+
//# sourceMappingURL=style.d.ts.map
|
package/style.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../src/style.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAA;AAEnB,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAE3C,eAAO,MAAM,UAAU;;;;;CAKtB,CAAA;AAED,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;CAiBtB,CAAA;AAED,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;EAKtB,CAAA;AAEF,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAA;AAErD,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,GAAE,WAAgB,GAAG,MAAM,CAOtE;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEjD"}
|
package/style.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.stripStyle = exports.format = exports.StringStyle = exports.ansiColors = exports.ansiStyles = exports.indent = exports.strConcat = void 0;
|
|
7
|
+
const zod_1 = __importDefault(require("zod"));
|
|
8
|
+
const utils_1 = require("./utils");
|
|
9
|
+
var utils_2 = require("./utils");
|
|
10
|
+
Object.defineProperty(exports, "strConcat", { enumerable: true, get: function () { return utils_2.strConcat; } });
|
|
11
|
+
Object.defineProperty(exports, "indent", { enumerable: true, get: function () { return utils_2.indent; } });
|
|
12
|
+
exports.ansiStyles = {
|
|
13
|
+
reset: '\x1b[0m',
|
|
14
|
+
bold: '\x1b[1m',
|
|
15
|
+
underline: '\x1b[4m',
|
|
16
|
+
black: '\x1b[30m',
|
|
17
|
+
};
|
|
18
|
+
exports.ansiColors = {
|
|
19
|
+
red: '\x1b[31m',
|
|
20
|
+
green: '\x1b[32m',
|
|
21
|
+
yellow: '\x1b[33m',
|
|
22
|
+
blue: '\x1b[34m',
|
|
23
|
+
magenta: '\x1b[35m',
|
|
24
|
+
cyan: '\x1b[36m',
|
|
25
|
+
white: '\x1b[37m',
|
|
26
|
+
gray: '\x1b[90m',
|
|
27
|
+
grey: '\x1b[90m',
|
|
28
|
+
brightRed: '\x1b[91m',
|
|
29
|
+
brightGreen: '\x1b[92m',
|
|
30
|
+
brightYellow: '\x1b[93m',
|
|
31
|
+
brightBlue: '\x1b[94m',
|
|
32
|
+
brightMagenta: '\x1b[95m',
|
|
33
|
+
brightCyan: '\x1b[96m',
|
|
34
|
+
brightWhite: '\x1b[97m',
|
|
35
|
+
};
|
|
36
|
+
exports.StringStyle = zod_1.default.object({
|
|
37
|
+
bold: zod_1.default.boolean().optional(),
|
|
38
|
+
underline: zod_1.default.boolean().optional(),
|
|
39
|
+
color: (0, utils_1.zodEnumFromObjKeys)(exports.ansiColors).optional(),
|
|
40
|
+
reset: zod_1.default.boolean().default(true).optional(),
|
|
41
|
+
});
|
|
42
|
+
function format(string, style = {}) {
|
|
43
|
+
const { color, bold, underline, reset = true } = style;
|
|
44
|
+
const colorCode = color ? exports.ansiColors[color] : '';
|
|
45
|
+
const boldCode = bold ? exports.ansiStyles.bold : '';
|
|
46
|
+
const underlineCode = underline ? exports.ansiStyles.underline : '';
|
|
47
|
+
const resetCode = reset ? exports.ansiStyles.reset : '';
|
|
48
|
+
return `${colorCode}${boldCode}${underlineCode}${string}${resetCode}`;
|
|
49
|
+
}
|
|
50
|
+
exports.format = format;
|
|
51
|
+
function stripStyle(string) {
|
|
52
|
+
return string.replace(/\x1b\[\d+m/gi, '');
|
|
53
|
+
}
|
|
54
|
+
exports.stripStyle = stripStyle;
|
|
55
|
+
//# sourceMappingURL=style.js.map
|
package/style.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"style.js","sourceRoot":"","sources":["../src/style.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAmB;AACnB,mCAA4C;AAC5C,iCAA2C;AAAlC,kGAAA,SAAS,OAAA;AAAE,+FAAA,MAAM,OAAA;AAEb,QAAA,UAAU,GAAG;IACxB,KAAK,EAAE,SAAS;IAChB,IAAI,EAAE,SAAS;IACf,SAAS,EAAE,SAAS;IACpB,KAAK,EAAE,UAA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AAA;IAC3D,MAAM,SAAS,GAAG,KAAK,CAAC,CAAC,CAAC,kBAAU,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAA;IAC/C,OAAO,GAAG,SAAS,GAAG,QAAQ,GAAG,aAAa,GAAG,MAAM,GAAG,SAAS,EAAE,CAAA;AACvE,CAAC;AAPD,wBAOC;AAED,SAAgB,UAAU,CAAC,MAAc;IACvC,OAAO,MAAM,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,CAAA;AAC3C,CAAC;AAFD,gCAEC"}
|
package/utils.d.ts
CHANGED
|
@@ -1,14 +1,36 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
export declare function
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
/** @internal */
|
|
3
|
+
export declare function setOrPush<T>(newValue: unknown, currentValue: T[] | T | undefined, isArray: boolean): T;
|
|
4
|
+
type Parseable = string | number | boolean | null | undefined | Record<string, unknown>;
|
|
5
|
+
/** A type that makes all properties of an object required, recursively. */
|
|
6
|
+
export type DeepRequired<T> = {
|
|
7
|
+
[P in keyof T]-?: T[P] extends object ? DeepRequired<T[P]> : NonNullable<T[P]>;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Concatenates strings, arrays of strings, and objects with truthy values.
|
|
11
|
+
*
|
|
12
|
+
* It works recursively, so adding an array of strings to an array of strings will work.
|
|
13
|
+
*
|
|
14
|
+
* Falsy values are ignored, so pasing `undefined` or `null` will not add anything to the result,
|
|
15
|
+
* and using a boolean will only add it if it is `true`. Using 0 will also not add anything.
|
|
16
|
+
*/
|
|
17
|
+
export declare function strConcat(...strs: (Parseable | Parseable[])[]): string;
|
|
18
|
+
/**
|
|
19
|
+
* Indents a string or an array of strings. Concatenates them all using `strConcat`.
|
|
20
|
+
*/
|
|
21
|
+
export declare function indent(str: Parseable | Parseable[], indent?: number): string;
|
|
22
|
+
/** @internal */
|
|
23
|
+
export declare function zodEnumFromObjKeys<K extends string>(obj: Record<K, any>): z.ZodEnum<[K, ...K[]]>;
|
|
24
|
+
/** @internal */
|
|
25
|
+
export declare function deepMerge<T1, T2>(obj1: T1, obj2: T2): NonNullable<T1> & NonNullable<T2>;
|
|
26
|
+
export declare function capitalize(str: string): string;
|
|
27
|
+
/**
|
|
28
|
+
* Splits a name into words, using camelCase, PascalCase, snake_case, and kebab-case or
|
|
29
|
+
* regular spaced strings.
|
|
30
|
+
*/
|
|
31
|
+
export declare function splitWords(str: string): string[];
|
|
32
|
+
export declare function toCamelCase(str: string): string;
|
|
33
|
+
export declare function toPascalCase(str: string): string;
|
|
34
|
+
export declare function getErrorMessage(err: unknown): string;
|
|
35
|
+
export {};
|
|
14
36
|
//# sourceMappingURL=utils.d.ts.map
|
package/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAA;AAGnB,gBAAgB;AAChB,wBAAgB,SAAS,CAAC,CAAC,EACzB,QAAQ,EAAE,OAAO,EACjB,YAAY,EAAE,CAAC,EAAE,GAAG,CAAC,GAAG,SAAS,EACjC,OAAO,EAAE,OAAO,GACf,CAAC,CAKH;AACD,KAAK,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAEvF,2EAA2E;AAC3E,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI;KAC3B,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,C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