Fix: drop pad

This commit is contained in:
eight 2017-09-12 20:44:12 +08:00
parent 8e5ffd036f
commit 6b1d6564fb

View File

@ -72,20 +72,13 @@ var usercss = (function () {
return `rgba(${r}, ${g}, ${b}, ${a})`; return `rgba(${r}, ${g}, ${b}, ${a})`;
} }
function pad(s) {
if (s.padStart) {
// chrome 57+
return s.padStart(2, '0');
}
return `00${s}`.slice(-2);
}
function formatHex({r, g, b, a = null}) { function formatHex({r, g, b, a = null}) {
const values = [r, g, b]; const values = [r, g, b];
let hex = '#' + (0x1000000 + (r << 16) + (g << 8) + (b | 0)).toString(16).substr(1);
if (a !== null) { if (a !== null) {
values.push(Math.floor(a * 255)); hex += (0x100 + Math.floor(a * 255)).toString(16).substr(1);
} }
return '#' + values.map(n => pad(n.toString(16))).join(''); return hex;
} }
return {parse, format, formatHex}; return {parse, format, formatHex};