mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Color validation extended
This commit is contained in:
@@ -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
4
color/color.d.ts
vendored
@@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user