generated from mvllow/package
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
43 lines (36 loc) · 1011 Bytes
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import test from 'ava'
import colorish from '../source/index.js'
const stuff = {iris: '#c4a7e7', gold: '#f6c177'}
const nestedStuff = {stuff}
test('converts hex value', (t) => {
t.is(colorish('fa8072', 0.5), '#fa807280')
t.is(colorish('#fa8072', 0.01), '#fa807203')
})
test('converts short hex value', (t) => {
t.is(colorish('c00', 0.5), '#cc000080')
t.is(colorish('#c00', 0.5), '#cc000080')
})
test('converts object of hex values', (t) => {
t.deepEqual(colorish(stuff, 0.5), {
iris: '#c4a7e780',
gold: '#f6c17780',
})
})
test('converts deep object of hex values', (t) => {
t.deepEqual(colorish(nestedStuff, 0.5), {
stuff: {iris: '#c4a7e780', gold: '#f6c17780'},
})
})
test('callback applies to each value', (t) => {
t.deepEqual(
colorish(stuff, 0.5, (value) => `${value}_modified`),
{
iris: '#c4a7e780_modified',
gold: '#f6c17780_modified',
}
)
})
test('rejects non-hex values', (t) => {
t.throws(() => colorish('%fa8072', 0.5))
t.throws(() => colorish('#ga8072', 0.5))
})