Socket
Socket
Sign inDemoInstall

magic-string

Package Overview
Dependencies
1
Maintainers
1
Versions
114
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.1 to 0.1.3

8

CHANGELOG.md
# changelog
## 0.1.3
* `s.trim()` returns `this` (i.e. is chainable)
## 0.1.2
* Implement `s.slice()`
## 0.1.1

@@ -4,0 +12,0 @@

17

lib/index.js

@@ -136,3 +136,3 @@ var guessIndent = require( './guessIndent' ),

d = content.length - ( end - start );
d = content.length - ( lastChar + 1 - firstChar );

@@ -144,2 +144,15 @@ blank( this.mappings, start, end );

slice: function ( start, end ) {
var firstChar, lastChar;
firstChar = this.locate( start );
lastChar = this.locate( end );
if ( firstChar === null || lastChar === null ) {
throw new Error( 'Cannot use replaced characters as slice anchors' );
}
return this.str.slice( firstChar, lastChar );
},
toString: function () {

@@ -193,2 +206,4 @@ return this.str;

});
return this;
}

@@ -195,0 +210,0 @@ };

2

package.json
{
"name": "magic-string",
"author": "Rich Harris",
"version": "0.1.1",
"version": "0.1.3",
"main": "index.js",

@@ -6,0 +6,0 @@ "license": "MIT",

@@ -87,2 +87,6 @@ # magic-string

### s.slice( start, end )
Returns the content of the generated string that corresponds to the slice between `start` and `end` of the original string. Throws error if the indices are for characters that were already removed.
### s.toString()

@@ -89,0 +93,0 @@

@@ -222,3 +222,3 @@ var assert = require( 'assert' ),

it.only( 'should correctly locate characters in trimmed appended/prepended content', function () {
it( 'should correctly locate characters in trimmed appended/prepended content', function () {
var s = new MagicString( ' abcdefghijkl ' );

@@ -309,2 +309,18 @@

describe( 'MagicString$slice', function () {
it( 'should return the generated content between the specified original characters', function () {
var s = new MagicString( 'abcdefghijkl' );
assert.equal( s.slice( 3, 9 ), 'defghi' );
s.replace( 4, 8, 'XX' );
assert.equal( s.slice( 3, 9 ), 'dXXi' );
s.replace( 2, 10, 'ZZ' );
assert.equal( s.slice( 1, 11 ), 'bZZk' );
assert.throws( function () {
s.slice( 2, 10 );
});
});
});
describe( 'MagicString$trim', function () {

@@ -331,2 +347,7 @@ it( 'should trim original content', function () {

});
it( 'should return this', function () {
var s = new MagicString( ' abcdefghijkl ' );
assert.strictEqual( s.trim(), s );
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc