@augment-vir/common 29.2.0 → 30.0.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/LICENSE-CC0 +121 -0
- package/LICENSE-MIT +21 -0
- package/dist/augments/array/array-map.d.ts +6 -0
- package/dist/augments/array/array-map.js +4 -0
- package/dist/augments/array/array-to-object.d.ts +17 -0
- package/dist/augments/array/array-to-object.js +31 -0
- package/dist/augments/array/awaited/awaited-filter.d.ts +7 -0
- package/dist/augments/array/awaited/awaited-filter.js +7 -0
- package/dist/augments/array/awaited/awaited-for-each.d.ts +6 -0
- package/dist/augments/array/awaited/awaited-for-each.js +9 -0
- package/dist/augments/array/awaited/awaited-map.d.ts +1 -0
- package/dist/augments/array/awaited/awaited-map.js +8 -0
- package/dist/augments/array/filter.d.ts +3 -0
- package/dist/augments/array/filter.js +13 -0
- package/dist/augments/array/repeat-array.d.ts +1 -0
- package/dist/augments/array/repeat-array.js +3 -0
- package/dist/augments/array/shuffle-array.d.ts +2 -0
- package/dist/augments/array/shuffle-array.js +10 -0
- package/dist/augments/array/string-array.d.ts +1 -0
- package/dist/augments/array/string-array.js +3 -0
- package/dist/augments/boolean/if-truthy.d.ts +2 -0
- package/dist/{esm/augments/boolean.js → augments/boolean/if-truthy.js} +2 -7
- package/dist/augments/core-exports.d.ts +1 -0
- package/dist/augments/core-exports.js +1 -0
- package/dist/augments/enum/enum-value-check.d.ts +2 -0
- package/dist/augments/enum/enum-value-check.js +4 -0
- package/dist/augments/error/combine-errors.d.ts +3 -0
- package/dist/augments/error/combine-errors.js +12 -0
- package/dist/augments/function/call-asynchronously.d.ts +6 -0
- package/dist/augments/function/call-asynchronously.js +7 -0
- package/dist/augments/function/call-with-retries.d.ts +4 -0
- package/dist/augments/function/call-with-retries.js +27 -0
- package/dist/augments/function/debounce.d.ts +22 -0
- package/dist/augments/function/debounce.js +50 -0
- package/dist/augments/function/execution-duration.d.ts +8 -0
- package/dist/{esm/augments/time.js → augments/function/execution-duration.js} +7 -12
- package/dist/{types/augments → augments/function}/wrap-in-try.d.ts +2 -3
- package/dist/{esm/augments → augments/function}/wrap-in-try.js +4 -4
- package/dist/augments/json/append-json.d.ts +5 -0
- package/dist/augments/json/append-json.js +26 -0
- package/dist/augments/json/copy-through-json.d.ts +3 -0
- package/dist/augments/json/copy-through-json.js +11 -0
- package/dist/augments/json/jsonify.d.ts +2 -0
- package/dist/augments/json/jsonify.js +4 -0
- package/dist/augments/log/log-colors.d.ts +23 -0
- package/dist/augments/log/log-colors.js +116 -0
- package/dist/augments/log/log-string.d.ts +14 -0
- package/dist/augments/log/log-string.js +66 -0
- package/dist/augments/log/log-writer.d.ts +8 -0
- package/dist/augments/log/log.d.ts +13 -0
- package/dist/augments/log/log.js +42 -0
- package/dist/augments/log/logger.d.ts +11 -0
- package/dist/augments/log/logger.js +38 -0
- package/dist/augments/number/clamp.d.ts +7 -0
- package/dist/augments/number/clamp.js +8 -0
- package/dist/augments/number/coords.d.ts +19 -0
- package/dist/augments/number/digit.d.ts +1 -0
- package/dist/augments/number/dimensions.d.ts +19 -0
- package/dist/augments/number/min-max.d.ts +11 -0
- package/dist/augments/number/min-max.js +14 -0
- package/dist/augments/number/number-conversion.d.ts +23 -0
- package/dist/augments/number/number-conversion.js +50 -0
- package/dist/augments/number/round.d.ts +3 -0
- package/dist/augments/number/round.js +5 -0
- package/dist/augments/number/scientific.d.ts +1 -0
- package/dist/augments/number/scientific.js +3 -0
- package/dist/{esm/augments → augments/number}/truncate-number.js +14 -12
- package/dist/augments/number/wrap-number.d.ts +13 -0
- package/dist/augments/number/wrap-number.js +22 -0
- package/dist/augments/object/diff.d.ts +29 -0
- package/dist/augments/object/diff.js +133 -0
- package/dist/augments/object/empty.d.ts +3 -0
- package/dist/augments/object/get-or-set.d.ts +31 -0
- package/dist/{esm/augments → augments}/object/get-or-set.js +5 -3
- package/dist/{types/augments → augments}/object/key-count.d.ts +9 -5
- package/dist/augments/object/map-entries.d.ts +13 -0
- package/dist/augments/object/map-entries.js +57 -0
- package/dist/augments/object/map-enum.d.ts +4 -0
- package/dist/augments/object/map-enum.js +21 -0
- package/dist/{types/augments/object/map-object.d.ts → augments/object/map-values.d.ts} +6 -3
- package/dist/{esm/augments/object/map-object.js → augments/object/map-values.js} +9 -9
- package/dist/{esm/augments → augments}/object/merge-deep.js +5 -6
- package/dist/augments/object/merge-defined-properties.d.ts +6 -0
- package/dist/augments/object/merge-defined-properties.js +19 -0
- package/dist/{esm/augments → augments}/object/merge-property-arrays.js +1 -1
- package/dist/augments/object/object-entries.d.ts +4 -0
- package/dist/augments/object/object-entries.js +13 -0
- package/dist/augments/object/object-filter.d.ts +2 -0
- package/dist/augments/object/object-filter.js +7 -0
- package/dist/augments/object/object-keys.d.ts +2 -0
- package/dist/augments/object/object-keys.js +11 -0
- package/dist/augments/object/object-values.d.ts +2 -0
- package/dist/augments/object/object-values.js +4 -0
- package/dist/augments/prisma/prisma-models.d.ts +106 -0
- package/dist/augments/prisma/prisma-models.js +1 -0
- package/dist/augments/promise/timed-promise.d.ts +7 -0
- package/dist/augments/promise/timed-promise.js +36 -0
- package/dist/augments/random/random-boolean.d.ts +18 -0
- package/dist/augments/random/random-boolean.js +26 -0
- package/dist/augments/random/random-integer.d.ts +12 -0
- package/dist/augments/random/random-integer.js +32 -0
- package/dist/augments/random/random-string.d.ts +14 -0
- package/dist/augments/random/random-string.js +63 -0
- package/dist/{types/augments/regexp.d.ts → augments/regexp/regexp-flags.d.ts} +1 -1
- package/dist/augments/regexp/regexp-flags.js +18 -0
- package/dist/augments/regexp/regexp-string.d.ts +5 -0
- package/dist/augments/regexp/regexp-string.js +7 -0
- package/dist/augments/regexp/safe-match.d.ts +1 -0
- package/dist/augments/regexp/safe-match.js +4 -0
- package/dist/augments/selection-set/select-collapsed.d.ts +11 -0
- package/dist/augments/selection-set/select-collapsed.js +25 -0
- package/dist/augments/selection-set/select-from.d.ts +3 -0
- package/dist/augments/selection-set/select-from.js +25 -0
- package/dist/augments/selection-set/selection-set.d.ts +18 -0
- package/dist/augments/selection-set/selection-set.js +4 -0
- package/dist/augments/string/casing/capitalization.d.ts +3 -0
- package/dist/augments/string/casing/capitalization.js +11 -0
- package/dist/augments/string/casing/casing.d.ts +27 -0
- package/dist/augments/string/casing/casing.js +40 -0
- package/dist/augments/string/casing/kebab-and-camel.d.ts +3 -0
- package/dist/augments/string/casing/kebab-and-camel.js +42 -0
- package/dist/augments/string/commas.d.ts +7 -0
- package/dist/augments/string/commas.js +29 -0
- package/dist/augments/string/join.d.ts +10 -0
- package/dist/augments/string/join.js +23 -0
- package/dist/{types/augments/string/prefixes.d.ts → augments/string/prefix.d.ts} +16 -1
- package/dist/{esm/augments/string/prefixes.js → augments/string/prefix.js} +11 -1
- package/dist/augments/string/replace.d.ts +1 -0
- package/dist/augments/string/replace.js +5 -0
- package/dist/augments/string/split.d.ts +4 -0
- package/dist/augments/string/split.js +28 -0
- package/dist/augments/string/substring-index.d.ts +13 -0
- package/dist/augments/string/substring-index.js +38 -0
- package/dist/augments/string/suffix.d.ts +74 -0
- package/dist/augments/string/suffix.js +73 -0
- package/dist/augments/string/white-space.d.ts +5 -0
- package/dist/augments/string/white-space.js +12 -0
- package/dist/augments/string/wrap-string.d.ts +4 -0
- package/dist/augments/string/wrap-string.js +5 -0
- package/dist/augments/type/ensure-type.d.ts +8 -0
- package/dist/augments/type/ensure-type.js +10 -0
- package/dist/augments/type/readonly.d.ts +2 -0
- package/dist/augments/type/readonly.js +3 -0
- package/dist/augments/type/type-recursion.js +1 -0
- package/dist/augments/type/void-type.d.ts +5 -0
- package/dist/augments/type/void-type.js +1 -0
- package/dist/augments/type/writable.d.ts +3 -0
- package/dist/augments/type/writable.js +3 -0
- package/dist/index.d.ts +81 -0
- package/dist/index.js +81 -0
- package/package.json +33 -15
- package/README.md +0 -7
- package/dist/cjs/augments/ansi.js +0 -27
- package/dist/cjs/augments/array/array.js +0 -68
- package/dist/cjs/augments/array/remove-duplicates.js +0 -16
- package/dist/cjs/augments/async.js +0 -28
- package/dist/cjs/augments/boolean.js +0 -19
- package/dist/cjs/augments/common-number.js +0 -112
- package/dist/cjs/augments/common-string.js +0 -245
- package/dist/cjs/augments/debounce.js +0 -38
- package/dist/cjs/augments/environment.js +0 -6
- package/dist/cjs/augments/error.js +0 -52
- package/dist/cjs/augments/esm-path.js +0 -11
- package/dist/cjs/augments/function.js +0 -2
- package/dist/cjs/augments/json-compatible.js +0 -2
- package/dist/cjs/augments/json.js +0 -28
- package/dist/cjs/augments/object/any-object.js +0 -2
- package/dist/cjs/augments/object/enum.js +0 -48
- package/dist/cjs/augments/object/filter-object.js +0 -26
- package/dist/cjs/augments/object/get-or-set.js +0 -40
- package/dist/cjs/augments/object/has-key.js +0 -6
- package/dist/cjs/augments/object/jsonify.js +0 -6
- package/dist/cjs/augments/object/key-count.js +0 -2
- package/dist/cjs/augments/object/map-object.js +0 -61
- package/dist/cjs/augments/object/merge-deep.js +0 -52
- package/dist/cjs/augments/object/merge-property-arrays.js +0 -14
- package/dist/cjs/augments/object/object-entries.js +0 -40
- package/dist/cjs/augments/object/object.js +0 -18
- package/dist/cjs/augments/object/pick-deep.js +0 -2
- package/dist/cjs/augments/object/selection-set.js +0 -56
- package/dist/cjs/augments/object/typed-has-property.js +0 -29
- package/dist/cjs/augments/promise/deferred-promise.js +0 -31
- package/dist/cjs/augments/promise/promise.js +0 -79
- package/dist/cjs/augments/promise/wait.js +0 -66
- package/dist/cjs/augments/random.js +0 -123
- package/dist/cjs/augments/regexp.js +0 -19
- package/dist/cjs/augments/string/prefixes.js +0 -20
- package/dist/cjs/augments/string/suffixes.js +0 -40
- package/dist/cjs/augments/string/uuid.js +0 -7
- package/dist/cjs/augments/time.js +0 -35
- package/dist/cjs/augments/truncate-number.js +0 -153
- package/dist/cjs/augments/tuple.js +0 -20
- package/dist/cjs/augments/type-recursion.js +0 -2
- package/dist/cjs/augments/type.js +0 -36
- package/dist/cjs/augments/union.js +0 -2
- package/dist/cjs/augments/wrap-in-try.js +0 -37
- package/dist/cjs/index.js +0 -60
- package/dist/esm/augments/ansi.js +0 -24
- package/dist/esm/augments/array/array.js +0 -57
- package/dist/esm/augments/async.js +0 -23
- package/dist/esm/augments/common-number.js +0 -100
- package/dist/esm/augments/common-string.js +0 -227
- package/dist/esm/augments/debounce.js +0 -34
- package/dist/esm/augments/environment.js +0 -3
- package/dist/esm/augments/error.js +0 -45
- package/dist/esm/augments/json.js +0 -24
- package/dist/esm/augments/object/enum.js +0 -41
- package/dist/esm/augments/object/filter-object.js +0 -21
- package/dist/esm/augments/object/has-key.js +0 -3
- package/dist/esm/augments/object/jsonify.js +0 -3
- package/dist/esm/augments/object/object-entries.js +0 -32
- package/dist/esm/augments/object/object.js +0 -14
- package/dist/esm/augments/object/selection-set.js +0 -52
- package/dist/esm/augments/object/typed-has-property.js +0 -25
- package/dist/esm/augments/promise/deferred-promise.js +0 -28
- package/dist/esm/augments/promise/promise.js +0 -71
- package/dist/esm/augments/promise/wait.js +0 -60
- package/dist/esm/augments/random.js +0 -117
- package/dist/esm/augments/regexp.js +0 -14
- package/dist/esm/augments/string/suffixes.js +0 -31
- package/dist/esm/augments/string/uuid.js +0 -4
- package/dist/esm/augments/tuple.js +0 -16
- package/dist/esm/augments/type.js +0 -30
- package/dist/esm/index.js +0 -44
- package/dist/types/augments/ansi.d.ts +0 -1
- package/dist/types/augments/array/array.d.ts +0 -26
- package/dist/types/augments/async.d.ts +0 -14
- package/dist/types/augments/boolean.d.ts +0 -6
- package/dist/types/augments/common-number.d.ts +0 -52
- package/dist/types/augments/common-string.d.ts +0 -74
- package/dist/types/augments/debounce.d.ts +0 -15
- package/dist/types/augments/environment.d.ts +0 -1
- package/dist/types/augments/error.d.ts +0 -9
- package/dist/types/augments/function.d.ts +0 -25
- package/dist/types/augments/json.d.ts +0 -9
- package/dist/types/augments/object/any-object.d.ts +0 -2
- package/dist/types/augments/object/enum.d.ts +0 -8
- package/dist/types/augments/object/filter-object.d.ts +0 -4
- package/dist/types/augments/object/get-or-set.d.ts +0 -26
- package/dist/types/augments/object/has-key.d.ts +0 -1
- package/dist/types/augments/object/jsonify.d.ts +0 -2
- package/dist/types/augments/object/object-entries.d.ts +0 -8
- package/dist/types/augments/object/object.d.ts +0 -21
- package/dist/types/augments/object/pick-deep.d.ts +0 -14
- package/dist/types/augments/object/selection-set.d.ts +0 -27
- package/dist/types/augments/object/typed-has-property.d.ts +0 -7
- package/dist/types/augments/promise/deferred-promise.d.ts +0 -8
- package/dist/types/augments/promise/promise.d.ts +0 -15
- package/dist/types/augments/promise/wait.d.ts +0 -18
- package/dist/types/augments/random.d.ts +0 -39
- package/dist/types/augments/string/suffixes.d.ts +0 -17
- package/dist/types/augments/string/uuid.d.ts +0 -1
- package/dist/types/augments/time.d.ts +0 -14
- package/dist/types/augments/tuple.d.ts +0 -17
- package/dist/types/augments/type.d.ts +0 -69
- package/dist/types/augments/union.d.ts +0 -5
- package/dist/types/index.d.ts +0 -44
- /package/dist/{types/augments → augments}/array/remove-duplicates.d.ts +0 -0
- /package/dist/{esm/augments → augments}/array/remove-duplicates.js +0 -0
- /package/dist/{types/augments → augments/file}/esm-path.d.ts +0 -0
- /package/dist/{esm/augments → augments/file}/esm-path.js +0 -0
- /package/dist/{types/augments → augments/json}/json-compatible.d.ts +0 -0
- /package/dist/{esm/augments → augments/json}/json-compatible.js +0 -0
- /package/dist/{esm/augments/function.js → augments/log/log-writer.js} +0 -0
- /package/dist/{esm/augments/object/any-object.js → augments/number/coords.js} +0 -0
- /package/dist/{esm/augments/object/key-count.js → augments/number/digit.js} +0 -0
- /package/dist/{esm/augments/object/pick-deep.js → augments/number/dimensions.js} +0 -0
- /package/dist/{types/augments → augments/number}/truncate-number.d.ts +0 -0
- /package/dist/{esm/augments/type-recursion.js → augments/object/empty.js} +0 -0
- /package/dist/{esm/augments/union.js → augments/object/key-count.js} +0 -0
- /package/dist/{types/augments → augments}/object/merge-deep.d.ts +0 -0
- /package/dist/{types/augments → augments}/object/merge-property-arrays.d.ts +0 -0
- /package/dist/{types/augments → augments/type}/type-recursion.d.ts +0 -0
package/LICENSE-CC0
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
CC0 1.0 Universal
|
|
2
|
+
|
|
3
|
+
Creative Commons Legal Code
|
|
4
|
+
|
|
5
|
+
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
|
|
6
|
+
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
|
|
7
|
+
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
|
|
8
|
+
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
|
|
9
|
+
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
|
|
10
|
+
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
|
|
11
|
+
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
|
|
12
|
+
HEREUNDER.
|
|
13
|
+
|
|
14
|
+
Statement of Purpose
|
|
15
|
+
|
|
16
|
+
The laws of most jurisdictions throughout the world automatically confer
|
|
17
|
+
exclusive Copyright and Related Rights (defined below) upon the creator
|
|
18
|
+
and subsequent owner(s) (each and all, an "owner") of an original work of
|
|
19
|
+
authorship and/or a database (each, a "Work").
|
|
20
|
+
|
|
21
|
+
Certain owners wish to permanently relinquish those rights to a Work for
|
|
22
|
+
the purpose of contributing to a commons of creative, cultural and
|
|
23
|
+
scientific works ("Commons") that the public can reliably and without fear
|
|
24
|
+
of later claims of infringement build upon, modify, incorporate in other
|
|
25
|
+
works, reuse and redistribute as freely as possible in any form whatsoever
|
|
26
|
+
and for any purposes, including without limitation commercial purposes.
|
|
27
|
+
These owners may contribute to the Commons to promote the ideal of a free
|
|
28
|
+
culture and the further production of creative, cultural and scientific
|
|
29
|
+
works, or to gain reputation or greater distribution for their Work in
|
|
30
|
+
part through the use and efforts of others.
|
|
31
|
+
|
|
32
|
+
For these and/or other purposes and motivations, and without any
|
|
33
|
+
expectation of additional consideration or compensation, the person
|
|
34
|
+
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
|
|
35
|
+
is an owner of Copyright and Related Rights in the Work, voluntarily
|
|
36
|
+
elects to apply CC0 to the Work and publicly distribute the Work under its
|
|
37
|
+
terms, with knowledge of his or her Copyright and Related Rights in the
|
|
38
|
+
Work and the meaning and intended legal effect of CC0 on those rights.
|
|
39
|
+
|
|
40
|
+
1. Copyright and Related Rights. A Work made available under CC0 may be
|
|
41
|
+
protected by copyright and related or neighboring rights ("Copyright and
|
|
42
|
+
Related Rights"). Copyright and Related Rights include, but are not
|
|
43
|
+
limited to, the following:
|
|
44
|
+
|
|
45
|
+
i. the right to reproduce, adapt, distribute, perform, display,
|
|
46
|
+
communicate, and translate a Work;
|
|
47
|
+
ii. moral rights retained by the original author(s) and/or performer(s);
|
|
48
|
+
iii. publicity and privacy rights pertaining to a person's image or
|
|
49
|
+
likeness depicted in a Work;
|
|
50
|
+
iv. rights protecting against unfair competition in regards to a Work,
|
|
51
|
+
subject to the limitations in paragraph 4(a), below;
|
|
52
|
+
v. rights protecting the extraction, dissemination, use and reuse of data
|
|
53
|
+
in a Work;
|
|
54
|
+
vi. database rights (such as those arising under Directive 96/9/EC of the
|
|
55
|
+
European Parliament and of the Council of 11 March 1996 on the legal
|
|
56
|
+
protection of databases, and under any national implementation
|
|
57
|
+
thereof, including any amended or successor version of such
|
|
58
|
+
directive); and
|
|
59
|
+
vii. other similar, equivalent or corresponding rights throughout the
|
|
60
|
+
world based on applicable law or treaty, and any national
|
|
61
|
+
implementations thereof.
|
|
62
|
+
|
|
63
|
+
2. Waiver. To the greatest extent permitted by, but not in contravention
|
|
64
|
+
of, applicable law, Affirmer hereby overtly, fully, permanently,
|
|
65
|
+
irrevocably and unconditionally waives, abandons, and surrenders all of
|
|
66
|
+
Affirmer's Copyright and Related Rights and associated claims and causes
|
|
67
|
+
of action, whether now known or unknown (including existing as well as
|
|
68
|
+
future claims and causes of action), in the Work (i) in all territories
|
|
69
|
+
worldwide, (ii) for the maximum duration provided by applicable law or
|
|
70
|
+
treaty (including future time extensions), (iii) in any current or future
|
|
71
|
+
medium and for any number of copies, and (iv) for any purpose whatsoever,
|
|
72
|
+
including without limitation commercial, advertising or promotional
|
|
73
|
+
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
|
|
74
|
+
member of the public at large and to the detriment of Affirmer's heirs and
|
|
75
|
+
successors, fully intending that such Waiver shall not be subject to
|
|
76
|
+
revocation, rescission, cancellation, termination, or any other legal or
|
|
77
|
+
equitable action to disrupt the quiet enjoyment of the Work by the public
|
|
78
|
+
as contemplated by Affirmer's express Statement of Purpose.
|
|
79
|
+
|
|
80
|
+
3. Public License Fallback. Should any part of the Waiver for any reason
|
|
81
|
+
be judged legally invalid or ineffective under applicable law, then the
|
|
82
|
+
Waiver shall be preserved to the maximum extent permitted taking into
|
|
83
|
+
account Affirmer's express Statement of Purpose. In addition, to the
|
|
84
|
+
extent the Waiver is so judged Affirmer hereby grants to each affected
|
|
85
|
+
person a royalty-free, non transferable, non sublicensable, non exclusive,
|
|
86
|
+
irrevocable and unconditional license to exercise Affirmer's Copyright and
|
|
87
|
+
Related Rights in the Work (i) in all territories worldwide, (ii) for the
|
|
88
|
+
maximum duration provided by applicable law or treaty (including future
|
|
89
|
+
time extensions), (iii) in any current or future medium and for any number
|
|
90
|
+
of copies, and (iv) for any purpose whatsoever, including without
|
|
91
|
+
limitation commercial, advertising or promotional purposes (the
|
|
92
|
+
"License"). The License shall be deemed effective as of the date CC0 was
|
|
93
|
+
applied by Affirmer to the Work. Should any part of the License for any
|
|
94
|
+
reason be judged legally invalid or ineffective under applicable law, such
|
|
95
|
+
partial invalidity or ineffectiveness shall not invalidate the remainder
|
|
96
|
+
of the License, and in such case Affirmer hereby affirms that he or she
|
|
97
|
+
will not (i) exercise any of his or her remaining Copyright and Related
|
|
98
|
+
Rights in the Work or (ii) assert any associated claims and causes of
|
|
99
|
+
action with respect to the Work, in either case contrary to Affirmer's
|
|
100
|
+
express Statement of Purpose.
|
|
101
|
+
|
|
102
|
+
4. Limitations and Disclaimers.
|
|
103
|
+
|
|
104
|
+
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
|
105
|
+
surrendered, licensed or otherwise affected by this document.
|
|
106
|
+
b. Affirmer offers the Work as-is and makes no representations or
|
|
107
|
+
warranties of any kind concerning the Work, express, implied,
|
|
108
|
+
statutory or otherwise, including without limitation warranties of
|
|
109
|
+
title, merchantability, fitness for a particular purpose, non
|
|
110
|
+
infringement, or the absence of latent or other defects, accuracy, or
|
|
111
|
+
the present or absence of errors, whether or not discoverable, all to
|
|
112
|
+
the greatest extent permissible under applicable law.
|
|
113
|
+
c. Affirmer disclaims responsibility for clearing rights of other persons
|
|
114
|
+
that may apply to the Work or any use thereof, including without
|
|
115
|
+
limitation any person's Copyright and Related Rights in the Work.
|
|
116
|
+
Further, Affirmer disclaims responsibility for obtaining any necessary
|
|
117
|
+
consents, permissions or other rights required for any use of the
|
|
118
|
+
Work.
|
|
119
|
+
d. Affirmer understands and acknowledges that Creative Commons is not a
|
|
120
|
+
party to this document and has no duty or obligation with respect to
|
|
121
|
+
this CC0 or use of the Work.
|
package/LICENSE-MIT
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 electrovir
|
|
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.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ArrayElement } from '@augment-vir/core';
|
|
2
|
+
import { Writable } from '../type/writable.js';
|
|
3
|
+
/** Preserves tuple types. */
|
|
4
|
+
export declare function typedMap<const ArrayGeneric extends ReadonlyArray<any>, const OutputType>(arrayToMap: ArrayGeneric, mapCallback: (value: ArrayElement<NoInfer<ArrayGeneric>>, index: number, array: NoInfer<ArrayGeneric>) => OutputType): Writable<{
|
|
5
|
+
[Index in keyof ArrayGeneric]: OutputType;
|
|
6
|
+
}>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Polyfill for `Object.groupBy`:
|
|
3
|
+
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/groupBy
|
|
4
|
+
*
|
|
5
|
+
* @category Object:Common
|
|
6
|
+
*/
|
|
7
|
+
export declare function groupArrayBy<ElementType, NewKey extends PropertyKey>(inputArray: ReadonlyArray<ElementType>, callback: (value: ElementType, index: number, originalArray: ReadonlyArray<ElementType>) => NewKey): Partial<Record<NewKey, ElementType[]>>;
|
|
8
|
+
/**
|
|
9
|
+
* Like `groupArrayBy` but maps array entries to a single key. Meaning, the resulting object does
|
|
10
|
+
* not have an array of elements (unless the original array itself contains arrays).
|
|
11
|
+
*
|
|
12
|
+
* @category Object:Common
|
|
13
|
+
*/
|
|
14
|
+
export declare function arrayToObject<ElementType, NewKey extends PropertyKey, NewValue>(inputArray: ReadonlyArray<ElementType>, callback: (value: ElementType, index: number, originalArray: ReadonlyArray<ElementType>) => {
|
|
15
|
+
key: NewKey;
|
|
16
|
+
value: NewValue;
|
|
17
|
+
}): Partial<Record<NewKey, NewValue>>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { getOrSet } from '../object/get-or-set.js';
|
|
2
|
+
import { typedObjectFromEntries } from '../object/object-entries.js';
|
|
3
|
+
/**
|
|
4
|
+
* Polyfill for `Object.groupBy`:
|
|
5
|
+
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/groupBy
|
|
6
|
+
*
|
|
7
|
+
* @category Object:Common
|
|
8
|
+
*/
|
|
9
|
+
export function groupArrayBy(inputArray, callback) {
|
|
10
|
+
return inputArray.reduce((accum, entry, index, originalArray) => {
|
|
11
|
+
const key = callback(entry, index, originalArray);
|
|
12
|
+
const entryArray = getOrSet(accum, key, () => []);
|
|
13
|
+
entryArray.push(entry);
|
|
14
|
+
return accum;
|
|
15
|
+
}, {});
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Like `groupArrayBy` but maps array entries to a single key. Meaning, the resulting object does
|
|
19
|
+
* not have an array of elements (unless the original array itself contains arrays).
|
|
20
|
+
*
|
|
21
|
+
* @category Object:Common
|
|
22
|
+
*/
|
|
23
|
+
export function arrayToObject(inputArray, callback) {
|
|
24
|
+
return typedObjectFromEntries(inputArray.map((entry, index, originalArray) => {
|
|
25
|
+
const { key, value } = callback(entry, index, originalArray);
|
|
26
|
+
return [
|
|
27
|
+
key,
|
|
28
|
+
value,
|
|
29
|
+
];
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function awaitedFilter<OriginalGeneric>(arrayInput: ReadonlyArray<OriginalGeneric>, filterCallback: (arrayElement: OriginalGeneric, index: number, wholeArray: ReadonlyArray<OriginalGeneric>) => Promise<unknown>, options?: {
|
|
2
|
+
/**
|
|
3
|
+
* Each call to the filter callback is blocking, meaning the next one won't start until the
|
|
4
|
+
* current one finishes. By default this is false.
|
|
5
|
+
*/
|
|
6
|
+
blocking?: boolean | undefined;
|
|
7
|
+
}): Promise<OriginalGeneric[]>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { awaitedBlockingMap } from './awaited-map.js';
|
|
2
|
+
export async function awaitedFilter(arrayInput, filterCallback, options) {
|
|
3
|
+
const callbackResults = options?.blocking
|
|
4
|
+
? await awaitedBlockingMap(arrayInput, filterCallback)
|
|
5
|
+
: await Promise.all(arrayInput.map(filterCallback));
|
|
6
|
+
return arrayInput.filter((originalValue, index) => !!callbackResults[index]);
|
|
7
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Acts like calling Array.prototype.forEach in that all elements are executed upon in order, and
|
|
3
|
+
* each execution is blocking. Meaning, the callback won't be called on element 2 until the callback
|
|
4
|
+
* has finished its call on element 1.
|
|
5
|
+
*/
|
|
6
|
+
export declare function awaitedForEach<OriginalGeneric>(input: ReadonlyArray<OriginalGeneric>, callback: (arrayElement: OriginalGeneric, index: number, wholeArray: ReadonlyArray<OriginalGeneric>) => void | PromiseLike<void>): Promise<void>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { awaitedBlockingMap } from './awaited-map.js';
|
|
2
|
+
/**
|
|
3
|
+
* Acts like calling Array.prototype.forEach in that all elements are executed upon in order, and
|
|
4
|
+
* each execution is blocking. Meaning, the callback won't be called on element 2 until the callback
|
|
5
|
+
* has finished its call on element 1.
|
|
6
|
+
*/
|
|
7
|
+
export async function awaitedForEach(input, callback) {
|
|
8
|
+
await awaitedBlockingMap(input, callback);
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function awaitedBlockingMap<OriginalGeneric, MappedGeneric>(input: ReadonlyArray<OriginalGeneric>, callback: (arrayElement: OriginalGeneric, index: number, wholeArray: ReadonlyArray<OriginalGeneric>) => MappedGeneric | PromiseLike<MappedGeneric>): Promise<Awaited<MappedGeneric>[]>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export async function awaitedBlockingMap(input, callback) {
|
|
2
|
+
return await input.reduce(async (accumPromise, currentElement, index, wholeArray) => {
|
|
3
|
+
const accum = await accumPromise;
|
|
4
|
+
const mappedValue = await callback(currentElement, index, wholeArray);
|
|
5
|
+
accum.push(mappedValue);
|
|
6
|
+
return accum;
|
|
7
|
+
}, Promise.resolve([]));
|
|
8
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare function filterOutIndexes<T>(array: ReadonlyArray<T>, indexes: ReadonlyArray<number>): T[];
|
|
2
|
+
export declare function filterMap<ElementType, MappedEntry, TypeGuarded extends MappedEntry>(inputArray: ReadonlyArray<ElementType>, mapCallback: (entry: ElementType, index: number, originalArray: ReadonlyArray<ElementType>) => MappedEntry, filterCallback: (mappedOutput: MappedEntry, originalEntry: ElementType, index: number, originalArray: ReadonlyArray<ElementType>) => mappedOutput is TypeGuarded): TypeGuarded[];
|
|
3
|
+
export declare function filterMap<ElementType, MappedEntry>(inputArray: ReadonlyArray<ElementType>, mapCallback: (entry: ElementType, index: number, originalArray: ReadonlyArray<ElementType>) => MappedEntry, filterCallback: (mappedOutput: MappedEntry, originalEntry: ElementType, index: number, originalArray: ReadonlyArray<ElementType>) => boolean): MappedEntry[];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function filterOutIndexes(array, indexes) {
|
|
2
|
+
return array.filter((_, index) => !indexes.includes(index));
|
|
3
|
+
}
|
|
4
|
+
export function filterMap(inputArray, mapCallback, filterCallback) {
|
|
5
|
+
return inputArray.reduce((accum, entry, index, originalArray) => {
|
|
6
|
+
const mapOutput = mapCallback(entry, index, originalArray);
|
|
7
|
+
const filterOutput = filterCallback(mapOutput, entry, index, originalArray);
|
|
8
|
+
if (filterOutput) {
|
|
9
|
+
accum.push(mapOutput);
|
|
10
|
+
}
|
|
11
|
+
return accum;
|
|
12
|
+
}, []);
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function repeatArray<T>(repeatCount: number, array: T[]): T[];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { randomString } from '../random/random-string.js';
|
|
2
|
+
/** Creates a new array which is a shuffled version of the input array. */
|
|
3
|
+
export function shuffleArray(input) {
|
|
4
|
+
return input
|
|
5
|
+
.map((value) => {
|
|
6
|
+
return { value, sort: randomString() };
|
|
7
|
+
})
|
|
8
|
+
.sort((a, b) => a.sort.localeCompare(b.sort))
|
|
9
|
+
.map(({ value }) => value);
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function trimArrayStrings(input: ReadonlyArray<string>): string[];
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { type Falsy, type Truthy } from '@augment-vir/assert';
|
|
2
|
+
export declare function ifTruthy<const InputType, IfTruthyType, IfFalsyType>(checkThis: InputType, ifTruthyCallback: (truthyInput: Truthy<InputType>) => IfTruthyType, ifFalsyCallback: (truthyInput: Falsy<InputType>) => IfFalsyType): IfTruthyType | IfFalsyType;
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
return !!input;
|
|
3
|
-
}
|
|
4
|
-
export function isFalsy(input) {
|
|
5
|
-
return !input;
|
|
6
|
-
}
|
|
1
|
+
import { check } from '@augment-vir/assert';
|
|
7
2
|
export function ifTruthy(checkThis, ifTruthyCallback, ifFalsyCallback) {
|
|
8
|
-
if (isTruthy(checkThis)) {
|
|
3
|
+
if (check.isTruthy(checkThis)) {
|
|
9
4
|
return ifTruthyCallback(checkThis);
|
|
10
5
|
}
|
|
11
6
|
else {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@augment-vir/core';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@augment-vir/core';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { check } from '@augment-vir/assert';
|
|
2
|
+
import { extractErrorMessage } from '@augment-vir/core';
|
|
3
|
+
export function combineErrors(rawErrors) {
|
|
4
|
+
const errors = rawErrors.filter((error) => error);
|
|
5
|
+
if (!check.isLengthAtLeast(errors, 1)) {
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
if (errors.length === 1) {
|
|
9
|
+
return errors[0];
|
|
10
|
+
}
|
|
11
|
+
return new Error(errors.map((error) => extractErrorMessage(error).trim()).join('\n'));
|
|
12
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { MaybePromise } from '@augment-vir/core';
|
|
2
|
+
/**
|
|
3
|
+
* Call a function asynchronously without interrupting current synchronous execution, even if the
|
|
4
|
+
* function was originally synchronous.
|
|
5
|
+
*/
|
|
6
|
+
export declare function callAsynchronously<T>(callback: () => MaybePromise<T>): Promise<T>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { MaybePromise } from '@augment-vir/core';
|
|
2
|
+
export declare function callWithRetries<const T>(maxRetries: number, callback: () => Promise<T>): Promise<T>;
|
|
3
|
+
export declare function callWithRetries<const T>(maxRetries: number, callback: () => T): T;
|
|
4
|
+
export declare function callWithRetries<const T>(maxRetries: number, callback: () => MaybePromise<T>): MaybePromise<T>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ensureErrorAndPrependMessage } from '@augment-vir/core';
|
|
2
|
+
export function callWithRetries(maxRetries, callback) {
|
|
3
|
+
try {
|
|
4
|
+
const result = callback();
|
|
5
|
+
if (result instanceof Promise) {
|
|
6
|
+
return result.catch((error) => {
|
|
7
|
+
if (maxRetries <= 1) {
|
|
8
|
+
throw ensureErrorAndPrependMessage(error, 'Retry max reached');
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
return callWithRetries(maxRetries - 1, callback);
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
if (maxRetries <= 1) {
|
|
21
|
+
throw ensureErrorAndPrependMessage(error, 'Retry max reached');
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
return callWithRetries(maxRetries - 1, callback);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { MaybePromise } from '@augment-vir/core';
|
|
2
|
+
import { AnyDuration } from '@date-vir/duration';
|
|
3
|
+
export declare enum DebounceStyle {
|
|
4
|
+
/**
|
|
5
|
+
* Fires on the first call, then waits the given amount of milliseconds until a subsequent call
|
|
6
|
+
* can be made.
|
|
7
|
+
*/
|
|
8
|
+
FirstThenWait = "first-then-wait",
|
|
9
|
+
/**
|
|
10
|
+
* Waits the given amount of milliseconds after the first call and then fires the latest
|
|
11
|
+
* assigned callback.
|
|
12
|
+
*/
|
|
13
|
+
AfterWait = "after-wait"
|
|
14
|
+
}
|
|
15
|
+
export declare class Debounce {
|
|
16
|
+
debounceStyle: DebounceStyle;
|
|
17
|
+
debounceDuration: AnyDuration;
|
|
18
|
+
nextCallTimestamp: number;
|
|
19
|
+
callback: (() => MaybePromise<void>) | undefined;
|
|
20
|
+
constructor(debounceStyle: DebounceStyle, debounceDuration: AnyDuration, callback?: typeof this.callback | undefined);
|
|
21
|
+
execute(callback?: typeof this.callback | undefined): void;
|
|
22
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { convertDuration, DurationUnit } from '@date-vir/duration';
|
|
2
|
+
export var DebounceStyle;
|
|
3
|
+
(function (DebounceStyle) {
|
|
4
|
+
/**
|
|
5
|
+
* Fires on the first call, then waits the given amount of milliseconds until a subsequent call
|
|
6
|
+
* can be made.
|
|
7
|
+
*/
|
|
8
|
+
DebounceStyle["FirstThenWait"] = "first-then-wait";
|
|
9
|
+
/**
|
|
10
|
+
* Waits the given amount of milliseconds after the first call and then fires the latest
|
|
11
|
+
* assigned callback.
|
|
12
|
+
*/
|
|
13
|
+
DebounceStyle["AfterWait"] = "after-wait";
|
|
14
|
+
})(DebounceStyle || (DebounceStyle = {}));
|
|
15
|
+
export class Debounce {
|
|
16
|
+
debounceStyle;
|
|
17
|
+
debounceDuration;
|
|
18
|
+
nextCallTimestamp = 0;
|
|
19
|
+
callback;
|
|
20
|
+
constructor(debounceStyle, debounceDuration, callback) {
|
|
21
|
+
this.debounceStyle = debounceStyle;
|
|
22
|
+
this.debounceDuration = debounceDuration;
|
|
23
|
+
if (callback) {
|
|
24
|
+
this.callback = callback;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
execute(callback) {
|
|
28
|
+
if (callback) {
|
|
29
|
+
this.callback = callback;
|
|
30
|
+
}
|
|
31
|
+
else if (!this.callback) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const now = Date.now();
|
|
35
|
+
if (this.nextCallTimestamp > now) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (this.debounceStyle === DebounceStyle.FirstThenWait) {
|
|
39
|
+
void this.callback();
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
setTimeout(() => {
|
|
43
|
+
/** Use whatever the latest latestCallback is. */
|
|
44
|
+
void this.callback?.();
|
|
45
|
+
}, this.debounceDuration.milliseconds);
|
|
46
|
+
}
|
|
47
|
+
this.nextCallTimestamp =
|
|
48
|
+
now + convertDuration(this.debounceDuration, DurationUnit.Milliseconds).milliseconds;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Duration, DurationUnit } from '@date-vir/duration';
|
|
2
|
+
export type ExecutionDuration = Duration<DurationUnit.Milliseconds>;
|
|
3
|
+
/**
|
|
4
|
+
* Measures how long (in milliseconds) the given callback takes to run to completion. Automatically
|
|
5
|
+
* switches to async mode and awaits callbacks if they return a promise (otherwise this function is
|
|
6
|
+
* purely synchronous).
|
|
7
|
+
*/
|
|
8
|
+
export declare function measureExecutionDuration<T>(callback: () => T): T extends Promise<any> ? Promise<ExecutionDuration> : ExecutionDuration;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { ensureError } from '@augment-vir/core';
|
|
1
2
|
/**
|
|
2
3
|
* Measures how long (in milliseconds) the given callback takes to run to completion. Automatically
|
|
3
4
|
* switches to async mode and awaits callbacks if they return a promise (otherwise this function is
|
|
4
5
|
* purely synchronous).
|
|
5
6
|
*/
|
|
6
|
-
export function
|
|
7
|
+
export function measureExecutionDuration(callback) {
|
|
7
8
|
const startTime = Date.now();
|
|
8
9
|
const result = callback();
|
|
9
10
|
if (result instanceof Promise) {
|
|
@@ -11,21 +12,15 @@ export function timeCallback(callback) {
|
|
|
11
12
|
try {
|
|
12
13
|
await result;
|
|
13
14
|
const endTime = Date.now();
|
|
14
|
-
resolve(endTime - startTime);
|
|
15
|
+
resolve({ milliseconds: endTime - startTime });
|
|
15
16
|
}
|
|
16
17
|
catch (caught) {
|
|
17
|
-
reject(caught);
|
|
18
|
+
reject(ensureError(caught));
|
|
18
19
|
}
|
|
19
20
|
});
|
|
20
21
|
}
|
|
21
22
|
const endTime = Date.now();
|
|
22
|
-
return
|
|
23
|
+
return {
|
|
24
|
+
milliseconds: endTime - startTime,
|
|
25
|
+
};
|
|
23
26
|
}
|
|
24
|
-
/**
|
|
25
|
-
* Measures how long (in milliseconds) the given callback takes to run to completion. Automatically
|
|
26
|
-
* switches to async mode and awaits callbacks if they return a promise (otherwise this function is
|
|
27
|
-
* purely synchronous).
|
|
28
|
-
*
|
|
29
|
-
* Alias of timeCallback.
|
|
30
|
-
*/
|
|
31
|
-
export const measureCallbackDuration = timeCallback;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { NoInputsFunction } from '
|
|
2
|
-
|
|
3
|
-
export type WrapInTryOptions<FallbackValue> = PartialAndUndefined<{
|
|
1
|
+
import { type NoInputsFunction, type PartialWithUndefined } from '@augment-vir/core';
|
|
2
|
+
export type WrapInTryOptions<FallbackValue> = PartialWithUndefined<{
|
|
4
3
|
/**
|
|
5
4
|
* A callback that is passed the error. The output of this callback is returned by `wrapInTry`.
|
|
6
5
|
* This takes precedence over the other two options.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ensureError } from '
|
|
1
|
+
import { check } from '@augment-vir/assert';
|
|
2
|
+
import { ensureError, } from '@augment-vir/core';
|
|
3
3
|
export function wrapInTry(callback, options = {}) {
|
|
4
4
|
try {
|
|
5
5
|
const value = callback();
|
|
@@ -8,7 +8,7 @@ export function wrapInTry(callback, options = {}) {
|
|
|
8
8
|
if (options.handleError) {
|
|
9
9
|
return options.handleError(error);
|
|
10
10
|
}
|
|
11
|
-
else if (
|
|
11
|
+
else if (check.hasKey(options, 'fallbackValue')) {
|
|
12
12
|
return options.fallbackValue;
|
|
13
13
|
}
|
|
14
14
|
else {
|
|
@@ -24,7 +24,7 @@ export function wrapInTry(callback, options = {}) {
|
|
|
24
24
|
if (options.handleError) {
|
|
25
25
|
return options.handleError(error);
|
|
26
26
|
}
|
|
27
|
-
else if (
|
|
27
|
+
else if (check.hasKey(options, 'fallbackValue')) {
|
|
28
28
|
return options.fallbackValue;
|
|
29
29
|
}
|
|
30
30
|
else {
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { JsonCompatibleArray, JsonCompatibleObject, JsonCompatibleValue } from './json-compatible.js';
|
|
2
|
+
export declare function appendJson(...entries: ReadonlyArray<JsonCompatibleObject | undefined>): JsonCompatibleObject;
|
|
3
|
+
export declare function appendJson(...entries: ReadonlyArray<JsonCompatibleArray | undefined>): JsonCompatibleArray;
|
|
4
|
+
export declare function appendJson(...entries: ReadonlyArray<JsonCompatibleObject | JsonCompatibleArray | undefined>): JsonCompatibleObject | JsonCompatibleArray;
|
|
5
|
+
export declare function appendJson(...entries: ReadonlyArray<JsonCompatibleValue | undefined>): JsonCompatibleObject | JsonCompatibleArray;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { check } from '@augment-vir/assert';
|
|
2
|
+
import { copyThroughJson } from './copy-through-json.js';
|
|
3
|
+
export function appendJson(...rawEntries) {
|
|
4
|
+
const entries = rawEntries.filter(check.isTruthy);
|
|
5
|
+
if (!check.isLengthAtLeast(entries, 1)) {
|
|
6
|
+
return {};
|
|
7
|
+
}
|
|
8
|
+
const firstEntry = copyThroughJson(entries[0]);
|
|
9
|
+
const combinedData = typeof firstEntry === 'object'
|
|
10
|
+
? firstEntry
|
|
11
|
+
: [firstEntry];
|
|
12
|
+
entries.slice(1).forEach((entry) => {
|
|
13
|
+
if (check.isArray(combinedData)) {
|
|
14
|
+
if (check.isArray(entry)) {
|
|
15
|
+
combinedData.push(...entry);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
combinedData.push(entry);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
Object.assign(combinedData, entry);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return combinedData;
|
|
26
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** The input here must be serializable otherwise the output will not match the input. */
|
|
2
|
+
export function copyThroughJson(input) {
|
|
3
|
+
try {
|
|
4
|
+
return JSON.parse(JSON.stringify(input));
|
|
5
|
+
/* node:coverage ignore next 4 */
|
|
6
|
+
}
|
|
7
|
+
catch (error) {
|
|
8
|
+
console.error(`Failed to JSON copy for`, input);
|
|
9
|
+
throw error;
|
|
10
|
+
}
|
|
11
|
+
}
|