react-native-advanced-input-mask
Version:
Text input mask for React Native on iOS, Android and web. Synchronous and easy formatting without hustle
40 lines (32 loc) • 864 B
text/typescript
import State from "./State";
import type { Next } from "../types";
class FixedState extends State {
ownCharacter: string;
constructor(child: State, ownCharacter: string) {
super(child);
this.ownCharacter = ownCharacter;
}
accept: (char: string) => Next = (char) =>
char === this.ownCharacter
? {
state: this.nextState(),
pass: true,
insert: char,
value: char,
}
: {
state: this.nextState(),
insert: this.ownCharacter,
value: this.ownCharacter,
pass: false,
};
autocomplete: () => Next = () => ({
state: this.nextState(),
insert: this.ownCharacter,
value: this.ownCharacter,
pass: false,
});
toString = () =>
`{${this.ownCharacter}} -> ${this.child?.toString() ?? "null"} `;
}
export default FixedState;