UNPKG

react-native-advanced-input-mask

Version:

Text input mask for React Native on iOS, Android and web. Synchronous and easy formatting without hustle

42 lines 1.17 kB
import Mask from "./Mask"; import RTLCaretStringIterator from "./RTLCaretStringIterator"; export default class RTLMask extends Mask { static rtlCache = new Map(); constructor(format, customNotations) { super(RTLMask.reversedFormat(format), customNotations); } static getOrCreate(format, customNotations) { const key = RTLMask.reversedFormat(format); const cachedMask = RTLMask.rtlCache.get(key); if (!cachedMask) { const newMask = new RTLMask(format, customNotations); RTLMask.rtlCache.set(key, newMask); return newMask; } return cachedMask; } apply(text) { return super.apply(text.reversed()).reversed(); } makeIterator(text) { return new RTLCaretStringIterator(text); } static reversedFormat(format) { const mapped = format.split("").reduceRight((acc, char) => { switch (char) { case "[": return acc + "]"; case "]": return acc + "["; case "{": return acc + "}"; case "}": return acc + "{"; default: return acc + char; } }, ""); return mapped; } } //# sourceMappingURL=RTLMask.js.map