Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tippex

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tippex - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

CHANGELOG.md

29

dist/tippex.es6.js

@@ -188,3 +188,30 @@ function find(str) {

export { find, erase };
function match(str, pattern, callback) {
if (!pattern.global) throw new Error('regular expression must have the g (global) flag');
var found = find(str);
var match = undefined;
var chunkIndex = 0;
while (match = pattern.exec(str)) {
var chunk = undefined;
do {
chunk = found[chunkIndex];
if (chunk && chunk.end < match.index) {
chunkIndex += 1;
} else {
break;
}
} while (chunk);
if (!chunk || chunk.start > match.index) {
callback.apply(null, match);
}
}
}
export { find, erase, match };
//# sourceMappingURL=tippex.es6.js.map

@@ -194,6 +194,34 @@ (function (global, factory) {

function match(str, pattern, callback) {
if (!pattern.global) throw new Error('regular expression must have the g (global) flag');
var found = find(str);
var match = undefined;
var chunkIndex = 0;
while (match = pattern.exec(str)) {
var chunk = undefined;
do {
chunk = found[chunkIndex];
if (chunk && chunk.end < match.index) {
chunkIndex += 1;
} else {
break;
}
} while (chunk);
if (!chunk || chunk.start > match.index) {
callback.apply(null, match);
}
}
}
exports.find = find;
exports.erase = erase;
exports.match = match;
}));
//# sourceMappingURL=tippex.umd.js.map

2

package.json
{
"name": "tippex",
"description": "Find and erase strings and comments in JavaScript code",
"version": "1.0.0",
"version": "1.1.0",
"author": "Rich Harris",

@@ -6,0 +6,0 @@ "main": "dist/tippex.umd.js",

@@ -79,3 +79,29 @@ # Tippex

Sometimes you might need to match a regular expression against the original string, but ignoring comments etc. For that you can use `tippex.match`:
```js
var code = `
import a from './a.js';
// import b from './b.js'; TODO do we need this?
`;
var importPattern = /import (.+?) from '([^']+)'/g; // must have 'g' flag
var importDeclarations = [];
tippex.match( code, importPattern, ( match, name, source ) => {
// this callback will be called for each match that *doesn't* begin
// inside a comment, string or regular expression
importDeclarations.push({ name, source });
});
console.log( importDeclarations );
// -> [{
// name: 'a',
// source: './a.js'
// }]
```
(A complete regular expression for ES6 imports would be a bit more complicated; this is for illustrative purposes.)
## License

@@ -82,0 +108,0 @@

@@ -172,1 +172,28 @@ export function find ( str ) {

}
export function match ( str, pattern, callback ) {
if ( !pattern.global ) throw new Error( 'regular expression must have the g (global) flag' );
const found = find( str );
let match;
let chunkIndex = 0;
while ( match = pattern.exec( str ) ) {
let chunk;
do {
chunk = found[ chunkIndex ];
if ( chunk && chunk.end < match.index ) {
chunkIndex += 1;
} else {
break;
}
} while ( chunk );
if ( !chunk || chunk.start > match.index ) {
callback.apply( null, match );
}
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc