mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-14 21:28:03 +08:00
This PR replaces the set of methods related to validation and normalization of input values in the select-kit utils mixin with simple exported functions from a input-utils lib file. We maintain the `_normalize` method on the select-kit component because there are external repos dependent on that part of the interface. We'll replace the remainder of the mixin with another utils lib file in a separate PR.
24 lines
743 B
JavaScript
24 lines
743 B
JavaScript
export function isValidInput(eventKey) {
|
|
// relying on passing the event to the input is risky as it could not work
|
|
// dispatching the event won't work as the event won't be trusted
|
|
// safest solution is to filter event and prefill filter with it
|
|
const nonInputKeysRegex =
|
|
/F\d+|Arrow.+|Meta|Alt|Control|Shift|Delete|Enter|Escape|Tab|Space|Insert|Backspace/;
|
|
return !nonInputKeysRegex.test(eventKey);
|
|
}
|
|
|
|
export function isNumeric(input) {
|
|
return !isNaN(parseFloat(input)) && isFinite(input);
|
|
}
|
|
|
|
export function normalize(input) {
|
|
if (input) {
|
|
input = input.toLowerCase();
|
|
|
|
if (typeof input.normalize === "function") {
|
|
input = input.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
|
}
|
|
}
|
|
|
|
return input;
|
|
}
|