Skip to content

Class: BindingMagicString

Defined in: binding.d.cts:1442

Constructors

Constructor

  • Type: (source: string, options?: BindingMagicStringOptions | null) => BindingMagicString
Defined in: binding.d.cts:1443

Parameters

source

string

options?

BindingMagicStringOptions | null

Returns

BindingMagicString

Accessors

filename

Get Signature

  • Type: () => string | null
Defined in: binding.d.cts:1444
Returns

string | null

Methods

append()

  • Type: (content: string) => this
Defined in: binding.d.cts:1448

Parameters

content

string

Returns

this


appendLeft()

  • Type: (index: number, content: string) => this
Defined in: binding.d.cts:1451

Parameters

index

number

content

string

Returns

this


appendRight()

  • Type: (index: number, content: string) => this
Defined in: binding.d.cts:1452

Parameters

index

number

content

string

Returns

this


clone()

  • Type: () => BindingMagicString
Defined in: binding.d.cts:1482

Returns a clone of the MagicString instance.

Returns

BindingMagicString


generateDecodedMap()

  • Type: (options?: BindingSourceMapOptions | null) => BindingDecodedMap
Defined in: binding.d.cts:1509

Generates a decoded source map for the transformations applied to this MagicString. Returns a BindingDecodedMap object with mappings as an array of arrays.

Parameters

options?

BindingSourceMapOptions | null

Returns

BindingDecodedMap


generateMap()

  • Type: (options?: BindingSourceMapOptions | null) => BindingSourceMap
Defined in: binding.d.cts:1504

Generates a source map for the transformations applied to this MagicString. Returns a BindingSourceMap object with version, file, sources, sourcesContent, names, mappings.

Parameters

options?

BindingSourceMapOptions | null

Returns

BindingSourceMap


hasChanged()

  • Type: () => boolean
Defined in: binding.d.cts:1455

Returns

boolean


indent()

  • Type: (indentor?: string | null) => this
Defined in: binding.d.cts:1467

Parameters

indentor?

string | null

Returns

this


insert()

  • Type: (index: number, content: string) => void
Defined in: binding.d.cts:1480

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()

  • Type: () => boolean
Defined in: binding.d.cts:1457

Returns

boolean


lastChar()

  • Type: () => string
Defined in: binding.d.cts:1484

Returns the last character of the generated string, or an empty string if empty.

Returns

string


lastLine()

  • Type: () => string
Defined in: binding.d.cts:1486

Returns the content after the last newline in the generated string.

Returns

string


length()

  • Type: () => number
Defined in: binding.d.cts:1456

Returns

number


move()

  • Type: (start: number, end: number, index: number) => this
Defined in: binding.d.cts:1466

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()

  • Type: (start: number, end: number, content: string) => this
Defined in: binding.d.cts:1453

Parameters

start

number

end

number

content

string

Returns

this


prepend()

  • Type: (content: string) => this
Defined in: binding.d.cts:1447

Parameters

content

string

Returns

this


prependLeft()

  • Type: (index: number, content: string) => this
Defined in: binding.d.cts:1449

Parameters

index

number

content

string

Returns

this


prependRight()

  • Type: (index: number, content: string) => this
Defined in: binding.d.cts:1450

Parameters

index

number

content

string

Returns

this


relocate()

  • Type: (start: number, end: number, to: number) => this
Defined in: binding.d.cts:1460

Parameters

start

number

end

number

to

number

Returns

this


remove()

  • Type: (start: number, end: number) => this
Defined in: binding.d.cts:1458

Parameters

start

number

end

number

Returns

this


replace()

  • Type: (from: string, to: string) => this
Defined in: binding.d.cts:1445

Parameters

from

string

to

string

Returns

this


replaceAll()

  • Type: (from: string, to: string) => this
Defined in: binding.d.cts:1446

Parameters

from

string

to

string

Returns

this


reset()

  • Type: (start: number, end: number) => this
Defined in: binding.d.cts:1494

Resets the portion of the string from start to end to its original content. This undoes any modifications made to that range. Supports negative indices (counting from the end).

Parameters

start

number

end

number

Returns

this


slice()

  • Type: (start?: number | null, end?: number | null) => string
Defined in: binding.d.cts:1499

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()

  • Type: (start: number, end: number) => BindingMagicString
Defined in: binding.d.cts:1488

Returns a clone with content outside the specified range removed.

Parameters

start

number

end

number

Returns

BindingMagicString


toString()

  • Type: () => string
Defined in: binding.d.cts:1454

Returns

string


trim()

  • Type: (charType?: string | null) => this
Defined in: binding.d.cts:1469

Trims whitespace or specified characters from the start and end.

Parameters

charType?

string | null

Returns

this


trimEnd()

  • Type: (charType?: string | null) => this
Defined in: binding.d.cts:1473

Trims whitespace or specified characters from the end.

Parameters

charType?

string | null

Returns

this


trimLines()

  • Type: () => this
Defined in: binding.d.cts:1475

Trims newlines from the start and end.

Returns

this


trimStart()

  • Type: (charType?: string | null) => this
Defined in: binding.d.cts:1471

Trims whitespace or specified characters from the start.

Parameters

charType?

string | null

Returns

this


update()

  • Type: (start: number, end: number, content: string) => this
Defined in: binding.d.cts:1459

Parameters

start

number

end

number

content

string

Returns

this