Comparing version 0.3.0 to 0.4.0
{ | ||
"name": "regjsgen", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "Generate regular expressions from regjsparser’s AST.", | ||
"homepage": "https://github.com/demoneaux/regjsgen", | ||
"homepage": "https://github.com/bnjmnt4n/regjsgen", | ||
"main": "regjsgen.js", | ||
@@ -17,9 +17,9 @@ "keywords": [ | ||
"name": "Benjamin Tan", | ||
"url": "https://demoneaux.github.io/" | ||
"url": "https://bnjmnt4n.now.sh/" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/demoneaux/regjsgen.git" | ||
"url": "https://github.com/bnjmnt4n/regjsgen.git" | ||
}, | ||
"bugs": "https://github.com/demoneaux/regjsgen/issues", | ||
"bugs": "https://github.com/bnjmnt4n/regjsgen/issues", | ||
"files": [ | ||
@@ -35,7 +35,7 @@ "LICENSE", | ||
"devDependencies": { | ||
"coveralls": "^2.11.8", | ||
"istanbul": "~0.4.2", | ||
"regjsparser": "~0.2.0", | ||
"request": "^2.69.0" | ||
"codecov": "^3.0.0", | ||
"istanbul": "~0.4.5", | ||
"regjsparser": "~0.3.0", | ||
"request": "^2.83.0" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# regjsgen [![Build status](https://travis-ci.org/demoneaux/regjsgen.svg?branch=master)](https://travis-ci.org/demoneaux/regjsgen) [![Code coverage status](https://coveralls.io/repos/github/demoneaux/regjsgen/badge.svg)](https://coveralls.io/github/demoneaux/regjsgen?branch=master) | ||
# regjsgen [![Build status](https://travis-ci.org/bnjmnt4n/regjsgen.svg?branch=master)](https://travis-ci.org/bnjmnt4n/regjsgen) [![Code coverage status](https://codecov.io/gh/bnjmnt4n/regjsgen/branch/master/graph/badge.svg)](https://codecov.io/gh/bnjmnt4n/regjsgen) | ||
@@ -33,14 +33,2 @@ Generate regular expressions from [regjsparser](https://github.com/jviereck/regjsparser)’s AST. | ||
Tested in Node.js 0.10.x, 0.12.x, 4.x and 5.x. | ||
## Author | ||
| [![twitter/demoneaux](https://gravatar.com/avatar/029b19dba521584d83398ada3ecf6131?s=70)](https://twitter.com/demoneaux "Follow @demoneaux on Twitter") | | ||
|---| | ||
| [Benjamin Tan](https://demoneaux.github.io/) | | ||
## Contributors | ||
| [![twitter/mathias](https://gravatar.com/avatar/24e08a9ea84deb17ae121074d0f17125?s=70)](https://twitter.com/mathias "Follow @mathias on Twitter") | | ||
|---| | ||
| [Mathias Bynens](https://mathiasbynens.be/) | | ||
Tested in Node.js 0.10, 0.12, 4, 6 and 8. |
113
regjsgen.js
/*! | ||
* regjsgen 0.3.0 | ||
* Copyright 2014-2016 Benjamin Tan <https://demoneaux.github.io/> | ||
* Available under MIT license <https://github.com/demoneaux/regjsgen/blob/master/LICENSE> | ||
* regjsgen 0.4.0 | ||
* Copyright 2014-2018 Benjamin Tan <https://bnjmnt4n.now.sh/> | ||
* Available under MIT license <https://github.com/bnjmnt4n/regjsgen/blob/master/LICENSE> | ||
*/ | ||
@@ -19,9 +19,9 @@ ;(function() { | ||
// Detect free variable `exports`. | ||
var freeExports = objectTypes[typeof exports] && exports; | ||
var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports; | ||
// Detect free variable `module`. | ||
var freeModule = objectTypes[typeof module] && module && !module.nodeType && module; | ||
var hasFreeModule = objectTypes[typeof module] && module && !module.nodeType; | ||
// Detect free variable `global` from Node.js or Browserified code and use it as `root`. | ||
var freeGlobal = freeExports && freeModule && typeof global == 'object' && global; | ||
var freeGlobal = freeExports && hasFreeModule && typeof global == 'object' && global; | ||
if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal || freeGlobal.self === freeGlobal)) { | ||
@@ -36,44 +36,27 @@ root = freeGlobal; | ||
// Generates strings based on the given code points. | ||
// Based on https://mths.be/fromcodepoint v0.2.0 by @mathias. | ||
var stringFromCharCode = String.fromCharCode; | ||
var floor = Math.floor; | ||
// Generates a string based on the given code point. | ||
// Based on https://mths.be/fromcodepoint by @mathias. | ||
function fromCodePoint() { | ||
var MAX_SIZE = 0x4000; | ||
var codeUnits = []; | ||
var highSurrogate; | ||
var lowSurrogate; | ||
var index = -1; | ||
var length = arguments.length; | ||
if (!length) { | ||
return ''; | ||
var codePoint = Number(arguments[0]); | ||
if ( | ||
!isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity` | ||
codePoint < 0 || // not a valid Unicode code point | ||
codePoint > 0x10FFFF || // not a valid Unicode code point | ||
Math.floor(codePoint) != codePoint // not an integer | ||
) { | ||
throw RangeError('Invalid code point: ' + codePoint); | ||
} | ||
var result = ''; | ||
while (++index < length) { | ||
var codePoint = Number(arguments[index]); | ||
if ( | ||
!isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity` | ||
codePoint < 0 || // not a valid Unicode code point | ||
codePoint > 0x10FFFF || // not a valid Unicode code point | ||
floor(codePoint) != codePoint // not an integer | ||
) { | ||
throw RangeError('Invalid code point: ' + codePoint); | ||
} | ||
if (codePoint <= 0xFFFF) { | ||
// BMP code point | ||
codeUnits.push(codePoint); | ||
} else { | ||
// Astral code point; split in surrogate halves | ||
// http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae | ||
codePoint -= 0x10000; | ||
highSurrogate = (codePoint >> 10) + 0xD800; | ||
lowSurrogate = (codePoint % 0x400) + 0xDC00; | ||
codeUnits.push(highSurrogate, lowSurrogate); | ||
} | ||
if (index + 1 == length || codeUnits.length > MAX_SIZE) { | ||
result += stringFromCharCode.apply(null, codeUnits); | ||
codeUnits.length = 0; | ||
} | ||
if (codePoint <= 0xFFFF) { | ||
// BMP code point | ||
return String.fromCharCode(codePoint); | ||
} else { | ||
// Astral code point; split in surrogate halves | ||
// http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae | ||
codePoint -= 0x10000; | ||
var highSurrogate = (codePoint >> 10) + 0xD800; | ||
var lowSurrogate = (codePoint % 0x400) + 0xDC00; | ||
return String.fromCharCode(highSurrogate, lowSurrogate); | ||
} | ||
return result; | ||
} | ||
@@ -239,2 +222,5 @@ | ||
case 'normal': | ||
if (node.name) { | ||
result += '?<' + generateIdentifier(node.name) + '>'; | ||
} | ||
break; | ||
@@ -265,2 +251,8 @@ case 'ignore': | ||
function generateIdentifier(node) { | ||
assertType(node.type, 'identifier'); | ||
return node.value; | ||
} | ||
function generateQuantifier(node) { | ||
@@ -299,3 +291,10 @@ assertType(node.type, 'quantifier'); | ||
return '\\' + node.matchIndex; | ||
if (node.matchIndex) { | ||
return '\\' + node.matchIndex; | ||
} | ||
if (node.name) { | ||
return '\\k<' + generateIdentifier(node.name) + '>'; | ||
} | ||
throw new Error('Unknown reference type'); | ||
} | ||
@@ -315,2 +314,6 @@ | ||
if (typeof codePoint != 'number') { | ||
throw new Error('Invalid code point: ' + codePoint); | ||
} | ||
switch (kind) { | ||
@@ -342,3 +345,3 @@ case 'controlLetter': | ||
default: | ||
throw Error('Invalid codepoint: ' + codePoint); | ||
throw Error('Invalid code point: ' + codePoint); | ||
} | ||
@@ -377,2 +380,6 @@ case 'symbol': | ||
// Export regjsgen. | ||
var regjsgen = { | ||
'generate': generate | ||
}; | ||
// Some AMD build optimizers, like r.js, check for condition patterns like the following: | ||
@@ -382,9 +389,9 @@ if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) { | ||
define(function() { | ||
return { | ||
'generate': generate | ||
}; | ||
return regjsgen; | ||
}); | ||
root.regjsgen = regjsgen; | ||
} | ||
// Check for `exports` after `define` in case a build optimizer adds an `exports` object. | ||
else if (freeExports && freeModule) { | ||
else if (freeExports && hasFreeModule) { | ||
// Export for CommonJS support. | ||
@@ -395,6 +402,4 @@ freeExports.generate = generate; | ||
// Export to the global object. | ||
root.regjsgen = { | ||
'generate': generate | ||
}; | ||
root.regjsgen = regjsgen; | ||
} | ||
}.call(this)); |
Sorry, the diff of this file is not supported yet
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
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
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
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
13492
317
34