mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Fix: crashes when applying css
This commit is contained in:
@@ -3,6 +3,7 @@ import types = require("utils/types");
|
||||
import knownColors = require("color/known-colors");
|
||||
|
||||
var AMP = "#";
|
||||
var HEX_REGEX = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i;
|
||||
|
||||
export class Color implements definition.Color {
|
||||
private _a: number;
|
||||
@@ -107,6 +108,18 @@ export class Color implements definition.Color {
|
||||
return value1.equals(value2);
|
||||
}
|
||||
|
||||
public static isValid(value: string): boolean {
|
||||
if (!types.isString(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (knownColors.isKnownName(value)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return HEX_REGEX.test(value);
|
||||
}
|
||||
|
||||
private _buildHex(): string {
|
||||
return AMP + this._componentToHex(this._a) + this._componentToHex(this._r) + this._componentToHex(this._g) + this._componentToHex(this._b);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user