zod-args-parser 1.0.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 +215 -0
- package/lib/commonjs/help.js +1 -0
- package/lib/commonjs/help.js.map +1 -0
- package/lib/commonjs/index.js +1 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/parser.js +1 -0
- package/lib/commonjs/parser.js.map +1 -0
- package/lib/commonjs/types.js +1 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/commonjs/utils.js +1 -0
- package/lib/commonjs/utils.js.map +1 -0
- package/lib/module/help.js +1 -0
- package/lib/module/help.js.map +1 -0
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/parser.js +1 -0
- package/lib/module/parser.js.map +1 -0
- package/lib/module/types.js +1 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/utils.js +1 -0
- package/lib/module/utils.js.map +1 -0
- package/lib/typescript/help.d.ts +9 -0
- package/lib/typescript/help.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +8 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/parser.d.ts +6 -0
- package/lib/typescript/parser.d.ts.map +1 -0
- package/lib/typescript/types.d.ts +256 -0
- package/lib/typescript/types.d.ts.map +1 -0
- package/lib/typescript/utils.d.ts +38 -0
- package/lib/typescript/utils.d.ts.map +1 -0
- package/package.json +50 -0
- package/src/help.ts +340 -0
- package/src/index.ts +22 -0
- package/src/parser.ts +299 -0
- package/src/types.ts +286 -0
- package/src/utils.ts +154 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
|
|
3
|
+
export type Subcommand = {
|
|
4
|
+
/**
|
|
5
|
+
* - The subcommand name, use `kebab-case`.
|
|
6
|
+
* - Make sure to not duplicate commands and aliases.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* name: "test";
|
|
10
|
+
* name: "run-app";
|
|
11
|
+
*/
|
|
12
|
+
name: string;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* - The action is executed with the result of the parsed arguments.
|
|
16
|
+
* - To get typescript types use `setAction` instead of this.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* const helpCommand = createSubcommand({ name: "help", options: [...] });
|
|
20
|
+
* helpCommand.setAction(res => console.log(res));
|
|
21
|
+
*/
|
|
22
|
+
action?: (results?: any) => void;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* - The description of the subcommand.
|
|
26
|
+
* - Used for generating the help message.
|
|
27
|
+
*/
|
|
28
|
+
description?: string;
|
|
29
|
+
|
|
30
|
+
/** - Used for generating the help message. */
|
|
31
|
+
placeholder?: string;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* - Provide an example to show to the user.
|
|
35
|
+
* - Used for generating the help message.
|
|
36
|
+
*/
|
|
37
|
+
example?: string;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* - The aliases of the subcommand.
|
|
41
|
+
* - Make sure to not duplicate aliases and commands.
|
|
42
|
+
*/
|
|
43
|
+
aliases?: string[];
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* - Allows positional arguments for this subcommand.
|
|
47
|
+
* - Unlike `arguments`, which are strictly typed, positional arguments are untyped and represented as a string array of
|
|
48
|
+
* variable length.
|
|
49
|
+
* - When enabled and `arguments` are provided, `arguments` will be parsed first. Any remaining arguments will be
|
|
50
|
+
* considered positional arguments and added to the `positional` property in the result.
|
|
51
|
+
*/
|
|
52
|
+
allowPositional?: boolean;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* - The options of the command.
|
|
56
|
+
* - Those options are specific to this subcommand.
|
|
57
|
+
*/
|
|
58
|
+
options?: [Option, ...Option[]];
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* - Specifies a list of strictly typed arguments.
|
|
62
|
+
* - The order is important; for example, the first argument will be validated against the first specified type.
|
|
63
|
+
* - It is recommended to not use optional arguments as the parser will fill the arguments by order and can't determine
|
|
64
|
+
* which arguments are optional.
|
|
65
|
+
*/
|
|
66
|
+
arguments?: [Argument, ...Argument[]];
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export type Cli = Prettify<
|
|
70
|
+
Omit<Subcommand, "name"> & {
|
|
71
|
+
/** - The name of the CLI program. */
|
|
72
|
+
cliName: string;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* - The usage of the CLI program.
|
|
76
|
+
* - Used for generating the help message.
|
|
77
|
+
*/
|
|
78
|
+
usage?: string;
|
|
79
|
+
}
|
|
80
|
+
>;
|
|
81
|
+
|
|
82
|
+
export type Option = {
|
|
83
|
+
/**
|
|
84
|
+
* - The name of the option, use `CamelCase`.
|
|
85
|
+
* - For example: the syntax for the option `rootPath` is `--root-path`.
|
|
86
|
+
*/
|
|
87
|
+
name: string;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* - The will be used to validate the user input.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* type: z.boolean().default(false);
|
|
94
|
+
* type: z.coerce.number(); // will be coerced to number by Zod
|
|
95
|
+
* type: z.preprocess(parseStringToArrFn, z.array(z.coerce.number())); // array of numbers
|
|
96
|
+
*
|
|
97
|
+
* @see https://zod.dev/?id=types
|
|
98
|
+
*/
|
|
99
|
+
type: z.ZodTypeAny;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* - The description of the option.
|
|
103
|
+
* - Used for generating the help message.
|
|
104
|
+
*/
|
|
105
|
+
description?: string;
|
|
106
|
+
|
|
107
|
+
/** - Used for generating the help message. */
|
|
108
|
+
placeholder?: string;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* - The example of using the option.
|
|
112
|
+
* - Used for generating the help message.
|
|
113
|
+
*/
|
|
114
|
+
example?: string;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* - The aliases of the option, use `CamelCase`.
|
|
118
|
+
* - Here you can specify short names or flags.
|
|
119
|
+
* - Make sure to not duplicate aliases.
|
|
120
|
+
*/
|
|
121
|
+
aliases?: [string, ...string[]];
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
export type Argument = {
|
|
125
|
+
/** - The name of the argument. */
|
|
126
|
+
name: string;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* - The will be used to validate the user input.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* type: z.boolean();
|
|
133
|
+
* type: z.coerce.number(); // will be coerced to number by Zod
|
|
134
|
+
* type: z.preprocess(ParseStringToArrFn, z.array(z.coerce.number())); // array of numbers
|
|
135
|
+
*
|
|
136
|
+
* @see https://zod.dev/?id=types
|
|
137
|
+
*/
|
|
138
|
+
type: z.ZodTypeAny;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* - The description of the argument.
|
|
142
|
+
* - Used for generating the help message.
|
|
143
|
+
*/
|
|
144
|
+
description?: string;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* - The example of using the argument.
|
|
148
|
+
* - Used for generating the help message.
|
|
149
|
+
*/
|
|
150
|
+
example?: string;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
export type ColorFnType = (...text: unknown[]) => string;
|
|
154
|
+
|
|
155
|
+
export type PrintHelpOpt = {
|
|
156
|
+
/**
|
|
157
|
+
* - **Optional** `boolean`
|
|
158
|
+
* - Whether to print colors or not.
|
|
159
|
+
* - Default: `true`
|
|
160
|
+
*/
|
|
161
|
+
colors?: boolean;
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* - **Optional** `object`
|
|
165
|
+
* - The colors to use for the help message.
|
|
166
|
+
*/
|
|
167
|
+
customColors?: {
|
|
168
|
+
title?: ColorFnType;
|
|
169
|
+
description?: ColorFnType;
|
|
170
|
+
default?: ColorFnType;
|
|
171
|
+
optional?: ColorFnType;
|
|
172
|
+
exampleTitle?: ColorFnType;
|
|
173
|
+
example?: ColorFnType;
|
|
174
|
+
command?: ColorFnType;
|
|
175
|
+
option?: ColorFnType;
|
|
176
|
+
argument?: ColorFnType;
|
|
177
|
+
placeholder?: ColorFnType;
|
|
178
|
+
punctuation?: ColorFnType;
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
export type _Info = {
|
|
183
|
+
/**
|
|
184
|
+
* - The raw argument as it was passed in
|
|
185
|
+
* - For options that have a default value and are not passed in, the raw argument will be `undefined`
|
|
186
|
+
*/
|
|
187
|
+
rawArg?: string;
|
|
188
|
+
/**
|
|
189
|
+
* - The raw value of the argument as it was passed in
|
|
190
|
+
* - It will be empty string for `boolean` options. E.g. `--help` or `-h`
|
|
191
|
+
* - For options that have a default value and are not passed in, the raw value will be `undefined`
|
|
192
|
+
*/
|
|
193
|
+
rawValue?: string;
|
|
194
|
+
/**
|
|
195
|
+
* - The source value of the argument:
|
|
196
|
+
* - `cli`: The argument was passed in by the user
|
|
197
|
+
* - `default`: The argument was not passed in and has a default value
|
|
198
|
+
*/
|
|
199
|
+
source: "cli" | "default";
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* - Infer the options type from a subcommand.
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* const subcommand = createSubcommand({ name: "build", options: [...] });
|
|
207
|
+
* type OptionsType = InferOptionsType<typeof subcommand>;
|
|
208
|
+
*/
|
|
209
|
+
export type InferOptionsType<T extends Partial<Subcommand>> = T["options"] extends infer U extends Option[]
|
|
210
|
+
? ToOptional<{ [K in U[number]["name"]]: z.infer<Extract<U[number], { name: K }>["type"]> }>
|
|
211
|
+
: undefined;
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* - Infer the arguments type from a subcommand.
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* const subcommand = createSubcommand({ name: "build", arguments: [...] });
|
|
218
|
+
* type ArgumentsType = InferArgumentsType<typeof subcommand>;
|
|
219
|
+
*/
|
|
220
|
+
export type InferArgumentsType<T extends Partial<Subcommand>> = T["arguments"] extends infer U extends Argument[]
|
|
221
|
+
? { [K in keyof U]: U[K] extends { type: z.ZodTypeAny } ? z.infer<U[K]["type"]> : never }
|
|
222
|
+
: undefined;
|
|
223
|
+
|
|
224
|
+
/** `{ some props } & { other props }` => `{ some props, other props }` */
|
|
225
|
+
export type Prettify<T> = { [K in keyof T]: T[K] } & {};
|
|
226
|
+
|
|
227
|
+
/** Allow string type for literal union and get auto completion */
|
|
228
|
+
export type LiteralUnion<T extends string> = T | (string & {});
|
|
229
|
+
|
|
230
|
+
/** Extract the undefined properties from an object */
|
|
231
|
+
type UndefinedProperties<T> = { [P in keyof T]-?: undefined extends T[P] ? P : never }[keyof T];
|
|
232
|
+
|
|
233
|
+
/** Make undefined properties optional? */
|
|
234
|
+
type ToOptional<T> = Prettify<
|
|
235
|
+
Partial<Pick<T, UndefinedProperties<T>>> & Pick<T, Exclude<keyof T, UndefinedProperties<T>>>
|
|
236
|
+
>;
|
|
237
|
+
|
|
238
|
+
export type OptionsArr2RecordType<T extends Option[] | undefined> = T extends Option[]
|
|
239
|
+
? ToOptional<{ [K in T[number]["name"]]: z.infer<Extract<T[number], { name: K }>["type"]> }>
|
|
240
|
+
: object;
|
|
241
|
+
|
|
242
|
+
export type ArgumentsArr2ArrType<T extends Argument[] | undefined> = T extends Argument[]
|
|
243
|
+
? { arguments: { [K in keyof T]: T[K] extends { type: z.ZodTypeAny } ? z.infer<T[K]["type"]> : never } }
|
|
244
|
+
: object;
|
|
245
|
+
|
|
246
|
+
export type Positional<S extends Partial<Subcommand>> = S["allowPositional"] extends true ? { positional: string[] } : object;
|
|
247
|
+
|
|
248
|
+
export type Info<T extends Option[] | undefined> = T extends Option[]
|
|
249
|
+
? {
|
|
250
|
+
_info: ToOptional<{
|
|
251
|
+
[K in T[number]["name"]]: Extract<T[number], { name: K }> extends infer U extends Option
|
|
252
|
+
? undefined extends z.infer<U["type"]>
|
|
253
|
+
? undefined | Prettify<_Info & U> // if optional add undefined
|
|
254
|
+
: Prettify<_Info & U>
|
|
255
|
+
: never;
|
|
256
|
+
}>;
|
|
257
|
+
}
|
|
258
|
+
: object;
|
|
259
|
+
|
|
260
|
+
export type NoSubcommand = { name: undefined };
|
|
261
|
+
|
|
262
|
+
export type ParseResult<S extends Partial<Subcommand>[]> = {
|
|
263
|
+
[K in keyof S]: Prettify<
|
|
264
|
+
{ subcommand: S[K]["name"] } & Positional<S[K]> &
|
|
265
|
+
Info<S[K]["options"]> &
|
|
266
|
+
OptionsArr2RecordType<S[K]["options"]> &
|
|
267
|
+
ArgumentsArr2ArrType<S[K]["arguments"]>
|
|
268
|
+
>;
|
|
269
|
+
}[number];
|
|
270
|
+
|
|
271
|
+
export type PrintMethods<N extends Subcommand["name"] | undefined> = {
|
|
272
|
+
printCliHelp: (options?: PrintHelpOpt) => void;
|
|
273
|
+
printSubcommandHelp: (subcommand: LiteralUnion<NonNullable<N>>, options?: PrintHelpOpt) => void;
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
export type UnSafeParseResult<S extends Partial<Subcommand>[]> = Prettify<
|
|
277
|
+
ParseResult<S> & PrintMethods<S[number]["name"]>
|
|
278
|
+
>;
|
|
279
|
+
|
|
280
|
+
export type SafeParseResult<S extends Partial<Subcommand>[]> = Prettify<
|
|
281
|
+
({ success: false; error: Error } | { success: true; data: ParseResult<S> }) & PrintMethods<S[number]["name"]>
|
|
282
|
+
>;
|
|
283
|
+
|
|
284
|
+
export type ActionFn<T extends Subcommand | Cli> = {
|
|
285
|
+
setAction: (actions: (res: UnSafeParseResult<[T]>) => void) => void;
|
|
286
|
+
};
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import assert from "node:assert";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @param name - Should start with `'--'`
|
|
6
|
+
* @returns - The transformed name E.g. `--input-dir` -> `InputDir`
|
|
7
|
+
*/
|
|
8
|
+
export function transformArg(name: string): string {
|
|
9
|
+
assert(name.startsWith("-"), `[transformArg] Invalid arg name: ${name}`);
|
|
10
|
+
name = name.startsWith("--") ? name.substring(2) : name.substring(1);
|
|
11
|
+
return name.replace(/-([a-z])/g, g => g[1].toUpperCase());
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** - Reverse of `transformArg`. E.g. `InputDir` -> `--input-dir` , `i` -> `-i` */
|
|
15
|
+
export function transformOptionToArg(name: string): string {
|
|
16
|
+
name = name.replace(/^[A-Z]/g, g => g.toLowerCase()); // first letter always lower case
|
|
17
|
+
if (name.length === 1) return `-${name}`;
|
|
18
|
+
return `--${name.replace(/[A-Z]/g, g => "-" + g.toLowerCase())}`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** - Check if an arg string is a short arg. E.g. `-i` -> `true` */
|
|
22
|
+
export function isFlagArg(name: string): boolean {
|
|
23
|
+
return /^-[a-z]$/.test(name);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** - Check if an arg string is an options arg. E.g. `--input-dir` -> `true` , `-i` -> `true` */
|
|
27
|
+
export function isOptionArg(name: string | boolean): boolean {
|
|
28
|
+
if (typeof name !== "string") return false;
|
|
29
|
+
return isFlagArg(name) || name.startsWith("--");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* - Transform option name to no name. E.g. `include` -> `noInclude`
|
|
34
|
+
* - For short name like `-i` it will be ignored
|
|
35
|
+
*/
|
|
36
|
+
export function noName(name: string): string {
|
|
37
|
+
if (name.length === 1) return name;
|
|
38
|
+
return "no" + name.replace(/^[a-z]/, g => g.toUpperCase());
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** - Convert string to boolean. E.g. `"true"` -> `true` , `"false"` -> `false` */
|
|
42
|
+
export function stringToBoolean(str: string): boolean {
|
|
43
|
+
if (str.toLowerCase() === "true") return true;
|
|
44
|
+
if (str.toLowerCase() === "false") return false;
|
|
45
|
+
throw new Error(`[stringToBoolean] Invalid boolean value: "${str}"; Expected "true" or "false"`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function getOrdinalPlacement(index: number): string {
|
|
49
|
+
if (index < 0) return "";
|
|
50
|
+
|
|
51
|
+
const suffixes = ["th", "st", "nd", "rd"];
|
|
52
|
+
const lastDigit = index % 10;
|
|
53
|
+
const lastTwoDigits = index % 100;
|
|
54
|
+
|
|
55
|
+
const suffix =
|
|
56
|
+
lastDigit === 1 && lastTwoDigits !== 11
|
|
57
|
+
? suffixes[1]
|
|
58
|
+
: lastDigit === 2 && lastTwoDigits !== 12
|
|
59
|
+
? suffixes[2]
|
|
60
|
+
: lastDigit === 3 && lastTwoDigits !== 13
|
|
61
|
+
? suffixes[3]
|
|
62
|
+
: suffixes[0];
|
|
63
|
+
|
|
64
|
+
return `${index + 1}${suffix}`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** - Check if a schema is a boolean */
|
|
68
|
+
export function isBooleanSchema(schema: z.ZodTypeAny): boolean {
|
|
69
|
+
let type = schema;
|
|
70
|
+
while (type) {
|
|
71
|
+
if (type instanceof z.ZodBoolean) {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (type instanceof z.ZodLiteral) {
|
|
76
|
+
return type.value === true || type.value === false;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
type = type._def.innerType;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function getDefaultValueFromSchema(schema: z.ZodTypeAny): unknown | undefined {
|
|
86
|
+
let type = schema;
|
|
87
|
+
while (type) {
|
|
88
|
+
if (type instanceof z.ZodDefault) {
|
|
89
|
+
const defaultValue = type._def.defaultValue();
|
|
90
|
+
return defaultValue;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
type = type._def.innerType;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** - Decouple flags E.g. `-rf` -> `-r, -f` */
|
|
100
|
+
export function decoupleFlags(args: string[]): string[] {
|
|
101
|
+
const flagsRe = /^-[a-z]{2,}$/i;
|
|
102
|
+
|
|
103
|
+
const result = [];
|
|
104
|
+
for (let i = 0; i < args.length; i++) {
|
|
105
|
+
const arg = args[i];
|
|
106
|
+
const isCoupled = flagsRe.test(arg);
|
|
107
|
+
|
|
108
|
+
if (!isCoupled) {
|
|
109
|
+
result.push(arg);
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const decoupledArr = arg
|
|
114
|
+
.substring(1)
|
|
115
|
+
.split("")
|
|
116
|
+
.map(c => "-" + c);
|
|
117
|
+
|
|
118
|
+
result.push(...decoupledArr);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return result;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Print */
|
|
125
|
+
export function print(...messages: string[]) {
|
|
126
|
+
return process.stdout.write(messages.join(" "));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Print line */
|
|
130
|
+
export function println(...messages: string[]) {
|
|
131
|
+
messages = messages.filter(Boolean);
|
|
132
|
+
return console.log(...messages);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** New line */
|
|
136
|
+
export function ln(count: number) {
|
|
137
|
+
return "\n".repeat(count);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** Space */
|
|
141
|
+
export function indent(count: number) {
|
|
142
|
+
return " ".repeat(count);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** Add indent before each new line */
|
|
146
|
+
export function addIndentLn(message: string, indent: string = "") {
|
|
147
|
+
return message.replace(/\n/g, `\n${indent}`);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Concat strings */
|
|
151
|
+
export function concat(...messages: string[]) {
|
|
152
|
+
messages = messages.filter(Boolean);
|
|
153
|
+
return messages.join(" ");
|
|
154
|
+
}
|