jarvis-vraj 1.0.0 → 1.2.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/LICENSE +21 -0
- package/README.md +201 -5
- package/bin/cli.js +69 -0
- package/index.d.ts +38 -0
- package/index.js +164 -3
- package/package.json +36 -9
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Vraj Raval
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,12 +1,208 @@
|
|
|
1
1
|
# jarvis-vraj
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/jarvis-vraj)
|
|
4
|
+
[](./LICENSE)
|
|
5
|
+
[](https://nodejs.org)
|
|
6
|
+
|
|
7
|
+
A small, friendly assistant toolkit for Node.js. It greets you based on the time of day, reports on your machine's health, formats durations and file sizes, and has a quip ready when you need one.
|
|
8
|
+
|
|
9
|
+
- **Zero dependencies.** Only uses Node's built-in modules.
|
|
10
|
+
- **TypeScript types included.**
|
|
11
|
+
- **Command-line tool included.** Try it with `npx jarvis-vraj`.
|
|
12
|
+
|
|
13
|
+
---
|
|
4
14
|
|
|
5
15
|
## Install
|
|
6
16
|
|
|
7
|
-
|
|
17
|
+
```bash
|
|
18
|
+
npm install jarvis-vraj
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Or run the CLI without installing:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npx jarvis-vraj
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Requires **Node.js 18 or newer**.
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Quick start
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
const { greet, statusReport, quip } = require('jarvis-vraj');
|
|
35
|
+
|
|
36
|
+
console.log(greet('Vraj'));
|
|
37
|
+
// Good evening, Vraj.
|
|
38
|
+
|
|
39
|
+
console.log(statusReport({ name: 'Vraj' }));
|
|
40
|
+
// Status report for Vraj:
|
|
41
|
+
// Host Vrajs-MacBook-Air (darwin/arm64)
|
|
42
|
+
// CPU 8 cores
|
|
43
|
+
// Memory 6.2 GB of 8.0 GB used (78%)
|
|
44
|
+
// Uptime 2d 4h 13m 9s
|
|
45
|
+
// Node.js v22.11.0
|
|
46
|
+
// All systems nominal.
|
|
47
|
+
|
|
48
|
+
console.log(quip());
|
|
49
|
+
// Backing up your work. Optimism is not a backup strategy.
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Using ES modules or TypeScript:
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import { greet, formatDuration } from 'jarvis-vraj';
|
|
56
|
+
|
|
57
|
+
greet('Tony', { style: 'butler' });
|
|
58
|
+
formatDuration(3725); // "1h 2m 5s"
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## API
|
|
64
|
+
|
|
65
|
+
### `greet(name?, options?)`
|
|
66
|
+
|
|
67
|
+
Returns a greeting that matches the time of day.
|
|
68
|
+
|
|
69
|
+
| Parameter | Type | Default | Description |
|
|
70
|
+
|---|---|---|---|
|
|
71
|
+
| `name` | `string` | `"sir"` | Who to greet |
|
|
72
|
+
| `options.style` | `"formal"` \| `"casual"` \| `"butler"` | `"formal"` | Tone of the greeting |
|
|
73
|
+
| `options.date` | `Date` | now | Time used to choose morning, afternoon or evening |
|
|
74
|
+
|
|
75
|
+
```js
|
|
76
|
+
greet('Tony'); // "Good morning, Tony."
|
|
77
|
+
greet('Tony', { style: 'casual' }); // "Hey Tony! Hope your morning is going well."
|
|
78
|
+
greet('Tony', { style: 'butler' }); // "Good morning, Tony. Your systems are online and awaiting instructions."
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Throws a `TypeError` for an empty name, and a `RangeError` for an unknown style.
|
|
82
|
+
|
|
83
|
+
### `timeOfDay(date?)`
|
|
84
|
+
|
|
85
|
+
Returns `"morning"` (5:00–11:59), `"afternoon"` (12:00–16:59), `"evening"` (17:00–20:59) or `"night"` (21:00–4:59).
|
|
86
|
+
|
|
87
|
+
```js
|
|
88
|
+
timeOfDay(new Date('2026-01-01T09:00:00')); // "morning"
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### `statusReport(options?)`
|
|
92
|
+
|
|
93
|
+
Returns a multi-line text report about the current machine: host, CPU cores, memory use, uptime and Node.js version.
|
|
94
|
+
|
|
95
|
+
| Parameter | Type | Default |
|
|
96
|
+
|---|---|---|
|
|
97
|
+
| `options.name` | `string` | `"sir"` |
|
|
98
|
+
|
|
99
|
+
### `systemInfo()`
|
|
100
|
+
|
|
101
|
+
The same data as `statusReport`, returned as an object so you can use it in your own code.
|
|
102
|
+
|
|
103
|
+
```js
|
|
104
|
+
const info = systemInfo();
|
|
105
|
+
// {
|
|
106
|
+
// hostname: 'Vrajs-MacBook-Air', platform: 'darwin', arch: 'arm64',
|
|
107
|
+
// cpus: 8, memoryTotal: 8589934592, memoryFree: 1879048192,
|
|
108
|
+
// memoryUsedPercent: 78, uptimeSeconds: 187989, nodeVersion: 'v22.11.0'
|
|
109
|
+
// }
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### `formatDuration(seconds)`
|
|
113
|
+
|
|
114
|
+
Turns a number of seconds into readable text.
|
|
115
|
+
|
|
116
|
+
```js
|
|
117
|
+
formatDuration(0); // "0s"
|
|
118
|
+
formatDuration(3725); // "1h 2m 5s"
|
|
119
|
+
formatDuration(90000); // "1d 1h"
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### `formatBytes(bytes)`
|
|
123
|
+
|
|
124
|
+
Turns a number of bytes into readable text.
|
|
125
|
+
|
|
126
|
+
```js
|
|
127
|
+
formatBytes(500); // "500 B"
|
|
128
|
+
formatBytes(1536); // "1.5 KB"
|
|
129
|
+
formatBytes(8589934592); // "8.0 GB"
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### `quip(random?)`
|
|
133
|
+
|
|
134
|
+
Returns a random witty line. Pass your own random function if you need predictable output (for example, in tests).
|
|
135
|
+
|
|
136
|
+
```js
|
|
137
|
+
quip(); // random line
|
|
138
|
+
quip(() => 0); // always the first line
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### `STYLES`
|
|
142
|
+
|
|
143
|
+
The list of supported greeting styles: `['formal', 'casual', 'butler']`.
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## Command-line tool
|
|
148
|
+
|
|
149
|
+
```text
|
|
150
|
+
Usage:
|
|
151
|
+
jarvis-vraj [command] [options]
|
|
152
|
+
|
|
153
|
+
Commands:
|
|
154
|
+
greet [name] Time-aware greeting (default)
|
|
155
|
+
status System status report
|
|
156
|
+
quip A random witty line
|
|
157
|
+
|
|
158
|
+
Options:
|
|
159
|
+
-n, --name <name> Name to use (default: your OS username)
|
|
160
|
+
-s, --style <style> Greeting style: formal | casual | butler
|
|
161
|
+
-v, --version Show version
|
|
162
|
+
-h, --help Show help
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Examples:
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
npx jarvis-vraj # Good evening, vraj.
|
|
169
|
+
npx jarvis-vraj greet Tony --style butler
|
|
170
|
+
npx jarvis-vraj status
|
|
171
|
+
npx jarvis-vraj quip
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Install it globally to use it without `npx`:
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
npm install -g jarvis-vraj
|
|
178
|
+
jarvis-vraj status
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
## Development
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
npm test
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Tests use Node's built-in test runner, so there is nothing extra to install.
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## Changelog
|
|
194
|
+
|
|
195
|
+
### 1.1.0
|
|
196
|
+
- Added `statusReport`, `systemInfo`, `formatDuration`, `formatBytes`, `quip` and `timeOfDay`.
|
|
197
|
+
- Added greeting styles (`formal`, `casual`, `butler`).
|
|
198
|
+
- Added the `jarvis-vraj` command-line tool.
|
|
199
|
+
- Added TypeScript types and tests.
|
|
200
|
+
|
|
201
|
+
### 1.0.0
|
|
202
|
+
- First release with `greet(name)`.
|
|
203
|
+
|
|
204
|
+
---
|
|
8
205
|
|
|
9
|
-
##
|
|
206
|
+
## License
|
|
10
207
|
|
|
11
|
-
|
|
12
|
-
console.log(greet('Tony')); // Hello, Tony!
|
|
208
|
+
[MIT](./LICENSE) © Vraj Raval
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const { greet, statusReport, quip, STYLES } = require('../index.js');
|
|
5
|
+
const pkg = require('../package.json');
|
|
6
|
+
|
|
7
|
+
const HELP = `jarvis-vraj v${pkg.version}
|
|
8
|
+
|
|
9
|
+
Usage:
|
|
10
|
+
jarvis-vraj [command] [options]
|
|
11
|
+
|
|
12
|
+
Commands:
|
|
13
|
+
greet [name] Time-aware greeting (default)
|
|
14
|
+
status System status report
|
|
15
|
+
quip A random witty line
|
|
16
|
+
|
|
17
|
+
Options:
|
|
18
|
+
-n, --name <name> Name to use (default: your OS username)
|
|
19
|
+
-s, --style <style> Greeting style: ${STYLES.join(' | ')} (default: formal)
|
|
20
|
+
-v, --version Show version
|
|
21
|
+
-h, --help Show this help
|
|
22
|
+
|
|
23
|
+
Examples:
|
|
24
|
+
npx jarvis-vraj
|
|
25
|
+
npx jarvis-vraj greet Tony --style butler
|
|
26
|
+
npx jarvis-vraj status
|
|
27
|
+
`;
|
|
28
|
+
|
|
29
|
+
function defaultName() {
|
|
30
|
+
try { return require('os').userInfo().username || 'sir'; } catch { return 'sir'; }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function parse(argv) {
|
|
34
|
+
const opts = { command: 'greet', name: null, style: 'formal', positional: [] };
|
|
35
|
+
for (let i = 0; i < argv.length; i++) {
|
|
36
|
+
const a = argv[i];
|
|
37
|
+
if (a === '-h' || a === '--help') opts.help = true;
|
|
38
|
+
else if (a === '-v' || a === '--version') opts.version = true;
|
|
39
|
+
else if (a === '-n' || a === '--name') opts.name = argv[++i];
|
|
40
|
+
else if (a === '-s' || a === '--style') opts.style = argv[++i];
|
|
41
|
+
else if (a.startsWith('-')) throw new Error(`Unknown option: ${a}`);
|
|
42
|
+
else opts.positional.push(a);
|
|
43
|
+
}
|
|
44
|
+
if (['greet', 'status', 'quip'].includes(opts.positional[0])) opts.command = opts.positional.shift();
|
|
45
|
+
if (!opts.name && opts.positional.length) opts.name = opts.positional.join(' ');
|
|
46
|
+
return opts;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function main() {
|
|
50
|
+
let opts;
|
|
51
|
+
try { opts = parse(process.argv.slice(2)); } catch (e) {
|
|
52
|
+
console.error(`Error: ${e.message}\n\n${HELP}`);
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
if (opts.help) return console.log(HELP);
|
|
56
|
+
if (opts.version) return console.log(pkg.version);
|
|
57
|
+
|
|
58
|
+
const name = opts.name || defaultName();
|
|
59
|
+
try {
|
|
60
|
+
if (opts.command === 'status') console.log(statusReport({ name }));
|
|
61
|
+
else if (opts.command === 'quip') console.log(quip());
|
|
62
|
+
else console.log(greet(name, { style: opts.style }));
|
|
63
|
+
} catch (e) {
|
|
64
|
+
console.error(`Error: ${e.message}`);
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
main();
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export type GreetingStyle = 'formal' | 'casual' | 'butler';
|
|
2
|
+
export type PartOfDay = 'morning' | 'afternoon' | 'evening' | 'night';
|
|
3
|
+
|
|
4
|
+
export interface GreetOptions {
|
|
5
|
+
/** Greeting style. Default: "formal". */
|
|
6
|
+
style?: GreetingStyle;
|
|
7
|
+
/** Date used to pick morning/afternoon/evening. Default: now. */
|
|
8
|
+
date?: Date;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface SystemInfo {
|
|
12
|
+
hostname: string;
|
|
13
|
+
platform: string;
|
|
14
|
+
arch: string;
|
|
15
|
+
cpus: number;
|
|
16
|
+
memoryTotal: number;
|
|
17
|
+
memoryFree: number;
|
|
18
|
+
memoryUsedPercent: number;
|
|
19
|
+
uptimeSeconds: number;
|
|
20
|
+
nodeVersion: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Time-aware greeting. */
|
|
24
|
+
export function greet(name?: string, options?: GreetOptions): string;
|
|
25
|
+
/** Part of the day for a date. */
|
|
26
|
+
export function timeOfDay(date?: Date): PartOfDay;
|
|
27
|
+
/** 3725 -> "1h 2m 5s" */
|
|
28
|
+
export function formatDuration(seconds: number): string;
|
|
29
|
+
/** 1536 -> "1.5 KB" */
|
|
30
|
+
export function formatBytes(bytes: number): string;
|
|
31
|
+
/** Information about the current machine. */
|
|
32
|
+
export function systemInfo(): SystemInfo;
|
|
33
|
+
/** Multi-line status report about the current machine. */
|
|
34
|
+
export function statusReport(options?: { name?: string }): string;
|
|
35
|
+
/** A random witty line. */
|
|
36
|
+
export function quip(random?: () => number): string;
|
|
37
|
+
/** All supported greeting styles. */
|
|
38
|
+
export const STYLES: GreetingStyle[];
|
package/index.js
CHANGED
|
@@ -1,5 +1,166 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* jarvis-vraj
|
|
5
|
+
* A small, friendly assistant toolkit for Node.js:
|
|
6
|
+
* time-aware greetings, a system status report, duration formatting and quips.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const os = require('os');
|
|
10
|
+
|
|
11
|
+
const STYLES = ['formal', 'casual', 'butler'];
|
|
12
|
+
|
|
13
|
+
const QUIPS = [
|
|
14
|
+
'All systems nominal. Coffee levels, however, are concerning.',
|
|
15
|
+
'I have run the numbers. They ran back.',
|
|
16
|
+
'Your code compiled on the first try. I have logged this as a historic event.',
|
|
17
|
+
'Shall I schedule a break? Your keyboard has filed a complaint.',
|
|
18
|
+
'Diagnostics complete. The bug was, as suspected, a missing semicolon.',
|
|
19
|
+
'Backing up your work. Optimism is not a backup strategy.',
|
|
20
|
+
'I took the liberty of closing 47 browser tabs. You are welcome.',
|
|
21
|
+
'Today’s forecast: 90% chance of productivity, 10% chance of meetings.',
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Work out the part of the day for a given date.
|
|
26
|
+
* @param {Date} [date=new Date()]
|
|
27
|
+
* @returns {'morning'|'afternoon'|'evening'|'night'}
|
|
28
|
+
*/
|
|
29
|
+
function timeOfDay(date = new Date()) {
|
|
30
|
+
if (!(date instanceof Date) || Number.isNaN(date.getTime())) {
|
|
31
|
+
throw new TypeError('timeOfDay: "date" must be a valid Date');
|
|
32
|
+
}
|
|
33
|
+
const h = date.getHours();
|
|
34
|
+
if (h >= 5 && h < 12) return 'morning';
|
|
35
|
+
if (h >= 12 && h < 17) return 'afternoon';
|
|
36
|
+
if (h >= 17 && h < 21) return 'evening';
|
|
37
|
+
return 'night';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Greet someone, JARVIS style.
|
|
42
|
+
* @param {string} [name='sir']
|
|
43
|
+
* @param {{ style?: 'formal'|'casual'|'butler', date?: Date }} [options]
|
|
44
|
+
* @returns {string}
|
|
45
|
+
*/
|
|
46
|
+
function greet(name = 'sir', options = {}) {
|
|
47
|
+
if (typeof name !== 'string' || !name.trim()) {
|
|
48
|
+
throw new TypeError('greet: "name" must be a non-empty string');
|
|
49
|
+
}
|
|
50
|
+
const { style = 'formal', date = new Date() } = options;
|
|
51
|
+
if (!STYLES.includes(style)) {
|
|
52
|
+
throw new RangeError(`greet: "style" must be one of ${STYLES.join(', ')}`);
|
|
53
|
+
}
|
|
54
|
+
const who = name.trim();
|
|
55
|
+
const part = timeOfDay(date);
|
|
56
|
+
const partWord = part === 'night' ? 'evening' : part;
|
|
57
|
+
|
|
58
|
+
switch (style) {
|
|
59
|
+
case 'casual':
|
|
60
|
+
return `Hey ${who}! Hope your ${part} is going well.`;
|
|
61
|
+
case 'butler':
|
|
62
|
+
return `Good ${partWord}, ${who}. Your systems are online and awaiting instructions.`;
|
|
63
|
+
default:
|
|
64
|
+
return `Good ${partWord}, ${who}.`;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Turn a number of seconds into readable text, e.g. 3725 -> "1h 2m 5s".
|
|
70
|
+
* @param {number} seconds
|
|
71
|
+
* @returns {string}
|
|
72
|
+
*/
|
|
73
|
+
function formatDuration(seconds) {
|
|
74
|
+
if (typeof seconds !== 'number' || !Number.isFinite(seconds) || seconds < 0) {
|
|
75
|
+
throw new TypeError('formatDuration: "seconds" must be a non-negative number');
|
|
76
|
+
}
|
|
77
|
+
let s = Math.floor(seconds);
|
|
78
|
+
const d = Math.floor(s / 86400); s %= 86400;
|
|
79
|
+
const h = Math.floor(s / 3600); s %= 3600;
|
|
80
|
+
const m = Math.floor(s / 60); s %= 60;
|
|
81
|
+
const parts = [];
|
|
82
|
+
if (d) parts.push(`${d}d`);
|
|
83
|
+
if (h) parts.push(`${h}h`);
|
|
84
|
+
if (m) parts.push(`${m}m`);
|
|
85
|
+
if (s || parts.length === 0) parts.push(`${s}s`);
|
|
86
|
+
return parts.join(' ');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Turn bytes into readable text, e.g. 1536 -> "1.5 KB".
|
|
91
|
+
* @param {number} bytes
|
|
92
|
+
* @returns {string}
|
|
93
|
+
*/
|
|
94
|
+
function formatBytes(bytes) {
|
|
95
|
+
if (typeof bytes !== 'number' || !Number.isFinite(bytes) || bytes < 0) {
|
|
96
|
+
throw new TypeError('formatBytes: "bytes" must be a non-negative number');
|
|
97
|
+
}
|
|
98
|
+
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
|
99
|
+
let i = 0;
|
|
100
|
+
let v = bytes;
|
|
101
|
+
while (v >= 1024 && i < units.length - 1) { v /= 1024; i++; }
|
|
102
|
+
return `${i === 0 ? v : v.toFixed(1)} ${units[i]}`;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Collect information about the machine this code is running on.
|
|
107
|
+
* @returns {{ hostname: string, platform: string, arch: string, cpus: number,
|
|
108
|
+
* memoryTotal: number, memoryFree: number, memoryUsedPercent: number,
|
|
109
|
+
* uptimeSeconds: number, nodeVersion: string }}
|
|
110
|
+
*/
|
|
111
|
+
function systemInfo() {
|
|
112
|
+
const total = os.totalmem();
|
|
113
|
+
const free = os.freemem();
|
|
114
|
+
return {
|
|
115
|
+
hostname: os.hostname(),
|
|
116
|
+
platform: os.platform(),
|
|
117
|
+
arch: os.arch(),
|
|
118
|
+
cpus: os.cpus().length,
|
|
119
|
+
memoryTotal: total,
|
|
120
|
+
memoryFree: free,
|
|
121
|
+
memoryUsedPercent: Math.round(((total - free) / total) * 100),
|
|
122
|
+
uptimeSeconds: Math.floor(os.uptime()),
|
|
123
|
+
nodeVersion: process.version,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* A multi-line status report about this machine.
|
|
129
|
+
* @param {{ name?: string }} [options]
|
|
130
|
+
* @returns {string}
|
|
131
|
+
*/
|
|
132
|
+
function statusReport(options = {}) {
|
|
133
|
+
const { name = 'sir' } = options;
|
|
134
|
+
const info = systemInfo();
|
|
135
|
+
const used = info.memoryTotal - info.memoryFree;
|
|
136
|
+
const health = info.memoryUsedPercent >= 90 ? 'Memory is running hot.' : 'All systems nominal.';
|
|
137
|
+
return [
|
|
138
|
+
`Status report for ${name}:`,
|
|
139
|
+
` Host ${info.hostname} (${info.platform}/${info.arch})`,
|
|
140
|
+
` CPU ${info.cpus} cores`,
|
|
141
|
+
` Memory ${formatBytes(used)} of ${formatBytes(info.memoryTotal)} used (${info.memoryUsedPercent}%)`,
|
|
142
|
+
` Uptime ${formatDuration(info.uptimeSeconds)}`,
|
|
143
|
+
` Node.js ${info.nodeVersion}`,
|
|
144
|
+
` ${health}`,
|
|
145
|
+
].join('\n');
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* A random witty line.
|
|
150
|
+
* @param {() => number} [random=Math.random] Inject your own RNG for predictable output.
|
|
151
|
+
* @returns {string}
|
|
152
|
+
*/
|
|
153
|
+
function quip(random = Math.random) {
|
|
154
|
+
return QUIPS[Math.floor(random() * QUIPS.length) % QUIPS.length];
|
|
3
155
|
}
|
|
4
156
|
|
|
5
|
-
module.exports = {
|
|
157
|
+
module.exports = {
|
|
158
|
+
greet,
|
|
159
|
+
timeOfDay,
|
|
160
|
+
formatDuration,
|
|
161
|
+
formatBytes,
|
|
162
|
+
systemInfo,
|
|
163
|
+
statusReport,
|
|
164
|
+
quip,
|
|
165
|
+
STYLES,
|
|
166
|
+
};
|
package/package.json
CHANGED
|
@@ -1,16 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jarvis-vraj",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"description": "A friendly assistant toolkit for Node.js: time-aware greetings, system status reports, duration/byte formatting and witty quips, plus a CLI.",
|
|
5
5
|
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./index.d.ts",
|
|
10
|
+
"default": "./index.js"
|
|
11
|
+
},
|
|
12
|
+
"./package.json": "./package.json"
|
|
13
|
+
},
|
|
14
|
+
"bin": {
|
|
15
|
+
"jarvis-vraj": "bin/cli.js"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"index.js",
|
|
19
|
+
"index.d.ts",
|
|
20
|
+
"bin"
|
|
21
|
+
],
|
|
6
22
|
"scripts": {
|
|
7
|
-
"test": "
|
|
23
|
+
"test": "node --test",
|
|
24
|
+
"prepublishOnly": "npm test"
|
|
8
25
|
},
|
|
9
|
-
"keywords": [
|
|
10
|
-
|
|
26
|
+
"keywords": [
|
|
27
|
+
"jarvis",
|
|
28
|
+
"assistant",
|
|
29
|
+
"greeting",
|
|
30
|
+
"greet",
|
|
31
|
+
"cli",
|
|
32
|
+
"system-info",
|
|
33
|
+
"status",
|
|
34
|
+
"uptime",
|
|
35
|
+
"format-duration",
|
|
36
|
+
"format-bytes"
|
|
37
|
+
],
|
|
38
|
+
"author": "Vraj Raval",
|
|
11
39
|
"license": "MIT",
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
]
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=18"
|
|
42
|
+
}
|
|
16
43
|
}
|