@tempots/std 0.9.5 → 0.9.7

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 (128) hide show
  1. package/arrays.d.ts +49 -0
  2. package/arrays.js +249 -0
  3. package/async-result.d.ts +37 -0
  4. package/async-result.js +75 -0
  5. package/bigint.d.ts +18 -0
  6. package/bigint.js +110 -0
  7. package/booleans.d.ts +23 -0
  8. package/{src/booleans.ts → booleans.js} +33 -38
  9. package/colors/cmyk.d.ts +21 -0
  10. package/colors/cmyk.js +54 -0
  11. package/colors/convert.d.ts +283 -0
  12. package/colors/convert.js +742 -0
  13. package/colors/hsl.d.ts +24 -0
  14. package/colors/hsl.js +56 -0
  15. package/colors/hsla.d.ts +18 -0
  16. package/colors/hsla.js +35 -0
  17. package/colors/hsluv.d.ts +24 -0
  18. package/colors/hsluv.js +56 -0
  19. package/colors/hsv.d.ts +24 -0
  20. package/colors/hsv.js +54 -0
  21. package/colors/lab.d.ts +24 -0
  22. package/colors/lab.js +54 -0
  23. package/colors/lch.d.ts +19 -0
  24. package/colors/lch.js +44 -0
  25. package/colors/luv.d.ts +19 -0
  26. package/colors/luv.js +45 -0
  27. package/colors/rgb.d.ts +13 -0
  28. package/colors/rgb.js +47 -0
  29. package/colors/rgba.d.ts +12 -0
  30. package/colors/rgba.js +44 -0
  31. package/colors/srgb.d.ts +24 -0
  32. package/colors/srgb.js +51 -0
  33. package/colors/xyz.d.ts +19 -0
  34. package/colors/xyz.js +41 -0
  35. package/edit.d.ts +20 -0
  36. package/edit.js +29 -0
  37. package/equals.d.ts +3 -0
  38. package/equals.js +122 -0
  39. package/functions.d.ts +20 -0
  40. package/functions.js +38 -0
  41. package/json.d.ts +14 -0
  42. package/json.js +33 -0
  43. package/match.d.ts +16 -0
  44. package/match.js +45 -0
  45. package/maybe.d.ts +9 -0
  46. package/{src/maybe.ts → maybe.js} +11 -18
  47. package/memoize.d.ts +1 -0
  48. package/memoize.js +9 -0
  49. package/newtype.d.ts +28 -0
  50. package/newtype.js +29 -0
  51. package/numbers.d.ts +104 -0
  52. package/numbers.js +183 -0
  53. package/objects.d.ts +9 -0
  54. package/objects.js +33 -0
  55. package/ord.d.ts +19 -0
  56. package/ord.js +73 -0
  57. package/package.json +3 -7
  58. package/reg-exps.d.ts +10 -0
  59. package/{src/reg-exps.ts → reg-exps.js} +19 -24
  60. package/result.d.ts +31 -0
  61. package/result.js +95 -0
  62. package/strings.d.ts +314 -0
  63. package/strings.js +685 -0
  64. package/types/assert.d.ts +12 -0
  65. package/types/assert.js +13 -0
  66. package/types/differentiate.d.ts +13 -0
  67. package/types/differentiate.js +14 -0
  68. package/types/functions.d.ts +22 -0
  69. package/types/functions.js +13 -0
  70. package/types/generic.d.ts +9 -0
  71. package/types/generic.js +13 -0
  72. package/types/objects.d.ts +50 -0
  73. package/types/objects.js +13 -0
  74. package/types/tuples.d.ts +44 -0
  75. package/types/tuples.js +24 -0
  76. package/{src/types/utility.ts → types/utility.d.ts} +2 -3
  77. package/types/utility.js +1 -0
  78. package/uuid.d.ts +13 -0
  79. package/uuid.js +56 -0
  80. package/validation.d.ts +23 -0
  81. package/validation.js +44 -0
  82. package/src/arrays.ts +0 -296
  83. package/src/async-result.ts +0 -103
  84. package/src/bigint.ts +0 -111
  85. package/src/colors/cmyk.ts +0 -84
  86. package/src/colors/convert.ts +0 -1093
  87. package/src/colors/hsl.ts +0 -73
  88. package/src/colors/hsla.ts +0 -45
  89. package/src/colors/hsluv.ts +0 -73
  90. package/src/colors/hsv.ts +0 -75
  91. package/src/colors/lab.ts +0 -69
  92. package/src/colors/lch.ts +0 -53
  93. package/src/colors/luv.ts +0 -56
  94. package/src/colors/rgb.ts +0 -55
  95. package/src/colors/rgba.ts +0 -53
  96. package/src/colors/srgb.ts +0 -72
  97. package/src/colors/xyz.ts +0 -52
  98. package/src/edit.ts +0 -29
  99. package/src/equals.ts +0 -116
  100. package/src/functions.ts +0 -108
  101. package/src/json.ts +0 -52
  102. package/src/match.ts +0 -88
  103. package/src/memoize.ts +0 -9
  104. package/src/newtype.ts +0 -59
  105. package/src/numbers.ts +0 -222
  106. package/src/objects.ts +0 -47
  107. package/src/ord.ts +0 -79
  108. package/src/result.ts +0 -140
  109. package/src/strings.ts +0 -768
  110. package/src/types/assert.ts +0 -96
  111. package/src/types/differentiate.ts +0 -89
  112. package/src/types/functions.ts +0 -114
  113. package/src/types/generic.ts +0 -42
  114. package/src/types/objects.ts +0 -212
  115. package/src/types/tuples.ts +0 -244
  116. package/src/uuid.ts +0 -61
  117. package/src/validation.ts +0 -69
  118. package/test/arrays.spec.ts +0 -410
  119. package/test/colors.spec.ts +0 -406
  120. package/test/commmon.ts +0 -9
  121. package/test/equals.spec.ts +0 -165
  122. package/test/functions.spec.ts +0 -9
  123. package/test/index.d.ts +0 -20
  124. package/test/objects.spec.ts +0 -22
  125. package/test/reg-exps.spec.ts +0 -33
  126. package/test/strings.spec.ts +0 -333
  127. package/test/uuid.spec.ts +0 -35
  128. 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
- })