@brianbuie/node-kit 0.10.0 → 0.11.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 +95 -44
- package/dist/index.d.mts +34 -12
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +72 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -2
- package/src/Cache.ts +3 -4
- package/src/Dir.test.ts +4 -4
- package/src/Dir.ts +18 -15
- package/src/File.test.ts +1 -1
- package/src/Format.test.ts +34 -0
- package/src/Format.ts +49 -0
- package/src/index.ts +1 -0
- package/src/snapshot.test.ts +2 -2
- package/tsconfig.json +11 -0
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# Node Kit
|
|
4
4
|
|
|
5
|
-
Basic tools for
|
|
5
|
+
Basic tools for Node.js projects
|
|
6
6
|
|
|
7
7
|
# Installing
|
|
8
8
|
|
|
@@ -18,7 +18,7 @@ import { Fetcher, Log } from '@brianbuie/node-kit';
|
|
|
18
18
|
|
|
19
19
|
<!--#region ts2md-api-merged-here-->
|
|
20
20
|
|
|
21
|
-
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
21
|
+
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
22
22
|
|
|
23
23
|
# Classes
|
|
24
24
|
|
|
@@ -32,11 +32,12 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types
|
|
|
32
32
|
| [FileTypeCsv](#class-filetypecsv) |
|
|
33
33
|
| [FileTypeJson](#class-filetypejson) |
|
|
34
34
|
| [FileTypeNdjson](#class-filetypendjson) |
|
|
35
|
+
| [Format](#class-format) |
|
|
35
36
|
| [Log](#class-log) |
|
|
36
37
|
| [TempDir](#class-tempdir) |
|
|
37
38
|
| [TypeWriter](#class-typewriter) |
|
|
38
39
|
|
|
39
|
-
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
40
|
+
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
40
41
|
|
|
41
42
|
---
|
|
42
43
|
|
|
@@ -59,24 +60,24 @@ export class Cache<T> {
|
|
|
59
60
|
}
|
|
60
61
|
```
|
|
61
62
|
|
|
62
|
-
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
63
|
+
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
63
64
|
|
|
64
65
|
---
|
|
65
66
|
## Class: Dir
|
|
66
67
|
|
|
67
|
-
Reference to a specific directory with
|
|
68
|
-
|
|
68
|
+
Reference to a specific directory with methods to create and list files.
|
|
69
|
+
Created immediately if it doesn't exist
|
|
69
70
|
|
|
70
71
|
```ts
|
|
71
72
|
export class Dir {
|
|
72
73
|
path;
|
|
73
|
-
constructor(
|
|
74
|
-
create()
|
|
74
|
+
constructor(inputPath = "./")
|
|
75
75
|
dir(subPath: string)
|
|
76
76
|
tempDir(subPath: string)
|
|
77
|
-
sanitize(
|
|
77
|
+
sanitize(filename: string)
|
|
78
78
|
filepath(base: string)
|
|
79
79
|
file(base: string)
|
|
80
|
+
get files()
|
|
80
81
|
}
|
|
81
82
|
```
|
|
82
83
|
|
|
@@ -87,7 +88,7 @@ export class Dir {
|
|
|
87
88
|
### Constructor
|
|
88
89
|
|
|
89
90
|
```ts
|
|
90
|
-
constructor(
|
|
91
|
+
constructor(inputPath = "./")
|
|
91
92
|
```
|
|
92
93
|
|
|
93
94
|
Argument Details
|
|
@@ -106,15 +107,15 @@ dir(subPath: string)
|
|
|
106
107
|
Argument Details
|
|
107
108
|
|
|
108
109
|
+ **subPath**
|
|
109
|
-
+ to create
|
|
110
|
+
+ relative path to create
|
|
110
111
|
|
|
111
112
|
Example
|
|
112
113
|
|
|
113
114
|
```ts
|
|
114
115
|
const folder = new Dir('example');
|
|
115
|
-
// folder.path = '
|
|
116
|
+
// folder.path = '/absolute/path/to/example'
|
|
116
117
|
const child = folder.dir('path/to/dir');
|
|
117
|
-
// child.path = '
|
|
118
|
+
// child.path = '/absolute/path/to/example/path/to/dir'
|
|
118
119
|
```
|
|
119
120
|
|
|
120
121
|
### Method filepath
|
|
@@ -138,7 +139,7 @@ const filepath = folder.resolve('file.json');
|
|
|
138
139
|
|
|
139
140
|
</details>
|
|
140
141
|
|
|
141
|
-
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
142
|
+
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
142
143
|
|
|
143
144
|
---
|
|
144
145
|
## Class: Fetcher
|
|
@@ -236,7 +237,7 @@ See also: [FetchOptions](#type-fetchoptions), [Route](#type-route)
|
|
|
236
237
|
|
|
237
238
|
</details>
|
|
238
239
|
|
|
239
|
-
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
240
|
+
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
240
241
|
|
|
241
242
|
---
|
|
242
243
|
## Class: File
|
|
@@ -297,7 +298,7 @@ lines as strings, removes trailing '\n'
|
|
|
297
298
|
|
|
298
299
|
</details>
|
|
299
300
|
|
|
300
|
-
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
301
|
+
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
301
302
|
|
|
302
303
|
---
|
|
303
304
|
## Class: FileType
|
|
@@ -314,7 +315,7 @@ export class FileType {
|
|
|
314
315
|
}
|
|
315
316
|
```
|
|
316
317
|
|
|
317
|
-
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
318
|
+
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
318
319
|
|
|
319
320
|
---
|
|
320
321
|
## Class: FileTypeCsv
|
|
@@ -333,7 +334,7 @@ export class FileTypeCsv<Row extends object> extends FileType {
|
|
|
333
334
|
|
|
334
335
|
See also: [FileType](#class-filetype)
|
|
335
336
|
|
|
336
|
-
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
337
|
+
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
337
338
|
|
|
338
339
|
---
|
|
339
340
|
## Class: FileTypeJson
|
|
@@ -351,7 +352,7 @@ export class FileTypeJson<T> extends FileType {
|
|
|
351
352
|
|
|
352
353
|
See also: [FileType](#class-filetype)
|
|
353
354
|
|
|
354
|
-
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
355
|
+
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
355
356
|
|
|
356
357
|
---
|
|
357
358
|
## Class: FileTypeNdjson
|
|
@@ -368,7 +369,58 @@ export class FileTypeNdjson<T extends object> extends FileType {
|
|
|
368
369
|
|
|
369
370
|
See also: [FileType](#class-filetype)
|
|
370
371
|
|
|
371
|
-
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
372
|
+
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
373
|
+
|
|
374
|
+
---
|
|
375
|
+
## Class: Format
|
|
376
|
+
|
|
377
|
+
Helpers for formatting dates, times, and numbers as strings
|
|
378
|
+
|
|
379
|
+
```ts
|
|
380
|
+
export class Format {
|
|
381
|
+
static date(formatStr: "iso" | "ymd" | string = "iso", d: DateArg<Date> = new Date())
|
|
382
|
+
static round(n: number, places = 0)
|
|
383
|
+
static ms(ms: number)
|
|
384
|
+
static bytes(b: number)
|
|
385
|
+
}
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
<details>
|
|
389
|
+
|
|
390
|
+
<summary>Class Format Details</summary>
|
|
391
|
+
|
|
392
|
+
### Method date
|
|
393
|
+
|
|
394
|
+
date-fns format() with some shortcuts
|
|
395
|
+
|
|
396
|
+
```ts
|
|
397
|
+
static date(formatStr: "iso" | "ymd" | string = "iso", d: DateArg<Date> = new Date())
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
Argument Details
|
|
401
|
+
|
|
402
|
+
+ **formatStr**
|
|
403
|
+
+ 'iso' to get ISO date, 'ymd' to format as 'yyyy-MM-dd', full options: https://date-fns.org/v4.1.0/docs/format
|
|
404
|
+
|
|
405
|
+
### Method ms
|
|
406
|
+
|
|
407
|
+
Make millisecond durations actually readable (eg "123ms", "3.56s", "1m 34s", "3h 24m", "2d 4h")
|
|
408
|
+
|
|
409
|
+
```ts
|
|
410
|
+
static ms(ms: number)
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
### Method round
|
|
414
|
+
|
|
415
|
+
Round a number to a specific set of places
|
|
416
|
+
|
|
417
|
+
```ts
|
|
418
|
+
static round(n: number, places = 0)
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
</details>
|
|
422
|
+
|
|
423
|
+
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
372
424
|
|
|
373
425
|
---
|
|
374
426
|
## Class: Log
|
|
@@ -433,7 +485,7 @@ static prepare(...input: unknown[]): {
|
|
|
433
485
|
|
|
434
486
|
</details>
|
|
435
487
|
|
|
436
|
-
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
488
|
+
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
437
489
|
|
|
438
490
|
---
|
|
439
491
|
## Class: TempDir
|
|
@@ -448,7 +500,7 @@ export class TempDir extends Dir {
|
|
|
448
500
|
|
|
449
501
|
See also: [Dir](#class-dir)
|
|
450
502
|
|
|
451
|
-
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
503
|
+
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
452
504
|
|
|
453
505
|
---
|
|
454
506
|
## Class: TypeWriter
|
|
@@ -482,7 +534,7 @@ async toString()
|
|
|
482
534
|
|
|
483
535
|
</details>
|
|
484
536
|
|
|
485
|
-
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
537
|
+
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
486
538
|
|
|
487
539
|
---
|
|
488
540
|
# Functions
|
|
@@ -490,9 +542,10 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types
|
|
|
490
542
|
| |
|
|
491
543
|
| --- |
|
|
492
544
|
| [snapshot](#function-snapshot) |
|
|
545
|
+
| [temp](#function-temp) |
|
|
493
546
|
| [timeout](#function-timeout) |
|
|
494
547
|
|
|
495
|
-
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
548
|
+
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
496
549
|
|
|
497
550
|
---
|
|
498
551
|
|
|
@@ -505,7 +558,18 @@ functions are removed
|
|
|
505
558
|
export function snapshot(i: unknown, max = 50, depth = 0): any
|
|
506
559
|
```
|
|
507
560
|
|
|
508
|
-
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
561
|
+
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
562
|
+
|
|
563
|
+
---
|
|
564
|
+
## Function: temp
|
|
565
|
+
|
|
566
|
+
Creates a '.temp' directory in current working directory
|
|
567
|
+
|
|
568
|
+
```ts
|
|
569
|
+
export function temp()
|
|
570
|
+
```
|
|
571
|
+
|
|
572
|
+
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
509
573
|
|
|
510
574
|
---
|
|
511
575
|
## Function: timeout
|
|
@@ -514,7 +578,7 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types
|
|
|
514
578
|
export async function timeout(ms: number)
|
|
515
579
|
```
|
|
516
580
|
|
|
517
|
-
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
581
|
+
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
518
582
|
|
|
519
583
|
---
|
|
520
584
|
# Types
|
|
@@ -525,7 +589,7 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types
|
|
|
525
589
|
| [Query](#type-query) |
|
|
526
590
|
| [Route](#type-route) |
|
|
527
591
|
|
|
528
|
-
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
592
|
+
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
529
593
|
|
|
530
594
|
---
|
|
531
595
|
|
|
@@ -545,7 +609,7 @@ export type FetchOptions = RequestInit & {
|
|
|
545
609
|
|
|
546
610
|
See also: [Query](#type-query), [timeout](#function-timeout)
|
|
547
611
|
|
|
548
|
-
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
612
|
+
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
549
613
|
|
|
550
614
|
---
|
|
551
615
|
## Type: Query
|
|
@@ -554,7 +618,7 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types
|
|
|
554
618
|
export type Query = Record<string, QueryVal | QueryVal[]>
|
|
555
619
|
```
|
|
556
620
|
|
|
557
|
-
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
621
|
+
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
558
622
|
|
|
559
623
|
---
|
|
560
624
|
## Type: Route
|
|
@@ -563,21 +627,8 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types
|
|
|
563
627
|
export type Route = string | URL
|
|
564
628
|
```
|
|
565
629
|
|
|
566
|
-
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
567
|
-
|
|
568
|
-
---
|
|
569
|
-
# Variables
|
|
570
|
-
|
|
571
|
-
## Variable: temp
|
|
572
|
-
|
|
573
|
-
```ts
|
|
574
|
-
temp = new TempDir(".temp")
|
|
575
|
-
```
|
|
576
|
-
|
|
577
|
-
See also: [TempDir](#class-tempdir)
|
|
578
|
-
|
|
579
|
-
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
630
|
+
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types)
|
|
580
631
|
|
|
581
632
|
---
|
|
582
633
|
|
|
583
|
-
<!--#endregion ts2md-api-merged-here-->
|
|
634
|
+
<!--#endregion ts2md-api-merged-here-->
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
2
|
import { Readable } from "node:stream";
|
|
3
|
-
import { Duration } from "date-fns";
|
|
3
|
+
import { DateArg, Duration } from "date-fns";
|
|
4
4
|
import { ChalkInstance } from "chalk";
|
|
5
5
|
import * as qt from "quicktype-core";
|
|
6
6
|
import * as quicktype_core_dist_TargetLanguage_js0 from "quicktype-core/dist/TargetLanguage.js";
|
|
@@ -90,28 +90,27 @@ declare class FileTypeCsv<Row extends object> extends FileType {
|
|
|
90
90
|
//#endregion
|
|
91
91
|
//#region src/Dir.d.ts
|
|
92
92
|
/**
|
|
93
|
-
* Reference to a specific directory with
|
|
94
|
-
*
|
|
93
|
+
* Reference to a specific directory with methods to create and list files.
|
|
94
|
+
* Created immediately if it doesn't exist
|
|
95
95
|
*/
|
|
96
96
|
declare class Dir {
|
|
97
97
|
path: string;
|
|
98
98
|
/**
|
|
99
99
|
* @param path can be relative to workspace or absolute
|
|
100
100
|
*/
|
|
101
|
-
constructor(
|
|
102
|
-
create(): void;
|
|
101
|
+
constructor(inputPath?: string);
|
|
103
102
|
/**
|
|
104
103
|
* Create a new Dir inside the current Dir
|
|
105
|
-
* @param subPath to create
|
|
104
|
+
* @param subPath relative path to create
|
|
106
105
|
* @example
|
|
107
106
|
* const folder = new Dir('example');
|
|
108
|
-
* // folder.path = '
|
|
107
|
+
* // folder.path = '/absolute/path/to/example'
|
|
109
108
|
* const child = folder.dir('path/to/dir');
|
|
110
|
-
* // child.path = '
|
|
109
|
+
* // child.path = '/absolute/path/to/example/path/to/dir'
|
|
111
110
|
*/
|
|
112
111
|
dir(subPath: string): Dir;
|
|
113
112
|
tempDir(subPath: string): TempDir;
|
|
114
|
-
sanitize(
|
|
113
|
+
sanitize(filename: string): string;
|
|
115
114
|
/**
|
|
116
115
|
* @param base - The file name with extension
|
|
117
116
|
* @example
|
|
@@ -121,6 +120,7 @@ declare class Dir {
|
|
|
121
120
|
*/
|
|
122
121
|
filepath(base: string): string;
|
|
123
122
|
file(base: string): File;
|
|
123
|
+
get files(): File[];
|
|
124
124
|
}
|
|
125
125
|
/**
|
|
126
126
|
* Extends Dir class with method to `clear()` contents
|
|
@@ -129,9 +129,9 @@ declare class TempDir extends Dir {
|
|
|
129
129
|
clear(): void;
|
|
130
130
|
}
|
|
131
131
|
/**
|
|
132
|
-
*
|
|
132
|
+
* Creates a '.temp' directory in current working directory
|
|
133
133
|
*/
|
|
134
|
-
declare
|
|
134
|
+
declare function temp(): TempDir;
|
|
135
135
|
//#endregion
|
|
136
136
|
//#region src/Cache.d.ts
|
|
137
137
|
/**
|
|
@@ -216,6 +216,28 @@ declare class Fetcher {
|
|
|
216
216
|
fetchJson<T>(route: Route, opts?: FetchOptions): Promise<[T, Response, Request]>;
|
|
217
217
|
}
|
|
218
218
|
//#endregion
|
|
219
|
+
//#region src/Format.d.ts
|
|
220
|
+
/**
|
|
221
|
+
* Helpers for formatting dates, times, and numbers as strings
|
|
222
|
+
*/
|
|
223
|
+
declare class Format {
|
|
224
|
+
/**
|
|
225
|
+
* date-fns format() with some shortcuts
|
|
226
|
+
* @param formatStr
|
|
227
|
+
* 'iso' to get ISO date, 'ymd' to format as 'yyyy-MM-dd', full options: https://date-fns.org/v4.1.0/docs/format
|
|
228
|
+
*/
|
|
229
|
+
static date(formatStr?: 'iso' | 'ymd' | string, d?: DateArg<Date>): string;
|
|
230
|
+
/**
|
|
231
|
+
* Round a number to a specific set of places
|
|
232
|
+
*/
|
|
233
|
+
static round(n: number, places?: number): string;
|
|
234
|
+
/**
|
|
235
|
+
* Make millisecond durations actually readable (eg "123ms", "3.56s", "1m 34s", "3h 24m", "2d 4h")
|
|
236
|
+
*/
|
|
237
|
+
static ms(ms: number): string;
|
|
238
|
+
static bytes(b: number): string;
|
|
239
|
+
}
|
|
240
|
+
//#endregion
|
|
219
241
|
//#region src/Log.d.ts
|
|
220
242
|
type Severity = 'DEFAULT' | 'DEBUG' | 'INFO' | 'NOTICE' | 'WARNING' | 'ERROR' | 'CRITICAL' | 'ALERT' | 'EMERGENCY';
|
|
221
243
|
type Options = {
|
|
@@ -722,5 +744,5 @@ declare class TypeWriter {
|
|
|
722
744
|
toFile(): Promise<void>;
|
|
723
745
|
}
|
|
724
746
|
//#endregion
|
|
725
|
-
export { Cache, Dir, type FetchOptions, Fetcher, File, FileType, FileTypeCsv, FileTypeJson, FileTypeNdjson, Log, type Query, type Route, TempDir, TypeWriter, snapshot, temp, timeout };
|
|
747
|
+
export { Cache, Dir, type FetchOptions, Fetcher, File, FileType, FileTypeCsv, FileTypeJson, FileTypeNdjson, Format, Log, type Query, type Route, TempDir, TypeWriter, snapshot, temp, timeout };
|
|
726
748
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/File.ts","../src/Dir.ts","../src/Cache.ts","../src/Fetcher.ts","../src/Log.ts","../src/snapshot.ts","../src/timeout.ts","../src/TypeWriter.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;;;cAUa,IAAA;;;;;;;;;;;EAAA;;;EA0CI,KAAA,CAAA,CAAA,EAAA,MAAA,EAAA;EAKU,IAAA,UAAA,CAAA,CAAA,EATX,EAAA,CAAA,UASW,GATX,QASW;EAAc,IAAA,WAAA,CAAA,CAAA,EALxB,EAAA,CAAA,WAKwB;EAiBpB,KAAA,CAAA,QAAA,EAAA,MAAA,GAjBM,cAiBN,CAAA,EAAA,IAAA,GAjBoB,OAiBpB,CAAA,IAAA,CAAA;EAIA;;;;EAQc,MAAA,CAAA,KAAA,EAAA,MAAA,GAAA,MAAA,EAAA,C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YAAA,8DAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MA/BoD,QAAQ,EAAA,CAAG;4CAgB9B;cAK/B;YAUF"}
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/File.ts","../src/Dir.ts","../src/Cache.ts","../src/Fetcher.ts","../src/Format.ts","../src/Log.ts","../src/snapshot.ts","../src/timeout.ts","../src/TypeWriter.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;;;cAUa,IAAA;;;;;;;;;;;EAAA;;;EA0CI,KAAA,CAAA,CAAA,EAAA,MAAA,EAAA;EAKU,IAAA,UAAA,CAAA,CAAA,EATX,EAAA,CAAA,UASW,GATX,QASW;EAAc,IAAA,WAAA,CAAA,CAAA,EALxB,EAAA,CAAA,WAKwB;EAiBpB,KAAA,CAAA,QAAA,EAAA,MAAA,GAjBM,cAiBN,CAAA,EAAA,IAAA,GAjBoB,OAiBpB,CAAA,IAAA,CAAA;EAIA;;;;EAQc,MAAA,CAAA,KAAA,EAAA,MAAA,GAAA,MAAA,EAAA,CAAA,EAAA,IAAA;EAAI,WAAA,QAAA,CAAA,CAAA,EAAA,OAZlB,QAYkB;EAAG,IAAA,CAAA,CAAA,CAAA,CAAA,QAAA,CAAA,EARrB,CAQqB,CAAA,EARpB,YAQoB,CARpB,CAQoB,CAAA;EAAA,WAAA,IAAA,CAAA,CAAA,EAAA,OAJzB,YAIyB;EAIvB,MAAA,CAAA,UAAA,MAAA,CAAA,CAAA,KAAA,CAAA,EAJgB,CAIhB,GAJoB,CAIpB,EAAA,CAAA,EAJuB,cAIvB,CAJuB,CAIvB,CAAA;EAIkB,WAAA,MAAA,CAAA,CAAA,EAAA,OAJlB,cAIkB;EAAmB,GAAA,CAAA,UAAA,MAAA,CAAA,CAAA,IAAA,CAAA,EAAnB,CAAmB,EAAA,EAAA,IAAA,CAAA,EAAA,CAAA,MAAA,CAAA,CAAA,EAAA,CAA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
|
5
5
|
import { finished } from "node:stream/promises";
|
|
6
6
|
import { parseStream, writeToStream } from "fast-csv";
|
|
7
7
|
import { isObjectLike, merge } from "lodash-es";
|
|
8
|
-
import { add, isAfter } from "date-fns";
|
|
8
|
+
import { add, format, formatISO, isAfter } from "date-fns";
|
|
9
9
|
import extractDomain from "extract-domain";
|
|
10
10
|
import { inspect } from "node:util";
|
|
11
11
|
import chalk from "chalk";
|
|
@@ -211,28 +211,26 @@ var FileTypeCsv = class extends FileType {
|
|
|
211
211
|
//#endregion
|
|
212
212
|
//#region src/Dir.ts
|
|
213
213
|
/**
|
|
214
|
-
* Reference to a specific directory with
|
|
215
|
-
*
|
|
214
|
+
* Reference to a specific directory with methods to create and list files.
|
|
215
|
+
* Created immediately if it doesn't exist
|
|
216
216
|
*/
|
|
217
217
|
var Dir = class Dir {
|
|
218
218
|
path;
|
|
219
219
|
/**
|
|
220
220
|
* @param path can be relative to workspace or absolute
|
|
221
221
|
*/
|
|
222
|
-
constructor(
|
|
223
|
-
this.path = path.resolve(
|
|
224
|
-
}
|
|
225
|
-
create() {
|
|
222
|
+
constructor(inputPath = "./") {
|
|
223
|
+
this.path = path.resolve(inputPath);
|
|
226
224
|
fs.mkdirSync(this.path, { recursive: true });
|
|
227
225
|
}
|
|
228
226
|
/**
|
|
229
227
|
* Create a new Dir inside the current Dir
|
|
230
|
-
* @param subPath to create
|
|
228
|
+
* @param subPath relative path to create
|
|
231
229
|
* @example
|
|
232
230
|
* const folder = new Dir('example');
|
|
233
|
-
* // folder.path = '
|
|
231
|
+
* // folder.path = '/absolute/path/to/example'
|
|
234
232
|
* const child = folder.dir('path/to/dir');
|
|
235
|
-
* // child.path = '
|
|
233
|
+
* // child.path = '/absolute/path/to/example/path/to/dir'
|
|
236
234
|
*/
|
|
237
235
|
dir(subPath) {
|
|
238
236
|
return new Dir(path.resolve(this.path, subPath));
|
|
@@ -240,8 +238,8 @@ var Dir = class Dir {
|
|
|
240
238
|
tempDir(subPath) {
|
|
241
239
|
return new TempDir(path.resolve(this.path, subPath));
|
|
242
240
|
}
|
|
243
|
-
sanitize(
|
|
244
|
-
return sanitizeFilename(
|
|
241
|
+
sanitize(filename) {
|
|
242
|
+
return sanitizeFilename(filename.replace("https://", "").replace("www.", ""), { replacement: "_" }).slice(-200);
|
|
245
243
|
}
|
|
246
244
|
/**
|
|
247
245
|
* @param base - The file name with extension
|
|
@@ -256,6 +254,9 @@ var Dir = class Dir {
|
|
|
256
254
|
file(base) {
|
|
257
255
|
return new File(this.filepath(base));
|
|
258
256
|
}
|
|
257
|
+
get files() {
|
|
258
|
+
return fs.readdirSync(this.path).map((filename) => this.file(filename));
|
|
259
|
+
}
|
|
259
260
|
};
|
|
260
261
|
/**
|
|
261
262
|
* Extends Dir class with method to `clear()` contents
|
|
@@ -266,17 +267,18 @@ var TempDir = class extends Dir {
|
|
|
266
267
|
recursive: true,
|
|
267
268
|
force: true
|
|
268
269
|
});
|
|
269
|
-
this.
|
|
270
|
+
fs.mkdirSync(this.path, { recursive: true });
|
|
270
271
|
}
|
|
271
272
|
};
|
|
272
273
|
/**
|
|
273
|
-
*
|
|
274
|
+
* Creates a '.temp' directory in current working directory
|
|
274
275
|
*/
|
|
275
|
-
|
|
276
|
+
function temp() {
|
|
277
|
+
return new TempDir(".temp");
|
|
278
|
+
}
|
|
276
279
|
|
|
277
280
|
//#endregion
|
|
278
281
|
//#region src/Cache.ts
|
|
279
|
-
const cacheDir = temp.dir("cache");
|
|
280
282
|
/**
|
|
281
283
|
* Save data to a local file with an expiration.
|
|
282
284
|
* Fresh/stale data is returned with a flag for if it's fresh or not,
|
|
@@ -286,7 +288,7 @@ var Cache = class {
|
|
|
286
288
|
file;
|
|
287
289
|
ttl;
|
|
288
290
|
constructor(key, ttl, initialData) {
|
|
289
|
-
this.file =
|
|
291
|
+
this.file = new TempDir(".cache").file(key).json();
|
|
290
292
|
this.ttl = typeof ttl === "number" ? { minutes: ttl } : ttl;
|
|
291
293
|
if (initialData) this.write(initialData);
|
|
292
294
|
}
|
|
@@ -409,6 +411,58 @@ var Fetcher = class {
|
|
|
409
411
|
}
|
|
410
412
|
};
|
|
411
413
|
|
|
414
|
+
//#endregion
|
|
415
|
+
//#region src/Format.ts
|
|
416
|
+
/**
|
|
417
|
+
* Helpers for formatting dates, times, and numbers as strings
|
|
418
|
+
*/
|
|
419
|
+
var Format = class {
|
|
420
|
+
/**
|
|
421
|
+
* date-fns format() with some shortcuts
|
|
422
|
+
* @param formatStr
|
|
423
|
+
* 'iso' to get ISO date, 'ymd' to format as 'yyyy-MM-dd', full options: https://date-fns.org/v4.1.0/docs/format
|
|
424
|
+
*/
|
|
425
|
+
static date(formatStr = "iso", d = /* @__PURE__ */ new Date()) {
|
|
426
|
+
if (formatStr === "iso") return formatISO(d);
|
|
427
|
+
if (formatStr === "ymd") return format(d, "yyyy-MM-dd");
|
|
428
|
+
return format(d, formatStr);
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Round a number to a specific set of places
|
|
432
|
+
*/
|
|
433
|
+
static round(n, places = 0) {
|
|
434
|
+
return new Intl.NumberFormat("en-US", { maximumFractionDigits: places }).format(n);
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Make millisecond durations actually readable (eg "123ms", "3.56s", "1m 34s", "3h 24m", "2d 4h")
|
|
438
|
+
*/
|
|
439
|
+
static ms(ms) {
|
|
440
|
+
if (ms < 1e3) return `${this.round(ms)}ms`;
|
|
441
|
+
const s = ms / 1e3;
|
|
442
|
+
if (s < 60) return `${this.round(s, 2)}s`;
|
|
443
|
+
const m = Math.floor(s / 60);
|
|
444
|
+
if (m < 60) return `${m}m ${Math.floor(s) % 60}s`;
|
|
445
|
+
const h = Math.floor(m / 60);
|
|
446
|
+
if (h < 24) return `${h}h ${m % 60}m`;
|
|
447
|
+
return `${Math.floor(h / 24)}d ${h % 24}h`;
|
|
448
|
+
}
|
|
449
|
+
static bytes(b) {
|
|
450
|
+
const labels = [
|
|
451
|
+
"b",
|
|
452
|
+
"KB",
|
|
453
|
+
"MB",
|
|
454
|
+
"GB",
|
|
455
|
+
"TB"
|
|
456
|
+
];
|
|
457
|
+
let factor = 0;
|
|
458
|
+
while (b >= 1024 && labels[factor + 1]) {
|
|
459
|
+
b = b / 1024;
|
|
460
|
+
factor++;
|
|
461
|
+
}
|
|
462
|
+
return `${this.round(b, 2)} ${labels[factor]}`;
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
|
|
412
466
|
//#endregion
|
|
413
467
|
//#region src/Log.ts
|
|
414
468
|
var Log = class {
|
|
@@ -569,5 +623,5 @@ var TypeWriter = class {
|
|
|
569
623
|
};
|
|
570
624
|
|
|
571
625
|
//#endregion
|
|
572
|
-
export { Cache, Dir, Fetcher, File, FileType, FileTypeCsv, FileTypeJson, FileTypeNdjson, Log, TempDir, TypeWriter, snapshot, temp, timeout };
|
|
626
|
+
export { Cache, Dir, Fetcher, File, FileType, FileTypeCsv, FileTypeJson, FileTypeNdjson, Format, Log, TempDir, TypeWriter, snapshot, temp, timeout };
|
|
573
627
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["output: Record<string, any>","obj: Record<string, any>","parsed: Row[]","#parseVal","params: [string, string][]","timeout","#toGcloud","#toConsole","#log"],"sources":["../src/snapshot.ts","../src/File.ts","../src/Dir.ts","../src/Cache.ts","../src/Fetcher.ts","../src/Log.ts","../src/timeout.ts","../src/TypeWriter.ts"],"sourcesContent":["import { isObjectLike } from 'lodash-es';\n\n/**\n * Allows special objects (Error, Headers, Set) to be included in JSON.stringify output\n * functions are removed\n */\nexport function snapshot(i: unknown, max = 50, depth = 0): any {\n if (Array.isArray(i)) {\n if (depth === max) return [];\n return i.map((c) => snapshot(c, max, depth + 1));\n }\n if (typeof i === 'function') return undefined;\n if (!isObjectLike(i)) return i;\n\n if (depth === max) return {};\n let output: Record<string, any> = {};\n // @ts-ignore If it has an 'entries' function, use that for looping (eg. Set, Map, Headers)\n if (typeof i.entries === 'function') {\n // @ts-ignore\n for (let [k, v] of i.entries()) {\n output[k] = snapshot(v, max, depth + 1);\n }\n return output;\n }\n\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Enumerability_and_ownership_of_properties\n\n // Get Enumerable, inherited properties\n const obj: Record<string, any> = i!;\n for (let key in obj) {\n output[key] = snapshot(obj[key], max, depth + 1);\n }\n\n // Get Non-enumberable, own properties\n Object.getOwnPropertyNames(obj).forEach((key) => {\n output[key] = snapshot(obj[key], max, depth + 1);\n });\n\n return output;\n}\n","import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { Readable } from 'node:stream';\nimport { finished } from 'node:stream/promises';\nimport { writeToStream, parseStream } from 'fast-csv';\nimport { snapshot } from './snapshot.ts';\n\n/**\n * WARNING: API will change!\n */\nexport class File {\n path;\n root;\n dir;\n base;\n ext;\n name;\n\n constructor(filepath: string) {\n this.path = filepath;\n const { root, dir, base, ext, name } = path.parse(filepath);\n this.root = root;\n this.dir = dir;\n this.base = base;\n this.ext = ext;\n this.name = name;\n }\n\n get exists() {\n return fs.existsSync(this.path);\n }\n\n delete() {\n fs.rmSync(this.path, { force: true });\n }\n\n read() {\n return this.exists ? fs.readFileSync(this.path, 'utf8') : undefined;\n }\n\n /**\n * @returns lines as strings, removes trailing '\\n'\n */\n lines() {\n const contents = (this.read() || '').split('\\n');\n return contents.slice(0, contents.length - 1);\n }\n\n get readStream() {\n return this.exists ? fs.createReadStream(this.path) : Readable.from([]);\n }\n\n get writeStream() {\n fs.mkdirSync(path.parse(this.path).dir, { recursive: true });\n return fs.createWriteStream(this.path);\n }\n\n write(contents: string | ReadableStream) {\n fs.mkdirSync(path.parse(this.path).dir, { recursive: true });\n if (typeof contents === 'string') return fs.writeFileSync(this.path, contents);\n if (contents instanceof ReadableStream) return finished(Readable.from(contents).pipe(this.writeStream));\n throw new Error(`Invalid content type: ${typeof contents}`);\n }\n\n /**\n * creates file if it doesn't exist, appends string or array of strings as new lines.\n * File always ends with '\\n', so contents don't need to be read before appending\n */\n append(lines: string | string[]) {\n if (!this.exists) this.write('');\n const contents = Array.isArray(lines) ? lines.join('\\n') : lines;\n fs.appendFileSync(this.path, contents + '\\n');\n }\n\n static get FileType() {\n return FileType;\n }\n\n json<T>(contents?: T) {\n return new FileTypeJson<T>(this.path, contents);\n }\n\n static get json() {\n return FileTypeJson;\n }\n\n ndjson<T extends object>(lines?: T | T[]) {\n return new FileTypeNdjson<T>(this.path, lines);\n }\n\n static get ndjson() {\n return FileTypeNdjson;\n }\n\n async csv<T extends object>(rows?: T[], keys?: (keyof T)[]) {\n const csvFile = new FileTypeCsv<T>(this.path);\n if (rows) await csvFile.write(rows, keys);\n return csvFile;\n }\n\n static get csv() {\n return FileTypeCsv;\n }\n}\n\n/**\n * A generic file adaptor, extended by specific file type implementations\n */\nexport class FileType {\n file;\n\n constructor(filepath: string, contents?: string) {\n this.file = new File(filepath);\n if (contents) this.file.write(contents);\n }\n\n get exists() {\n return this.file.exists;\n }\n\n get path() {\n return this.file.path;\n }\n\n delete() {\n this.file.delete();\n }\n}\n\n/**\n * A .json file that maintains data type when reading/writing.\n * This is unsafe! Type is not checked at runtime, avoid using on files manipulated outside of your application.\n */\nexport class FileTypeJson<T> extends FileType {\n constructor(filepath: string, contents?: T) {\n super(filepath.endsWith('.json') ? filepath : filepath + '.json');\n if (contents) this.write(contents);\n }\n\n read() {\n const contents = this.file.read();\n return contents ? (JSON.parse(contents) as T) : undefined;\n }\n\n write(contents: T) {\n this.file.write(JSON.stringify(snapshot(contents), null, 2));\n }\n}\n\n/**\n * New-line delimited json file (.ndjson)\n * @see https://jsonltools.com/ndjson-format-specification\n */\nexport class FileTypeNdjson<T extends object> extends FileType {\n constructor(filepath: string, lines?: T | T[]) {\n super(filepath.endsWith('.ndjson') ? filepath : filepath + '.ndjson');\n if (lines) this.append(lines);\n }\n\n append(lines: T | T[]) {\n this.file.append(\n Array.isArray(lines) ? lines.map((l) => JSON.stringify(snapshot(l))) : JSON.stringify(snapshot(lines)),\n );\n }\n\n lines() {\n return this.file.lines().map((l) => JSON.parse(l) as T);\n }\n}\n\ntype Key<T extends object> = keyof T;\n\n/**\n * Comma separated values (.csv).\n * Input rows as objects, keys are used as column headers\n */\nexport class FileTypeCsv<Row extends object> extends FileType {\n constructor(filepath: string) {\n super(filepath.endsWith('.csv') ? filepath : filepath + '.csv');\n }\n\n async write(rows: Row[], keys?: Key<Row>[]) {\n const headerSet = new Set<Key<Row>>();\n if (keys) {\n for (const key of keys) headerSet.add(key);\n } else {\n for (const row of rows) {\n for (const key in row) headerSet.add(key);\n }\n }\n const headers = Array.from(headerSet);\n const outRows = rows.map((row) => headers.map((key) => row[key]));\n return finished(writeToStream(this.file.writeStream, [headers, ...outRows]));\n }\n\n #parseVal(val: string) {\n if (val.toLowerCase() === 'false') return false;\n if (val.toLowerCase() === 'true') return true;\n if (val.length === 0) return null;\n if (/^[\\.0-9]+$/.test(val)) return Number(val);\n return val;\n }\n\n async read() {\n return new Promise<Row[]>((resolve, reject) => {\n const parsed: Row[] = [];\n parseStream(this.file.readStream, { headers: true })\n .on('error', (e) => reject(e))\n .on('data', (raw: Record<Key<Row>, string>) => {\n parsed.push(\n Object.entries(raw).reduce(\n (all, [key, val]) => ({\n ...all,\n [key]: this.#parseVal(val as string),\n }),\n {} as Row,\n ),\n );\n })\n .on('end', () => resolve(parsed));\n });\n }\n}\n","import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport sanitizeFilename from 'sanitize-filename';\nimport { File } from './File.ts';\n\n/**\n * Reference to a specific directory with helpful methods for resolving filepaths,\n * sanitizing filenames, and saving files.\n */\nexport class Dir {\n path;\n\n /**\n * @param path can be relative to workspace or absolute\n */\n constructor(_path = './') {\n this.path = path.resolve(_path);\n }\n\n create() {\n fs.mkdirSync(this.path, { recursive: true });\n }\n\n /**\n * Create a new Dir inside the current Dir\n * @param subPath to create in current Dir\n * @example\n * const folder = new Dir('example');\n * // folder.path = './example'\n * const child = folder.dir('path/to/dir');\n * // child.path = './example/path/to/dir'\n */\n dir(subPath: string) {\n return new Dir(path.resolve(this.path, subPath));\n }\n\n tempDir(subPath: string) {\n return new TempDir(path.resolve(this.path, subPath));\n }\n\n sanitize(name: string) {\n return sanitizeFilename(name.replace('https://', '').replace('www.', ''), { replacement: '_' }).slice(-200);\n }\n\n /**\n * @param base - The file name with extension\n * @example\n * const folder = new Dir('example');\n * const filepath = folder.resolve('file.json');\n * // 'example/file.json'\n */\n filepath(base: string) {\n return path.resolve(this.path, this.sanitize(base));\n }\n\n file(base: string) {\n return new File(this.filepath(base));\n }\n}\n\n/**\n * Extends Dir class with method to `clear()` contents\n */\nexport class TempDir extends Dir {\n clear() {\n fs.rmSync(this.path, { recursive: true, force: true });\n this.create();\n }\n}\n\n/**\n * Common temp dir location\n */\nexport const temp = new TempDir('.temp');\n","import { type Duration, isAfter, add } from 'date-fns';\nimport { temp } from './Dir.ts';\n\nconst cacheDir = temp.dir('cache');\n\n/**\n * Save data to a local file with an expiration.\n * Fresh/stale data is returned with a flag for if it's fresh or not,\n * so stale data can still be used if needed.\n */\nexport class Cache<T> {\n file;\n ttl;\n\n constructor(key: string, ttl: number | Duration, initialData?: T) {\n this.file = cacheDir.file(key).json<{ savedAt: string; data: T }>();\n this.ttl = typeof ttl === 'number' ? { minutes: ttl } : ttl;\n if (initialData) this.write(initialData);\n }\n\n write(data: T) {\n this.file.write({ savedAt: new Date().toUTCString(), data });\n }\n\n read(): [T | undefined, boolean] {\n const { savedAt, data } = this.file.read() || {};\n const isFresh = Boolean(savedAt && isAfter(add(savedAt, this.ttl), new Date()));\n return [data, isFresh];\n }\n}\n","import { merge } from 'lodash-es';\nimport extractDomain from 'extract-domain';\n\nexport type Route = string | URL;\n\ntype QueryVal = string | number | boolean | null | undefined;\nexport type Query = Record<string, QueryVal | QueryVal[]>;\n\nexport type FetchOptions = RequestInit & {\n base?: string;\n query?: Query;\n headers?: Record<string, string>;\n data?: any;\n timeout?: number;\n retries?: number;\n retryDelay?: number;\n};\n\n/**\n * Fetcher provides a quick way to set up a basic API connection\n * with options applied to every request.\n * Includes basic methods for requesting and parsing responses\n */\nexport class Fetcher {\n defaultOptions;\n\n constructor(opts: FetchOptions = {}) {\n this.defaultOptions = {\n timeout: 60000,\n retries: 0,\n retryDelay: 3000,\n ...opts,\n };\n }\n\n /**\n * Build URL with URLSearchParams if query is provided.\n * Also returns domain, to help with cookies\n */\n buildUrl(route: Route, opts: FetchOptions = {}): [URL, string] {\n const mergedOptions = merge({}, this.defaultOptions, opts);\n const params: [string, string][] = [];\n Object.entries(mergedOptions.query || {}).forEach(([key, val]) => {\n if (val === undefined) return;\n if (Array.isArray(val)) {\n val.forEach((v) => {\n params.push([key, `${v}`]);\n });\n } else {\n params.push([key, `${val}`]);\n }\n });\n const search = params.length > 0 ? '?' + new URLSearchParams(params).toString() : '';\n const url = new URL(route + search, this.defaultOptions.base);\n const domain = extractDomain(url.href) as string;\n return [url, domain];\n }\n\n /**\n * Merges options to get headers. Useful when extending the Fetcher class to add custom auth.\n */\n buildHeaders(route: Route, opts: FetchOptions = {}) {\n const { headers } = merge({}, this.defaultOptions, opts);\n return headers || {};\n }\n\n /**\n * Builds request, merging defaultOptions and provided options.\n * Includes Abort signal for timeout\n */\n buildRequest(route: Route, opts: FetchOptions = {}): [Request, FetchOptions, string] {\n const mergedOptions = merge({}, this.defaultOptions, opts);\n const { query, data, timeout, retries, ...init } = mergedOptions;\n init.headers = this.buildHeaders(route, mergedOptions);\n if (data) {\n init.headers['content-type'] = init.headers['content-type'] || 'application/json';\n init.method = init.method || 'POST';\n init.body = JSON.stringify(data);\n }\n if (timeout) {\n init.signal = AbortSignal.timeout(timeout);\n }\n const [url, domain] = this.buildUrl(route, mergedOptions);\n const req = new Request(url, init);\n return [req, mergedOptions, domain];\n }\n\n /**\n * Builds and performs the request, merging provided options with defaultOptions.\n * If `opts.data` is provided, method is updated to POST, content-type json, data is stringified in the body.\n * Retries on local or network error, with increasing backoff.\n */\n async fetch(route: Route, opts: FetchOptions = {}): Promise<[Response, Request]> {\n const [_req, options] = this.buildRequest(route, opts);\n const maxAttempts = (options.retries || 0) + 1;\n let attempt = 0;\n while (attempt < maxAttempts) {\n attempt++;\n const [req] = this.buildRequest(route, opts);\n const res = await fetch(req)\n .then((r) => {\n if (!r.ok) throw new Error(r.statusText);\n return r;\n })\n .catch(async (error) => {\n if (attempt < maxAttempts) {\n const wait = attempt * 3000;\n console.warn(`${req.method} ${req.url} (attempt ${attempt} of ${maxAttempts})`, error);\n await new Promise((resolve) => setTimeout(resolve, wait));\n } else {\n throw new Error(error);\n }\n });\n if (res) return [res, req];\n }\n throw new Error(`Failed to fetch ${_req.url}`);\n }\n\n async fetchText(route: Route, opts: FetchOptions = {}): Promise<[string, Response, Request]> {\n return this.fetch(route, opts).then(async ([res, req]) => {\n const text = await res.text();\n return [text, res, req];\n });\n }\n\n async fetchJson<T>(route: Route, opts: FetchOptions = {}): Promise<[T, Response, Request]> {\n return this.fetchText(route, opts).then(([txt, res, req]) => [JSON.parse(txt) as T, res, req]);\n }\n}\n","import { inspect } from 'node:util';\nimport { isObjectLike } from 'lodash-es';\nimport chalk, { type ChalkInstance } from 'chalk';\nimport { snapshot } from './snapshot.ts';\n\ntype Severity = 'DEFAULT' | 'DEBUG' | 'INFO' | 'NOTICE' | 'WARNING' | 'ERROR' | 'CRITICAL' | 'ALERT' | 'EMERGENCY';\n\ntype Options = {\n severity: Severity;\n color: ChalkInstance;\n};\n\ntype Entry = {\n message?: string;\n severity: Severity;\n details?: unknown[];\n};\n\nexport class Log {\n // Only silence logs when THIS package is running its own tests\n static isTest = process.env.npm_package_name === '@brianbuie/node-kit' && process.env.npm_lifecycle_event === 'test';\n\n /**\n * Gcloud parses JSON in stdout\n */\n static #toGcloud(entry: Entry) {\n if (entry.details?.length === 1) {\n console.log(JSON.stringify({ ...entry, details: entry.details[0] }));\n } else {\n console.log(JSON.stringify(entry));\n }\n }\n\n /**\n * Includes colors and better inspection for logging during dev\n */\n static #toConsole(entry: Entry, color: ChalkInstance) {\n if (entry.message) console.log(color(`[${entry.severity}] ${entry.message}`));\n entry.details?.forEach((detail) => {\n console.log(inspect(detail, { depth: 10, breakLength: 100, compact: true, colors: true }));\n });\n }\n\n static #log(options: Options, ...input: unknown[]) {\n const { message, details } = this.prepare(...input);\n // https://cloud.google.com/run/docs/container-contract#env-vars\n const isGcloud = process.env.K_SERVICE !== undefined || process.env.CLOUD_RUN_JOB !== undefined;\n if (isGcloud) {\n this.#toGcloud({ message, severity: options.severity, details });\n return { message, details, options };\n }\n // Hide output while testing this package\n if (!this.isTest) {\n this.#toConsole({ message, severity: options.severity, details }, options.color);\n }\n return { message, details, options };\n }\n\n /**\n * Handle first argument being a string or an object with a 'message' prop\n * Also snapshots special objects (eg Error, Response) to keep props in later JSON.stringify output\n */\n static prepare(...input: unknown[]): { message?: string; details: unknown[] } {\n let [first, ...rest] = input.map((i) => snapshot(i));\n if (typeof first === 'string') return { message: first, details: rest };\n // @ts-ignore\n if (isObjectLike(first) && typeof first['message'] === 'string') {\n const { message, ...firstDetails } = first as { message: string };\n return { message, details: [firstDetails, ...rest] };\n }\n return { details: input };\n }\n\n /**\n * Logs error details before throwing\n */\n static error(...input: unknown[]) {\n const { message } = this.#log({ severity: 'ERROR', color: chalk.red }, ...input);\n throw new Error(message);\n }\n\n static warn(...input: unknown[]) {\n return this.#log({ severity: 'WARNING', color: chalk.yellow }, ...input);\n }\n\n static notice(...input: unknown[]) {\n return this.#log({ severity: 'NOTICE', color: chalk.cyan }, ...input);\n }\n\n static info(...input: unknown[]) {\n return this.#log({ severity: 'INFO', color: chalk.white }, ...input);\n }\n\n static debug(...input: unknown[]) {\n const debugging = process.argv.some((arg) => arg.includes('--debug')) || process.env.DEBUG !== undefined;\n if (debugging || process.env.NODE_ENV !== 'production') {\n return this.#log({ severity: 'DEBUG', color: chalk.gray }, ...input);\n }\n }\n}\n","export async function timeout(ms: number) {\n return new Promise((resolve) => {\n setTimeout(resolve, ms);\n });\n}\n","import * as fs from 'node:fs';\nimport { merge } from 'lodash-es';\nimport * as qt from 'quicktype-core';\n\nexport class TypeWriter {\n moduleName;\n input = qt.jsonInputForTargetLanguage('typescript');\n outDir;\n qtSettings;\n\n constructor(moduleName: string, settings: { outDir?: string } & Partial<qt.Options> = {}) {\n this.moduleName = moduleName;\n const { outDir, ...qtSettings } = settings;\n this.outDir = outDir || './types';\n const defaultSettings = {\n lang: 'typescript',\n rendererOptions: {\n 'just-types': true,\n 'prefer-types': true,\n },\n inferEnums: false,\n inferDateTimes: false,\n };\n this.qtSettings = merge(defaultSettings, qtSettings);\n }\n\n async addMember(name: string, _samples: any[]) {\n const samples = _samples.map((s) => (typeof s === 'string' ? s : JSON.stringify(s)));\n await this.input.addSource({ name, samples });\n }\n\n async toString() {\n const inputData = new qt.InputData();\n inputData.addInput(this.input);\n const result = await qt.quicktype({\n inputData,\n ...this.qtSettings,\n });\n return result.lines.join('\\n');\n }\n\n async toFile() {\n const result = await this.toString();\n fs.mkdirSync(this.outDir, { recursive: true });\n fs.writeFileSync(`${this.outDir}/${this.moduleName}.d.ts`, result);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAMA,SAAgB,SAAS,GAAY,MAAM,IAAI,QAAQ,GAAQ;AAC7D,KAAI,MAAM,QAAQ,EAAE,EAAE;AACpB,MAAI,UAAU,IAAK,QAAO,EAAE;AAC5B,SAAO,EAAE,KAAK,MAAM,SAAS,GAAG,KAAK,QAAQ,EAAE,CAAC;;AAElD,KAAI,OAAO,MAAM,WAAY,QAAO;AACpC,KAAI,CAAC,aAAa,EAAE,CAAE,QAAO;AAE7B,KAAI,UAAU,IAAK,QAAO,EAAE;CAC5B,IAAIA,SAA8B,EAAE;AAEpC,KAAI,OAAO,EAAE,YAAY,YAAY;AAEnC,OAAK,IAAI,CAAC,GAAG,MAAM,EAAE,SAAS,CAC5B,QAAO,KAAK,SAAS,GAAG,KAAK,QA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UAAU,UAC9E,QAAQ,IAAI,aAAa,aACxC,QAAO,MAAKA,IAAK;GAAE,UAAU;GAAS,OAAO,MAAM;GAAM,EAAE,GAAG,MAAM;;;;;;AChG1E,eAAsB,QAAQ,IAAY;AACxC,QAAO,IAAI,SAAS,YAAY;AAC9B,aAAW,SAAS,GAAG;GACvB;;;;;ACCJ,IAAa,aAAb,MAAwB;CACtB;CACA,QAAQ,GAAG,2BAA2B,aAAa;CACnD;CACA;CAEA,YAAY,YAAoB,WAAsD,EAAE,EAAE;AACxF,OAAK,aAAa;EAClB,MAAM,EAAE,QAAQ,GAAG,eAAe;AAClC,OAAK,SAAS,UAAU;AAUxB,OAAK,aAAa,MATM;GACtB,MAAM;GACN,iBAAiB;IACf,cAAc;IACd,gBAAgB;IACjB;GACD,YAAY;GACZ,gBAAgB;GACjB,EACwC,WAAW;;CAGtD,MAAM,UAAU,MAAc,UAAiB;EAC7C,MAAM,UAAU,SAAS,KAAK,MAAO,OAAO,MAAM,WAAW,IAAI,KAAK,UAAU,EAAE,CAAE;AACpF,QAAM,KAAK,MAAM,UAAU;GAAE;GAAM;GAAS,CAAC;;CAG/C,MAAM,WAAW;EACf,MAAM,YAAY,IAAI,GAAG,WAAW;AACpC,YAAU,SAAS,KAAK,MAAM;AAK9B,UAJe,MAAM,GAAG,UAAU;GAChC;GACA,GAAG,KAAK;GACT,CAAC,EACY,MAAM,KAAK,KAAK;;CAGhC,MAAM,SAAS;EACb,MAAM,SAAS,MAAM,KAAK,UAAU;AACpC,KAAG,UAAU,KAAK,QAAQ,EAAE,WAAW,MAAM,CAAC;AAC9C,KAAG,cAAc,GAAG,KAAK,OAAO,GAAG,KAAK,WAAW,QAAQ,OAAO"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["output: Record<string, any>","obj: Record<string, any>","parsed: Row[]","#parseVal","params: [string, string][]","timeout","#toGcloud","#toConsole","#log"],"sources":["../src/snapshot.ts","../src/File.ts","../src/Dir.ts","../src/Cache.ts","../src/Fetcher.ts","../src/Format.ts","../src/Log.ts","../src/timeout.ts","../src/TypeWriter.ts"],"sourcesContent":["import { isObjectLike } from 'lodash-es';\n\n/**\n * Allows special objects (Error, Headers, Set) to be included in JSON.stringify output\n * functions are removed\n */\nexport function snapshot(i: unknown, max = 50, depth = 0): any {\n if (Array.isArray(i)) {\n if (depth === max) return [];\n return i.map((c) => snapshot(c, max, depth + 1));\n }\n if (typeof i === 'function') return undefined;\n if (!isObjectLike(i)) return i;\n\n if (depth === max) return {};\n let output: Record<string, any> = {};\n // @ts-ignore If it has an 'entries' function, use that for looping (eg. Set, Map, Headers)\n if (typeof i.entries === 'function') {\n // @ts-ignore\n for (let [k, v] of i.entries()) {\n output[k] = snapshot(v, max, depth + 1);\n }\n return output;\n }\n\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Enumerability_and_ownership_of_properties\n\n // Get Enumerable, inherited properties\n const obj: Record<string, any> = i!;\n for (let key in obj) {\n output[key] = snapshot(obj[key], max, depth + 1);\n }\n\n // Get Non-enumberable, own properties\n Object.getOwnPropertyNames(obj).forEach((key) => {\n output[key] = snapshot(obj[key], max, depth + 1);\n });\n\n return output;\n}\n","import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { Readable } from 'node:stream';\nimport { finished } from 'node:stream/promises';\nimport { writeToStream, parseStream } from 'fast-csv';\nimport { snapshot } from './snapshot.ts';\n\n/**\n * WARNING: API will change!\n */\nexport class File {\n path;\n root;\n dir;\n base;\n ext;\n name;\n\n constructor(filepath: string) {\n this.path = filepath;\n const { root, dir, base, ext, name } = path.parse(filepath);\n this.root = root;\n this.dir = dir;\n this.base = base;\n this.ext = ext;\n this.name = name;\n }\n\n get exists() {\n return fs.existsSync(this.path);\n }\n\n delete() {\n fs.rmSync(this.path, { force: true });\n }\n\n read() {\n return this.exists ? fs.readFileSync(this.path, 'utf8') : undefined;\n }\n\n /**\n * @returns lines as strings, removes trailing '\\n'\n */\n lines() {\n const contents = (this.read() || '').split('\\n');\n return contents.slice(0, contents.length - 1);\n }\n\n get readStream() {\n return this.exists ? fs.createReadStream(this.path) : Readable.from([]);\n }\n\n get writeStream() {\n fs.mkdirSync(path.parse(this.path).dir, { recursive: true });\n return fs.createWriteStream(this.path);\n }\n\n write(contents: string | ReadableStream) {\n fs.mkdirSync(path.parse(this.path).dir, { recursive: true });\n if (typeof contents === 'string') return fs.writeFileSync(this.path, contents);\n if (contents instanceof ReadableStream) return finished(Readable.from(contents).pipe(this.writeStream));\n throw new Error(`Invalid content type: ${typeof contents}`);\n }\n\n /**\n * creates file if it doesn't exist, appends string or array of strings as new lines.\n * File always ends with '\\n', so contents don't need to be read before appending\n */\n append(lines: string | string[]) {\n if (!this.exists) this.write('');\n const contents = Array.isArray(lines) ? lines.join('\\n') : lines;\n fs.appendFileSync(this.path, contents + '\\n');\n }\n\n static get FileType() {\n return FileType;\n }\n\n json<T>(contents?: T) {\n return new FileTypeJson<T>(this.path, contents);\n }\n\n static get json() {\n return FileTypeJson;\n }\n\n ndjson<T extends object>(lines?: T | T[]) {\n return new FileTypeNdjson<T>(this.path, lines);\n }\n\n static get ndjson() {\n return FileTypeNdjson;\n }\n\n async csv<T extends object>(rows?: T[], keys?: (keyof T)[]) {\n const csvFile = new FileTypeCsv<T>(this.path);\n if (rows) await csvFile.write(rows, keys);\n return csvFile;\n }\n\n static get csv() {\n return FileTypeCsv;\n }\n}\n\n/**\n * A generic file adaptor, extended by specific file type implementations\n */\nexport class FileType {\n file;\n\n constructor(filepath: string, contents?: string) {\n this.file = new File(filepath);\n if (contents) this.file.write(contents);\n }\n\n get exists() {\n return this.file.exists;\n }\n\n get path() {\n return this.file.path;\n }\n\n delete() {\n this.file.delete();\n }\n}\n\n/**\n * A .json file that maintains data type when reading/writing.\n * This is unsafe! Type is not checked at runtime, avoid using on files manipulated outside of your application.\n */\nexport class FileTypeJson<T> extends FileType {\n constructor(filepath: string, contents?: T) {\n super(filepath.endsWith('.json') ? filepath : filepath + '.json');\n if (contents) this.write(contents);\n }\n\n read() {\n const contents = this.file.read();\n return contents ? (JSON.parse(contents) as T) : undefined;\n }\n\n write(contents: T) {\n this.file.write(JSON.stringify(snapshot(contents), null, 2));\n }\n}\n\n/**\n * New-line delimited json file (.ndjson)\n * @see https://jsonltools.com/ndjson-format-specification\n */\nexport class FileTypeNdjson<T extends object> extends FileType {\n constructor(filepath: string, lines?: T | T[]) {\n super(filepath.endsWith('.ndjson') ? filepath : filepath + '.ndjson');\n if (lines) this.append(lines);\n }\n\n append(lines: T | T[]) {\n this.file.append(\n Array.isArray(lines) ? lines.map((l) => JSON.stringify(snapshot(l))) : JSON.stringify(snapshot(lines)),\n );\n }\n\n lines() {\n return this.file.lines().map((l) => JSON.parse(l) as T);\n }\n}\n\ntype Key<T extends object> = keyof T;\n\n/**\n * Comma separated values (.csv).\n * Input rows as objects, keys are used as column headers\n */\nexport class FileTypeCsv<Row extends object> extends FileType {\n constructor(filepath: string) {\n super(filepath.endsWith('.csv') ? filepath : filepath + '.csv');\n }\n\n async write(rows: Row[], keys?: Key<Row>[]) {\n const headerSet = new Set<Key<Row>>();\n if (keys) {\n for (const key of keys) headerSet.add(key);\n } else {\n for (const row of rows) {\n for (const key in row) headerSet.add(key);\n }\n }\n const headers = Array.from(headerSet);\n const outRows = rows.map((row) => headers.map((key) => row[key]));\n return finished(writeToStream(this.file.writeStream, [headers, ...outRows]));\n }\n\n #parseVal(val: string) {\n if (val.toLowerCase() === 'false') return false;\n if (val.toLowerCase() === 'true') return true;\n if (val.length === 0) return null;\n if (/^[\\.0-9]+$/.test(val)) return Number(val);\n return val;\n }\n\n async read() {\n return new Promise<Row[]>((resolve, reject) => {\n const parsed: Row[] = [];\n parseStream(this.file.readStream, { headers: true })\n .on('error', (e) => reject(e))\n .on('data', (raw: Record<Key<Row>, string>) => {\n parsed.push(\n Object.entries(raw).reduce(\n (all, [key, val]) => ({\n ...all,\n [key]: this.#parseVal(val as string),\n }),\n {} as Row,\n ),\n );\n })\n .on('end', () => resolve(parsed));\n });\n }\n}\n","import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport sanitizeFilename from 'sanitize-filename';\nimport { File } from './File.ts';\n\n/**\n * Reference to a specific directory with methods to create and list files.\n * Created immediately if it doesn't exist\n */\nexport class Dir {\n path;\n\n /**\n * @param path can be relative to workspace or absolute\n */\n constructor(inputPath = './') {\n this.path = path.resolve(inputPath);\n fs.mkdirSync(this.path, { recursive: true });\n }\n\n /**\n * Create a new Dir inside the current Dir\n * @param subPath relative path to create\n * @example\n * const folder = new Dir('example');\n * // folder.path = '/absolute/path/to/example'\n * const child = folder.dir('path/to/dir');\n * // child.path = '/absolute/path/to/example/path/to/dir'\n */\n dir(subPath: string) {\n return new Dir(path.resolve(this.path, subPath));\n }\n\n tempDir(subPath: string) {\n return new TempDir(path.resolve(this.path, subPath));\n }\n\n sanitize(filename: string) {\n return sanitizeFilename(filename.replace('https://', '').replace('www.', ''), { replacement: '_' }).slice(-200);\n }\n\n /**\n * @param base - The file name with extension\n * @example\n * const folder = new Dir('example');\n * const filepath = folder.resolve('file.json');\n * // 'example/file.json'\n */\n filepath(base: string) {\n return path.resolve(this.path, this.sanitize(base));\n }\n\n file(base: string) {\n return new File(this.filepath(base));\n }\n\n get files() {\n return fs.readdirSync(this.path).map((filename) => this.file(filename));\n }\n}\n\n/**\n * Extends Dir class with method to `clear()` contents\n */\nexport class TempDir extends Dir {\n clear() {\n fs.rmSync(this.path, { recursive: true, force: true });\n fs.mkdirSync(this.path, { recursive: true });\n }\n}\n\n/**\n * Creates a '.temp' directory in current working directory\n */\nexport function temp() {\n return new TempDir('.temp');\n}\n","import { type Duration, isAfter, add } from 'date-fns';\nimport { TempDir } from './Dir.ts';\n\n/**\n * Save data to a local file with an expiration.\n * Fresh/stale data is returned with a flag for if it's fresh or not,\n * so stale data can still be used if needed.\n */\nexport class Cache<T> {\n file;\n ttl;\n\n constructor(key: string, ttl: number | Duration, initialData?: T) {\n const dir = new TempDir('.cache');\n this.file = dir.file(key).json<{ savedAt: string; data: T }>();\n this.ttl = typeof ttl === 'number' ? { minutes: ttl } : ttl;\n if (initialData) this.write(initialData);\n }\n\n write(data: T) {\n this.file.write({ savedAt: new Date().toUTCString(), data });\n }\n\n read(): [T | undefined, boolean] {\n const { savedAt, data } = this.file.read() || {};\n const isFresh = Boolean(savedAt && isAfter(add(savedAt, this.ttl), new Date()));\n return [data, isFresh];\n }\n}\n","import { merge } from 'lodash-es';\nimport extractDomain from 'extract-domain';\n\nexport type Route = string | URL;\n\ntype QueryVal = string | number | boolean | null | undefined;\nexport type Query = Record<string, QueryVal | QueryVal[]>;\n\nexport type FetchOptions = RequestInit & {\n base?: string;\n query?: Query;\n headers?: Record<string, string>;\n data?: any;\n timeout?: number;\n retries?: number;\n retryDelay?: number;\n};\n\n/**\n * Fetcher provides a quick way to set up a basic API connection\n * with options applied to every request.\n * Includes basic methods for requesting and parsing responses\n */\nexport class Fetcher {\n defaultOptions;\n\n constructor(opts: FetchOptions = {}) {\n this.defaultOptions = {\n timeout: 60000,\n retries: 0,\n retryDelay: 3000,\n ...opts,\n };\n }\n\n /**\n * Build URL with URLSearchParams if query is provided.\n * Also returns domain, to help with cookies\n */\n buildUrl(route: Route, opts: FetchOptions = {}): [URL, string] {\n const mergedOptions = merge({}, this.defaultOptions, opts);\n const params: [string, string][] = [];\n Object.entries(mergedOptions.query || {}).forEach(([key, val]) => {\n if (val === undefined) return;\n if (Array.isArray(val)) {\n val.forEach((v) => {\n params.push([key, `${v}`]);\n });\n } else {\n params.push([key, `${val}`]);\n }\n });\n const search = params.length > 0 ? '?' + new URLSearchParams(params).toString() : '';\n const url = new URL(route + search, this.defaultOptions.base);\n const domain = extractDomain(url.href) as string;\n return [url, domain];\n }\n\n /**\n * Merges options to get headers. Useful when extending the Fetcher class to add custom auth.\n */\n buildHeaders(route: Route, opts: FetchOptions = {}) {\n const { headers } = merge({}, this.defaultOptions, opts);\n return headers || {};\n }\n\n /**\n * Builds request, merging defaultOptions and provided options.\n * Includes Abort signal for timeout\n */\n buildRequest(route: Route, opts: FetchOptions = {}): [Request, FetchOptions, string] {\n const mergedOptions = merge({}, this.defaultOptions, opts);\n const { query, data, timeout, retries, ...init } = mergedOptions;\n init.headers = this.buildHeaders(route, mergedOptions);\n if (data) {\n init.headers['content-type'] = init.headers['content-type'] || 'application/json';\n init.method = init.method || 'POST';\n init.body = JSON.stringify(data);\n }\n if (timeout) {\n init.signal = AbortSignal.timeout(timeout);\n }\n const [url, domain] = this.buildUrl(route, mergedOptions);\n const req = new Request(url, init);\n return [req, mergedOptions, domain];\n }\n\n /**\n * Builds and performs the request, merging provided options with defaultOptions.\n * If `opts.data` is provided, method is updated to POST, content-type json, data is stringified in the body.\n * Retries on local or network error, with increasing backoff.\n */\n async fetch(route: Route, opts: FetchOptions = {}): Promise<[Response, Request]> {\n const [_req, options] = this.buildRequest(route, opts);\n const maxAttempts = (options.retries || 0) + 1;\n let attempt = 0;\n while (attempt < maxAttempts) {\n attempt++;\n const [req] = this.buildRequest(route, opts);\n const res = await fetch(req)\n .then((r) => {\n if (!r.ok) throw new Error(r.statusText);\n return r;\n })\n .catch(async (error) => {\n if (attempt < maxAttempts) {\n const wait = attempt * 3000;\n console.warn(`${req.method} ${req.url} (attempt ${attempt} of ${maxAttempts})`, error);\n await new Promise((resolve) => setTimeout(resolve, wait));\n } else {\n throw new Error(error);\n }\n });\n if (res) return [res, req];\n }\n throw new Error(`Failed to fetch ${_req.url}`);\n }\n\n async fetchText(route: Route, opts: FetchOptions = {}): Promise<[string, Response, Request]> {\n return this.fetch(route, opts).then(async ([res, req]) => {\n const text = await res.text();\n return [text, res, req];\n });\n }\n\n async fetchJson<T>(route: Route, opts: FetchOptions = {}): Promise<[T, Response, Request]> {\n return this.fetchText(route, opts).then(([txt, res, req]) => [JSON.parse(txt) as T, res, req]);\n }\n}\n","import { format, formatISO, type DateArg } from 'date-fns';\n\n/**\n * Helpers for formatting dates, times, and numbers as strings\n */\nexport class Format {\n /**\n * date-fns format() with some shortcuts\n * @param formatStr\n * 'iso' to get ISO date, 'ymd' to format as 'yyyy-MM-dd', full options: https://date-fns.org/v4.1.0/docs/format\n */\n static date(formatStr: 'iso' | 'ymd' | string = 'iso', d: DateArg<Date> = new Date()) {\n if (formatStr === 'iso') return formatISO(d);\n if (formatStr === 'ymd') return format(d, 'yyyy-MM-dd');\n return format(d, formatStr);\n }\n\n /**\n * Round a number to a specific set of places\n */\n static round(n: number, places = 0) {\n return new Intl.NumberFormat('en-US', { maximumFractionDigits: places }).format(n);\n }\n\n /**\n * Make millisecond durations actually readable (eg \"123ms\", \"3.56s\", \"1m 34s\", \"3h 24m\", \"2d 4h\")\n */\n static ms(ms: number) {\n if (ms < 1000) return `${this.round(ms)}ms`;\n const s = ms / 1000;\n if (s < 60) return `${this.round(s, 2)}s`;\n const m = Math.floor(s / 60);\n if (m < 60) return `${m}m ${Math.floor(s) % 60}s`;\n const h = Math.floor(m / 60);\n if (h < 24) return `${h}h ${m % 60}m`;\n const d = Math.floor(h / 24);\n return `${d}d ${h % 24}h`;\n }\n\n static bytes(b: number) {\n const labels = ['b', 'KB', 'MB', 'GB', 'TB'];\n let factor = 0;\n while (b >= 1024 && labels[factor + 1]) {\n b = b / 1024;\n factor++;\n }\n return `${this.round(b, 2)} ${labels[factor]}`;\n }\n}\n","import { inspect } from 'node:util';\nimport { isObjectLike } from 'lodash-es';\nimport chalk, { type ChalkInstance } from 'chalk';\nimport { snapshot } from './snapshot.ts';\n\ntype Severity = 'DEFAULT' | 'DEBUG' | 'INFO' | 'NOTICE' | 'WARNING' | 'ERROR' | 'CRITICAL' | 'ALERT' | 'EMERGENCY';\n\ntype Options = {\n severity: Severity;\n color: ChalkInstance;\n};\n\ntype Entry = {\n message?: string;\n severity: Severity;\n details?: unknown[];\n};\n\nexport class Log {\n // Only silence logs when THIS package is running its own tests\n static isTest = process.env.npm_package_name === '@brianbuie/node-kit' && process.env.npm_lifecycle_event === 'test';\n\n /**\n * Gcloud parses JSON in stdout\n */\n static #toGcloud(entry: Entry) {\n if (entry.details?.length === 1) {\n console.log(JSON.stringify({ ...entry, details: entry.details[0] }));\n } else {\n console.log(JSON.stringify(entry));\n }\n }\n\n /**\n * Includes colors and better inspection for logging during dev\n */\n static #toConsole(entry: Entry, color: ChalkInstance) {\n if (entry.message) console.log(color(`[${entry.severity}] ${entry.message}`));\n entry.details?.forEach((detail) => {\n console.log(inspect(detail, { depth: 10, breakLength: 100, compact: true, colors: true }));\n });\n }\n\n static #log(options: Options, ...input: unknown[]) {\n const { message, details } = this.prepare(...input);\n // https://cloud.google.com/run/docs/container-contract#env-vars\n const isGcloud = process.env.K_SERVICE !== undefined || process.env.CLOUD_RUN_JOB !== undefined;\n if (isGcloud) {\n this.#toGcloud({ message, severity: options.severity, details });\n return { message, details, options };\n }\n // Hide output while testing this package\n if (!this.isTest) {\n this.#toConsole({ message, severity: options.severity, details }, options.color);\n }\n return { message, details, options };\n }\n\n /**\n * Handle first argument being a string or an object with a 'message' prop\n * Also snapshots special objects (eg Error, Response) to keep props in later JSON.stringify output\n */\n static prepare(...input: unknown[]): { message?: string; details: unknown[] } {\n let [first, ...rest] = input.map((i) => snapshot(i));\n if (typeof first === 'string') return { message: first, details: rest };\n // @ts-ignore\n if (isObjectLike(first) && typeof first['message'] === 'string') {\n const { message, ...firstDetails } = first as { message: string };\n return { message, details: [firstDetails, ...rest] };\n }\n return { details: input };\n }\n\n /**\n * Logs error details before throwing\n */\n static error(...input: unknown[]) {\n const { message } = this.#log({ severity: 'ERROR', color: chalk.red }, ...input);\n throw new Error(message);\n }\n\n static warn(...input: unknown[]) {\n return this.#log({ severity: 'WARNING', color: chalk.yellow }, ...input);\n }\n\n static notice(...input: unknown[]) {\n return this.#log({ severity: 'NOTICE', color: chalk.cyan }, ...input);\n }\n\n static info(...input: unknown[]) {\n return this.#log({ severity: 'INFO', color: chalk.white }, ...input);\n }\n\n static debug(...input: unknown[]) {\n const debugging = process.argv.some((arg) => arg.includes('--debug')) || process.env.DEBUG !== undefined;\n if (debugging || process.env.NODE_ENV !== 'production') {\n return this.#log({ severity: 'DEBUG', color: chalk.gray }, ...input);\n }\n }\n}\n","export async function timeout(ms: number) {\n return new Promise((resolve) => {\n setTimeout(resolve, ms);\n });\n}\n","import * as fs from 'node:fs';\nimport { merge } from 'lodash-es';\nimport * as qt from 'quicktype-core';\n\nexport class TypeWriter {\n moduleName;\n input = qt.jsonInputForTargetLanguage('typescript');\n outDir;\n qtSettings;\n\n constructor(moduleName: string, settings: { outDir?: string } & Partial<qt.Options> = {}) {\n this.moduleName = moduleName;\n const { outDir, ...qtSettings } = settings;\n this.outDir = outDir || './types';\n const defaultSettings = {\n lang: 'typescript',\n rendererOptions: {\n 'just-types': true,\n 'prefer-types': true,\n },\n inferEnums: false,\n inferDateTimes: false,\n };\n this.qtSettings = merge(defaultSettings, qtSettings);\n }\n\n async addMember(name: string, _samples: any[]) {\n const samples = _samples.map((s) => (typeof s === 'string' ? s : JSON.stringify(s)));\n await this.input.addSource({ name, samples });\n }\n\n async toString() {\n const inputData = new qt.InputData();\n inputData.addInput(this.input);\n const result = await qt.quicktype({\n inputData,\n ...this.qtSettings,\n });\n return result.lines.join('\\n');\n }\n\n async toFile() {\n const result = await this.toString();\n fs.mkdirSync(this.outDir, { recursive: true });\n fs.writeFileSync(`${this.outDir}/${this.moduleName}.d.ts`, result);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAMA,SAAgB,SAAS,GAAY,MAAM,IAAI,QAAQ,GAAQ;AAC7D,KAAI,MAAM,QAAQ,EAAE,EAAE;AACpB,MAAI,UAAU,IAAK,QAAO,EAAE;AAC5B,SAAO,EAAE,KAAK,MAAM,SAAS,GAAG,KAAK,QAAQ,EAAE,CAAC;;AAElD,KAAI,OAAO,MAAM,WAAY,QAAO;AACpC,KAAI,CAAC,aAAa,EAAE,CAAE,QAAO;AAE7B,KAAI,UAAU,IAAK,QAAO,EAAE;CAC5B,IAAIA,SAA8B,EAAE;AAEpC,KAAI,OAAO,EAAE,Y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
"license": "ISC",
|
|
5
|
+
"description": "Basic tools for Node.js projects",
|
|
6
|
+
"author": "Brian Buie <brian@buie.dev>",
|
|
5
7
|
"repository": {
|
|
6
8
|
"type": "git",
|
|
7
9
|
"url": "git+https://github.com/brianbuie/node-kit.git"
|
|
@@ -22,7 +24,7 @@
|
|
|
22
24
|
"files": [
|
|
23
25
|
"src",
|
|
24
26
|
"dist",
|
|
25
|
-
"
|
|
27
|
+
"tsconfig.json"
|
|
26
28
|
],
|
|
27
29
|
"engines": {
|
|
28
30
|
"node": ">=24"
|
package/src/Cache.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { type Duration, isAfter, add } from 'date-fns';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
const cacheDir = temp.dir('cache');
|
|
2
|
+
import { TempDir } from './Dir.ts';
|
|
5
3
|
|
|
6
4
|
/**
|
|
7
5
|
* Save data to a local file with an expiration.
|
|
@@ -13,7 +11,8 @@ export class Cache<T> {
|
|
|
13
11
|
ttl;
|
|
14
12
|
|
|
15
13
|
constructor(key: string, ttl: number | Duration, initialData?: T) {
|
|
16
|
-
|
|
14
|
+
const dir = new TempDir('.cache');
|
|
15
|
+
this.file = dir.file(key).json<{ savedAt: string; data: T }>();
|
|
17
16
|
this.ttl = typeof ttl === 'number' ? { minutes: ttl } : ttl;
|
|
18
17
|
if (initialData) this.write(initialData);
|
|
19
18
|
}
|
package/src/Dir.test.ts
CHANGED
|
@@ -3,7 +3,7 @@ import assert from 'node:assert';
|
|
|
3
3
|
import { Dir, TempDir, temp } from './Dir.ts';
|
|
4
4
|
|
|
5
5
|
describe('Dir', () => {
|
|
6
|
-
const testDir = temp.dir('dir-test');
|
|
6
|
+
const testDir = temp().dir('dir-test');
|
|
7
7
|
|
|
8
8
|
it('Sanitizes filenames', () => {
|
|
9
9
|
const name = testDir.sanitize(':/something/else.json');
|
|
@@ -19,13 +19,13 @@ describe('Dir', () => {
|
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
it('TempDir.tempDir returns instance of TempDir', () => {
|
|
22
|
-
const sub = temp.tempDir('example');
|
|
22
|
+
const sub = temp().tempDir('example');
|
|
23
23
|
assert(sub instanceof TempDir);
|
|
24
24
|
});
|
|
25
25
|
|
|
26
26
|
it('Resolves filenames in folder', () => {
|
|
27
|
-
const txt = temp.filepath('test.txt');
|
|
28
|
-
assert(txt.includes(temp.path));
|
|
27
|
+
const txt = temp().filepath('test.txt');
|
|
28
|
+
assert(txt.includes(temp().path));
|
|
29
29
|
assert(txt.includes('test.txt'));
|
|
30
30
|
});
|
|
31
31
|
});
|
package/src/Dir.ts
CHANGED
|
@@ -4,8 +4,8 @@ import sanitizeFilename from 'sanitize-filename';
|
|
|
4
4
|
import { File } from './File.ts';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Reference to a specific directory with
|
|
8
|
-
*
|
|
7
|
+
* Reference to a specific directory with methods to create and list files.
|
|
8
|
+
* Created immediately if it doesn't exist
|
|
9
9
|
*/
|
|
10
10
|
export class Dir {
|
|
11
11
|
path;
|
|
@@ -13,22 +13,19 @@ export class Dir {
|
|
|
13
13
|
/**
|
|
14
14
|
* @param path can be relative to workspace or absolute
|
|
15
15
|
*/
|
|
16
|
-
constructor(
|
|
17
|
-
this.path = path.resolve(
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
create() {
|
|
16
|
+
constructor(inputPath = './') {
|
|
17
|
+
this.path = path.resolve(inputPath);
|
|
21
18
|
fs.mkdirSync(this.path, { recursive: true });
|
|
22
19
|
}
|
|
23
20
|
|
|
24
21
|
/**
|
|
25
22
|
* Create a new Dir inside the current Dir
|
|
26
|
-
* @param subPath to create
|
|
23
|
+
* @param subPath relative path to create
|
|
27
24
|
* @example
|
|
28
25
|
* const folder = new Dir('example');
|
|
29
|
-
* // folder.path = '
|
|
26
|
+
* // folder.path = '/absolute/path/to/example'
|
|
30
27
|
* const child = folder.dir('path/to/dir');
|
|
31
|
-
* // child.path = '
|
|
28
|
+
* // child.path = '/absolute/path/to/example/path/to/dir'
|
|
32
29
|
*/
|
|
33
30
|
dir(subPath: string) {
|
|
34
31
|
return new Dir(path.resolve(this.path, subPath));
|
|
@@ -38,8 +35,8 @@ export class Dir {
|
|
|
38
35
|
return new TempDir(path.resolve(this.path, subPath));
|
|
39
36
|
}
|
|
40
37
|
|
|
41
|
-
sanitize(
|
|
42
|
-
return sanitizeFilename(
|
|
38
|
+
sanitize(filename: string) {
|
|
39
|
+
return sanitizeFilename(filename.replace('https://', '').replace('www.', ''), { replacement: '_' }).slice(-200);
|
|
43
40
|
}
|
|
44
41
|
|
|
45
42
|
/**
|
|
@@ -56,6 +53,10 @@ export class Dir {
|
|
|
56
53
|
file(base: string) {
|
|
57
54
|
return new File(this.filepath(base));
|
|
58
55
|
}
|
|
56
|
+
|
|
57
|
+
get files() {
|
|
58
|
+
return fs.readdirSync(this.path).map((filename) => this.file(filename));
|
|
59
|
+
}
|
|
59
60
|
}
|
|
60
61
|
|
|
61
62
|
/**
|
|
@@ -64,11 +65,13 @@ export class Dir {
|
|
|
64
65
|
export class TempDir extends Dir {
|
|
65
66
|
clear() {
|
|
66
67
|
fs.rmSync(this.path, { recursive: true, force: true });
|
|
67
|
-
this.
|
|
68
|
+
fs.mkdirSync(this.path, { recursive: true });
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
71
|
|
|
71
72
|
/**
|
|
72
|
-
*
|
|
73
|
+
* Creates a '.temp' directory in current working directory
|
|
73
74
|
*/
|
|
74
|
-
export
|
|
75
|
+
export function temp() {
|
|
76
|
+
return new TempDir('.temp');
|
|
77
|
+
}
|
package/src/File.test.ts
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { describe } from 'node:test';
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
import { Format } from './Format.ts';
|
|
4
|
+
|
|
5
|
+
describe('Format.round', () => {
|
|
6
|
+
assert.equal(Format.round(1.22), '1');
|
|
7
|
+
assert.equal(Format.round(1.55), '2');
|
|
8
|
+
assert.equal(Format.round(1.823, 2), '1.82');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
describe('Format.ms', () => {
|
|
12
|
+
const SECOND = 1000;
|
|
13
|
+
const MINUTE = 60 * SECOND;
|
|
14
|
+
const HOUR = 60 * MINUTE;
|
|
15
|
+
const DAY = 24 * HOUR;
|
|
16
|
+
assert.equal(Format.ms(100), '100ms');
|
|
17
|
+
assert.equal(Format.ms(5 * SECOND), '5s');
|
|
18
|
+
assert.equal(Format.ms(75 * SECOND), '1m 15s');
|
|
19
|
+
assert.equal(Format.ms(30 * MINUTE + 30 * SECOND), '30m 30s');
|
|
20
|
+
assert.equal(Format.ms(2 * HOUR + 2 * MINUTE), '2h 2m');
|
|
21
|
+
assert.equal(Format.ms(2 * DAY + 2 * HOUR), '2d 2h');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
describe('Format.bytes', () => {
|
|
25
|
+
const base = 1024;
|
|
26
|
+
assert.equal(Format.bytes(2), '2 b');
|
|
27
|
+
assert.equal(Format.bytes(base), '1 KB');
|
|
28
|
+
assert.equal(Format.bytes(base + 0.1 * base), '1.1 KB');
|
|
29
|
+
assert.equal(Format.bytes(base + 0.25 * base), '1.25 KB');
|
|
30
|
+
assert.equal(Format.bytes(base ** 2), '1 MB');
|
|
31
|
+
assert.equal(Format.bytes(base ** 3), '1 GB');
|
|
32
|
+
assert.equal(Format.bytes(base ** 4), '1 TB');
|
|
33
|
+
assert.equal(Format.bytes(base ** 5), '1,024 TB');
|
|
34
|
+
});
|
package/src/Format.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { format, formatISO, type DateArg } from 'date-fns';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Helpers for formatting dates, times, and numbers as strings
|
|
5
|
+
*/
|
|
6
|
+
export class Format {
|
|
7
|
+
/**
|
|
8
|
+
* date-fns format() with some shortcuts
|
|
9
|
+
* @param formatStr
|
|
10
|
+
* 'iso' to get ISO date, 'ymd' to format as 'yyyy-MM-dd', full options: https://date-fns.org/v4.1.0/docs/format
|
|
11
|
+
*/
|
|
12
|
+
static date(formatStr: 'iso' | 'ymd' | string = 'iso', d: DateArg<Date> = new Date()) {
|
|
13
|
+
if (formatStr === 'iso') return formatISO(d);
|
|
14
|
+
if (formatStr === 'ymd') return format(d, 'yyyy-MM-dd');
|
|
15
|
+
return format(d, formatStr);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Round a number to a specific set of places
|
|
20
|
+
*/
|
|
21
|
+
static round(n: number, places = 0) {
|
|
22
|
+
return new Intl.NumberFormat('en-US', { maximumFractionDigits: places }).format(n);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Make millisecond durations actually readable (eg "123ms", "3.56s", "1m 34s", "3h 24m", "2d 4h")
|
|
27
|
+
*/
|
|
28
|
+
static ms(ms: number) {
|
|
29
|
+
if (ms < 1000) return `${this.round(ms)}ms`;
|
|
30
|
+
const s = ms / 1000;
|
|
31
|
+
if (s < 60) return `${this.round(s, 2)}s`;
|
|
32
|
+
const m = Math.floor(s / 60);
|
|
33
|
+
if (m < 60) return `${m}m ${Math.floor(s) % 60}s`;
|
|
34
|
+
const h = Math.floor(m / 60);
|
|
35
|
+
if (h < 24) return `${h}h ${m % 60}m`;
|
|
36
|
+
const d = Math.floor(h / 24);
|
|
37
|
+
return `${d}d ${h % 24}h`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static bytes(b: number) {
|
|
41
|
+
const labels = ['b', 'KB', 'MB', 'GB', 'TB'];
|
|
42
|
+
let factor = 0;
|
|
43
|
+
while (b >= 1024 && labels[factor + 1]) {
|
|
44
|
+
b = b / 1024;
|
|
45
|
+
factor++;
|
|
46
|
+
}
|
|
47
|
+
return `${this.round(b, 2)} ${labels[factor]}`;
|
|
48
|
+
}
|
|
49
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ export { Dir, TempDir, temp } from './Dir.ts';
|
|
|
2
2
|
export { Cache } from './Cache.ts';
|
|
3
3
|
export { Fetcher, type Route, type Query, type FetchOptions } from './Fetcher.ts';
|
|
4
4
|
export { File, FileType, FileTypeJson, FileTypeNdjson, FileTypeCsv } from './File.ts';
|
|
5
|
+
export { Format } from './Format.ts';
|
|
5
6
|
export { Log } from './Log.ts';
|
|
6
7
|
export { snapshot } from './snapshot.ts';
|
|
7
8
|
export { timeout } from './timeout.ts';
|
package/src/snapshot.test.ts
CHANGED
|
@@ -46,9 +46,9 @@ describe('snapshot', () => {
|
|
|
46
46
|
const t1 = createThing(1);
|
|
47
47
|
const t2 = createThing(2, t1);
|
|
48
48
|
const result = snapshot(t1, 20) as Thing;
|
|
49
|
-
const f1 = temp.file('recursive').json(result);
|
|
49
|
+
const f1 = temp().file('recursive').json(result);
|
|
50
50
|
const parsed = f1.read();
|
|
51
|
-
const f2 = temp.file('recursive2').json(parsed);
|
|
51
|
+
const f2 = temp().file('recursive2').json(parsed);
|
|
52
52
|
assert.deepEqual(f1.read(), f2.read());
|
|
53
53
|
});
|
|
54
54
|
});
|