Skip to content

Commit

Permalink
refactor: no nested ternary
Browse files Browse the repository at this point in the history
  • Loading branch information
tpluscode committed Aug 2, 2023
1 parent 048f3c3 commit 88fcf6f
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions packages/rdf/lib/localFetch/localFetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ import { isReadableStream } from 'is-stream'
import protoFetch from 'proto-fetch'
import { getParserByExtension } from './lookupParser.js'

function isAbsolute(str) {
return str.startsWith('https:') || str.startsWith('http:') || str.startsWith('file:')
}

async function streamWithMetadata(input) {
return {
quadStream: input,
Expand Down Expand Up @@ -78,14 +74,11 @@ async function localFetch(

try {
return fetch(new URL(input).toString())
} catch (e) {
const url = isAbsolute(input)
? input
: basePath
? pathToFileURL(resolve(basePath, input)).toString()
: pathToFileURL(input).toString()
} catch {
// in case of error, the input must be path string
const absolutPath = basePath ? resolve(basePath, input) : input

return fetch(url)
return fetch(pathToFileURL(absolutPath).toString())
}
}

Expand Down

0 comments on commit 88fcf6f

Please sign in to comment.