Class: BindingMagicString
Constructors
Constructor
new BindingMagicString(
source,options?):BindingMagicString
Parameters
source
string
options?
BindingMagicStringOptions | null
Returns
BindingMagicString
Accessors
filename
Get Signature
get filename():
string|null
Returns
string | null
Methods
append()
append(
content):this
Parameters
content
string
Returns
this
appendLeft()
appendLeft(
index,content):this
Parameters
index
number
content
string
Returns
this
appendRight()
appendRight(
index,content):this
Parameters
index
number
content
string
Returns
this
clone()
clone():
BindingMagicString
Returns a clone of the MagicString instance.
Returns
BindingMagicString
hasChanged()
hasChanged():
boolean
Returns
boolean
indent()
indent(
indentor?):this
Parameters
indentor?
string | null
Returns
this
insert()
insert(
index,content):void
Deprecated method that throws an error directing users to use prependRight or appendLeft. This matches the original magic-string API which deprecated this method.
Parameters
index
number
content
string
Returns
void
isEmpty()
isEmpty():
boolean
Returns
boolean
lastChar()
lastChar():
string
Returns the last character of the generated string, or an empty string if empty.
Returns
string
lastLine()
lastLine():
string
Returns the content after the last newline in the generated string.
Returns
string
length()
length():
number
Returns
number
move()
move(
start,end,index):this
Alias for relocate to match the original magic-string API. Moves the characters from start to end to index. Returns this for method chaining.
Parameters
start
number
end
number
index
number
Returns
this
overwrite()
overwrite(
start,end,content):this
Parameters
start
number
end
number
content
string
Returns
this
prepend()
prepend(
content):this
Parameters
content
string
Returns
this
prependLeft()
prependLeft(
index,content):this
Parameters
index
number
content
string
Returns
this
prependRight()
prependRight(
index,content):this
Parameters
index
number
content
string
Returns
this
relocate()
relocate(
start,end,to):this
Parameters
start
number
end
number
to
number
Returns
this
remove()
remove(
start,end):this
Parameters
start
number
end
number
Returns
this
replace()
replace(
from,to):this
Parameters
from
string
to
string
Returns
this
replaceAll()
replaceAll(
from,to):this
Parameters
from
string
to
string
Returns
this
slice()
slice(
start?,end?):string
Returns the content between the specified original character positions. Supports negative indices (counting from the end).
Parameters
start?
number | null
end?
number | null
Returns
string
snip()
snip(
start,end):BindingMagicString
Returns a clone with content outside the specified range removed.
Parameters
start
number
end
number
Returns
BindingMagicString
toString()
toString():
string
Returns
string
trim()
trim(
charType?):this
Trims whitespace or specified characters from the start and end.
Parameters
charType?
string | null
Returns
this
trimEnd()
trimEnd(
charType?):this
Trims whitespace or specified characters from the end.
Parameters
charType?
string | null
Returns
this
trimLines()
trimLines():
this
Trims newlines from the start and end.
Returns
this
trimStart()
trimStart(
charType?):this
Trims whitespace or specified characters from the start.
Parameters
charType?
string | null
Returns
this
update()
update(
start,end,content):this
Parameters
start
number
end
number
content
string
Returns
this