Using package validate-color to validate css colors.
This commit is contained in:
parent
ede36695cd
commit
bcdee7eb2b
6
package-lock.json
generated
6
package-lock.json
generated
@ -7031,6 +7031,12 @@
|
|||||||
"integrity": "sha512-l8lCEmLcLYZh4nbunNZvQCJc5pv7+RCwa8q/LdUx8u7lsWvPDKmpodJAJNwkAhJC//dFY48KuIEmjtd4RViDrA==",
|
"integrity": "sha512-l8lCEmLcLYZh4nbunNZvQCJc5pv7+RCwa8q/LdUx8u7lsWvPDKmpodJAJNwkAhJC//dFY48KuIEmjtd4RViDrA==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"validate-color": {
|
||||||
|
"version": "2.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/validate-color/-/validate-color-2.2.1.tgz",
|
||||||
|
"integrity": "sha512-1eDb1zqP6W6bbfKKl6dRXObelNoQpW7aF3BUTh2AivWuhcD0pa3ejwURWqrVsyKJMLBMlHLFcM3sj5J+dSFhbg==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"validate-npm-package-license": {
|
"validate-npm-package-license": {
|
||||||
"version": "3.0.4",
|
"version": "3.0.4",
|
||||||
"resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz",
|
||||||
|
@ -64,6 +64,7 @@
|
|||||||
"svgo": "^2.8.0",
|
"svgo": "^2.8.0",
|
||||||
"ts-loader": "^8.3.0",
|
"ts-loader": "^8.3.0",
|
||||||
"typescript": "^4.3.5",
|
"typescript": "^4.3.5",
|
||||||
|
"validate-color": "^2.2.1",
|
||||||
"webpack": "^4.46.0",
|
"webpack": "^4.46.0",
|
||||||
"webpack-cli": "^3.3.12"
|
"webpack-cli": "^3.3.12"
|
||||||
},
|
},
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import type { ChatType } from './types'
|
import type { ChatType } from './types'
|
||||||
|
const validateColor = require('validate-color').default
|
||||||
|
|
||||||
type AutoColorValue = string
|
type AutoColorValue = string
|
||||||
|
|
||||||
@ -38,12 +39,7 @@ function areAutoColorsValid (autocolors: AutoColors): true | string[] {
|
|||||||
for (const k in autocolors) {
|
for (const k in autocolors) {
|
||||||
const color = autocolors[k as keyof AutoColors]
|
const color = autocolors[k as keyof AutoColors]
|
||||||
// FIXME: there are missing cases. For now there are only basic values formats.
|
// FIXME: there are missing cases. For now there are only basic values formats.
|
||||||
if (
|
if (!validateColor(color)) {
|
||||||
!/^rgb\(\d{1,3},\s*\d{1,3},\s*\d{1,3}\)$/.test(color) &&
|
|
||||||
!/^rgba\(\d{1,3},\s*\d{1,3},\s*\d{1,3},\s*(1|0|0?.\d+)\)$/.test(color) &&
|
|
||||||
!/^#[0-9a-fA-F]{3,6}$/.test(color) &&
|
|
||||||
!/^[a-z]+$/
|
|
||||||
) {
|
|
||||||
errors.push(color)
|
errors.push(color)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user