File: index.js

package info (click to toggle)
node-colormin 1.1.2-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 220 kB
  • sloc: makefile: 4
file content (46 lines) | stat: -rw-r--r-- 3,886 bytes parent folder | download
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
44
45
46
const test = require('tape');
const min = require('../..');

function isEqual (t, input, output, options = {}) {
    t.deepEqual(min(input, options), output);
    t.end();
}

test('should lowercase keywords', function(t) {isEqual(t, 'RED', 'red')});
test('should convert shorthand hex to keyword', function(t) {isEqual(t, '#f00', 'red')});
test('should convert longhand hex to keyword', function(t) {isEqual(t, '#ff0000', 'red')});
test('should convert rgb to keyword', function(t) {isEqual(t, 'rgb(255,0,0)', 'red')});
test('should convert fully opaque rgb to keyword', function(t) {isEqual(t, 'rgba(255, 0, 0, 1)', 'red')});
test('should convert hsl to keyword', function(t) {isEqual(t, 'hsl(0, 100%, 50%)', 'red')});
test('should convert fully oqaque hsl to keyword', function(t) {isEqual(t, 'hsla(0, 100%, 50%, 1)', 'red')});
test('should convert translucent hsla to rgba', function(t) {isEqual(t, 'hsla(0, 100%, 50%, .5)', 'rgba(255,0,0,.5)')});
test('should convert longhand hex to shorthand, case insensitive', function(t) {isEqual(t, '#FFFFFF', '#fff')});
test('should convert keyword to hex, case insensitive', function(t) {isEqual(t, 'WHiTE', '#fff')});
test('should convert keyword to hex', function(t) {isEqual(t, 'yellow', '#ff0')});
test('should convert rgb to hex', function(t) {isEqual(t, 'rgb(12, 134, 29)', '#0c861d')});
test('should convert hsl to hex', function(t) {isEqual(t, 'hsl(230, 50%, 40%)', '#349')});
test('should convert another longhand hex to keyword', function(t) {isEqual(t, '#000080', 'navy')});
test('should convert rgba to hsla when shorter', function(t) {isEqual(t, 'rgba(199, 190, 179, 0.8)', 'hsla(33,15%,74%,.8)')});
test('should convert this specific rgba value to "transparent"', function(t) {isEqual(t, 'rgba(0,0,0,0)', 'transparent')});
test('should not convert this specific rgba value to "transparent" (legacy mode)', function(t) {isEqual(t, 'rgba(0,0,0,0)', 'rgba(0,0,0,0)', {legacy: true})});
test('should convert this specific hsla value to "transparent"', function(t) {isEqual(t, 'hsla(0,0%,0%,0)', 'transparent')});
test('should convert hsla values with 0 saturation & 0 lightness to "transparent"', function(t) {isEqual(t, 'hsla(200,0%,0%,0)', 'transparent')});
test('should leave transparent as it is', function(t) {isEqual(t, 'transparent', 'transparent')});
test('should prefer to output hex rather than keywords when they are the same length', function(t) {isEqual(t, '#696969', '#696969')});
test('should cap values at their maximum', function(t) {isEqual(t, 'rgb(400,400,400)', '#fff')});
test('should cap values at their maximum (2)', function(t) {isEqual(t, 'hsl(400, 400%, 50%)', 'red')});
test('should remove leading zeros', function(t) {isEqual(t, 'hsla(0, 0%, 100%, 0.5)', 'hsla(0,0%,100%,.5)')});
test('should convert signed numbers', function(t) {isEqual(t, 'rgba(-100,0,-100,.5)', 'rgba(0,0,0,.5)')});
test('should convert signed numbers (2)', function(t) {isEqual(t, 'hsla(-400,50%,10%,.5)', 'rgba(38,13,13,.5)')});
test('should convert percentage based rgb values', function(t) {isEqual(t, 'rgb(100%,100%,100%)', '#fff')});
test('should convert percentage based rgba values (2)', function(t) {isEqual(t, 'rgba(50%,50%,50%,0.5)', 'hsla(0,0%,50%,.5)')});
test('should convert percentage based rgba values (3)', function(t) {isEqual(t, 'rgb(100%,100%,100%)', '#fff')});
test('should convert percentage based rgba values (4)', function(t) {isEqual(t, 'rgba(100%,100%,100%,0.5)', 'hsla(0,0%,100%,.5)')});
test('should convert percentage based rgba values (5)', function(t) {isEqual(t, 'rgba(100%,64.7%,0%,.5)', 'rgba(255,165,0,.5)')});
test('should pass through on invalid rgb functions', function(t) {isEqual(t, 'rgb(50%,23,54)', 'rgb(50%,23,54)')});

test('should pass through if not recognised', t => {
    t.deepEqual(min('Unrecognised'), 'Unrecognised');
    t.deepEqual(min('inherit'), 'inherit');
    t.end();
});