react-native-advanced-input-mask
Version:
Text input mask for React Native on iOS, Android and web. Synchronous and easy formatting without hustle
44 lines • 1.46 kB
JavaScript
import { getCharacterTypeString } from "../utils";
import State from "./State";
class ValueState extends State {
constructor(child, valueState) {
super(child);
this.stateType = valueState;
}
accepts(character) {
if ("name" in this.stateType) {
if (this.stateType.name === "ellipsis") {
return this.checkEllipsis(this.stateType.inheritedType, character);
}
return this.stateType.regex.test(character);
}
return this.stateType.characterSet.includes(character);
}
checkEllipsis(stateType, character) {
if ("name" in stateType) {
if (stateType.name === "ellipsis") {
this.checkEllipsis(stateType.inheritedType, character);
} else {
return stateType.regex.test(character);
}
}
return stateType.characterSet.includes(character);
}
accept = character => this.accepts(character) ? {
state: this.nextState(),
insert: character,
pass: true,
value: character
} : null;
get isElliptical() {
return "name" in this.stateType && this.stateType.name === "ellipsis";
}
nextState = () => this.isElliptical ? this : this.child;
toString = () => {
var _this$child;
const typeStr = getCharacterTypeString(this.stateType);
return `${typeStr} -> ${((_this$child = this.child) === null || _this$child === void 0 ? void 0 : _this$child.toString()) ?? "null"}`;
};
}
export default ValueState;
//# sourceMappingURL=ValueState.js.map