@asamuzakjp/css-color
Advanced tools
Comparing version 2.4.0 to 2.5.0
@@ -54,3 +54,3 @@ { | ||
}, | ||
"version": "2.4.0" | ||
"version": "2.5.0" | ||
} |
@@ -20,3 +20,3 @@ # CSS color | ||
```javascript | ||
import { convert, resolve } from '@asamuzakjp/css-color'; | ||
import { convert, isColor, resolve } from '@asamuzakjp/css-color'; | ||
@@ -29,2 +29,5 @@ const resolvedValue = | ||
// '#008000' | ||
const result = isColor('green'); | ||
// true | ||
``` | ||
@@ -229,2 +232,14 @@ | ||
### isColor(color) | ||
is valid color type | ||
#### Parameters | ||
* `color` **[string][133]** color value | ||
* system colors are not supported | ||
Returns **[boolean][136]** | ||
--- | ||
@@ -231,0 +246,0 @@ Copyright (c) 2024 [asamuzaK (Kazz)](https://github.com/asamuzaK/) |
@@ -10,1 +10,2 @@ /*! | ||
export { resolve } from './js/resolve.js'; | ||
export { isColor } from './js/util.js'; |
@@ -9,7 +9,6 @@ /** | ||
import { getType, isString } from './common.js'; | ||
import { valueToJsonString } from './util.js'; | ||
import { isColor, valueToJsonString } from './util.js'; | ||
/* constants */ | ||
import { NAMED_COLORS } from './color.js'; | ||
import { FUNC_CALC, FUNC_VAR, SYN_COLOR_TYPE, SYN_MIX } from './constant.js'; | ||
import { FUNC_CALC, FUNC_VAR } from './constant.js'; | ||
const { | ||
@@ -19,6 +18,2 @@ CloseParen: CLOSE_PAREN, Comment: COMMENT, Ident: IDENT, Whitespace: W_SPACE | ||
/* regexp */ | ||
const REG_COLOR = new RegExp(`^(?:${SYN_COLOR_TYPE})$`); | ||
const REG_MIX = new RegExp(`${SYN_MIX}`); | ||
/* cached results */ | ||
@@ -30,23 +25,2 @@ export const cachedResults = new LRUCache({ | ||
/** | ||
* is color | ||
* @param {string} value - value | ||
* @returns {boolean} - result | ||
*/ | ||
export const isColor = value => { | ||
let bool; | ||
if (isString(value)) { | ||
value = value.toLowerCase().trim(); | ||
if (/^[a-z]+$/.test(value)) { | ||
if (/^(?:currentcolor|transparent)$/.test(value) || | ||
Object.prototype.hasOwnProperty.call(NAMED_COLORS, value)) { | ||
bool = true; | ||
} | ||
} else if (REG_COLOR.test(value) || REG_MIX.test(value)) { | ||
bool = true; | ||
} | ||
} | ||
return !!bool; | ||
}; | ||
/** | ||
* resolve CSS variable | ||
@@ -53,0 +27,0 @@ * @param {Array.<Array>} tokens - tokens |
@@ -5,3 +5,35 @@ /** | ||
import { isString } from './common.js'; | ||
/* constants */ | ||
import { NAMED_COLORS } from './color.js'; | ||
import { SYN_COLOR_TYPE, SYN_MIX } from './constant.js'; | ||
/* regexp */ | ||
const REG_COLOR = new RegExp(`^(?:${SYN_COLOR_TYPE})$`); | ||
const REG_MIX = new RegExp(`${SYN_MIX}`); | ||
/** | ||
* is color | ||
* @param {string} value - value | ||
* @returns {boolean} - result | ||
*/ | ||
export const isColor = value => { | ||
if (isString(value)) { | ||
value = value.toLowerCase().trim(); | ||
if (value) { | ||
if (/^[a-z]+$/.test(value)) { | ||
if (/^(?:currentcolor|transparent)$/.test(value) || | ||
Object.prototype.hasOwnProperty.call(NAMED_COLORS, value)) { | ||
return true; | ||
} | ||
} else if (REG_COLOR.test(value) || REG_MIX.test(value)) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
}; | ||
/** | ||
* value to JSON string | ||
@@ -8,0 +40,0 @@ * @param {*} value - value |
export { convert } from "./js/convert.js"; | ||
export { resolve } from "./js/resolve.js"; | ||
export { isColor } from "./js/util.js"; |
@@ -9,3 +9,2 @@ export function resolveCssVariable(tokens: Array<any[]>, opt?: { | ||
export const cachedResults: LRUCache<{}, {}, unknown>; | ||
export function isColor(value: string): boolean; | ||
import { LRUCache } from 'lru-cache'; |
@@ -0,1 +1,2 @@ | ||
export function isColor(value: string): boolean; | ||
export function valueToJsonString(value: any, func?: boolean): string; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
1311190
5522
262