@thangk/easythemer
Version:
Easily generate shades from a colour palette for use in your app
34 lines (33 loc) • 943 B
TypeScript
/**
* Validate user's hex code input to make sure it's a valid hex code.
*
* Logic flow:
* 1. check length
* - 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
* @getters getResult()
*/
export default class validateHex<T> {
private result;
private errors;
private errmsg;
private hexInput;
constructor(hexInput: string);
get getResult(): T | null;
get isError(): boolean;
get errorsList(): string[];
get getInput(): string;
private addError;
private setErrorState;
private showErrors;
private isLenTooLong;
private isLenTooShort;
private isLen3Or5;
private isLen6;
private addHashIfNeeded;
}