diff options
author | Jordan Harband <ljharb@gmail.com> | 2023-11-30 10:33:44 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-30 18:33:44 +0000 |
commit | 334c118c9780f95869337dad413ca74aab53df4d (patch) | |
tree | 079b2568ebc27dc9118b87c51a72788628b278cd /ext/console/01_console.js | |
parent | 91626bac4974150cfac4ca10c9e83d82633540df (diff) |
refactor (parseCssColor): use parseInt, avoid unnecessary coercion (#20856)
Upstream some changes from https://github.com/nodejs/node/pull/49205
Signed-off-by: Jordan Harband <ljharb@gmail.com>
Diffstat (limited to 'ext/console/01_console.js')
-rw-r--r-- | ext/console/01_console.js | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/ext/console/01_console.js b/ext/console/01_console.js index 9c199aa59..4f0ff6362 100644 --- a/ext/console/01_console.js +++ b/ext/console/01_console.js @@ -2753,34 +2753,34 @@ const HSL_PATTERN = new SafeRegExp( ); function parseCssColor(colorString) { - if (MapPrototypeHas(colorKeywords, colorString)) { - colorString = MapPrototypeGet(colorKeywords, colorString); + if (colorKeywords.has(colorString)) { + colorString = colorKeywords.get(colorString); } // deno-fmt-ignore const hashMatch = StringPrototypeMatch(colorString, HASH_PATTERN); if (hashMatch != null) { return [ - Number(`0x${hashMatch[1]}`), - Number(`0x${hashMatch[2]}`), - Number(`0x${hashMatch[3]}`), + NumberParseInt(hashMatch[1], 16), + NumberParseInt(hashMatch[2], 16), + NumberParseInt(hashMatch[3], 16), ]; } // deno-fmt-ignore const smallHashMatch = StringPrototypeMatch(colorString, SMALL_HASH_PATTERN); if (smallHashMatch != null) { return [ - Number(`0x${smallHashMatch[1]}${smallHashMatch[1]}`), - Number(`0x${smallHashMatch[2]}${smallHashMatch[2]}`), - Number(`0x${smallHashMatch[3]}${smallHashMatch[3]}`), + NumberParseInt(`${smallHashMatch[1]}${smallHashMatch[1]}`, 16), + NumberParseInt(`${smallHashMatch[2]}${smallHashMatch[2]}`, 16), + NumberParseInt(`${smallHashMatch[3]}${smallHashMatch[3]}`, 16), ]; } // deno-fmt-ignore const rgbMatch = StringPrototypeMatch(colorString, RGB_PATTERN); if (rgbMatch != null) { return [ - MathRound(MathMax(0, MathMin(255, Number(rgbMatch[1])))), - MathRound(MathMax(0, MathMin(255, Number(rgbMatch[2])))), - MathRound(MathMax(0, MathMin(255, Number(rgbMatch[3])))), + MathRound(MathMax(0, MathMin(255, rgbMatch[1]))), + MathRound(MathMax(0, MathMin(255, rgbMatch[2]))), + MathRound(MathMax(0, MathMin(255, rgbMatch[3]))), ]; } // deno-fmt-ignore @@ -2791,8 +2791,8 @@ function parseCssColor(colorString) { if (h < 0) { h += 360; } - const s = MathMax(0, MathMin(100, Number(hslMatch[2]))) / 100; - const l = MathMax(0, MathMin(100, Number(hslMatch[3]))) / 100; + const s = MathMax(0, MathMin(100, hslMatch[2])) / 100; + const l = MathMax(0, MathMin(100, hslMatch[3])) / 100; const c = (1 - MathAbs(2 * l - 1)) * s; const x = c * (1 - MathAbs((h / 60) % 2 - 1)); const m = l - c / 2; |