magic-string
Advanced tools
Comparing version 0.3.0 to 0.3.1
@@ -575,3 +575,10 @@ (function (global, factory) { | ||
} else { | ||
this.replace( index, index, content ); | ||
var mapped = this.locate(index); | ||
if ( mapped === null ) { | ||
throw new Error( 'Cannot insert at replaced character index: ' + index ); | ||
} | ||
this.str = this.str.substr( 0, mapped ) + content + this.str.substr( mapped ); | ||
adjust( this.mappings, index, this.mappings.length, content.length ); | ||
} | ||
@@ -632,2 +639,9 @@ | ||
if ( firstChar > lastChar + 1 ) { | ||
throw new Error( | ||
'BUG! First character mapped to a position after the last character: ' + | ||
'[' + start + ', ' + end + '] -> [' + firstChar + ', ' + ( lastChar + 1 ) + ']' | ||
); | ||
} | ||
this.str = this.str.substr( 0, firstChar ) + content + this.str.substring( lastChar + 1 ); | ||
@@ -634,0 +648,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"author": "Rich Harris", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"repository": "https://github.com/rich-harris/magic-string", | ||
@@ -8,0 +8,0 @@ "main": "magic-string.js", |
@@ -9,3 +9,3 @@ # magic-string | ||
Currently, magic-string only works in node.js (this will likely change in future): | ||
magic-string works in both node.js and browser environments. For node, install with npm: | ||
@@ -16,4 +16,15 @@ ```bash | ||
To use in browser, you'll need to make [vlq](https://github.com/Rich-Harris/vlq) available. Add it, along with [magic-string.js](https://raw.githubusercontent.com/Rich-Harris/magic-string/master/magic-string.js), to your page: | ||
```html | ||
<script src='vlq.js'></script> | ||
<script src='magic-string.js'></script> | ||
``` | ||
(Both libraries also work with various module systems, if you prefer that sort of thing.) | ||
## Usage | ||
These examples assume you're in node.js, or something similar: | ||
```js | ||
@@ -169,2 +180,2 @@ var MagicString = require( 'magic-string' ); | ||
MIT | ||
MIT |
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
25030
606
179