0.0.0 • Published 11 months ago

theres-waldo v0.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

theres-waldo

npm version License: MIT

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: The import.meta.url of the current module.

  • Returns an object with properties:

    • file -- current filename
    • dir -- 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

0.0.0

11 months ago