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
+45-41Lines changed: 45 additions & 41 deletions
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,7 @@ npm i magic-string
28
28
To use in browser, grab the [magic-string.umd.js](https://unpkg.com/magic-string/dist/magic-string.umd.js) file and add it to your page:
29
29
30
30
```html
31
-
<scriptsrc='magic-string.umd.js'></script>
31
+
<scriptsrc="magic-string.umd.js"></script>
32
32
```
33
33
34
34
(It also works with various module systems, if you prefer that sort of thing - it has a dependency on [vlq](https://github.com/Rich-Harris/vlq).)
@@ -39,7 +39,7 @@ These examples assume you're in node.js, or something similar:
39
39
40
40
```js
41
41
importMagicStringfrom'magic-string';
42
-
importfsfrom'fs'
42
+
importfsfrom'fs';
43
43
44
44
consts=newMagicString('problems = 99');
45
45
@@ -53,9 +53,9 @@ s.prepend('var ').append(';'); // most methods are chainable
53
53
s.toString(); // 'var answer = 42;'
54
54
55
55
constmap=s.generateMap({
56
-
source:'source.js',
57
-
file:'converted.js.map',
58
-
includeContent:true
56
+
source:'source.js',
57
+
file:'converted.js.map',
58
+
includeContent:true,
59
59
}); // generates a v3 sourcemap
60
60
61
61
fs.writeFileSync('converted.js', s.toString());
@@ -66,11 +66,13 @@ You can pass an options argument:
66
66
67
67
```js
68
68
consts=newMagicString(someCode, {
69
-
// these options will be used if you later call `bundle.addSource( s )` - see below
70
-
filename:'foo.js',
71
-
indentExclusionRanges: [/*...*/],
72
-
// mark source as ignore in DevTools, see below #Bundling
73
-
ignoreList:false
69
+
// these options will be used if you later call `bundle.addSource( s )` - see below
70
+
filename:'foo.js',
71
+
indentExclusionRanges: [
72
+
/*...*/
73
+
],
74
+
// mark source as ignore in DevTools, see below #Bundling
75
+
ignoreList:false,
74
76
});
75
77
```
76
78
@@ -86,11 +88,11 @@ Appends the specified content to the end of the string. Returns `this`.
86
88
87
89
### s.appendLeft( index, content )
88
90
89
-
Appends the specified `content` at the `index` in the original string. If a range *ending* with `index` is subsequently moved, the insert will be moved with it. Returns `this`. See also `s.prependLeft(...)`.
91
+
Appends the specified `content` at the `index` in the original string. If a range _ending_ with `index` is subsequently moved, the insert will be moved with it. Returns `this`. See also `s.prependLeft(...)`.
90
92
91
93
### s.appendRight( index, content )
92
94
93
-
Appends the specified `content` at the `index` in the original string. If a range *starting* with `index` is subsequently moved, the insert will be moved with it. Returns `this`. See also `s.prependRight(...)`.
95
+
Appends the specified `content` at the `index` in the original string. If a range _starting_ with `index` is subsequently moved, the insert will be moved with it. Returns `this`. See also `s.prependRight(...)`.
94
96
95
97
### s.clone()
96
98
@@ -104,15 +106,15 @@ Generates a sourcemap object with raw mappings in array form, rather than encode
104
106
105
107
Generates a [version 3 sourcemap](https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit). All options are, well, optional:
106
108
107
-
*`file` - the filename where you plan to write the sourcemap
108
-
*`source` - the filename of the file containing the original source
109
-
*`includeContent` - whether to include the original content in the map's `sourcesContent` array
110
-
*`hires` - whether the mapping should be high-resolution. Hi-res mappings map every single character, meaning (for example) your devtools will always be able to pinpoint the exact location of function calls and so on. With lo-res mappings, devtools may only be able to identify the correct line - but they're quicker to generate and less bulky. You can also set `"boundary"` to generate a semi-hi-res mappings segmented per word boundary instead of per character, suitable for string semantics that are separated by words. If sourcemap locations have been specified with `s.addSourcemapLocation()`, they will be used here.
109
+
-`file` - the filename where you plan to write the sourcemap
110
+
-`source` - the filename of the file containing the original source
111
+
-`includeContent` - whether to include the original content in the map's `sourcesContent` array
112
+
-`hires` - whether the mapping should be high-resolution. Hi-res mappings map every single character, meaning (for example) your devtools will always be able to pinpoint the exact location of function calls and so on. With lo-res mappings, devtools may only be able to identify the correct line - but they're quicker to generate and less bulky. You can also set `"boundary"` to generate a semi-hi-res mappings segmented per word boundary instead of per character, suitable for string semantics that are separated by words. If sourcemap locations have been specified with `s.addSourcemapLocation()`, they will be used here.
111
113
112
114
The returned sourcemap has two (non-enumerable) methods attached for convenience:
113
115
114
-
*`toString` - returns the equivalent of `JSON.stringify(map)`
115
-
*`toUrl` - returns a DataURI containing the sourcemap. Useful for doing this sort of thing:
116
+
-`toString` - returns the equivalent of `JSON.stringify(map)`
117
+
-`toUrl` - returns a DataURI containing the sourcemap. Useful for doing this sort of thing:
116
118
117
119
```js
118
120
code +='\n//# sourceMappingURL='+map.toUrl();
@@ -166,27 +168,28 @@ Prepends the string with the specified content. Returns `this`.
166
168
167
169
### s.prependLeft ( index, content )
168
170
169
-
Same as `s.appendLeft(...)`, except that the inserted content will go *before* any previous appends or prepends at `index`
171
+
Same as `s.appendLeft(...)`, except that the inserted content will go _before_ any previous appends or prepends at `index`
170
172
171
173
### s.prependRight ( index, content )
172
174
173
-
Same as `s.appendRight(...)`, except that the inserted content will go *before* any previous appends or prepends at `index`
175
+
Same as `s.appendRight(...)`, except that the inserted content will go _before_ any previous appends or prepends at `index`
174
176
175
177
### s.replace( regexpOrString, substitution )
176
178
177
179
String replacement with RegExp or string. When using a RegExp, replacer function is also supported. Returns `this`.
0 commit comments