MCPcopy
hub / github.com/uNmAnNeR/imaskjs / append

Function append

packages/imask/src/masked/base.ts:304–331  ·  view source on GitHub ↗

Appends symbols considering flags

(str: string, flags?: AppendFlags, tail?: string | String | TailDetails)

Source from the content-addressed store, hash-verified

302
303 /** Appends symbols considering flags */
304 append (str: string, flags?: AppendFlags, tail?: string | String | TailDetails): ChangeDetails {
305 if (!isString(str)) throw new Error('value should be string');
306 const checkTail = isString(tail) ? new ContinuousTailDetails(String(tail)) : tail as TailDetails;
307 if (flags?.tail) flags._beforeTailState = this.state;
308
309 let details;
310 [str, details] = this.doPrepare(str, flags);
311
312 for (let ci=0; ci<str.length; ++ci) {
313 const d = this._appendChar(str[ci], flags, checkTail);
314 if (!d.rawInserted && !this.doSkipInvalid(str[ci], flags, checkTail)) break;
315 details.aggregate(d);
316 }
317
318 if ((this.eager === true || this.eager === 'append') && flags?.input && str) {
319 details.aggregate(this._appendEager());
320 }
321
322 // append tail but aggregate only tailShift
323 if (checkTail != null) {
324 details.tailShift += this.appendTail(checkTail).tailShift;
325 // TODO it's a good idea to clear state after appending ends
326 // but it causes bugs when one append calls another (when dynamic dispatch set rawInputValue)
327 // this._resetBeforeTailState();
328 }
329
330 return details;
331 }
332
333 remove (fromPos: number=0, toPos: number=this.displayValue.length): ChangeDetails {
334 this._value = this.displayValue.slice(0, fromPos) + this.displayValue.slice(toPos);

Callers

nothing calls this directly

Calls 7

isStringFunction · 0.90
doPrepareMethod · 0.80
doSkipInvalidMethod · 0.80
aggregateMethod · 0.80
_appendCharMethod · 0.65
_appendEagerMethod · 0.65
appendTailMethod · 0.65

Tested by

no test coverage detected