@rtorcato/js-common 1.8.0 ā 2.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/CHANGELOG.md +25 -0
- package/README.md +59 -85
- package/dist/arrays/index.js +1 -1
- package/dist/boolean/index.js +1 -1
- package/dist/chunks/chunk-6J7HIWG6.js +1 -0
- package/dist/chunks/chunk-FBDKWWIQ.js +3 -0
- package/dist/cli/cli.mjs +439 -0
- package/dist/cli/index.mjs +22 -436
- package/dist/env/index.js +1 -3
- package/dist/errors/index.js +1 -1
- package/dist/index.js +0 -1
- package/dist/logger/index.js +1 -0
- package/dist/logger/logger.js +1 -0
- package/dist/logging/index.js +1 -1
- package/dist/math/index.js +1 -1
- package/dist/validation/index.js +1 -1
- package/package.json +14 -24
- package/dist/chunks/chunk-DCFILRIS.js +0 -1
- package/dist/helloworld/index.js +0 -1
- package/dist/logging/index1.js +0 -1
- package/dist/math/math.js +0 -1
package/dist/cli/index.mjs
CHANGED
|
@@ -1,440 +1,26 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import
|
|
10
|
-
import { fileURLToPath } from 'node:url';
|
|
11
|
-
// Get current directory
|
|
12
|
-
const currentDir = dirname(fileURLToPath(import.meta.url));
|
|
13
|
-
// Get package version
|
|
14
|
-
const packageJson = JSON.parse(readFileSync(resolve(currentDir, '../../package.json'), 'utf-8'));
|
|
15
|
-
program
|
|
16
|
-
.name('js-common')
|
|
17
|
-
.description(chalk.cyan('⨠CLI utilities from @rtorcato/js-common'))
|
|
18
|
-
.version(packageJson.version);
|
|
19
|
-
// Function categories for list and interactive mode
|
|
20
|
-
const functionCategories = {
|
|
21
|
-
date: {
|
|
22
|
-
name: 'š
Date & Time',
|
|
23
|
-
functions: [
|
|
24
|
-
{ name: 'today', description: "Get today's date (YYYY-MM-DD)" },
|
|
25
|
-
{ name: 'now', description: 'Get current timestamp' },
|
|
26
|
-
{ name: 'between', description: 'Calculate days between dates' },
|
|
27
|
-
],
|
|
28
|
-
},
|
|
29
|
-
math: {
|
|
30
|
-
name: 'š¢ Mathematical',
|
|
31
|
-
functions: [
|
|
32
|
-
{ name: 'sum', description: 'Calculate sum of numbers' },
|
|
33
|
-
{ name: 'avg', description: 'Calculate average of numbers' },
|
|
34
|
-
{ name: 'random', description: 'Generate random number' },
|
|
35
|
-
{ name: 'round', description: 'Round to decimal places' },
|
|
36
|
-
{ name: 'clamp', description: 'Clamp between min/max' },
|
|
37
|
-
],
|
|
38
|
-
},
|
|
39
|
-
text: {
|
|
40
|
-
name: 'š Text Formatting',
|
|
41
|
-
functions: [
|
|
42
|
-
{ name: 'capitalize', description: 'Capitalize first letter' },
|
|
43
|
-
{ name: 'title', description: 'Convert to title case' },
|
|
44
|
-
{ name: 'pad', description: 'Pad with leading zeros' },
|
|
45
|
-
],
|
|
46
|
-
},
|
|
47
|
-
file: {
|
|
48
|
-
name: 'š File Operations',
|
|
49
|
-
functions: [
|
|
50
|
-
{ name: 'exists', description: 'Check if file exists' },
|
|
51
|
-
{ name: 'ext', description: 'Get file extension' },
|
|
52
|
-
],
|
|
53
|
-
},
|
|
54
|
-
security: {
|
|
55
|
-
name: 'š Security',
|
|
56
|
-
functions: [
|
|
57
|
-
{ name: 'password', description: 'Check password strength' },
|
|
58
|
-
{ name: 'token', description: 'Generate secure token' },
|
|
59
|
-
],
|
|
60
|
-
},
|
|
61
|
-
validate: {
|
|
62
|
-
name: 'ā
Validation',
|
|
63
|
-
functions: [{ name: 'url', description: 'Validate URL format' }],
|
|
64
|
-
},
|
|
65
|
-
system: {
|
|
66
|
-
name: 'š» System Info',
|
|
67
|
-
functions: [
|
|
68
|
-
{ name: 'pid', description: 'Get process ID' },
|
|
69
|
-
{ name: 'uptime', description: 'Get process uptime' },
|
|
70
|
-
{ name: 'ci', description: 'Check CI environment' },
|
|
71
|
-
{ name: 'node-version', description: 'Get Node.js version' },
|
|
72
|
-
],
|
|
73
|
-
},
|
|
74
|
-
};
|
|
75
|
-
// List all functions - add as a separate command
|
|
76
|
-
program
|
|
77
|
-
.command('list')
|
|
78
|
-
.alias('ls')
|
|
79
|
-
.description('š List all available functions')
|
|
80
|
-
.action(() => {
|
|
81
|
-
console.log(chalk.cyan('\n⨠Available Functions:\n'));
|
|
82
|
-
Object.entries(functionCategories).forEach(([key, category]) => {
|
|
83
|
-
console.log(chalk.bold(category.name));
|
|
84
|
-
console.log(); // Add space after category header
|
|
85
|
-
category.functions.forEach((func) => {
|
|
86
|
-
console.log(chalk.gray(` js-common ${key} ${func.name}`) + chalk.dim(` - ${func.description}`));
|
|
87
|
-
});
|
|
88
|
-
console.log(); // Add space after function list
|
|
89
|
-
});
|
|
90
|
-
console.log(chalk.yellow('š” Use ') +
|
|
91
|
-
chalk.green('js-common add') +
|
|
92
|
-
chalk.yellow(' to integrate functions into your project'));
|
|
93
|
-
console.log(chalk.yellow('š” Use ') +
|
|
94
|
-
chalk.green('js-common interactive') +
|
|
95
|
-
chalk.yellow(' for interactive mode'));
|
|
96
|
-
console.log(chalk.yellow('š” Use ') +
|
|
97
|
-
chalk.green('js-common <command> --help') +
|
|
98
|
-
chalk.yellow(' for detailed help\n'));
|
|
99
|
-
});
|
|
100
|
-
// Also add as an option for compatibility
|
|
101
|
-
program.option('-l, --list', 'List all available functions');
|
|
102
|
-
// Interactive mode
|
|
103
|
-
program
|
|
104
|
-
.command('interactive')
|
|
105
|
-
.alias('i')
|
|
106
|
-
.description('š® Interactive mode with guided prompts')
|
|
107
|
-
.action(async () => {
|
|
108
|
-
// Welcome animation
|
|
109
|
-
const title = figlet.textSync('JS Common', { font: 'Small' });
|
|
110
|
-
console.log(gradient.pastel.multiline(title));
|
|
111
|
-
const rainbow = chalkAnimation.rainbow('\n⨠Welcome to JS Common Interactive Mode! āØ\n');
|
|
112
|
-
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
113
|
-
rainbow.stop();
|
|
114
|
-
try {
|
|
115
|
-
// Main interactive loop
|
|
116
|
-
while (true) {
|
|
117
|
-
const category = await select({
|
|
118
|
-
message: chalk.cyan('What would you like to do?'),
|
|
119
|
-
choices: Object.entries(functionCategories)
|
|
120
|
-
.reduce((acc, [key, cat], index) => {
|
|
121
|
-
acc.push({ name: cat.name, value: key });
|
|
122
|
-
if (index < Object.entries(functionCategories).length - 1) {
|
|
123
|
-
acc.push(new Separator(' '));
|
|
124
|
-
}
|
|
125
|
-
return acc;
|
|
126
|
-
}, [])
|
|
127
|
-
.concat([new Separator(' '), { name: chalk.red('ā Exit'), value: 'exit' }]),
|
|
128
|
-
pageSize: 17,
|
|
129
|
-
loop: false,
|
|
130
|
-
});
|
|
131
|
-
// Handle exit selection
|
|
132
|
-
if (category === 'exit') {
|
|
133
|
-
console.log(chalk.yellow('\nš Goodbye!\n'));
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
const selectedCategory = functionCategories[category];
|
|
137
|
-
// Function selection loop
|
|
138
|
-
while (true) {
|
|
139
|
-
const functionName = await select({
|
|
140
|
-
message: chalk.cyan(`Choose a ${selectedCategory.name} function:`),
|
|
141
|
-
choices: selectedCategory.functions
|
|
142
|
-
.reduce((acc, func, index) => {
|
|
143
|
-
acc.push({ name: `${func.name} - ${func.description}`, value: func.name });
|
|
144
|
-
if (index < selectedCategory.functions.length - 1) {
|
|
145
|
-
acc.push(new Separator(' '));
|
|
146
|
-
}
|
|
147
|
-
return acc;
|
|
148
|
-
}, [])
|
|
149
|
-
.concat([
|
|
150
|
-
new Separator(' '),
|
|
151
|
-
{ name: chalk.gray('ā¬
ļø Back to categories'), value: 'back' },
|
|
152
|
-
{ name: chalk.red('ā Exit'), value: 'exit' },
|
|
153
|
-
]),
|
|
154
|
-
pageSize: 12,
|
|
155
|
-
loop: false,
|
|
156
|
-
});
|
|
157
|
-
// Handle navigation options
|
|
158
|
-
if (functionName === 'exit') {
|
|
159
|
-
console.log(chalk.yellow('\nš Goodbye!\n'));
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
if (functionName === 'back') {
|
|
163
|
-
break; // Break out of function selection loop, go back to categories
|
|
164
|
-
}
|
|
165
|
-
// Show the command
|
|
166
|
-
console.log(chalk.green(`\nš You can run this command:`));
|
|
167
|
-
console.log(chalk.yellow(`js-common ${category} ${functionName} [arguments]`));
|
|
168
|
-
console.log(chalk.gray(`\nFor detailed usage, run: js-common ${category} ${functionName} --help\n`));
|
|
169
|
-
return; // Exit after showing the command
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
catch (error) {
|
|
174
|
-
if (error && typeof error === 'object' && 'isTtyError' in error) {
|
|
175
|
-
console.log(chalk.red('\nā Interactive mode requires a TTY terminal'));
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
console.log(chalk.red('\nā Something went wrong in interactive mode'));
|
|
179
|
-
}
|
|
180
|
-
process.exit(1);
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
// Add command - help developers integrate functions into their projects
|
|
184
|
-
program
|
|
185
|
-
.command('add')
|
|
186
|
-
.alias('a')
|
|
187
|
-
.description('š§ Add utility functions to your project')
|
|
188
|
-
.action(async () => {
|
|
189
|
-
// Welcome message
|
|
190
|
-
console.log(gradient.pastel('\nš§ Function Integration Helper\n'));
|
|
191
|
-
try {
|
|
192
|
-
const category = await select({
|
|
193
|
-
message: chalk.cyan('Which category of utilities do you need?'),
|
|
194
|
-
choices: Object.entries(functionCategories)
|
|
195
|
-
.reduce((acc, [key, cat], index) => {
|
|
196
|
-
acc.push({ name: cat.name, value: key });
|
|
197
|
-
if (index < Object.entries(functionCategories).length - 1) {
|
|
198
|
-
acc.push(new Separator(' '));
|
|
199
|
-
}
|
|
200
|
-
return acc;
|
|
201
|
-
}, [])
|
|
202
|
-
.concat([new Separator(' '), { name: chalk.red('ā Exit'), value: 'exit' }]),
|
|
203
|
-
pageSize: 17,
|
|
204
|
-
loop: false,
|
|
205
|
-
});
|
|
206
|
-
// Handle exit selection
|
|
207
|
-
if (category === 'exit') {
|
|
208
|
-
console.log(chalk.yellow('\nš Goodbye!\n'));
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
const selectedCategory = functionCategories[category];
|
|
212
|
-
const functions = await checkbox({
|
|
213
|
-
message: chalk.cyan(`Select ${selectedCategory.name} functions to add:`),
|
|
214
|
-
choices: selectedCategory.functions.map((func) => ({
|
|
215
|
-
name: `${func.name} - ${func.description}`,
|
|
216
|
-
value: func.name,
|
|
217
|
-
checked: false,
|
|
218
|
-
})),
|
|
219
|
-
pageSize: 10,
|
|
220
|
-
loop: false,
|
|
221
|
-
});
|
|
222
|
-
if (functions.length === 0) {
|
|
223
|
-
console.log(chalk.yellow('\nš No functions selected. Exiting...\n'));
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
console.log(chalk.green('\nš¦ Import Statement:'));
|
|
227
|
-
console.log(chalk.white(`import { ${functions.join(', ')} } from '@rtorcato/js-common/${category}'`));
|
|
228
|
-
console.log(chalk.green('\nš Usage Examples:'));
|
|
229
|
-
functions.forEach((func) => {
|
|
230
|
-
const funcInfo = selectedCategory.functions.find((f) => f.name === func);
|
|
231
|
-
if (funcInfo) {
|
|
232
|
-
console.log(chalk.gray(`\n// ${funcInfo.description}`));
|
|
233
|
-
generateUsageExample(category, func);
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
console.log(chalk.green('\nš Documentation:'));
|
|
237
|
-
console.log(chalk.blue(`https://github.com/rtorcato/js-common#${category}-utilities`));
|
|
238
|
-
console.log(chalk.yellow('\nš” Tip: Run ') +
|
|
239
|
-
chalk.green(`js-common ${category} ${functions[0]} --help`) +
|
|
240
|
-
chalk.yellow(' for detailed CLI usage\n'));
|
|
241
|
-
}
|
|
242
|
-
catch (error) {
|
|
243
|
-
if (error && typeof error === 'object' && 'isTtyError' in error) {
|
|
244
|
-
console.log(chalk.red('\nā Interactive mode requires a TTY terminal'));
|
|
245
|
-
}
|
|
246
|
-
else {
|
|
247
|
-
console.log(chalk.red('\nā Something went wrong'));
|
|
248
|
-
}
|
|
249
|
-
process.exit(1);
|
|
250
|
-
}
|
|
251
|
-
});
|
|
252
|
-
// Helper function to generate usage examples
|
|
253
|
-
function generateUsageExample(category, functionName) {
|
|
254
|
-
const examples = {
|
|
255
|
-
date: {
|
|
256
|
-
today: `const today = today(); // "${new Date().toISOString().split('T')[0]}"`,
|
|
257
|
-
now: `const timestamp = now(); // ${Date.now()}`,
|
|
258
|
-
between: `const days = daysBetween('2023-01-01', '2023-12-31'); // 364`,
|
|
259
|
-
},
|
|
260
|
-
math: {
|
|
261
|
-
sum: `const total = sum([1, 2, 3, 4, 5]); // 15`,
|
|
262
|
-
avg: `const average = avg([10, 20, 30]); // 20`,
|
|
263
|
-
random: `const num = randomBetween(1, 100); // 42`,
|
|
264
|
-
round: `const rounded = roundTo(3.14159, 2); // 3.14`,
|
|
265
|
-
clamp: `const clamped = clamp(150, 0, 100); // 100`,
|
|
266
|
-
},
|
|
267
|
-
text: {
|
|
268
|
-
capitalize: `const text = capitalize('hello world'); // "Hello world"`,
|
|
269
|
-
title: `const title = toTitleCase('hello world'); // "Hello World"`,
|
|
270
|
-
pad: `const padded = padWithZeros(42, 5); // "00042"`,
|
|
271
|
-
},
|
|
272
|
-
file: {
|
|
273
|
-
exists: `const exists = await fileExists('package.json'); // true`,
|
|
274
|
-
ext: `const extension = getFileExtension('file.txt'); // "txt"`,
|
|
275
|
-
},
|
|
276
|
-
security: {
|
|
277
|
-
password: `const isStrong = checkPasswordStrength('MyPass123!'); // true`,
|
|
278
|
-
token: `const token = generateSecureToken(32); // "abc123..."`,
|
|
279
|
-
},
|
|
280
|
-
validate: {
|
|
281
|
-
url: `const isValid = isValidUrl('https://example.com'); // true`,
|
|
282
|
-
},
|
|
283
|
-
system: {
|
|
284
|
-
pid: `const processId = getProcessId(); // 12345`,
|
|
285
|
-
uptime: `const uptime = getProcessUptime(); // 123.45`,
|
|
286
|
-
ci: `const isCI = isCiEnvironment(); // false`,
|
|
287
|
-
'node-version': `const version = getNodeVersion(); // "18.17.0"`,
|
|
288
|
-
},
|
|
289
|
-
};
|
|
290
|
-
const example = examples[category]?.[functionName];
|
|
291
|
-
if (example) {
|
|
292
|
-
console.log(chalk.white(example));
|
|
293
|
-
}
|
|
2
|
+
// Entry point for the js-common CLI binary.
|
|
3
|
+
// CLI-only npm deps (chalk, commander, figlet, ā¦) live under
|
|
4
|
+
// `optionalDependencies` to keep the install footprint small for
|
|
5
|
+
// library-only consumers. If any of them is missing at runtime we
|
|
6
|
+
// catch the resolution error and print install instructions instead
|
|
7
|
+
// of letting Node emit an opaque ERR_MODULE_NOT_FOUND trace.
|
|
8
|
+
try {
|
|
9
|
+
await import('./cli.mjs');
|
|
294
10
|
}
|
|
295
|
-
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
.option('-t, --time', 'Time only')
|
|
308
|
-
.action((options) => {
|
|
309
|
-
if (options.iso) {
|
|
310
|
-
console.log(new Date().toISOString());
|
|
311
|
-
}
|
|
312
|
-
else if (options.time) {
|
|
313
|
-
console.log(new Date().toTimeString());
|
|
314
|
-
}
|
|
315
|
-
else {
|
|
316
|
-
console.log(Date.now());
|
|
11
|
+
catch (err) {
|
|
12
|
+
const isMissingModule = err !== null &&
|
|
13
|
+
typeof err === 'object' &&
|
|
14
|
+
'code' in err &&
|
|
15
|
+
err.code === 'ERR_MODULE_NOT_FOUND';
|
|
16
|
+
if (isMissingModule) {
|
|
17
|
+
process.stderr.write('The js-common CLI requires optional dependencies that are not installed.\n' +
|
|
18
|
+
'Install them globally to use the CLI:\n\n' +
|
|
19
|
+
' npm install -g @rtorcato/js-common\n\n' +
|
|
20
|
+
'Or run it ad-hoc with npx, which installs them on demand:\n\n' +
|
|
21
|
+
' npx @rtorcato/js-common@latest --help\n');
|
|
22
|
+
process.exit(1);
|
|
317
23
|
}
|
|
318
|
-
|
|
319
|
-
dateCmd
|
|
320
|
-
.command('between')
|
|
321
|
-
.description('Calculate days between dates')
|
|
322
|
-
.argument('<date1>', 'First date (YYYY-MM-DD)')
|
|
323
|
-
.argument('<date2>', 'Second date (YYYY-MM-DD)')
|
|
324
|
-
.action((date1, date2) => {
|
|
325
|
-
const d1 = new Date(date1);
|
|
326
|
-
const d2 = new Date(date2);
|
|
327
|
-
const timeDiff = Math.abs(d2.getTime() - d1.getTime());
|
|
328
|
-
const daysDiff = Math.ceil(timeDiff / (1000 * 3600 * 24));
|
|
329
|
-
console.log(`${daysDiff} days`);
|
|
330
|
-
});
|
|
331
|
-
// Math commands
|
|
332
|
-
const mathCmd = program.command('math').description('š¢ Mathematical utilities');
|
|
333
|
-
mathCmd
|
|
334
|
-
.command('sum')
|
|
335
|
-
.description('Calculate sum of numbers')
|
|
336
|
-
.argument('<numbers...>', 'Numbers to sum')
|
|
337
|
-
.action((numbers) => {
|
|
338
|
-
const nums = numbers.map(Number).filter((n) => !Number.isNaN(n));
|
|
339
|
-
console.log(nums.reduce((a, b) => a + b, 0));
|
|
340
|
-
});
|
|
341
|
-
mathCmd
|
|
342
|
-
.command('avg')
|
|
343
|
-
.description('Calculate average of numbers')
|
|
344
|
-
.argument('<numbers...>', 'Numbers to average')
|
|
345
|
-
.action((numbers) => {
|
|
346
|
-
const nums = numbers.map(Number).filter((n) => !Number.isNaN(n));
|
|
347
|
-
console.log(nums.reduce((a, b) => a + b, 0) / nums.length);
|
|
348
|
-
});
|
|
349
|
-
mathCmd
|
|
350
|
-
.command('random')
|
|
351
|
-
.description('Generate random number')
|
|
352
|
-
.argument('<min>', 'Minimum value')
|
|
353
|
-
.argument('<max>', 'Maximum value')
|
|
354
|
-
.action((min, max) => {
|
|
355
|
-
const minNum = Number(min);
|
|
356
|
-
const maxNum = Number(max);
|
|
357
|
-
console.log(Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum);
|
|
358
|
-
});
|
|
359
|
-
mathCmd
|
|
360
|
-
.command('round')
|
|
361
|
-
.description('Round to decimal places')
|
|
362
|
-
.argument('<number>', 'Number to round')
|
|
363
|
-
.argument('<decimals>', 'Decimal places')
|
|
364
|
-
.action((number, decimals) => {
|
|
365
|
-
const num = Number(number);
|
|
366
|
-
const dec = Number(decimals);
|
|
367
|
-
console.log(Number(num.toFixed(dec)));
|
|
368
|
-
});
|
|
369
|
-
mathCmd
|
|
370
|
-
.command('clamp')
|
|
371
|
-
.description('Clamp between min/max')
|
|
372
|
-
.argument('<number>', 'Number to clamp')
|
|
373
|
-
.argument('<min>', 'Minimum value')
|
|
374
|
-
.argument('<max>', 'Maximum value')
|
|
375
|
-
.action((number, min, max) => {
|
|
376
|
-
const num = Number(number);
|
|
377
|
-
const minVal = Number(min);
|
|
378
|
-
const maxVal = Number(max);
|
|
379
|
-
console.log(Math.min(Math.max(num, minVal), maxVal));
|
|
380
|
-
});
|
|
381
|
-
// Simple implementations for other commands
|
|
382
|
-
const textCmd = program.command('text').description('š Text formatting utilities');
|
|
383
|
-
textCmd
|
|
384
|
-
.command('capitalize')
|
|
385
|
-
.description('Capitalize first letter')
|
|
386
|
-
.argument('<text>', 'Text to capitalize')
|
|
387
|
-
.action((text) => {
|
|
388
|
-
console.log(text.charAt(0).toUpperCase() + text.slice(1));
|
|
389
|
-
});
|
|
390
|
-
textCmd
|
|
391
|
-
.command('title')
|
|
392
|
-
.description('Convert to title case')
|
|
393
|
-
.argument('<text>', 'Text to convert')
|
|
394
|
-
.action((text) => {
|
|
395
|
-
console.log(text.replace(/\w\S*/g, (txt) => txt.charAt(0).toUpperCase() + txt.substring(1).toLowerCase()));
|
|
396
|
-
});
|
|
397
|
-
// System commands
|
|
398
|
-
const systemCmd = program.command('system').description('š» System information utilities');
|
|
399
|
-
systemCmd
|
|
400
|
-
.command('pid')
|
|
401
|
-
.description('Get process ID')
|
|
402
|
-
.action(() => {
|
|
403
|
-
console.log(process.pid);
|
|
404
|
-
});
|
|
405
|
-
systemCmd
|
|
406
|
-
.command('uptime')
|
|
407
|
-
.description('Get process uptime')
|
|
408
|
-
.action(() => {
|
|
409
|
-
console.log(`${Math.floor(process.uptime())} seconds`);
|
|
410
|
-
});
|
|
411
|
-
systemCmd
|
|
412
|
-
.command('node-version')
|
|
413
|
-
.description('Get Node.js version')
|
|
414
|
-
.action(() => {
|
|
415
|
-
console.log(process.version);
|
|
416
|
-
});
|
|
417
|
-
// Handle --list option before parsing
|
|
418
|
-
if (process.argv.includes('--list') || process.argv.includes('-l')) {
|
|
419
|
-
console.log(chalk.cyan('\n⨠Available Functions:\n'));
|
|
420
|
-
Object.entries(functionCategories).forEach(([key, category]) => {
|
|
421
|
-
console.log(chalk.bold(category.name));
|
|
422
|
-
console.log(); // Add space after category header
|
|
423
|
-
category.functions.forEach((func) => {
|
|
424
|
-
console.log(chalk.gray(` js-common ${key} ${func.name}`) + chalk.dim(` - ${func.description}`));
|
|
425
|
-
});
|
|
426
|
-
console.log(); // Add space after function list
|
|
427
|
-
});
|
|
428
|
-
console.log(chalk.yellow('š” Use ') +
|
|
429
|
-
chalk.green('js-common add') +
|
|
430
|
-
chalk.yellow(' to integrate functions into your project'));
|
|
431
|
-
console.log(chalk.yellow('š” Use ') +
|
|
432
|
-
chalk.green('js-common interactive') +
|
|
433
|
-
chalk.yellow(' for interactive mode'));
|
|
434
|
-
console.log(chalk.yellow('š” Use ') +
|
|
435
|
-
chalk.green('js-common <command> --help') +
|
|
436
|
-
chalk.yellow(' for detailed help\n'));
|
|
437
|
-
process.exit(0);
|
|
24
|
+
throw err;
|
|
438
25
|
}
|
|
439
|
-
|
|
440
|
-
program.parse();
|
|
26
|
+
export {};
|
package/dist/env/index.js
CHANGED
|
@@ -1,3 +1 @@
|
|
|
1
|
-
import"../chunks/chunk-ANN5UYCF.js";
|
|
2
|
-
`;t+=Object.keys(e.flatten().fieldErrors).join(`
|
|
3
|
-
`);let s=new Error(t);throw s.stack="",s}throw e}}var f=n.object({NODE_ENV:n.enum(["development","test","production"]).default("development"),LOG_LEVEL:n.enum(["debug","info","warn","error"]).default("info"),PORT:n.coerce.number().default(3e3)});export{f as RootApiEnvSchema,a as checkEnv,c as getENV,u as getNodeEnv,d as isDev,p as isProd,E as isTest};
|
|
1
|
+
import{a,b,c,d,e,f,g}from"../chunks/chunk-FBDKWWIQ.js";import"../chunks/chunk-ANN5UYCF.js";export{g as RootApiEnvSchema,f as checkEnv,a as getENV,e as getNodeEnv,b as isDev,c as isProd,d as isTest};
|
package/dist/errors/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"../chunks/chunk-ANN5UYCF.js";function e(n,r){let t=new Error(r);return t.name=n,t}function o(n,r){return n instanceof Error&&n.name===r}function i(n){if(n instanceof Error)return n.message;if(typeof n=="string")return n;try{return JSON.stringify(n)}catch{return String(n)}}function s(n,r){if(!n)throw new Error(r)}async function a(n,r){try{return await n()}catch{return r}}export{s as assert,e as createCustomError,i as getErrorMessage,o as isErrorName,a as
|
|
1
|
+
import"../chunks/chunk-ANN5UYCF.js";function e(n,r){let t=new Error(r);return t.name=n,t}function o(n,r){return n instanceof Error&&n.name===r}function i(n){if(n instanceof Error)return n.message;if(typeof n=="string")return n;try{return JSON.stringify(n)}catch{return String(n)}}function s(n,r){if(!n)throw new Error(r)}async function a(n,r){try{return await n()}catch{return r}}export{s as assert,e as createCustomError,i as getErrorMessage,o as isErrorName,a as tryWithFallback};
|
package/dist/index.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"./chunks/chunk-ANN5UYCF.js";var t=()=>(console.log("test"),"testPackage");export{t as testPackage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as o}from"../chunks/chunk-6J7HIWG6.js";import"../chunks/chunk-FBDKWWIQ.js";import"../chunks/chunk-ANN5UYCF.js";export{o as logger};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a}from"../chunks/chunk-6J7HIWG6.js";import"../chunks/chunk-FBDKWWIQ.js";import"../chunks/chunk-ANN5UYCF.js";export{a as logger};
|
package/dist/logging/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"../chunks/chunk-ANN5UYCF.js";function
|
|
1
|
+
import"../chunks/chunk-ANN5UYCF.js";function i(o,r="info"){let n=new Date().toISOString();console[r](`[${n}] ${o}`)}function t(o){console.warn(`[WARN] ${o}`)}function s(o){console.error(`[ERROR] ${o}`)}function c(o){console.info(`[INFO] ${o}`)}function l(o){let r={log:console.log,info:console.info,warn:console.warn,error:console.error};return["log","info","warn","error"].forEach(n=>{console[n]=(...e)=>{o(n,...e),r[n](...e)}}),()=>{Object.assign(console,r)}}export{l as captureConsole,s as error,c as info,i as logWithTimestamp,t as warn};
|
package/dist/math/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import"../chunks/chunk-ANN5UYCF.js";var n=(e,r)=>e+r,u=(e,r)=>e-r,b=(e,r)=>e*r,m=(e,r)=>e/r;export{n as add,m as divide,b as multiply,u as subtract};
|
package/dist/validation/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"../chunks/chunk-ANN5UYCF.js";function r(n){return n!=null}function e(n){return typeof n=="string"}function t(n){return typeof n=="number"&&!Number.isNaN(n)}function
|
|
1
|
+
import"../chunks/chunk-ANN5UYCF.js";function r(n){return n!=null}function e(n){return typeof n=="string"}function t(n){return typeof n=="number"&&!Number.isNaN(n)}function o(n){return typeof n=="boolean"}function u(n){return Array.isArray(n)}function i(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)}function s(n){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(n)}function a(n){try{return new URL(n),!0}catch{return!1}}export{u as isArray,o as isBoolean,r as isDefined,s as isEmail,t as isNumber,i as isObject,e as isString,a as isUrl};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rtorcato/js-common",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "JavaScript and TypeScript common code",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"scripts": {
|
|
29
29
|
"build-dev": "rimraf ./dist && cross-env NODE_ENV=development node build.mjs && tsc --emitDeclarationOnly --project tsconfig.build.json && npm run build-cli",
|
|
30
30
|
"build-prod": "rimraf ./dist && cross-env NODE_ENV=production node build.mjs && tsc --emitDeclarationOnly --project tsconfig.build.json && npm run build-cli",
|
|
31
|
-
"build-cli": "tsc src/cli/cli.ts --ignoreConfig --types node --outDir dist/cli --target ES2022 --module ES2022 --moduleResolution bundler --allowImportingTsExtensions false --esModuleInterop --skipLibCheck &&
|
|
31
|
+
"build-cli": "tsc src/cli/bootstrap.ts src/cli/cli.ts --ignoreConfig --types node --outDir dist/cli --target ES2022 --module ES2022 --moduleResolution bundler --allowImportingTsExtensions false --esModuleInterop --skipLibCheck && echo '#!/usr/bin/env node' > dist/cli/index.mjs && cat dist/cli/bootstrap.js >> dist/cli/index.mjs && rm dist/cli/bootstrap.js && mv dist/cli/cli.js dist/cli/cli.mjs && sed -i.bak \"s|'./cli.js'|'./cli.mjs'|g\" dist/cli/index.mjs && rm dist/cli/index.mjs.bak && chmod +x dist/cli/index.mjs",
|
|
32
32
|
"prepublishOnly": "npm run build-prod",
|
|
33
33
|
"==================== Common ====================": "",
|
|
34
34
|
"lint": "pnpm exec biome lint .",
|
|
@@ -116,6 +116,10 @@
|
|
|
116
116
|
"import": "./dist/file/index.js",
|
|
117
117
|
"types": "./dist/file/index.d.ts"
|
|
118
118
|
},
|
|
119
|
+
"./formatting": {
|
|
120
|
+
"import": "./dist/formatting/index.js",
|
|
121
|
+
"types": "./dist/formatting/index.d.ts"
|
|
122
|
+
},
|
|
119
123
|
"./functions": {
|
|
120
124
|
"import": "./dist/functions/index.js",
|
|
121
125
|
"types": "./dist/functions/index.d.ts"
|
|
@@ -249,7 +253,6 @@
|
|
|
249
253
|
"@semantic-release/release-notes-generator": "^14.1.0",
|
|
250
254
|
"@types/chalk-animation": "^1.6.3",
|
|
251
255
|
"@types/figlet": "^1.7.0",
|
|
252
|
-
"@types/inquirer": "^9.0.9",
|
|
253
256
|
"@types/luxon": "^3.7.1",
|
|
254
257
|
"@types/node": "^24.9.1",
|
|
255
258
|
"@vitest/coverage-istanbul": "^4.0.17",
|
|
@@ -258,46 +261,33 @@
|
|
|
258
261
|
"husky": "^9.1.7",
|
|
259
262
|
"jsdom": "^29.0.1",
|
|
260
263
|
"knip": "^6.14.2",
|
|
261
|
-
"lint-staged": "^16.2.6",
|
|
262
264
|
"rimraf": "^6.0.1",
|
|
263
265
|
"semantic-release": "^25.0.1",
|
|
264
266
|
"typescript": "^6.0.2",
|
|
265
267
|
"vitest": "^4.0.17"
|
|
266
268
|
},
|
|
267
269
|
"dependencies": {
|
|
268
|
-
"@inquirer/prompts": "^8.5.0",
|
|
269
|
-
"chalk": "^5.6.2",
|
|
270
|
-
"chalk-animation": "^2.0.3",
|
|
271
|
-
"commander": "^14.0.1",
|
|
272
270
|
"date-fns": "^4.1.0",
|
|
273
271
|
"date-fns-tz": "^3.2.0",
|
|
274
|
-
"figlet": "^1.9.3",
|
|
275
|
-
"gradient-string": "^3.0.0",
|
|
276
|
-
"inquirer": "^13.3.2",
|
|
277
272
|
"luxon": "^3.7.2",
|
|
278
|
-
"nanospinner": "^1.2.2",
|
|
279
273
|
"pino": "^10.1.0",
|
|
280
274
|
"short-uuid": "^6.0.3",
|
|
281
275
|
"uuid": "^13.0.0",
|
|
282
276
|
"zod": "^4.1.12"
|
|
283
277
|
},
|
|
278
|
+
"optionalDependencies": {
|
|
279
|
+
"@inquirer/prompts": "^8.5.0",
|
|
280
|
+
"chalk": "^5.6.2",
|
|
281
|
+
"chalk-animation": "^2.0.3",
|
|
282
|
+
"commander": "^14.0.1",
|
|
283
|
+
"figlet": "^1.9.3",
|
|
284
|
+
"gradient-string": "^3.0.0"
|
|
285
|
+
},
|
|
284
286
|
"config": {
|
|
285
287
|
"commitizen": {
|
|
286
288
|
"path": "cz-conventional-changelog"
|
|
287
289
|
}
|
|
288
290
|
},
|
|
289
|
-
"lint-staged": {
|
|
290
|
-
"*.{js,ts,json,md}": [
|
|
291
|
-
"pnpm exec biome lint",
|
|
292
|
-
"pnpm exec biome format",
|
|
293
|
-
"git add"
|
|
294
|
-
]
|
|
295
|
-
},
|
|
296
|
-
"husky": {
|
|
297
|
-
"hooks": {
|
|
298
|
-
"pre-commit": "lint-staged"
|
|
299
|
-
}
|
|
300
|
-
},
|
|
301
291
|
"publishConfig": {
|
|
302
292
|
"access": "public"
|
|
303
293
|
},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var n=(e,r)=>e+r,u=(e,r)=>e-r,b=(e,r)=>e*r,m=(e,r)=>e/r;export{n as a,u as b,b as c,m as d};
|
package/dist/helloworld/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"../chunks/chunk-ANN5UYCF.js";function l(){return"Hello, World!"}export{l as helloWorld};
|
package/dist/logging/index1.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"../chunks/chunk-ANN5UYCF.js";var t=(...o)=>{let n=new Date().toISOString();console.log(`[${n}]`,...o)},e=(...o)=>{console.warn("\x1B[33m%s\x1B[0m",...o)},s=(...o)=>{console.error("\x1B[31m%s\x1B[0m",...o)},r=(...o)=>{console.info("\x1B[34m%s\x1B[0m",...o)};export{s as error,r as info,t as logWithTimestamp,e as warn};
|
package/dist/math/math.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a,b,c,d}from"../chunks/chunk-DCFILRIS.js";import"../chunks/chunk-ANN5UYCF.js";export{a as add,d as divide,c as multiply,b as subtract};
|