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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Tiny debug tool (~500 bytes) for terminal and browser inspired by [debug-js/debu
## Motivation

`@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.
as the same way as the great debug-js/debug tool.

## Installation

Expand Down
2 changes: 1 addition & 1 deletion examples/browser/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ console.log("isProd", isProd)
export default defineConfig({
esbuild: {
pure: isProd ? ["console.log"] : [],
//drop: isProd ? ["console"] : [],
//drop: ["console"],
},
})
2 changes: 1 addition & 1 deletion examples/node/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const debug = require("@wbe/debug")
import debug from "@wbe/debug"
const str = "hello debug!"

debug("01-namespace")(str)
Expand Down
9 changes: 3 additions & 6 deletions examples/node/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
{
"name": "node",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@wbe/debug": "workspace:*"
}
Expand Down
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
{
"name": "@wbe/debug",
"version": "1.2.0",
"description": "Tiny debug tool (~500 bytes) for terminal and browser inspired by visionmedia/debug API.",
"description": "Tiny debug tool (~500 bytes) for terminal and browser inspired by debug-js/debug API.",
"author": "Willy Brauner",
"license": "MIT",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
}
},
"sideEffects": false,
"repository": {
"type": "git",
Expand Down
14 changes: 9 additions & 5 deletions src/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,33 @@ import { isBrowser, stringToRgb } from "./helpers"
* debug
*/
// prettier-ignore
export const debug = (namespace?: string) => (...rest: any[]): void =>
{
export const debug = (namespace?: string) => (...rest: any[]): void => {
const rgb = stringToRgb(namespace)

const showLog = (value: string): boolean =>
value?.includes(":*")
? namespace.startsWith( value.split(":*")[0])
: value === namespace || value === "*"

// Allow to bypass dropping of console.log from the build process
// tested with esbuild config: pure: ["console.log"] or drop: ["console"]
const log = console['log']

if (isBrowser)
{
showLog(localStorage.getItem("debug"))
&&
console.log(
log(
namespace && `%c${namespace}`, `color: rgb(${rgb[0]}, ${rgb[1]}, ${rgb[2]})`,
...rest
)
}

else
{
{
showLog(process.env.DEBUG)
&&
console.log(
log(
namespace && couleur.bold(couleur.rgb(rgb[0], rgb[1], rgb[2])(namespace)),
...rest
)
Expand Down