0.0.0 • Published 1 year ago
theres-waldo v0.0.0
theres-waldo
Find the directory and file name of the file from which it is called in es6 modules.
Installation
npm install theres-waldoUsage
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.urlof the current module.Returns an object with properties:
file-- current filenamedir-- directory properties.
!WARNING Function must always be called with
import.meta.urlas 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
0.0.0
1 year ago