@fgv/ts-extras 5.0.0-2 → 5.0.0-21
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/.vscode/settings.json +27 -0
- package/config/api-extractor.json +343 -0
- package/config/rig.json +16 -0
- package/dist/ts-extras.d.ts +11 -4
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/packlets/zip-file-tree/zipFileTreeAccessors.d.ts +11 -4
- package/lib/packlets/zip-file-tree/zipFileTreeAccessors.js +57 -35
- package/lib/test/unit/converters.test.d.ts +2 -0
- package/lib/test/unit/csvHelpers.test.d.ts +2 -0
- package/lib/test/unit/extendedArray.test.d.ts +2 -0
- package/lib/test/unit/formatter.test.d.ts +2 -0
- package/lib/test/unit/md5Normalizer.test.d.ts +2 -0
- package/lib/test/unit/rangeOf.test.d.ts +2 -0
- package/lib/test/unit/recordJarHelpers.test.d.ts +2 -0
- package/lib/test/unit/zipFileTreeAccessors.test.d.ts +2 -0
- package/package.json +14 -15
- package/src/index.ts +31 -0
- package/src/packlets/conversion/converters.ts +124 -0
- package/src/packlets/conversion/index.ts +25 -0
- package/src/packlets/csv/csvHelpers.ts +58 -0
- package/src/packlets/csv/index.ts +23 -0
- package/src/packlets/experimental/extendedArray.ts +110 -0
- package/src/packlets/experimental/formatter.ts +114 -0
- package/src/packlets/experimental/index.ts +25 -0
- package/src/packlets/experimental/rangeOf.ts +222 -0
- package/src/packlets/hash/index.ts +23 -0
- package/src/packlets/hash/md5Normalizer.ts +38 -0
- package/src/packlets/record-jar/index.ts +23 -0
- package/src/packlets/record-jar/recordJarHelpers.ts +278 -0
- package/src/packlets/zip-file-tree/index.ts +33 -0
- package/src/packlets/zip-file-tree/zipFileTreeAccessors.ts +404 -0
- 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
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { unzipSync, unzip, Unzipped } from 'fflate';
|
|
24
|
+
import { Result, succeed, fail, captureResult, Converter, Validator, FileTree } from '@fgv/ts-utils';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Implementation of `FileTree.IFileTreeFileItem` for files in a ZIP archive.
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
export class ZipFileItem implements FileTree.IFileTreeFileItem {
|
|
31
|
+
/**
|
|
32
|
+
* Indicates that this `FileTree.FileTreeItem` is a file.
|
|
33
|
+
*/
|
|
34
|
+
public readonly type: 'file' = 'file';
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The absolute path of the file within the ZIP archive.
|
|
38
|
+
*/
|
|
39
|
+
public readonly absolutePath: string;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The name of the file
|
|
43
|
+
*/
|
|
44
|
+
public readonly name: string;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The base name of the file (without extension)
|
|
48
|
+
*/
|
|
49
|
+
public readonly baseName: string;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The extension of the file
|
|
53
|
+
*/
|
|
54
|
+
public readonly extension: string;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The pre-loaded contents of the file.
|
|
58
|
+
*/
|
|
59
|
+
private readonly _contents: string;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The ZIP file tree accessors that created this item.
|
|
63
|
+
*/
|
|
64
|
+
private readonly _accessors: ZipFileTreeAccessors;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Constructor for ZipFileItem.
|
|
68
|
+
* @param zipFilePath - The path of the file within the ZIP.
|
|
69
|
+
* @param contents - The pre-loaded contents of the file.
|
|
70
|
+
* @param accessors - The ZIP file tree accessors.
|
|
71
|
+
*/
|
|
72
|
+
public constructor(zipFilePath: string, contents: string, accessors: ZipFileTreeAccessors) {
|
|
73
|
+
this._contents = contents;
|
|
74
|
+
this._accessors = accessors;
|
|
75
|
+
this.absolutePath = '/' + zipFilePath;
|
|
76
|
+
this.name = accessors.getBaseName(zipFilePath);
|
|
77
|
+
this.extension = accessors.getExtension(zipFilePath);
|
|
78
|
+
this.baseName = accessors.getBaseName(zipFilePath, this.extension);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Gets the contents of the file as parsed JSON.
|
|
83
|
+
*/
|
|
84
|
+
public getContents(): Result<unknown>;
|
|
85
|
+
public getContents<T>(converter: Validator<T> | Converter<T>): Result<T>;
|
|
86
|
+
public getContents<T>(converter?: Validator<T> | Converter<T>): Result<T | unknown> {
|
|
87
|
+
return this.getRawContents()
|
|
88
|
+
.onSuccess((contents) => {
|
|
89
|
+
return captureResult(() => {
|
|
90
|
+
const parsed = JSON.parse(contents);
|
|
91
|
+
if (converter) {
|
|
92
|
+
if ('convert' in converter) {
|
|
93
|
+
return converter.convert(parsed);
|
|
94
|
+
} /* c8 ignore next 3 - validator branch functionally tested but coverage tool misses due to interface complexity */ else {
|
|
95
|
+
return (converter as Validator<T>).validate(parsed);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return succeed(parsed);
|
|
99
|
+
}).onFailure(() => {
|
|
100
|
+
return fail(`Failed to parse JSON from file: ${this.absolutePath}`);
|
|
101
|
+
});
|
|
102
|
+
})
|
|
103
|
+
.onFailure((error) => {
|
|
104
|
+
return fail(`Failed to get contents from file: ${error}`);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Gets the raw contents of the file as a string.
|
|
110
|
+
*/
|
|
111
|
+
public getRawContents(): Result<string> {
|
|
112
|
+
return succeed(this._contents);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Implementation of `IFileTreeDirectoryItem` for directories in a ZIP archive.
|
|
118
|
+
* @public
|
|
119
|
+
*/
|
|
120
|
+
export class ZipDirectoryItem implements FileTree.IFileTreeDirectoryItem {
|
|
121
|
+
/**
|
|
122
|
+
* Indicates that this `FileTree.FileTreeItem` is a directory.
|
|
123
|
+
*/
|
|
124
|
+
public readonly type: 'directory' = 'directory';
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* The absolute path of the directory within the ZIP archive.
|
|
128
|
+
*/
|
|
129
|
+
public readonly absolutePath: string;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* The name of the directory
|
|
133
|
+
*/
|
|
134
|
+
public readonly name: string;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* The ZIP file tree accessors that created this item.
|
|
138
|
+
*/
|
|
139
|
+
private readonly _accessors: ZipFileTreeAccessors;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Constructor for ZipDirectoryItem.
|
|
143
|
+
* @param directoryPath - The path of the directory within the ZIP.
|
|
144
|
+
* @param accessors - The ZIP file tree accessors.
|
|
145
|
+
*/
|
|
146
|
+
public constructor(directoryPath: string, accessors: ZipFileTreeAccessors) {
|
|
147
|
+
this._accessors = accessors;
|
|
148
|
+
this.absolutePath = '/' + directoryPath.replace(/\/$/, ''); // Normalize path
|
|
149
|
+
this.name = accessors.getBaseName(directoryPath);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Gets the children of the directory.
|
|
154
|
+
*/
|
|
155
|
+
public getChildren(): Result<ReadonlyArray<FileTree.FileTreeItem>> {
|
|
156
|
+
return this._accessors.getChildren(this.absolutePath);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* File tree accessors for ZIP archives.
|
|
162
|
+
* @public
|
|
163
|
+
*/
|
|
164
|
+
export class ZipFileTreeAccessors implements FileTree.IFileTreeAccessors {
|
|
165
|
+
/**
|
|
166
|
+
* The unzipped file data.
|
|
167
|
+
*/
|
|
168
|
+
private readonly _files: Unzipped;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Optional prefix to prepend to paths.
|
|
172
|
+
*/
|
|
173
|
+
private readonly _prefix: string;
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Cache of all items in the ZIP for efficient lookups.
|
|
177
|
+
*/
|
|
178
|
+
private readonly _itemCache: Map<string, FileTree.FileTreeItem> = new Map();
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Constructor for ZipFileTreeAccessors.
|
|
182
|
+
* @param files - The unzipped file data from fflate.
|
|
183
|
+
* @param prefix - Optional prefix to prepend to paths.
|
|
184
|
+
*/
|
|
185
|
+
private constructor(files: Unzipped, prefix?: string) {
|
|
186
|
+
this._files = files;
|
|
187
|
+
this._prefix = prefix || '';
|
|
188
|
+
this._buildItemCache();
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Creates a new ZipFileTreeAccessors instance from a ZIP file buffer (synchronous).
|
|
193
|
+
* @param zipBuffer - The ZIP file as an ArrayBuffer or Uint8Array.
|
|
194
|
+
* @param prefix - Optional prefix to prepend to paths.
|
|
195
|
+
* @returns Result containing the ZipFileTreeAccessors instance.
|
|
196
|
+
*/
|
|
197
|
+
public static fromBuffer(
|
|
198
|
+
zipBuffer: ArrayBuffer | Uint8Array,
|
|
199
|
+
prefix?: string
|
|
200
|
+
): Result<ZipFileTreeAccessors> {
|
|
201
|
+
try {
|
|
202
|
+
/* c8 ignore next 1 - defense in depth */
|
|
203
|
+
const uint8Buffer = zipBuffer instanceof Uint8Array ? zipBuffer : new Uint8Array(zipBuffer);
|
|
204
|
+
const files = unzipSync(uint8Buffer);
|
|
205
|
+
return succeed(new ZipFileTreeAccessors(files, prefix));
|
|
206
|
+
} catch (error) {
|
|
207
|
+
/* c8 ignore next 1 - defensive coding: fflate always throws Error objects in practice */
|
|
208
|
+
return fail(`Failed to load ZIP archive: ${error instanceof Error ? error.message : String(error)}`);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Creates a new ZipFileTreeAccessors instance from a ZIP file buffer (asynchronous).
|
|
214
|
+
* @param zipBuffer - The ZIP file as an ArrayBuffer or Uint8Array.
|
|
215
|
+
* @param prefix - Optional prefix to prepend to paths.
|
|
216
|
+
* @returns Promise containing Result with the ZipFileTreeAccessors instance.
|
|
217
|
+
*/
|
|
218
|
+
public static async fromBufferAsync(
|
|
219
|
+
zipBuffer: ArrayBuffer | Uint8Array,
|
|
220
|
+
prefix?: string
|
|
221
|
+
): Promise<Result<ZipFileTreeAccessors>> {
|
|
222
|
+
return new Promise((resolve) => {
|
|
223
|
+
try {
|
|
224
|
+
/* c8 ignore next 1 - defense in depth */
|
|
225
|
+
const uint8Buffer = zipBuffer instanceof Uint8Array ? zipBuffer : new Uint8Array(zipBuffer);
|
|
226
|
+
unzip(uint8Buffer, (err, files) => {
|
|
227
|
+
if (err) {
|
|
228
|
+
resolve(fail(`Failed to load ZIP archive: ${err.message}`));
|
|
229
|
+
} else {
|
|
230
|
+
resolve(succeed(new ZipFileTreeAccessors(files, prefix)));
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
} catch (error) {
|
|
234
|
+
/* c8 ignore next 5 - defensive coding: fflate always throws Error objects in practice */
|
|
235
|
+
resolve(
|
|
236
|
+
fail(`Failed to load ZIP archive: ${error instanceof Error ? error.message : String(error)}`)
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Creates a new ZipFileTreeAccessors instance from a File object (browser environment).
|
|
244
|
+
* @param file - The File object containing ZIP data.
|
|
245
|
+
* @param prefix - Optional prefix to prepend to paths.
|
|
246
|
+
* @returns Result containing the ZipFileTreeAccessors instance.
|
|
247
|
+
*/
|
|
248
|
+
public static async fromFile(file: File, prefix?: string): Promise<Result<ZipFileTreeAccessors>> {
|
|
249
|
+
try {
|
|
250
|
+
const arrayBuffer = await file.arrayBuffer();
|
|
251
|
+
return await ZipFileTreeAccessors.fromBufferAsync(new Uint8Array(arrayBuffer), prefix);
|
|
252
|
+
} catch (error) {
|
|
253
|
+
return fail(`Failed to read file: ${error instanceof Error ? error.message : String(error)}`);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Builds the cache of all items in the ZIP archive.
|
|
259
|
+
*/
|
|
260
|
+
private _buildItemCache(): void {
|
|
261
|
+
const directories = new Set<string>();
|
|
262
|
+
|
|
263
|
+
// Process all files and collect directory paths
|
|
264
|
+
for (const [relativePath, fileData] of Object.entries(this._files)) {
|
|
265
|
+
// Skip directories in fflate output (they have null data)
|
|
266
|
+
/* c8 ignore next 5 - handles explicit directory entries from external ZIP tools (fflate doesn't create these) */
|
|
267
|
+
if (fileData === null || fileData === undefined) {
|
|
268
|
+
const dirPath = relativePath.replace(/\/$/, '');
|
|
269
|
+
if (dirPath) {
|
|
270
|
+
directories.add(dirPath);
|
|
271
|
+
}
|
|
272
|
+
} else {
|
|
273
|
+
// Extract directory paths from file paths
|
|
274
|
+
const pathParts = relativePath.split('/');
|
|
275
|
+
for (let i = 1; i < pathParts.length; i++) {
|
|
276
|
+
const dirPath = pathParts.slice(0, i).join('/');
|
|
277
|
+
if (dirPath) {
|
|
278
|
+
directories.add(dirPath);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// Add the file item with its contents
|
|
283
|
+
const absolutePath = this.resolveAbsolutePath(relativePath);
|
|
284
|
+
const contents = new TextDecoder().decode(fileData);
|
|
285
|
+
const item = new ZipFileItem(relativePath, contents, this);
|
|
286
|
+
this._itemCache.set(absolutePath, item);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// Add directory items to cache
|
|
291
|
+
directories.forEach((dirPath) => {
|
|
292
|
+
const absolutePath = this.resolveAbsolutePath(dirPath);
|
|
293
|
+
const item = new ZipDirectoryItem(dirPath, this);
|
|
294
|
+
this._itemCache.set(absolutePath, item);
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Resolves paths to an absolute path.
|
|
300
|
+
*/
|
|
301
|
+
public resolveAbsolutePath(...paths: string[]): string {
|
|
302
|
+
const joinedPath = this.joinPaths(...paths);
|
|
303
|
+
const prefixed = this._prefix ? this.joinPaths(this._prefix, joinedPath) : joinedPath;
|
|
304
|
+
return prefixed.startsWith('/') ? prefixed : '/' + prefixed;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Gets the extension of a path.
|
|
309
|
+
*/
|
|
310
|
+
public getExtension(path: string): string {
|
|
311
|
+
const name = this.getBaseName(path);
|
|
312
|
+
const lastDotIndex = name.lastIndexOf('.');
|
|
313
|
+
return lastDotIndex >= 0 ? name.substring(lastDotIndex) : '';
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Gets the base name of a path.
|
|
318
|
+
*/
|
|
319
|
+
public getBaseName(path: string, suffix?: string): string {
|
|
320
|
+
const normalizedPath = path.replace(/\/$/, ''); // Remove trailing slash
|
|
321
|
+
const parts = normalizedPath.split('/');
|
|
322
|
+
let baseName = parts[parts.length - 1] || '';
|
|
323
|
+
|
|
324
|
+
if (suffix && baseName.endsWith(suffix)) {
|
|
325
|
+
baseName = baseName.substring(0, baseName.length - suffix.length);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
return baseName;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Joins paths together.
|
|
333
|
+
*/
|
|
334
|
+
public joinPaths(...paths: string[]): string {
|
|
335
|
+
return paths
|
|
336
|
+
.filter((p) => p && p.length > 0)
|
|
337
|
+
.map((p) => p.replace(/^\/+|\/+$/g, '')) // Remove leading/trailing slashes
|
|
338
|
+
.join('/')
|
|
339
|
+
.replace(/\/+/g, '/'); // Normalize multiple slashes
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Gets an item from the file tree.
|
|
344
|
+
*/
|
|
345
|
+
public getItem(path: string): Result<FileTree.FileTreeItem> {
|
|
346
|
+
const absolutePath = this.resolveAbsolutePath(path);
|
|
347
|
+
const item = this._itemCache.get(absolutePath);
|
|
348
|
+
|
|
349
|
+
if (item) {
|
|
350
|
+
return succeed(item);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
return fail(`Item not found: ${absolutePath}`);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Gets the contents of a file in the file tree.
|
|
358
|
+
*/
|
|
359
|
+
public getFileContents(path: string): Result<string> {
|
|
360
|
+
return this.getItem(path).onSuccess((item) => {
|
|
361
|
+
if (item.type !== 'file') {
|
|
362
|
+
return fail(`Path is not a file: ${path}`);
|
|
363
|
+
}
|
|
364
|
+
return item.getRawContents();
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Gets the children of a directory in the file tree.
|
|
370
|
+
*/
|
|
371
|
+
public getChildren(path: string): Result<ReadonlyArray<FileTree.FileTreeItem>> {
|
|
372
|
+
const absolutePath = this.resolveAbsolutePath(path);
|
|
373
|
+
const children: FileTree.FileTreeItem[] = [];
|
|
374
|
+
|
|
375
|
+
// Find all items that are direct children of this directory
|
|
376
|
+
for (const [itemPath, item] of this._itemCache) {
|
|
377
|
+
if (this._isDirectChild(absolutePath, itemPath)) {
|
|
378
|
+
children.push(item);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
return succeed(children);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* Checks if childPath is a direct child of parentPath.
|
|
387
|
+
*/
|
|
388
|
+
private _isDirectChild(parentPath: string, childPath: string): boolean {
|
|
389
|
+
// Normalize paths
|
|
390
|
+
const normalizedParent = parentPath.replace(/\/$/, '');
|
|
391
|
+
const normalizedChild = childPath.replace(/\/$/, '');
|
|
392
|
+
|
|
393
|
+
// Child must start with parent path
|
|
394
|
+
if (!normalizedChild.startsWith(normalizedParent + '/')) {
|
|
395
|
+
return false;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// Get the relative path from parent to child
|
|
399
|
+
const relativePath = normalizedChild.substring(normalizedParent.length + 1);
|
|
400
|
+
|
|
401
|
+
// Direct child means no additional slashes in the relative path
|
|
402
|
+
return !relativePath.includes('/');
|
|
403
|
+
}
|
|
404
|
+
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
# Change Log - @fgv/ts-extras
|
|
2
|
-
|
|
3
|
-
This log was last generated on Thu, 17 Jul 2025 00:13:24 GMT and should not be manually modified.
|
|
4
|
-
|
|
5
|
-
## 5.0.0
|
|
6
|
-
Thu, 17 Jul 2025 00:13:24 GMT
|
|
7
|
-
|
|
8
|
-
### Updates
|
|
9
|
-
|
|
10
|
-
- upgrade dependencies
|
|
11
|
-
- bump version
|
|
12
|
-
|
|
13
|
-
## 4.6.0
|
|
14
|
-
Wed, 02 Jul 2025 05:48:16 GMT
|
|
15
|
-
|
|
16
|
-
_Version update only_
|
|
17
|
-
|
|
18
|
-
## 4.5.1
|
|
19
|
-
Wed, 02 Jul 2025 05:47:11 GMT
|
|
20
|
-
|
|
21
|
-
### Updates
|
|
22
|
-
|
|
23
|
-
- update rushstack
|
|
24
|
-
|
|
25
|
-
## 4.5.0
|
|
26
|
-
Tue, 01 Jul 2025 03:26:11 GMT
|
|
27
|
-
|
|
28
|
-
_Version update only_
|
|
29
|
-
|
|
30
|
-
## 4.4.0
|
|
31
|
-
Sat, 01 Feb 2025 17:13:10 GMT
|
|
32
|
-
|
|
33
|
-
_Version update only_
|
|
34
|
-
|
|
35
|
-
## 4.3.0
|
|
36
|
-
Thu, 30 Jan 2025 00:35:17 GMT
|
|
37
|
-
|
|
38
|
-
_Version update only_
|
|
39
|
-
|
|
40
|
-
## 4.2.2
|
|
41
|
-
Thu, 23 Jan 2025 06:19:32 GMT
|
|
42
|
-
|
|
43
|
-
_Version update only_
|
|
44
|
-
|
|
45
|
-
## 4.2.1
|
|
46
|
-
Tue, 21 Jan 2025 04:19:21 GMT
|
|
47
|
-
|
|
48
|
-
_Version update only_
|
|
49
|
-
|
|
50
|
-
## 4.2.0
|
|
51
|
-
Mon, 20 Jan 2025 09:46:53 GMT
|
|
52
|
-
|
|
53
|
-
_Version update only_
|
|
54
|
-
|
|
55
|
-
## 4.1.0
|
|
56
|
-
Thu, 09 Jan 2025 05:33:39 GMT
|
|
57
|
-
|
|
58
|
-
### Updates
|
|
59
|
-
|
|
60
|
-
- update dependencies
|
|
61
|
-
|
|
62
|
-
## 4.0.2
|
|
63
|
-
Tue, 14 May 2024 14:45:53 GMT
|
|
64
|
-
|
|
65
|
-
_Version update only_
|
|
66
|
-
|
|
67
|
-
## 4.0.1
|
|
68
|
-
Tue, 14 May 2024 05:02:20 GMT
|
|
69
|
-
|
|
70
|
-
### Updates
|
|
71
|
-
|
|
72
|
-
- publish
|
|
73
|
-
|
|
74
|
-
## 4.0.0
|
|
75
|
-
Tue, 14 May 2024 03:09:27 GMT
|
|
76
|
-
|
|
77
|
-
### Updates
|
|
78
|
-
|
|
79
|
-
- move templateString, rangeOf and isoDate converters from ts-utils
|
|
80
|
-
- update generated api docs
|
|
81
|
-
|
|
82
|
-
## 3.0.0
|
|
83
|
-
Mon, 22 Jan 2024 07:00:18 GMT
|
|
84
|
-
|
|
85
|
-
### Updates
|
|
86
|
-
|
|
87
|
-
- refactor hash implementation
|
|
88
|
-
- refactor and cleanup
|
|
89
|
-
- Factor extras into their own package
|
|
90
|
-
|
|
91
|
-
## 2.2.0
|
|
92
|
-
Thu, 18 Jan 2024 05:45:04 GMT
|
|
93
|
-
|
|
94
|
-
### Updates
|
|
95
|
-
|
|
96
|
-
- refactor and cleanup
|
|
97
|
-
- Factor extras into their own package
|
|
98
|
-
|
package/lib/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,GAAG,MAAM,gBAAgB,CAAC;AACtC,OAAO,KAAK,YAAY,MAAM,yBAAyB,CAAC;AACxD,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AACxC,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAC;AACnD,OAAO,KAAK,WAAW,MAAM,0BAA0B,CAAC;AAExD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC"}
|
package/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,oDAAsC;AAQjB,kBAAG;AAPxB,sEAAwD;AAO9B,oCAAY;AANtC,sDAAwC;AAMA,oBAAI;AAL5C,iEAAmD;AAKL,8BAAS;AAJvD,sEAAwD;AAIC,kCAAW;AAFpE,sDAAmD;AAE1C,2FAFA,uBAAU,OAEA","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport * as Csv from './packlets/csv';\nimport * as Experimental from './packlets/experimental';\nimport * as Hash from './packlets/hash';\nimport * as RecordJar from './packlets/record-jar';\nimport * as ZipFileTree from './packlets/zip-file-tree';\n\nimport { Converters } from './packlets/conversion';\n\nexport { Converters, Csv, Experimental, Hash, RecordJar, ZipFileTree };\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"converters.d.ts","sourceRoot":"","sources":["../../../src/packlets/conversion/converters.ts"],"names":[],"mappings":"AAsBA,OAAO,EA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W,CAAoB,SAAS,EAAE,sBAAO,CAAC,WAAW,CAAC,CAAC;AACxE,CAAC","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Conversion, Converter, Converters, Result, captureResult, fail, succeed } from '@fgv/ts-utils';\nimport { DateTime } from 'luxon';\nimport Mustache from 'mustache';\nimport { ExtendedArray, RangeOf, RangeOfProperties } from '../experimental';\n\n/**\n * Helper function to create a `StringConverter` which converts\n * `unknown` to `string`, applying template conversions supplied at construction time or at\n * runtime as context.\n * @remarks\n * Template conversions are applied using `mustache` syntax.\n * @param defaultContext - Optional default context to use for template values.\n * @returns A new `Converter` returning `string`.\n * @public\n */\nexport function templateString(defaultContext?: unknown): Conversion.StringConverter<string, unknown> {\n return new Conversion.StringConverter<string, unknown>(\n defaultContext,\n undefined,\n (from: unknown, __self: Converter<string, unknown>, context?: unknown) => {\n if (typeof from !== 'string') {\n return fail(`Not a string: ${JSON.stringify(from)}`);\n }\n return captureResult(() => Mustache.render(from, context));\n }\n );\n}\n\n/**\n * A `Converter` which converts an iso formatted string, a number or a `Date` object to\n * a `Date` object.\n * @public\n */\nexport const isoDate: Converter<Date, unknown> = new Conversion.BaseConverter<Date>((from: unknown) => {\n if (typeof from === 'string') {\n const dt = DateTime.fromISO(from);\n if (dt.isValid) {\n return succeed(dt.toJSDate());\n }\n return fail(`Invalid date: ${dt.invalidExplanation}`);\n } else if (typeof from === 'number') {\n return succeed(new Date(from));\n } else if (from instanceof Date) {\n return succeed(from);\n }\n return fail(`Cannot convert ${JSON.stringify(from)} to Date`);\n});\n\n/**\n * A helper function to create a `Converter` which converts `unknown` to {@link Experimental.ExtendedArray | ExtendedArray<T>}.\n * @remarks\n * If `onError` is `'failOnError'` (default), then the entire conversion fails if any element cannot\n * be converted. If `onError` is `'ignoreErrors'`, then failing elements are silently ignored.\n * @param converter - `Converter` used to convert each item in the array\n * @param ignoreErrors - Specifies treatment of unconvertible elements\n * @beta\n */\nexport function extendedArrayOf<T, TC = undefined>(\n label: string,\n converter: Converter<T, TC>,\n onError: Conversion.OnError = 'failOnError'\n): Converter<ExtendedArray<T>, TC> {\n return Converters.arrayOf(converter, onError).map((items: T[]) => {\n return captureResult(() => new ExtendedArray(label, ...items));\n });\n}\n\n/**\n * A helper wrapper to construct a `Converter` which converts to an arbitrary strongly-typed\n * range of some comparable type.\n * @param converter - `Converter` used to convert `min` and `max` extent of the range.\n * @param constructor - Static constructor to instantiate the object.\n * @public\n */\nexport function rangeTypeOf<T, RT extends RangeOf<T>, TC = unknown>(\n converter: Converter<T, TC>,\n constructor: (init: RangeOfProperties<T>) => Result<RT>\n): Converter<RT, TC> {\n return new Conversion.BaseConverter((from: unknown, __self, context?: TC) => {\n const result = Converters.object(\n {\n min: converter,\n max: converter\n },\n { optionalFields: ['min', 'max'] }\n ).convert(from, context);\n if (result.isSuccess()) {\n return constructor({ min: result.value.min, max: result.value.max });\n }\n return fail(result.message);\n });\n}\n\n/**\n * A helper wrapper to construct a `Converter` which converts to {@link Experimental.RangeOf | RangeOf<T>}\n * where `<T>` is some comparable type.\n * @param converter - `Converter` used to convert `min` and `max` extent of the range.\n * @public\n */\nexport function rangeOf<T, TC = unknown>(converter: Converter<T, TC>): Converter<RangeOf<T>, TC> {\n return rangeTypeOf<T, RangeOf<T>, TC>(converter, RangeOf.createRange);\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/conversion/index.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/conversion/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,yDAA2C;AAElC,gCAAU","sourcesContent":["/*\n * Copyright (c) 2023 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport * as Converters from './converters';\n\nexport { Converters };\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"csvHelpers.d.ts","sourceRoot":"","sources":["../../../src/packlets/csv/csvHelpers.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,MAAM,EAAiB,MAAM,eAAe,CAAC;AAKtD;;;GAGG;AAEH,MAAM,WAAW,UAAU;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,CActF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"csvHelpers.js","sourceRoot":"","sources":["../../../src/packlets/csv/csvHelpers.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBH,0CAcC;AAnCD,4CAAsD;AACtD,uCAAyB;AACzB,yCAAkC;AAClC,2CAA6B;AAW7B;;;;;;GAMG;AACH,SAAgB,eAAe,CAAC,OAAe,EAAE,OAAoB;IACnE,OAAO,IAAA,wBAAa,EAAC,GAAG,EAAE;QACxB,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACvC,MAAM,IAAI,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC;QAC1D,OAAO,GAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,CAAC;QACxB,2BAA2B;QAC3B,OAAO,IAAA,iBAAK,EAAC,IAAI,kBACf,SAAS,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,EAClC,MAAM,EAAE,KAAK,EACb,aAAa,EAAE,KAAK,EACpB,cAAc,EAAE,QAAQ,IACrB,OAAO,EACV,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACnB,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Result, captureResult } from '@fgv/ts-utils';\nimport * as fs from 'fs';\nimport { parse } from 'papaparse';\nimport * as path from 'path';\n\n/**\n * Options for {@link Csv.readCsvFileSync | readCsvFileSync}\n * @beta\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport interface CsvOptions {\n delimiter?: string;\n}\n\n/**\n * Reads a CSV file from a supplied path.\n * @param srcPath - Source path from which the file is read.\n * @param options - optional parameters to control the processing\n * @returns The contents of the file.\n * @beta\n */\nexport function readCsvFileSync(srcPath: string, options?: CsvOptions): Result<unknown> {\n return captureResult(() => {\n const fullPath = path.resolve(srcPath);\n const body = fs.readFileSync(fullPath, 'utf8').toString();\n options = options ?? {};\n // eslint-disable-next-line\n return parse(body, {\n transform: (s: string) => s.trim(),\n header: false,\n dynamicTyping: false,\n skipEmptyLines: 'greedy',\n ...options\n }).data.slice(1);\n });\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/csv/index.ts"],"names":[],"mappings":"AAsBA,cAAc,cAAc,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/csv/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;AAEH,+CAA6B","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nexport * from './csvHelpers';\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extendedArray.d.ts","sourceRoot":"","sources":["../../../src/packlets/experimental/extendedArray.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,MAAM,EAAiB,MAAM,eAAe,CAAC;AAEtD;;;;GAIG;AACH,qBAAa,aAAa,CAAC,CAAC,CAAE,SAAQ,KAAK,CAAC,CAAC,CAAC;IAC5C,SAAgB,eAAe,EAAE,MAAM,CAAC;IAExC;;;;OAIG;gBACgB,eAAe,EAAE,MAAM,EAAE,GAAG,KAAK,EAAE,CAAC,EAAE;IAKzD;;;;;;OAMG;WACW,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,IAAI,aAAa,CAAC,CAAC,CAAC;IAIhE;;;;;;;OAOG;IACI,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC;IAW1D;;;;;;OAMG;IACI,KAAK,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC;IAO7C;;;;;;;OAOG;IACI,UAAU,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC;IAOpD;;;;OAIG;IACI,GAAG,IAAI,CAAC,EAAE;CAGlB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extendedArray.js","sourceRoot":"","sources":["../../../src/packlets/experimental/extendedArray.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,4CAAsD;AAEtD;;;;GAIG;AACH,MAAa,aAAiB,SAAQ,KAAQ;IAG5C;;;;OAIG;IACH,YAAmB,eAAuB,EAAE,GAAG,KAAU;QACvD,KAAK,CAAC,GAAG,KAAK,CAAC,CAAC;QAChB,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;IACzC,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,eAAe,CAAI,CAAO;QACtC,OAAO,CAAC,YAAY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CAAC,CAAC;IAC1B,CAAC;CACF;AAhFD,sCAgFC","sourcesContent":["/*\r\n * Copyright (c) 2020 Erik Fortune\r\n *\r\n * Permission is hereby granted, free of charge, to any person obtaining a copy\r\n * of this software and associated documentation files (the \"Software\"), to deal\r\n * in the Software without restriction, including without limitation the rights\r\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n * copies of the Software, and to permit persons to whom the Software is\r\n * furnished to do so, subject to the following conditions:\r\n *\r\n * The above copyright notice and this permission notice shall be included in all\r\n * copies or substantial portions of the Software.\r\n *\r\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\n * SOFTWARE.\r\n */\r\n\r\nimport { Result, fail, succeed } from '@fgv/ts-utils';\r\n\r\n/**\r\n * An experimental array template which extend built-in `Array` to include a handful\r\n * of predicates which return `Result<T>`.\r\n * @beta\r\n */\r\nexport class ExtendedArray<T> extends Array<T> {\r\n public readonly itemDescription: string;\r\n\r\n /**\r\n * Constructs an {@link Experimental.ExtendedArray | ExtendedArray}.\r\n * @param itemDescription - Brief description of the type of each item in this array.\r\n * @param items - The initial contents of the array.\r\n */\r\n public constructor(itemDescription: string, ...items: T[]) {\r\n super(...items);\r\n this.itemDescription = itemDescription;\r\n }\r\n\r\n /**\r\n * Type guard to determine if some arbitrary array is an\r\n * {@link Experimental.ExtendedArray}\r\n * @param a - The `Array` to be tested.\r\n * @returns Returns `true` if `a` is an {@link Experimental.ExtendedArray | ExtendedArray},\r\n * `false` otherwise.\r\n */\r\n public static isExtendedArray<T>(a?: T[]): a is ExtendedArray<T> {\r\n return a instanceof ExtendedArray;\r\n }\r\n\r\n /**\r\n * Determines if this array contains exactly one element which matches\r\n * a supplied predicate.\r\n * @param predicate - The predicate function to be applied.\r\n * @returns Returns `Success<T>` with the single matching\r\n * result if exactly one item matches `predicate`. Returns `Failure<T>`\r\n * with an error message if there are no matches or more than one match.\r\n */\r\n public single(predicate?: (item: T) => boolean): Result<T> {\r\n const match = predicate ? this.filter(predicate) : this;\r\n if (match.length === 1) {\r\n return succeed(match[0]);\r\n }\r\n if (match.length === 0) {\r\n return fail(`${this.itemDescription} not found`);\r\n }\r\n return fail(`${this.itemDescription} matches ${match.length} items`);\r\n }\r\n\r\n /**\r\n * Returns the first element of an {@link Experimental.ExtendedArray | ExtendedArray}. Fails with an\r\n * error message if the array is empty.\r\n * @param failMessage - Optional message to be displayed in the event of failure.\r\n * @returns Returns `Success<T>` with the value of the first element\r\n * in the array, or `Failure<T>` with an error message if the array is empty.\r\n */\r\n public first(failMessage?: string): Result<T> {\r\n if (this.length > 0) {\r\n return succeed(this[0]);\r\n }\r\n return fail(failMessage ?? `${this.itemDescription} not found`);\r\n }\r\n\r\n /**\r\n * Returns an array containing all elements of an {@link Experimental.ExtendedArray | ExtendedArray}.\r\n * Fails with an error message if the array is empty.\r\n * @param failMessage - Optional message to be displayed in the event of failure.\r\n * @returns Returns `Success<T>` with a new (non-extended) `Array`\r\n * containing the elements of this array, or `Failure<T>` with an error message\r\n * if the array is empty.\r\n */\r\n public atLeastOne(failMessage?: string): Result<T[]> {\r\n if (this.length > 0) {\r\n return succeed(Array.from(this));\r\n }\r\n return fail(failMessage ?? `${this.itemDescription} not found`);\r\n }\r\n\r\n /**\r\n * Gets a new (non-extended) `Array` containing all of the elements from this\r\n * {@link Experimental.ExtendedArray | ExtendedArray}.\r\n * @returns A new (non-extended) `Array<T>`.\r\n */\r\n public all(): T[] {\r\n return Array.from(this);\r\n }\r\n}\r\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../../src/packlets/experimental/formatter.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,MAAM,EAAsC,MAAM,eAAe,CAAC;AAK3E;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC;AAE1D;;;GAGG;AAEH,MAAM,WAAW,WAAW;IAC1B;;;;;OAKG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;CACxC;AAED;;;GAGG;AACH,qBAAa,eAAe;IAC1B;;;;;;OAMG;IACH,SAAS,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;IAOjG;;OAEG;IACI,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;CAGhD;AAED;;;;GAIG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC;AAEvE;;;;GAIG;AACH,MAAM,MAAM,0BAA0B,CAAC,GAAG,SAAS,aAAa,EAAE,CAAC,IAAI,MAAM,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;AACjG;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,CAAC,CAAC,IAAI,0BAA0B,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC;AAEjF;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,aAAa,EAAE,SAAS,CAAC,CAAC,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,OAAO,IAAA,kBAAO,EAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Result, captureResult, mapResults, succeed } from '@fgv/ts-utils';\nimport Mustache from 'mustache';\n\nMustache.escape = (s: string) => s;\n\n/**\n * Destination format for some formatted string.\n * @beta\n */\nexport type FormatTargets = 'text' | 'markdown' | 'embed';\n\n/**\n * Interface for an object that can be formatted.\n * @beta\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport interface Formattable {\n /**\n * Formats an object using the supplied mustache template.\n * @param format - A mustache template used to format the object.\n * @returns `Success<string>` with the resulting string, or `Failure<string>`\n * with an error message if an error occurs.\n */\n format(format: string): Result<string>;\n}\n\n/**\n * Base class which adds common formatting.\n * @beta\n */\nexport class FormattableBase {\n /**\n * Helper enables derived classes to add named details to a formatted presentation.\n * @param details - An array of detail description strings.\n * @param label - Label to use for the new detail.\n * @param value - Value to use for the new detail.\n * @internal\n */\n protected static _tryAddDetail(details: string[], label: string, value: string | undefined): void {\n if (value !== undefined) {\n const padded = ` ${label}:`.padEnd(20, ' ');\n details.push(`${padded} ${value}`);\n }\n }\n\n /**\n * {@inheritdoc Experimental.Formattable.format}\n */\n public format(template: string): Result<string> {\n return captureResult(() => Mustache.render(template, this));\n }\n}\n\n/**\n * Type definition for a formatting function, which takes a `string` and an\n * item and returns `Result<string>`.\n * @beta\n */\nexport type Formatter<T> = (format: string, item: T) => Result<string>;\n\n/**\n * A collection of {@link Experimental.Formatter | formatters} indexed by target name, to enable\n * different format methods per output target.\n * @beta\n */\nexport type FormattersByExtendedTarget<TFT extends FormatTargets, T> = Record<TFT, Formatter<T>>;\n/**\n * A collection of {@link Experimental.Formatter | formatters} indexed by the\n * {@link Experimental.FormatTargets | default supported target formats}.\n * @beta\n */\nexport type FormattersByTarget<T> = FormattersByExtendedTarget<FormatTargets, T>;\n\n/**\n * Formats a list of items using the supplied template and formatter, one result\n * per output line.\n * @param format - A mustache template used to format each item.\n * @param items - The items to be formatted.\n * @param itemFormatter - The {@link Experimental.Formatter | Formatter<T>} used to format each item.\n * @returns The resulting string.\n * @beta\n */\nexport function formatList<T>(format: string, items: T[], itemFormatter: Formatter<T>): Result<string> {\n return mapResults(\n items.map((item) => {\n return itemFormatter(format, item);\n })\n ).onSuccess((results: string[]) => {\n const filtered = results.filter((s) => s !== '');\n return succeed(filtered.join('\\n'));\n });\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/experimental/index.ts"],"names":[],"mappings":"AAsBA,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/experimental/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;AAEH,kDAAgC;AAChC,8CAA4B;AAC5B,4CAA0B","sourcesContent":["/*\n * Copyright (c) 2023 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nexport * from './extendedArray';\nexport * from './formatter';\nexport * from './rangeOf';\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rangeOf.d.ts","sourceRoot":"","sources":["../../../src/packlets/experimental/rangeOf.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,MAAM,EAAiB,MAAM,eAAe,CAAC;AAGtD;;;GAGG;AAEH,MAAM,WAAW,iBAAiB,CAAC,CAAC;IAClC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACjB,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;CAClB;AAED;;;;;GAKG;AAEH,MAAM,WAAW,cAAc;IAC7B,OAAO,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AO,OAAO,CAAC,eAAe,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IACzC,CAAC;CACF;AA7JD,0BA6JC","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Result, captureResult } from '@fgv/ts-utils';\nimport Mustache from 'mustache';\n\n/**\n * Represents a generic range of some comparable type `<T>`.\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport interface RangeOfProperties<T> {\n readonly min?: T;\n readonly max?: T;\n}\n\n/**\n * Format strings (in mustache format) to\n * use for both open-ended and complete\n * {@link Experimental.RangeOf | RangeOf<T>}.\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport interface RangeOfFormats {\n minOnly: string;\n maxOnly: string;\n minMax: string;\n}\n\n/**\n * Default {@link Experimental.RangeOfFormats | formats} to use for both\n * open-ended and complete {@link Experimental.RangeOf | RangeOf<T>}.\n * @public\n */\nexport const DEFAULT_RANGEOF_FORMATS: RangeOfFormats = {\n minOnly: '{{min}}-',\n maxOnly: '-{{max}}',\n minMax: '{{min}}-{{max}}'\n};\n\n/**\n * Simple implementation of a possibly open-ended range of some comparable\n * type `<T>` with test and formatting.\n * @public\n */\nexport class RangeOf<T> implements RangeOfProperties<T> {\n /**\n * Minimum extent of the range.\n */\n public readonly min?: T;\n /**\n * Maximum extent of the range.\n */\n public readonly max?: T;\n\n /**\n * Creates a new {@link Experimental.RangeOf | RangeOf<T>}.\n * @param min - Optional minimum extent of the range.\n * @param max - Optional maximum extent of the range.\n */\n public constructor(min?: T, max?: T) {\n if (min !== undefined && max !== undefined && this._compare(min, max) === 'greater') {\n throw new Error(`Inverted range - ${JSON.stringify(min)} must be <= ${JSON.stringify(max)}.`);\n }\n this.min = min;\n this.max = max;\n }\n\n /**\n * Static constructor for a {@link Experimental.RangeOf | RangeOf<T>}.\n * @param init - {@link Experimental.RangeOfProperties | Range initializer}.\n * @returns A new {@link Experimental.RangeOf | RangeOf<T>}.\n */\n public static createRange<T>(init?: RangeOfProperties<T>): Result<RangeOf<T>> {\n return captureResult(() => new RangeOf<T>(init?.min, init?.max));\n }\n\n /**\n * Gets a formatted description of a {@link Experimental.RangeOfProperties | RangeOfProperties<T>} given an\n * optional set of formats and 'empty' value to use.\n * @param range - The {@link Experimental.RangeOfProperties | RangeOfProperties<T>} to be formatted.\n * @param formats - Optional {@link Experimental.RangeOfFormats | formats} to use. Default is\n * {@link Experimental.DEFAULT_RANGEOF_FORMATS | DEFAULT_RANGEOF_FORMATS}.\n * @param emptyValue - Value which represents unbounded minimum or maximum for this range. Default is `undefined`.\n * @returns A string representation of the range.\n */\n public static propertiesToString<T>(\n range: RangeOfProperties<T>,\n formats?: RangeOfFormats,\n emptyValue?: T\n ): string | undefined {\n formats = formats ?? DEFAULT_RANGEOF_FORMATS;\n if (range.min !== undefined && range.min !== emptyValue) {\n if (range.max !== undefined && range.max !== emptyValue) {\n return Mustache.render(formats.minMax, range);\n } else {\n return Mustache.render(formats.minOnly, range);\n }\n } else if (range.max !== undefined && range.max !== emptyValue) {\n return Mustache.render(formats.maxOnly, range);\n }\n return undefined;\n }\n\n /**\n * Default comparison uses javascript built-in comparison.\n * @param t1 - First value to be compared.\n * @param t2 - Second value to be compared.\n * @returns `'less'` if `t1` is less than `t2`, `'greater'` if `t1` is larger\n * and `'equal'` if `t1` and `t2` are equal.\n * @internal\n */\n protected static _defaultCompare<T>(t1: T, t2: T): 'less' | 'equal' | 'greater' {\n if (t1 < t2) {\n return 'less';\n } else if (t1 > t2) {\n return 'greater';\n }\n return 'equal';\n }\n\n /**\n * Checks if a supplied value is within this range.\n * @param t - The value to be tested.\n * @returns `'included'` if `t` falls within the range, `'less'` if `t` falls\n * below the minimum extent of the range and `'greater'` if `t` is above the\n * maximum extent.\n */\n public check(t: T): 'less' | 'included' | 'greater' {\n if (this.min !== undefined && this._compare(t, this.min) === 'less') {\n return 'less';\n }\n if (this.max !== undefined && this._compare(t, this.max) !== 'less') {\n return 'greater';\n }\n return 'included';\n }\n\n /**\n * Determines if a supplied value is within this range.\n * @param t - The value to be tested.\n * @returns Returns `true` if `t` falls within the range, `false` otherwise.\n */\n public includes(t: T): boolean {\n return this.check(t) === 'included';\n }\n\n /**\n * Finds the transition value that would bring a supplied value `t` into\n * range.\n * @param t - The value to be tested.\n * @returns The minimum extent of the range if `t` is below the range or\n * the maximum extent of the range if `t` is above the range. Returns\n * `undefined` if `t` already falls within the range.\n */\n public findTransition(t: T): T | undefined {\n switch (this.check(t)) {\n case 'less':\n return this.min;\n case 'included':\n return this.max;\n }\n return undefined;\n }\n\n /**\n * Formats the minimum and maximum values of this range.\n * @param format - A format function used to format the values.\n * @returns A {@link Experimental.RangeOfProperties | RangeOfProperties<string>} containing the\n * formatted representation of the {@link Experimental.RangeOf.min | minimum} and\n * {@link Experimental.RangeOf.max | maximum}\n * extent of the range, or `undefined` for an extent that is not present.\n */\n public toFormattedProperties(format: (value: T) => string | undefined): RangeOfProperties<string> {\n return {\n min: this.min !== undefined ? format(this.min) : undefined,\n max: this.max !== undefined ? format(this.max) : undefined\n };\n }\n\n /**\n * Formats this range using the supplied format function.\n * @param format - Format function used to format minimum and maximum extent values.\n * @param formats - The {@link Experimental.RangeOfFormats | format strings} used to format the range\n * (default {@link Experimental.DEFAULT_RANGEOF_FORMATS}).\n * @returns Returns a formatted representation of this range.\n */\n public format(format: (value: T) => string | undefined, formats?: RangeOfFormats): string | undefined {\n return RangeOf.propertiesToString(this.toFormattedProperties(format), formats);\n }\n\n /**\n * Inner compare method can be overridden by a derived class.\n * @param t1 - First value to compare.\n * @param t2 - Second value to compare.\n * @returns `'less'` if `t1` is less than `t2`, `'greater'` if `t1` is larger\n * and `'equal'` if `t1` and `t2` are equal.\n * @internal\n */\n protected _compare(t1: T, t2: T): 'less' | 'equal' | 'greater' {\n return RangeOf._defaultCompare(t1, t2);\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/hash/index.ts"],"names":[],"mappings":"AAsBA,cAAc,iBAAiB,CAAC"}
|