@fgv/ts-extras 5.0.0-9 → 5.0.1-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +9 -3
- package/dist/ts-extras.d.ts +111 -21
- package/dist/tsdoc-metadata.json +1 -1
- package/eslint.config.js +16 -0
- package/lib/index.browser.d.ts +6 -0
- package/lib/index.browser.js +69 -0
- package/lib/packlets/csv/csvFileHelpers.d.ts +21 -0
- package/lib/packlets/csv/csvFileHelpers.js +92 -0
- package/lib/packlets/csv/csvHelpers.d.ts +4 -4
- package/lib/packlets/csv/csvHelpers.js +5 -43
- package/lib/packlets/csv/index.d.ts +1 -0
- package/lib/packlets/csv/index.js +3 -0
- package/lib/packlets/hash/index.browser.d.ts +2 -0
- package/lib/packlets/hash/index.browser.js +40 -0
- package/lib/packlets/hash/index.node.d.ts +2 -0
- package/lib/packlets/hash/index.node.js +42 -0
- package/lib/packlets/hash/md5Normalizer.browser.d.ts +13 -0
- package/lib/packlets/hash/md5Normalizer.browser.js +38 -0
- package/lib/packlets/record-jar/index.d.ts +1 -0
- package/lib/packlets/record-jar/index.js +3 -0
- package/lib/packlets/record-jar/recordJarFileHelpers.d.ts +23 -0
- package/lib/packlets/record-jar/recordJarFileHelpers.js +97 -0
- package/lib/packlets/record-jar/recordJarHelpers.d.ts +0 -9
- package/lib/packlets/record-jar/recordJarHelpers.js +0 -53
- package/lib/packlets/zip-file-tree/zipFileTreeAccessors.d.ts +75 -18
- package/lib/packlets/zip-file-tree/zipFileTreeAccessors.js +109 -52
- package/package.json +46 -23
- package/CHANGELOG.md +0 -98
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/packlets/conversion/converters.d.ts.map +0 -1
- package/lib/packlets/conversion/converters.js.map +0 -1
- package/lib/packlets/conversion/index.d.ts.map +0 -1
- package/lib/packlets/conversion/index.js.map +0 -1
- package/lib/packlets/csv/csvHelpers.d.ts.map +0 -1
- package/lib/packlets/csv/csvHelpers.js.map +0 -1
- package/lib/packlets/csv/index.d.ts.map +0 -1
- package/lib/packlets/csv/index.js.map +0 -1
- package/lib/packlets/experimental/extendedArray.d.ts.map +0 -1
- package/lib/packlets/experimental/extendedArray.js.map +0 -1
- package/lib/packlets/experimental/formatter.d.ts.map +0 -1
- package/lib/packlets/experimental/formatter.js.map +0 -1
- package/lib/packlets/experimental/index.d.ts.map +0 -1
- package/lib/packlets/experimental/index.js.map +0 -1
- package/lib/packlets/experimental/rangeOf.d.ts.map +0 -1
- package/lib/packlets/experimental/rangeOf.js.map +0 -1
- package/lib/packlets/hash/index.d.ts.map +0 -1
- package/lib/packlets/hash/index.js.map +0 -1
- package/lib/packlets/hash/md5Normalizer.d.ts.map +0 -1
- package/lib/packlets/hash/md5Normalizer.js.map +0 -1
- package/lib/packlets/record-jar/index.d.ts.map +0 -1
- package/lib/packlets/record-jar/index.js.map +0 -1
- package/lib/packlets/record-jar/recordJarHelpers.d.ts.map +0 -1
- package/lib/packlets/record-jar/recordJarHelpers.js.map +0 -1
- package/lib/packlets/zip-file-tree/index.d.ts.map +0 -1
- package/lib/packlets/zip-file-tree/index.js.map +0 -1
- package/lib/packlets/zip-file-tree/zipFileTreeAccessors.d.ts.map +0 -1
- package/lib/packlets/zip-file-tree/zipFileTreeAccessors.js.map +0 -1
package/CHANGELOG.json
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fgv/ts-extras",
|
|
3
3
|
"entries": [
|
|
4
|
+
{
|
|
5
|
+
"version": "5.0.1",
|
|
6
|
+
"tag": "@fgv/ts-extras_v5.0.1",
|
|
7
|
+
"date": "Tue, 23 Sep 2025 03:13:55 GMT",
|
|
8
|
+
"comments": {}
|
|
9
|
+
},
|
|
4
10
|
{
|
|
5
11
|
"version": "5.0.0",
|
|
6
12
|
"tag": "@fgv/ts-extras_v5.0.0",
|
|
7
|
-
"date": "
|
|
13
|
+
"date": "Tue, 23 Sep 2025 02:54:20 GMT",
|
|
8
14
|
"comments": {
|
|
9
15
|
"none": [
|
|
10
16
|
{
|
|
11
|
-
"comment": "
|
|
17
|
+
"comment": "New zip file tree accessors allow FileTree operations on zip files"
|
|
12
18
|
},
|
|
13
19
|
{
|
|
14
|
-
"comment": "
|
|
20
|
+
"comment": "update rushstack"
|
|
15
21
|
}
|
|
16
22
|
]
|
|
17
23
|
}
|
package/dist/ts-extras.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Conversion } from '@fgv/ts-utils';
|
|
2
2
|
import { Converter } from '@fgv/ts-utils';
|
|
3
|
-
import { FileTree } from '@fgv/ts-
|
|
3
|
+
import { FileTree } from '@fgv/ts-json-base';
|
|
4
4
|
import { Hash as Hash_2 } from '@fgv/ts-utils';
|
|
5
|
+
import { JsonValue } from '@fgv/ts-json-base';
|
|
5
6
|
import { Result } from '@fgv/ts-utils';
|
|
6
7
|
import { Validator } from '@fgv/ts-utils';
|
|
7
8
|
|
|
@@ -18,8 +19,10 @@ export { Converters }
|
|
|
18
19
|
|
|
19
20
|
declare namespace Csv {
|
|
20
21
|
export {
|
|
22
|
+
parseCsvString,
|
|
23
|
+
CsvOptions,
|
|
21
24
|
readCsvFileSync,
|
|
22
|
-
|
|
25
|
+
readCsvFromTree
|
|
23
26
|
}
|
|
24
27
|
}
|
|
25
28
|
export { Csv }
|
|
@@ -238,6 +241,15 @@ declare class Md5Normalizer extends Hash_2.HashingNormalizer {
|
|
|
238
241
|
static md5Hash(parts: string[]): string;
|
|
239
242
|
}
|
|
240
243
|
|
|
244
|
+
/**
|
|
245
|
+
* Parses CSV data from a string.
|
|
246
|
+
* @param body - The CSV string to parse.
|
|
247
|
+
* @param options - optional parameters to control the processing
|
|
248
|
+
* @returns The parsed CSV data.
|
|
249
|
+
* @beta
|
|
250
|
+
*/
|
|
251
|
+
declare function parseCsvString(body: string, options?: CsvOptions): Result<unknown>;
|
|
252
|
+
|
|
241
253
|
/**
|
|
242
254
|
* Reads a record-jar from an array of strings, each of which represents one
|
|
243
255
|
* line in the source file.
|
|
@@ -391,6 +403,16 @@ declare function rangeTypeOf<T, RT extends RangeOf<T>, TC = unknown>(converter:
|
|
|
391
403
|
*/
|
|
392
404
|
declare function readCsvFileSync(srcPath: string, options?: CsvOptions): Result<unknown>;
|
|
393
405
|
|
|
406
|
+
/**
|
|
407
|
+
* Reads a CSV file from a FileTree.
|
|
408
|
+
* @param fileTree - The FileTree to read from.
|
|
409
|
+
* @param filePath - Path of the file within the tree.
|
|
410
|
+
* @param options - optional parameters to control the processing
|
|
411
|
+
* @returns The parsed CSV data.
|
|
412
|
+
* @beta
|
|
413
|
+
*/
|
|
414
|
+
declare function readCsvFromTree(fileTree: FileTree.FileTree, filePath: string, options?: CsvOptions): Result<unknown>;
|
|
415
|
+
|
|
394
416
|
/**
|
|
395
417
|
* Reads a record-jar file from a supplied path.
|
|
396
418
|
* @param srcPath - Source path from which the file is read.
|
|
@@ -401,13 +423,25 @@ declare function readCsvFileSync(srcPath: string, options?: CsvOptions): Result<
|
|
|
401
423
|
*/
|
|
402
424
|
declare function readRecordJarFileSync(srcPath: string, options?: JarRecordParserOptions): Result<JarRecord[]>;
|
|
403
425
|
|
|
426
|
+
/**
|
|
427
|
+
* Reads a record-jar file from a FileTree.
|
|
428
|
+
* @param fileTree - The FileTree to read from.
|
|
429
|
+
* @param filePath - Path of the file within the tree.
|
|
430
|
+
* @param options - Optional parser configuration
|
|
431
|
+
* @returns The contents of the file as an array of `Record<string, string>`
|
|
432
|
+
* @see https://datatracker.ietf.org/doc/html/draft-phillips-record-jar-01
|
|
433
|
+
* @public
|
|
434
|
+
*/
|
|
435
|
+
declare function readRecordJarFromTree(fileTree: FileTree.FileTree, filePath: string, options?: JarRecordParserOptions): Result<JarRecord[]>;
|
|
436
|
+
|
|
404
437
|
declare namespace RecordJar {
|
|
405
438
|
export {
|
|
406
439
|
parseRecordJarLines,
|
|
407
|
-
readRecordJarFileSync,
|
|
408
440
|
JarRecord,
|
|
409
441
|
JarFieldPicker,
|
|
410
|
-
JarRecordParserOptions
|
|
442
|
+
JarRecordParserOptions,
|
|
443
|
+
readRecordJarFileSync,
|
|
444
|
+
readRecordJarFromTree
|
|
411
445
|
}
|
|
412
446
|
}
|
|
413
447
|
export { RecordJar }
|
|
@@ -428,7 +462,7 @@ declare function templateString(defaultContext?: unknown): Conversion.StringConv
|
|
|
428
462
|
* Implementation of `IFileTreeDirectoryItem` for directories in a ZIP archive.
|
|
429
463
|
* @public
|
|
430
464
|
*/
|
|
431
|
-
declare class ZipDirectoryItem implements FileTree.IFileTreeDirectoryItem {
|
|
465
|
+
declare class ZipDirectoryItem<TCT extends string = string> implements FileTree.IFileTreeDirectoryItem<TCT> {
|
|
432
466
|
/**
|
|
433
467
|
* Indicates that this `FileTree.FileTreeItem` is a directory.
|
|
434
468
|
*/
|
|
@@ -450,18 +484,18 @@ declare class ZipDirectoryItem implements FileTree.IFileTreeDirectoryItem {
|
|
|
450
484
|
* @param directoryPath - The path of the directory within the ZIP.
|
|
451
485
|
* @param accessors - The ZIP file tree accessors.
|
|
452
486
|
*/
|
|
453
|
-
constructor(directoryPath: string, accessors: ZipFileTreeAccessors);
|
|
487
|
+
constructor(directoryPath: string, accessors: ZipFileTreeAccessors<TCT>);
|
|
454
488
|
/**
|
|
455
489
|
* Gets the children of the directory.
|
|
456
490
|
*/
|
|
457
|
-
getChildren(): Result<ReadonlyArray<FileTree.FileTreeItem
|
|
491
|
+
getChildren(): Result<ReadonlyArray<FileTree.FileTreeItem<TCT>>>;
|
|
458
492
|
}
|
|
459
493
|
|
|
460
494
|
/**
|
|
461
495
|
* Implementation of `FileTree.IFileTreeFileItem` for files in a ZIP archive.
|
|
462
496
|
* @public
|
|
463
497
|
*/
|
|
464
|
-
declare class ZipFileItem implements FileTree.IFileTreeFileItem {
|
|
498
|
+
declare class ZipFileItem<TCT extends string = string> implements FileTree.IFileTreeFileItem<TCT> {
|
|
465
499
|
/**
|
|
466
500
|
* Indicates that this `FileTree.FileTreeItem` is a file.
|
|
467
501
|
*/
|
|
@@ -482,6 +516,10 @@ declare class ZipFileItem implements FileTree.IFileTreeFileItem {
|
|
|
482
516
|
* The extension of the file
|
|
483
517
|
*/
|
|
484
518
|
readonly extension: string;
|
|
519
|
+
/**
|
|
520
|
+
* The content type of the file.
|
|
521
|
+
*/
|
|
522
|
+
get contentType(): TCT | undefined;
|
|
485
523
|
/**
|
|
486
524
|
* The pre-loaded contents of the file.
|
|
487
525
|
*/
|
|
@@ -490,17 +528,30 @@ declare class ZipFileItem implements FileTree.IFileTreeFileItem {
|
|
|
490
528
|
* The ZIP file tree accessors that created this item.
|
|
491
529
|
*/
|
|
492
530
|
private readonly _accessors;
|
|
531
|
+
/**
|
|
532
|
+
* Mutable content type of the file.
|
|
533
|
+
*/
|
|
534
|
+
private _contentType;
|
|
535
|
+
/**
|
|
536
|
+
* Flag to track if content type should be inferred on first access.
|
|
537
|
+
*/
|
|
538
|
+
private _shouldInferContentType;
|
|
493
539
|
/**
|
|
494
540
|
* Constructor for ZipFileItem.
|
|
495
541
|
* @param zipFilePath - The path of the file within the ZIP.
|
|
496
542
|
* @param contents - The pre-loaded contents of the file.
|
|
497
543
|
* @param accessors - The ZIP file tree accessors.
|
|
498
544
|
*/
|
|
499
|
-
constructor(zipFilePath: string, contents: string, accessors: ZipFileTreeAccessors);
|
|
545
|
+
constructor(zipFilePath: string, contents: string, accessors: ZipFileTreeAccessors<TCT>);
|
|
546
|
+
/**
|
|
547
|
+
* Sets the content type of the file.
|
|
548
|
+
* @param contentType - The content type of the file.
|
|
549
|
+
*/
|
|
550
|
+
setContentType(contentType: TCT | undefined): void;
|
|
500
551
|
/**
|
|
501
552
|
* Gets the contents of the file as parsed JSON.
|
|
502
553
|
*/
|
|
503
|
-
getContents(): Result<
|
|
554
|
+
getContents(): Result<JsonValue>;
|
|
504
555
|
getContents<T>(converter: Validator<T> | Converter<T>): Result<T>;
|
|
505
556
|
/**
|
|
506
557
|
* Gets the raw contents of the file as a string.
|
|
@@ -521,39 +572,74 @@ export { ZipFileTree }
|
|
|
521
572
|
* File tree accessors for ZIP archives.
|
|
522
573
|
* @public
|
|
523
574
|
*/
|
|
524
|
-
declare class ZipFileTreeAccessors implements FileTree.IFileTreeAccessors {
|
|
575
|
+
declare class ZipFileTreeAccessors<TCT extends string = string> implements FileTree.IFileTreeAccessors<TCT> {
|
|
525
576
|
/**
|
|
526
|
-
* The
|
|
577
|
+
* The unzipped file data.
|
|
527
578
|
*/
|
|
528
|
-
private readonly
|
|
579
|
+
private readonly _files;
|
|
529
580
|
/**
|
|
530
581
|
* Optional prefix to prepend to paths.
|
|
531
582
|
*/
|
|
532
583
|
private readonly _prefix;
|
|
584
|
+
/**
|
|
585
|
+
* Content type inference function.
|
|
586
|
+
*/
|
|
587
|
+
private readonly _inferContentType;
|
|
533
588
|
/**
|
|
534
589
|
* Cache of all items in the ZIP for efficient lookups.
|
|
535
590
|
*/
|
|
536
591
|
private readonly _itemCache;
|
|
537
592
|
/**
|
|
538
593
|
* Constructor for ZipFileTreeAccessors.
|
|
539
|
-
* @param
|
|
540
|
-
* @param
|
|
594
|
+
* @param files - The unzipped file data from fflate.
|
|
595
|
+
* @param params - Optional initialization parameters.
|
|
541
596
|
*/
|
|
542
597
|
private constructor();
|
|
543
598
|
/**
|
|
544
|
-
*
|
|
599
|
+
* Default function to infer the content type of a file.
|
|
600
|
+
* @param filePath - The path of the file.
|
|
601
|
+
* @param provided - Optional supplied content type.
|
|
602
|
+
* @returns `Success` with the content type of the file if successful, or
|
|
603
|
+
* `Failure` with an error message otherwise.
|
|
604
|
+
* @remarks This default implementation always returns `Success` with `undefined`.
|
|
605
|
+
* @public
|
|
606
|
+
*/
|
|
607
|
+
static defaultInferContentType<TCT extends string = string>(__filePath: string, __provided?: string): Result<TCT | undefined>;
|
|
608
|
+
/**
|
|
609
|
+
* Creates a new ZipFileTreeAccessors instance from a ZIP file buffer (synchronous).
|
|
545
610
|
* @param zipBuffer - The ZIP file as an ArrayBuffer or Uint8Array.
|
|
546
611
|
* @param prefix - Optional prefix to prepend to paths.
|
|
547
612
|
* @returns Result containing the ZipFileTreeAccessors instance.
|
|
548
613
|
*/
|
|
549
|
-
static fromBuffer(zipBuffer: ArrayBuffer | Uint8Array, prefix?: string): Result<ZipFileTreeAccessors
|
|
614
|
+
static fromBuffer<TCT extends string = string>(zipBuffer: ArrayBuffer | Uint8Array, prefix?: string): Result<ZipFileTreeAccessors<TCT>>;
|
|
615
|
+
/**
|
|
616
|
+
* Creates a new ZipFileTreeAccessors instance from a ZIP file buffer (synchronous).
|
|
617
|
+
* @param zipBuffer - The ZIP file as an ArrayBuffer or Uint8Array.
|
|
618
|
+
* @param params - Optional initialization parameters.
|
|
619
|
+
* @returns Result containing the ZipFileTreeAccessors instance.
|
|
620
|
+
*/
|
|
621
|
+
static fromBuffer<TCT extends string = string>(zipBuffer: ArrayBuffer | Uint8Array, params?: FileTree.IFileTreeInitParams<TCT>): Result<ZipFileTreeAccessors<TCT>>;
|
|
622
|
+
/**
|
|
623
|
+
* Creates a new ZipFileTreeAccessors instance from a ZIP file buffer (asynchronous).
|
|
624
|
+
* @param zipBuffer - The ZIP file as an ArrayBuffer or Uint8Array.
|
|
625
|
+
* @param prefix - Optional prefix to prepend to paths.
|
|
626
|
+
* @returns Promise containing Result with the ZipFileTreeAccessors instance.
|
|
627
|
+
*/
|
|
628
|
+
static fromBufferAsync<TCT extends string = string>(zipBuffer: ArrayBuffer | Uint8Array, prefix?: string): Promise<Result<ZipFileTreeAccessors<TCT>>>;
|
|
629
|
+
/**
|
|
630
|
+
* Creates a new ZipFileTreeAccessors instance from a ZIP file buffer (asynchronous).
|
|
631
|
+
* @param zipBuffer - The ZIP file as an ArrayBuffer or Uint8Array.
|
|
632
|
+
* @param params - Optional initialization parameters.
|
|
633
|
+
* @returns Promise containing Result with the ZipFileTreeAccessors instance.
|
|
634
|
+
*/
|
|
635
|
+
static fromBufferAsync<TCT extends string = string>(zipBuffer: ArrayBuffer | Uint8Array, params?: FileTree.IFileTreeInitParams<TCT>): Promise<Result<ZipFileTreeAccessors<TCT>>>;
|
|
550
636
|
/**
|
|
551
637
|
* Creates a new ZipFileTreeAccessors instance from a File object (browser environment).
|
|
552
638
|
* @param file - The File object containing ZIP data.
|
|
553
|
-
* @param
|
|
639
|
+
* @param params - Optional initialization parameters.
|
|
554
640
|
* @returns Result containing the ZipFileTreeAccessors instance.
|
|
555
641
|
*/
|
|
556
|
-
static fromFile(file: File,
|
|
642
|
+
static fromFile<TCT extends string = string>(file: File, params?: FileTree.IFileTreeInitParams<TCT>): Promise<Result<ZipFileTreeAccessors<TCT>>>;
|
|
557
643
|
/**
|
|
558
644
|
* Builds the cache of all items in the ZIP archive.
|
|
559
645
|
*/
|
|
@@ -577,15 +663,19 @@ declare class ZipFileTreeAccessors implements FileTree.IFileTreeAccessors {
|
|
|
577
663
|
/**
|
|
578
664
|
* Gets an item from the file tree.
|
|
579
665
|
*/
|
|
580
|
-
getItem(path: string): Result<FileTree.FileTreeItem
|
|
666
|
+
getItem(path: string): Result<FileTree.FileTreeItem<TCT>>;
|
|
581
667
|
/**
|
|
582
668
|
* Gets the contents of a file in the file tree.
|
|
583
669
|
*/
|
|
584
670
|
getFileContents(path: string): Result<string>;
|
|
671
|
+
/**
|
|
672
|
+
* Gets the content type of a file in the file tree.
|
|
673
|
+
*/
|
|
674
|
+
getFileContentType(path: string, provided?: string): Result<TCT | undefined>;
|
|
585
675
|
/**
|
|
586
676
|
* Gets the children of a directory in the file tree.
|
|
587
677
|
*/
|
|
588
|
-
getChildren(path: string): Result<ReadonlyArray<FileTree.FileTreeItem
|
|
678
|
+
getChildren(path: string): Result<ReadonlyArray<FileTree.FileTreeItem<TCT>>>;
|
|
589
679
|
/**
|
|
590
680
|
* Checks if childPath is a direct child of parentPath.
|
|
591
681
|
*/
|
package/dist/tsdoc-metadata.json
CHANGED
package/eslint.config.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// ESLint 9 flat config
|
|
2
|
+
const nodeProfile = require('@rushstack/eslint-config/flat/profile/node');
|
|
3
|
+
const packletsPlugin = require('@rushstack/eslint-config/flat/mixins/packlets');
|
|
4
|
+
const tsdocPlugin = require('@rushstack/eslint-config/flat/mixins/tsdoc');
|
|
5
|
+
|
|
6
|
+
module.exports = [
|
|
7
|
+
...nodeProfile,
|
|
8
|
+
packletsPlugin,
|
|
9
|
+
...tsdocPlugin,
|
|
10
|
+
{
|
|
11
|
+
// Override specific rules if needed
|
|
12
|
+
rules: {
|
|
13
|
+
'@rushstack/packlets/mechanics': 'warn'
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
];
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as Experimental from './packlets/experimental';
|
|
2
|
+
import * as Hash from './packlets/hash/index.browser';
|
|
3
|
+
import * as ZipFileTree from './packlets/zip-file-tree';
|
|
4
|
+
import { Converters } from './packlets/conversion';
|
|
5
|
+
export { Converters, Experimental, Hash, ZipFileTree };
|
|
6
|
+
//# sourceMappingURL=index.browser.d.ts.map
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2020 Erik Fortune
|
|
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.
|
|
22
|
+
*/
|
|
23
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
24
|
+
if (k2 === undefined) k2 = k;
|
|
25
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
26
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
27
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
28
|
+
}
|
|
29
|
+
Object.defineProperty(o, k2, desc);
|
|
30
|
+
}) : (function(o, m, k, k2) {
|
|
31
|
+
if (k2 === undefined) k2 = k;
|
|
32
|
+
o[k2] = m[k];
|
|
33
|
+
}));
|
|
34
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
35
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
36
|
+
}) : function(o, v) {
|
|
37
|
+
o["default"] = v;
|
|
38
|
+
});
|
|
39
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
40
|
+
var ownKeys = function(o) {
|
|
41
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
42
|
+
var ar = [];
|
|
43
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
44
|
+
return ar;
|
|
45
|
+
};
|
|
46
|
+
return ownKeys(o);
|
|
47
|
+
};
|
|
48
|
+
return function (mod) {
|
|
49
|
+
if (mod && mod.__esModule) return mod;
|
|
50
|
+
var result = {};
|
|
51
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
52
|
+
__setModuleDefault(result, mod);
|
|
53
|
+
return result;
|
|
54
|
+
};
|
|
55
|
+
})();
|
|
56
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
|
+
exports.ZipFileTree = exports.Hash = exports.Experimental = exports.Converters = void 0;
|
|
58
|
+
/* c8 ignore start - Browser-specific export used conditionally in package.json */
|
|
59
|
+
const Experimental = __importStar(require("./packlets/experimental"));
|
|
60
|
+
exports.Experimental = Experimental;
|
|
61
|
+
// eslint-disable-next-line @rushstack/packlets/mechanics
|
|
62
|
+
const Hash = __importStar(require("./packlets/hash/index.browser"));
|
|
63
|
+
exports.Hash = Hash;
|
|
64
|
+
const ZipFileTree = __importStar(require("./packlets/zip-file-tree"));
|
|
65
|
+
exports.ZipFileTree = ZipFileTree;
|
|
66
|
+
const conversion_1 = require("./packlets/conversion");
|
|
67
|
+
Object.defineProperty(exports, "Converters", { enumerable: true, get: function () { return conversion_1.Converters; } });
|
|
68
|
+
/* c8 ignore stop */
|
|
69
|
+
//# sourceMappingURL=index.browser.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Result } from '@fgv/ts-utils';
|
|
2
|
+
import { FileTree } from '@fgv/ts-json-base';
|
|
3
|
+
import { CsvOptions } from './csvHelpers';
|
|
4
|
+
/**
|
|
5
|
+
* Reads a CSV file from a supplied path.
|
|
6
|
+
* @param srcPath - Source path from which the file is read.
|
|
7
|
+
* @param options - optional parameters to control the processing
|
|
8
|
+
* @returns The contents of the file.
|
|
9
|
+
* @beta
|
|
10
|
+
*/
|
|
11
|
+
export declare function readCsvFileSync(srcPath: string, options?: CsvOptions): Result<unknown>;
|
|
12
|
+
/**
|
|
13
|
+
* Reads a CSV file from a FileTree.
|
|
14
|
+
* @param fileTree - The FileTree to read from.
|
|
15
|
+
* @param filePath - Path of the file within the tree.
|
|
16
|
+
* @param options - optional parameters to control the processing
|
|
17
|
+
* @returns The parsed CSV data.
|
|
18
|
+
* @beta
|
|
19
|
+
*/
|
|
20
|
+
export declare function readCsvFromTree(fileTree: FileTree.FileTree, filePath: string, options?: CsvOptions): Result<unknown>;
|
|
21
|
+
//# sourceMappingURL=csvFileHelpers.d.ts.map
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2020 Erik Fortune
|
|
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.
|
|
22
|
+
*/
|
|
23
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
24
|
+
if (k2 === undefined) k2 = k;
|
|
25
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
26
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
27
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
28
|
+
}
|
|
29
|
+
Object.defineProperty(o, k2, desc);
|
|
30
|
+
}) : (function(o, m, k, k2) {
|
|
31
|
+
if (k2 === undefined) k2 = k;
|
|
32
|
+
o[k2] = m[k];
|
|
33
|
+
}));
|
|
34
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
35
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
36
|
+
}) : function(o, v) {
|
|
37
|
+
o["default"] = v;
|
|
38
|
+
});
|
|
39
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
40
|
+
var ownKeys = function(o) {
|
|
41
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
42
|
+
var ar = [];
|
|
43
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
44
|
+
return ar;
|
|
45
|
+
};
|
|
46
|
+
return ownKeys(o);
|
|
47
|
+
};
|
|
48
|
+
return function (mod) {
|
|
49
|
+
if (mod && mod.__esModule) return mod;
|
|
50
|
+
var result = {};
|
|
51
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
52
|
+
__setModuleDefault(result, mod);
|
|
53
|
+
return result;
|
|
54
|
+
};
|
|
55
|
+
})();
|
|
56
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
|
+
exports.readCsvFileSync = readCsvFileSync;
|
|
58
|
+
exports.readCsvFromTree = readCsvFromTree;
|
|
59
|
+
const ts_utils_1 = require("@fgv/ts-utils");
|
|
60
|
+
const fs = __importStar(require("fs"));
|
|
61
|
+
const path = __importStar(require("path"));
|
|
62
|
+
const csvHelpers_1 = require("./csvHelpers");
|
|
63
|
+
/**
|
|
64
|
+
* Reads a CSV file from a supplied path.
|
|
65
|
+
* @param srcPath - Source path from which the file is read.
|
|
66
|
+
* @param options - optional parameters to control the processing
|
|
67
|
+
* @returns The contents of the file.
|
|
68
|
+
* @beta
|
|
69
|
+
*/
|
|
70
|
+
function readCsvFileSync(srcPath, options) {
|
|
71
|
+
return (0, ts_utils_1.captureResult)(() => {
|
|
72
|
+
const fullPath = path.resolve(srcPath);
|
|
73
|
+
return fs.readFileSync(fullPath, 'utf8').toString();
|
|
74
|
+
}).onSuccess((body) => {
|
|
75
|
+
return (0, csvHelpers_1.parseCsvString)(body, options);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Reads a CSV file from a FileTree.
|
|
80
|
+
* @param fileTree - The FileTree to read from.
|
|
81
|
+
* @param filePath - Path of the file within the tree.
|
|
82
|
+
* @param options - optional parameters to control the processing
|
|
83
|
+
* @returns The parsed CSV data.
|
|
84
|
+
* @beta
|
|
85
|
+
*/
|
|
86
|
+
function readCsvFromTree(fileTree, filePath, options) {
|
|
87
|
+
return fileTree
|
|
88
|
+
.getFile(filePath)
|
|
89
|
+
.onSuccess((file) => file.getRawContents())
|
|
90
|
+
.onSuccess((contents) => (0, csvHelpers_1.parseCsvString)(contents, options));
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=csvFileHelpers.js.map
|
|
@@ -7,11 +7,11 @@ export interface CsvOptions {
|
|
|
7
7
|
delimiter?: string;
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
11
|
-
* @param
|
|
10
|
+
* Parses CSV data from a string.
|
|
11
|
+
* @param body - The CSV string to parse.
|
|
12
12
|
* @param options - optional parameters to control the processing
|
|
13
|
-
* @returns The
|
|
13
|
+
* @returns The parsed CSV data.
|
|
14
14
|
* @beta
|
|
15
15
|
*/
|
|
16
|
-
export declare function
|
|
16
|
+
export declare function parseCsvString(body: string, options?: CsvOptions): Result<unknown>;
|
|
17
17
|
//# sourceMappingURL=csvHelpers.d.ts.map
|
|
@@ -20,58 +20,20 @@
|
|
|
20
20
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
* SOFTWARE.
|
|
22
22
|
*/
|
|
23
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
24
|
-
if (k2 === undefined) k2 = k;
|
|
25
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
26
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
27
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
28
|
-
}
|
|
29
|
-
Object.defineProperty(o, k2, desc);
|
|
30
|
-
}) : (function(o, m, k, k2) {
|
|
31
|
-
if (k2 === undefined) k2 = k;
|
|
32
|
-
o[k2] = m[k];
|
|
33
|
-
}));
|
|
34
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
35
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
36
|
-
}) : function(o, v) {
|
|
37
|
-
o["default"] = v;
|
|
38
|
-
});
|
|
39
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
40
|
-
var ownKeys = function(o) {
|
|
41
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
42
|
-
var ar = [];
|
|
43
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
44
|
-
return ar;
|
|
45
|
-
};
|
|
46
|
-
return ownKeys(o);
|
|
47
|
-
};
|
|
48
|
-
return function (mod) {
|
|
49
|
-
if (mod && mod.__esModule) return mod;
|
|
50
|
-
var result = {};
|
|
51
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
52
|
-
__setModuleDefault(result, mod);
|
|
53
|
-
return result;
|
|
54
|
-
};
|
|
55
|
-
})();
|
|
56
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
|
-
exports.
|
|
24
|
+
exports.parseCsvString = parseCsvString;
|
|
58
25
|
const ts_utils_1 = require("@fgv/ts-utils");
|
|
59
|
-
const fs = __importStar(require("fs"));
|
|
60
26
|
const papaparse_1 = require("papaparse");
|
|
61
|
-
const path = __importStar(require("path"));
|
|
62
27
|
/**
|
|
63
|
-
*
|
|
64
|
-
* @param
|
|
28
|
+
* Parses CSV data from a string.
|
|
29
|
+
* @param body - The CSV string to parse.
|
|
65
30
|
* @param options - optional parameters to control the processing
|
|
66
|
-
* @returns The
|
|
31
|
+
* @returns The parsed CSV data.
|
|
67
32
|
* @beta
|
|
68
33
|
*/
|
|
69
|
-
function
|
|
34
|
+
function parseCsvString(body, options) {
|
|
70
35
|
return (0, ts_utils_1.captureResult)(() => {
|
|
71
|
-
const fullPath = path.resolve(srcPath);
|
|
72
|
-
const body = fs.readFileSync(fullPath, 'utf8').toString();
|
|
73
36
|
options = options !== null && options !== void 0 ? options : {};
|
|
74
|
-
// eslint-disable-next-line
|
|
75
37
|
return (0, papaparse_1.parse)(body, Object.assign({ transform: (s) => s.trim(), header: false, dynamicTyping: false, skipEmptyLines: 'greedy' }, options)).data.slice(1);
|
|
76
38
|
});
|
|
77
39
|
}
|
|
@@ -35,5 +35,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
35
35
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
// Export tree-shakeable functions
|
|
38
39
|
__exportStar(require("./csvHelpers"), exports);
|
|
40
|
+
// Filesystem helpers in separate module for tree-shaking
|
|
41
|
+
__exportStar(require("./csvFileHelpers"), exports);
|
|
39
42
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2020 Erik Fortune
|
|
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.
|
|
22
|
+
*/
|
|
23
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
24
|
+
if (k2 === undefined) k2 = k;
|
|
25
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
26
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
27
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
28
|
+
}
|
|
29
|
+
Object.defineProperty(o, k2, desc);
|
|
30
|
+
}) : (function(o, m, k, k2) {
|
|
31
|
+
if (k2 === undefined) k2 = k;
|
|
32
|
+
o[k2] = m[k];
|
|
33
|
+
}));
|
|
34
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
35
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
// Browser-safe hash exports - excludes Node.js crypto dependencies
|
|
39
|
+
__exportStar(require("./md5Normalizer.browser"), exports);
|
|
40
|
+
//# sourceMappingURL=index.browser.js.map
|