@elyukai/utils 0.1.2
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/AUTHORS +1 -0
- package/CHANGELOG.md +46 -0
- package/LICENSE +373 -0
- package/README.md +1 -0
- package/dist/array/filters.d.ts +14 -0
- package/dist/array/filters.js +24 -0
- package/dist/array/generators.d.ts +9 -0
- package/dist/array/generators.js +13 -0
- package/dist/array/groups.d.ts +24 -0
- package/dist/array/groups.js +45 -0
- package/dist/array/modify.d.ts +21 -0
- package/dist/array/modify.js +57 -0
- package/dist/array/nonEmpty.d.ts +23 -0
- package/dist/array/nonEmpty.js +15 -0
- package/dist/array/reductions.d.ts +39 -0
- package/dist/array/reductions.js +58 -0
- package/dist/array/sets.d.ts +17 -0
- package/dist/array/sets.js +19 -0
- package/dist/array.d.ts +4 -0
- package/dist/array.js +5 -0
- package/dist/async.d.ts +11 -0
- package/dist/async.js +11 -0
- package/dist/classList.d.ts +5 -0
- package/dist/classList.js +17 -0
- package/dist/compare.d.ts +44 -0
- package/dist/compare.js +73 -0
- package/dist/date.d.ts +5 -0
- package/dist/date.js +5 -0
- package/dist/dictionary/native.d.ts +116 -0
- package/dist/dictionary/native.js +142 -0
- package/dist/dictionary.d.ts +115 -0
- package/dist/dictionary.js +178 -0
- package/dist/equality.d.ts +44 -0
- package/dist/equality.js +53 -0
- package/dist/function.d.ts +48 -0
- package/dist/function.js +52 -0
- package/dist/lazy.d.ts +16 -0
- package/dist/lazy.js +32 -0
- package/dist/math.d.ts +47 -0
- package/dist/math.js +56 -0
- package/dist/maybe.d.ts +51 -0
- package/dist/maybe.js +36 -0
- package/dist/nullable.d.ts +50 -0
- package/dist/nullable.js +35 -0
- package/dist/number.d.ts +16 -0
- package/dist/number.js +16 -0
- package/dist/object.d.ts +40 -0
- package/dist/object.js +58 -0
- package/dist/ordering.d.ts +30 -0
- package/dist/ordering.js +46 -0
- package/dist/range.d.ts +37 -0
- package/dist/range.js +41 -0
- package/dist/regex.d.ts +28 -0
- package/dist/regex.js +35 -0
- package/dist/result.d.ts +54 -0
- package/dist/result.js +45 -0
- package/dist/roman.d.ts +4 -0
- package/dist/roman.js +47 -0
- package/dist/string/number.d.ts +31 -0
- package/dist/string/number.js +40 -0
- package/dist/string/regex.d.ts +28 -0
- package/dist/string/regex.js +38 -0
- package/dist/string.d.ts +32 -0
- package/dist/string.js +96 -0
- package/dist/typeSafety.d.ts +38 -0
- package/dist/typeSafety.js +33 -0
- package/package.json +46 -0
package/AUTHORS
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Lukas Obermann <lukas.obermann@icloud.com>
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
|
|
4
|
+
|
|
5
|
+
## [0.1.2](https://github.com/elyukai/ts-utils/compare/v0.1.1...v0.1.2) (2026-01-24)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* slow types ([e16e7a8](https://github.com/elyukai/ts-utils/commit/e16e7a8092d0a9111744916e78799ac010b0175e))
|
|
11
|
+
|
|
12
|
+
## [0.1.1](https://github.com/elyukai/ts-utils/compare/v0.1.0...v0.1.1) (2026-01-24)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* add function to identify duplicates in arrays ([8b49fff](https://github.com/elyukai/ts-utils/commit/8b49fffeaabe30dedb0015f2f94ae80737c4b210))
|
|
18
|
+
|
|
19
|
+
## 0.1.0 (2026-01-24)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Features
|
|
23
|
+
|
|
24
|
+
* add async wait function ([77ce70c](https://github.com/elyukai/ts-utils/commit/77ce70c5234d5181afb82b2a3cf558f9a8733ddc))
|
|
25
|
+
* add classlist function ([cb552d2](https://github.com/elyukai/ts-utils/commit/cb552d26f5277e1ebc5358adbd1db0d8d6ea48c2))
|
|
26
|
+
* add dictionary ([38b1af8](https://github.com/elyukai/ts-utils/commit/38b1af8c553e7ed7772e7b6eb2e7f6ff724016d7))
|
|
27
|
+
* add functions for equality checks ([c86aa71](https://github.com/elyukai/ts-utils/commit/c86aa71dfab1be5ad03c69f72a6e2beb4546b28e))
|
|
28
|
+
* add functions for ordering ([6ebe13b](https://github.com/elyukai/ts-utils/commit/6ebe13b74c3361ec5c21e50cc4c80e69826c839e))
|
|
29
|
+
* add functions for working with arrays ([6cbd038](https://github.com/elyukai/ts-utils/commit/6cbd038f085f87faa4b56109de6ff136aeb35aef))
|
|
30
|
+
* add functions for working with numbers ([8792558](https://github.com/elyukai/ts-utils/commit/8792558f9903f05e9e3688185d6cf63d343b9d85))
|
|
31
|
+
* add lazy class ([edb27d2](https://github.com/elyukai/ts-utils/commit/edb27d29c9c7ab0b131f19f6cd40081b91c2a321))
|
|
32
|
+
* add nullable functions ([010645f](https://github.com/elyukai/ts-utils/commit/010645ff66d74a094edebe4c5d7850d0d8d9b896))
|
|
33
|
+
* add object functions ([67deaac](https://github.com/elyukai/ts-utils/commit/67deaac619227bee8d88137861c5104ea0f6f4d3))
|
|
34
|
+
* add result and maybe types ([1b6987f](https://github.com/elyukai/ts-utils/commit/1b6987fdfa9e6e64eee55942cd75223d611b2753))
|
|
35
|
+
* add roman numeral converter ([4dbc788](https://github.com/elyukai/ts-utils/commit/4dbc7888bfc851f1b18e6cf5393920acecbc1640))
|
|
36
|
+
* add string functions ([5f4f190](https://github.com/elyukai/ts-utils/commit/5f4f190d73b7a2bb866726b995c4e8dc7159b968))
|
|
37
|
+
* add string regex checks ([ba7cfe1](https://github.com/elyukai/ts-utils/commit/ba7cfe11c102e3169211a7f573744682c0bdc7e6))
|
|
38
|
+
* add type safety functions ([5db4af4](https://github.com/elyukai/ts-utils/commit/5db4af4006d884c7bb4f92b851d51678492ce9a2))
|
|
39
|
+
* functions for working with general functions and predicates ([f6fb48a](https://github.com/elyukai/ts-utils/commit/f6fb48a6e744dc74355630fccfddae522d894ae7))
|
|
40
|
+
* functions for working with ranges ([e40d20f](https://github.com/elyukai/ts-utils/commit/e40d20f37554a32464ed1fbce86fe5fcdeb8077b))
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
### Bug Fixes
|
|
44
|
+
|
|
45
|
+
* slow types ([dcb096a](https://github.com/elyukai/ts-utils/commit/dcb096a5835ad07dbdb4c74bfcbdc9d97f51f329))
|
|
46
|
+
* slow types ([261d56a](https://github.com/elyukai/ts-utils/commit/261d56abcb6ab35de6b92185dea0ddc4b6313500))
|
package/LICENSE
ADDED
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
Mozilla Public License Version 2.0
|
|
2
|
+
==================================
|
|
3
|
+
|
|
4
|
+
1. Definitions
|
|
5
|
+
--------------
|
|
6
|
+
|
|
7
|
+
1.1. "Contributor"
|
|
8
|
+
means each individual or legal entity that creates, contributes to
|
|
9
|
+
the creation of, or owns Covered Software.
|
|
10
|
+
|
|
11
|
+
1.2. "Contributor Version"
|
|
12
|
+
means the combination of the Contributions of others (if any) used
|
|
13
|
+
by a Contributor and that particular Contributor's Contribution.
|
|
14
|
+
|
|
15
|
+
1.3. "Contribution"
|
|
16
|
+
means Covered Software of a particular Contributor.
|
|
17
|
+
|
|
18
|
+
1.4. "Covered Software"
|
|
19
|
+
means Source Code Form to which the initial Contributor has attached
|
|
20
|
+
the notice in Exhibit A, the Executable Form of such Source Code
|
|
21
|
+
Form, and Modifications of such Source Code Form, in each case
|
|
22
|
+
including portions thereof.
|
|
23
|
+
|
|
24
|
+
1.5. "Incompatible With Secondary Licenses"
|
|
25
|
+
means
|
|
26
|
+
|
|
27
|
+
(a) that the initial Contributor has attached the notice described
|
|
28
|
+
in Exhibit B to the Covered Software; or
|
|
29
|
+
|
|
30
|
+
(b) that the Covered Software was made available under the terms of
|
|
31
|
+
version 1.1 or earlier of the License, but not also under the
|
|
32
|
+
terms of a Secondary License.
|
|
33
|
+
|
|
34
|
+
1.6. "Executable Form"
|
|
35
|
+
means any form of the work other than Source Code Form.
|
|
36
|
+
|
|
37
|
+
1.7. "Larger Work"
|
|
38
|
+
means a work that combines Covered Software with other material, in
|
|
39
|
+
a separate file or files, that is not Covered Software.
|
|
40
|
+
|
|
41
|
+
1.8. "License"
|
|
42
|
+
means this document.
|
|
43
|
+
|
|
44
|
+
1.9. "Licensable"
|
|
45
|
+
means having the right to grant, to the maximum extent possible,
|
|
46
|
+
whether at the time of the initial grant or subsequently, any and
|
|
47
|
+
all of the rights conveyed by this License.
|
|
48
|
+
|
|
49
|
+
1.10. "Modifications"
|
|
50
|
+
means any of the following:
|
|
51
|
+
|
|
52
|
+
(a) any file in Source Code Form that results from an addition to,
|
|
53
|
+
deletion from, or modification of the contents of Covered
|
|
54
|
+
Software; or
|
|
55
|
+
|
|
56
|
+
(b) any new file in Source Code Form that contains any Covered
|
|
57
|
+
Software.
|
|
58
|
+
|
|
59
|
+
1.11. "Patent Claims" of a Contributor
|
|
60
|
+
means any patent claim(s), including without limitation, method,
|
|
61
|
+
process, and apparatus claims, in any patent Licensable by such
|
|
62
|
+
Contributor that would be infringed, but for the grant of the
|
|
63
|
+
License, by the making, using, selling, offering for sale, having
|
|
64
|
+
made, import, or transfer of either its Contributions or its
|
|
65
|
+
Contributor Version.
|
|
66
|
+
|
|
67
|
+
1.12. "Secondary License"
|
|
68
|
+
means either the GNU General Public License, Version 2.0, the GNU
|
|
69
|
+
Lesser General Public License, Version 2.1, the GNU Affero General
|
|
70
|
+
Public License, Version 3.0, or any later versions of those
|
|
71
|
+
licenses.
|
|
72
|
+
|
|
73
|
+
1.13. "Source Code Form"
|
|
74
|
+
means the form of the work preferred for making modifications.
|
|
75
|
+
|
|
76
|
+
1.14. "You" (or "Your")
|
|
77
|
+
means an individual or a legal entity exercising rights under this
|
|
78
|
+
License. For legal entities, "You" includes any entity that
|
|
79
|
+
controls, is controlled by, or is under common control with You. For
|
|
80
|
+
purposes of this definition, "control" means (a) the power, direct
|
|
81
|
+
or indirect, to cause the direction or management of such entity,
|
|
82
|
+
whether by contract or otherwise, or (b) ownership of more than
|
|
83
|
+
fifty percent (50%) of the outstanding shares or beneficial
|
|
84
|
+
ownership of such entity.
|
|
85
|
+
|
|
86
|
+
2. License Grants and Conditions
|
|
87
|
+
--------------------------------
|
|
88
|
+
|
|
89
|
+
2.1. Grants
|
|
90
|
+
|
|
91
|
+
Each Contributor hereby grants You a world-wide, royalty-free,
|
|
92
|
+
non-exclusive license:
|
|
93
|
+
|
|
94
|
+
(a) under intellectual property rights (other than patent or trademark)
|
|
95
|
+
Licensable by such Contributor to use, reproduce, make available,
|
|
96
|
+
modify, display, perform, distribute, and otherwise exploit its
|
|
97
|
+
Contributions, either on an unmodified basis, with Modifications, or
|
|
98
|
+
as part of a Larger Work; and
|
|
99
|
+
|
|
100
|
+
(b) under Patent Claims of such Contributor to make, use, sell, offer
|
|
101
|
+
for sale, have made, import, and otherwise transfer either its
|
|
102
|
+
Contributions or its Contributor Version.
|
|
103
|
+
|
|
104
|
+
2.2. Effective Date
|
|
105
|
+
|
|
106
|
+
The licenses granted in Section 2.1 with respect to any Contribution
|
|
107
|
+
become effective for each Contribution on the date the Contributor first
|
|
108
|
+
distributes such Contribution.
|
|
109
|
+
|
|
110
|
+
2.3. Limitations on Grant Scope
|
|
111
|
+
|
|
112
|
+
The licenses granted in this Section 2 are the only rights granted under
|
|
113
|
+
this License. No additional rights or licenses will be implied from the
|
|
114
|
+
distribution or licensing of Covered Software under this License.
|
|
115
|
+
Notwithstanding Section 2.1(b) above, no patent license is granted by a
|
|
116
|
+
Contributor:
|
|
117
|
+
|
|
118
|
+
(a) for any code that a Contributor has removed from Covered Software;
|
|
119
|
+
or
|
|
120
|
+
|
|
121
|
+
(b) for infringements caused by: (i) Your and any other third party's
|
|
122
|
+
modifications of Covered Software, or (ii) the combination of its
|
|
123
|
+
Contributions with other software (except as part of its Contributor
|
|
124
|
+
Version); or
|
|
125
|
+
|
|
126
|
+
(c) under Patent Claims infringed by Covered Software in the absence of
|
|
127
|
+
its Contributions.
|
|
128
|
+
|
|
129
|
+
This License does not grant any rights in the trademarks, service marks,
|
|
130
|
+
or logos of any Contributor (except as may be necessary to comply with
|
|
131
|
+
the notice requirements in Section 3.4).
|
|
132
|
+
|
|
133
|
+
2.4. Subsequent Licenses
|
|
134
|
+
|
|
135
|
+
No Contributor makes additional grants as a result of Your choice to
|
|
136
|
+
distribute the Covered Software under a subsequent version of this
|
|
137
|
+
License (see Section 10.2) or under the terms of a Secondary License (if
|
|
138
|
+
permitted under the terms of Section 3.3).
|
|
139
|
+
|
|
140
|
+
2.5. Representation
|
|
141
|
+
|
|
142
|
+
Each Contributor represents that the Contributor believes its
|
|
143
|
+
Contributions are its original creation(s) or it has sufficient rights
|
|
144
|
+
to grant the rights to its Contributions conveyed by this License.
|
|
145
|
+
|
|
146
|
+
2.6. Fair Use
|
|
147
|
+
|
|
148
|
+
This License is not intended to limit any rights You have under
|
|
149
|
+
applicable copyright doctrines of fair use, fair dealing, or other
|
|
150
|
+
equivalents.
|
|
151
|
+
|
|
152
|
+
2.7. Conditions
|
|
153
|
+
|
|
154
|
+
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
|
|
155
|
+
in Section 2.1.
|
|
156
|
+
|
|
157
|
+
3. Responsibilities
|
|
158
|
+
-------------------
|
|
159
|
+
|
|
160
|
+
3.1. Distribution of Source Form
|
|
161
|
+
|
|
162
|
+
All distribution of Covered Software in Source Code Form, including any
|
|
163
|
+
Modifications that You create or to which You contribute, must be under
|
|
164
|
+
the terms of this License. You must inform recipients that the Source
|
|
165
|
+
Code Form of the Covered Software is governed by the terms of this
|
|
166
|
+
License, and how they can obtain a copy of this License. You may not
|
|
167
|
+
attempt to alter or restrict the recipients' rights in the Source Code
|
|
168
|
+
Form.
|
|
169
|
+
|
|
170
|
+
3.2. Distribution of Executable Form
|
|
171
|
+
|
|
172
|
+
If You distribute Covered Software in Executable Form then:
|
|
173
|
+
|
|
174
|
+
(a) such Covered Software must also be made available in Source Code
|
|
175
|
+
Form, as described in Section 3.1, and You must inform recipients of
|
|
176
|
+
the Executable Form how they can obtain a copy of such Source Code
|
|
177
|
+
Form by reasonable means in a timely manner, at a charge no more
|
|
178
|
+
than the cost of distribution to the recipient; and
|
|
179
|
+
|
|
180
|
+
(b) You may distribute such Executable Form under the terms of this
|
|
181
|
+
License, or sublicense it under different terms, provided that the
|
|
182
|
+
license for the Executable Form does not attempt to limit or alter
|
|
183
|
+
the recipients' rights in the Source Code Form under this License.
|
|
184
|
+
|
|
185
|
+
3.3. Distribution of a Larger Work
|
|
186
|
+
|
|
187
|
+
You may create and distribute a Larger Work under terms of Your choice,
|
|
188
|
+
provided that You also comply with the requirements of this License for
|
|
189
|
+
the Covered Software. If the Larger Work is a combination of Covered
|
|
190
|
+
Software with a work governed by one or more Secondary Licenses, and the
|
|
191
|
+
Covered Software is not Incompatible With Secondary Licenses, this
|
|
192
|
+
License permits You to additionally distribute such Covered Software
|
|
193
|
+
under the terms of such Secondary License(s), so that the recipient of
|
|
194
|
+
the Larger Work may, at their option, further distribute the Covered
|
|
195
|
+
Software under the terms of either this License or such Secondary
|
|
196
|
+
License(s).
|
|
197
|
+
|
|
198
|
+
3.4. Notices
|
|
199
|
+
|
|
200
|
+
You may not remove or alter the substance of any license notices
|
|
201
|
+
(including copyright notices, patent notices, disclaimers of warranty,
|
|
202
|
+
or limitations of liability) contained within the Source Code Form of
|
|
203
|
+
the Covered Software, except that You may alter any license notices to
|
|
204
|
+
the extent required to remedy known factual inaccuracies.
|
|
205
|
+
|
|
206
|
+
3.5. Application of Additional Terms
|
|
207
|
+
|
|
208
|
+
You may choose to offer, and to charge a fee for, warranty, support,
|
|
209
|
+
indemnity or liability obligations to one or more recipients of Covered
|
|
210
|
+
Software. However, You may do so only on Your own behalf, and not on
|
|
211
|
+
behalf of any Contributor. You must make it absolutely clear that any
|
|
212
|
+
such warranty, support, indemnity, or liability obligation is offered by
|
|
213
|
+
You alone, and You hereby agree to indemnify every Contributor for any
|
|
214
|
+
liability incurred by such Contributor as a result of warranty, support,
|
|
215
|
+
indemnity or liability terms You offer. You may include additional
|
|
216
|
+
disclaimers of warranty and limitations of liability specific to any
|
|
217
|
+
jurisdiction.
|
|
218
|
+
|
|
219
|
+
4. Inability to Comply Due to Statute or Regulation
|
|
220
|
+
---------------------------------------------------
|
|
221
|
+
|
|
222
|
+
If it is impossible for You to comply with any of the terms of this
|
|
223
|
+
License with respect to some or all of the Covered Software due to
|
|
224
|
+
statute, judicial order, or regulation then You must: (a) comply with
|
|
225
|
+
the terms of this License to the maximum extent possible; and (b)
|
|
226
|
+
describe the limitations and the code they affect. Such description must
|
|
227
|
+
be placed in a text file included with all distributions of the Covered
|
|
228
|
+
Software under this License. Except to the extent prohibited by statute
|
|
229
|
+
or regulation, such description must be sufficiently detailed for a
|
|
230
|
+
recipient of ordinary skill to be able to understand it.
|
|
231
|
+
|
|
232
|
+
5. Termination
|
|
233
|
+
--------------
|
|
234
|
+
|
|
235
|
+
5.1. The rights granted under this License will terminate automatically
|
|
236
|
+
if You fail to comply with any of its terms. However, if You become
|
|
237
|
+
compliant, then the rights granted under this License from a particular
|
|
238
|
+
Contributor are reinstated (a) provisionally, unless and until such
|
|
239
|
+
Contributor explicitly and finally terminates Your grants, and (b) on an
|
|
240
|
+
ongoing basis, if such Contributor fails to notify You of the
|
|
241
|
+
non-compliance by some reasonable means prior to 60 days after You have
|
|
242
|
+
come back into compliance. Moreover, Your grants from a particular
|
|
243
|
+
Contributor are reinstated on an ongoing basis if such Contributor
|
|
244
|
+
notifies You of the non-compliance by some reasonable means, this is the
|
|
245
|
+
first time You have received notice of non-compliance with this License
|
|
246
|
+
from such Contributor, and You become compliant prior to 30 days after
|
|
247
|
+
Your receipt of the notice.
|
|
248
|
+
|
|
249
|
+
5.2. If You initiate litigation against any entity by asserting a patent
|
|
250
|
+
infringement claim (excluding declaratory judgment actions,
|
|
251
|
+
counter-claims, and cross-claims) alleging that a Contributor Version
|
|
252
|
+
directly or indirectly infringes any patent, then the rights granted to
|
|
253
|
+
You by any and all Contributors for the Covered Software under Section
|
|
254
|
+
2.1 of this License shall terminate.
|
|
255
|
+
|
|
256
|
+
5.3. In the event of termination under Sections 5.1 or 5.2 above, all
|
|
257
|
+
end user license agreements (excluding distributors and resellers) which
|
|
258
|
+
have been validly granted by You or Your distributors under this License
|
|
259
|
+
prior to termination shall survive termination.
|
|
260
|
+
|
|
261
|
+
************************************************************************
|
|
262
|
+
* *
|
|
263
|
+
* 6. Disclaimer of Warranty *
|
|
264
|
+
* ------------------------- *
|
|
265
|
+
* *
|
|
266
|
+
* Covered Software is provided under this License on an "as is" *
|
|
267
|
+
* basis, without warranty of any kind, either expressed, implied, or *
|
|
268
|
+
* statutory, including, without limitation, warranties that the *
|
|
269
|
+
* Covered Software is free of defects, merchantable, fit for a *
|
|
270
|
+
* particular purpose or non-infringing. The entire risk as to the *
|
|
271
|
+
* quality and performance of the Covered Software is with You. *
|
|
272
|
+
* Should any Covered Software prove defective in any respect, You *
|
|
273
|
+
* (not any Contributor) assume the cost of any necessary servicing, *
|
|
274
|
+
* repair, or correction. This disclaimer of warranty constitutes an *
|
|
275
|
+
* essential part of this License. No use of any Covered Software is *
|
|
276
|
+
* authorized under this License except under this disclaimer. *
|
|
277
|
+
* *
|
|
278
|
+
************************************************************************
|
|
279
|
+
|
|
280
|
+
************************************************************************
|
|
281
|
+
* *
|
|
282
|
+
* 7. Limitation of Liability *
|
|
283
|
+
* -------------------------- *
|
|
284
|
+
* *
|
|
285
|
+
* Under no circumstances and under no legal theory, whether tort *
|
|
286
|
+
* (including negligence), contract, or otherwise, shall any *
|
|
287
|
+
* Contributor, or anyone who distributes Covered Software as *
|
|
288
|
+
* permitted above, be liable to You for any direct, indirect, *
|
|
289
|
+
* special, incidental, or consequential damages of any character *
|
|
290
|
+
* including, without limitation, damages for lost profits, loss of *
|
|
291
|
+
* goodwill, work stoppage, computer failure or malfunction, or any *
|
|
292
|
+
* and all other commercial damages or losses, even if such party *
|
|
293
|
+
* shall have been informed of the possibility of such damages. This *
|
|
294
|
+
* limitation of liability shall not apply to liability for death or *
|
|
295
|
+
* personal injury resulting from such party's negligence to the *
|
|
296
|
+
* extent applicable law prohibits such limitation. Some *
|
|
297
|
+
* jurisdictions do not allow the exclusion or limitation of *
|
|
298
|
+
* incidental or consequential damages, so this exclusion and *
|
|
299
|
+
* limitation may not apply to You. *
|
|
300
|
+
* *
|
|
301
|
+
************************************************************************
|
|
302
|
+
|
|
303
|
+
8. Litigation
|
|
304
|
+
-------------
|
|
305
|
+
|
|
306
|
+
Any litigation relating to this License may be brought only in the
|
|
307
|
+
courts of a jurisdiction where the defendant maintains its principal
|
|
308
|
+
place of business and such litigation shall be governed by laws of that
|
|
309
|
+
jurisdiction, without reference to its conflict-of-law provisions.
|
|
310
|
+
Nothing in this Section shall prevent a party's ability to bring
|
|
311
|
+
cross-claims or counter-claims.
|
|
312
|
+
|
|
313
|
+
9. Miscellaneous
|
|
314
|
+
----------------
|
|
315
|
+
|
|
316
|
+
This License represents the complete agreement concerning the subject
|
|
317
|
+
matter hereof. If any provision of this License is held to be
|
|
318
|
+
unenforceable, such provision shall be reformed only to the extent
|
|
319
|
+
necessary to make it enforceable. Any law or regulation which provides
|
|
320
|
+
that the language of a contract shall be construed against the drafter
|
|
321
|
+
shall not be used to construe this License against a Contributor.
|
|
322
|
+
|
|
323
|
+
10. Versions of the License
|
|
324
|
+
---------------------------
|
|
325
|
+
|
|
326
|
+
10.1. New Versions
|
|
327
|
+
|
|
328
|
+
Mozilla Foundation is the license steward. Except as provided in Section
|
|
329
|
+
10.3, no one other than the license steward has the right to modify or
|
|
330
|
+
publish new versions of this License. Each version will be given a
|
|
331
|
+
distinguishing version number.
|
|
332
|
+
|
|
333
|
+
10.2. Effect of New Versions
|
|
334
|
+
|
|
335
|
+
You may distribute the Covered Software under the terms of the version
|
|
336
|
+
of the License under which You originally received the Covered Software,
|
|
337
|
+
or under the terms of any subsequent version published by the license
|
|
338
|
+
steward.
|
|
339
|
+
|
|
340
|
+
10.3. Modified Versions
|
|
341
|
+
|
|
342
|
+
If you create software not governed by this License, and you want to
|
|
343
|
+
create a new license for such software, you may create and use a
|
|
344
|
+
modified version of this License if you rename the license and remove
|
|
345
|
+
any references to the name of the license steward (except to note that
|
|
346
|
+
such modified license differs from this License).
|
|
347
|
+
|
|
348
|
+
10.4. Distributing Source Code Form that is Incompatible With Secondary
|
|
349
|
+
Licenses
|
|
350
|
+
|
|
351
|
+
If You choose to distribute Source Code Form that is Incompatible With
|
|
352
|
+
Secondary Licenses under the terms of this version of the License, the
|
|
353
|
+
notice described in Exhibit B of this License must be attached.
|
|
354
|
+
|
|
355
|
+
Exhibit A - Source Code Form License Notice
|
|
356
|
+
-------------------------------------------
|
|
357
|
+
|
|
358
|
+
This Source Code Form is subject to the terms of the Mozilla Public
|
|
359
|
+
License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
360
|
+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
361
|
+
|
|
362
|
+
If it is not possible or desirable to put the notice in a particular
|
|
363
|
+
file, then You may include the notice in a location (such as a LICENSE
|
|
364
|
+
file in a relevant directory) where a recipient would be likely to look
|
|
365
|
+
for such a notice.
|
|
366
|
+
|
|
367
|
+
You may add additional accurate notices of copyright ownership.
|
|
368
|
+
|
|
369
|
+
Exhibit B - "Incompatible With Secondary Licenses" Notice
|
|
370
|
+
---------------------------------------------------------
|
|
371
|
+
|
|
372
|
+
This Source Code Form is "Incompatible With Secondary Licenses", as
|
|
373
|
+
defined by the Mozilla Public License, v. 2.0.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# General TypeScript Helpers
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filters out duplicate values from an array. Objects are not supported, since
|
|
3
|
+
* they don’t provide value equality semantics.
|
|
4
|
+
*/
|
|
5
|
+
export declare const unique: <T extends number | boolean | string | symbol | null | undefined>(arr: T[]) => T[];
|
|
6
|
+
/**
|
|
7
|
+
* Checks if there are any duplicate elements in the array.
|
|
8
|
+
*/
|
|
9
|
+
export declare const anySame: <T>(arr: T[], equalityCheck?: (a: T, b: T) => boolean) => boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Checks if there are any duplicate elements in the array and returns an array
|
|
12
|
+
* of found duplicates where the values are the indices of these values.
|
|
13
|
+
*/
|
|
14
|
+
export declare const anySameIndices: <T>(arr: T[], equalityCheck?: (a: T, b: T) => boolean) => number[][];
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filters out duplicate values from an array. Objects are not supported, since
|
|
3
|
+
* they don’t provide value equality semantics.
|
|
4
|
+
*/
|
|
5
|
+
export const unique = (arr) => Array.from(new Set(arr));
|
|
6
|
+
/**
|
|
7
|
+
* Checks if there are any duplicate elements in the array.
|
|
8
|
+
*/
|
|
9
|
+
export const anySame = (arr, equalityCheck = (a, b) => a === b) => arr.some((item, index) => arr.findIndex((other) => equalityCheck(item, other)) !== index);
|
|
10
|
+
/**
|
|
11
|
+
* Checks if there are any duplicate elements in the array and returns an array
|
|
12
|
+
* of found duplicates where the values are the indices of these values.
|
|
13
|
+
*/
|
|
14
|
+
export const anySameIndices = (arr, equalityCheck = (a, b) => a === b) => arr.reduce((acc, item, index) => {
|
|
15
|
+
const firstIndex = arr.findIndex((other) => equalityCheck(item, other));
|
|
16
|
+
if (firstIndex === index) {
|
|
17
|
+
return acc;
|
|
18
|
+
}
|
|
19
|
+
const accIndex = acc.findIndex((accElem) => accElem[0] === firstIndex);
|
|
20
|
+
return accIndex === -1
|
|
21
|
+
? [...acc, [firstIndex, index]]
|
|
22
|
+
: // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- The index must exist according to the findIndex above
|
|
23
|
+
acc.with(accIndex, [...acc[accIndex], index]);
|
|
24
|
+
}, []);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the possibilities of all the combinations of nested array values.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
*
|
|
6
|
+
* flatCombine([["a", "b"], ["c"]]) // [["a", "c"], ["b", "c"]]
|
|
7
|
+
* flatCombine([["a", "b"], ["c", "d"]]) // [["a", "c"], ["b", "c"], ["a", "d"], ["b", "d"]]
|
|
8
|
+
*/
|
|
9
|
+
export declare const flatCombine: <T>(arr: T[][]) => T[][];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the possibilities of all the combinations of nested array values.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
*
|
|
6
|
+
* flatCombine([["a", "b"], ["c"]]) // [["a", "c"], ["b", "c"]]
|
|
7
|
+
* flatCombine([["a", "b"], ["c", "d"]]) // [["a", "c"], ["b", "c"], ["a", "d"], ["b", "d"]]
|
|
8
|
+
*/
|
|
9
|
+
export const flatCombine = (arr) => arr.length === 0
|
|
10
|
+
? []
|
|
11
|
+
: arr.slice(1).reduce((acc, elem) => elem.flatMap((elemInner) => acc.map((accElem) => [...accElem, elemInner])),
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- it is checked before if the array is empty
|
|
13
|
+
arr[0].map((elem) => [elem]));
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Equality } from "../equality.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Partitions an array into two arrays based on a predicate.
|
|
4
|
+
* @param arr The array to split.
|
|
5
|
+
* @param predicate The function to apply to each element in the array.
|
|
6
|
+
* @returns An array with two elements, the first one containing all elements
|
|
7
|
+
* that satisfy the predicate, the second one containing all elements that do
|
|
8
|
+
* not satisfy the predicate.
|
|
9
|
+
*/
|
|
10
|
+
export declare function partition<T, T1 extends T>(arr: T[], predicate: (value: T) => value is T1): [pos: T1[], neg: T[]];
|
|
11
|
+
export declare function partition<T>(arr: T[], predicate: (value: T) => boolean): [pos: T[], neg: T[]];
|
|
12
|
+
/**
|
|
13
|
+
* Returns a new array, where adjacent elements that are considered equal by the
|
|
14
|
+
* given equality function are grouped together. Calling the `flat` method on
|
|
15
|
+
* the result will return the original array.
|
|
16
|
+
*/
|
|
17
|
+
export declare const groupBy: <T>(arr: T[], equal: Equality<T>) => T[][];
|
|
18
|
+
/**
|
|
19
|
+
* Splits an array into chunks of a specified size.
|
|
20
|
+
* @param arr The array to be chunked.
|
|
21
|
+
* @param size The size of each chunk.
|
|
22
|
+
* @returns An array of chunks, where each chunk is an array of elements. The last chunk may be smaller than the specified size if there are not enough elements left.
|
|
23
|
+
*/
|
|
24
|
+
export declare const chunk: <T>(arr: T[], size: number) => T[][];
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Partitions an array into two arrays based on a predicate.
|
|
3
|
+
* @param arr The array to split.
|
|
4
|
+
* @param predicate The function to apply to each element in the array.
|
|
5
|
+
* @returns An array with two elements, the first one containing all elements
|
|
6
|
+
* that satisfy the predicate, the second one containing all elements that do
|
|
7
|
+
* not satisfy the predicate.
|
|
8
|
+
*/
|
|
9
|
+
export function partition(arr, predicate) {
|
|
10
|
+
return arr.reduce((acc, value) => {
|
|
11
|
+
acc[predicate(value) ? 0 : 1].push(value);
|
|
12
|
+
return acc;
|
|
13
|
+
}, [[], []]);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Returns a new array, where adjacent elements that are considered equal by the
|
|
17
|
+
* given equality function are grouped together. Calling the `flat` method on
|
|
18
|
+
* the result will return the original array.
|
|
19
|
+
*/
|
|
20
|
+
export const groupBy = (arr, equal) => arr.reduce((acc, value) => {
|
|
21
|
+
const lastGroup = acc[acc.length - 1];
|
|
22
|
+
if (lastGroup?.[0] !== undefined && equal(lastGroup[0], value)) {
|
|
23
|
+
lastGroup.push(value);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
acc.push([value]);
|
|
27
|
+
}
|
|
28
|
+
return acc;
|
|
29
|
+
}, []);
|
|
30
|
+
/**
|
|
31
|
+
* Splits an array into chunks of a specified size.
|
|
32
|
+
* @param arr The array to be chunked.
|
|
33
|
+
* @param size The size of each chunk.
|
|
34
|
+
* @returns An array of chunks, where each chunk is an array of elements. The last chunk may be smaller than the specified size if there are not enough elements left.
|
|
35
|
+
*/
|
|
36
|
+
export const chunk = (arr, size) => {
|
|
37
|
+
if (size <= 0) {
|
|
38
|
+
throw new RangeError(`size must be a positive integer, got ${size.toString()}`);
|
|
39
|
+
}
|
|
40
|
+
return arr.reduce((chunks, item, index) => {
|
|
41
|
+
const chunkIndex = Math.floor(index / size);
|
|
42
|
+
(chunks[chunkIndex] ??= []).push(item);
|
|
43
|
+
return chunks;
|
|
44
|
+
}, []);
|
|
45
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Moves an element from one position to another within the array.
|
|
3
|
+
*/
|
|
4
|
+
export declare const reorder: <T>(arr: T[], sourceIndex: number, targetIndex: number) => T[];
|
|
5
|
+
/**
|
|
6
|
+
* Returns a new array with all elements from the original array except for the
|
|
7
|
+
* given index.
|
|
8
|
+
*
|
|
9
|
+
* This function does not modify the original array.
|
|
10
|
+
*
|
|
11
|
+
* @throws {RangeError} Index is out of bounds.
|
|
12
|
+
*/
|
|
13
|
+
export declare const removeAt: <T>(arr: T[], index: number) => T[];
|
|
14
|
+
/**
|
|
15
|
+
* Inserts an element at a given position in an array and returns a new array with the result of the operation.
|
|
16
|
+
*
|
|
17
|
+
* This function does not modify the original array. The index given can be a valid index in the current array or the length of the array to append the item at the end.
|
|
18
|
+
*
|
|
19
|
+
* @throws {RangeError} Index is out of bounds.
|
|
20
|
+
*/
|
|
21
|
+
export declare const insertAt: <T>(arr: T[], index: number, item: T) => T[];
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Moves an element from one position to another within the array.
|
|
3
|
+
*/
|
|
4
|
+
export const reorder = (arr, sourceIndex, targetIndex) => {
|
|
5
|
+
if (sourceIndex < 0 || sourceIndex >= arr.length) {
|
|
6
|
+
throw new RangeError(`source index ${sourceIndex.toString()} is out of bounds for array of length ${arr.length.toString()}`);
|
|
7
|
+
}
|
|
8
|
+
if (targetIndex < 0 || targetIndex >= arr.length) {
|
|
9
|
+
throw new RangeError(`target index ${targetIndex.toString()} is out of bounds for array of length ${arr.length.toString()}`);
|
|
10
|
+
}
|
|
11
|
+
if (sourceIndex === targetIndex) {
|
|
12
|
+
return arr;
|
|
13
|
+
}
|
|
14
|
+
if (sourceIndex < targetIndex) {
|
|
15
|
+
return [
|
|
16
|
+
...arr.slice(0, sourceIndex),
|
|
17
|
+
...arr.slice(sourceIndex + 1, targetIndex + 1),
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
19
|
+
arr[sourceIndex],
|
|
20
|
+
...arr.slice(targetIndex + 1),
|
|
21
|
+
];
|
|
22
|
+
}
|
|
23
|
+
return [
|
|
24
|
+
...arr.slice(0, targetIndex),
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
26
|
+
arr[sourceIndex],
|
|
27
|
+
...arr.slice(targetIndex, sourceIndex),
|
|
28
|
+
...arr.slice(sourceIndex + 1),
|
|
29
|
+
];
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Returns a new array with all elements from the original array except for the
|
|
33
|
+
* given index.
|
|
34
|
+
*
|
|
35
|
+
* This function does not modify the original array.
|
|
36
|
+
*
|
|
37
|
+
* @throws {RangeError} Index is out of bounds.
|
|
38
|
+
*/
|
|
39
|
+
export const removeAt = (arr, index) => {
|
|
40
|
+
if (index < 0 || index >= arr.length) {
|
|
41
|
+
throw new RangeError(`index ${index.toString()} is out of bounds for array of length ${arr.length.toString()}`);
|
|
42
|
+
}
|
|
43
|
+
return [...arr.slice(0, index), ...arr.slice(index + 1)];
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Inserts an element at a given position in an array and returns a new array with the result of the operation.
|
|
47
|
+
*
|
|
48
|
+
* This function does not modify the original array. The index given can be a valid index in the current array or the length of the array to append the item at the end.
|
|
49
|
+
*
|
|
50
|
+
* @throws {RangeError} Index is out of bounds.
|
|
51
|
+
*/
|
|
52
|
+
export const insertAt = (arr, index, item) => {
|
|
53
|
+
if (index < 0 || index > arr.length) {
|
|
54
|
+
throw new RangeError(`index ${index.toString()} is out of bounds for array of length ${arr.length.toString()}`);
|
|
55
|
+
}
|
|
56
|
+
return [...arr.slice(0, index), item, ...arr.slice(index)];
|
|
57
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types and functions to check for non-empty arrays.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* The empty array type.
|
|
6
|
+
*/
|
|
7
|
+
export type EmptyArray = [];
|
|
8
|
+
/**
|
|
9
|
+
* A type representing a non-empty array, i.e., an array with at least one element.
|
|
10
|
+
*/
|
|
11
|
+
export type NonEmptyArray<T> = [T, ...T[]];
|
|
12
|
+
/**
|
|
13
|
+
* Checks if the array is empty.
|
|
14
|
+
*/
|
|
15
|
+
export declare const isEmpty: (arr: unknown[]) => arr is EmptyArray;
|
|
16
|
+
/**
|
|
17
|
+
* Checks if the array is not empty, i.e., contains at least one element.
|
|
18
|
+
*/
|
|
19
|
+
export declare const isNotEmpty: <T>(arr: T[]) => arr is NonEmptyArray<T>;
|
|
20
|
+
/**
|
|
21
|
+
* Returns `undefined` if the array is empty, otherwise the non-empty array.
|
|
22
|
+
*/
|
|
23
|
+
export declare const ensureNonEmpty: <T>(arr: T[]) => NonEmptyArray<T> | undefined;
|