@tempots/std 0.9.6 → 0.10.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/README.md +1 -3
  2. package/array.cjs +1 -0
  3. package/array.d.ts +49 -0
  4. package/array.js +223 -0
  5. package/bigint.cjs +1 -0
  6. package/bigint.d.ts +18 -0
  7. package/bigint.js +96 -0
  8. package/boolean.cjs +1 -0
  9. package/boolean.d.ts +23 -0
  10. package/boolean.js +44 -0
  11. package/domain.cjs +1 -0
  12. package/domain.d.ts +22 -0
  13. package/domain.js +1 -0
  14. package/equal.cjs +1 -0
  15. package/equal.d.ts +3 -0
  16. package/equal.js +68 -0
  17. package/function.cjs +1 -0
  18. package/function.d.ts +20 -0
  19. package/function.js +29 -0
  20. package/index.cjs +1 -0
  21. package/index.d.ts +0 -0
  22. package/index.js +1 -0
  23. package/maybe.cjs +1 -0
  24. package/maybe.d.ts +9 -0
  25. package/maybe.js +9 -0
  26. package/number.cjs +1 -0
  27. package/number.d.ts +101 -0
  28. package/number.js +103 -0
  29. package/object.cjs +1 -0
  30. package/object.d.ts +8 -0
  31. package/object.js +30 -0
  32. package/package.json +55 -25
  33. package/regexp.cjs +1 -0
  34. package/regexp.d.ts +10 -0
  35. package/regexp.js +14 -0
  36. package/string.cjs +3 -0
  37. package/string.d.ts +312 -0
  38. package/string.js +396 -0
  39. package/src/arrays.ts +0 -296
  40. package/src/async-result.ts +0 -103
  41. package/src/bigint.ts +0 -111
  42. package/src/booleans.ts +0 -73
  43. package/src/colors/cmyk.ts +0 -84
  44. package/src/colors/convert.ts +0 -1093
  45. package/src/colors/hsl.ts +0 -73
  46. package/src/colors/hsla.ts +0 -45
  47. package/src/colors/hsluv.ts +0 -73
  48. package/src/colors/hsv.ts +0 -75
  49. package/src/colors/lab.ts +0 -69
  50. package/src/colors/lch.ts +0 -53
  51. package/src/colors/luv.ts +0 -56
  52. package/src/colors/rgb.ts +0 -55
  53. package/src/colors/rgba.ts +0 -53
  54. package/src/colors/srgb.ts +0 -72
  55. package/src/colors/xyz.ts +0 -52
  56. package/src/edit.ts +0 -29
  57. package/src/equals.ts +0 -116
  58. package/src/functions.ts +0 -108
  59. package/src/json.ts +0 -52
  60. package/src/match.ts +0 -88
  61. package/src/maybe.ts +0 -32
  62. package/src/memoize.ts +0 -9
  63. package/src/newtype.ts +0 -59
  64. package/src/numbers.ts +0 -222
  65. package/src/objects.ts +0 -47
  66. package/src/ord.ts +0 -79
  67. package/src/reg-exps.ts +0 -48
  68. package/src/result.ts +0 -140
  69. package/src/strings.ts +0 -768
  70. package/src/types/assert.ts +0 -96
  71. package/src/types/differentiate.ts +0 -89
  72. package/src/types/functions.ts +0 -114
  73. package/src/types/generic.ts +0 -42
  74. package/src/types/objects.ts +0 -212
  75. package/src/types/tuples.ts +0 -244
  76. package/src/types/utility.ts +0 -3
  77. package/src/uuid.ts +0 -61
  78. package/src/validation.ts +0 -69
  79. package/test/arrays.spec.ts +0 -410
  80. package/test/colors.spec.ts +0 -406
  81. package/test/commmon.ts +0 -9
  82. package/test/equals.spec.ts +0 -165
  83. package/test/functions.spec.ts +0 -9
  84. package/test/index.d.ts +0 -20
  85. package/test/objects.spec.ts +0 -22
  86. package/test/reg-exps.spec.ts +0 -33
  87. package/test/strings.spec.ts +0 -333
  88. package/test/uuid.spec.ts +0 -35
  89. package/tsconfig.json +0 -19
