标签:pad sub efi 数字 div turn ros 默认 色值
deciToHex(0) ==> #000000
const deciToHex = (color, defaultColor) => {
  // 指定个非法的值不生效
  if (color && color[0] === ‘#‘) {
return color
  }
  var c = defaultColor || ‘none‘
  color = parseInt(color)
  if (color === undefined || color > 16777215 || color < 0 || color === null) {
return c
  }
  c = color.toString(16)
  c = leftZeroPad(c, 6)
  c = ‘#‘ + c
  return c
}
// 左填充
const leftZeroPad = (val, minLength) => {
  var MANY_ZEROS = ‘000000000000000000‘
  if (typeof (val) !== ‘string‘) {
val = String(val)
  }
  return (MANY_ZEROS.substring(0, minLength - val.length)) + val
}标签:pad sub efi 数字 div turn ros 默认 色值
原文地址:http://www.cnblogs.com/a-xi-ba/p/7874562.html