Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ Tiny debug tool (~500 bytes) for terminal and browser inspired by [debug-js/debu

![](screen.jpg)

## Motivation
## Motivation

`@wbe/debug` was built in order to be as light as possible for terminal and browser,
`@wbe/debug` was built in order to be as light as possible for terminal and browser,
as the same way as the great visionmedia/debug tool.

## Installation
Expand All @@ -24,40 +24,45 @@ $ npm i @wbe/debug
## debug node

```shell
DEBUG=* node file.js
DEBUG=* node file.js
```

file.js:

```js
const debug = require("@wbe/debug")
debug('foo'); // "foo"
import debug from "@wbe/debug"
const log = debug("namespace")
log("hello") // "namespace hello"
```

`process.env.DEBUG` value can be defined as a specific namespace too:

```shell
DEBUG=namespace node file.js
DEBUG=namespace-1 node file.js
```

Only debug function declaration with `namespace` declared as namespace will be printed in the console:
Only debug function declaration with `namespace-1` declared as namespace will be printed in the console:

```js
// add the namspace as returned function paramater
const debug = require("@wbe/debug")("namespace")
debug('foo'); // "namespace foo"
import debug from "@wbe/debug"
const log = debug("namespace-1")
log("hello") // "namespace-1 hello"
```

`process.env.DEBUG` value accept "one glob parameter level":

```shell
DEBUG=config:* node file.js
```

Every debug function declaration with namespace `config:{somestring}` will be logged.

## debug in browser

In the same way as nodejs usage, `debug` is browser compatible with the same API. The only difference is
In the same way as nodejs usage, `debug` is browser compatible with the same API. The only difference is
we need to set the current namespace in localStorage.

Add on your browser localStorage:
Add on your browser localStorage:

```shell
localStorage.debug = "foo"
Expand All @@ -68,21 +73,20 @@ Use debug in javascript:
```js
// es6 import
import debug from "@wbe/debug"
const log = debug('foo');
const log = debug("foo")
log("bar") // "foo bar"

// commonjs import
const debug = require("@wbe/debug")("foo")
debug('bar'); // "foo bar"
```

## Examples

Install dependencies:

```shell
pnpm i
```

Start example:

```shell
# browser example
npm run dev:example-browser
Expand All @@ -97,6 +101,3 @@ Willy Brauner
## Licence

MIT



13 changes: 0 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
/**
* Export to be able to require module in node/browser env
*
* Usage ex:
*
* const debug = require("@wbe/debug")("namespace")
* // ...
* debug("...")
*
*/
import { debug } from "./debug"
if (typeof module != "undefined") module.exports = debug

/**
* Export as es6 module
*
Expand Down
4 changes: 2 additions & 2 deletions tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ export default defineConfig({
splitting: false,
clean: true,
dts: true,
format: ["cjs", "esm"],
format: ["esm"],
name: "debug",
minify: "terser",
minify: "terser",
terserOptions: {
compress: true,
},
Expand Down