Skip to content

Commit

Permalink
refactor(webpack/loaders): replace indexOf === 0 with startsWith
Browse files Browse the repository at this point in the history
It is more readable to call `startsWith` than to call `indexOf === 0`
and compare the result with zero to determine whether a string starts
with a given prefix.

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
  • Loading branch information
Juneezee committed Jul 24, 2024
1 parent af6aa78 commit 0bce62b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ function normalizeSourceMap(map: any, resourcePath: string) {
// We should normalize path because previous loaders like `sass-loader` using backslash when generate source map
newMap.sources = newMap.sources.map((source: string) => {
// Non-standard syntax from `postcss`
if (source.indexOf('<') === 0) {
if (source.startsWith('<')) {
return source
}

Expand Down Expand Up @@ -297,7 +297,7 @@ function normalizeSourceMapForRuntime(map: any, loaderContext: any) {

resultMap.sources = resultMap.sources.map((source: string) => {
// Non-standard syntax from `postcss`
if (source.indexOf('<') === 0) {
if (source.startsWith('<')) {
return source
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function normalizeSourceMapAfterPostcss(map: any, resourceContext: string) {

// eslint-disable-next-line no-param-reassign
newMap.sources = newMap.sources.map((source: string) => {
if (source.indexOf('<') === 0) {
if (source.startsWith('<')) {
return source
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function formatMessage(
}

// Cleans up verbose "module not found" messages for files and packages.
if (lines[1] && lines[1].indexOf('Module not found: ') === 0) {
if (lines[1] && lines[1].startsWith('Module not found: ')) {
lines = [
lines[0],
lines[1]
Expand Down

0 comments on commit 0bce62b

Please sign in to comment.