braft-utils
Advanced tools
Comparing version 0.0.8 to 0.0.9
@@ -150,28 +150,29 @@ "use strict"; | ||
exports.default = { | ||
var getHexColor = function getHexColor(color) { | ||
namedColors: namedColors, | ||
color = color.replace('color:', '').replace(';', '').replace(' ', ''); | ||
getHexColor: function getHexColor(color) { | ||
if (/^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(color)) { | ||
return color; | ||
} else if (namedColors[color]) { | ||
return namedColors[color]; | ||
} else if (color.indexOf('rgb') === 0) { | ||
color = color.replace('color:', '').replace(';', '').replace(' ', ''); | ||
var rgbArray = color.split(','); | ||
var convertedColor = rgbArray.length < 3 ? null : '#' + [rgbArray[0], rgbArray[1], rgbArray[2]].map(function (x) { | ||
var hex = parseInt(x.replace(/\D/g, ''), 10).toString(16); | ||
return hex.length === 1 ? '0' + hex : hex; | ||
}).join(''); | ||
if (/^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(color)) { | ||
return color; | ||
} else if (namedColors[color]) { | ||
return namedColors[color]; | ||
} else if (color.indexOf('rgb') === 0) { | ||
return (/^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(convertedColor) ? convertedColor : null | ||
); | ||
} else { | ||
return null; | ||
} | ||
}; | ||
var rgbArray = color.split(','); | ||
var convertedColor = rgbArray.length < 3 ? null : '#' + [rgbArray[0], rgbArray[1], rgbArray[2]].map(function (x) { | ||
var hex = parseInt(x.replace(/\D/g, ''), 10).toString(16); | ||
return hex.length === 1 ? '0' + hex : hex; | ||
}).join(''); | ||
exports.default = { | ||
return (/^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(convertedColor) ? convertedColor : null | ||
); | ||
} else { | ||
return null; | ||
} | ||
}, | ||
namedColors: namedColors, getHexColor: getHexColor, | ||
detectColorsFromHTMLString: function detectColorsFromHTMLString(html) { | ||
@@ -178,0 +179,0 @@ return typeof html !== 'string' ? [] : (html.match(/color:[^;]{3,24};/g) || []).map(getHexColor).filter(function (color) { |
{ | ||
"name": "braft-utils", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description": "Utils for Braft Editor", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
108524