Skip to content

debug() wrapper that creates a string based on your file's path within the package. 🧶

License

Notifications You must be signed in to change notification settings

JoshuaKGoldberg/debug-for-file

Repository files navigation

debug-for-file

debug wrapper that creates a string based on your file's path within the package. 🧶

👪 All Contributors: 1 🤝 Code of Conduct: Kept 🧪 Coverage 📝 License: MIT 📦 npm version 💪 TypeScript: Strict

Usage

npm i debug-for-file
import { debugForFile } from "debug-for-file";

const log = debugForFile(import.meta.url);

log("booting $o", "My App");

debugForFile takes in the current path to your file, creates a namespace string based off your package name and the file's path, and passes that namespace to debug. Some examples:

Package Name File Path debug Namespace
example lib/index.js 'example:index'
example lib/abc/def.js 'example:abc:def'
@org/example lib/abc/def.js 'org:example:abc:def'

In other words, if your package name is example and your file name is lib/index.js, the following two code blocks are equivalent:

import debug from "debug";

const log = debug("example:lib:index");

log("Hello, world!");
import { debugForFile } from "debug";

const log = debugForFile(import.meta.url);

log("Hello, world!");

Why?

Hand-writing debug namespaces is a pain. They tend to become very long in large projects. It's easy to forget to change those long strings when you move around or rename files.

This helper manages all that for you. Plus, it establishes a predictable format for the namespaces.

Development

See .github/CONTRIBUTING.md, then .github/DEVELOPMENT.md. Thanks! 💖

Contributors

Josh Goldberg ✨
Josh Goldberg ✨

💻 🖋 🤔 🚇 🚧 📆 🔧 📖

💝 This package was templated with create-typescript-app using the create engine.

About

debug() wrapper that creates a string based on your file's path within the package. 🧶

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published