0.2.0 โ€ข Published 5 months ago

debug-for-file v0.2.0

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

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 NameFile Pathdebug Namespace
examplelib/index.js'example:index'
examplelib/abc/def.js'example:abc:def'
@org/examplelib/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

๐Ÿ’ This package was templated with create-typescript-app using the create engine.

0.2.0

5 months ago

0.1.0

5 months ago