You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+15-5
Original file line number
Diff line number
Diff line change
@@ -43,10 +43,10 @@ import fs from 'fs'
43
43
44
44
consts=newMagicString('problems = 99');
45
45
46
-
s.overwrite(0, 8, 'answer');
46
+
s.update(0, 8, 'answer');
47
47
s.toString(); // 'answer = 99'
48
48
49
-
s.overwrite(11, 13, '42'); // character indices always refer to the original string
49
+
s.update(11, 13, '42'); // character indices always refer to the original string
50
50
s.toString(); // 'answer = 42'
51
51
52
52
s.prepend('var ').append(';'); // most methods are chainable
@@ -135,6 +135,10 @@ The `options` argument can have an `exclude` property, which is an array of `[st
135
135
136
136
**DEPRECATED** since 0.17 – use `s.prependRight(...)` instead
137
137
138
+
### s.isEmpty()
139
+
140
+
Returns true if the resulting source is empty (disregarding white space).
141
+
138
142
### s.locate( index )
139
143
140
144
**DEPRECATED** since 0.10 – see [#30](https://github.com/Rich-Harris/magic-string/pull/30)
@@ -149,10 +153,12 @@ Moves the characters from `start` and `end` to `index`. Returns `this`.
149
153
150
154
### s.overwrite( start, end, content[, options] )
151
155
152
-
Replaces the characters from `start` to `end` with `content`. The same restrictions as `s.remove()` apply. Returns `this`.
156
+
Replaces the characters from `start` to `end` with `content`, along with the appended/prepended content in that range. The same restrictions as `s.remove()` apply. Returns `this`.
153
157
154
158
The fourth argument is optional. It can have a `storeName` property — if `true`, the original name will be stored for later inclusion in a sourcemap's `names` array — and a `contentOnly` property which determines whether only the content is overwritten, or anything that was appended/prepended to the range as well.
155
159
160
+
It may be preferred to use `s.update(...)` instead if you wish to avoid overwriting the appended/prepended content.
161
+
156
162
### s.prepend( content )
157
163
158
164
Prepends the string with the specified content. Returns `this`.
@@ -220,9 +226,13 @@ Trims content matching `charType` (defaults to `\s`, i.e. whitespace) from the e
220
226
221
227
Removes empty lines from the start and end. Returns `this`.
222
228
223
-
### s.isEmpty()
229
+
### s.update( start, end, content[, options])
224
230
225
-
Returns true if the resulting source is empty (disregarding white space).
231
+
Replaces the characters from `start` to `end` with `content`. The same restrictions as `s.remove()` apply. Returns `this`.
232
+
233
+
The fourth argument is optional. It can have a `storeName` property — if `true`, the original name will be stored for later inclusion in a sourcemap's `names` array — and an `overwrite` property which defaults to `false` and determines whether anything that was appended/prepended to the range will be overwritten along with the original content.
234
+
235
+
`s.update(start, end, content)` is equivalent to `s.overwrite(start, end, content, { contentOnly: true })`.
0 commit comments