debug-for-file
TypeScript icon, indicating that this package has built-in type declarations

0.2.0Β β€’Β PublicΒ β€’Β Published

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.

Readme

Keywords

none

Package Sidebar

Install

npm i debug-for-file

Weekly Downloads

440

Version

0.2.0

License

MIT

Unpacked Size

11.4 kB

Total Files

12

Last publish

Collaborators

  • joshuakgoldberg