react-native-advanced-input-mask
Version:
Text input mask for React Native on iOS, Android and web. Synchronous and easy formatting without hustle
35 lines • 1.01 kB
JavaScript
import { getCharacterTypeString } from "../utils";
import State from "./State";
class OptionalValueState extends State {
constructor(child, stateType) {
super(child);
this.stateType = stateType;
}
accepts(character) {
if (this.stateType) {
if ("name" in this.stateType) {
return this.stateType.regex.test(character);
}
return this.stateType.characterSet.includes(character);
}
return false;
}
accept = character => this.accepts(character) ? {
state: this.nextState(),
insert: character,
pass: true,
value: character
} : {
state: this.nextState(),
insert: null,
pass: false,
value: null
};
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 OptionalValueState;
//# sourceMappingURL=OptionalValueState.js.map