Deriving absolute directory or file path from import.meta with a consistent fallback order.
This function is Node.js-only and expects the url property to be a file: URL.
url
file:
For type 'dir', the fallback order is:
'dir'
importMeta.dirname
dirname(importMeta.filename)
dirname(fileURLToPath(importMeta.url))
For type 'file', the fallback order is:
'file'
importMeta.filename
fileURLToPath(importMeta.url)
An object resembling import.meta, containing at least a url property as a file: URL.
import.meta
The type of path to retrieve: 'dir' for directory or 'file' for file path. Defaults to 'dir'.
The derived directory or file path as a string.
If the type argument is not 'dir' or 'file'.
type
Deriving absolute directory or file path from import.meta with a consistent fallback order.
This function is Node.js-only and expects the
url
property to be afile:
URL.For type
'dir'
, the fallback order is:importMeta.dirname
(if present)dirname(importMeta.filename)
(if present)dirname(fileURLToPath(importMeta.url))
For type
'file'
, the fallback order is:importMeta.filename
(if present)fileURLToPath(importMeta.url)