@@ -1,410 +0,0 @@
1
- /*
2
- Copyright 2019 Google LLC
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
6
- https://www.apache.org/licenses/LICENSE-2.0
7
- Unless required by applicable law or agreed to in writing, software
8
- distributed under the License is distributed on an "AS IS" BASIS,
9
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
- See the License for the specific language governing permissions and
11
- limitations under the License.
12
- */
13
-
14
- import { describe, expect, test } from 'vitest'
15
- import { applyOperations, type DiffOperations, diffOperations, map, head, tail, numbersRange, fill, makeCompare } from '../src/arrays'
16
- import { compare as compareString } from '../src/strings'
17
-
18
- describe('arrays:map', () => {
19
- test('should work with empty arrays', () => {
20
- expect(map([], a => a)).toEqual([])
21
- })
22
-
23
- test('should work with any array', () => {
24
- expect(map([1, 2, 3], a => a + 1)).toEqual([2, 3, 4])
25
- })
26
- })
27
-
28
- describe('arrays:head', () => {
29
- test('should return nothing if the array is empy', () => {
30
- expect(head([])).not.toBeDefined()
31
- })
32
-
33
- test('should return the first element', () => {
34
- expect(head([1])).toEqual(1)
35
- expect(head([1, 2])).toEqual(1)
36
- expect(head([1, 2, 3])).toEqual(1)
37
- })
38
- })
39
-
40
- describe('arrays:tail', () => {
41
- test('should return nothing if the array is empy', () => {
42
- expect(tail([])).toEqual([])
43
- })
44
-
45
- test('should return all the elements except for the first', () => {
46
- expect(tail([1])).toEqual([])
47
- expect(tail([1, 2])).toEqual([2])
48
- expect(tail([1, 2, 3])).toEqual([2, 3])
49
- })
50
- })
51
-
52
- describe('arrays', () => {
53
- test('numberRange', () => {
54
- expect(numbersRange(4)).toEqual([0, 1, 2, 3])
55
- expect(numbersRange(4, 1)).toEqual([1, 2, 3, 4])
56
- })
57
-
58
- test('fill', () => {
59
- expect(fill(4, 'x')).toEqual(['x', 'x', 'x', 'x'])
60
- })
61
- })
62
-
63
- describe('arrays:makeCompare', () => {
64
- test('should compare arrays of the same length', () => {
65
- const tests = [
66
- { a: ['a'], b: ['b'], r: -1 },
67
- { a: ['b'], b: ['a'], r: 1 },
68
- { a: ['a'], b: ['a'], r: 0 },
69
- { a: ['a', 'b'], b: ['a', 'b'], r: 0 }
70
- ]
71
-
72
- const compare = makeCompare(compareString, true)
73
- tests.forEach(test => {
74
- expect(compare(test.a, test.b)).toBe(test.r)
75
- })
76
- })
77
-
78
- test('should compare arrays with different lengths', () => {
79
- const tests = [
80
- { a: [], b: ['a'], r: -1 },
81
- { a: ['a'], b: [], r: 1 },
82
- { a: ['a'], b: ['a', 'b'], r: -1 },
83
- { a: ['b'], b: ['a', 'b'], r: -1 },
84
- { a: ['b', 'b'], b: ['a', 'b', 'c'], r: -1 }
85
- ]
86
-
87
- let compare = makeCompare(compareString, true)
88
- tests.forEach(test => {
89
- expect(compare(test.a, test.b)).toBe(test.r)
90
- })
91
-
92
- compare = makeCompare(compareString, false)
93
- tests.forEach(test => {
94
- expect(compare(test.a, test.b)).toBe(test.r * -1)
95
- })
96
- })
97
- })
98
-
99
- const cases: Array<{
100
- a: string[]
101
- b: string[]
102
- operations: DiffOperations<string>
103
- }> = [
104
- {
105
- a: [],
106
- b: [],
107
- operations: {
108
- removals: [],
109
- swaps: [],
110
- inserts: []
111
- }
112
- },
113
- {
114
- a: ['a'],
115
- b: ['a'],
116
- operations: {
117
- removals: [],
118
- swaps: [],
119
- inserts: []
120
- }
121
- },
122
- {
123
- a: ['a'],
124
- b: ['b'],
125
- operations: {
126
- removals: [{ at: 0, qt: 1 }],
127
- swaps: [],
128
- inserts: [{ at: 0, values: ['b'] }]
129
- }
130
- },
131
- {
132
- a: ['a', 'b', 'c'],
133
- b: ['b'],
134
- operations: {
135
- removals: [
136
- { at: 2, qt: 1 },
137
- { at: 0, qt: 1 }
138
- ],
139
- swaps: [],
140
- inserts: []
141
- }
142
- },
143
- {
144
- a: ['a', 'b', 'c'],
145
- b: ['d'],
146
- operations: {
147
- removals: [{ at: 0, qt: 3 }],
148
- swaps: [],
149
- inserts: [{ at: 0, values: ['d'] }]
150
- }
151
- },
152
- {
153
- a: ['a', 'b', 'c', 'd'],
154
- b: ['a', 'd'],
155
- operations: {
156
- removals: [{ at: 1, qt: 2 }],
157
- swaps: [],
158
- inserts: []
159
- }
160
- },
161
- {
162
- a: ['a', 'b', 'c', 'd'],
163
- b: ['x', 'd'],
164
- operations: {
165
- removals: [{ at: 0, qt: 3 }],
166
- swaps: [],
167
- inserts: [{ at: 0, values: ['x'] }]
168
- }
169
- },
170
- {
171
- a: ['a', 'b', 'c', 'd'],
172
- b: ['x', 'b', 'y', 'd'],
173
- operations: {
174
- removals: [
175
- { at: 2, qt: 1 },
176
- { at: 0, qt: 1 }
177
- ],
178
- swaps: [],
179
- inserts: [
180
- { at: 0, values: ['x'] },
181
- { at: 2, values: ['y'] }
182
- ]
183
- }
184
- },
185
- {
186
- a: ['b'],
187
- b: ['a', 'b', 'c'],
188
- operations: {
189
- removals: [],
190
- swaps: [],
191
- inserts: [
192
- { at: 0, values: ['a'] },
193
- { at: 2, values: ['c'] }
194
- ]
195
- }
196
- },
197
- {
198
- a: ['d'],
199
- b: ['a', 'b', 'c'],
200
- operations: {
201
- removals: [{ at: 0, qt: 1 }],
202
- swaps: [],
203
- inserts: [{ at: 0, values: ['a', 'b', 'c'] }]
204
- }
205
- },
206
- {
207
- a: ['a', 'd'],
208
- b: ['a', 'b', 'c', 'd'],
209
- operations: {
210
- removals: [],
211
- swaps: [],
212
- inserts: [{ at: 1, values: ['b', 'c'] }]
213
- }
214
- },
215
- {
216
- a: ['x', 'd'],
217
- b: ['a', 'b', 'c', 'd'],
218
- operations: {
219
- removals: [{ at: 0, qt: 1 }],
220
- swaps: [],
221
- inserts: [{ at: 0, values: ['a', 'b', 'c'] }]
222
- }
223
- },
224
- {
225
- a: ['a', 'b', 'c', 'd', 'e'],
226
- b: ['b', 'x', 'd'],
227
- operations: {
228
- removals: [
229
- { at: 4, qt: 1 },
230
- { at: 2, qt: 1 },
231
- { at: 0, qt: 1 }
232
- ],
233
- swaps: [],
234
- inserts: [{ at: 1, values: ['x'] }]
235
- }
236
- },
237
- {
238
- a: ['b', 'x', 'd'],
239
- b: ['a', 'b', 'c', 'd', 'e'],
240
- operations: {
241
- removals: [{ at: 1, qt: 1 }],
242
- swaps: [],
243
- inserts: [
244
- { at: 0, values: ['a'] },
245
- { at: 2, values: ['c'] },
246
- { at: 4, values: ['e'] }
247
- ]
248
- }
249
- },
250
- {
251
- a: ['a', 'b', 'c'],
252
- b: ['c', 'b', 'a'],
253
- operations: {
254
- removals: [],
255
- swaps: [{ from: 0, to: 2 }],
256
- inserts: []
257
- }
258
- },
259
- {
260
- a: ['a', 'b', 'c'],
261
- b: ['c', 'x', 'b', 'a'],
262
- operations: {
263
- removals: [],
264
- swaps: [{ from: 0, to: 2 }],
265
- inserts: [{ at: 1, values: ['x'] }]
266
- }
267
- },
268
- {
269
- a: ['c', 'x', 'b', 'a'],
270
- b: ['a', 'b', 'c'],
271
- operations: {
272
- removals: [{ at: 1, qt: 1 }],
273
- swaps: [{ from: 0, to: 2 }],
274
- inserts: []
275
- }
276
- },
277
- {
278
- a: ['a', 'b', 'c', 'x'],
279
- b: ['c', 'x', 'y', 'z', 'a', 'b'],
280
- operations: {
281
- removals: [],
282
- swaps: [
283
- { from: 0, to: 2 },
284
- { from: 1, to: 3 }
285
- ],
286
- inserts: [{ at: 2, values: ['y', 'z'] }]
287
- }
288
- },
289
- {
290
- a: ['c', 'x', 'y', 'z', 'a', 'b'],
291
- b: ['a', 'b', 'c', 'x'],
292
- operations: {
293
- removals: [{ at: 2, qt: 2 }],
294
- swaps: [
295
- { from: 0, to: 2 },
296
- { from: 1, to: 3 }
297
- ],
298
- inserts: []
299
- }
300
- }
301
- ]
302
-
303
- const js = JSON.stringify
304
-
305
- describe('array helpers', () => {
306
- test('diffOperations', () => {
307
- for (const { a, b, operations } of cases) {
308
- const res = diffOperations(a, b, v => v)
309
- try {
310
- expect(res).toEqual(operations)
311
- } catch {
312
- throw new Error(
313
- `Expected ${js(a)} and ${js(b)} to produce\n${js(
314
- operations
315
- )}\nbut got\n${js(res)} instead`
316
- )
317
- }
318
- }
319
- })
320
-
321
- test('applyOperations', () => {
322
- for (const { a, b, operations } of cases) {
323
- const res = applyOperations(operations, a)
324
- try {
325
- expect(res).toEqual(b)
326
- } catch {
327
- throw new Error(
328
- `Expected ${js(operations)} applied to ${js(a)} to produce\n${js(
329
- b
330
- )}\nbut got\n${js(res)} instead`
331
- )
332
- }
333
- }
334
- })
335
-
336
- const roundtrips: Array<[string[], string[]]> = [
337
- [[], []],
338
- [['a'], ['b']],
339
- [['a', 'b'], ['b']],
340
- [['a', 'b'], ['x']],
341
- [['a', 'b', 'c'], ['b']],
342
- [['a', 'b', 'c'], ['c']],
343
- [['a', 'b', 'c'], ['x']],
344
- [['a', 'b', 'c'], ['a']],
345
- [
346
- ['a', 'b', 'c'],
347
- ['c', 'b']
348
- ],
349
- [
350
- ['a', 'b', 'c'],
351
- ['c', 'a']
352
- ],
353
- [
354
- ['a', 'b', 'c'],
355
- ['a', 'b']
356
- ],
357
- [
358
- ['a', 'b', 'c'],
359
- ['a', 'b', 'c']
360
- ],
361
- [
362
- ['a', 'b', 'c'],
363
- ['c', 'b', 'a']
364
- ],
365
- [
366
- ['a', 'b', 'c'],
367
- ['a', 'c', 'b']
368
- ],
369
- [
370
- ['a', 'b', 'c'],
371
- ['b', 'c', 'a']
372
- ],
373
- [
374
- ['a', 'b', 'c'],
375
- ['a', 'b', 'c', 'd', 'e', 'f']
376
- ],
377
- [
378
- ['c', 'a', 'b'],
379
- ['a', 'b', 'c']
380
- ]
381
- ]
382
-
383
- test('diffOperations and applyOperations roundtrips', () => {
384
- for (const [a, b] of roundtrips) {
385
- const ops = diffOperations(a, b, v => v)
386
- const res = applyOperations(ops, a)
387
- try {
388
- expect(res).toEqual(b)
389
- } catch {
390
- throw new Error(
391
- `${js(a)} and ${js(b)} produced ${js(ops)} but generated ${js(res)}`
392
- )
393
- }
394
- }
395
-
396
- for (const [b, a] of roundtrips) {
397
- const ops = diffOperations(a, b, v => v)
398
- const res = applyOperations(ops, a)
399
- try {
400
- expect(res).toEqual(b)
401
- } catch {
402
- throw new Error(
403
- `Swapped ${js(a)} and ${js(b)} produced ${js(ops)} but generated ${js(
404
- res
405
- )}`
406
- )
407
- }
408
- }
409
- })
410
- })