imask
Version:
vanilla javascript input mask
48 lines (39 loc) • 1.21 kB
JavaScript
import IMask from './holder.js';
/** Provides details of changing model value */
class ChangeDetails {
/** Inserted symbols */
/** Additional offset if any changes occurred before tail */
/** Raw inserted is used by dynamic mask */
/** Can skip chars */
static normalize(prep) {
return Array.isArray(prep) ? prep : [prep, new ChangeDetails()];
}
constructor(details) {
Object.assign(this, {
inserted: '',
rawInserted: '',
tailShift: 0,
skip: false
}, details);
}
/** Aggregate changes */
aggregate(details) {
this.inserted += details.inserted;
this.rawInserted += details.rawInserted;
this.tailShift += details.tailShift;
this.skip = this.skip || details.skip;
return this;
}
/** Total offset considering all changes */
get offset() {
return this.tailShift + this.inserted.length;
}
get consumed() {
return Boolean(this.rawInserted) || this.skip;
}
equals(details) {
return this.inserted === details.inserted && this.tailShift === details.tailShift && this.rawInserted === details.rawInserted && this.skip === details.skip;
}
}
IMask.ChangeDetails = ChangeDetails;
export { ChangeDetails as default };