theres-waldo

0.0.0 • Public • Published

theres-waldo

npm version License: MIT

Waldo standing next to a sign that reads: There's 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: 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

Package Sidebar

Install

npm i theres-waldo

Weekly Downloads

1

Version

0.0.0

License

MIT

Unpacked Size

92.3 kB

Total Files

6

Last publish

Collaborators

  • johnhenry