Skip to content

Commit

Permalink
feat: remove xregexp
Browse files Browse the repository at this point in the history
  • Loading branch information
viceice committed Jan 11, 2022
1 parent 2a42100 commit 3bd1fd5
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 475 deletions.
7 changes: 7 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/node_modules
/coverage
/tmp
.DS_Store
.cache
/*.log
.clinic/
7 changes: 3 additions & 4 deletions lib/specifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// 2.0, and the BSD License. See the LICENSE file in the root of this repository
// for complete details.

const XRegExp = require("xregexp");
const { VERSION_PATTERN, explain: explainVersion } = require("./version");

const Operator = require("./operator");
Expand Down Expand Up @@ -30,7 +29,7 @@ module.exports = {

const isEqualityOperator = (op) => ["==", "!=", "==="].includes(op);

const rangeRegex = new XRegExp("^" + RANGE_PATTERN + "$", "i");
const rangeRegex = new RegExp("^" + RANGE_PATTERN + "$", "i");

function parse(ranges) {
if (!ranges.trim()) {
Expand All @@ -39,8 +38,8 @@ function parse(ranges) {

const specifiers = ranges
.split(",")
.map((range) => XRegExp.exec(range.trim(), rangeRegex))
.map((groups) => {
.map((range) => rangeRegex.exec(range.trim()) || {})
.map(({ groups }) => {
if (!groups) {
return null;
}
Expand Down
8 changes: 3 additions & 5 deletions lib/version.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const XRegExp = require("xregexp");

const VERSION_PATTERN = [
"v?",
"(?:",
Expand Down Expand Up @@ -40,20 +38,20 @@ module.exports = {
stringify,
};

const validRegex = new XRegExp("^" + VERSION_PATTERN + "$", "i");
const validRegex = new RegExp("^" + VERSION_PATTERN + "$", "i");

function valid(version) {
return validRegex.test(version) ? version : null;
}

const cleanRegex = new XRegExp("^\\s*" + VERSION_PATTERN + "\\s*$", "i");
const cleanRegex = new RegExp("^\\s*" + VERSION_PATTERN + "\\s*$", "i");
function clean(version) {
return stringify(parse(version, cleanRegex));
}

function parse(version, regex) {
// Validate the version and parse it into pieces
const groups = XRegExp.exec(version, regex || validRegex);
const { groups } = (regex || validRegex).exec(version) || {};
if (!groups) {
return null;
}
Expand Down
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,5 @@
"index.js",
"lib",
"index.d.ts"
],
"dependencies": {
"xregexp": "4.4.1"
}
]
}
Loading

0 comments on commit 3bd1fd5

Please sign in to comment.