magic-string
Advanced tools
Comparing version 0.30.8 to 0.30.9
@@ -1174,17 +1174,25 @@ 'use strict'; | ||
matches.forEach((match) => { | ||
if (match.index != null) | ||
if (match.index != null) { | ||
const replacement = getReplacement(match, this.original); | ||
if (replacement !== match[0]) { | ||
this.overwrite( | ||
match.index, | ||
match.index + match[0].length, | ||
replacement | ||
); | ||
} | ||
} | ||
}); | ||
} else { | ||
const match = this.original.match(searchValue); | ||
if (match && match.index != null) { | ||
const replacement = getReplacement(match, this.original); | ||
if (replacement !== match[0]) { | ||
this.overwrite( | ||
match.index, | ||
match.index + match[0].length, | ||
getReplacement(match, this.original), | ||
replacement | ||
); | ||
}); | ||
} else { | ||
const match = this.original.match(searchValue); | ||
if (match && match.index != null) | ||
this.overwrite( | ||
match.index, | ||
match.index + match[0].length, | ||
getReplacement(match, this.original), | ||
); | ||
} | ||
} | ||
} | ||
@@ -1221,3 +1229,5 @@ return this; | ||
) { | ||
this.overwrite(index, index + stringLength, replacement); | ||
const previous = original.slice(index, index + stringLength); | ||
if (previous !== replacement) | ||
this.overwrite(index, index + stringLength, replacement); | ||
} | ||
@@ -1224,0 +1234,0 @@ |
@@ -1264,17 +1264,25 @@ (function (global, factory) { | ||
matches.forEach((match) => { | ||
if (match.index != null) | ||
if (match.index != null) { | ||
const replacement = getReplacement(match, this.original); | ||
if (replacement !== match[0]) { | ||
this.overwrite( | ||
match.index, | ||
match.index + match[0].length, | ||
replacement | ||
); | ||
} | ||
} | ||
}); | ||
} else { | ||
const match = this.original.match(searchValue); | ||
if (match && match.index != null) { | ||
const replacement = getReplacement(match, this.original); | ||
if (replacement !== match[0]) { | ||
this.overwrite( | ||
match.index, | ||
match.index + match[0].length, | ||
getReplacement(match, this.original), | ||
replacement | ||
); | ||
}); | ||
} else { | ||
const match = this.original.match(searchValue); | ||
if (match && match.index != null) | ||
this.overwrite( | ||
match.index, | ||
match.index + match[0].length, | ||
getReplacement(match, this.original), | ||
); | ||
} | ||
} | ||
} | ||
@@ -1311,3 +1319,5 @@ return this; | ||
) { | ||
this.overwrite(index, index + stringLength, replacement); | ||
const previous = original.slice(index, index + stringLength); | ||
if (previous !== replacement) | ||
this.overwrite(index, index + stringLength, replacement); | ||
} | ||
@@ -1314,0 +1324,0 @@ |
{ | ||
"name": "magic-string", | ||
"version": "0.30.8", | ||
"version": "0.30.9", | ||
"description": "Modify strings, generate sourcemaps", | ||
@@ -32,6 +32,7 @@ "keywords": [ | ||
"scripts": { | ||
"build": "rollup -c && cp ./src/index.d.ts ./dist/magic-string.es.d.mts && cp ./src/index.d.ts ./dist/magic-string.cjs.d.ts", | ||
"build": "rollup -c", | ||
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s", | ||
"format": "prettier --single-quote --print-width 100 --use-tabs --write src/*.js src/**/*.js", | ||
"lint": "eslint src test && publint", | ||
"lint:fix": "eslint src test --fix", | ||
"prepare": "npm run build", | ||
@@ -38,0 +39,0 @@ "prepublishOnly": "npm run lint && rm -rf dist && npm test", |
@@ -196,3 +196,3 @@ # magic-string | ||
Same as `s.replace`, but replace all matched strings instead of just one. | ||
If `substitution` is a regex, then it must have the global (`g`) flag set, or a `TypeError` is thrown. Matches the behavior of the bultin [`String.property.replaceAll`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll). | ||
If `substitution` is a regex, then it must have the global (`g`) flag set, or a `TypeError` is thrown. Matches the behavior of the builtin [`String.property.replaceAll`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll). | ||
@@ -199,0 +199,0 @@ ### s.remove( start, end ) |
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
452267
4042