MCPcopy Create free account
hub / github.com/Rich-Harris/magic-string / slice

Method slice

benchmark/data-min.js:514–538  ·  view source on GitHub ↗
(t = 0, e = this.original.length)

Source from the content-addressed store, hash-verified

512 );
513 }
514 slice(t = 0, e = this.original.length) {
515 for (; t < 0; ) t += this.original.length;
516 for (; e < 0; ) e += this.original.length;
517 let n = '',
518 i = this.firstChunk;
519 for (; i && (i.start > t || i.end <= t); ) {
520 if (i.start < e && i.end >= e) return n;
521 i = i.next;
522 }
523 if (i && i.edited && i.start !== t)
524 throw new Error(`Cannot use replaced character ${t} as slice start anchor.`);
525 const r = i;
526 for (; i; ) {
527 i.intro && (r !== i || i.start === t) && (n += i.intro);
528 const s = i.start < e && i.end >= e;
529 if (s && i.edited && i.end !== e)
530 throw new Error(`Cannot use replaced character ${e} as slice end anchor.`);
531 const h = r === i ? t - i.start : 0,
532 o = s ? i.content.length + e - i.end : i.content.length;
533 if (((n += i.content.slice(h, o)), i.outro && (!s || i.end === e) && (n += i.outro), s))
534 break;
535 i = i.next;
536 }
537 return n;
538 }
539 snip(t, e) {
540 const n = this.clone();
541 return (n.remove(0, t), n.remove(e, n.original.length), n);

Callers 6

constructorMethod · 0.45
splitMethod · 0.45
cloneMethod · 0.45
overwriteMethod · 0.45
indentMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected