New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

regexp-utils

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

regexp-utils - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

54

index.js

@@ -57,38 +57,30 @@ "use strict";

*
* Creates a matcher from an array of a mix of
* - a regexp
* - a string
* - an array of [regexp or string, value]
* Creates a single regexp matcher function from matcher objects with a
* 'pattern' regexp property.
* {
* pattern: /^fo(o)/
* }
*
* The matcher can then be applied to an input string, and yields either null
* if nothing matched, or a result object like this:
* The returned matcher can then be applied to an input string, and yields
* either null if nothing matched, or a result object like this:
*
* { match: [ 'foo', 'o', index: 0, input: 'foo' ],
* value: 'foo matched!' }
* {
* match: [ 'foo', 'o', index: 0, input: 'foo' ],
* matcher: {} // the original matcher object
* }
*
* The value is the optional value passed in as the second member in the
* array, or undefined.
* */
RU.makeRegExpSwitch = function (regexps) {
RU.makeRegExpSwitch = function (matchers) {
var reBits = [],
matchers = {},
values = {},
matcherOffsetMap = {}, // Map group offset -> matcher
reOffset = 0,
reBit;
regexps.forEach(function(re) {
if (Array.isArray(re)) {
values[reOffset] = re[1];
re = re[0];
matchers.forEach(function(matcher) {
var re = matcher.pattern;
reBit = RU.toSource(re);
if (re.length === undefined) {
re.length = RU.countCapturingGroups(reBit);
}
if (RU.isRegExp(re)) {
reBit = RU.toSource(re);
if (re.length === undefined) {
re.length = RU.countCapturingGroups(reBit);
}
matchers[reOffset] = re;
reOffset += re.length + 1;
} else {
reBit = RU.escapeRegExp(re);
reOffset++;
}
matcherOffsetMap[reOffset] = matcher;
reOffset += re.length + 1;
reBits.push('(' + reBit + ')');

@@ -106,5 +98,5 @@ });

}
if (matchers[i-1]) {
if (matcherOffsetMap[i-1]) {
// extract the capturing group results
var newMatch = match.slice(i, i + matchers[i-1].length + 1);
var newMatch = match.slice(i, i + matcherOffsetMap[i-1].pattern.length + 1);
newMatch.index = match.index;

@@ -120,3 +112,3 @@ newMatch.input = s;

match: match,
value: values[i-1]
matcher: matcherOffsetMap[i-1]
};

@@ -123,0 +115,0 @@ } else {

{
"name": "regexp-utils",
"version": "0.2.0",
"version": "0.3.0",
"description": "RegExp related utilities",

@@ -5,0 +5,0 @@ "main": "index.js",

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