theres-waldo
v0.0.0
Published
A utility to find the directory and file name of the file from which it's called
Downloads
4
Maintainers
Readme
theres-waldo
Find the directory and file name of the file from which it is called in es6 modules.
Installation
npm install theres-waldo
Usage
import theresWaldo from "theres-waldo";
const { file, dir } = theresWaldo(import.meta.url); // Note: pass in `import.meta.url`
console.log(`Current file: ${file}`);
console.log(`Current directory: ${dir}`);
API
The package exports the following function:
theresWaldo(importMetaUrl)
importMetaUrl
: Theimport.meta.url
of the current module.Returns an object with properties:
file
-- current filenamedir
-- directory properties.
[!WARNING] Function must always be called with
import.meta.url
as its only argument.
Old Behavior
Looking to polyfill commonJS behavior? Use the following snippet:
import theresWaldo from "theres-waldo";
const { file: __filename, dir: __dirname } = theresWaldo(import.meta.url);
License
MIT