24 lines
649 B
TypeScript
24 lines
649 B
TypeScript
/**
|
|
* The character counter's states, for fields with a length limit.
|
|
*
|
|
* @module
|
|
*/
|
|
|
|
/**
|
|
* Returns the counter's modifier class for `len` characters out of `max`: warn
|
|
* from 85%, danger at the limit, none below.
|
|
*/
|
|
export function charCountClass(len: number, max: number): string {
|
|
if (len >= max) return " text-editor-count--danger";
|
|
if (len >= max * 0.85) return " text-editor-count--warn";
|
|
return "";
|
|
}
|
|
|
|
/**
|
|
* Checks whether `value` is past `max` — the counter's danger state past its
|
|
* edge, and what the server would refuse.
|
|
*/
|
|
export function overLimit(value: string, max: number): boolean {
|
|
return value.length > max;
|
|
}
|