Skip to content

Commit

Permalink
Merge pull request #129 from styfle/remove-process-global
Browse files Browse the repository at this point in the history
feat!: remove process global to work outside of node
  • Loading branch information
jonschlinkert committed Feb 8, 2024
2 parents 5214db4 + 3b2726c commit c0f9c55
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 26 deletions.
4 changes: 0 additions & 4 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -698,10 +698,6 @@ const parse = (input, options) => {
const next = peek();
let output = value;

if (next === '<' && !utils.supportsLookbehinds()) {
throw new Error('Node.js v10 or higher is required for regex lookbehinds');
}

if ((prev.value === '(' && !/[!=<:]/.test(next)) || (next === '<' && !/<([!=]|\w+>)/.test(remaining()))) {
output = `\\${value}`;
}
Expand Down
10 changes: 0 additions & 10 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,6 @@ exports.removeBackslashes = str => {
});
};

exports.supportsLookbehinds = () => {
if (typeof process !== 'undefined') {
const segs = process.version.slice(1).split('.').map(Number);
if (segs.length === 3 && segs[0] >= 9 || (segs[0] === 8 && segs[1] >= 10)) {
return true;
}
}
return false;
};

exports.escapeLast = (input, char, lastIdx) => {
const idx = input.lastIndexOf(char, lastIdx);
if (idx === -1) return input;
Expand Down
16 changes: 4 additions & 12 deletions test/regex-features.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,10 @@ describe('regex features', () => {

describe('regex lookarounds', () => {
it('should support regex lookbehinds', () => {
if (utils.supportsLookbehinds()) {
assert(isMatch('foo/cbaz', 'foo/*(?<!d)baz'));
assert(!isMatch('foo/cbaz', 'foo/*(?<!c)baz'));
assert(!isMatch('foo/cbaz', 'foo/*(?<=d)baz'));
assert(isMatch('foo/cbaz', 'foo/*(?<=c)baz'));
}
});

it('should throw an error when regex lookbehinds are used on an unsupported node version', () => {
Reflect.defineProperty(process, 'version', { value: 'v6.0.0' });
assert.throws(() => isMatch('foo/cbaz', 'foo/*(?<!c)baz'), /Node\.js v10 or higher/);
Reflect.defineProperty(process, 'version', { value: version });
assert(isMatch('foo/cbaz', 'foo/*(?<!d)baz'));
assert(!isMatch('foo/cbaz', 'foo/*(?<!c)baz'));
assert(!isMatch('foo/cbaz', 'foo/*(?<=d)baz'));
assert(isMatch('foo/cbaz', 'foo/*(?<=c)baz'));
});
});

Expand Down

0 comments on commit c0f9c55

Please sign in to comment.