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 cbc0453 commit 7c6d7ec
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 38 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 @@ -57,8 +57,5 @@
"index.js",
"lib",
"index.d.ts"
],
"dependencies": {
"xregexp": "4.4.1"
}
]
}
25 changes: 0 additions & 25 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -403,14 +403,6 @@
dependencies:
"@babel/helper-plugin-utils" "^7.16.7"

"@babel/runtime-corejs3@^7.12.1":
version "7.16.5"
resolved "https://registry.yarnpkg.com/@babel/runtime-corejs3/-/runtime-corejs3-7.16.5.tgz#9057d879720c136193f0440bc400088212a74894"
integrity sha512-F1pMwvTiUNSAM8mc45kccMQxj31x3y3P+tA/X8hKNWp3/hUsxdGxZ3D3H8JIkxtfA8qGkaBTKvcmvStaYseAFw==
dependencies:
core-js-pure "^3.19.0"
regenerator-runtime "^0.13.4"

"@babel/template@^7.16.0", "@babel/template@^7.3.3":
version "7.16.0"
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.16.0.tgz#d16a35ebf4cd74e202083356fab21dd89363ddd6"
Expand Down Expand Up @@ -1200,11 +1192,6 @@ convert-source-map@^1.4.0, convert-source-map@^1.6.0, convert-source-map@^1.7.0:
dependencies:
safe-buffer "~5.1.1"

core-js-pure@^3.19.0:
version "3.20.1"
resolved "https://registry.yarnpkg.com/core-js-pure/-/core-js-pure-3.20.1.tgz#f7a2c62f98de83e4da8fca7b78846d3a2f542145"
integrity sha512-yeNNr3L9cEBwNy6vhhIJ0nko7fE7uFO6PgawcacGt2VWep4WqQx0RiqlkgSP7kqUMC1IKdfO9qPeWXcUheHLVQ==

cross-spawn@^6.0.5:
version "6.0.5"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4"
Expand Down Expand Up @@ -3092,11 +3079,6 @@ read-pkg@^3.0.0:
normalize-package-data "^2.3.2"
path-type "^3.0.0"

regenerator-runtime@^0.13.4:
version "0.13.9"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.9.tgz#8925742a98ffd90814988d7566ad30ca3b263b52"
integrity sha512-p3VT+cOEgxFsRRA9X4lkI1E+k2/CtnKtU4gcxyaCUreilL/vqI6CdZ3wxVUx3UOUg+gnUOQQcRI7BmSI656MYA==

regexpp@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-3.2.0.tgz#0425a2768d8f23bad70ca4b90461fa2f1213e1b2"
Expand Down Expand Up @@ -3717,13 +3699,6 @@ xmlchars@^2.2.0:
resolved "https://registry.yarnpkg.com/xmlchars/-/xmlchars-2.2.0.tgz#060fe1bcb7f9c76fe2a17db86a9bc3ab894210cb"
integrity sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw==

xregexp@4.4.1:
version "4.4.1"
resolved "https://registry.yarnpkg.com/xregexp/-/xregexp-4.4.1.tgz#c84a88fa79e9ab18ca543959712094492185fe65"
integrity sha512-2u9HwfadaJaY9zHtRRnH6BY6CQVNQKkYm3oLtC9gJXXzfsbACg5X5e4EZZGVAH+YIfa+QA9lsFQTTe3HURF3ag==
dependencies:
"@babel/runtime-corejs3" "^7.12.1"

y18n@^5.0.5:
version "5.0.8"
resolved "https://registry.yarnpkg.com/y18n/-/y18n-5.0.8.tgz#7f4934d0f7ca8c56f95314939ddcd2dd91ce1d55"
Expand Down

0 comments on commit 7c6d7ec

Please sign in to comment.