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

regjsgen

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

regjsgen - npm Package Compare versions

Comparing version 0.5.1 to 0.5.2

LICENSE-MIT.txt

15

package.json
{
"name": "regjsgen",
"version": "0.5.1",
"version": "0.5.2",
"description": "Generate regular expressions from regjsparser’s AST.",

@@ -17,3 +17,3 @@ "homepage": "https://github.com/bnjmnt4n/regjsgen",

"name": "Benjamin Tan",
"url": "https://bnjmnt4n.now.sh/"
"url": "https://ofcr.se/"
},

@@ -26,3 +26,3 @@ "repository": {

"files": [
"LICENSE",
"LICENSE-MIT.txt",
"regjsgen.js"

@@ -33,10 +33,11 @@ ],

"coverage": "nyc --reporter=html npm test",
"report-coverage": "nyc --reporter=lcov npm test && codecov",
"update-fixtures": "node tests/update-fixtures.js"
},
"devDependencies": {
"codecov": "^3.6.1",
"nyc": "^14.1.1",
"regjsparser": "~0.6.0",
"request": "^2.88.0"
"codecov": "^3.7.0",
"nyc": "^15.0.1",
"regjsparser": "~0.6.4",
"request": "^2.88.2"
}
}

@@ -7,3 +7,3 @@ # regjsgen [![Build status][travis-ci-img]][travis-ci] [![Code coverage status][codecov-img]][codecov]

```bash
```sh
npm i regjsgen

@@ -19,7 +19,7 @@ ```

```js
var regjsparser = require('regjsparser');
var regjsgen = require('regjsgen');
const regjsparser = require('regjsparser');
const regjsgen = require('regjsgen');
// Generate an AST with `regjsparser`.
var ast = regjsparser.parse(regex);
let ast = regjsparser.parse(regex);

@@ -30,3 +30,3 @@ // Modify AST

// Generate `RegExp` string with `regjsgen`.
regex = regjsgen.generate(ast);
let regex = regjsgen.generate(ast);
```

@@ -36,3 +36,4 @@

Tested in Node.js 0.10, 0.12, 4, 6, 8, 10 and 12.
Tested in Node.js 0.10, 0.12, 4, 6, 8, 10, 12 and 14.<br>
Compatible with regjsparser v0.6.4’s AST.

@@ -39,0 +40,0 @@

/*!
* regjsgen 0.5.1
* Copyright 2014-2019 Benjamin Tan <https://bnjmnt4n.now.sh/>
* Available under MIT license <https://github.com/bnjmnt4n/regjsgen/blob/master/LICENSE>
* regjsgen 0.5.2
* Copyright 2014-2020 Benjamin Tan <https://ofcr.se/>
* Available under the MIT license <https://github.com/bnjmnt4n/regjsgen/blob/master/LICENSE-MIT.txt>
*/

@@ -99,14 +99,28 @@ ;(function() {

/*--------------------------------------------------------------------------*/
// Constructs a string by concatentating the output of each term.
function generateSequence(generator, terms) {
var i = -1,
length = terms.length,
result = '',
term;
function generateAlternative(node) {
assertType(node.type, 'alternative');
while (++i < length) {
term = terms[i];
var terms = node.body,
i = -1,
length = terms.length,
result = '';
// Ensure that `\0` null escapes followed by number symbols are not
// treated as backreferences.
if (
i + 1 < length &&
terms[i].type == 'value' &&
terms[i].kind == 'null' &&
terms[i + 1].type == 'value' &&
terms[i + 1].kind == 'symbol' &&
terms[i + 1].codePoint >= 48 &&
terms[i + 1].codePoint <= 57
) {
result += '\\000';
continue;
}
while (++i < length) {
result += generateTerm(terms[i]);
result += generator(term);
}

@@ -117,2 +131,10 @@

/*--------------------------------------------------------------------------*/
function generateAlternative(node) {
assertType(node.type, 'alternative');
return generateSequence(generateTerm, node.body);
}
function generateAnchor(node) {

@@ -144,16 +166,6 @@ assertType(node.type, 'anchor');

var classRanges = node.body,
i = -1,
length = classRanges.length,
result = '';
if (node.negative) {
result += '^';
}
while (++i < length) {
result += generateClassAtom(classRanges[i]);
}
return '[' + result + ']';
return '[' +
(node.negative ? '^' : '') +
generateSequence(generateClassAtom, node.body) +
']';
}

@@ -167,8 +179,2 @@

function generateUnicodePropertyEscape(node) {
assertType(node.type, 'unicodePropertyEscape');
return '\\' + (node.negative ? 'P' : 'p') + '{' + node.value + '}';
}
function generateCharacterClassRange(node) {

@@ -247,10 +253,4 @@ assertType(node.type, 'characterClassRange');

var body = node.body,
i = -1,
length = body.length;
result += generateSequence(generate, node.body);
while (++i < length) {
result += generate(body[i]);
}
return '(' + result + ')';

@@ -314,2 +314,8 @@ }

function generateUnicodePropertyEscape(node) {
assertType(node.type, 'unicodePropertyEscape');
return '\\' + (node.negative ? 'P' : 'p') + '{' + node.value + '}';
}
function generateValue(node) {

@@ -335,3 +341,3 @@ assertType(node.type, 'value');

case 'octal':
return '\\' + codePoint.toString(8);
return '\\' + ('000' + codePoint.toString(8)).slice(-3);
case 'singleEscape':

@@ -351,2 +357,4 @@ switch (codePoint) {

return '\\r';
case 0x002D:
return '\\-';
default:

@@ -375,3 +383,2 @@ throw Error('Invalid code point: ' + codePoint);

'characterClassRange': generateCharacterClassRange,
'unicodePropertyEscape': generateUnicodePropertyEscape,
'disjunction': generateDisjunction,

@@ -382,2 +389,3 @@ 'dot': generateDot,

'reference': generateReference,
'unicodePropertyEscape': generateUnicodePropertyEscape,
'value': generateValue

@@ -384,0 +392,0 @@ };

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