Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use includes where appropriate (#4412)
* refactor: use includes where appropriate * refactor: replace .substr with .substring * Extract some regular expressions Co-authored-by: Lukas Taegert-Atkinson <lukastaegert@users.noreply.github.com> Co-authored-by: Lukas Taegert-Atkinson <lukas.taegert-atkinson@tngtech.com>
- Loading branch information
1 parent
213e721
commit 70d0025
Showing
24 changed files
with
75 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
const absolutePath = /^(?:\/|(?:[A-Za-z]:)?[\\|/])/; | ||
const relativePath = /^\.?\.\//; | ||
const ABSOLUTE_PATH_REGEX = /^(?:\/|(?:[A-Za-z]:)?[\\|/])/; | ||
const RELATIVE_PATH_REGEX = /^\.?\.\//; | ||
|
||
export function isAbsolute(path: string): boolean { | ||
return absolutePath.test(path); | ||
return ABSOLUTE_PATH_REGEX.test(path); | ||
} | ||
|
||
export function isRelative(path: string): boolean { | ||
return relativePath.test(path); | ||
return RELATIVE_PATH_REGEX.test(path); | ||
} | ||
|
||
const BACKSLASH_REGEX = /\\/g; | ||
|
||
export function normalize(path: string): string { | ||
if (path.indexOf('\\') == -1) return path; | ||
return path.replace(/\\/g, '/'); | ||
return path.replace(BACKSLASH_REGEX, '/'); | ||
} | ||
|
||
export { basename, dirname, extname, relative, resolve } from 'path'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
test/function/samples/relative-external-include-once-two-external/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
const assert = require('assert'); | ||
const path = require('path'); | ||
const { join } = require('path'); | ||
|
||
module.exports = { | ||
description: 'includes a relative external module only once (two external deps)', | ||
options: { | ||
external: [path.join(__dirname, './foo.js'), path.join(__dirname, './first/foo.js')] | ||
external: [join(__dirname, './foo.js'), join(__dirname, './first/foo.js')] | ||
}, | ||
context: { | ||
require(required) { | ||
assert(['./foo.js', './first/foo.js'].indexOf(required) !== -1, 'required wrong module'); | ||
assert.ok(['./foo.js', './first/foo.js'].includes(required), 'required wrong module'); | ||
return required === './foo.js' ? 'a' : 'b'; | ||
} | ||
}, | ||
exports(exports) { | ||
assert(exports === 'ab' || exports === 'ba', 'two different modules should be required'); | ||
assert.ok(exports === 'ab' || exports === 'ba', 'two different modules should be required'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.