Color validation extended

This commit is contained in:
vakrilov
2015-07-27 17:09:51 +03:00
parent 5902ab4981
commit 312d113059
2 changed files with 8 additions and 4 deletions

View File

@@ -3,7 +3,7 @@ import types = require("utils/types");
import knownColors = require("color/known-colors"); import knownColors = require("color/known-colors");
var AMP = "#"; var AMP = "#";
var HEX_REGEX = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i; var HEX_REGEX = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$|(^#[0-9A-F]{8}$)/i;
export class Color implements definition.Color { export class Color implements definition.Color {
private _a: number; private _a: number;
@@ -108,7 +108,11 @@ export class Color implements definition.Color {
return value1.equals(value2); return value1.equals(value2);
} }
public static isValid(value: string): boolean { public static isValid(value: any): boolean {
if (types.isNullOrUndefined(value) || value instanceof Color) {
return true;
}
if (!types.isString(value)) { if (!types.isString(value)) {
return false; return false;
} }

4
color/color.d.ts vendored
View File

@@ -70,9 +70,9 @@ declare module "color" {
public static equals(value1: Color, value2: Color): boolean; public static equals(value1: Color, value2: Color): boolean;
/** /**
* Validates if a string value can be converted to color. * Validates if a value can be converted to color.
* @param value Input string. * @param value Input string.
*/ */
public static isValid(value: string): boolean; public static isValid(value: any): boolean;
} }
} }