@jiaminghi/color
Advanced tools
Comparing version 1.0.0 to 1.1.1
@@ -25,14 +25,12 @@ module.exports = { | ||
'@typescript-eslint/ban-ts-ignore': 'off', | ||
// 'no-unused-vars': 'off', | ||
// '@typescript-eslint/no-unused-expressions': 'off', | ||
// '@typescript-eslint/no-unused-vars': [ | ||
// 'error', | ||
// { | ||
// vars: 'all', | ||
// args: 'after-used', | ||
// ignoreRestSiblings: true, | ||
// argsIgnorePattern: '^_', // ignore unused variables whose name is '_' | ||
// }, | ||
// ], | ||
'@typescript-eslint/no-unused-vars': [ | ||
'error', | ||
{ | ||
vars: 'all', | ||
args: 'after-used', | ||
ignoreRestSiblings: true, | ||
argsIgnorePattern: '^_', // ignore unused variables whose name is '_' | ||
}, | ||
], | ||
}, | ||
} |
@@ -1,3 +0,15 @@ | ||
# 1.0.0-alpha (2020-04-11) | ||
# 1.1.1 (2020-05-14) | ||
### Bug Fixes | ||
- **types:** Absolute path cause import error. | ||
# 1.1.0 (2020-04-21) | ||
### Perfect | ||
- **devDep:** Add rollup into devDep. | ||
# 1.0.0 (2020-04-11) | ||
### Upgrade | ||
@@ -4,0 +16,0 @@ |
@@ -238,3 +238,3 @@ (function (global, factory) { | ||
* @param {string} color Hex|Rgb|Rgba color or color keywords | ||
* @return {string|null} Valid color (Invalid input will return null) | ||
* @return {string} Color (Invalid input will throw an error) | ||
*/ | ||
@@ -245,3 +245,5 @@ | ||
if (isHex(color) || isRgbOrRgba(color)) return color; | ||
return getColorByKeyword(color) || null; | ||
var keywordColor = getColorByKeyword(color); | ||
if (!keywordColor) throw new Error("Color: Invalid Input of " + color); | ||
return keywordColor; | ||
} | ||
@@ -280,3 +282,3 @@ /** | ||
* @param {string} color Hex|Rgb|Rgba color or color keyword | ||
* @return {RgbValue|null} Rgb value of the color (Invalid input will return null) | ||
* @return {RgbValue} Rgb value of the color | ||
*/ | ||
@@ -287,3 +289,2 @@ | ||
var validColor = validator(color); | ||
if (!validColor) return null; | ||
var lowerColor = validColor.toLowerCase(); | ||
@@ -300,3 +301,3 @@ return isHex(lowerColor) ? getRgbValueFromHex(lowerColor) : getRgbValueFromRgb(lowerColor); | ||
var validColor = validator(color); | ||
if (!validColor || !isRgba(validColor)) return 1; | ||
if (!isRgba(validColor)) return 1; | ||
return Number(validColor.toLowerCase().split(',').slice(-1)[0].replace(/[)|\s]/g, '')); | ||
@@ -307,3 +308,3 @@ } | ||
* @param {string} color Hex|Rgb|Rgba color or color keyword | ||
* @return {RgbaValue|null} Rgba value of the color (Invalid input will return null) | ||
* @return {RgbaValue} Rgba value of the color | ||
*/ | ||
@@ -319,3 +320,3 @@ | ||
* @param {number} opacity The opacity of color | ||
* @return {string|null} Rgb|Rgba color (Invalid input will return null) | ||
* @return {string} Rgb|Rgba color | ||
*/ | ||
@@ -325,3 +326,2 @@ | ||
var rgbValue = getRgbValue(color); | ||
if (!rgbValue) return null; | ||
return typeof opacity === 'number' ? "rgba(" + rgbValue.join(',') + "," + opacity + ")" : "rgb(" + rgbValue.join(',') + ")"; | ||
@@ -332,3 +332,3 @@ } | ||
* @param {string} color Hex|Rgb|Rgba color or color keyword | ||
* @return {string|null} Hex color (Invalid input will return null) | ||
* @return {string} Hex color | ||
*/ | ||
@@ -339,3 +339,2 @@ | ||
var colorValue = getRgbValue(color); | ||
if (!colorValue) return null; | ||
@@ -351,9 +350,9 @@ var format10To16 = function format10To16(_) { | ||
* @param {RgbValue|RgbaValue} value Rgb|Rgba color value | ||
* @return {string|null} Rgb|Rgba color (Invalid input will return null) | ||
* @return {string} Rgb|Rgba color | ||
*/ | ||
function getColorFromRgbValue(value) { | ||
if (!Array.isArray(value)) return null; | ||
if (!Array.isArray(value)) throw new Error("getColorFromRgbValue: " + value + " is not an array"); | ||
var length = value.length; | ||
if (length !== 3 && length !== 4) return null; | ||
if (length !== 3 && length !== 4) throw new Error("getColorFromRgbValue: value length should be 3 or 4"); | ||
return (length === 3 ? 'rgb(' : 'rgba(') + value.join(',') + ')'; | ||
@@ -365,3 +364,3 @@ } | ||
* @param {number} percent of Deepen (1-100) | ||
* @return {string|null} Rgba color (Invalid input will return null) | ||
* @return {string} Rgba color | ||
*/ | ||
@@ -375,3 +374,2 @@ | ||
var rgbaValue = getRgbaValue(color); | ||
if (!rgbaValue) return null; | ||
rgbaValue = rgbaValue.map(function (v, i) { | ||
@@ -388,3 +386,3 @@ return i === 3 ? v : v - Math.ceil(2.55 * percent); | ||
* @param {number} percent of brighten (1-100) | ||
* @return {string|null} Rgba color (Invalid input will return null) | ||
* @return {string} Rgba color | ||
*/ | ||
@@ -398,3 +396,2 @@ | ||
var rgbaValue = getRgbaValue(color); | ||
if (!rgbaValue) return null; | ||
rgbaValue = rgbaValue.map(function (v, i) { | ||
@@ -411,3 +408,3 @@ return i === 3 ? v : v + Math.ceil(2.55 * percent); | ||
* @param {number} percent of opacity | ||
* @return {string|null} Rgba color (Invalid input will return null) | ||
* @return {string} Rgba color | ||
*/ | ||
@@ -421,3 +418,2 @@ | ||
var rgbValue = getRgbValue(color); | ||
if (!rgbValue) return null; | ||
return getColorFromRgbValue(__spreadArrays(rgbValue, [percent / 100])); | ||
@@ -424,0 +420,0 @@ } |
@@ -15,2 +15,2 @@ !function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((e=e||self).Color={})}(this,(function(e){"use strict"; | ||
and limitations under the License. | ||
***************************************************************************** */function r(){for(var e=0,r=0,a=arguments.length;a>r;r++)e+=arguments[r].length;var f=Array(e),n=0;for(r=0;a>r;r++)for(var t=arguments[r],i=0,l=t.length;l>i;i++,n++)f[n]=t[i];return f}var a;!function(e){e.transparent="rgba(0,0,0,0)",e.black="#000000",e.silver="#C0C0C0",e.gray="#808080",e.white="#FFFFFF",e.maroon="#800000",e.red="#FF0000",e.purple="#800080",e.fuchsia="#FF00FF",e.green="#008000",e.lime="#00FF00",e.olive="#808000",e.yellow="#FFFF00",e.navy="#000080",e.blue="#0000FF",e.teal="#008080",e.aqua="#00FFFF",e.aliceblue="#f0f8ff",e.antiquewhite="#faebd7",e.aquamarine="#7fffd4",e.azure="#f0ffff",e.beige="#f5f5dc",e.bisque="#ffe4c4",e.blanchedalmond="#ffebcd",e.blueviolet="#8a2be2",e.brown="#a52a2a",e.burlywood="#deb887",e.cadetblue="#5f9ea0",e.chartreuse="#7fff00",e.chocolate="#d2691e",e.coral="#ff7f50",e.cornflowerblue="#6495ed",e.cornsilk="#fff8dc",e.crimson="#dc143c",e.cyan="#00ffff",e.darkblue="#00008b",e.darkcyan="#008b8b",e.darkgoldenrod="#b8860b",e.darkgray="#a9a9a9",e.darkgreen="#006400",e.darkgrey="#a9a9a9",e.darkkhaki="#bdb76b",e.darkmagenta="#8b008b",e.darkolivegreen="#556b2f",e.darkorange="#ff8c00",e.darkorchid="#9932cc",e.darkred="#8b0000",e.darksalmon="#e9967a",e.darkseagreen="#8fbc8f",e.darkslateblue="#483d8b",e.darkslategray="#2f4f4f",e.darkslategrey="#2f4f4f",e.darkturquoise="#00ced1",e.darkviolet="#9400d3",e.deeppink="#ff1493",e.deepskyblue="#00bfff",e.dimgray="#696969",e.dimgrey="#696969",e.dodgerblue="#1e90ff",e.firebrick="#b22222",e.floralwhite="#fffaf0",e.forestgreen="#228b22",e.gainsboro="#dcdcdc",e.ghostwhite="#f8f8ff",e.gold="#ffd700",e.goldenrod="#daa520",e.greenyellow="#adff2f",e.grey="#808080",e.honeydew="#f0fff0",e.hotpink="#ff69b4",e.indianred="#cd5c5c",e.indigo="#4b0082",e.ivory="#fffff0",e.khaki="#f0e68c",e.lavender="#e6e6fa",e.lavenderblush="#fff0f5",e.lawngreen="#7cfc00",e.lemonchiffon="#fffacd",e.lightblue="#add8e6",e.lightcoral="#f08080",e.lightcyan="#e0ffff",e.lightgoldenrodyellow="#fafad2",e.lightgray="#d3d3d3",e.lightgreen="#90ee90",e.lightgrey="#d3d3d3",e.lightpink="#ffb6c1",e.lightsalmon="#ffa07a",e.lightseagreen="#20b2aa",e.lightskyblue="#87cefa",e.lightslategray="#778899",e.lightslategrey="#778899",e.lightsteelblue="#b0c4de",e.lightyellow="#ffffe0",e.limegreen="#32cd32",e.linen="#faf0e6",e.magenta="#ff00ff",e.mediumaquamarine="#66cdaa",e.mediumblue="#0000cd",e.mediumorchid="#ba55d3",e.mediumpurple="#9370db",e.mediumseagreen="#3cb371",e.mediumslateblue="#7b68ee",e.mediumspringgreen="#00fa9a",e.mediumturquoise="#48d1cc",e.mediumvioletred="#c71585",e.midnightblue="#191970",e.mintcream="#f5fffa",e.mistyrose="#ffe4e1",e.moccasin="#ffe4b5",e.navajowhite="#ffdead",e.oldlace="#fdf5e6",e.olivedrab="#6b8e23",e.orange="#ffa500",e.orangered="#ff4500",e.orchid="#da70d6",e.palegoldenrod="#eee8aa",e.palegreen="#98fb98",e.paleturquoise="#afeeee",e.palevioletred="#db7093",e.papayawhip="#ffefd5",e.peachpuff="#ffdab9",e.peru="#cd853f",e.pink="#ffc0cb",e.plum="#dda0dd",e.powderblue="#b0e0e6",e.rosybrown="#bc8f8f",e.royalblue="#4169e1",e.saddlebrown="#8b4513",e.salmon="#fa8072",e.sandybrown="#f4a460",e.seagreen="#2e8b57",e.seashell="#fff5ee",e.sienna="#a0522d",e.skyblue="#87ceeb",e.slateblue="#6a5acd",e.slategray="#708090",e.snow="#fffafa",e.springgreen="#00ff7f",e.steelblue="#4682b4",e.tan="#d2b48c",e.thistle="#d8bfd8",e.tomato="#ff6347",e.turquoise="#40e0d0",e.violet="#ee82ee",e.wheat="#f5deb3",e.whitesmoke="#f5f5f5",e.yellowgreen="#9acd32"}(a||(a={}));var f=a;function n(e){return"string"==typeof e&&(e=e.toLowerCase(),/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(e))}function t(e){return"string"==typeof e&&(e=e.toLowerCase(),/^(rgb\(|RGB\()/.test(e))}function i(e){return"string"==typeof e&&(e=e.toLowerCase(),/^(rgba|RGBA)/.test(e))}function l(e){return/^(rgb|rgba|RGB|RGBA)/.test(e)}function o(e){return n(e)||l(e)?e:f[e]||null}function d(e){var r=o(e);if(!r)return null;var a=r.toLowerCase();return n(a)?function(e){3===(e=e.replace("#","")).length&&(e=Array.from(e).map((function(e){return e+e})).join(""));var r=e.split("");return[,,,].fill(0).map((function(e,a){return parseInt("0x"+r[2*a]+r[2*a+1])}))}(a):function(e){return e.replace(/rgb\(|rgba\(|\)/g,"").split(",").slice(0,3).map((function(e){return parseInt(e)}))}(a)}function u(e){var r=o(e);return r&&i(r)?Number(r.toLowerCase().split(",").slice(-1)[0].replace(/[)|\s]/g,"")):1}function b(e){var a=d(e);return a&&r(a,[u(e)])}function g(e,r){var a=d(e);return a?"number"==typeof r?"rgba("+a.join(",")+","+r+")":"rgb("+a.join(",")+")":null}function c(e){if(n(e))return e;var r=d(e);if(!r)return null;return"#"+r.map((function(e){return Number(e).toString(16).padStart(2,"0")})).join("")}function s(e){if(!Array.isArray(e))return null;var r=e.length;return 3!==r&&4!==r?null:(3===r?"rgb(":"rgba(")+e.join(",")+")"}function m(e,r){void 0===r&&(r=0);var a=b(e);return a?s(a=a.map((function(e,a){return 3===a?e:e-Math.ceil(2.55*r)})).map((function(e){return 0>e?0:e}))):null}function p(e,r){void 0===r&&(r=0);var a=b(e);return a?s(a=a.map((function(e,a){return 3===a?e:e+Math.ceil(2.55*r)})).map((function(e){return e>255?255:e}))):null}function h(e,a){void 0===a&&(a=100);var f=d(e);return f?s(r(f,[a/100])):null}var y={isHex:n,isRgb:t,isRgba:i,isRgbOrRgba:l,fade:h,toHex:c,toRgb:g,darken:m,lighten:p,getOpacity:u,getRgbValue:d,getRgbaValue:b,getColorFromRgbValue:s};e.darken=m,e.default=y,e.fade=h,e.getColorFromRgbValue=s,e.getOpacity=u,e.getRgbValue=d,e.getRgbaValue=b,e.isHex=n,e.isRgb=t,e.isRgbOrRgba=l,e.isRgba=i,e.lighten=p,e.toHex=c,e.toRgb=g,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
***************************************************************************** */function r(){for(var e=0,r=0,a=arguments.length;a>r;r++)e+=arguments[r].length;var f=Array(e),n=0;for(r=0;a>r;r++)for(var t=arguments[r],o=0,i=t.length;i>o;o++,n++)f[n]=t[o];return f}var a;!function(e){e.transparent="rgba(0,0,0,0)",e.black="#000000",e.silver="#C0C0C0",e.gray="#808080",e.white="#FFFFFF",e.maroon="#800000",e.red="#FF0000",e.purple="#800080",e.fuchsia="#FF00FF",e.green="#008000",e.lime="#00FF00",e.olive="#808000",e.yellow="#FFFF00",e.navy="#000080",e.blue="#0000FF",e.teal="#008080",e.aqua="#00FFFF",e.aliceblue="#f0f8ff",e.antiquewhite="#faebd7",e.aquamarine="#7fffd4",e.azure="#f0ffff",e.beige="#f5f5dc",e.bisque="#ffe4c4",e.blanchedalmond="#ffebcd",e.blueviolet="#8a2be2",e.brown="#a52a2a",e.burlywood="#deb887",e.cadetblue="#5f9ea0",e.chartreuse="#7fff00",e.chocolate="#d2691e",e.coral="#ff7f50",e.cornflowerblue="#6495ed",e.cornsilk="#fff8dc",e.crimson="#dc143c",e.cyan="#00ffff",e.darkblue="#00008b",e.darkcyan="#008b8b",e.darkgoldenrod="#b8860b",e.darkgray="#a9a9a9",e.darkgreen="#006400",e.darkgrey="#a9a9a9",e.darkkhaki="#bdb76b",e.darkmagenta="#8b008b",e.darkolivegreen="#556b2f",e.darkorange="#ff8c00",e.darkorchid="#9932cc",e.darkred="#8b0000",e.darksalmon="#e9967a",e.darkseagreen="#8fbc8f",e.darkslateblue="#483d8b",e.darkslategray="#2f4f4f",e.darkslategrey="#2f4f4f",e.darkturquoise="#00ced1",e.darkviolet="#9400d3",e.deeppink="#ff1493",e.deepskyblue="#00bfff",e.dimgray="#696969",e.dimgrey="#696969",e.dodgerblue="#1e90ff",e.firebrick="#b22222",e.floralwhite="#fffaf0",e.forestgreen="#228b22",e.gainsboro="#dcdcdc",e.ghostwhite="#f8f8ff",e.gold="#ffd700",e.goldenrod="#daa520",e.greenyellow="#adff2f",e.grey="#808080",e.honeydew="#f0fff0",e.hotpink="#ff69b4",e.indianred="#cd5c5c",e.indigo="#4b0082",e.ivory="#fffff0",e.khaki="#f0e68c",e.lavender="#e6e6fa",e.lavenderblush="#fff0f5",e.lawngreen="#7cfc00",e.lemonchiffon="#fffacd",e.lightblue="#add8e6",e.lightcoral="#f08080",e.lightcyan="#e0ffff",e.lightgoldenrodyellow="#fafad2",e.lightgray="#d3d3d3",e.lightgreen="#90ee90",e.lightgrey="#d3d3d3",e.lightpink="#ffb6c1",e.lightsalmon="#ffa07a",e.lightseagreen="#20b2aa",e.lightskyblue="#87cefa",e.lightslategray="#778899",e.lightslategrey="#778899",e.lightsteelblue="#b0c4de",e.lightyellow="#ffffe0",e.limegreen="#32cd32",e.linen="#faf0e6",e.magenta="#ff00ff",e.mediumaquamarine="#66cdaa",e.mediumblue="#0000cd",e.mediumorchid="#ba55d3",e.mediumpurple="#9370db",e.mediumseagreen="#3cb371",e.mediumslateblue="#7b68ee",e.mediumspringgreen="#00fa9a",e.mediumturquoise="#48d1cc",e.mediumvioletred="#c71585",e.midnightblue="#191970",e.mintcream="#f5fffa",e.mistyrose="#ffe4e1",e.moccasin="#ffe4b5",e.navajowhite="#ffdead",e.oldlace="#fdf5e6",e.olivedrab="#6b8e23",e.orange="#ffa500",e.orangered="#ff4500",e.orchid="#da70d6",e.palegoldenrod="#eee8aa",e.palegreen="#98fb98",e.paleturquoise="#afeeee",e.palevioletred="#db7093",e.papayawhip="#ffefd5",e.peachpuff="#ffdab9",e.peru="#cd853f",e.pink="#ffc0cb",e.plum="#dda0dd",e.powderblue="#b0e0e6",e.rosybrown="#bc8f8f",e.royalblue="#4169e1",e.saddlebrown="#8b4513",e.salmon="#fa8072",e.sandybrown="#f4a460",e.seagreen="#2e8b57",e.seashell="#fff5ee",e.sienna="#a0522d",e.skyblue="#87ceeb",e.slateblue="#6a5acd",e.slategray="#708090",e.snow="#fffafa",e.springgreen="#00ff7f",e.steelblue="#4682b4",e.tan="#d2b48c",e.thistle="#d8bfd8",e.tomato="#ff6347",e.turquoise="#40e0d0",e.violet="#ee82ee",e.wheat="#f5deb3",e.whitesmoke="#f5f5f5",e.yellowgreen="#9acd32"}(a||(a={}));var f=a;function n(e){return"string"==typeof e&&(e=e.toLowerCase(),/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(e))}function t(e){return"string"==typeof e&&(e=e.toLowerCase(),/^(rgb\(|RGB\()/.test(e))}function o(e){return"string"==typeof e&&(e=e.toLowerCase(),/^(rgba|RGBA)/.test(e))}function i(e){return/^(rgb|rgba|RGB|RGBA)/.test(e)}function l(e){if(n(e)||i(e))return e;var r=f[e];if(!r)throw Error("Color: Invalid Input of "+e);return r}function d(e){var r=l(e).toLowerCase();return n(r)?function(e){3===(e=e.replace("#","")).length&&(e=Array.from(e).map((function(e){return e+e})).join(""));var r=e.split("");return[,,,].fill(0).map((function(e,a){return parseInt("0x"+r[2*a]+r[2*a+1])}))}(r):function(e){return e.replace(/rgb\(|rgba\(|\)/g,"").split(",").slice(0,3).map((function(e){return parseInt(e)}))}(r)}function u(e){var r=l(e);return o(r)?Number(r.toLowerCase().split(",").slice(-1)[0].replace(/[)|\s]/g,"")):1}function g(e){var a=d(e);return a&&r(a,[u(e)])}function b(e,r){var a=d(e);return"number"==typeof r?"rgba("+a.join(",")+","+r+")":"rgb("+a.join(",")+")"}function c(e){if(n(e))return e;return"#"+d(e).map((function(e){return Number(e).toString(16).padStart(2,"0")})).join("")}function s(e){if(!Array.isArray(e))throw Error("getColorFromRgbValue: "+e+" is not an array");var r=e.length;if(3!==r&&4!==r)throw Error("getColorFromRgbValue: value length should be 3 or 4");return(3===r?"rgb(":"rgba(")+e.join(",")+")"}function m(e,r){void 0===r&&(r=0);var a=g(e);return s(a=a.map((function(e,a){return 3===a?e:e-Math.ceil(2.55*r)})).map((function(e){return 0>e?0:e})))}function h(e,r){void 0===r&&(r=0);var a=g(e);return s(a=a.map((function(e,a){return 3===a?e:e+Math.ceil(2.55*r)})).map((function(e){return e>255?255:e})))}function p(e,a){return void 0===a&&(a=100),s(r(d(e),[a/100]))}var y={isHex:n,isRgb:t,isRgba:o,isRgbOrRgba:i,fade:p,toHex:c,toRgb:b,darken:m,lighten:h,getOpacity:u,getRgbValue:d,getRgbaValue:g,getColorFromRgbValue:s};e.darken=m,e.default=y,e.fade=p,e.getColorFromRgbValue=s,e.getOpacity=u,e.getRgbValue=d,e.getRgbaValue=g,e.isHex=n,e.isRgb=t,e.isRgbOrRgba=i,e.isRgba=o,e.lighten=h,e.toHex=c,e.toRgb=b,Object.defineProperty(e,"__esModule",{value:!0})})); |
@@ -232,3 +232,3 @@ /*! ***************************************************************************** | ||
* @param {string} color Hex|Rgb|Rgba color or color keywords | ||
* @return {string|null} Valid color (Invalid input will return null) | ||
* @return {string} Color (Invalid input will throw an error) | ||
*/ | ||
@@ -239,3 +239,5 @@ | ||
if (isHex(color) || isRgbOrRgba(color)) return color; | ||
return getColorByKeyword(color) || null; | ||
var keywordColor = getColorByKeyword(color); | ||
if (!keywordColor) throw new Error("Color: Invalid Input of " + color); | ||
return keywordColor; | ||
} | ||
@@ -274,3 +276,3 @@ /** | ||
* @param {string} color Hex|Rgb|Rgba color or color keyword | ||
* @return {RgbValue|null} Rgb value of the color (Invalid input will return null) | ||
* @return {RgbValue} Rgb value of the color | ||
*/ | ||
@@ -281,3 +283,2 @@ | ||
var validColor = validator(color); | ||
if (!validColor) return null; | ||
var lowerColor = validColor.toLowerCase(); | ||
@@ -294,3 +295,3 @@ return isHex(lowerColor) ? getRgbValueFromHex(lowerColor) : getRgbValueFromRgb(lowerColor); | ||
var validColor = validator(color); | ||
if (!validColor || !isRgba(validColor)) return 1; | ||
if (!isRgba(validColor)) return 1; | ||
return Number(validColor.toLowerCase().split(',').slice(-1)[0].replace(/[)|\s]/g, '')); | ||
@@ -301,3 +302,3 @@ } | ||
* @param {string} color Hex|Rgb|Rgba color or color keyword | ||
* @return {RgbaValue|null} Rgba value of the color (Invalid input will return null) | ||
* @return {RgbaValue} Rgba value of the color | ||
*/ | ||
@@ -313,3 +314,3 @@ | ||
* @param {number} opacity The opacity of color | ||
* @return {string|null} Rgb|Rgba color (Invalid input will return null) | ||
* @return {string} Rgb|Rgba color | ||
*/ | ||
@@ -319,3 +320,2 @@ | ||
var rgbValue = getRgbValue(color); | ||
if (!rgbValue) return null; | ||
return typeof opacity === 'number' ? "rgba(" + rgbValue.join(',') + "," + opacity + ")" : "rgb(" + rgbValue.join(',') + ")"; | ||
@@ -326,3 +326,3 @@ } | ||
* @param {string} color Hex|Rgb|Rgba color or color keyword | ||
* @return {string|null} Hex color (Invalid input will return null) | ||
* @return {string} Hex color | ||
*/ | ||
@@ -333,3 +333,2 @@ | ||
var colorValue = getRgbValue(color); | ||
if (!colorValue) return null; | ||
@@ -345,9 +344,9 @@ var format10To16 = function format10To16(_) { | ||
* @param {RgbValue|RgbaValue} value Rgb|Rgba color value | ||
* @return {string|null} Rgb|Rgba color (Invalid input will return null) | ||
* @return {string} Rgb|Rgba color | ||
*/ | ||
function getColorFromRgbValue(value) { | ||
if (!Array.isArray(value)) return null; | ||
if (!Array.isArray(value)) throw new Error("getColorFromRgbValue: " + value + " is not an array"); | ||
var length = value.length; | ||
if (length !== 3 && length !== 4) return null; | ||
if (length !== 3 && length !== 4) throw new Error("getColorFromRgbValue: value length should be 3 or 4"); | ||
return (length === 3 ? 'rgb(' : 'rgba(') + value.join(',') + ')'; | ||
@@ -359,3 +358,3 @@ } | ||
* @param {number} percent of Deepen (1-100) | ||
* @return {string|null} Rgba color (Invalid input will return null) | ||
* @return {string} Rgba color | ||
*/ | ||
@@ -369,3 +368,2 @@ | ||
var rgbaValue = getRgbaValue(color); | ||
if (!rgbaValue) return null; | ||
rgbaValue = rgbaValue.map(function (v, i) { | ||
@@ -382,3 +380,3 @@ return i === 3 ? v : v - Math.ceil(2.55 * percent); | ||
* @param {number} percent of brighten (1-100) | ||
* @return {string|null} Rgba color (Invalid input will return null) | ||
* @return {string} Rgba color | ||
*/ | ||
@@ -392,3 +390,2 @@ | ||
var rgbaValue = getRgbaValue(color); | ||
if (!rgbaValue) return null; | ||
rgbaValue = rgbaValue.map(function (v, i) { | ||
@@ -405,3 +402,3 @@ return i === 3 ? v : v + Math.ceil(2.55 * percent); | ||
* @param {number} percent of opacity | ||
* @return {string|null} Rgba color (Invalid input will return null) | ||
* @return {string} Rgba color | ||
*/ | ||
@@ -415,3 +412,2 @@ | ||
var rgbValue = getRgbValue(color); | ||
if (!rgbValue) return null; | ||
return getColorFromRgbValue(__spreadArrays(rgbValue, [percent / 100])); | ||
@@ -418,0 +414,0 @@ } |
@@ -236,3 +236,3 @@ 'use strict'; | ||
* @param {string} color Hex|Rgb|Rgba color or color keywords | ||
* @return {string|null} Valid color (Invalid input will return null) | ||
* @return {string} Color (Invalid input will throw an error) | ||
*/ | ||
@@ -243,3 +243,5 @@ | ||
if (isHex(color) || isRgbOrRgba(color)) return color; | ||
return getColorByKeyword(color) || null; | ||
var keywordColor = getColorByKeyword(color); | ||
if (!keywordColor) throw new Error("Color: Invalid Input of " + color); | ||
return keywordColor; | ||
} | ||
@@ -278,3 +280,3 @@ /** | ||
* @param {string} color Hex|Rgb|Rgba color or color keyword | ||
* @return {RgbValue|null} Rgb value of the color (Invalid input will return null) | ||
* @return {RgbValue} Rgb value of the color | ||
*/ | ||
@@ -285,3 +287,2 @@ | ||
var validColor = validator(color); | ||
if (!validColor) return null; | ||
var lowerColor = validColor.toLowerCase(); | ||
@@ -298,3 +299,3 @@ return isHex(lowerColor) ? getRgbValueFromHex(lowerColor) : getRgbValueFromRgb(lowerColor); | ||
var validColor = validator(color); | ||
if (!validColor || !isRgba(validColor)) return 1; | ||
if (!isRgba(validColor)) return 1; | ||
return Number(validColor.toLowerCase().split(',').slice(-1)[0].replace(/[)|\s]/g, '')); | ||
@@ -305,3 +306,3 @@ } | ||
* @param {string} color Hex|Rgb|Rgba color or color keyword | ||
* @return {RgbaValue|null} Rgba value of the color (Invalid input will return null) | ||
* @return {RgbaValue} Rgba value of the color | ||
*/ | ||
@@ -317,3 +318,3 @@ | ||
* @param {number} opacity The opacity of color | ||
* @return {string|null} Rgb|Rgba color (Invalid input will return null) | ||
* @return {string} Rgb|Rgba color | ||
*/ | ||
@@ -323,3 +324,2 @@ | ||
var rgbValue = getRgbValue(color); | ||
if (!rgbValue) return null; | ||
return typeof opacity === 'number' ? "rgba(" + rgbValue.join(',') + "," + opacity + ")" : "rgb(" + rgbValue.join(',') + ")"; | ||
@@ -330,3 +330,3 @@ } | ||
* @param {string} color Hex|Rgb|Rgba color or color keyword | ||
* @return {string|null} Hex color (Invalid input will return null) | ||
* @return {string} Hex color | ||
*/ | ||
@@ -337,3 +337,2 @@ | ||
var colorValue = getRgbValue(color); | ||
if (!colorValue) return null; | ||
@@ -349,9 +348,9 @@ var format10To16 = function format10To16(_) { | ||
* @param {RgbValue|RgbaValue} value Rgb|Rgba color value | ||
* @return {string|null} Rgb|Rgba color (Invalid input will return null) | ||
* @return {string} Rgb|Rgba color | ||
*/ | ||
function getColorFromRgbValue(value) { | ||
if (!Array.isArray(value)) return null; | ||
if (!Array.isArray(value)) throw new Error("getColorFromRgbValue: " + value + " is not an array"); | ||
var length = value.length; | ||
if (length !== 3 && length !== 4) return null; | ||
if (length !== 3 && length !== 4) throw new Error("getColorFromRgbValue: value length should be 3 or 4"); | ||
return (length === 3 ? 'rgb(' : 'rgba(') + value.join(',') + ')'; | ||
@@ -363,3 +362,3 @@ } | ||
* @param {number} percent of Deepen (1-100) | ||
* @return {string|null} Rgba color (Invalid input will return null) | ||
* @return {string} Rgba color | ||
*/ | ||
@@ -373,3 +372,2 @@ | ||
var rgbaValue = getRgbaValue(color); | ||
if (!rgbaValue) return null; | ||
rgbaValue = rgbaValue.map(function (v, i) { | ||
@@ -386,3 +384,3 @@ return i === 3 ? v : v - Math.ceil(2.55 * percent); | ||
* @param {number} percent of brighten (1-100) | ||
* @return {string|null} Rgba color (Invalid input will return null) | ||
* @return {string} Rgba color | ||
*/ | ||
@@ -396,3 +394,2 @@ | ||
var rgbaValue = getRgbaValue(color); | ||
if (!rgbaValue) return null; | ||
rgbaValue = rgbaValue.map(function (v, i) { | ||
@@ -409,3 +406,3 @@ return i === 3 ? v : v + Math.ceil(2.55 * percent); | ||
* @param {number} percent of opacity | ||
* @return {string|null} Rgba color (Invalid input will return null) | ||
* @return {string} Rgba color | ||
*/ | ||
@@ -419,3 +416,2 @@ | ||
var rgbValue = getRgbValue(color); | ||
if (!rgbValue) return null; | ||
return getColorFromRgbValue(__spreadArrays(rgbValue, [percent / 100])); | ||
@@ -422,0 +418,0 @@ } |
{ | ||
"name": "@jiaminghi/color", | ||
"version": "1.0.0", | ||
"version": "1.1.1", | ||
"author": "JiaMing <743192023@qq.com>", | ||
@@ -16,6 +16,6 @@ "description": "Color extension", | ||
"clean": "rimraf lib dist es types", | ||
"format": "prettier --write .", | ||
"format:check": "prettier --check .", | ||
"type:check": "tsc --noEmit", | ||
"lint": "eslint --ext js,ts src test", | ||
"format:check": "prettier --check .", | ||
"format": "prettier --write .", | ||
"build": "rollup -c", | ||
@@ -66,2 +66,3 @@ "prepare": "npm run clean && npm run check && npm run build", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^2.6.1", | ||
"rollup-plugin-babel": "^4.4.0", | ||
@@ -68,0 +69,0 @@ "rollup-plugin-node-resolve": "^5.2.0", |
@@ -183,5 +183,5 @@ [中文](./README.md) | ||
* @param {number} percent Percent of Deepen (1-100) | ||
* @return {string|null} Rgba color (Invalid input will return null) | ||
* @return {string} Rgba color (Invalid input will throw an error) | ||
*/ | ||
type darken = (color: string, percent: number) => string | null | ||
type darken = (color: string, percent: number) => string | ||
@@ -205,5 +205,5 @@ const before = '#3080E8' | ||
* @param {number} percent Percent of brighten (1-100) | ||
* @return {string|null} Rgba color (Invalid input will return null) | ||
* @return {string} Rgba color (Invalid input will throw an error) | ||
*/ | ||
type lighten = (color: string, percent: number) => string | null | ||
type lighten = (color: string, percent: number) => string | ||
@@ -227,5 +227,5 @@ const before = '#3080E8' | ||
* @param {number} percent Percent of opacity | ||
* @return {string|null} Rgba color (Invalid input will return null) | ||
* @return {string} Rgba color (Invalid input will throw an error) | ||
*/ | ||
type fade = (color: string, percent: number) => string | null | ||
type fade = (color: string, percent: number) => string | ||
@@ -248,5 +248,5 @@ const before = '#3080E8' | ||
* @param {string} color Hex|Rgb|Rgba color or color keyword | ||
* @return {string|null} Hex color (Invalid input will return null) | ||
* @return {string} Hex color (Invalid input will throw an error) | ||
*/ | ||
type toHex = (color: string) => string | null | ||
type toHex = (color: string) => string | ||
@@ -266,5 +266,5 @@ const before = 'rgb(48,128,232)' | ||
* @param {number} opacity The opacity of color | ||
* @return {string|null} Rgb|Rgba color (Invalid input will return null) | ||
* @return {string} Rgb|Rgba color (Invalid input will throw an error) | ||
*/ | ||
type toRgb = (color: string, opacity: number) => string | null | ||
type toRgb = (color: string, opacity: number) => string | ||
@@ -285,5 +285,5 @@ const before = '#3080E8' | ||
* @param {string} color Hex|Rgb|Rgba color or color keyword | ||
* @return {number|null} Color opacity (Invalid input will return null) | ||
* @return {number} Color opacity (Invalid input will throw an error) | ||
*/ | ||
type getOpacity = (color: string) => number | null | ||
type getOpacity = (color: string) => number | ||
@@ -305,6 +305,6 @@ const color1 = '#3080E8' | ||
* @param {string} color Hex|Rgb|Rgba color or color keyword | ||
* @return {RgbValue|null} Rgb value of the color (Invalid input will return null) | ||
* @return {RgbValue} Rgb value of the color (Invalid input will throw an error) | ||
*/ | ||
type RgbValue = [number, number, number] | ||
type getRgbValue = (color: string) => RgbValue | null | ||
type getRgbValue = (color: string) => RgbValue | ||
@@ -323,3 +323,3 @@ const color = '#3080E8' | ||
* @param {string} color Hex|Rgb|Rgba color or color keyword | ||
* @return {RgbaValue|null} Rgba value of the color (Invalid input will return null) | ||
* @return {RgbaValue} Rgba value of the color (Invalid input will throw an error) | ||
*/ | ||
@@ -344,3 +344,3 @@ type RgbaValue = [number, number, number, number] | ||
* @param {Value} value Rgb|Rgba color value | ||
* @return {string|null} Rgb|Rgba color (Invalid input will return null) | ||
* @return {string} Rgb|Rgba color (Invalid input will throw an error) | ||
*/ | ||
@@ -347,0 +347,0 @@ type RgbValue = [number, number, number] |
@@ -183,5 +183,5 @@ [ENGLISH](./README_EN.md) | ||
* @param {number} percent 加深的百分比 (1-100) | ||
* @return {string|null} Rgba颜色 (无效输入将返回null) | ||
* @return {string} Rgba颜色 (无效输入将抛出异常) | ||
*/ | ||
type darken = (color: string, percent: number) => string | null | ||
type darken = (color: string, percent: number) => string | ||
@@ -205,5 +205,5 @@ const before = '#3080E8' | ||
* @param {number} percent 提亮的百分比 (1-100) | ||
* @return {string|null} Rgba颜色 (无效输入将返回null) | ||
* @return {string} Rgba颜色 (无效输入将抛出异常) | ||
*/ | ||
type lighten = (color: string, percent: number) => string | null | ||
type lighten = (color: string, percent: number) => string | ||
@@ -227,5 +227,5 @@ const before = '#3080E8' | ||
* @param {number} Percent 透明度百分比 | ||
* @return {string|null} Rgba颜色 (无效输入将返回null) | ||
* @return {string} Rgba颜色 (无效输入将抛出异常) | ||
*/ | ||
type fade = (color: string, percent: number) => string | null | ||
type fade = (color: string, percent: number) => string | ||
@@ -248,5 +248,5 @@ const before = '#3080E8' | ||
* @param {string} color Hex|Rgb|Rgba颜色或颜色关键字 | ||
* @return {string|null} Hex颜色 (无效输入将返回null) | ||
* @return {string} Hex颜色 (无效输入将抛出异常) | ||
*/ | ||
type toHex = (color: string) => string | false | ||
type toHex = (color: string) => string | ||
@@ -266,5 +266,5 @@ const before = 'rgb(48,128,232)' | ||
* @param {number} opacity 颜色的透明度 (输入该参数将生成Rgba颜色) | ||
* @return {string|null} Rgb或Rgba颜色 (无效输入将返回null) | ||
* @return {string} Rgb或Rgba颜色 (无效输入将抛出异常) | ||
*/ | ||
type toRgb = (color: string, opacity: number) => string | null | ||
type toRgb = (color: string, opacity: number) => string | ||
@@ -285,5 +285,5 @@ const before = '#3080E8' | ||
* @param {string} color Hex|Rgb|Rgba颜色或颜色关键字 | ||
* @return {number|null} 颜色透明度 (无效输入将返回null) | ||
* @return {number} 颜色透明度 (无效输入将抛出异常) | ||
*/ | ||
type getOpacity = (color: string) => number | null | ||
type getOpacity = (color: string) => number | ||
@@ -305,6 +305,6 @@ const color1 = '#3080E8' | ||
* @param {string} color Hex|Rgb|Rgba颜色或颜色关键字 | ||
* @return {RgbValue|null} Rgb值 (无效输入将返回null) | ||
* @return {RgbValue} Rgb值 (无效输入将抛出异常) | ||
*/ | ||
type RgbValue = [number, number, number] | ||
type getRgbValue = (color: string) => RgbValue | null | ||
type getRgbValue = (color: string) => RgbValue | ||
@@ -323,3 +323,3 @@ const color = '#3080E8' | ||
* @param {String} color Hex|Rgb|Rgba颜色或颜色关键字 | ||
* @return {RgbaValue|null} Rgba值 (无效输入将返回null) | ||
* @return {RgbaValue|null} Rgba值 (无效输入将抛出异常) | ||
*/ | ||
@@ -344,3 +344,3 @@ type RgbaValue = [number, number, number, number] | ||
* @param {Value} value Rgb或Rgba颜色的值 | ||
* @return {string|null} Rgb颜色或Rgba颜色 (无效输入将返回null) | ||
* @return {string} Rgb颜色或Rgba颜色 (无效输入将抛出异常) | ||
*/ | ||
@@ -350,3 +350,3 @@ type RgbValue = [number, number, number] | ||
type Value = RgbValue | RgbaValue | ||
type getColorFromRgbValue = (value: Value) => string | null | ||
type getColorFromRgbValue = (value: Value) => string | ||
@@ -353,0 +353,0 @@ const value1 = [48, 128, 232] |
@@ -1,2 +0,2 @@ | ||
import { RgbValue, RgbaValue } from 'types/index' | ||
import { RgbValue, RgbaValue } from './types/index' | ||
import ColorKeywords from './config/keywords' | ||
@@ -61,8 +61,11 @@ | ||
* @param {string} color Hex|Rgb|Rgba color or color keywords | ||
* @return {string|null} Valid color (Invalid input will return null) | ||
* @return {string} Color (Invalid input will throw an error) | ||
*/ | ||
function validator(color: string): string | null { | ||
function validator(color: string): string { | ||
if (isHex(color) || isRgbOrRgba(color)) return color | ||
return getColorByKeyword(color as keyof typeof ColorKeywords) || null | ||
const keywordColor = getColorByKeyword(color as keyof typeof ColorKeywords) | ||
if (!keywordColor) throw new Error(`Color: Invalid Input of ${color}`) | ||
return keywordColor | ||
} | ||
@@ -106,9 +109,7 @@ | ||
* @param {string} color Hex|Rgb|Rgba color or color keyword | ||
* @return {RgbValue|null} Rgb value of the color (Invalid input will return null) | ||
* @return {RgbValue} Rgb value of the color | ||
*/ | ||
export function getRgbValue(color: string): RgbValue | null { | ||
export function getRgbValue(color: string): RgbValue { | ||
const validColor = validator(color) | ||
if (!validColor) return null | ||
const lowerColor = validColor.toLowerCase() | ||
@@ -127,3 +128,3 @@ | ||
if (!validColor || !isRgba(validColor)) return 1 | ||
if (!isRgba(validColor)) return 1 | ||
@@ -142,5 +143,5 @@ return Number( | ||
* @param {string} color Hex|Rgb|Rgba color or color keyword | ||
* @return {RgbaValue|null} Rgba value of the color (Invalid input will return null) | ||
* @return {RgbaValue} Rgba value of the color | ||
*/ | ||
export function getRgbaValue(color: string): RgbaValue | null { | ||
export function getRgbaValue(color: string): RgbaValue { | ||
const rgbValue = getRgbValue(color) | ||
@@ -155,7 +156,6 @@ | ||
* @param {number} opacity The opacity of color | ||
* @return {string|null} Rgb|Rgba color (Invalid input will return null) | ||
* @return {string} Rgb|Rgba color | ||
*/ | ||
export function toRgb(color: string, opacity?: number): string | null { | ||
export function toRgb(color: string, opacity?: number): string { | ||
const rgbValue = getRgbValue(color) | ||
if (!rgbValue) return null | ||
@@ -170,9 +170,8 @@ return typeof opacity === 'number' | ||
* @param {string} color Hex|Rgb|Rgba color or color keyword | ||
* @return {string|null} Hex color (Invalid input will return null) | ||
* @return {string} Hex color | ||
*/ | ||
export function toHex(color: string): string | null { | ||
export function toHex(color: string): string { | ||
if (isHex(color)) return color | ||
const colorValue = getRgbValue(color) | ||
if (!colorValue) return null | ||
@@ -187,9 +186,10 @@ const format10To16 = (_: number): string => Number(_).toString(16).padStart(2, '0') | ||
* @param {RgbValue|RgbaValue} value Rgb|Rgba color value | ||
* @return {string|null} Rgb|Rgba color (Invalid input will return null) | ||
* @return {string} Rgb|Rgba color | ||
*/ | ||
export function getColorFromRgbValue(value: RgbValue | RgbaValue): string | null { | ||
if (!Array.isArray(value)) return null | ||
export function getColorFromRgbValue(value: RgbValue | RgbaValue): string { | ||
if (!Array.isArray(value)) throw new Error(`getColorFromRgbValue: ${value} is not an array`) | ||
const { length } = value | ||
if (length !== 3 && length !== 4) return null | ||
if (length !== 3 && length !== 4) | ||
throw new Error(`getColorFromRgbValue: value length should be 3 or 4`) | ||
@@ -203,7 +203,6 @@ return (length === 3 ? 'rgb(' : 'rgba(') + value.join(',') + ')' | ||
* @param {number} percent of Deepen (1-100) | ||
* @return {string|null} Rgba color (Invalid input will return null) | ||
* @return {string} Rgba color | ||
*/ | ||
export function darken(color: string, percent = 0): string | null { | ||
export function darken(color: string, percent = 0): string { | ||
let rgbaValue = getRgbaValue(color) | ||
if (!rgbaValue) return null | ||
@@ -221,7 +220,6 @@ rgbaValue = rgbaValue | ||
* @param {number} percent of brighten (1-100) | ||
* @return {string|null} Rgba color (Invalid input will return null) | ||
* @return {string} Rgba color | ||
*/ | ||
export function lighten(color: string, percent = 0): string | null { | ||
export function lighten(color: string, percent = 0): string { | ||
let rgbaValue = getRgbaValue(color) | ||
if (!rgbaValue) return null | ||
@@ -239,7 +237,6 @@ rgbaValue = rgbaValue | ||
* @param {number} percent of opacity | ||
* @return {string|null} Rgba color (Invalid input will return null) | ||
* @return {string} Rgba color | ||
*/ | ||
export function fade(color: string, percent = 100): string | null { | ||
export function fade(color: string, percent = 100): string { | ||
const rgbValue = getRgbValue(color) | ||
if (!rgbValue) return null | ||
@@ -246,0 +243,0 @@ return getColorFromRgbValue([...rgbValue, percent / 100] as RgbaValue) |
@@ -19,10 +19,8 @@ import { expect } from 'chai' | ||
const INVALID_COLOR_REGEXP = /Color: Invalid Input of undefined/ | ||
describe('isHex', () => { | ||
it(`isHex()`, () => { | ||
try { | ||
// @ts-ignore | ||
isHex() | ||
} catch (e) { | ||
expect(true).to.be.true | ||
} | ||
// @ts-ignore | ||
expect(isHex()).to.be.false | ||
}) | ||
@@ -61,8 +59,4 @@ | ||
it(`isRgb()`, () => { | ||
try { | ||
// @ts-ignore | ||
isRgb() | ||
} catch (e) { | ||
expect(true).to.be.true | ||
} | ||
// @ts-ignore | ||
expect(isRgb()).to.be.false | ||
}) | ||
@@ -101,8 +95,4 @@ | ||
it(`isRgba()`, () => { | ||
try { | ||
// @ts-ignore | ||
isRgba() | ||
} catch (e) { | ||
expect(true).to.be.true | ||
} | ||
// @ts-ignore | ||
expect(isRgba()).to.be.false | ||
}) | ||
@@ -141,8 +131,4 @@ | ||
it(`isRgbOrRgba()`, () => { | ||
try { | ||
// @ts-ignore | ||
isRgbOrRgba() | ||
} catch (e) { | ||
expect(true).to.be.true | ||
} | ||
// @ts-ignore | ||
expect(isRgbOrRgba()).to.be.false | ||
}) | ||
@@ -180,19 +166,6 @@ | ||
describe('fade', () => { | ||
it(`fade('Not A Color')`, () => { | ||
try { | ||
fade('Not A Color') | ||
} catch (e) { | ||
expect(true).to.be.true | ||
} | ||
it(`fade error`, () => { | ||
expect(fade).to.throw(INVALID_COLOR_REGEXP) | ||
}) | ||
it(`fade()`, () => { | ||
try { | ||
// @ts-ignore | ||
fade() | ||
} catch (e) { | ||
expect(true).to.be.true | ||
} | ||
}) | ||
it(`fade('black', 50)`, () => { | ||
@@ -252,19 +225,6 @@ expect(fade('black', 50)).to.equal('rgba(0,0,0,0.5)') | ||
describe('toHex', () => { | ||
it(`toHex()`, () => { | ||
try { | ||
// @ts-ignore | ||
toHex() | ||
} catch (e) { | ||
expect(true).to.be.true | ||
} | ||
it(`toHex error`, () => { | ||
expect(toHex).to.throw(INVALID_COLOR_REGEXP) | ||
}) | ||
it(`toHex('Not A Color')`, () => { | ||
try { | ||
toHex('Not A Color') | ||
} catch (e) { | ||
expect(true).to.be.true | ||
} | ||
}) | ||
it(`toHex('#000')`, () => { | ||
@@ -292,19 +252,6 @@ expect(toHex('#000')).to.equal('#000') | ||
describe('toRgb', () => { | ||
it(`toRgb()`, () => { | ||
try { | ||
// @ts-ignore | ||
toRgb() | ||
} catch (e) { | ||
expect(true).to.be.true | ||
} | ||
it(`toRgb error`, () => { | ||
expect(toRgb).to.throw(INVALID_COLOR_REGEXP) | ||
}) | ||
it(`toRgb('Not A Color')`, () => { | ||
try { | ||
toRgb('Not A Color') | ||
} catch (e) { | ||
expect(true).to.be.true | ||
} | ||
}) | ||
it(`toRgb('#000')`, () => { | ||
@@ -348,19 +295,6 @@ expect(toRgb('#000')).to.equal('rgb(0,0,0)') | ||
describe('darken', () => { | ||
it(`darken()`, () => { | ||
try { | ||
// @ts-ignore | ||
darken() | ||
} catch (e) { | ||
expect(true).to.be.true | ||
} | ||
it(`darken error`, () => { | ||
expect(darken).to.throw(INVALID_COLOR_REGEXP) | ||
}) | ||
it(`darken('Not A Color')`, () => { | ||
try { | ||
darken('Not A Color') | ||
} catch (e) { | ||
expect(true).to.be.true | ||
} | ||
}) | ||
it(`darken('#3080E8', 20)`, () => { | ||
@@ -396,19 +330,6 @@ expect(darken('#3080E8', 20)).to.equal('rgba(0,77,181,1)') | ||
describe('lighten', () => { | ||
it(`lighten()`, () => { | ||
try { | ||
// @ts-ignore | ||
darken() | ||
} catch (e) { | ||
expect(true).to.be.true | ||
} | ||
it(`lighten error`, () => { | ||
expect(lighten).to.throw(INVALID_COLOR_REGEXP) | ||
}) | ||
it(`lighten('Not A Color')`, () => { | ||
try { | ||
darken('Not A Color') | ||
} catch (e) { | ||
expect(true).to.be.true | ||
} | ||
}) | ||
it(`lighten('#3080E8', 20)`, () => { | ||
@@ -444,19 +365,6 @@ expect(lighten('#3080E8', 20)).to.equal('rgba(99,179,255,1)') | ||
describe('getOpacity', () => { | ||
it(`getOpacity()`, () => { | ||
try { | ||
// @ts-ignore | ||
darken() | ||
} catch (e) { | ||
expect(true).to.be.true | ||
} | ||
it(`getOpacity error`, () => { | ||
expect(getOpacity).to.throw(INVALID_COLOR_REGEXP) | ||
}) | ||
it(`getOpacity('Not A Color')`, () => { | ||
try { | ||
darken('Not A Color') | ||
} catch (e) { | ||
expect(true).to.be.true | ||
} | ||
}) | ||
it(`getOpacity('#000')`, () => { | ||
@@ -499,20 +407,41 @@ expect(getOpacity('#000')).to.equal(1) | ||
describe('getRgbaValue', () => { | ||
it(`getRgbaValue()`, () => { | ||
try { | ||
// @ts-ignore | ||
getRgbValue() | ||
} catch (e) { | ||
expect(true).to.be.true | ||
} | ||
describe('getRgbValue', () => { | ||
it(`getRgbValue error`, () => { | ||
expect(getRgbValue).to.throw(INVALID_COLOR_REGEXP) | ||
}) | ||
it(`getRgbaValue('Not A Color')`, () => { | ||
try { | ||
getRgbValue('Not A Color') | ||
} catch (e) { | ||
expect(true).to.be.true | ||
} | ||
it(`getRgbValue('black')`, () => { | ||
expect(getRgbValue('black')).to.deep.equal([0, 0, 0]) | ||
}) | ||
it(`getRgbValue('#000')`, () => { | ||
expect(getRgbValue('#000')).to.deep.equal([0, 0, 0]) | ||
}) | ||
it(`getRgbValue('#000000')`, () => { | ||
expect(getRgbValue('#000000')).to.deep.equal([0, 0, 0]) | ||
}) | ||
it(`getRgbValue('rgb(0,0,0)')`, () => { | ||
expect(getRgbValue('rgb(0,0,0)')).to.deep.equal([0, 0, 0]) | ||
}) | ||
it(`getRgbValue('rgb(1, 12, 12)')`, () => { | ||
expect(getRgbValue('rgb(1, 12, 123)')).to.deep.equal([1, 12, 123]) | ||
}) | ||
it(`getRgbValue('rgba(1,12,123,1)')`, () => { | ||
expect(getRgbValue('rgba(1,12,123,1)')).to.deep.equal([1, 12, 123]) | ||
}) | ||
it(`getRgbValue('rgba(1, 12, 123, 1)')`, () => { | ||
expect(getRgbValue('rgba(1, 12, 123, 1)')).to.deep.equal([1, 12, 123]) | ||
}) | ||
}) | ||
describe('getRgbaValue', () => { | ||
it(`getRgbaValue error`, () => { | ||
expect(getRgbaValue).to.throw(INVALID_COLOR_REGEXP) | ||
}) | ||
it(`getRgbaValue('black')`, () => { | ||
@@ -551,59 +480,17 @@ expect(getRgbaValue('black')).to.deep.equal([0, 0, 0, 1]) | ||
describe('getRgbaValue', () => { | ||
it(`getRgbValue()`, () => { | ||
try { | ||
// @ts-ignore | ||
getRgbValue() | ||
} catch (e) { | ||
expect(true).to.be.true | ||
} | ||
}) | ||
it(`getRgbValue('Not A Color')`, () => { | ||
try { | ||
getRgbValue('Not A Color') | ||
} catch (e) { | ||
expect(true).to.be.true | ||
} | ||
}) | ||
it(`getRgbValue('black')`, () => { | ||
expect(getRgbValue('black')).to.deep.equal([0, 0, 0]) | ||
}) | ||
it(`getRgbValue('#000')`, () => { | ||
expect(getRgbValue('#000')).to.deep.equal([0, 0, 0]) | ||
}) | ||
it(`getRgbValue('#000000')`, () => { | ||
expect(getRgbValue('#000000')).to.deep.equal([0, 0, 0]) | ||
}) | ||
it(`getRgbValue('rgb(0,0,0)')`, () => { | ||
expect(getRgbValue('rgb(0,0,0)')).to.deep.equal([0, 0, 0]) | ||
}) | ||
it(`getRgbValue('rgb(1, 12, 12)')`, () => { | ||
expect(getRgbValue('rgb(1, 12, 123)')).to.deep.equal([1, 12, 123]) | ||
}) | ||
it(`getRgbValue('rgba(1,12,123,1)')`, () => { | ||
expect(getRgbValue('rgba(1,12,123,1)')).to.deep.equal([1, 12, 123]) | ||
}) | ||
it(`getRgbValue('rgba(1, 12, 123, 1)')`, () => { | ||
expect(getRgbValue('rgba(1, 12, 123, 1)')).to.deep.equal([1, 12, 123]) | ||
}) | ||
}) | ||
describe('getColorFromRgbValue', () => { | ||
it(`getColorFromRgbValue()`, () => { | ||
try { | ||
expect(() => { | ||
// @ts-ignore | ||
getColorFromRgbValue() | ||
} catch (e) { | ||
expect(true).to.equal(true) | ||
} | ||
}).to.throw(/is not an array/) | ||
}) | ||
it(`getColorFromRgbValue([])`, () => { | ||
expect(() => { | ||
// @ts-ignore | ||
getColorFromRgbValue([]) | ||
}).to.throw(/value length should be 3 or 4/) | ||
}) | ||
it(`getColorFromRgbValue([0,0,0])`, () => { | ||
@@ -610,0 +497,0 @@ expect(getColorFromRgbValue([0, 0, 0])).to.equal('rgb(0,0,0)') |
@@ -1,2 +0,2 @@ | ||
import { RgbValue, RgbaValue } from 'types/index'; | ||
import { RgbValue, RgbaValue } from './types/index'; | ||
/** | ||
@@ -29,5 +29,5 @@ * @description Test if a hex color | ||
* @param {string} color Hex|Rgb|Rgba color or color keyword | ||
* @return {RgbValue|null} Rgb value of the color (Invalid input will return null) | ||
* @return {RgbValue} Rgb value of the color | ||
*/ | ||
export declare function getRgbValue(color: string): RgbValue | null; | ||
export declare function getRgbValue(color: string): RgbValue; | ||
/** | ||
@@ -42,5 +42,5 @@ * @description Get the opacity of color | ||
* @param {string} color Hex|Rgb|Rgba color or color keyword | ||
* @return {RgbaValue|null} Rgba value of the color (Invalid input will return null) | ||
* @return {RgbaValue} Rgba value of the color | ||
*/ | ||
export declare function getRgbaValue(color: string): RgbaValue | null; | ||
export declare function getRgbaValue(color: string): RgbaValue; | ||
/** | ||
@@ -50,17 +50,17 @@ * @description Convert color to Rgb|Rgba color | ||
* @param {number} opacity The opacity of color | ||
* @return {string|null} Rgb|Rgba color (Invalid input will return null) | ||
* @return {string} Rgb|Rgba color | ||
*/ | ||
export declare function toRgb(color: string, opacity?: number): string | null; | ||
export declare function toRgb(color: string, opacity?: number): string; | ||
/** | ||
* @description Convert color to Hex color | ||
* @param {string} color Hex|Rgb|Rgba color or color keyword | ||
* @return {string|null} Hex color (Invalid input will return null) | ||
* @return {string} Hex color | ||
*/ | ||
export declare function toHex(color: string): string | null; | ||
export declare function toHex(color: string): string; | ||
/** | ||
* @description Get Color from Rgb|Rgba value | ||
* @param {RgbValue|RgbaValue} value Rgb|Rgba color value | ||
* @return {string|null} Rgb|Rgba color (Invalid input will return null) | ||
* @return {string} Rgb|Rgba color | ||
*/ | ||
export declare function getColorFromRgbValue(value: RgbValue | RgbaValue): string | null; | ||
export declare function getColorFromRgbValue(value: RgbValue | RgbaValue): string; | ||
/** | ||
@@ -70,5 +70,5 @@ * @description Deepen color | ||
* @param {number} percent of Deepen (1-100) | ||
* @return {string|null} Rgba color (Invalid input will return null) | ||
* @return {string} Rgba color | ||
*/ | ||
export declare function darken(color: string, percent?: number): string | null; | ||
export declare function darken(color: string, percent?: number): string; | ||
/** | ||
@@ -78,5 +78,5 @@ * @description Brighten color | ||
* @param {number} percent of brighten (1-100) | ||
* @return {string|null} Rgba color (Invalid input will return null) | ||
* @return {string} Rgba color | ||
*/ | ||
export declare function lighten(color: string, percent?: number): string | null; | ||
export declare function lighten(color: string, percent?: number): string; | ||
/** | ||
@@ -86,5 +86,5 @@ * @description Adjust color opacity | ||
* @param {number} percent of opacity | ||
* @return {string|null} Rgba color (Invalid input will return null) | ||
* @return {string} Rgba color | ||
*/ | ||
export declare function fade(color: string, percent?: number): string | null; | ||
export declare function fade(color: string, percent?: number): string; | ||
declare const _default: { | ||
@@ -91,0 +91,0 @@ isHex: typeof isHex; |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
157307
25
2442