magic-string
Advanced tools
Comparing version 0.26.5 to 0.26.6
@@ -678,2 +678,8 @@ 'use strict'; | ||
overwrite(start, end, content, options) { | ||
options = options || {}; | ||
options.overwrite = !options.contentOnly; | ||
return this.update(start, end, content, options); | ||
} | ||
update(start, end, content, options) { | ||
if (typeof content !== 'string') throw new TypeError('replacement content must be a string'); | ||
@@ -704,3 +710,3 @@ | ||
const storeName = options !== undefined ? options.storeName : false; | ||
const contentOnly = options !== undefined ? options.contentOnly : false; | ||
const overwrite = options !== undefined ? options.overwrite : false; | ||
@@ -729,3 +735,3 @@ if (storeName) { | ||
first.edit(content, storeName, contentOnly); | ||
first.edit(content, storeName, !overwrite); | ||
} else { | ||
@@ -732,0 +738,0 @@ // must be inserting at the end |
@@ -732,2 +732,8 @@ (function (global, factory) { | ||
overwrite(start, end, content, options) { | ||
options = options || {}; | ||
options.overwrite = !options.contentOnly; | ||
return this.update(start, end, content, options); | ||
} | ||
update(start, end, content, options) { | ||
if (typeof content !== 'string') throw new TypeError('replacement content must be a string'); | ||
@@ -758,3 +764,3 @@ | ||
const storeName = options !== undefined ? options.storeName : false; | ||
const contentOnly = options !== undefined ? options.contentOnly : false; | ||
const overwrite = options !== undefined ? options.overwrite : false; | ||
@@ -783,3 +789,3 @@ if (storeName) { | ||
first.edit(content, storeName, contentOnly); | ||
first.edit(content, storeName, !overwrite); | ||
} else { | ||
@@ -786,0 +792,0 @@ // must be inserting at the end |
@@ -101,2 +101,7 @@ export interface BundleOptions { | ||
export interface UpdateOptions { | ||
storeName?: boolean; | ||
overwrite?: boolean; | ||
} | ||
export default class MagicString { | ||
@@ -159,3 +164,4 @@ constructor(str: string, options?: MagicStringOptions); | ||
/** | ||
* Replaces the characters from `start` to `end` with `content`. The same restrictions as `s.remove()` apply. | ||
* 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. | ||
* | ||
@@ -165,5 +171,15 @@ * The fourth argument is optional. It can have a storeName property — if true, the original name will be stored | ||
* the content is overwritten, or anything that was appended/prepended to the range as well. | ||
* | ||
* It may be preferred to use `s.update(...)` instead if you wish to avoid overwriting the appended/prepended content. | ||
*/ | ||
overwrite(start: number, end: number, content: string, options?: boolean | OverwriteOptions): MagicString; | ||
/** | ||
* Replaces the characters from `start` to `end` with `content`. The same restrictions as `s.remove()` apply. | ||
* | ||
* 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 determines whether only | ||
* the content is overwritten, or anything that was appended/prepended to the range as well. | ||
*/ | ||
update(start: number, end: number, content: string, options?: boolean | UpdateOptions): MagicString; | ||
/** | ||
* Prepends the string with the specified content. | ||
@@ -170,0 +186,0 @@ */ |
{ | ||
"name": "magic-string", | ||
"version": "0.26.5", | ||
"version": "0.26.6", | ||
"description": "Modify strings, generate sourcemaps", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -46,6 +46,6 @@ # magic-string | ||
s.overwrite(0, 8, 'answer'); | ||
s.update(0, 8, 'answer'); | ||
s.toString(); // 'answer = 99' | ||
s.overwrite(11, 13, '42'); // character indices always refer to the original string | ||
s.update(11, 13, '42'); // character indices always refer to the original string | ||
s.toString(); // 'answer = 42' | ||
@@ -139,2 +139,6 @@ | ||
### s.isEmpty() | ||
Returns true if the resulting source is empty (disregarding white space). | ||
### s.locate( index ) | ||
@@ -154,6 +158,8 @@ | ||
Replaces the characters from `start` to `end` with `content`. The same restrictions as `s.remove()` apply. Returns `this`. | ||
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`. | ||
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. | ||
It may be preferred to use `s.update(...)` instead if you wish to avoid overwriting the appended/prepended content. | ||
### s.prepend( content ) | ||
@@ -226,6 +232,10 @@ | ||
### s.isEmpty() | ||
### s.update( start, end, content[, options] ) | ||
Returns true if the resulting source is empty (disregarding white space). | ||
Replaces the characters from `start` to `end` with `content`. The same restrictions as `s.remove()` apply. Returns `this`. | ||
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. | ||
`s.update(start, end, content)` is equivalent to `s.overwrite(start, end, content, { contentOnly: true })`. | ||
## Bundling | ||
@@ -232,0 +242,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
400813
3688
290