colors-convert
Advanced tools
Comparing version 1.0.7 to 1.0.9
@@ -1,3 +0,6 @@ | ||
export { isHex, isRgb, isRgba, isCmyk, isColor } from './types/types'; | ||
export { color2string, color2cssString, hex2rgbOrRgba, hex2rgba, rgb2hex, hex2hexWithAlpha, rgb2cmyk, hex2cmyk, cmyk2rgb, cmyk2hex, } from './lib/color-utils'; | ||
export { isHex, isRgb, isRgba, isCmyk, isColor } from './types/isType'; | ||
export { color2string, color2cssString } from './lib/color'; | ||
export { hex2rgbOrRgba, hex2rgba, hex2hexWithAlpha, hex2cmyk } from './lib/hex'; | ||
export { rgb2hex, rgb2cmyk } from './lib/rgb'; | ||
export { cmyk2rgb, cmyk2hex } from './lib/cmyk'; | ||
export { getRandomColor } from './lib/random'; |
@@ -1,4 +0,7 @@ | ||
export { isHex, isRgb, isRgba, isCmyk, isColor } from './types/types'; | ||
export { color2string, color2cssString, hex2rgbOrRgba, hex2rgba, rgb2hex, hex2hexWithAlpha, rgb2cmyk, hex2cmyk, cmyk2rgb, cmyk2hex, } from './lib/color-utils'; | ||
export { isHex, isRgb, isRgba, isCmyk, isColor } from './types/isType'; | ||
export { color2string, color2cssString } from './lib/color'; | ||
export { hex2rgbOrRgba, hex2rgba, hex2hexWithAlpha, hex2cmyk } from './lib/hex'; | ||
export { rgb2hex, rgb2cmyk } from './lib/rgb'; | ||
export { cmyk2rgb, cmyk2hex } from './lib/cmyk'; | ||
export { getRandomColor } from './lib/random'; | ||
//# sourceMappingURL=index.js.map |
@@ -6,4 +6,4 @@ // TODO: not only hex | ||
export var getRandomColor = function () { | ||
var alphabet = "0123456789ABCDEF"; | ||
var color = "#"; | ||
var alphabet = '0123456789ABCDEF'; | ||
var color = '#'; | ||
for (var i = 0; i < 6; i++) { | ||
@@ -10,0 +10,0 @@ color += alphabet[Math.floor(Math.random() * 16)]; |
@@ -20,6 +20,1 @@ export declare type HEX = string; | ||
export declare type COLOR = HEX | RGB | RGBA | CMYK; | ||
export declare function isHex(color: any): color is HEX; | ||
export declare function isRgb(color: any): color is RGB; | ||
export declare function isRgba(color: any): color is RGBA; | ||
export declare function isCmyk(color: any): color is CMYK; | ||
export declare function isColor(color: any): color is COLOR; |
@@ -1,57 +0,1 @@ | ||
import { between, sameContent } from '../lib/utils'; | ||
// Accept: | ||
// - long form: #FFFFFF | ||
// - short form: #FFF | ||
// - long form with opacity: #FFFFFFFF (white with opacity FF=1) | ||
export function isHex(color) { | ||
var reg = /^#([0-9A-F]{3}){1,2}([0-9A-F]{2})?$/i; | ||
return reg.test(color); | ||
} | ||
// Accept an object like this {r, g, b} with r,b,g numeric values in range [0, 255] | ||
export function isRgb(color) { | ||
var keys = Object.keys(color); | ||
if (keys.length !== 3) | ||
return false; | ||
if (!sameContent(keys, ['r', 'g', 'b'])) | ||
return false; | ||
var isValid = function (value) { return typeof value === 'number' && between(value, [0, 255]); }; | ||
var r = isValid(color.r); | ||
var g = isValid(color.g); | ||
var b = isValid(color.b); | ||
return r && g && b; | ||
} | ||
// TODO: add support for values in [0, 100]% | ||
// TODO: accept also rgba without a, consider it 1 as default | ||
// Accept an object like this {r, g, b, a} with r,g,b numeric values in range [0, 255] and a in range [0,1] | ||
export function isRgba(color) { | ||
var keys = Object.keys(color); | ||
if (keys.length !== 4) | ||
return false; | ||
if (!sameContent(keys, ['r', 'g', 'b', 'a'])) | ||
return false; | ||
var isValid = function (value) { return typeof value === 'number' && between(value, [0, 255]); }; | ||
var r = isValid(color.r); | ||
var g = isValid(color.g); | ||
var b = isValid(color.b); | ||
var a = typeof color.a === 'number' && between(color.a, [0, 1]); | ||
return r && g && b && a; | ||
} | ||
// TODO: add support for values in [0, 1] | ||
// Accept an object like this {c, m, y, k} with c,m,y,k numeric values in range [0, 100] | ||
export function isCmyk(color) { | ||
var keys = Object.keys(color); | ||
if (keys.length !== 4) | ||
return false; | ||
if (!sameContent(keys, ['c', 'm', 'y', 'k'])) | ||
return false; | ||
var isValid = function (value) { return typeof value === 'number' && between(value, [0, 100]); }; | ||
var c = isValid(color.c); | ||
var m = isValid(color.m); | ||
var y = isValid(color.y); | ||
var k = isValid(color.k); | ||
return c && m && y && k; | ||
} | ||
export function isColor(color) { | ||
return isHex(color) || isRgb(color) || isRgba(color) || isCmyk(color); | ||
} | ||
//# sourceMappingURL=types.js.map |
{ | ||
"name": "colors-convert", | ||
"version": "1.0.7", | ||
"version": "1.0.9", | ||
"main": "dist/index.js", | ||
@@ -31,5 +31,6 @@ "types": "dist/index.d.ts", | ||
"coverage-interactive-watch": "npx live-server --port=9000 coverage", | ||
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"", | ||
"lint": "tslint -p tsconfig.json", | ||
"prepublish": "rm -rf dist/ && tsc", | ||
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"", | ||
"lint": "tslint -p tsconfig.json" | ||
"clean": "yarn format && yarn lint" | ||
}, | ||
@@ -36,0 +37,0 @@ "files": [ |
@@ -16,6 +16,7 @@ # Colors-convert | ||
- `yarn coverage-interactive-watch` run interactive coverage test in watch mode (look at http://127.0.0.1:9000/lcov-report/) | ||
- `yarn prepublish` to remove the dist folder, ricreate it and compile Typescript | ||
- `yarn publish` to publish the package on NPM | ||
- `yarn format` to format the code using Prettier | ||
- `yarn lint` to lint the code using tslint. | ||
- `yarn clean` format and lint code | ||
- `yarn prepublish` to remove the dist folder, ricreate it and compile Typescript | ||
@@ -22,0 +23,0 @@ So, to publish on NPM: |
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
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
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
50768
50
540
30
1