@fgv/ts-utils 2.1.0 → 2.1.1-alpha.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 +0 -30
- package/CHANGELOG.md +1 -14
- package/dist/ts-utils.d.ts +1509 -1924
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/index.d.ts +1 -6
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -9
- package/lib/index.js.map +1 -1
- package/lib/packlets/base/logger.js.map +1 -1
- package/lib/packlets/base/normalize.js.map +1 -1
- package/lib/packlets/base/result.d.ts +20 -6
- package/lib/packlets/base/result.d.ts.map +1 -1
- package/lib/packlets/base/result.js +4 -6
- package/lib/packlets/base/result.js.map +1 -1
- package/lib/packlets/base/utils.js.map +1 -1
- package/lib/packlets/conversion/converter.js.map +1 -1
- package/lib/packlets/conversion/converters.d.ts +5 -29
- package/lib/packlets/conversion/converters.d.ts.map +1 -1
- package/lib/packlets/conversion/converters.js +1 -47
- package/lib/packlets/conversion/converters.js.map +1 -1
- package/lib/packlets/conversion/objectConverter.js.map +1 -1
- package/lib/packlets/conversion/stringConverter.js.map +1 -1
- package/lib/packlets/validation/array.js.map +1 -1
- package/lib/packlets/validation/boolean.js.map +1 -1
- package/lib/packlets/validation/field.js.map +1 -1
- package/lib/packlets/validation/genericValidator.js.map +1 -1
- package/lib/packlets/validation/number.js.map +1 -1
- package/lib/packlets/validation/object.js.map +1 -1
- package/lib/packlets/validation/string.js.map +1 -1
- package/lib/packlets/validation/typeGuard.js.map +1 -1
- package/lib/packlets/validation/validators.js.map +1 -1
- package/package.json +22 -23
- package/lib/packlets/csv/csvHelpers.d.ts +0 -17
- package/lib/packlets/csv/csvHelpers.d.ts.map +0 -1
- package/lib/packlets/csv/csvHelpers.js +0 -69
- package/lib/packlets/csv/csvHelpers.js.map +0 -1
- package/lib/packlets/csv/index.d.ts +0 -2
- package/lib/packlets/csv/index.d.ts.map +0 -1
- package/lib/packlets/csv/index.js +0 -39
- package/lib/packlets/csv/index.js.map +0 -1
- package/lib/packlets/experimental/extendedArray.d.ts +0 -56
- package/lib/packlets/experimental/extendedArray.d.ts.map +0 -1
- package/lib/packlets/experimental/extendedArray.js +0 -106
- package/lib/packlets/experimental/extendedArray.js.map +0 -1
- package/lib/packlets/experimental/formatter.d.ts +0 -66
- package/lib/packlets/experimental/formatter.d.ts.map +0 -1
- package/lib/packlets/experimental/formatter.js +0 -75
- package/lib/packlets/experimental/formatter.js.map +0 -1
- package/lib/packlets/experimental/index.d.ts +0 -4
- package/lib/packlets/experimental/index.d.ts.map +0 -1
- package/lib/packlets/experimental/index.js +0 -41
- package/lib/packlets/experimental/index.js.map +0 -1
- package/lib/packlets/experimental/rangeOf.d.ts +0 -122
- package/lib/packlets/experimental/rangeOf.d.ts.map +0 -1
- package/lib/packlets/experimental/rangeOf.js +0 -185
- package/lib/packlets/experimental/rangeOf.js.map +0 -1
- package/lib/packlets/hash/hash.d.ts +0 -51
- package/lib/packlets/hash/hash.d.ts.map +0 -1
- package/lib/packlets/hash/hash.js +0 -166
- package/lib/packlets/hash/hash.js.map +0 -1
- package/lib/packlets/hash/index.d.ts +0 -2
- package/lib/packlets/hash/index.d.ts.map +0 -1
- package/lib/packlets/hash/index.js +0 -39
- package/lib/packlets/hash/index.js.map +0 -1
- package/lib/packlets/record-jar/index.d.ts +0 -2
- package/lib/packlets/record-jar/index.d.ts.map +0 -1
- package/lib/packlets/record-jar/index.js +0 -39
- package/lib/packlets/record-jar/index.js.map +0 -1
- package/lib/packlets/record-jar/recordJarHelpers.d.ts +0 -37
- package/lib/packlets/record-jar/recordJarHelpers.d.ts.map +0 -1
- package/lib/packlets/record-jar/recordJarHelpers.js +0 -263
- package/lib/packlets/record-jar/recordJarHelpers.js.map +0 -1
|
@@ -1,39 +0,0 @@
|
|
|
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
|
-
__exportStar(require("./csvHelpers"), exports);
|
|
39
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -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,56 +0,0 @@
|
|
|
1
|
-
import { Result } from '../base';
|
|
2
|
-
/**
|
|
3
|
-
* An experimental array template which extend built-in `Array` to include a handful
|
|
4
|
-
* of predicates which return {@link Result | Result<T>}.
|
|
5
|
-
* @beta
|
|
6
|
-
*/
|
|
7
|
-
export declare class ExtendedArray<T> extends Array<T> {
|
|
8
|
-
readonly itemDescription: string;
|
|
9
|
-
/**
|
|
10
|
-
* Constructs an {@link Experimental.ExtendedArray}.
|
|
11
|
-
* @param itemDescription - Brief description of the type of each item in this array.
|
|
12
|
-
* @param items - The initial contents of the array.
|
|
13
|
-
*/
|
|
14
|
-
constructor(itemDescription: string, ...items: T[]);
|
|
15
|
-
/**
|
|
16
|
-
* Type guard to determine if some arbitrary array is an
|
|
17
|
-
* {@link Experimental.ExtendedArray}
|
|
18
|
-
* @param a - The `Array` to be tested.
|
|
19
|
-
* @returns Returns `true` if `a` is an {@link Experimental.ExtendedArray},
|
|
20
|
-
* `false` otherwise.
|
|
21
|
-
*/
|
|
22
|
-
static isExtendedArray<T>(a?: T[]): a is ExtendedArray<T>;
|
|
23
|
-
/**
|
|
24
|
-
* Determines if this array contains exactly one element which matches
|
|
25
|
-
* a supplied predicate.
|
|
26
|
-
* @param predicate - The predicate function to be applied.
|
|
27
|
-
* @returns Returns {@link Success | Success<T>} with the single matching
|
|
28
|
-
* result if exactly one item matches `predicate`. Returns {@link Failure}
|
|
29
|
-
* with an error message if there are no matches or more than one match.
|
|
30
|
-
*/
|
|
31
|
-
single(predicate?: (item: T) => boolean): Result<T>;
|
|
32
|
-
/**
|
|
33
|
-
* Returns the first element of an {@link Experimental.ExtendedArray}. Fails with an
|
|
34
|
-
* error message if the array is empty.
|
|
35
|
-
* @param failMessage - Optional message to be displayed in the event of failure.
|
|
36
|
-
* @returns Returns {@link Success | Success<T>} with the value of the first element
|
|
37
|
-
* in the array, or {@link Failure} with an error message if the array is empty.
|
|
38
|
-
*/
|
|
39
|
-
first(failMessage?: string): Result<T>;
|
|
40
|
-
/**
|
|
41
|
-
* Returns an array containing all elements of an {@link Experimental.ExtendedArray}. Fails with
|
|
42
|
-
* an error message if the array is empty.
|
|
43
|
-
* @param failMessage - Optional message to be displayed in the event of failure.
|
|
44
|
-
* @returns Returns {@link Success | Success<T[]>} with a new (non-extended) `Array`
|
|
45
|
-
* containing the elements of this array, or {@link Failure} with an error message
|
|
46
|
-
* if the array is empty.
|
|
47
|
-
*/
|
|
48
|
-
atLeastOne(failMessage?: string): Result<T[]>;
|
|
49
|
-
/**
|
|
50
|
-
* Gets a new (non-extended) `Array` containing all of the elements from this
|
|
51
|
-
* {@link Experimental.ExtendedArray}.
|
|
52
|
-
* @returns A new (non-extended) `Array<T>`.
|
|
53
|
-
*/
|
|
54
|
-
all(): T[];
|
|
55
|
-
}
|
|
56
|
-
//# sourceMappingURL=extendedArray.d.ts.map
|
|
@@ -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,SAAS,CAAC;AAEhD;;;;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,106 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.ExtendedArray = void 0;
|
|
25
|
-
const base_1 = require("../base");
|
|
26
|
-
/**
|
|
27
|
-
* An experimental array template which extend built-in `Array` to include a handful
|
|
28
|
-
* of predicates which return {@link Result | Result<T>}.
|
|
29
|
-
* @beta
|
|
30
|
-
*/
|
|
31
|
-
class ExtendedArray extends Array {
|
|
32
|
-
/**
|
|
33
|
-
* Constructs an {@link Experimental.ExtendedArray}.
|
|
34
|
-
* @param itemDescription - Brief description of the type of each item in this array.
|
|
35
|
-
* @param items - The initial contents of the array.
|
|
36
|
-
*/
|
|
37
|
-
constructor(itemDescription, ...items) {
|
|
38
|
-
super(...items);
|
|
39
|
-
this.itemDescription = itemDescription;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Type guard to determine if some arbitrary array is an
|
|
43
|
-
* {@link Experimental.ExtendedArray}
|
|
44
|
-
* @param a - The `Array` to be tested.
|
|
45
|
-
* @returns Returns `true` if `a` is an {@link Experimental.ExtendedArray},
|
|
46
|
-
* `false` otherwise.
|
|
47
|
-
*/
|
|
48
|
-
static isExtendedArray(a) {
|
|
49
|
-
return a instanceof ExtendedArray;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Determines if this array contains exactly one element which matches
|
|
53
|
-
* a supplied predicate.
|
|
54
|
-
* @param predicate - The predicate function to be applied.
|
|
55
|
-
* @returns Returns {@link Success | Success<T>} with the single matching
|
|
56
|
-
* result if exactly one item matches `predicate`. Returns {@link Failure}
|
|
57
|
-
* with an error message if there are no matches or more than one match.
|
|
58
|
-
*/
|
|
59
|
-
single(predicate) {
|
|
60
|
-
const match = predicate ? this.filter(predicate) : this;
|
|
61
|
-
if (match.length === 1) {
|
|
62
|
-
return (0, base_1.succeed)(match[0]);
|
|
63
|
-
}
|
|
64
|
-
if (match.length === 0) {
|
|
65
|
-
return (0, base_1.fail)(`${this.itemDescription} not found`);
|
|
66
|
-
}
|
|
67
|
-
return (0, base_1.fail)(`${this.itemDescription} matches ${match.length} items`);
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Returns the first element of an {@link Experimental.ExtendedArray}. Fails with an
|
|
71
|
-
* error message if the array is empty.
|
|
72
|
-
* @param failMessage - Optional message to be displayed in the event of failure.
|
|
73
|
-
* @returns Returns {@link Success | Success<T>} with the value of the first element
|
|
74
|
-
* in the array, or {@link Failure} with an error message if the array is empty.
|
|
75
|
-
*/
|
|
76
|
-
first(failMessage) {
|
|
77
|
-
if (this.length > 0) {
|
|
78
|
-
return (0, base_1.succeed)(this[0]);
|
|
79
|
-
}
|
|
80
|
-
return (0, base_1.fail)(failMessage !== null && failMessage !== void 0 ? failMessage : `${this.itemDescription} not found`);
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Returns an array containing all elements of an {@link Experimental.ExtendedArray}. Fails with
|
|
84
|
-
* an error message if the array is empty.
|
|
85
|
-
* @param failMessage - Optional message to be displayed in the event of failure.
|
|
86
|
-
* @returns Returns {@link Success | Success<T[]>} with a new (non-extended) `Array`
|
|
87
|
-
* containing the elements of this array, or {@link Failure} with an error message
|
|
88
|
-
* if the array is empty.
|
|
89
|
-
*/
|
|
90
|
-
atLeastOne(failMessage) {
|
|
91
|
-
if (this.length > 0) {
|
|
92
|
-
return (0, base_1.succeed)(Array.from(this));
|
|
93
|
-
}
|
|
94
|
-
return (0, base_1.fail)(failMessage !== null && failMessage !== void 0 ? failMessage : `${this.itemDescription} not found`);
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Gets a new (non-extended) `Array` containing all of the elements from this
|
|
98
|
-
* {@link Experimental.ExtendedArray}.
|
|
99
|
-
* @returns A new (non-extended) `Array<T>`.
|
|
100
|
-
*/
|
|
101
|
-
all() {
|
|
102
|
-
return Array.from(this);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
exports.ExtendedArray = ExtendedArray;
|
|
106
|
-
//# sourceMappingURL=extendedArray.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extendedArray.js","sourceRoot":"","sources":["../../../src/packlets/experimental/extendedArray.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,kCAAgD;AAEhD;;;;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,aAAa,CAAC;IACpC,CAAC;IAED;;;;;;;OAOG;IACI,MAAM,CAAC,SAAgC;QAC5C,MAAM,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACxD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;YACtB,OAAO,IAAA,cAAO,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;SAC1B;QACD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;YACtB,OAAO,IAAA,WAAI,EAAC,GAAG,IAAI,CAAC,eAAe,YAAY,CAAC,CAAC;SAClD;QACD,OAAO,IAAA,WAAI,EAAC,GAAG,IAAI,CAAC,eAAe,YAAY,KAAK,CAAC,MAAM,QAAQ,CAAC,CAAC;IACvE,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,WAAoB;QAC/B,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;YACnB,OAAO,IAAA,cAAO,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;SACzB;QACD,OAAO,IAAA,WAAI,EAAC,WAAW,aAAX,WAAW,cAAX,WAAW,GAAI,GAAG,IAAI,CAAC,eAAe,YAAY,CAAC,CAAC;IAClE,CAAC;IAED;;;;;;;OAOG;IACI,UAAU,CAAC,WAAoB;QACpC,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;YACnB,OAAO,IAAA,cAAO,EAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;SAClC;QACD,OAAO,IAAA,WAAI,EAAC,WAAW,aAAX,WAAW,cAAX,WAAW,GAAI,GAAG,IAAI,CAAC,eAAe,YAAY,CAAC,CAAC;IAClE,CAAC;IAED;;;;OAIG;IACI,GAAG;QACR,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,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 '../base';\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 {@link Result | 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}.\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},\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 {@link Success | Success<T>} with the single matching\r\n * result if exactly one item matches `predicate`. Returns {@link Failure}\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}. 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 {@link Success | Success<T>} with the value of the first element\r\n * in the array, or {@link Failure} 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}. Fails with\r\n * 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 {@link Success | Success<T[]>} with a new (non-extended) `Array`\r\n * containing the elements of this array, or {@link Failure} 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}.\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,66 +0,0 @@
|
|
|
1
|
-
import { Result } from '../base';
|
|
2
|
-
/**
|
|
3
|
-
* Destination format for some formatted string.
|
|
4
|
-
* @beta
|
|
5
|
-
*/
|
|
6
|
-
export type FormatTargets = 'text' | 'markdown' | 'embed';
|
|
7
|
-
/**
|
|
8
|
-
* Interface for an object that can be formatted.
|
|
9
|
-
* @beta
|
|
10
|
-
*/
|
|
11
|
-
export interface Formattable {
|
|
12
|
-
/**
|
|
13
|
-
* Formats an object using the supplied mustache template.
|
|
14
|
-
* @param format - A mustache template used to format the object.
|
|
15
|
-
* @returns {@link Success} with the resulting string, or {@link Failure}
|
|
16
|
-
* with an error message if an error occurs.
|
|
17
|
-
*/
|
|
18
|
-
format(format: string): Result<string>;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Base class which adds common formatting.
|
|
22
|
-
* @beta
|
|
23
|
-
*/
|
|
24
|
-
export declare class FormattableBase {
|
|
25
|
-
/**
|
|
26
|
-
* Helper enables derived classes to add named details to a formatted presentation.
|
|
27
|
-
* @param details - An array of detail description strings.
|
|
28
|
-
* @param label - Label to use for the new detail.
|
|
29
|
-
* @param value - Value to use for the new detail.
|
|
30
|
-
* @internal
|
|
31
|
-
*/
|
|
32
|
-
protected static _tryAddDetail(details: string[], label: string, value: string | undefined): void;
|
|
33
|
-
/**
|
|
34
|
-
* {@inheritdoc Experimental.Formattable.format}
|
|
35
|
-
*/
|
|
36
|
-
format(template: string): Result<string>;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Type definition for a formatting function, which takes a `string` and an
|
|
40
|
-
* item and returns {@link Result | Result<string>}.
|
|
41
|
-
* @beta
|
|
42
|
-
*/
|
|
43
|
-
export type Formatter<T> = (format: string, item: T) => Result<string>;
|
|
44
|
-
/**
|
|
45
|
-
* A collection of {@link Experimental.Formatter | formatters} indexed by target name, to enable
|
|
46
|
-
* different format methods per output target.
|
|
47
|
-
* @beta
|
|
48
|
-
*/
|
|
49
|
-
export type FormattersByExtendedTarget<TFT extends FormatTargets, T> = Record<TFT, Formatter<T>>;
|
|
50
|
-
/**
|
|
51
|
-
* A collection of {@link Experimental.Formatter | formatters} indexed by the
|
|
52
|
-
* {@link Experimental.FormatTargets | default supported target formats}.
|
|
53
|
-
* @beta
|
|
54
|
-
*/
|
|
55
|
-
export type FormattersByTarget<T> = FormattersByExtendedTarget<FormatTargets, T>;
|
|
56
|
-
/**
|
|
57
|
-
* Formats a list of items using the supplied template and formatter, one result
|
|
58
|
-
* per output line.
|
|
59
|
-
* @param format - A mustache template used to format each item.
|
|
60
|
-
* @param items - The items to be formatted.
|
|
61
|
-
* @param itemFormatter - The {@link Experimental.Formatter | Formatter<T>} used to format each item.
|
|
62
|
-
* @returns The resulting string.
|
|
63
|
-
* @beta
|
|
64
|
-
*/
|
|
65
|
-
export declare function formatList<T>(format: string, items: T[], itemFormatter: Formatter<T>): Result<string>;
|
|
66
|
-
//# sourceMappingURL=formatter.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../../src/packlets/experimental/formatter.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,MAAM,EAAsC,MAAM,SAAS,CAAC;AAIrE;;;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,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,CASrG"}
|
|
@@ -1,75 +0,0 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
24
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
25
|
-
};
|
|
26
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.formatList = exports.FormattableBase = void 0;
|
|
28
|
-
const mustache_1 = __importDefault(require("mustache"));
|
|
29
|
-
const base_1 = require("../base");
|
|
30
|
-
mustache_1.default.escape = (s) => s;
|
|
31
|
-
/**
|
|
32
|
-
* Base class which adds common formatting.
|
|
33
|
-
* @beta
|
|
34
|
-
*/
|
|
35
|
-
class FormattableBase {
|
|
36
|
-
/**
|
|
37
|
-
* Helper enables derived classes to add named details to a formatted presentation.
|
|
38
|
-
* @param details - An array of detail description strings.
|
|
39
|
-
* @param label - Label to use for the new detail.
|
|
40
|
-
* @param value - Value to use for the new detail.
|
|
41
|
-
* @internal
|
|
42
|
-
*/
|
|
43
|
-
static _tryAddDetail(details, label, value) {
|
|
44
|
-
if (value !== undefined) {
|
|
45
|
-
const padded = ` ${label}:`.padEnd(20, ' ');
|
|
46
|
-
details.push(`${padded} ${value}`);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* {@inheritdoc Experimental.Formattable.format}
|
|
51
|
-
*/
|
|
52
|
-
format(template) {
|
|
53
|
-
return (0, base_1.captureResult)(() => mustache_1.default.render(template, this));
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
exports.FormattableBase = FormattableBase;
|
|
57
|
-
/**
|
|
58
|
-
* Formats a list of items using the supplied template and formatter, one result
|
|
59
|
-
* per output line.
|
|
60
|
-
* @param format - A mustache template used to format each item.
|
|
61
|
-
* @param items - The items to be formatted.
|
|
62
|
-
* @param itemFormatter - The {@link Experimental.Formatter | Formatter<T>} used to format each item.
|
|
63
|
-
* @returns The resulting string.
|
|
64
|
-
* @beta
|
|
65
|
-
*/
|
|
66
|
-
function formatList(format, items, itemFormatter) {
|
|
67
|
-
return (0, base_1.mapResults)(items.map((item) => {
|
|
68
|
-
return itemFormatter(format, item);
|
|
69
|
-
})).onSuccess((results) => {
|
|
70
|
-
const filtered = results.filter((s) => s !== '');
|
|
71
|
-
return (0, base_1.succeed)(filtered.join('\n'));
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
exports.formatList = formatList;
|
|
75
|
-
//# sourceMappingURL=formatter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formatter.js","sourceRoot":"","sources":["../../../src/packlets/experimental/formatter.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;AAEH,wDAAgC;AAChC,kCAAqE;AAErE,kBAAQ,CAAC,MAAM,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC;AAuBnC;;;GAGG;AACH,MAAa,eAAe;IAC1B;;;;;;OAMG;IACO,MAAM,CAAC,aAAa,CAAC,OAAiB,EAAE,KAAa,EAAE,KAAyB;QACxF,IAAI,KAAK,KAAK,SAAS,EAAE;YACvB,MAAM,MAAM,GAAG,KAAK,KAAK,GAAG,CAAC,MAAM,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;YAC7C,OAAO,CAAC,IAAI,CAAC,GAAG,MAAM,IAAI,KAAK,EAAE,CAAC,CAAC;SACpC;IACH,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,QAAgB;QAC5B,OAAO,IAAA,oBAAa,EAAC,GAAG,EAAE,CAAC,kBAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC;IAC9D,CAAC;CACF;AArBD,0CAqBC;AAsBD;;;;;;;;GAQG;AACH,SAAgB,UAAU,CAAI,MAAc,EAAE,KAAU,EAAE,aAA2B;IACnF,OAAO,IAAA,iBAAU,EACf,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACjB,OAAO,aAAa,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACrC,CAAC,CAAC,CACH,CAAC,SAAS,CAAC,CAAC,OAAiB,EAAE,EAAE;QAChC,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;QACjD,OAAO,IAAA,cAAO,EAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;AACL,CAAC;AATD,gCASC","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 Mustache from 'mustache';\nimport { Result, captureResult, mapResults, succeed } from '../base';\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 {@link Success} with the resulting string, or {@link Failure}\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 {@link Result | 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,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright (c) 2023 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
|
-
__exportStar(require("./extendedArray"), exports);
|
|
39
|
-
__exportStar(require("./formatter"), exports);
|
|
40
|
-
__exportStar(require("./rangeOf"), exports);
|
|
41
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -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,122 +0,0 @@
|
|
|
1
|
-
import { Result } from '../base';
|
|
2
|
-
/**
|
|
3
|
-
* Represents a generic range of some comparable type `<T>`.
|
|
4
|
-
* @public
|
|
5
|
-
*/
|
|
6
|
-
export interface RangeOfProperties<T> {
|
|
7
|
-
readonly min?: T;
|
|
8
|
-
readonly max?: T;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Format strings (in mustache format) to
|
|
12
|
-
* use for both open-ended and complete
|
|
13
|
-
* {@link Experimental.RangeOf | RangeOf<T>}.
|
|
14
|
-
* @public
|
|
15
|
-
*/
|
|
16
|
-
export interface RangeOfFormats {
|
|
17
|
-
minOnly: string;
|
|
18
|
-
maxOnly: string;
|
|
19
|
-
minMax: string;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Default {@link Experimental.RangeOfFormats | formats} to use for both
|
|
23
|
-
* open-ended and complete {@link Experimental.RangeOf | RangeOf<T>}.
|
|
24
|
-
* @public
|
|
25
|
-
*/
|
|
26
|
-
export declare const DEFAULT_RANGEOF_FORMATS: RangeOfFormats;
|
|
27
|
-
/**
|
|
28
|
-
* Simple implementation of a possibly open-ended range of some comparable
|
|
29
|
-
* type `<T>` with test and formatting.
|
|
30
|
-
* @public
|
|
31
|
-
*/
|
|
32
|
-
export declare class RangeOf<T> implements RangeOfProperties<T> {
|
|
33
|
-
/**
|
|
34
|
-
* Minimum extent of the range.
|
|
35
|
-
*/
|
|
36
|
-
readonly min?: T;
|
|
37
|
-
/**
|
|
38
|
-
* Maximum extent of the range.
|
|
39
|
-
*/
|
|
40
|
-
readonly max?: T;
|
|
41
|
-
/**
|
|
42
|
-
* Creates a new {@link Experimental.RangeOf | RangeOf<T>}.
|
|
43
|
-
* @param min - Optional minimum extent of the range.
|
|
44
|
-
* @param max - Optional maximum extent of the range.
|
|
45
|
-
*/
|
|
46
|
-
constructor(min?: T, max?: T);
|
|
47
|
-
/**
|
|
48
|
-
* Static constructor for a {@link Experimental.RangeOf | RangeOf<T>}.
|
|
49
|
-
* @param init - {@link Experimental.RangeOfProperties | Range initializer}.
|
|
50
|
-
* @returns A new {@link Experimental.RangeOf | RangeOf<T>}.
|
|
51
|
-
*/
|
|
52
|
-
static createRange<T>(init?: RangeOfProperties<T>): Result<RangeOf<T>>;
|
|
53
|
-
/**
|
|
54
|
-
* Gets a formatted description of a {@link Experimental.RangeOfProperties | RangeOfProperties<T>} given an
|
|
55
|
-
* optional set of formats and 'empty' value to use.
|
|
56
|
-
* @param range - The {@link Experimental.RangeOfProperties | RangeOfProperties<T>} to be formatted.
|
|
57
|
-
* @param formats - Optional {@link Experimental.RangeOfFormats | formats} to use. Default is
|
|
58
|
-
* {@link Experimental.DEFAULT_RANGEOF_FORMATS | DEFAULT_RANGEOF_FORMATS}.
|
|
59
|
-
* @param emptyValue - Value which represents unbounded minimum or maximum for this range. Default is `undefined`.
|
|
60
|
-
* @returns A string representation of the range.
|
|
61
|
-
*/
|
|
62
|
-
static propertiesToString<T>(range: RangeOfProperties<T>, formats?: RangeOfFormats, emptyValue?: T): string | undefined;
|
|
63
|
-
/**
|
|
64
|
-
* Default comparison uses javascript built-in comparison.
|
|
65
|
-
* @param t1 - First value to be compared.
|
|
66
|
-
* @param t2 - Second value to be compared.
|
|
67
|
-
* @returns `'less'` if `t1` is less than `t2`, `'greater'` if `t1` is larger
|
|
68
|
-
* and `'equal'` if `t1` and `t2` are equal.
|
|
69
|
-
* @internal
|
|
70
|
-
*/
|
|
71
|
-
protected static _defaultCompare<T>(t1: T, t2: T): 'less' | 'equal' | 'greater';
|
|
72
|
-
/**
|
|
73
|
-
* Checks if a supplied value is within this range.
|
|
74
|
-
* @param t - The value to be tested.
|
|
75
|
-
* @returns `'included'` if `t` falls within the range, `'less'` if `t` falls
|
|
76
|
-
* below the minimum extent of the range and `'greater'` if `t` is above the
|
|
77
|
-
* maximum extent.
|
|
78
|
-
*/
|
|
79
|
-
check(t: T): 'less' | 'included' | 'greater';
|
|
80
|
-
/**
|
|
81
|
-
* Determines if a supplied value is within this range.
|
|
82
|
-
* @param t - The value to be tested.
|
|
83
|
-
* @returns Returns `true` if `t` falls within the range, `false` otherwise.
|
|
84
|
-
*/
|
|
85
|
-
includes(t: T): boolean;
|
|
86
|
-
/**
|
|
87
|
-
* Finds the transition value that would bring a supplied value `t` into
|
|
88
|
-
* range.
|
|
89
|
-
* @param t - The value to be tested.
|
|
90
|
-
* @returns The minimum extent of the range if `t` is below the range or
|
|
91
|
-
* the maximum extent of the range if `t` is above the range. Returns
|
|
92
|
-
* `undefined` if `t` already falls within the range.
|
|
93
|
-
*/
|
|
94
|
-
findTransition(t: T): T | undefined;
|
|
95
|
-
/**
|
|
96
|
-
* Formats the minimum and maximum values of this range.
|
|
97
|
-
* @param format - A format function used to format the values.
|
|
98
|
-
* @returns A {@link Experimental.RangeOfProperties | RangeOfProperties<string>} containing the
|
|
99
|
-
* formatted representation of the {@link Experimental.RangeOf.min | minimum} and
|
|
100
|
-
* {@link Experimental.RangeOf.max | maximum}
|
|
101
|
-
* extent of the range, or `undefined` for an extent that is not present.
|
|
102
|
-
*/
|
|
103
|
-
toFormattedProperties(format: (value: T) => string | undefined): RangeOfProperties<string>;
|
|
104
|
-
/**
|
|
105
|
-
* Formats this range using the supplied format function.
|
|
106
|
-
* @param format - Format function used to format minimum and maximum extent values.
|
|
107
|
-
* @param formats - The {@link Experimental.RangeOfFormats | format strings} used to format the range
|
|
108
|
-
* (default {@link Experimental.DEFAULT_RANGEOF_FORMATS}).
|
|
109
|
-
* @returns Returns a formatted representation of this range.
|
|
110
|
-
*/
|
|
111
|
-
format(format: (value: T) => string | undefined, formats?: RangeOfFormats): string | undefined;
|
|
112
|
-
/**
|
|
113
|
-
* Inner compare method can be overridden by a derived class.
|
|
114
|
-
* @param t1 - First value to compare.
|
|
115
|
-
* @param t2 - Second value to compare.
|
|
116
|
-
* @returns `'less'` if `t1` is less than `t2`, `'greater'` if `t1` is larger
|
|
117
|
-
* and `'equal'` if `t1` and `t2` are equal.
|
|
118
|
-
* @internal
|
|
119
|
-
*/
|
|
120
|
-
protected _compare(t1: T, t2: T): 'less' | 'equal' | 'greater';
|
|
121
|
-
}
|
|
122
|
-
//# sourceMappingURL=rangeOf.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rangeOf.d.ts","sourceRoot":"","sources":["../../../src/packlets/experimental/rangeOf.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,MAAM,EAAiB,MAAM,SAAS,CAAC;AAEhD;;;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,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,EAAE,cAIrC,CAAC;AAEF;;;;GAIG;AACH,qBAAa,OAAO,CAAC,CAAC,CAAE,YAAW,iBAAiB,CAAC,CAAC,CAAC;IACrD;;OAEG;IACH,SAAgB,GAAG,CAAC,EAAE,CAAC,CAAC;IACxB;;OAEG;IACH,SAAgB,GAAG,CAAC,EAAE,CAAC,CAAC;IAExB;;;;OAIG;gBACgB,GAAG,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;IAQnC;;;;OAIG;WACW,WAAW,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAI7E;;;;;;;;OAQG;WACW,kBAAkB,CAAC,CAAC,EAChC,KAAK,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAC3B,OAAO,CAAC,EAAE,cAAc,EACxB,UAAU,CAAC,EAAE,CAAC,GACb,MAAM,GAAG,SAAS;IAcrB;;;;;;;OAOG;IACH,SAAS,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS;IAS/E;;;;;;OAMG;IACI,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,MAAM,GAAG,UAAU,GAAG,SAAS;IAUnD;;;;OAIG;IACI,QAAQ,CAAC,CAAC,EAAE,CAAC,GAAG,OAAO;IAI9B;;;;;;;OAOG;IACI,cAAc,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS;IAU1C;;;;;;;OAOG;IACI,qBAAqB,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,MAAM,GAAG,SAAS,GAAG,iBAAiB,CAAC,MAAM,CAAC;IAOjG;;;;;;OAMG;IACI,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,MAAM,GAAG,SAAS,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,MAAM,GAAG,SAAS;IAIrG;;;;;;;OAOG;IACH,SAAS,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS;CAG/D"}
|