@thangk/easythemer
Version:
Easily generate shades from a colour palette for use in your app
34 lines (33 loc) • 1.04 kB
TypeScript
/**
* Validate user's hex code input to make sure it's a valid hex code.
*
* Logic flow:
* - len > 6, too long, error
* - len < 3, too short, error
* - len = 3 or 5, is # the one missing? yes: add it at front, no: error
* - len = 6, is # at the front? yes: success, no: error
* - success status: len = 6 wit # at front or len = 5 with no #, then add at front
*
* @param hexInput Hex code string to validate.
* @getters getResult(), getHexInput(), hasErrors(), getErrorsList()
* @result string or null
*/
export default class ValidateHex {
private result;
private errors;
private errmsg;
private hexInput;
constructor(hexInput: string);
get getResult(): string | null;
get getHexInput(): string;
get hasErrors(): boolean;
get getErrorsList(): string[];
private addError;
private setErrorState;
private showErrors;
isLenTooLong(): boolean;
private isLenTooShort;
private isLen4Or7;
private isLenNot6;
private addHashIfNeeded;
}