Motivation
There is a gap in the magic-string API that insertLeft() and insertRight() cannot accommodate.
Proposal
New methods:
-
s.prependLeft( index, content )
-
s.appendRight( index, content )
Synonyms for existing methods for naming consistency:
-
s.appendLeft( index, content )
- appendLeft is a synonym for insertLeft
-
s.prependRight( index, content )
- prependRight is a synonym for insertRight
Illustrative example:
var s = new MagicString('0123456789');
s.insertLeft(5, 'A');
s.insertRight(5, 'a');
s.insertRight(5, 'b');
s.insertLeft(5, 'B');
s.insertLeft(5, 'C');
s.insertRight(5, 'c');
// s === '01234ABCcba56789'
console.log(s.toString());
console.log('left of 5:', s.slice(0, 5));
// left of 5: 01234ABC
console.log('right of 5:', s.slice(5));
// right of 5: cba56789
//
// Proposed methods
//
s.prependLeft(5, '<');
s.prependLeft(5, '{');
// s === '01234{<ABCcba56789'
s.appendRight(5, '>');
s.appendRight(5, '}');
// s === '01234{<ABCcba>}56789'
s.appendLeft(5, '('); // appendLeft is a synonym for insertLeft
s.appendLeft(5, '['); // appendLeft is a synonym for insertLeft
// s === '01234{<ABC([cba>}56789'
s.prependRight(5, ')'); // prependRight is a synonym for insertRight
s.prependRight(5, ']'); // prependRight is a synonym for insertRight
// s === '01234{<ABC([])cba>}56789'
console.log('left of 5:', s.slice(0, 5));
// left of 5: '01234{<ABC(['
console.log('right of 5:', s.slice(5));
// right of 5: '])cba>}56789'
Motivation
There is a gap in the magic-string API that
insertLeft()andinsertRight()cannot accommodate.Proposal
New methods:
s.prependLeft( index, content )
s.appendRight( index, content )
Synonyms for existing methods for naming consistency:
s.appendLeft( index, content )
s.prependRight( index, content )
Illustrative example: