+22
-22
| "use strict"; | ||
| // Inherited from https://github.com/grammyjs/debug/blob/502f75667a64391adb9a73b1312a52a8e9ba5f64/colors.ts | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.colourNs = void 0; | ||
| exports.selectColour = selectColour; | ||
| // https://github.com/debug-js/debug/blob/4.3.7/src/browser.js | ||
| const colors = [ | ||
| 0x0000cc, 0x0000ff, 0x0033cc, 0x0033ff, 0x0066cc, 0x0066ff, 0x0099cc, 0x0099ff, 0x00cc00, 0x00cc33, 0x00cc66, | ||
| 0x00cc99, 0x00cccc, 0x00ccff, 0x3300cc, 0x3300ff, 0x3333cc, 0x3333ff, 0x3366cc, 0x3366ff, 0x3399cc, 0x3399ff, | ||
| 0x33cc00, 0x33cc33, 0x33cc66, 0x33cc99, 0x33cccc, 0x33ccff, 0x6600cc, 0x6600ff, 0x6633cc, 0x6633ff, 0x66cc00, | ||
| 0x66cc33, 0x9900cc, 0x9900ff, 0x9933cc, 0x9933ff, 0x99cc00, 0x99cc33, 0xcc0000, 0xcc0033, 0xcc0066, 0xcc0099, | ||
| 0xcc00cc, 0xcc00ff, 0xcc3300, 0xcc3333, 0xcc3366, 0xcc3399, 0xcc33cc, 0xcc33ff, 0xcc6600, 0xcc6633, 0xcc9900, | ||
| 0xcc9933, 0xcccc00, 0xcccc33, 0xff0000, 0xff0033, 0xff0066, 0xff0099, 0xff00cc, 0xff00ff, 0xff3300, 0xff3333, | ||
| 0xff3366, 0xff3399, 0xff33cc, 0xff33ff, 0xff6600, 0xff6633, 0xff9900, 0xff9933, 0xffcc00, 0xffcc33, | ||
| ]; | ||
| // https://github.com/debug-js/debug/blob/4.3.4/src/common.js#L41 | ||
| const genColours = (n = 72) => { | ||
| const colors = []; | ||
| for (let i = 0; i < n; i++) { | ||
| const h = (i * 137.5) % 360; | ||
| const r = Math.round(Math.sin((h * Math.PI) / 180) * 105 + 105); | ||
| const g = Math.round(Math.sin(((h + 120) * Math.PI) / 180) * 105 + 105); | ||
| const b = Math.round(Math.sin(((h + 240) * Math.PI) / 180) * 105 + 105); | ||
| // store rgb values as numbers for server runtimes | ||
| // precompute all hex strings so browser runtimes are faster | ||
| colors.push([r, g, b, [r, g, b].map(c => c.toString(16).padStart(2, "0")).join("")]); | ||
| } | ||
| return colors; | ||
| }; | ||
| const colours = genColours(); | ||
| const hash = (str) => { | ||
| let h = 5381; | ||
| for (let i = 0; i < str.length; i++) | ||
| h = ((h << 5) + h) ^ str.charCodeAt(i); | ||
| return h >>> 0; // Convert to unsigned 32-bit integer | ||
| }; | ||
| function selectColour(ns) { | ||
| let hash = 0; | ||
| for (let i = 0; i < ns.length; i++) { | ||
| hash = (hash << 5) - hash + ns.charCodeAt(i); | ||
| hash |= 0; // Convert to 32bit integer | ||
| } | ||
| return colors[Math.abs(hash) % colors.length]; | ||
| return colours[Math.abs(hash(ns)) % colours.length]; | ||
| } | ||
| const colourNs = (ns) => { | ||
| const color = selectColour(ns); | ||
| const r = color >> 16; | ||
| const g = (color >> 8) & 0xff; | ||
| const b = color & 0xff; | ||
| const [r, g, b] = selectColour(ns); | ||
| return `\x1b[38;2;${r};${g};${b}m${ns}\x1b[1;0m`; | ||
| }; | ||
| exports.colourNs = colourNs; |
+4
-15
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.getEnv = void 0; | ||
| exports.env = void 0; | ||
| const types_ts_1 = require("./types.js"); | ||
| const getDenoEnv = (variable) => { | ||
| const Deno = types_ts_1.context.Deno; | ||
| const state = Deno.permissions.querySync?.({ name: "env", variable })?.state; | ||
| if (state === "prompt") | ||
| return ""; | ||
| return Deno.env.get(variable) ?? ""; | ||
| }; | ||
| const deno = "Deno" in globalThis; | ||
| const getEnv = (variable) => { | ||
| if (deno) | ||
| return getDenoEnv(variable); | ||
| return types_ts_1.context.process?.env[variable] || types_ts_1.context.env?.[variable] || ""; | ||
| }; | ||
| exports.getEnv = getEnv; | ||
| const prompts = (variable) => types_ts_1.context.Deno?.permissions.querySync?.({ name: "env", variable })?.state === "prompt"; | ||
| const env = (variable) => (!prompts(variable) && (types_ts_1.context.process?.env ?? types_ts_1.context.env)?.[variable]) || ""; | ||
| exports.env = env; |
@@ -33,3 +33,3 @@ "use strict"; | ||
| let current = this.parsed; | ||
| let tentative = false; | ||
| let tentative = current.allowed; | ||
| for (const part of chain) { | ||
@@ -36,0 +36,0 @@ let picked = current.children[part]; |
+10
-12
@@ -9,5 +9,5 @@ "use strict"; | ||
| const namespacing_ts_1 = require("./namespacing.js"); | ||
| const DEBUG = (0, env_ts_1.getEnv)("DEBUG"); | ||
| const DEBUG = (0, env_ts_1.env)("DEBUG"); | ||
| const stderr = types_ts_1.context.process?.stderr; | ||
| const useColour = stderr?.isTTY && !(0, env_ts_1.getEnv)("NO_COLOR"); | ||
| const useColour = stderr?.isTTY && !(0, env_ts_1.env)("NO_COLOR"); | ||
| const debug = types_ts_1.context.console.Console?.(stderr)?.debug || types_ts_1.context.console.debug; | ||
@@ -39,12 +39,10 @@ /** | ||
| function w(namespace = "") { | ||
| const debugfn = (...args) => { | ||
| if (debugfn.enabled) { | ||
| const [p0, ...rest] = args; | ||
| if (types_ts_1.context.document) { | ||
| debugfn.logger(`%c${namespace}%c ${p0}`, `color: #${(0, colours_ts_1.selectColour)(namespace).toString(16)}`, "color: inherit", ...rest); | ||
| } | ||
| else { | ||
| let ns = useColour ? (0, colours_ts_1.colourNs)(namespace) : namespace; | ||
| debugfn.logger(`${ns} ${p0}`, ...rest); | ||
| } | ||
| const debugfn = (start = "", ...rest) => { | ||
| if (!debugfn.enabled) | ||
| return; | ||
| if (types_ts_1.context.document) | ||
| debugfn.logger(`%c${namespace}%c ${start}`, `color: #${(0, colours_ts_1.selectColour)(namespace)[3]}`, "color: inherit", ...rest); | ||
| else { | ||
| const ns = useColour ? (0, colours_ts_1.colourNs)(namespace) : namespace; | ||
| debugfn.logger(`${ns} ${start}`, ...rest); | ||
| } | ||
@@ -51,0 +49,0 @@ }; |
+1
-1
| { | ||
| "name": "w", | ||
| "version": "2.1.5", | ||
| "version": "2.2.0", | ||
| "homepage": "https://github.com/feathers-studio/wiretap", | ||
@@ -5,0 +5,0 @@ "repository": { |
+6
-5
| <div align="center"> | ||
| <img src="https://raw.githubusercontent.com/feathers-studio/wiretap/master/w.png" alt="logo" width="128" /> | ||
| </div> | ||
| <img src="https://raw.githubusercontent.com/feathers-studio/wiretap/master/docs/w.png" alt="logo" width="128" /> | ||
| <div align="center"> | ||
| <h1><code>w</code>iretap</h1> | ||
| </div> | ||
@@ -13,2 +10,5 @@ Extremely tiny debug logging utility for all JavaScript runtimes. | ||
| <img src="https://raw.githubusercontent.com/feathers-studio/wiretap/master/docs/example.png" alt="example" width="400" /> | ||
| </div> | ||
| ## Installation | ||
@@ -120,2 +120,3 @@ | ||
| // Replace the default logger with your own | ||
| log.logger = console.log.bind(console); // or | ||
| log.logger = (...args) => console.log("[CUSTOM]", ...args); | ||
@@ -130,2 +131,2 @@ ``` | ||
| - Cloudflare Workers | ||
| - Browsers | ||
| - Browsers (by default, you _may_ need to turn on the "debug", "verbose", or similar setting in the console to see the logs in your browser to see debug logs) |
Sorry, the diff of this file is not supported yet
130
0.78%9996
-20.71%8
-11.11%140
-8.5%