From 856d8bbb028309b2c47f22b0c37a3c2cb52efd8e Mon Sep 17 00:00:00 2001 From: Dmitry Iv Date: Tue, 22 Aug 2023 11:46:05 -0400 Subject: [PATCH 1/4] Get rid of CJS, introduce oklch --- index.js | 211 +++++++++++++++++++------------------------- index.mjs | 170 ----------------------------------- package.json | 13 ++- readme.md | 26 +++--- test.mjs => test.js | 49 +++++++++- 5 files changed, 157 insertions(+), 312 deletions(-) delete mode 100644 index.mjs rename test.mjs => test.js (88%) diff --git a/index.js b/index.js index 9609eec..3861af2 100644 --- a/index.js +++ b/index.js @@ -1,12 +1,9 @@ /** * @module color-parse */ +import names from 'color-name' -'use strict' - -var names = require('color-name') - -module.exports = parse +export default parse /** * Base hues @@ -30,139 +27,111 @@ var baseHues = { function parse(cstr) { var m, parts = [], alpha = 1, space - if (typeof cstr === 'string') { - cstr = cstr.toLowerCase(); - - //keyword - if (names[cstr]) { - parts = names[cstr].slice() - space = 'rgb' - } - - //reserved words - else if (cstr === 'transparent') { - alpha = 0 - space = 'rgb' - parts = [0, 0, 0] - } - - //hex - else if (/^#[A-Fa-f0-9]+$/.test(cstr)) { - var base = cstr.slice(1) - var size = base.length - var isShort = size <= 4 - alpha = 1 - - if (isShort) { - parts = [ - parseInt(base[0] + base[0], 16), - parseInt(base[1] + base[1], 16), - parseInt(base[2] + base[2], 16) - ] - if (size === 4) { - alpha = parseInt(base[3] + base[3], 16) / 255 - } - } - else { - parts = [ - parseInt(base[0] + base[1], 16), - parseInt(base[2] + base[3], 16), - parseInt(base[4] + base[5], 16) - ] - if (size === 8) { - alpha = parseInt(base[6] + base[7], 16) / 255 - } - } - - if (!parts[0]) parts[0] = 0 - if (!parts[1]) parts[1] = 0 - if (!parts[2]) parts[2] = 0 - - space = 'rgb' - } - - //color space - else if (m = /^((?:rgb|hs[lvb]|hwb|cmyk?|xy[zy]|gray|lab|lchu?v?|[ly]uv|lms)a?)\s*\(([^\)]*)\)/.exec(cstr)) { - var name = m[1] - var isRGB = name === 'rgb' - var base = name.replace(/a$/, '') - space = base - var size = base === 'cmyk' ? 4 : base === 'gray' ? 1 : 3 - parts = m[2].trim() - .split(/\s*[,\/]\s*|\s+/) - .map(function (x, i) { - // - if (/%$/.test(x)) { - //alpha - if (i === size) return parseFloat(x) / 100 - //rgb - if (base === 'rgb') return parseFloat(x) * 255 / 100 - return parseFloat(x) - } - //hue - else if (base[i] === 'h') { - // - if (/deg$/.test(x)) { - return parseFloat(x) - } - // - else if (baseHues[x] !== undefined) { - return baseHues[x] - } - } - return parseFloat(x) - }) - - if (name === base) parts.push(1) - alpha = (isRGB) ? 1 : (parts[size] === undefined) ? 1 : parts[size] - parts = parts.slice(0, size) - } - - //named channels case - else if (cstr.length > 10 && /[0-9](?:\s|\/)/.test(cstr)) { - parts = cstr.match(/([0-9]+)/g).map(function (value) { - return parseFloat(value) - }) - - space = cstr.match(/([a-z])/ig).join('').toLowerCase() - } + //numeric case + if (typeof cstr === 'number') { + return { space: 'rgb', values: [cstr >>> 16, (cstr & 0x00ff00) >>> 8, cstr & 0x0000ff], alpha: 1 } } - //numeric case - else if (!isNaN(cstr)) { + cstr = String(cstr).toLowerCase(); + + //keyword + if (names[cstr]) { + parts = names[cstr].slice() space = 'rgb' - parts = [cstr >>> 16, (cstr & 0x00ff00) >>> 8, cstr & 0x0000ff] } - //array-like - else if (Array.isArray(cstr) || cstr.length) { - parts = [cstr[0], cstr[1], cstr[2]] + //reserved words + else if (cstr === 'transparent') { + alpha = 0 space = 'rgb' - alpha = cstr.length === 4 ? cstr[3] : 1 + parts = [0, 0, 0] } - //object case - detects css cases of rgb and hsl - else if (cstr instanceof Object) { - if (cstr.r != null || cstr.red != null || cstr.R != null) { - space = 'rgb' + //hex + else if (/^#[A-Fa-f0-9]+$/.test(cstr)) { + var base = cstr.slice(1) + var size = base.length + var isShort = size <= 4 + alpha = 1 + + if (isShort) { parts = [ - cstr.r || cstr.red || cstr.R || 0, - cstr.g || cstr.green || cstr.G || 0, - cstr.b || cstr.blue || cstr.B || 0 + parseInt(base[0] + base[0], 16), + parseInt(base[1] + base[1], 16), + parseInt(base[2] + base[2], 16) ] + if (size === 4) { + alpha = parseInt(base[3] + base[3], 16) / 255 + } } else { - space = 'hsl' parts = [ - cstr.h || cstr.hue || cstr.H || 0, - cstr.s || cstr.saturation || cstr.S || 0, - cstr.l || cstr.lightness || cstr.L || cstr.b || cstr.brightness + parseInt(base[0] + base[1], 16), + parseInt(base[2] + base[3], 16), + parseInt(base[4] + base[5], 16) ] + if (size === 8) { + alpha = parseInt(base[6] + base[7], 16) / 255 + } } - alpha = cstr.a || cstr.alpha || cstr.opacity || 1 + if (!parts[0]) parts[0] = 0 + if (!parts[1]) parts[1] = 0 + if (!parts[2]) parts[2] = 0 + + space = 'rgb' + } + + //color space + else if (m = /^((?:rgba?|hs[lvb]a?|hwba?|cmyk?|xy[zy]|gray|lab|lchu?v?|[ly]uv|lms|oklch|oklab))\s*\(([^\)]*)\)/.exec(cstr)) { + var name = m[1] + var isRGB = name === 'rgb' + var base = name.replace(/a$/, '') + space = base + var size = base === 'cmyk' ? 4 : base === 'gray' ? 1 : 3 + parts = m[2].trim() + .split(/\s*[,\/]\s*|\s+/) + .map(function (x, i) { + // + if (x[x.length - 1] === '%') { + //alpha + if (i === 4) return parseFloat(x) / 100 + //rgb + if (base === 'rgb') return parseFloat(x) * 255 / 100 + // lch/oklch + if (/^(ok)?l/.test(base)) { + if (!i) return parseFloat(x) / 100 + return parseFloat(x) * 0.4 / 100 + } + return parseFloat(x) + } + //hue + if (base[i] === 'h') { + // + if (/deg$/.test(x)) { + return parseFloat(x) + } + // + else if (baseHues[x] !== undefined) { + return baseHues[x] + } + } + if (x === 'none') return 0 + return parseFloat(x) + }) + + if (name === base) parts.push(1) + alpha = (isRGB) ? 1 : (parts[size] === undefined) ? 1 : parts[size] + parts = parts.slice(0, size) + } + + //named channels case + else if (cstr.length > 10 && /[0-9](?:\s|\/)/.test(cstr)) { + parts = cstr.match(/([0-9]+)/g).map(function (value) { + return parseFloat(value) + }) - if (cstr.opacity != null) alpha /= 100 + space = cstr.match(/([a-z])/ig).join('').toLowerCase() } return { diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 8e58193..0000000 --- a/index.mjs +++ /dev/null @@ -1,170 +0,0 @@ -/** - * @module color-parse - */ -import names from 'color-name' - -export default parse - -/** - * Base hues - * http://dev.w3.org/csswg/css-color/#typedef-named-hue - */ -//FIXME: use external hue detector -var baseHues = { - red: 0, - orange: 60, - yellow: 120, - green: 180, - blue: 240, - purple: 300 -} - -/** - * Parse color from the string passed - * - * @return {Object} A space indicator `space`, an array `values` and `alpha` - */ -function parse(cstr) { - var m, parts = [], alpha = 1, space - - if (typeof cstr === 'string') { - cstr = cstr.toLowerCase(); - - //keyword - if (names[cstr]) { - parts = names[cstr].slice() - space = 'rgb' - } - - //reserved words - else if (cstr === 'transparent') { - alpha = 0 - space = 'rgb' - parts = [0, 0, 0] - } - - //hex - else if (/^#[A-Fa-f0-9]+$/.test(cstr)) { - var base = cstr.slice(1) - var size = base.length - var isShort = size <= 4 - alpha = 1 - - if (isShort) { - parts = [ - parseInt(base[0] + base[0], 16), - parseInt(base[1] + base[1], 16), - parseInt(base[2] + base[2], 16) - ] - if (size === 4) { - alpha = parseInt(base[3] + base[3], 16) / 255 - } - } - else { - parts = [ - parseInt(base[0] + base[1], 16), - parseInt(base[2] + base[3], 16), - parseInt(base[4] + base[5], 16) - ] - if (size === 8) { - alpha = parseInt(base[6] + base[7], 16) / 255 - } - } - - if (!parts[0]) parts[0] = 0 - if (!parts[1]) parts[1] = 0 - if (!parts[2]) parts[2] = 0 - - space = 'rgb' - } - - //color space - else if (m = /^((?:rgb|hs[lvb]|hwb|cmyk?|xy[zy]|gray|lab|lchu?v?|[ly]uv|lms)a?)\s*\(([^\)]*)\)/.exec(cstr)) { - var name = m[1] - var isRGB = name === 'rgb' - var base = name.replace(/a$/, '') - space = base - var size = base === 'cmyk' ? 4 : base === 'gray' ? 1 : 3 - parts = m[2].trim() - .split(/\s*[,\/]\s*|\s+/) - .map(function (x, i) { - // - if (/%$/.test(x)) { - //alpha - if (i === size) return parseFloat(x) / 100 - //rgb - if (base === 'rgb') return parseFloat(x) * 255 / 100 - return parseFloat(x) - } - //hue - else if (base[i] === 'h') { - // - if (/deg$/.test(x)) { - return parseFloat(x) - } - // - else if (baseHues[x] !== undefined) { - return baseHues[x] - } - } - return parseFloat(x) - }) - - if (name === base) parts.push(1) - alpha = (isRGB) ? 1 : (parts[size] === undefined) ? 1 : parts[size] - parts = parts.slice(0, size) - } - - //named channels case - else if (cstr.length > 10 && /[0-9](?:\s|\/)/.test(cstr)) { - parts = cstr.match(/([0-9]+)/g).map(function (value) { - return parseFloat(value) - }) - - space = cstr.match(/([a-z])/ig).join('').toLowerCase() - } - } - - //numeric case - else if (!isNaN(cstr)) { - space = 'rgb' - parts = [cstr >>> 16, (cstr & 0x00ff00) >>> 8, cstr & 0x0000ff] - } - - //array-like - else if (Array.isArray(cstr) || cstr.length) { - parts = [cstr[0], cstr[1], cstr[2]] - space = 'rgb' - alpha = cstr.length === 4 ? cstr[3] : 1 - } - - //object case - detects css cases of rgb and hsl - else if (cstr instanceof Object) { - if (cstr.r != null || cstr.red != null || cstr.R != null) { - space = 'rgb' - parts = [ - cstr.r || cstr.red || cstr.R || 0, - cstr.g || cstr.green || cstr.G || 0, - cstr.b || cstr.blue || cstr.B || 0 - ] - } - else { - space = 'hsl' - parts = [ - cstr.h || cstr.hue || cstr.H || 0, - cstr.s || cstr.saturation || cstr.S || 0, - cstr.l || cstr.lightness || cstr.L || cstr.b || cstr.brightness - ] - } - - alpha = cstr.a || cstr.alpha || cstr.opacity || 1 - - if (cstr.opacity != null) alpha /= 100 - } - - return { - space: space, - values: parts, - alpha: alpha - } -} diff --git a/package.json b/package.json index 039d448..048e2ba 100644 --- a/package.json +++ b/package.json @@ -4,13 +4,10 @@ "description": "Color string parser", "main": "index.js", "browser": "index.js", - "module": "./index.mjs", - "exports": { - "require": "./index.js", - "import": "./index.mjs" - }, + "module": "./index.js", + "type": "module", "scripts": { - "test": "node test.mjs" + "test": "node test.js" }, "repository": { "type": "git", @@ -22,7 +19,7 @@ "color-parse", "color-string" ], - "author": "Deema Ywanov ", + "author": "Dmitry Ivanov ", "license": "MIT", "bugs": { "url": "https://github.com/colorjs/color-parse/issues" @@ -34,4 +31,4 @@ "devDependencies": { "tape": "^4.7.0" } -} +} \ No newline at end of file diff --git a/readme.md b/readme.md index 8eccf23..7fc1109 100644 --- a/readme.md +++ b/readme.md @@ -17,30 +17,32 @@ parse('hsla(12 10% 50% / .3)') * [x] `#RGB[A]` * [x] `#RRGGBB[AA]` * [x] `rgb[a](R, G, B[, A])` -* [x] `rgb[a](R G B[ / A])` +* [x] `rgb(R G B[ / A])` * [x] `hsl[a](H, S, L[, A])`, inc. [named hues](http://dev.w3.org/csswg/css-color/#simple-hues) -* [x] `hsl[a](H S L [ / A])` +* [x] `hsl(H S L [ / A])` * [x] `hwb(H, W, B)` * [x] `cmyk(C, M, Y, K)` * [x] `xyz(X, Y, Z)` * [x] `lab(L, A, B)` +* [ ] `lab(L a b[ / A])` * [x] `lch(L, C, H)` +* [ ] `lch(L C H[ / A])` +* [ ] `oklch(L C H[ / A])` +* [x] `oklab(L a b[ / A])` * [x] `luv(L, U, V)` +* [ ] `luv(L U V[ / A])` +* [ ] `color(space c1 c2 c3[ / A])` * [x] `R:10 G:20 B:30` * [x] `(R10 / G20 / B30)` * [x] `C100/M80/Y0/K35` +* [ ] `[10, 20, 20]` as RGB +* [ ] `10,20,20` as RGB +* [x] `0x00ff00`, `0x0000ff` numbers as RGB -## Parsed not strings +## Not parsed -* [x] `[10, 20, 20]` as RGB color space -* [x] `{r: 10, g: 20, b: 30}` -* [x] `{red: 10, green: 20, blue: 30}` -* [x] `{h: 10, s: 20, l: 30}` -* [x] `0x00ff00`, `0x0000ff` numbers - -## Not parsed strings - -* [x] `'yellowblue'` returns `null` +* [x] unknown strings eg. `'yellowblue'` +* [x] not strings: object, arrays etc. ## Related diff --git a/test.mjs b/test.js similarity index 88% rename from test.mjs rename to test.js index 7a55133..20f0e0f 100644 --- a/test.mjs +++ b/test.js @@ -1,4 +1,4 @@ -import parse from './index.mjs' +import parse from './index.js' import t from 'tape' /** parse-color tests */ @@ -343,6 +343,53 @@ t('lch(5, 5, orange)', function (t) { }); t.end() }); +t('oklab', function (t) { + t.deepEqual(parse('oklab(40.1% 0.1143 0.045)'), { + space: 'oklab', + values: [0.401, 0.1143, 0.045], + alpha: 1 + }); + t.deepEqual(parse('oklab(59.69% 0.1007 -0.1191 / 0.5)'), { + space: 'oklab', + values: [0.5969, 0.1007, -0.1191], + alpha: 0.5 + }); + t.deepEqual(parse('oklab(0.123 100% -100% / 2)'), { + space: 'oklab', + values: [0.123, 0.4, -0.4], + alpha: 2 + }); + t.deepEqual(parse('oklab(none none none / none)'), { + space: 'oklab', + values: [0, 0, 0], + alpha: 0 + }); + t.end() +}); +t.only('oklch', function (t) { + t.deepEqual(parse('oklch(40.1% 0.1143 0.045)'), { + space: 'oklch', + values: [0.401, 0.1143, 0.045], + alpha: 1 + }); + t.deepEqual(parse('oklch(59.69% 10% 49.77 / 0.5)'), { + space: 'oklch', + values: [0.5969, 0.1007, -0.1191], + alpha: 0.5 + }); + t.deepEqual(parse('oklch(40.1% 0.156 49.77% / .5)'), { + space: 'oklch', + values: [0.123, 0.4, -0.4], + alpha: 2 + }); + t.deepEqual(parse('oklch(none none none / none)'), { + space: 'oklch', + values: [0, 0, 0], + alpha: 0 + }); + t.end() +}); + t('#afd6', function (t) { t.deepEqual(parse('#afd6'), { space: 'rgb', From c52fbaa6d492564ec3c3295366fc0c5f9614461b Mon Sep 17 00:00:00 2001 From: Dmitry Iv Date: Fri, 15 Sep 2023 13:13:41 -0400 Subject: [PATCH 2/4] Fix tests --- index.js | 11 ++++++----- test.js | 30 ++++++++++++++++-------------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/index.js b/index.js index 3861af2..beb95a2 100644 --- a/index.js +++ b/index.js @@ -31,6 +31,7 @@ function parse(cstr) { if (typeof cstr === 'number') { return { space: 'rgb', values: [cstr >>> 16, (cstr & 0x00ff00) >>> 8, cstr & 0x0000ff], alpha: 1 } } + if (typeof cstr === 'number') return { space: 'rgb', values: [cstr >>> 16, (cstr & 0x00ff00) >>> 8, cstr & 0x0000ff], alpha: 1 } cstr = String(cstr).toLowerCase(); @@ -95,7 +96,7 @@ function parse(cstr) { // if (x[x.length - 1] === '%') { //alpha - if (i === 4) return parseFloat(x) / 100 + if (i === 3) return parseFloat(x) / 100 //rgb if (base === 'rgb') return parseFloat(x) * 255 / 100 // lch/oklch @@ -126,17 +127,17 @@ function parse(cstr) { } //named channels case - else if (cstr.length > 10 && /[0-9](?:\s|\/)/.test(cstr)) { + else if (/[0-9](?:\s|\/|,)/.test(cstr)) { parts = cstr.match(/([0-9]+)/g).map(function (value) { return parseFloat(value) }) - space = cstr.match(/([a-z])/ig).join('').toLowerCase() + space = cstr.match(/([a-z])/ig)?.join('')?.toLowerCase() || 'rgb' } return { - space: space, + space, values: parts, - alpha: alpha + alpha } } diff --git a/test.js b/test.js index 20f0e0f..3467234 100644 --- a/test.js +++ b/test.js @@ -250,9 +250,6 @@ t('rgba(200, 20, 233, 0.2)', function (t) { t.end() }); - - - t('rgba(300, 600, 100, 3)', function (t) { t.deepEqual(parse('rgba(300, 600, 100, 3)'), { space: 'rgb', @@ -292,9 +289,6 @@ t('yellowblue', function (t) { }); - - - t('hsla(101.12, 45.2%, 21.0%, 1.0)', function (t) { t.deepEqual(parse('hsla(101.12, 45.2%, 21.0%, 1.0)'), { space: 'hsl', @@ -335,6 +329,14 @@ t('hsl(10deg, 10%, 10%)', function (t) { }); t.end() }); +t('hsl(10deg, 10%, 10%)', function (t) { + t.deepEqual(parse('hsl(10deg, 10%, 10%)'), { + space: 'hsl', + values: [10, 10, 10], + alpha: 1 + }); + t.end() +}); t('lch(5, 5, orange)', function (t) { t.deepEqual(parse('lch(5, 5, orange)'), { space: 'lch', @@ -366,7 +368,7 @@ t('oklab', function (t) { }); t.end() }); -t.only('oklch', function (t) { +t.skip('oklch', function (t) { t.deepEqual(parse('oklch(40.1% 0.1143 0.045)'), { space: 'oklch', values: [0.401, 0.1143, 0.045], @@ -446,7 +448,7 @@ t('C100/M80/Y0/K35', function (t) { }); t.end() }); -t('Array', function (t) { +t.skip('Array', function (t) { t.deepEqual(parse([1, 2, 3]), { space: 'rgb', values: [1, 2, 3], @@ -454,7 +456,7 @@ t('Array', function (t) { }); t.end() }); -t('Object', function (t) { +t.skip('Object', function (t) { t.deepEqual(parse({ r: 1, g: 2, b: 3 }), { space: 'rgb', values: [1, 2, 3], @@ -493,10 +495,10 @@ t('Number', function (t) { values: [0x00, 0x00, 0xff], alpha: 1 }); - t.deepEqual(parse(new Number(0x0000ff)), { - space: 'rgb', - values: [0x00, 0x00, 0xff], - alpha: 1 - }); + // t.deepEqual(parse(new Number(0x0000ff)), { + // space: 'rgb', + // values: [0x00, 0x00, 0xff], + // alpha: 1 + // }); t.end() }); From 0fce97c91e216c1cbededf42b30fe2bc30c873f1 Mon Sep 17 00:00:00 2001 From: Dmitry Iv Date: Fri, 15 Sep 2023 13:23:24 -0400 Subject: [PATCH 3/4] More parsing spaces --- index.js | 12 +++++------- readme.md | 14 +++++++------- test.js | 49 +++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 57 insertions(+), 18 deletions(-) diff --git a/index.js b/index.js index beb95a2..3241df9 100644 --- a/index.js +++ b/index.js @@ -108,14 +108,12 @@ function parse(cstr) { } //hue if (base[i] === 'h') { - // - if (/deg$/.test(x)) { - return parseFloat(x) - } // - else if (baseHues[x] !== undefined) { - return baseHues[x] - } + if (baseHues[x] !== undefined) return baseHues[x] + // + if (/deg$/.test(x)) return parseFloat(x) + // + if (/turn$/.test(x)) return parseFloat(x) * 360 } if (x === 'none') return 0 return parseFloat(x) diff --git a/readme.md b/readme.md index 7fc1109..69e7f65 100644 --- a/readme.md +++ b/readme.md @@ -24,19 +24,19 @@ parse('hsla(12 10% 50% / .3)') * [x] `cmyk(C, M, Y, K)` * [x] `xyz(X, Y, Z)` * [x] `lab(L, A, B)` -* [ ] `lab(L a b[ / A])` +* [x] `lab(L a b[ / A])` * [x] `lch(L, C, H)` -* [ ] `lch(L C H[ / A])` -* [ ] `oklch(L C H[ / A])` -* [x] `oklab(L a b[ / A])` +* [x] `lch(L C H[ / A])` * [x] `luv(L, U, V)` -* [ ] `luv(L U V[ / A])` +* [x] `luv(L U V[ / A])` +* [x] `oklab(L a b[ / A])` +* [ ] `oklch(L C H[ / A])` * [ ] `color(space c1 c2 c3[ / A])` * [x] `R:10 G:20 B:30` * [x] `(R10 / G20 / B30)` * [x] `C100/M80/Y0/K35` -* [ ] `[10, 20, 20]` as RGB -* [ ] `10,20,20` as RGB +* [x] `[10, 20, 20]` as RGB +* [x] `10,20,20` as RGB * [x] `0x00ff00`, `0x0000ff` numbers as RGB ## Not parsed diff --git a/test.js b/test.js index 3467234..4b33e9f 100644 --- a/test.js +++ b/test.js @@ -59,7 +59,6 @@ t('rgba(153,50,204,60%)', function (t) { - t('#fef', function (t) { t.deepEqual(parse('#fef'), { space: 'rgb', @@ -250,6 +249,7 @@ t('rgba(200, 20, 233, 0.2)', function (t) { t.end() }); + t('rgba(300, 600, 100, 3)', function (t) { t.deepEqual(parse('rgba(300, 600, 100, 3)'), { space: 'rgb', @@ -329,10 +329,10 @@ t('hsl(10deg, 10%, 10%)', function (t) { }); t.end() }); -t('hsl(10deg, 10%, 10%)', function (t) { - t.deepEqual(parse('hsl(10deg, 10%, 10%)'), { +t('hsl(1.5turn, 10%, 10%)', function (t) { + t.deepEqual(parse('hsl(1.5turn, 10%, 10%)'), { space: 'hsl', - values: [10, 10, 10], + values: [540, 10, 10], alpha: 1 }); t.end() @@ -345,6 +345,47 @@ t('lch(5, 5, orange)', function (t) { }); t.end() }); +t('lch(5 5 orange / .5)', function (t) { + t.deepEqual(parse('lch(5 5 orange / .5)'), { + space: 'lch', + values: [5, 5, 60], + alpha: 0.5 + }); + t.end() +}); +t('lab(0.25, 0.25, 0.25)', function (t) { + t.deepEqual(parse('lab(0.25, 0.25, 0.25)'), { + space: 'lab', + values: [0.25, 0.25, 0.25], + alpha: 1 + }); + t.end() +}); +t('lab(0.25 0.25 0.25 / 0.5)', function (t) { + t.deepEqual(parse('lab(0.25 0.25 0.25 / 0.5)'), { + space: 'lab', + values: [0.25, 0.25, 0.25], + alpha: 0.5 + }); + t.end() +}); + +t('luv(0.25, 0.25, 0.25)', function (t) { + t.deepEqual(parse('luv(0.25, 0.25, 0.25)'), { + space: 'luv', + values: [0.25, 0.25, 0.25], + alpha: 1 + }); + t.end() +}); +t('luv(0.25 0.25 0.25 / 0.5)', function (t) { + t.deepEqual(parse('luv(0.25 0.25 0.25 / 0.5)'), { + space: 'luv', + values: [0.25, 0.25, 0.25], + alpha: 0.5 + }); + t.end() +}); t('oklab', function (t) { t.deepEqual(parse('oklab(40.1% 0.1143 0.045)'), { space: 'oklab', From b4b3cd09f9ce510cbdb71802254a6602f23f9aff Mon Sep 17 00:00:00 2001 From: Dmitry Iv Date: Fri, 15 Sep 2023 13:24:56 -0400 Subject: [PATCH 4/4] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 69e7f65..d8469a9 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -# color-parse [![build](https://travis-ci.org/colorjs/color-parse.svg?branch=master)](https://travis-ci.org/colorjs/color-parse) [![size](https://img.shields.io/bundlephobia/minzip/color-parse?label=size)](https://bundlephobia.com/result?p=color-parse) ![stable](https://img.shields.io/badge/stability-stable-green) +# color-parse [![test](https://github.com/colorjs/color-parse/actions/workflows/test.js.yml/badge.svg)](https://github.com/colorjs/color-parse/actions/workflows/test.js.yml) [![size](https://img.shields.io/bundlephobia/minzip/color-parse?label=size)](https://bundlephobia.com/result?p=color-parse) ![stable](https://img.shields.io/badge/stability-stable-green) Fast and compact color string parser.