restore scientific number notation support in colors
rgba(1.5E2 0 0 / .5e2%)
This commit is contained in:
parent
215cfeac92
commit
41be0453e6
|
@ -54,12 +54,14 @@ const colorConverter = (() => {
|
||||||
}
|
}
|
||||||
|
|
||||||
function validatePercentage(s) {
|
function validatePercentage(s) {
|
||||||
const match = s.match(/^(\d+|\d*\.\d+)%$/);
|
if (!s.endsWith('%')) return false;
|
||||||
return match && Number(match[1]) >= 0 && Number(match[1]) <= 100;
|
const n = Number(s.slice(0, -1));
|
||||||
|
return n >= 0 && n <= 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
function validateNum(s) {
|
function validateNum(s) {
|
||||||
return /^\d+$/.test(s) && Number(s) >= 0 && Number(s) <= 255;
|
const n = Number(s);
|
||||||
|
return n >= 0 && n <= 255;
|
||||||
}
|
}
|
||||||
|
|
||||||
function validateHSL(nums) {
|
function validateHSL(nums) {
|
||||||
|
@ -74,7 +76,8 @@ const colorConverter = (() => {
|
||||||
if (alpha.endsWith('%')) {
|
if (alpha.endsWith('%')) {
|
||||||
return validatePercentage(alpha);
|
return validatePercentage(alpha);
|
||||||
}
|
}
|
||||||
return Number(alpha) >= 0 && Number(alpha) <= 1;
|
const n = Number(alpha);
|
||||||
|
return n >= 0 && n <= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
function parse(str) {
|
function parse(str) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user