@fgv/ts-extras 2.0.1

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.
Files changed (57) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +48 -0
  3. package/dist/ts-extras.d.ts +445 -0
  4. package/dist/tsdoc-metadata.json +11 -0
  5. package/lib/index.d.ts +7 -0
  6. package/lib/index.d.ts.map +1 -0
  7. package/lib/index.js +58 -0
  8. package/lib/index.js.map +1 -0
  9. package/lib/packlets/conversion/converters.d.ts +28 -0
  10. package/lib/packlets/conversion/converters.d.ts.map +1 -0
  11. package/lib/packlets/conversion/converters.js +72 -0
  12. package/lib/packlets/conversion/converters.js.map +1 -0
  13. package/lib/packlets/conversion/index.d.ts +3 -0
  14. package/lib/packlets/conversion/index.d.ts.map +1 -0
  15. package/lib/packlets/conversion/index.js +50 -0
  16. package/lib/packlets/conversion/index.js.map +1 -0
  17. package/lib/packlets/csv/csvHelpers.d.ts +17 -0
  18. package/lib/packlets/csv/csvHelpers.d.ts.map +1 -0
  19. package/lib/packlets/csv/csvHelpers.js +69 -0
  20. package/lib/packlets/csv/csvHelpers.js.map +1 -0
  21. package/lib/packlets/csv/index.d.ts +2 -0
  22. package/lib/packlets/csv/index.d.ts.map +1 -0
  23. package/lib/packlets/csv/index.js +39 -0
  24. package/lib/packlets/csv/index.js.map +1 -0
  25. package/lib/packlets/experimental/extendedArray.d.ts +56 -0
  26. package/lib/packlets/experimental/extendedArray.d.ts.map +1 -0
  27. package/lib/packlets/experimental/extendedArray.js +106 -0
  28. package/lib/packlets/experimental/extendedArray.js.map +1 -0
  29. package/lib/packlets/experimental/formatter.d.ts +66 -0
  30. package/lib/packlets/experimental/formatter.d.ts.map +1 -0
  31. package/lib/packlets/experimental/formatter.js +75 -0
  32. package/lib/packlets/experimental/formatter.js.map +1 -0
  33. package/lib/packlets/experimental/index.d.ts +4 -0
  34. package/lib/packlets/experimental/index.d.ts.map +1 -0
  35. package/lib/packlets/experimental/index.js +41 -0
  36. package/lib/packlets/experimental/index.js.map +1 -0
  37. package/lib/packlets/experimental/rangeOf.d.ts +122 -0
  38. package/lib/packlets/experimental/rangeOf.d.ts.map +1 -0
  39. package/lib/packlets/experimental/rangeOf.js +185 -0
  40. package/lib/packlets/experimental/rangeOf.js.map +1 -0
  41. package/lib/packlets/hash/hash.d.ts +51 -0
  42. package/lib/packlets/hash/hash.d.ts.map +1 -0
  43. package/lib/packlets/hash/hash.js +166 -0
  44. package/lib/packlets/hash/hash.js.map +1 -0
  45. package/lib/packlets/hash/index.d.ts +2 -0
  46. package/lib/packlets/hash/index.d.ts.map +1 -0
  47. package/lib/packlets/hash/index.js +39 -0
  48. package/lib/packlets/hash/index.js.map +1 -0
  49. package/lib/packlets/record-jar/index.d.ts +2 -0
  50. package/lib/packlets/record-jar/index.d.ts.map +1 -0
  51. package/lib/packlets/record-jar/index.js +39 -0
  52. package/lib/packlets/record-jar/index.js.map +1 -0
  53. package/lib/packlets/record-jar/recordJarHelpers.d.ts +37 -0
  54. package/lib/packlets/record-jar/recordJarHelpers.d.ts.map +1 -0
  55. package/lib/packlets/record-jar/recordJarHelpers.js +263 -0
  56. package/lib/packlets/record-jar/recordJarHelpers.js.map +1 -0
  57. package/package.json +69 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
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.
package/README.md ADDED
@@ -0,0 +1,48 @@
1
+ <div align="center">
2
+ <h1>ts-utils</h1>
3
+ Assorted Typescript Utilities
4
+ </div>
5
+
6
+ <hr/>
7
+
8
+ ## Summary
9
+
10
+ Assorted less-developed or more specialized odds-and-ends borrowed from one project or another - much less polished and more likely change or disappear:
11
+ * ExtendedArray\<T\> - adds a few useful operations to the built-in Array
12
+ * Formattable\<T\> - simple helpers to create mustache wrappers for objects and make them easily printable
13
+ * Logger - A very basic logger suitable for hobby projects
14
+ * RangeOf\<T\> - Generic open or closed ranges of orderable items (numbers, dates, etc)
15
+
16
+ ---
17
+
18
+ - [Summary](#summary)
19
+ - [Installation](#installation)
20
+ - [API Documentation](#api-documentation)
21
+ - [Overview](#overview)
22
+ - [API](#api)
23
+ - [ExtendedArray\<T\>](#extendedarrayt)
24
+ - [Formattable\<T\>](#formattablet)
25
+ - [Logger](#logger)
26
+ - [RangeOf\<T\>](#rangeoft)
27
+
28
+ ## Installation
29
+
30
+ With npm:
31
+ ```sh
32
+ npm install @fgv/ts-extras
33
+ ```
34
+
35
+ ## API Documentation
36
+ Extracted API documentation is [here](./docs/ts-extras.md).
37
+
38
+ ## Overview
39
+
40
+ ## API
41
+
42
+ ### ExtendedArray\<T\>
43
+
44
+ ### Formattable\<T\>
45
+
46
+ ### Logger
47
+
48
+ ### RangeOf\<T\>
@@ -0,0 +1,445 @@
1
+ import { Converter } from '@fgv/ts-utils';
2
+ import { Converters as Converters_2 } from '@fgv/ts-utils';
3
+ import { Result } from '@fgv/ts-utils';
4
+
5
+ /**
6
+ * Computes an md5 hash from an array of strings. Not secure and not intended to be secure.
7
+ * @param parts - The strings to be hashed
8
+ * @returns An md5 hash of the parts
9
+ * @public
10
+ */
11
+ declare function computeHash(parts: string[]): string;
12
+
13
+ declare namespace Converters {
14
+ export {
15
+ extendedArrayOf,
16
+ rangeTypeOf,
17
+ rangeOf
18
+ }
19
+ }
20
+ export { Converters }
21
+
22
+ declare namespace Csv {
23
+ export {
24
+ readCsvFileSync,
25
+ CsvOptions
26
+ }
27
+ }
28
+ export { Csv }
29
+
30
+ /**
31
+ * Options for {@link Csv.readCsvFileSync}
32
+ * @beta
33
+ */
34
+ declare interface CsvOptions {
35
+ delimiter?: string;
36
+ }
37
+
38
+ /**
39
+ * Default {@link Experimental.RangeOfFormats | formats} to use for both
40
+ * open-ended and complete {@link Experimental.RangeOf | RangeOf<T>}.
41
+ * @public
42
+ */
43
+ declare const DEFAULT_RANGEOF_FORMATS: RangeOfFormats;
44
+
45
+ declare namespace Experimental {
46
+ export {
47
+ ExtendedArray,
48
+ formatList,
49
+ FormatTargets,
50
+ Formattable,
51
+ FormattableBase,
52
+ Formatter,
53
+ FormattersByExtendedTarget,
54
+ FormattersByTarget,
55
+ RangeOfProperties,
56
+ RangeOfFormats,
57
+ DEFAULT_RANGEOF_FORMATS,
58
+ RangeOf
59
+ }
60
+ }
61
+ export { Experimental }
62
+
63
+ /**
64
+ * An experimental array template which extend built-in `Array` to include a handful
65
+ * of predicates which return {@link Result | Result<T>}.
66
+ * @beta
67
+ */
68
+ declare class ExtendedArray<T> extends Array<T> {
69
+ readonly itemDescription: string;
70
+ /**
71
+ * Constructs an {@link Experimental.ExtendedArray}.
72
+ * @param itemDescription - Brief description of the type of each item in this array.
73
+ * @param items - The initial contents of the array.
74
+ */
75
+ constructor(itemDescription: string, ...items: T[]);
76
+ /**
77
+ * Type guard to determine if some arbitrary array is an
78
+ * {@link Experimental.ExtendedArray}
79
+ * @param a - The `Array` to be tested.
80
+ * @returns Returns `true` if `a` is an {@link Experimental.ExtendedArray},
81
+ * `false` otherwise.
82
+ */
83
+ static isExtendedArray<T>(a?: T[]): a is ExtendedArray<T>;
84
+ /**
85
+ * Determines if this array contains exactly one element which matches
86
+ * a supplied predicate.
87
+ * @param predicate - The predicate function to be applied.
88
+ * @returns Returns {@link Success | Success<T>} with the single matching
89
+ * result if exactly one item matches `predicate`. Returns {@link Failure}
90
+ * with an error message if there are no matches or more than one match.
91
+ */
92
+ single(predicate?: (item: T) => boolean): Result<T>;
93
+ /**
94
+ * Returns the first element of an {@link Experimental.ExtendedArray}. Fails with an
95
+ * error message if the array is empty.
96
+ * @param failMessage - Optional message to be displayed in the event of failure.
97
+ * @returns Returns {@link Success | Success<T>} with the value of the first element
98
+ * in the array, or {@link Failure} with an error message if the array is empty.
99
+ */
100
+ first(failMessage?: string): Result<T>;
101
+ /**
102
+ * Returns an array containing all elements of an {@link Experimental.ExtendedArray}. Fails with
103
+ * an error message if the array is empty.
104
+ * @param failMessage - Optional message to be displayed in the event of failure.
105
+ * @returns Returns {@link Success | Success<T[]>} with a new (non-extended) `Array`
106
+ * containing the elements of this array, or {@link Failure} with an error message
107
+ * if the array is empty.
108
+ */
109
+ atLeastOne(failMessage?: string): Result<T[]>;
110
+ /**
111
+ * Gets a new (non-extended) `Array` containing all of the elements from this
112
+ * {@link Experimental.ExtendedArray}.
113
+ * @returns A new (non-extended) `Array<T>`.
114
+ */
115
+ all(): T[];
116
+ }
117
+
118
+ /**
119
+ * A helper function to create a {@link Converter} which converts `unknown` to {@link Experimental.ExtendedArray | ExtendedArray<T>}.
120
+ * @remarks
121
+ * If `onError` is `'failOnError'` (default), then the entire conversion fails if any element cannot
122
+ * be converted. If `onError` is `'ignoreErrors'`, then failing elements are silently ignored.
123
+ * @param converter - {@link Converter} used to convert each item in the array
124
+ * @param ignoreErrors - Specifies treatment of unconvertible elements
125
+ * @beta
126
+ */
127
+ declare function extendedArrayOf<T, TC = undefined>(label: string, converter: Converter<T, TC>, onError?: Converters_2.OnError): Converter<ExtendedArray<T>, TC>;
128
+
129
+ /**
130
+ * Formats a list of items using the supplied template and formatter, one result
131
+ * per output line.
132
+ * @param format - A mustache template used to format each item.
133
+ * @param items - The items to be formatted.
134
+ * @param itemFormatter - The {@link Experimental.Formatter | Formatter<T>} used to format each item.
135
+ * @returns The resulting string.
136
+ * @beta
137
+ */
138
+ declare function formatList<T>(format: string, items: T[], itemFormatter: Formatter<T>): Result<string>;
139
+
140
+ /**
141
+ * Interface for an object that can be formatted.
142
+ * @beta
143
+ */
144
+ declare interface Formattable {
145
+ /**
146
+ * Formats an object using the supplied mustache template.
147
+ * @param format - A mustache template used to format the object.
148
+ * @returns {@link Success} with the resulting string, or {@link Failure}
149
+ * with an error message if an error occurs.
150
+ */
151
+ format(format: string): Result<string>;
152
+ }
153
+
154
+ /**
155
+ * Base class which adds common formatting.
156
+ * @beta
157
+ */
158
+ declare class FormattableBase {
159
+ /**
160
+ * Helper enables derived classes to add named details to a formatted presentation.
161
+ * @param details - An array of detail description strings.
162
+ * @param label - Label to use for the new detail.
163
+ * @param value - Value to use for the new detail.
164
+ * @internal
165
+ */
166
+ protected static _tryAddDetail(details: string[], label: string, value: string | undefined): void;
167
+ /**
168
+ * {@inheritdoc Experimental.Formattable.format}
169
+ */
170
+ format(template: string): Result<string>;
171
+ }
172
+
173
+ /**
174
+ * Destination format for some formatted string.
175
+ * @beta
176
+ */
177
+ declare type FormatTargets = 'text' | 'markdown' | 'embed';
178
+
179
+ /**
180
+ * Type definition for a formatting function, which takes a `string` and an
181
+ * item and returns {@link Result | Result<string>}.
182
+ * @beta
183
+ */
184
+ declare type Formatter<T> = (format: string, item: T) => Result<string>;
185
+
186
+ /**
187
+ * A collection of {@link Experimental.Formatter | formatters} indexed by target name, to enable
188
+ * different format methods per output target.
189
+ * @beta
190
+ */
191
+ declare type FormattersByExtendedTarget<TFT extends FormatTargets, T> = Record<TFT, Formatter<T>>;
192
+
193
+ /**
194
+ * A collection of {@link Experimental.Formatter | formatters} indexed by the
195
+ * {@link Experimental.FormatTargets | default supported target formats}.
196
+ * @beta
197
+ */
198
+ declare type FormattersByTarget<T> = FormattersByExtendedTarget<FormatTargets, T>;
199
+
200
+ declare namespace Hash {
201
+ export {
202
+ computeHash,
203
+ Normalizer
204
+ }
205
+ }
206
+ export { Hash }
207
+
208
+ /**
209
+ * @public
210
+ */
211
+ declare type JarFieldPicker<T extends JarRecord = JarRecord> = (record: T) => (keyof T)[];
212
+
213
+ /**
214
+ * Represents a single record in a JAR file
215
+ * @public
216
+ */
217
+ declare type JarRecord = Record<string, string | string[]>;
218
+
219
+ /**
220
+ * Options for a JAR record parser.
221
+ * @public
222
+ */
223
+ declare interface JarRecordParserOptions {
224
+ readonly arrayFields?: string[] | JarFieldPicker;
225
+ readonly fixedContinuationSize?: number;
226
+ }
227
+
228
+ /**
229
+ * Computes a normalized hash for an arbitrary javascript value.
230
+ * @public
231
+ */
232
+ declare class Normalizer {
233
+ /**
234
+ * Computes a normalized md5 hash from an arbitrary supplied object. Not secure and not
235
+ * intended to be secure. Also not fast and not intended to be fast.
236
+ *
237
+ * Normalization just sorts Maps, Sets and object keys by hash so that differences in order
238
+ * do not affect the hash.
239
+ *
240
+ * @param from - The arbitrary `unknown` to be hashed.
241
+ * @returns A normalized md5 hash for the supplied value.
242
+ */
243
+ computeHash(from: unknown): Result<string>;
244
+ /**
245
+ * Compares two property names from some object being normalized.
246
+ * @param k1 - First key to be compared.
247
+ * @param k2 - Second key to be compared.
248
+ * @returns `1` if `k1` is greater, `-1` if `k2` is greater and
249
+ * `0` if they are equal.
250
+ * @internal
251
+ */
252
+ protected _compareKeys(k1: unknown, k2: unknown): number;
253
+ /**
254
+ * Normalizes an array of object property entries (e.g. as returned by `Object.entries()`).
255
+ * @remarks
256
+ * Converts property names (entry key) to string and then sorts as string.
257
+ * @param entries - The entries to be normalized.
258
+ * @returns A normalized sorted array of entries.
259
+ * @internal
260
+ */
261
+ protected _normalizeEntries(entries: Iterable<[unknown, unknown]>): [unknown, unknown][];
262
+ /**
263
+ * Constructs a normalized string representation of some literal value.
264
+ * @param from - The literal value to be normalized.
265
+ * @returns A normalized string representation of the literal.
266
+ * @internal
267
+ */
268
+ protected _normalizeLiteral(from: string | number | bigint | boolean | symbol | undefined | Date | RegExp | null): Result<string>;
269
+ }
270
+
271
+ /**
272
+ * Reads a record-jar from an array of strings, each of which represents one
273
+ * line in the source file.
274
+ * @param lines - the array of strings to be parsed
275
+ * @param options - Optional parser configuration
276
+ * @returns a corresponding array of `Record<string, string>`
277
+ * @public
278
+ */
279
+ declare function parseRecordJarLines(lines: string[], options?: JarRecordParserOptions): Result<JarRecord[]>;
280
+
281
+ /**
282
+ * Simple implementation of a possibly open-ended range of some comparable
283
+ * type `<T>` with test and formatting.
284
+ * @public
285
+ */
286
+ declare class RangeOf<T> implements RangeOfProperties<T> {
287
+ /**
288
+ * Minimum extent of the range.
289
+ */
290
+ readonly min?: T;
291
+ /**
292
+ * Maximum extent of the range.
293
+ */
294
+ readonly max?: T;
295
+ /**
296
+ * Creates a new {@link Experimental.RangeOf | RangeOf<T>}.
297
+ * @param min - Optional minimum extent of the range.
298
+ * @param max - Optional maximum extent of the range.
299
+ */
300
+ constructor(min?: T, max?: T);
301
+ /**
302
+ * Static constructor for a {@link Experimental.RangeOf | RangeOf<T>}.
303
+ * @param init - {@link Experimental.RangeOfProperties | Range initializer}.
304
+ * @returns A new {@link Experimental.RangeOf | RangeOf<T>}.
305
+ */
306
+ static createRange<T>(init?: RangeOfProperties<T>): Result<RangeOf<T>>;
307
+ /**
308
+ * Gets a formatted description of a {@link Experimental.RangeOfProperties | RangeOfProperties<T>} given an
309
+ * optional set of formats and 'empty' value to use.
310
+ * @param range - The {@link Experimental.RangeOfProperties | RangeOfProperties<T>} to be formatted.
311
+ * @param formats - Optional {@link Experimental.RangeOfFormats | formats} to use. Default is
312
+ * {@link Experimental.DEFAULT_RANGEOF_FORMATS | DEFAULT_RANGEOF_FORMATS}.
313
+ * @param emptyValue - Value which represents unbounded minimum or maximum for this range. Default is `undefined`.
314
+ * @returns A string representation of the range.
315
+ */
316
+ static propertiesToString<T>(range: RangeOfProperties<T>, formats?: RangeOfFormats, emptyValue?: T): string | undefined;
317
+ /**
318
+ * Default comparison uses javascript built-in comparison.
319
+ * @param t1 - First value to be compared.
320
+ * @param t2 - Second value to be compared.
321
+ * @returns `'less'` if `t1` is less than `t2`, `'greater'` if `t1` is larger
322
+ * and `'equal'` if `t1` and `t2` are equal.
323
+ * @internal
324
+ */
325
+ protected static _defaultCompare<T>(t1: T, t2: T): 'less' | 'equal' | 'greater';
326
+ /**
327
+ * Checks if a supplied value is within this range.
328
+ * @param t - The value to be tested.
329
+ * @returns `'included'` if `t` falls within the range, `'less'` if `t` falls
330
+ * below the minimum extent of the range and `'greater'` if `t` is above the
331
+ * maximum extent.
332
+ */
333
+ check(t: T): 'less' | 'included' | 'greater';
334
+ /**
335
+ * Determines if a supplied value is within this range.
336
+ * @param t - The value to be tested.
337
+ * @returns Returns `true` if `t` falls within the range, `false` otherwise.
338
+ */
339
+ includes(t: T): boolean;
340
+ /**
341
+ * Finds the transition value that would bring a supplied value `t` into
342
+ * range.
343
+ * @param t - The value to be tested.
344
+ * @returns The minimum extent of the range if `t` is below the range or
345
+ * the maximum extent of the range if `t` is above the range. Returns
346
+ * `undefined` if `t` already falls within the range.
347
+ */
348
+ findTransition(t: T): T | undefined;
349
+ /**
350
+ * Formats the minimum and maximum values of this range.
351
+ * @param format - A format function used to format the values.
352
+ * @returns A {@link Experimental.RangeOfProperties | RangeOfProperties<string>} containing the
353
+ * formatted representation of the {@link Experimental.RangeOf.min | minimum} and
354
+ * {@link Experimental.RangeOf.max | maximum}
355
+ * extent of the range, or `undefined` for an extent that is not present.
356
+ */
357
+ toFormattedProperties(format: (value: T) => string | undefined): RangeOfProperties<string>;
358
+ /**
359
+ * Formats this range using the supplied format function.
360
+ * @param format - Format function used to format minimum and maximum extent values.
361
+ * @param formats - The {@link Experimental.RangeOfFormats | format strings} used to format the range
362
+ * (default {@link Experimental.DEFAULT_RANGEOF_FORMATS}).
363
+ * @returns Returns a formatted representation of this range.
364
+ */
365
+ format(format: (value: T) => string | undefined, formats?: RangeOfFormats): string | undefined;
366
+ /**
367
+ * Inner compare method can be overridden by a derived class.
368
+ * @param t1 - First value to compare.
369
+ * @param t2 - Second value to compare.
370
+ * @returns `'less'` if `t1` is less than `t2`, `'greater'` if `t1` is larger
371
+ * and `'equal'` if `t1` and `t2` are equal.
372
+ * @internal
373
+ */
374
+ protected _compare(t1: T, t2: T): 'less' | 'equal' | 'greater';
375
+ }
376
+
377
+ /**
378
+ * A helper wrapper to construct a {@link Converter} which converts to {@link Experimental.RangeOf | RangeOf<T>}
379
+ * where `<T>` is some comparable type.
380
+ * @param converter - {@link Converter} used to convert `min` and `max` extent of the range.
381
+ * @public
382
+ */
383
+ declare function rangeOf<T, TC = unknown>(converter: Converter<T, TC>): Converter<RangeOf<T>, TC>;
384
+
385
+ /**
386
+ * Format strings (in mustache format) to
387
+ * use for both open-ended and complete
388
+ * {@link Experimental.RangeOf | RangeOf<T>}.
389
+ * @public
390
+ */
391
+ declare interface RangeOfFormats {
392
+ minOnly: string;
393
+ maxOnly: string;
394
+ minMax: string;
395
+ }
396
+
397
+ /**
398
+ * Represents a generic range of some comparable type `<T>`.
399
+ * @public
400
+ */
401
+ declare interface RangeOfProperties<T> {
402
+ readonly min?: T;
403
+ readonly max?: T;
404
+ }
405
+
406
+ /**
407
+ * A helper wrapper to construct a {@link Converter} which converts to an arbitrary strongly-typed
408
+ * range of some comparable type.
409
+ * @param converter - {@link Converter} used to convert `min` and `max` extent of the range.
410
+ * @param constructor - Static constructor to instantiate the object.
411
+ * @public
412
+ */
413
+ declare function rangeTypeOf<T, RT extends RangeOf<T>, TC = unknown>(converter: Converter<T, TC>, constructor: (init: RangeOfProperties<T>) => Result<RT>): Converter<RT, TC>;
414
+
415
+ /**
416
+ * Reads a CSV file from a supplied path.
417
+ * @param srcPath - Source path from which the file is read.
418
+ * @param options - optional parameters to control the processing
419
+ * @returns The contents of the file.
420
+ * @beta
421
+ */
422
+ declare function readCsvFileSync(srcPath: string, options?: CsvOptions): Result<unknown>;
423
+
424
+ /**
425
+ * Reads a record-jar file from a supplied path.
426
+ * @param srcPath - Source path from which the file is read.
427
+ * @param options - Optional parser configuration
428
+ * @returns The contents of the file as an array of `Record<string, string>`
429
+ * @see https://datatracker.ietf.org/doc/html/draft-phillips-record-jar-01
430
+ * @public
431
+ */
432
+ declare function readRecordJarFileSync(srcPath: string, options?: JarRecordParserOptions): Result<JarRecord[]>;
433
+
434
+ declare namespace RecordJar {
435
+ export {
436
+ parseRecordJarLines,
437
+ readRecordJarFileSync,
438
+ JarRecord,
439
+ JarFieldPicker,
440
+ JarRecordParserOptions
441
+ }
442
+ }
443
+ export { RecordJar }
444
+
445
+ export { }
@@ -0,0 +1,11 @@
1
+ // This file is read by tools that parse documentation comments conforming to the TSDoc standard.
2
+ // It should be published with your NPM package. It should not be tracked by Git.
3
+ {
4
+ "tsdocVersion": "0.12",
5
+ "toolPackages": [
6
+ {
7
+ "packageName": "@microsoft/api-extractor",
8
+ "packageVersion": "7.39.1"
9
+ }
10
+ ]
11
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import * as Csv from './packlets/csv';
2
+ import * as Experimental from './packlets/experimental';
3
+ import * as Hash from './packlets/hash';
4
+ import * as RecordJar from './packlets/record-jar';
5
+ import { Converters } from './packlets/conversion';
6
+ export { Converters, Csv, Experimental, Hash, RecordJar };
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
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;AAEnD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,58 @@
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 (mod) {
40
+ if (mod && mod.__esModule) return mod;
41
+ var result = {};
42
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
43
+ __setModuleDefault(result, mod);
44
+ return result;
45
+ };
46
+ Object.defineProperty(exports, "__esModule", { value: true });
47
+ exports.RecordJar = exports.Hash = exports.Experimental = exports.Csv = exports.Converters = void 0;
48
+ const Csv = __importStar(require("./packlets/csv"));
49
+ exports.Csv = Csv;
50
+ const Experimental = __importStar(require("./packlets/experimental"));
51
+ exports.Experimental = Experimental;
52
+ const Hash = __importStar(require("./packlets/hash"));
53
+ exports.Hash = Hash;
54
+ const RecordJar = __importStar(require("./packlets/record-jar"));
55
+ exports.RecordJar = RecordJar;
56
+ const conversion_1 = require("./packlets/conversion");
57
+ Object.defineProperty(exports, "Converters", { enumerable: true, get: function () { return conversion_1.Converters; } });
58
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,oDAAsC;AAOjB,kBAAG;AANxB,sEAAwD;AAM9B,oCAAY;AALtC,sDAAwC;AAKA,oBAAI;AAJ5C,iEAAmD;AAIL,8BAAS;AAFvD,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';\n\nimport { Converters } from './packlets/conversion';\n\nexport { Converters, Csv, Experimental, Hash, RecordJar };\n"]}
@@ -0,0 +1,28 @@
1
+ import { Converter, Converters, Result } from '@fgv/ts-utils';
2
+ import { ExtendedArray, RangeOf, RangeOfProperties } from '../experimental';
3
+ /**
4
+ * A helper function to create a {@link Converter} which converts `unknown` to {@link Experimental.ExtendedArray | ExtendedArray<T>}.
5
+ * @remarks
6
+ * If `onError` is `'failOnError'` (default), then the entire conversion fails if any element cannot
7
+ * be converted. If `onError` is `'ignoreErrors'`, then failing elements are silently ignored.
8
+ * @param converter - {@link Converter} used to convert each item in the array
9
+ * @param ignoreErrors - Specifies treatment of unconvertible elements
10
+ * @beta
11
+ */
12
+ export declare function extendedArrayOf<T, TC = undefined>(label: string, converter: Converter<T, TC>, onError?: Converters.OnError): Converter<ExtendedArray<T>, TC>;
13
+ /**
14
+ * A helper wrapper to construct a {@link Converter} which converts to an arbitrary strongly-typed
15
+ * range of some comparable type.
16
+ * @param converter - {@link Converter} used to convert `min` and `max` extent of the range.
17
+ * @param constructor - Static constructor to instantiate the object.
18
+ * @public
19
+ */
20
+ export declare function rangeTypeOf<T, RT extends RangeOf<T>, TC = unknown>(converter: Converter<T, TC>, constructor: (init: RangeOfProperties<T>) => Result<RT>): Converter<RT, TC>;
21
+ /**
22
+ * A helper wrapper to construct a {@link Converter} which converts to {@link Experimental.RangeOf | RangeOf<T>}
23
+ * where `<T>` is some comparable type.
24
+ * @param converter - {@link Converter} used to convert `min` and `max` extent of the range.
25
+ * @public
26
+ */
27
+ export declare function rangeOf<T, TC = unknown>(converter: Converter<T, TC>): Converter<RangeOf<T>, TC>;
28
+ //# sourceMappingURL=converters.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"converters.d.ts","sourceRoot":"","sources":["../../../src/packlets/conversion/converters.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAc,SAAS,EAAE,UAAU,EAAE,MAAM,EAAuB,MAAM,eAAe,CAAC;AAC/F,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAE5E;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,EAAE,GAAG,SAAS,EAC/C,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,EAC3B,OAAO,GAAE,UAAU,CAAC,OAAuB,GAC1C,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAIjC;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,EAAE,SAAS,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO,EAChE,SAAS,EAAE,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,EAC3B,WAAW,EAAE,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,EAAE,CAAC,GACtD,SAAS,CAAC,EAAE,EAAE,EAAE,CAAC,CAcnB;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAE/F"}