@tempots/std 0.9.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/dist/arrays.d.ts +49 -0
- package/dist/arrays.js +249 -0
- package/dist/async-result.d.ts +37 -0
- package/dist/async-result.js +75 -0
- package/dist/bigint.d.ts +18 -0
- package/dist/bigint.js +110 -0
- package/dist/booleans.d.ts +23 -0
- package/dist/booleans.js +68 -0
- package/dist/colors/cmyk.d.ts +21 -0
- package/dist/colors/cmyk.js +54 -0
- package/dist/colors/convert.d.ts +283 -0
- package/dist/colors/convert.js +742 -0
- package/dist/colors/hsl.d.ts +24 -0
- package/dist/colors/hsl.js +56 -0
- package/dist/colors/hsla.d.ts +18 -0
- package/dist/colors/hsla.js +35 -0
- package/dist/colors/hsluv.d.ts +24 -0
- package/dist/colors/hsluv.js +56 -0
- package/dist/colors/hsv.d.ts +24 -0
- package/dist/colors/hsv.js +54 -0
- package/dist/colors/lab.d.ts +24 -0
- package/dist/colors/lab.js +54 -0
- package/dist/colors/lch.d.ts +19 -0
- package/dist/colors/lch.js +44 -0
- package/dist/colors/luv.d.ts +19 -0
- package/dist/colors/luv.js +45 -0
- package/dist/colors/rgb.d.ts +13 -0
- package/dist/colors/rgb.js +47 -0
- package/dist/colors/rgba.d.ts +12 -0
- package/dist/colors/rgba.js +44 -0
- package/dist/colors/srgb.d.ts +24 -0
- package/dist/colors/srgb.js +51 -0
- package/dist/colors/xyz.d.ts +19 -0
- package/dist/colors/xyz.js +41 -0
- package/dist/edit.d.ts +20 -0
- package/dist/edit.js +29 -0
- package/dist/equals.d.ts +3 -0
- package/dist/equals.js +122 -0
- package/dist/functions.d.ts +20 -0
- package/dist/functions.js +38 -0
- package/dist/json.d.ts +14 -0
- package/dist/json.js +33 -0
- package/dist/match.d.ts +16 -0
- package/dist/match.js +45 -0
- package/dist/maybe.d.ts +9 -0
- package/dist/maybe.js +25 -0
- package/dist/memoize.d.ts +1 -0
- package/dist/memoize.js +9 -0
- package/dist/newtype.d.ts +28 -0
- package/dist/newtype.js +29 -0
- package/dist/numbers.d.ts +104 -0
- package/dist/numbers.js +183 -0
- package/dist/objects.d.ts +9 -0
- package/dist/objects.js +33 -0
- package/dist/ord.d.ts +19 -0
- package/dist/ord.js +73 -0
- package/dist/reg-exps.d.ts +10 -0
- package/dist/reg-exps.js +43 -0
- package/dist/result.d.ts +31 -0
- package/dist/result.js +95 -0
- package/dist/strings.d.ts +314 -0
- package/dist/strings.js +685 -0
- package/dist/types/assert.d.ts +12 -0
- package/dist/types/assert.js +13 -0
- package/dist/types/differentiate.d.ts +13 -0
- package/dist/types/differentiate.js +14 -0
- package/dist/types/functions.d.ts +22 -0
- package/dist/types/functions.js +13 -0
- package/dist/types/generic.d.ts +9 -0
- package/dist/types/generic.js +13 -0
- package/dist/types/objects.d.ts +50 -0
- package/dist/types/objects.js +13 -0
- package/dist/types/tuples.d.ts +44 -0
- package/dist/types/tuples.js +24 -0
- package/dist/types/utility.d.ts +2 -0
- package/dist/types/utility.js +1 -0
- package/dist/uuid.d.ts +13 -0
- package/dist/uuid.js +56 -0
- package/dist/validation.d.ts +23 -0
- package/dist/validation.js +44 -0
- package/package.json +36 -0
- package/src/arrays.ts +296 -0
- package/src/async-result.ts +103 -0
- package/src/bigint.ts +111 -0
- package/src/booleans.ts +73 -0
- package/src/colors/cmyk.ts +84 -0
- package/src/colors/convert.ts +1093 -0
- package/src/colors/hsl.ts +73 -0
- package/src/colors/hsla.ts +45 -0
- package/src/colors/hsluv.ts +73 -0
- package/src/colors/hsv.ts +75 -0
- package/src/colors/lab.ts +69 -0
- package/src/colors/lch.ts +53 -0
- package/src/colors/luv.ts +56 -0
- package/src/colors/rgb.ts +55 -0
- package/src/colors/rgba.ts +53 -0
- package/src/colors/srgb.ts +72 -0
- package/src/colors/xyz.ts +52 -0
- package/src/edit.ts +29 -0
- package/src/equals.ts +116 -0
- package/src/functions.ts +108 -0
- package/src/json.ts +52 -0
- package/src/match.ts +88 -0
- package/src/maybe.ts +32 -0
- package/src/memoize.ts +9 -0
- package/src/newtype.ts +59 -0
- package/src/numbers.ts +222 -0
- package/src/objects.ts +47 -0
- package/src/ord.ts +79 -0
- package/src/reg-exps.ts +48 -0
- package/src/result.ts +140 -0
- package/src/strings.ts +768 -0
- package/src/types/assert.ts +96 -0
- package/src/types/differentiate.ts +89 -0
- package/src/types/functions.ts +114 -0
- package/src/types/generic.ts +42 -0
- package/src/types/objects.ts +212 -0
- package/src/types/tuples.ts +244 -0
- package/src/types/utility.ts +3 -0
- package/src/uuid.ts +61 -0
- package/src/validation.ts +69 -0
- package/test/arrays.spec.ts +410 -0
- package/test/colors.spec.ts +406 -0
- package/test/commmon.ts +9 -0
- package/test/equals.spec.ts +165 -0
- package/test/functions.spec.ts +9 -0
- package/test/index.d.ts +20 -0
- package/test/objects.spec.ts +22 -0
- package/test/reg-exps.spec.ts +33 -0
- package/test/strings.spec.ts +333 -0
- package/test/uuid.spec.ts +35 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest'
|
|
2
|
+
import {
|
|
3
|
+
Channel,
|
|
4
|
+
hsl2hsluv,
|
|
5
|
+
hsl2hsv,
|
|
6
|
+
hsl2lab,
|
|
7
|
+
hsl2lch,
|
|
8
|
+
hsl2luv,
|
|
9
|
+
hsl2rgb,
|
|
10
|
+
hsl2srgb,
|
|
11
|
+
hsl2xyz,
|
|
12
|
+
hsluv2hsl,
|
|
13
|
+
hsluv2hsv,
|
|
14
|
+
hsluv2lab,
|
|
15
|
+
hsluv2lch,
|
|
16
|
+
hsluv2luv,
|
|
17
|
+
hsluv2rgb,
|
|
18
|
+
hsluv2srgb,
|
|
19
|
+
hsluv2xyz,
|
|
20
|
+
hsv2hsl,
|
|
21
|
+
hsv2hsluv,
|
|
22
|
+
hsv2lab,
|
|
23
|
+
hsv2lch,
|
|
24
|
+
hsv2luv,
|
|
25
|
+
hsv2rgb,
|
|
26
|
+
hsv2srgb,
|
|
27
|
+
hsv2xyz,
|
|
28
|
+
lab2hsl,
|
|
29
|
+
lab2hsluv,
|
|
30
|
+
lab2hsv,
|
|
31
|
+
lab2lch,
|
|
32
|
+
lab2luv,
|
|
33
|
+
lab2rgb,
|
|
34
|
+
lab2srgb,
|
|
35
|
+
lab2xyz,
|
|
36
|
+
lch2hsl,
|
|
37
|
+
lch2hsluv,
|
|
38
|
+
lch2hsv,
|
|
39
|
+
lch2lab,
|
|
40
|
+
lch2luv,
|
|
41
|
+
lch2rgb,
|
|
42
|
+
lch2srgb,
|
|
43
|
+
lch2xyz,
|
|
44
|
+
luv2hsl,
|
|
45
|
+
luv2hsluv,
|
|
46
|
+
luv2hsv,
|
|
47
|
+
luv2lab,
|
|
48
|
+
luv2lch,
|
|
49
|
+
luv2rgb,
|
|
50
|
+
luv2srgb,
|
|
51
|
+
luv2xyz,
|
|
52
|
+
rgb2hsl,
|
|
53
|
+
rgb2hsluv,
|
|
54
|
+
rgb2hsv,
|
|
55
|
+
rgb2lab,
|
|
56
|
+
rgb2lch,
|
|
57
|
+
rgb2luv,
|
|
58
|
+
rgb2srgb,
|
|
59
|
+
rgb2xyz,
|
|
60
|
+
srgb2hsl,
|
|
61
|
+
srgb2hsluv,
|
|
62
|
+
srgb2hsv,
|
|
63
|
+
srgb2lab,
|
|
64
|
+
srgb2lch,
|
|
65
|
+
srgb2luv,
|
|
66
|
+
srgb2rgb,
|
|
67
|
+
srgb2xyz,
|
|
68
|
+
WHITE_REFERENCE,
|
|
69
|
+
xyz2hsl,
|
|
70
|
+
xyz2hsluv,
|
|
71
|
+
xyz2hsv,
|
|
72
|
+
xyz2lab,
|
|
73
|
+
xyz2lch,
|
|
74
|
+
xyz2luv,
|
|
75
|
+
xyz2rgb,
|
|
76
|
+
xyz2srgb
|
|
77
|
+
} from '../src/colors/convert'
|
|
78
|
+
import { HSL } from '../src/colors/hsl'
|
|
79
|
+
import { HSLuv } from '../src/colors/hsluv'
|
|
80
|
+
import { HSV } from '../src/colors/hsv'
|
|
81
|
+
import { LAB } from '../src/colors/lab'
|
|
82
|
+
import { LCH } from '../src/colors/lch'
|
|
83
|
+
import { LUV } from '../src/colors/luv'
|
|
84
|
+
import { RGB } from '../src/colors/rgb'
|
|
85
|
+
import { SRGB } from '../src/colors/srgb'
|
|
86
|
+
import { XYZ } from '../src/colors/xyz'
|
|
87
|
+
import { nearEquals } from '../src/numbers'
|
|
88
|
+
|
|
89
|
+
expect.extend({
|
|
90
|
+
toNearEqual (
|
|
91
|
+
this: any,
|
|
92
|
+
received: number,
|
|
93
|
+
expected: number,
|
|
94
|
+
precision = 0.0001
|
|
95
|
+
) {
|
|
96
|
+
const pass = nearEquals(received, expected, precision)
|
|
97
|
+
if (pass) {
|
|
98
|
+
return {
|
|
99
|
+
message: () => `expected ${received} to be near ${expected}`,
|
|
100
|
+
pass: true
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
return {
|
|
104
|
+
message: () => `expected ${received} to be near ${expected}`,
|
|
105
|
+
pass: false
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
toNearEqualArray (
|
|
110
|
+
this: any,
|
|
111
|
+
received: number[],
|
|
112
|
+
expected: number[],
|
|
113
|
+
tollerance = 0.01
|
|
114
|
+
) {
|
|
115
|
+
const values = received.map((v, i) =>
|
|
116
|
+
nearEquals(v, expected[i], tollerance)
|
|
117
|
+
)
|
|
118
|
+
const pass = values.every(v => v)
|
|
119
|
+
const maybeNot = this.isNot ? 'not ' : ''
|
|
120
|
+
return {
|
|
121
|
+
message: () => `expected ${received} ${maybeNot}to equal ${expected}`,
|
|
122
|
+
pass
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
toColorEqual<
|
|
126
|
+
T extends { equals: (other: T, tollerance?: number) => boolean }
|
|
127
|
+
>(this: any, received: T, expected: T, tollerance = 0.001) {
|
|
128
|
+
const pass = received.equals(expected, tollerance)
|
|
129
|
+
const maybeNot = this.isNot ? 'not ' : ''
|
|
130
|
+
return {
|
|
131
|
+
message: () =>
|
|
132
|
+
`expected ${received} ${maybeNot}to equal ${expected} with tollerance ${tollerance}`,
|
|
133
|
+
pass
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
describe('Channel conversion', () => {
|
|
139
|
+
test('cmyk2rgb', () => {
|
|
140
|
+
expect(Channel.cmyk2rgb([0.6, 0.0, 0.08, 0.07])).toNearEqualArray([
|
|
141
|
+
0.372, 0.93, 0.8556
|
|
142
|
+
])
|
|
143
|
+
})
|
|
144
|
+
test('hsl2hsv', () => {
|
|
145
|
+
expect(Channel.hsl2hsv([172, 0.8, 0.65])).toNearEqualArray([
|
|
146
|
+
172, 0.60215, 0.93
|
|
147
|
+
])
|
|
148
|
+
})
|
|
149
|
+
test('hsv2hsl', () => {
|
|
150
|
+
expect(Channel.hsv2hsl([172, 0.60215, 0.93])).toNearEqualArray([
|
|
151
|
+
172, 0.8, 0.65
|
|
152
|
+
])
|
|
153
|
+
})
|
|
154
|
+
test('hsl2lab', () => {
|
|
155
|
+
expect(Channel.lch2lab([86.07, 42.79865, 183.0])).toNearEqualArray([
|
|
156
|
+
86.07, -42.74, -2.24
|
|
157
|
+
])
|
|
158
|
+
})
|
|
159
|
+
test('hsl2rgb', () => {
|
|
160
|
+
expect(Channel.hsl2rgb([172, 0.8, 0.65])).toNearEqualArray([
|
|
161
|
+
0.37, 0.9299, 0.8553
|
|
162
|
+
])
|
|
163
|
+
})
|
|
164
|
+
test('lab2lch', () => {
|
|
165
|
+
expect(Channel.lab2lch([86.07, -42.74, -2.24])).toNearEqualArray([
|
|
166
|
+
86.07, 42.79865, 183.0
|
|
167
|
+
])
|
|
168
|
+
})
|
|
169
|
+
test('lab2xyz', () => {
|
|
170
|
+
expect(
|
|
171
|
+
Channel.lab2xyz([86.07, -42.74, -2.24], WHITE_REFERENCE)
|
|
172
|
+
).toNearEqualArray([
|
|
173
|
+
47.65533671728852, 68.12717437567908, 77.04768177230773
|
|
174
|
+
])
|
|
175
|
+
})
|
|
176
|
+
test('lch2lab', () => {
|
|
177
|
+
expect(Channel.lch2lab([86, 42.699, 183.024])).toNearEqualArray([
|
|
178
|
+
86.0, -42.64, -2.25
|
|
179
|
+
])
|
|
180
|
+
})
|
|
181
|
+
test('luv2xyz', () => {
|
|
182
|
+
expect(
|
|
183
|
+
Channel.luv2xyz([81.495, -60.109, 95.919], WHITE_REFERENCE)
|
|
184
|
+
).toNearEqualArray([33.727, 59.37, 10.602])
|
|
185
|
+
})
|
|
186
|
+
test('rgb2cmyk', () => {
|
|
187
|
+
expect(Channel.rgb2cmyk([0.372, 0.93, 0.8556])).toNearEqualArray([
|
|
188
|
+
0.6, 0.0, 0.08, 0.07
|
|
189
|
+
])
|
|
190
|
+
})
|
|
191
|
+
test('rgb2hsl', () => {
|
|
192
|
+
expect(Channel.rgb2hsl([0.37, 0.9299, 0.8553])).toNearEqualArray([
|
|
193
|
+
172, 0.8, 0.65
|
|
194
|
+
])
|
|
195
|
+
})
|
|
196
|
+
test('rgb2xyz', () => {
|
|
197
|
+
expect(Channel.rgb2xyz([100 / 255, 230 / 255, 25 / 255])).toNearEqualArray([
|
|
198
|
+
33.727, 59.37, 10.602
|
|
199
|
+
])
|
|
200
|
+
})
|
|
201
|
+
test('xyz2lab', () => {
|
|
202
|
+
expect(
|
|
203
|
+
Channel.xyz2lab([47.6553, 68.1272, 77.0477], WHITE_REFERENCE)
|
|
204
|
+
).toNearEqualArray([86.07001279, -42.74015717, -2.2399919])
|
|
205
|
+
})
|
|
206
|
+
test('xyz2luv', () => {
|
|
207
|
+
expect(
|
|
208
|
+
Channel.xyz2luv([33.727, 59.37, 10.602], WHITE_REFERENCE)
|
|
209
|
+
).toNearEqualArray([81.495, -60.109, 95.919])
|
|
210
|
+
})
|
|
211
|
+
test('xyz2rgb', () => {
|
|
212
|
+
expect(Channel.xyz2rgb([33.727, 59.37, 10.602])).toNearEqualArray([
|
|
213
|
+
100 / 255,
|
|
214
|
+
230 / 255,
|
|
215
|
+
25 / 255
|
|
216
|
+
])
|
|
217
|
+
})
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
const data: Array<[string, HSL, HSLuv, HSV, LAB, LCH, LUV, RGB, SRGB, XYZ]> = [
|
|
221
|
+
[
|
|
222
|
+
'white',
|
|
223
|
+
new HSL(0, 0, 100),
|
|
224
|
+
new HSLuv(0, 0, 100),
|
|
225
|
+
new HSV(0, 0, 100),
|
|
226
|
+
new LAB(100.0, 0.00526049995830391, -0.010408184525267927),
|
|
227
|
+
new LCH(100, 0.011662039483869973, 296.81292623674057),
|
|
228
|
+
new LUV(100, 0.0008906695967064726, -0.01710795288980549), // ?
|
|
229
|
+
new RGB(0xffffff),
|
|
230
|
+
new SRGB(100, 100, 100),
|
|
231
|
+
new XYZ(95.047, 100.00001, 108.883)
|
|
232
|
+
],
|
|
233
|
+
[
|
|
234
|
+
'black',
|
|
235
|
+
new HSL(0, 0, 0),
|
|
236
|
+
new HSLuv(0, 0, 0),
|
|
237
|
+
new HSV(0, 0, 0),
|
|
238
|
+
new LAB(0, 0, 0),
|
|
239
|
+
new LCH(0, 0, 0),
|
|
240
|
+
new LUV(0, 0, 0), // ?
|
|
241
|
+
new RGB(0x000000),
|
|
242
|
+
new SRGB(0, 0, 0),
|
|
243
|
+
new XYZ(0, 0, 0)
|
|
244
|
+
],
|
|
245
|
+
[
|
|
246
|
+
'red',
|
|
247
|
+
new HSL(0, 100, 50),
|
|
248
|
+
new HSLuv(39.99901061253295, 130.2942612189005, 53.24079414130722),
|
|
249
|
+
new HSV(0, 100, 100),
|
|
250
|
+
new LAB(53.24079414130722, 80.09245959641109, 67.20319651585301),
|
|
251
|
+
new LCH(53.24079414130722, 104.55176567686985, 39.99901061253295),
|
|
252
|
+
new LUV(53.23711, 175.00981, 37.7651),
|
|
253
|
+
new RGB(0xff0000),
|
|
254
|
+
new SRGB(100, 0, 0),
|
|
255
|
+
new XYZ(41.24564, 21.26729, 1.93339)
|
|
256
|
+
],
|
|
257
|
+
[
|
|
258
|
+
'blue',
|
|
259
|
+
new HSL(240, 100, 50),
|
|
260
|
+
new HSLuv(306.2849380699878, 180.58923065120075, 32.297010932850725),
|
|
261
|
+
new HSV(240, 100, 100),
|
|
262
|
+
new LAB(32.297010932850725, 79.18751984512224, -107.8601617541481),
|
|
263
|
+
new LCH(32.297010932850725, 133.80761485376166, 306.2849380699878),
|
|
264
|
+
new LUV(32.30087, -9.40241, -130.35109), // ?
|
|
265
|
+
new RGB(0x0000ff),
|
|
266
|
+
new SRGB(0, 0, 100),
|
|
267
|
+
new XYZ(18.04375, 7.2175, 95.03041)
|
|
268
|
+
],
|
|
269
|
+
[
|
|
270
|
+
'orange',
|
|
271
|
+
new HSL(25, 100, 50),
|
|
272
|
+
new HSLuv(53.47833595850165, 111.817148741431, 63.03279007232754),
|
|
273
|
+
new HSV(25, 100, 100),
|
|
274
|
+
new LAB(63.03279007232754, 53.11047037606681, 71.71795303124753),
|
|
275
|
+
new LCH(63.03279007232754, 89.24229294767866, 53.47833595850165),
|
|
276
|
+
new LUV(63.03017, 124.01539, 54.82948), // ?
|
|
277
|
+
new RGB(0xff6a00),
|
|
278
|
+
new SRGB(100, 41.66666666666667, 0),
|
|
279
|
+
new XYZ(46.42513, 31.62627, 3.659886)
|
|
280
|
+
],
|
|
281
|
+
[
|
|
282
|
+
'magenta',
|
|
283
|
+
new HSL(300, 100, 50),
|
|
284
|
+
new HSLuv(328.23496466690494, 98.52676527397858, 60.32421212836874),
|
|
285
|
+
new HSV(300, 100, 100),
|
|
286
|
+
new LAB(60.32421212836874, 98.23431188800397, -60.82489220885008),
|
|
287
|
+
new LCH(60.32421212836874, 115.54067484798533, 328.23496466690494),
|
|
288
|
+
new LUV(60.32273, 84.05559, -108.69637), // ?
|
|
289
|
+
new RGB(0xff00ff),
|
|
290
|
+
new SRGB(100, 0, 100),
|
|
291
|
+
new XYZ(59.28939, 28.48479, 96.9638)
|
|
292
|
+
]
|
|
293
|
+
]
|
|
294
|
+
|
|
295
|
+
describe.each(data)(
|
|
296
|
+
'testing %s',
|
|
297
|
+
(name, hsl, hsluv, hsv, lab, lch, luv, rgb, srgb, xyz) => {
|
|
298
|
+
test(`Convert HSL ${name}`, () => {
|
|
299
|
+
expect(hsl).toColorEqual(hsl)
|
|
300
|
+
expect(hsl2hsluv(hsl)).toColorEqual(hsluv)
|
|
301
|
+
expect(hsl2hsv(hsl)).toColorEqual(hsv)
|
|
302
|
+
expect(hsl2lab(hsl)).toColorEqual(lab)
|
|
303
|
+
expect(hsl2lch(hsl)).toColorEqual(lch)
|
|
304
|
+
expect(hsl2luv(hsl)).toColorEqual(luv, 0.1)
|
|
305
|
+
expect(hsl2rgb(hsl)).toColorEqual(rgb)
|
|
306
|
+
expect(hsl2srgb(hsl)).toColorEqual(srgb)
|
|
307
|
+
expect(hsl2xyz(hsl)).toColorEqual(xyz)
|
|
308
|
+
})
|
|
309
|
+
|
|
310
|
+
test(`Convert HSLuv ${name}`, () => {
|
|
311
|
+
expect(hsluv).toColorEqual(hsluv)
|
|
312
|
+
expect(hsluv2hsl(hsluv)).toColorEqual(hsl)
|
|
313
|
+
expect(hsluv2hsv(hsluv)).toColorEqual(hsv)
|
|
314
|
+
expect(hsluv2lab(hsluv)).toColorEqual(lab)
|
|
315
|
+
expect(hsluv2lch(hsluv)).toColorEqual(lch)
|
|
316
|
+
expect(hsluv2luv(hsluv)).toColorEqual(luv, 0.1)
|
|
317
|
+
expect(hsluv2rgb(hsluv)).toColorEqual(rgb)
|
|
318
|
+
expect(hsluv2srgb(hsluv)).toColorEqual(srgb)
|
|
319
|
+
expect(hsluv2xyz(hsluv)).toColorEqual(xyz)
|
|
320
|
+
})
|
|
321
|
+
|
|
322
|
+
test(`Convert HSV ${name}`, () => {
|
|
323
|
+
expect(hsv).toColorEqual(hsv)
|
|
324
|
+
expect(hsv2hsl(hsv)).toColorEqual(hsl)
|
|
325
|
+
expect(hsv2hsluv(hsv)).toColorEqual(hsluv)
|
|
326
|
+
expect(hsv2lab(hsv)).toColorEqual(lab)
|
|
327
|
+
expect(hsv2lch(hsv)).toColorEqual(lch)
|
|
328
|
+
expect(hsv2luv(hsv)).toColorEqual(luv, 0.1)
|
|
329
|
+
expect(hsv2rgb(hsv)).toColorEqual(rgb)
|
|
330
|
+
expect(hsv2srgb(hsv)).toColorEqual(srgb)
|
|
331
|
+
expect(hsv2xyz(hsv)).toColorEqual(xyz)
|
|
332
|
+
})
|
|
333
|
+
|
|
334
|
+
test(`Convert LAB ${name}`, () => {
|
|
335
|
+
expect(lab).toColorEqual(lab)
|
|
336
|
+
expect(lab2hsl(lab)).toColorEqual(hsl)
|
|
337
|
+
expect(lab2hsluv(lab)).toColorEqual(hsluv)
|
|
338
|
+
expect(lab2hsv(lab)).toColorEqual(hsv, 0.1)
|
|
339
|
+
expect(lab2lch(lab)).toColorEqual(lch)
|
|
340
|
+
expect(lab2luv(lab)).toColorEqual(luv, 0.1)
|
|
341
|
+
expect(lab2rgb(lab)).toColorEqual(rgb)
|
|
342
|
+
expect(lab2srgb(lab)).toColorEqual(srgb)
|
|
343
|
+
expect(lab2xyz(lab)).toColorEqual(xyz, 0.1)
|
|
344
|
+
})
|
|
345
|
+
|
|
346
|
+
test(`Convert LCH ${name}`, () => {
|
|
347
|
+
expect(lch).toColorEqual(lch)
|
|
348
|
+
expect(lch2hsl(lch)).toColorEqual(hsl)
|
|
349
|
+
expect(lch2hsluv(lch)).toColorEqual(hsluv)
|
|
350
|
+
expect(lch2hsv(lch)).toColorEqual(hsv, 0.1)
|
|
351
|
+
expect(lch2lab(lch)).toColorEqual(lab)
|
|
352
|
+
expect(lch2luv(lch)).toColorEqual(luv, 0.1)
|
|
353
|
+
expect(lch2rgb(lch)).toColorEqual(rgb)
|
|
354
|
+
expect(lch2srgb(lch)).toColorEqual(srgb)
|
|
355
|
+
expect(lch2xyz(lch)).toColorEqual(xyz, 0.1)
|
|
356
|
+
})
|
|
357
|
+
|
|
358
|
+
test(`Convert LUV ${name}`, () => {
|
|
359
|
+
expect(luv).toColorEqual(luv)
|
|
360
|
+
expect(luv2hsl(luv)).toColorEqual(hsl, 0.1)
|
|
361
|
+
expect(luv2hsluv(luv)).toColorEqual(hsluv, 0.1)
|
|
362
|
+
expect(luv2hsv(luv)).toColorEqual(hsv, 0.1)
|
|
363
|
+
expect(luv2lab(luv)).toColorEqual(lab, 0.1)
|
|
364
|
+
expect(luv2lch(luv)).toColorEqual(lch, 0.1)
|
|
365
|
+
expect(luv2rgb(luv)).toColorEqual(rgb, 0.1)
|
|
366
|
+
expect(luv2srgb(luv)).toColorEqual(srgb, 0.1)
|
|
367
|
+
expect(luv2xyz(luv)).toColorEqual(xyz, 0.1)
|
|
368
|
+
})
|
|
369
|
+
|
|
370
|
+
test(`Convert RGB ${name}`, () => {
|
|
371
|
+
expect(rgb).toColorEqual(rgb)
|
|
372
|
+
expect(rgb2hsl(rgb)).toColorEqual(hsl, 0.2)
|
|
373
|
+
expect(rgb2hsluv(rgb)).toColorEqual(hsluv, 0.2)
|
|
374
|
+
expect(rgb2hsv(rgb)).toColorEqual(hsv, 0.2)
|
|
375
|
+
expect(rgb2lab(rgb)).toColorEqual(lab, 0.2)
|
|
376
|
+
expect(rgb2lch(rgb)).toColorEqual(lch, 0.2)
|
|
377
|
+
expect(rgb2luv(rgb)).toColorEqual(luv, 0.5)
|
|
378
|
+
expect(rgb2srgb(rgb)).toColorEqual(srgb, 0.2)
|
|
379
|
+
expect(rgb2xyz(rgb)).toColorEqual(xyz, 0.2)
|
|
380
|
+
})
|
|
381
|
+
|
|
382
|
+
test(`Convert sRGB ${name}`, () => {
|
|
383
|
+
expect(srgb).toColorEqual(srgb)
|
|
384
|
+
expect(srgb2hsl(srgb)).toColorEqual(hsl)
|
|
385
|
+
expect(srgb2hsluv(srgb)).toColorEqual(hsluv)
|
|
386
|
+
expect(srgb2hsv(srgb)).toColorEqual(hsv)
|
|
387
|
+
expect(srgb2lab(srgb)).toColorEqual(lab)
|
|
388
|
+
expect(srgb2lch(srgb)).toColorEqual(lch)
|
|
389
|
+
expect(srgb2luv(srgb)).toColorEqual(luv, 0.1)
|
|
390
|
+
expect(srgb2rgb(srgb)).toColorEqual(rgb)
|
|
391
|
+
expect(srgb2xyz(srgb)).toColorEqual(xyz)
|
|
392
|
+
})
|
|
393
|
+
|
|
394
|
+
test(`Convert XYZ ${name}`, () => {
|
|
395
|
+
expect(xyz).toColorEqual(xyz)
|
|
396
|
+
expect(xyz2hsl(xyz)).toColorEqual(hsl)
|
|
397
|
+
expect(xyz2hsluv(xyz)).toColorEqual(hsluv)
|
|
398
|
+
expect(xyz2hsv(xyz)).toColorEqual(hsv)
|
|
399
|
+
expect(xyz2lab(xyz)).toColorEqual(lab)
|
|
400
|
+
expect(xyz2lch(xyz)).toColorEqual(lch)
|
|
401
|
+
expect(xyz2luv(xyz)).toColorEqual(luv, 0.1)
|
|
402
|
+
expect(xyz2rgb(xyz)).toColorEqual(rgb)
|
|
403
|
+
expect(xyz2srgb(xyz)).toColorEqual(srgb)
|
|
404
|
+
})
|
|
405
|
+
}
|
|
406
|
+
)
|
package/test/commmon.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface Union1 { type: 'Union1', v1: number }
|
|
2
|
+
export interface Union2 { type: 'Union2', v2: boolean }
|
|
3
|
+
export interface Union3 { type: 'Union3', v3: string }
|
|
4
|
+
|
|
5
|
+
export type Union = Union1 | Union2 | Union3
|
|
6
|
+
|
|
7
|
+
export const makeUnion1 = (v1: number): Union1 => ({ type: 'Union1', v1 })
|
|
8
|
+
export const makeUnion2 = (v2: boolean): Union2 => ({ type: 'Union2', v2 })
|
|
9
|
+
export const makeUnion3 = (v3: string): Union3 => ({ type: 'Union3', v3 })
|
|
@@ -0,0 +1,165 @@
|
|
|
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 { strictEqual, deepEqual, looseEqual } from '../src/equals'
|
|
16
|
+
|
|
17
|
+
describe('equals', () => {
|
|
18
|
+
test('strictEqual with number', () => {
|
|
19
|
+
expect(strictEqual(1, 1)).toBe(true)
|
|
20
|
+
expect(strictEqual(0, 0)).toBe(true)
|
|
21
|
+
expect(strictEqual(-1, -1)).toBe(true)
|
|
22
|
+
|
|
23
|
+
expect(strictEqual(Math.E, Math.E)).toBe(true)
|
|
24
|
+
expect(strictEqual(Math.LN10, Math.LN10)).toBe(true)
|
|
25
|
+
expect(strictEqual(Math.LN2, Math.LN2)).toBe(true)
|
|
26
|
+
expect(strictEqual(Math.LOG10E, Math.LOG10E)).toBe(true)
|
|
27
|
+
expect(strictEqual(Math.PI, Math.PI)).toBe(true)
|
|
28
|
+
expect(strictEqual(Math.SQRT1_2, Math.SQRT1_2)).toBe(true)
|
|
29
|
+
expect(strictEqual(Math.SQRT2, Math.SQRT2)).toBe(true)
|
|
30
|
+
|
|
31
|
+
expect(strictEqual(Infinity, Infinity)).toBe(true)
|
|
32
|
+
expect(strictEqual(-Infinity, -Infinity)).toBe(true)
|
|
33
|
+
expect(strictEqual(NaN, NaN)).toBe(true)
|
|
34
|
+
|
|
35
|
+
expect(strictEqual(-Infinity, Infinity)).toBe(false)
|
|
36
|
+
expect(strictEqual(-1, 1)).toBe(false)
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
test('strictEqual with string', () => {
|
|
40
|
+
expect(strictEqual('', '')).toBe(true)
|
|
41
|
+
expect(strictEqual('a', 'a')).toBe(true)
|
|
42
|
+
|
|
43
|
+
expect(strictEqual('A', 'a')).toBe(false)
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
test('strictEqual with date', () => {
|
|
47
|
+
const a = new Date('2020-01-02')
|
|
48
|
+
const b = new Date('2020-01-02')
|
|
49
|
+
expect(strictEqual(a, a)).toBe(true)
|
|
50
|
+
expect(strictEqual(a, b)).toBe(false)
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
test('deepEqual with number', () => {
|
|
54
|
+
expect(deepEqual(1, 1)).toBe(true)
|
|
55
|
+
expect(deepEqual(0, 0)).toBe(true)
|
|
56
|
+
expect(deepEqual(-1, -1)).toBe(true)
|
|
57
|
+
|
|
58
|
+
expect(deepEqual(Math.E, Math.E)).toBe(true)
|
|
59
|
+
expect(deepEqual(Math.LN10, Math.LN10)).toBe(true)
|
|
60
|
+
expect(deepEqual(Math.LN2, Math.LN2)).toBe(true)
|
|
61
|
+
expect(deepEqual(Math.LOG10E, Math.LOG10E)).toBe(true)
|
|
62
|
+
expect(deepEqual(Math.PI, Math.PI)).toBe(true)
|
|
63
|
+
expect(deepEqual(Math.SQRT1_2, Math.SQRT1_2)).toBe(true)
|
|
64
|
+
expect(deepEqual(Math.SQRT2, Math.SQRT2)).toBe(true)
|
|
65
|
+
|
|
66
|
+
expect(deepEqual(Infinity, Infinity)).toBe(true)
|
|
67
|
+
expect(deepEqual(-Infinity, -Infinity)).toBe(true)
|
|
68
|
+
expect(deepEqual(NaN, NaN)).toBe(true)
|
|
69
|
+
|
|
70
|
+
expect(deepEqual(-Infinity, Infinity)).toBe(false)
|
|
71
|
+
expect(deepEqual(-1, 1)).toBe(false)
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
test('deepEqual with string', () => {
|
|
75
|
+
expect(deepEqual('', '')).toBe(true)
|
|
76
|
+
expect(deepEqual('a', 'a')).toBe(true)
|
|
77
|
+
|
|
78
|
+
expect(deepEqual('A', 'a')).toBe(false)
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
test('deepEqual with date', () => {
|
|
82
|
+
const a = new Date('2020-01-01')
|
|
83
|
+
const b = new Date('2020-01-01')
|
|
84
|
+
const c = new Date('2020-01-02')
|
|
85
|
+
expect(deepEqual(a, a)).toBe(true)
|
|
86
|
+
expect(deepEqual(a, b)).toBe(true)
|
|
87
|
+
expect(deepEqual(a, c)).toBe(false)
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
test('deepEqual with arrays', () => {
|
|
91
|
+
const a = [1, 'a']
|
|
92
|
+
const b = [1, 'a']
|
|
93
|
+
const c = [1, 2]
|
|
94
|
+
expect(deepEqual(a, a)).toBe(true)
|
|
95
|
+
expect(deepEqual(a, b)).toBe(true)
|
|
96
|
+
expect(deepEqual(a, c)).toBe(false)
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
test('deepEqual with objects', () => {
|
|
100
|
+
const a = { a: 1, b: 'b' }
|
|
101
|
+
const b = { a: 1, b: 'b' }
|
|
102
|
+
const c = { a: 1, b: 2 } as never
|
|
103
|
+
const d = { a: 1, b: 'b', c: undefined }
|
|
104
|
+
const e = { a: 1, b: 'b', c: undefined }
|
|
105
|
+
const f = { a: 1, b: 'b', c: null } as Record<string, unknown>
|
|
106
|
+
expect(deepEqual(a, a)).toBe(true)
|
|
107
|
+
expect(deepEqual(a, b)).toBe(true)
|
|
108
|
+
expect(deepEqual(a, c)).toBe(false)
|
|
109
|
+
expect(deepEqual(a, d)).toBe(false)
|
|
110
|
+
expect(deepEqual(f, e)).toBe(false)
|
|
111
|
+
expect(deepEqual(f, { ...f } as never)).toBe(true)
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
test('deepEqual with deep structures', () => {
|
|
115
|
+
const get = () => ({
|
|
116
|
+
a: 1,
|
|
117
|
+
b: {
|
|
118
|
+
c: undefined,
|
|
119
|
+
d: '1',
|
|
120
|
+
e: new Date('2020-01-01'),
|
|
121
|
+
f: [1, { g: true }]
|
|
122
|
+
}
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
expect(deepEqual(get(), get())).toBe(true)
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
test('deepEqual with Set', () => {
|
|
129
|
+
const get = () => new Set([1, 2, 3])
|
|
130
|
+
const get2 = () => new Set([1, 2, 4])
|
|
131
|
+
|
|
132
|
+
expect(deepEqual(get(), get())).toBe(true)
|
|
133
|
+
expect(deepEqual(get(), get2())).toBe(false)
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
test('deepEqual with Map', () => {
|
|
137
|
+
const get = () => {
|
|
138
|
+
const map = new Map()
|
|
139
|
+
map.set(1, 'a')
|
|
140
|
+
map.set(2, 'b')
|
|
141
|
+
map.set(3, 'c')
|
|
142
|
+
return map
|
|
143
|
+
}
|
|
144
|
+
const get2 = () => {
|
|
145
|
+
const map = new Map()
|
|
146
|
+
map.set(1, 'a')
|
|
147
|
+
map.set(2, 'b')
|
|
148
|
+
map.set(3, 'd')
|
|
149
|
+
return map
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
expect(deepEqual(get(), get())).toBe(true)
|
|
153
|
+
expect(deepEqual(get(), get2())).toBe(false)
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
test('looseEqual matches expectations', () => {
|
|
157
|
+
expect(looseEqual(1, 1)).toBe(true)
|
|
158
|
+
expect(looseEqual(1, 0)).toBe(false)
|
|
159
|
+
expect(looseEqual(null, null)).toBe(true)
|
|
160
|
+
expect(looseEqual(null, undefined)).toBe(true)
|
|
161
|
+
expect(looseEqual(null, '')).toBe(false)
|
|
162
|
+
expect(looseEqual(null, 0)).toBe(false)
|
|
163
|
+
expect(looseEqual('', 0 as unknown as string)).toBe(true)
|
|
164
|
+
})
|
|
165
|
+
})
|
package/test/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export {}
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
namespace jest {
|
|
5
|
+
interface Matchers<R> {
|
|
6
|
+
toColorEqual<T>(value: T, precision?: number): R
|
|
7
|
+
toNearEqual(value: number): R
|
|
8
|
+
toNearEqualArray(value: [number, number, number]): R
|
|
9
|
+
toNearEqualArray(value: number[]): R
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
namespace vitest {
|
|
13
|
+
interface Matchers<R> {
|
|
14
|
+
toColorEqual<T>(value: T, precision?: number): R
|
|
15
|
+
toNearEqual(value: number): R
|
|
16
|
+
toNearEqualArray(value: [number, number, number]): R
|
|
17
|
+
toNearEqualArray(value: number[]): R
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { sameKeys, isObject } from '../src/objects'
|
|
2
|
+
import { describe, expect, test } from 'vitest'
|
|
3
|
+
|
|
4
|
+
describe('objects helpers', () => {
|
|
5
|
+
test('sameKeys works as expected', () => {
|
|
6
|
+
expect(sameKeys({}, {})).toBe(true)
|
|
7
|
+
expect(sameKeys({ a: 1 }, { a: 2 })).toBe(true)
|
|
8
|
+
expect(sameKeys({ a: 1, b: 'c' }, { a: 2, b: true })).toBe(true)
|
|
9
|
+
expect(sameKeys({ a: 1 }, { a: 2, b: true })).toBe(false)
|
|
10
|
+
expect(sameKeys({ a: 1 }, { b: true })).toBe(false)
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
test('isObject behaves as expected', () => {
|
|
14
|
+
expect(isObject({})).toBe(true)
|
|
15
|
+
expect(isObject({ 1: 2 })).toBe(true)
|
|
16
|
+
expect(isObject({ a: 2 })).toBe(true)
|
|
17
|
+
expect(isObject(null)).toBe(false)
|
|
18
|
+
expect(isObject(undefined)).toBe(false)
|
|
19
|
+
expect(isObject(Array.from([1, 2]))).toBe(false)
|
|
20
|
+
expect(isObject('v')).toBe(false)
|
|
21
|
+
})
|
|
22
|
+
})
|
|
@@ -0,0 +1,33 @@
|
|
|
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 { map } from '../src/reg-exps'
|
|
15
|
+
import { describe, expect, test } from 'vitest'
|
|
16
|
+
|
|
17
|
+
describe('reg_exps.ts', () => {
|
|
18
|
+
test('Map with non-global pattern', () => {
|
|
19
|
+
const pattern = /xx|yyy/
|
|
20
|
+
expect(map('axxbbyyyc', pattern, v => v.toUpperCase())).toBe('aXXbbYYYc')
|
|
21
|
+
expect(map('xxbbyyy', pattern, v => v.toUpperCase())).toBe('XXbbYYY')
|
|
22
|
+
expect(map('xx', pattern, v => v.toUpperCase())).toBe('XX')
|
|
23
|
+
expect(map('x', pattern, v => v.toUpperCase())).toBe('x')
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
test('Map with global pattern', () => {
|
|
27
|
+
const pattern = /xx|yyy/g
|
|
28
|
+
expect(map('axxbbyyyc', pattern, v => v.toUpperCase())).toBe('aXXbbYYYc')
|
|
29
|
+
expect(map('xxbbyyy', pattern, v => v.toUpperCase())).toBe('XXbbYYY')
|
|
30
|
+
expect(map('xx', pattern, v => v.toUpperCase())).toBe('XX')
|
|
31
|
+
expect(map('x', pattern, v => v.toUpperCase())).toBe('x')
|
|
32
|
+
})
|
|
33
|
+
})
|