UEA-Prodem

This commit is contained in:
2026-06-10 12:38:42 -03:00
parent 3f33154e16
commit c41625e542
9352 changed files with 1128292 additions and 14752 deletions
Generated Vendored
+23
View File
@@ -0,0 +1,23 @@
The MIT License (MIT)
Copyright © 2025-PRESENT Kevin Deng (https://github.com/sxzz)
Copyright (c) 2014-2017 TJ Holowaychuk <tj@vision-media.ca>
Copyright (c) 2018-2021 Josh Junon
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+251
View File
@@ -0,0 +1,251 @@
# obug
[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![JSR][jsr-badge-src]][jsr-badge-href]
[![Unit Test][unit-test-src]][unit-test-href]
A lightweight JavaScript debugging utility, forked from [debug](https://www.npmjs.com/package/debug), featuring TypeScript and ESM support.
> [!NOTE]
> obug v1 retains most of the compatibility with [debug](https://github.com/debug-js/debug), but drops support for older browsers and Node.js, making it a drop-in replacement.
>
> obug v2 refactors some API imports and usage for better support of ESM and TypeScript, easier customization, and an even smaller package size.
## Key Differences from `debug`
- ✨ Minimal footprint
- 7.7 kB package size
- 1.4 KB minified + gzipped for browsers
- 📦 Zero dependencies
- 📝 Full TypeScript support
- 🚀 Native ESM compatibility
- 🌐 Optimized for modern runtimes
- ES2015+ browsers
- Modern Node.js versions
- 🎨 Customizable formatting
## Installation
```bash
npm install obug
```
## Usage
```ts
import { createDebug, disable, enable, enabled, namespaces } from 'obug'
// Get the currently enabled namespaces
console.log(namespaces())
const debug = createDebug('my-namespace', {
// All options are optional
useColors: true, // false, true, undefined for auto-detect
color: 2, // custom color
// custom formatArgs
formatArgs(args) {},
formatters: {},
// Node.js only
inspectOpts: {},
// custom log
log: console.log,
})
debug('This is a debug message')
console.log(
debug.namespace, // 'my-namespace'
debug.enabled, // Check if enabled
debug.useColors, // true
debug.color, // 2
debug.formatArgs, // custom formatArgs
debug.formatters, // {}
debug.inspectOpts, // {}
debug.log, // implemented log function
)
// Create a sub-namespace, and it will inherit options from the parent debugger
const sub = debug.extend('sub-namespace')
sub('This is a sub-namespace debug message')
console.log(sub.namespace) // 'my-namespace:sub-namespace'
```
## How to use
### Enabling debug output
obug picks up enabled namespaces from the `DEBUG` environment variable in Node.js, or from `localStorage.debug` in browsers.
In Node.js:
```bash
DEBUG=app:* node app.js
```
On Windows (CMD):
```cmd
set DEBUG=app:* & node app.js
```
On Windows (PowerShell):
```powershell
$env:DEBUG='app:*'; node app.js
```
In the browser, set the value in DevTools and refresh the page:
```js
localStorage.debug = 'app:*'
```
### Wildcards and exclusion
The `*` character is a wildcard. Suppose your library has debuggers named `connect:bodyParser`, `connect:compress`, and `connect:session` — instead of listing each one, use `DEBUG=connect:*`. Use `DEBUG=*` to enable everything.
Exclude namespaces by prefixing them with `-`:
```bash
DEBUG=*,-connect:* node app.js
```
### Namespace conventions
If you're using obug in a library, prefix your namespaces with the library name and use `:` to separate features (e.g. `connect:bodyParser`). This lets users opt into the parts they care about without guessing names.
### Extending a namespace
Use `.extend()` to create a sub-namespace that inherits options from its parent:
```ts
const log = createDebug('auth')
const logSign = log.extend('sign') // 'auth:sign'
const logLogin = log.extend('login') // 'auth:login'
log('hello') // auth hello
logSign('hello') // auth:sign hello
logLogin('hello') // auth:login hello
```
### Formatters
obug uses [printf-style](https://wikipedia.org/wiki/Printf_format_string) formatting. Built-in formatters:
| Formatter | Representation |
| --------- | -------------------------------------------------- |
| `%O` | Pretty-print an Object on multiple lines. |
| `%o` | Pretty-print an Object all on a single line. |
| `%%` | Single percent sign. Does not consume an argument. |
Other format specifiers supported by Node's `util.format` (`%s`, `%d`, `%j`, …) and the browser console pass through to the underlying logger.
#### Custom formatters
Register custom formatters via the `formatters` option. For example, to render a `Buffer` as hex with `%h`:
```ts
const debug = createDebug('foo', {
formatters: {
h: (v) => v.toString('hex'),
},
})
debug('this is hex: %h', Buffer.from('hello world'))
// foo this is hex: 68656c6c6f20776f726c64 +0ms
```
### Dynamic enable / disable
You can toggle namespaces at runtime:
```ts
import { disable, enable, enabled, namespaces } from 'obug'
enable('app:*')
console.log(enabled('app:server')) // true
const previous = disable()
console.log(enabled('app:server')) // false
// Restore later
enable(previous)
```
`namespaces()` returns the string of currently enabled namespaces. Note that calling `enable()` overrides the value initially read from `DEBUG`.
### Checking whether a debugger is enabled
Guard expensive work behind the `enabled` property:
```ts
const debug = createDebug('http')
if (debug.enabled) {
// expensive computation only when enabled
}
```
You can also force the state by assigning to `debug.enabled` directly.
### Custom output
By default, obug writes to `stderr` in Node.js and to the console in browsers. Override the `log` option to redirect output per-namespace:
```ts
const log = createDebug('app:log', {
log: console.log,
})
const error = createDebug('app:error') // still goes to stderr
```
### Environment variables (Node.js)
| Name | Purpose |
| ------------------- | ----------------------------------------------- |
| `DEBUG` | Enables/disables specific debugging namespaces. |
| `DEBUG_HIDE_DATE` | Hide date from debug output (non-TTY). |
| `DEBUG_COLORS` | Whether to use colors in the debug output. |
| `DEBUG_DEPTH` | Object inspection depth. |
| `DEBUG_SHOW_HIDDEN` | Shows hidden properties on inspected objects. |
Variables prefixed with `DEBUG_` are converted to camelCase keys on the options object passed to Node's [`util.inspect()`](https://nodejs.org/api/util.html#util_util_inspect_object_options) for the `%o` / `%O` formatters.
## Original Authors
As obug is a fork of debug with significant modifications, we would like to acknowledge the original authors:
- TJ Holowaychuk
- Nathan Rajlich
- Andrew Rhyne
- Josh Junon
## Sponsors
<p align="center">
<a href="https://cdn.jsdelivr.net/gh/sxzz/sponsors/sponsors.svg">
<img src='https://cdn.jsdelivr.net/gh/sxzz/sponsors/sponsors.svg'/>
</a>
</p>
## License
[MIT](./LICENSE) License © 2025-PRESENT [Kevin Deng](https://github.com/sxzz)
[The MIT License](./LICENSE) Copyright (c) 2014-2017 TJ Holowaychuk &lt;tj@vision-media.ca&gt;
[The MIT License](./LICENSE) Copyright (c) 2018-2021 Josh Junon
<!-- Badges -->
[npm-version-src]: https://img.shields.io/npm/v/obug.svg
[npm-version-href]: https://npmjs.com/package/obug
[npm-downloads-src]: https://img.shields.io/npm/dm/obug
[npm-downloads-href]: https://www.npmcharts.com/compare/obug?interval=30
[unit-test-src]: https://github.com/sxzz/obug/actions/workflows/unit-test.yml/badge.svg
[unit-test-href]: https://github.com/sxzz/obug/actions/workflows/unit-test.yml
[jsr-badge-src]: https://jsr.io/badges/@sxzz/obug
[jsr-badge-href]: https://jsr.io/@sxzz/obug
+11
View File
@@ -0,0 +1,11 @@
import { a as Debugger, i as DebugOptions, n as enabled, o as Formatters, r as namespaces, s as InspectOptions, t as disable } from "./core.js";
//#region src/browser.d.ts
declare function createDebug(namespace: string, options?: DebugOptions): Debugger;
/**
* Enables a debug mode by namespaces. This can include modes
* separated by a colon and wildcards.
*/
declare function enable(namespaces: string): void;
//#endregion
export { type DebugOptions, type Debugger, type Formatters, type InspectOptions, createDebug, disable, enable, enabled, namespaces };
+166
View File
@@ -0,0 +1,166 @@
import { a as namespaces, i as enabled, n as disable, o as humanize, r as enable$1, s as selectColor, t as createDebug$1 } from "./core.js";
//#region src/browser.ts
const colors = [
"#0000CC",
"#0000FF",
"#0033CC",
"#0033FF",
"#0066CC",
"#0066FF",
"#0099CC",
"#0099FF",
"#00CC00",
"#00CC33",
"#00CC66",
"#00CC99",
"#00CCCC",
"#00CCFF",
"#3300CC",
"#3300FF",
"#3333CC",
"#3333FF",
"#3366CC",
"#3366FF",
"#3399CC",
"#3399FF",
"#33CC00",
"#33CC33",
"#33CC66",
"#33CC99",
"#33CCCC",
"#33CCFF",
"#6600CC",
"#6600FF",
"#6633CC",
"#6633FF",
"#66CC00",
"#66CC33",
"#9900CC",
"#9900FF",
"#9933CC",
"#9933FF",
"#99CC00",
"#99CC33",
"#CC0000",
"#CC0033",
"#CC0066",
"#CC0099",
"#CC00CC",
"#CC00FF",
"#CC3300",
"#CC3333",
"#CC3366",
"#CC3399",
"#CC33CC",
"#CC33FF",
"#CC6600",
"#CC6633",
"#CC9900",
"#CC9933",
"#CCCC00",
"#CCCC33",
"#FF0000",
"#FF0033",
"#FF0066",
"#FF0099",
"#FF00CC",
"#FF00FF",
"#FF3300",
"#FF3333",
"#FF3366",
"#FF3399",
"#FF33CC",
"#FF33FF",
"#FF6600",
"#FF6633",
"#FF9900",
"#FF9933",
"#FFCC00",
"#FFCC33"
];
/**
* Colorize log arguments if enabled.
*/
function formatArgs(diff, args) {
const { useColors } = this;
args[0] = `${(useColors ? "%c" : "") + this.namespace + (useColors ? " %c" : " ") + args[0] + (useColors ? "%c " : " ")}+${this.humanize(diff)}`;
if (!useColors) return;
const c = `color: ${this.color}`;
args.splice(1, 0, c, "color: inherit");
let index = 0;
let lastC = 0;
args[0].replace(/%[a-z%]/gi, (match) => {
if (match === "%%") return;
index++;
if (match === "%c") lastC = index;
});
args.splice(lastC, 0, c);
}
/**
* Invokes `console.debug()` when available.
* No-op when `console.debug` is not a "function".
* If `console.debug` is not available, falls back
* to `console.log`.
*/
const log = console.debug || console.log || (() => {});
const storage = localstorage();
const defaultOptions = {
useColors: true,
formatArgs,
formatters: {
/**
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
*/
j(v) {
try {
return JSON.stringify(v);
} catch (error) {
return `[UnexpectedJSONParseError]: ${error.message}`;
}
} },
inspectOpts: {},
humanize,
log
};
function createDebug(namespace, options) {
var _ref;
const color = (_ref = options && options.color) !== null && _ref !== void 0 ? _ref : selectColor(colors, namespace);
return createDebug$1(namespace, Object.assign(defaultOptions, { color }, options));
}
/**
* Localstorage attempts to return the localstorage.
*
* This is necessary because safari throws
* when a user disables cookies/localstorage
* and you attempt to access it.
*/
function localstorage() {
try {
return localStorage;
} catch (_unused) {}
}
function load() {
let r;
try {
r = storage.getItem("debug") || storage.getItem("DEBUG");
} catch (_unused2) {}
if (!r && typeof process !== "undefined" && "env" in process) r = process.env.DEBUG;
return r || "";
}
function save(namespaces) {
try {
if (namespaces) storage.setItem("debug", namespaces);
else storage.removeItem("debug");
} catch (_unused3) {}
}
/**
* Enables a debug mode by namespaces. This can include modes
* separated by a colon and wildcards.
*/
function enable(namespaces) {
save(namespaces);
enable$1(namespaces);
}
enable$1(load());
//#endregion
export { createDebug, disable, enable, enabled, namespaces };
+1
View File
@@ -0,0 +1 @@
function e(e){return e instanceof Error?e.stack||e.message:e}function t(e,t){let n=0;for(let e=0;e<t.length;e++)n=(n<<5)-n+t.charCodeAt(e),n|=0;return e[Math.abs(n)%e.length]}function n(e,t){let n=0,r=0,i=-1,a=0;for(;n<e.length;)if(r<t.length&&(t[r]===e[n]||t[r]===`*`))t[r]===`*`?(i=r,a=n,r++):(n++,r++);else if(i!==-1)r=i+1,a++,n=a;else return!1;for(;r<t.length&&t[r]===`*`;)r++;return r===t.length}function r(e){return e>=1e3?`${(e/1e3).toFixed(1)}s`:`${e}ms`}let i=``;function a(){return i}function o(t,n){let r,a,s,c,l=(...t)=>{if(!l.enabled)return;let i=Date.now(),a=i-(r||i);r=i,t[0]=e(t[0]),typeof t[0]!=`string`&&t.unshift(`%O`);let o=0;t[0]=t[0].replace(/%([a-z%])/gi,(e,r)=>{if(e===`%%`)return`%`;o++;let i=n.formatters[r];if(typeof i==`function`){let n=t[o];e=i.call(l,n),t.splice(o,1),o--}return e}),n.formatArgs.call(l,a,t),l.log(...t)};return l.extend=function(e,t=`:`){return o(this.namespace+t+e,{useColors:this.useColors,color:this.color,formatArgs:this.formatArgs,formatters:this.formatters,inspectOpts:this.inspectOpts,log:this.log,humanize:this.humanize})},Object.assign(l,n),l.namespace=t,Object.defineProperty(l,"enabled",{enumerable:!0,configurable:!1,get:()=>a==null?(s!==i&&(s=i,c=d(t)),c):a,set:e=>{a=e}}),l}let s=[],c=[];function l(e){i=e,s=[],c=[];let t=i.trim().replace(/\s+/g,`,`).split(`,`).filter(Boolean);for(let e of t)e[0]===`-`?c.push(e.slice(1)):s.push(e)}function u(){let e=[...s,...c.map(e=>`-${e}`)].join(`,`);return l(``),e}function d(e){for(let t of c)if(n(e,t))return!1;for(let t of s)if(n(e,t))return!0;return!1}const f=`#0000CC.#0000FF.#0033CC.#0033FF.#0066CC.#0066FF.#0099CC.#0099FF.#00CC00.#00CC33.#00CC66.#00CC99.#00CCCC.#00CCFF.#3300CC.#3300FF.#3333CC.#3333FF.#3366CC.#3366FF.#3399CC.#3399FF.#33CC00.#33CC33.#33CC66.#33CC99.#33CCCC.#33CCFF.#6600CC.#6600FF.#6633CC.#6633FF.#66CC00.#66CC33.#9900CC.#9900FF.#9933CC.#9933FF.#99CC00.#99CC33.#CC0000.#CC0033.#CC0066.#CC0099.#CC00CC.#CC00FF.#CC3300.#CC3333.#CC3366.#CC3399.#CC33CC.#CC33FF.#CC6600.#CC6633.#CC9900.#CC9933.#CCCC00.#CCCC33.#FF0000.#FF0033.#FF0066.#FF0099.#FF00CC.#FF00FF.#FF3300.#FF3333.#FF3366.#FF3399.#FF33CC.#FF33FF.#FF6600.#FF6633.#FF9900.#FF9933.#FFCC00.#FFCC33`.split(`.`);function p(e,t){let{useColors:n}=this;if(t[0]=`${(n?`%c`:``)+this.namespace+(n?` %c`:` `)+t[0]+(n?`%c `:` `)}+${this.humanize(e)}`,!n)return;let r=`color: ${this.color}`;t.splice(1,0,r,`color: inherit`);let i=0,a=0;t[0].replace(/%[a-z%]/gi,e=>{e!==`%%`&&(i++,e===`%c`&&(a=i))}),t.splice(a,0,r)}const m=console.debug||console.log||(()=>{}),h=v(),g={useColors:!0,formatArgs:p,formatters:{j(e){try{return JSON.stringify(e)}catch(e){return`[UnexpectedJSONParseError]: ${e.message}`}}},inspectOpts:{},humanize:r,log:m};function _(e,n){var r;let i=(r=n&&n.color)==null?t(f,e):r;return o(e,Object.assign(g,{color:i},n))}function v(){try{return localStorage}catch(e){}}function y(){let e;try{e=h.getItem(`debug`)||h.getItem(`DEBUG`)}catch(e){}return!e&&typeof process<`u`&&`env`in process&&(e=process.env.DEBUG),e||``}function b(e){try{e?h.setItem(`debug`,e):h.removeItem(`debug`)}catch(e){}}function x(e){b(e),l(e)}l(y());export{_ as createDebug,u as disable,x as enable,d as enabled,a as namespaces};
+47
View File
@@ -0,0 +1,47 @@
import { InspectOptions } from "node:util";
//#region src/types.d.ts
interface InspectOptions$1 extends InspectOptions {
hideDate?: boolean;
}
/**
* Map of special "%n" handling functions, for the debug "format" argument.
*
* Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
*/
interface Formatters {
[formatter: string]: (this: Debugger, v: any) => string;
}
interface Debugger extends Required<DebugOptions> {
(formatter: any, ...args: any[]): void;
namespace: string;
enabled: boolean;
extend: (namespace: string, delimiter?: string) => Debugger;
}
interface DebugOptions {
useColors?: boolean;
color?: string | number;
formatArgs?: (this: Debugger, diff: number, args: [string, ...any[]]) => void;
formatters?: Formatters;
/** Node.js only */
inspectOpts?: InspectOptions$1;
/** Humanize a duration in milliseconds */
humanize?: (value: number) => string;
log?: (this: Debugger, ...args: any[]) => void;
}
//#endregion
//#region src/core.d.ts
/**
* Returns a string of the currently enabled debug namespaces.
*/
declare function namespaces(): string;
/**
* Disable debug output.
*/
declare function disable(): string;
/**
* Returns true if the given mode name is enabled, false otherwise.
*/
declare function enabled(name: string): boolean;
//#endregion
export { Debugger as a, DebugOptions as i, enabled as n, Formatters as o, namespaces as r, InspectOptions$1 as s, disable as t };
+144
View File
@@ -0,0 +1,144 @@
//#region src/utils.ts
/**
* Coerce `value`.
*/
function coerce(value) {
if (value instanceof Error) return value.stack || value.message;
return value;
}
/**
* Selects a color for a debug namespace
* @return An ANSI color code for the given namespace
*/
function selectColor(colors, namespace) {
let hash = 0;
for (let i = 0; i < namespace.length; i++) {
hash = (hash << 5) - hash + namespace.charCodeAt(i);
hash |= 0;
}
return colors[Math.abs(hash) % colors.length];
}
/**
* Checks if the given string matches a namespace template, honoring
* asterisks as wildcards.
*/
function matchesTemplate(search, template) {
let searchIndex = 0;
let templateIndex = 0;
let starIndex = -1;
let matchIndex = 0;
while (searchIndex < search.length) if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === "*")) if (template[templateIndex] === "*") {
starIndex = templateIndex;
matchIndex = searchIndex;
templateIndex++;
} else {
searchIndex++;
templateIndex++;
}
else if (starIndex !== -1) {
templateIndex = starIndex + 1;
matchIndex++;
searchIndex = matchIndex;
} else return false;
while (templateIndex < template.length && template[templateIndex] === "*") templateIndex++;
return templateIndex === template.length;
}
function humanize(value) {
if (value >= 1e3) return `${(value / 1e3).toFixed(1)}s`;
return `${value}ms`;
}
//#endregion
//#region src/core.ts
let globalNamespaces = "";
/**
* Returns a string of the currently enabled debug namespaces.
*/
function namespaces() {
return globalNamespaces;
}
function createDebug(namespace, options) {
let prevTime;
let enableOverride;
let namespacesCache;
let enabledCache;
const debug = (...args) => {
if (!debug.enabled) return;
const curr = Date.now();
const diff = curr - (prevTime || curr);
prevTime = curr;
args[0] = coerce(args[0]);
if (typeof args[0] !== "string") args.unshift("%O");
let index = 0;
args[0] = args[0].replace(/%([a-z%])/gi, (match, format) => {
if (match === "%%") return "%";
index++;
const formatter = options.formatters[format];
if (typeof formatter === "function") {
const value = args[index];
match = formatter.call(debug, value);
args.splice(index, 1);
index--;
}
return match;
});
options.formatArgs.call(debug, diff, args);
debug.log(...args);
};
debug.extend = function(namespace, delimiter = ":") {
return createDebug(this.namespace + delimiter + namespace, {
useColors: this.useColors,
color: this.color,
formatArgs: this.formatArgs,
formatters: this.formatters,
inspectOpts: this.inspectOpts,
log: this.log,
humanize: this.humanize
});
};
Object.assign(debug, options);
debug.namespace = namespace;
Object.defineProperty(debug, "enabled", {
enumerable: true,
configurable: false,
get: () => {
if (enableOverride != null) return enableOverride;
if (namespacesCache !== globalNamespaces) {
namespacesCache = globalNamespaces;
enabledCache = enabled(namespace);
}
return enabledCache;
},
set: (v) => {
enableOverride = v;
}
});
return debug;
}
let names = [];
let skips = [];
function enable(namespaces) {
globalNamespaces = namespaces;
names = [];
skips = [];
const split = globalNamespaces.trim().replace(/\s+/g, ",").split(",").filter(Boolean);
for (const ns of split) if (ns[0] === "-") skips.push(ns.slice(1));
else names.push(ns);
}
/**
* Disable debug output.
*/
function disable() {
const namespaces = [...names, ...skips.map((namespace) => `-${namespace}`)].join(",");
enable("");
return namespaces;
}
/**
* Returns true if the given mode name is enabled, false otherwise.
*/
function enabled(name) {
for (const skip of skips) if (matchesTemplate(name, skip)) return false;
for (const ns of names) if (matchesTemplate(name, ns)) return true;
return false;
}
//#endregion
export { namespaces as a, enabled as i, disable as n, humanize as o, enable as r, selectColor as s, createDebug as t };
+11
View File
@@ -0,0 +1,11 @@
import { a as Debugger, i as DebugOptions, n as enabled, o as Formatters, r as namespaces, s as InspectOptions, t as disable } from "./core.js";
//#region src/node.d.ts
declare function createDebug(namespace: string, options?: DebugOptions): Debugger;
/**
* Enables a debug mode by namespaces. This can include modes
* separated by a colon and wildcards.
*/
declare function enable(namespaces: string): void;
//#endregion
export { type DebugOptions, type Debugger, type Formatters, type InspectOptions, createDebug, disable, enable, enabled, namespaces };
+169
View File
@@ -0,0 +1,169 @@
import { a as namespaces, i as enabled, n as disable, o as humanize, r as enable$1, s as selectColor, t as createDebug$1 } from "./core.js";
import { isatty } from "node:tty";
import { formatWithOptions, inspect } from "node:util";
//#region src/node.ts
const colors = process.stderr.getColorDepth && process.stderr.getColorDepth() > 2 ? [
20,
21,
26,
27,
32,
33,
38,
39,
40,
41,
42,
43,
44,
45,
56,
57,
62,
63,
68,
69,
74,
75,
76,
77,
78,
79,
80,
81,
92,
93,
98,
99,
112,
113,
128,
129,
134,
135,
148,
149,
160,
161,
162,
163,
164,
165,
166,
167,
168,
169,
170,
171,
172,
173,
178,
179,
184,
185,
196,
197,
198,
199,
200,
201,
202,
203,
204,
205,
206,
207,
208,
209,
214,
215,
220,
221
] : [
6,
2,
3,
4,
5,
1
];
const inspectOpts = Object.keys(process.env).filter((key) => /^debug_/i.test(key)).reduce((obj, key) => {
const prop = key.slice(6).toLowerCase().replace(/_([a-z])/g, (_, k) => k.toUpperCase());
let value = process.env[key];
const lowerCase = typeof value === "string" && value.toLowerCase();
if (value === "null") value = null;
else if (lowerCase === "yes" || lowerCase === "on" || lowerCase === "true" || lowerCase === "enabled") value = true;
else if (lowerCase === "no" || lowerCase === "off" || lowerCase === "false" || lowerCase === "disabled") value = false;
else value = Number(value);
obj[prop] = value;
return obj;
}, Object.create(null));
/**
* Is stdout a TTY? Colored output is enabled when `true`.
*/
function useColors() {
return "colors" in inspectOpts ? Boolean(inspectOpts.colors) : isatty(process.stderr.fd);
}
function getDate() {
if (inspectOpts.hideDate) return "";
return `${(/* @__PURE__ */ new Date()).toISOString()} `;
}
/**
* Adds ANSI color escape codes if enabled.
*/
function formatArgs(diff, args) {
const { namespace: name, useColors } = this;
if (useColors) {
const c = this.color;
const colorCode = `\u001B[3${c < 8 ? c : `8;5;${c}`}`;
const prefix = ` ${colorCode};1m${name} \u001B[0m`;
args[0] = prefix + args[0].split("\n").join(`\n${prefix}`);
args.push(`${colorCode}m+${this.humanize(diff)}\u001B[0m`);
} else args[0] = `${getDate()}${name} ${args[0]}`;
}
function log(...args) {
process.stderr.write(`${formatWithOptions(this.inspectOpts, ...args)}\n`);
}
const defaultOptions = {
useColors: useColors(),
formatArgs,
formatters: {
/**
* Map %o to `util.inspect()`, all on a single line.
*/
o(v) {
this.inspectOpts.colors = this.useColors;
return inspect(v, this.inspectOpts).split("\n").map((str) => str.trim()).join(" ");
},
/**
* Map %O to `util.inspect()`, allowing multiple lines if needed.
*/
O(v) {
this.inspectOpts.colors = this.useColors;
return inspect(v, this.inspectOpts);
}
},
inspectOpts,
log,
humanize
};
function createDebug(namespace, options) {
var _ref;
const color = (_ref = options && options.color) !== null && _ref !== void 0 ? _ref : selectColor(colors, namespace);
return createDebug$1(namespace, Object.assign(defaultOptions, { color }, options));
}
function save(namespaces) {
if (namespaces) process.env.DEBUG = namespaces;
else delete process.env.DEBUG;
}
/**
* Enables a debug mode by namespaces. This can include modes
* separated by a colon and wildcards.
*/
function enable(namespaces) {
save(namespaces);
enable$1(namespaces);
}
enable$1(process.env.DEBUG || "");
//#endregion
export { createDebug, disable, enable, enabled, namespaces };
+72
View File
@@ -0,0 +1,72 @@
{
"name": "obug",
"type": "module",
"version": "2.1.2",
"description": "A lightweight JavaScript debugging utility, forked from debug, featuring TypeScript and ESM support.",
"author": "Kevin Deng <sxzz@sxzz.moe>",
"license": "MIT",
"funding": [
"https://github.com/sponsors/sxzz",
"https://opencollective.com/debug"
],
"homepage": "https://github.com/sxzz/obug#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/sxzz/obug.git"
},
"bugs": {
"url": "https://github.com/sxzz/obug/issues"
},
"exports": {
".": {
"browser": "./dist/browser.js",
"default": "./dist/node.js"
},
"./package.json": "./package.json"
},
"main": "./dist/node.js",
"module": "./dist/node.js",
"unpkg": "./dist/browser.min.js",
"jsdelivr": "./dist/browser.min.js",
"types": "./dist/browser.d.ts",
"files": [
"dist"
],
"publishConfig": {
"access": "public"
},
"engines": {
"node": ">=12.20.0"
},
"devDependencies": {
"@sxzz/eslint-config": "^8.1.0",
"@sxzz/prettier-config": "^2.3.1",
"@types/debug": "^4.1.13",
"@types/node": "^25.9.1",
"@typescript/native-preview": "7.0.0-dev.20260603.1",
"@vitest/browser-playwright": "^4.1.8",
"@vitest/coverage-v8": "^4.1.8",
"bumpp": "^11.1.0",
"debug": "^4.4.3",
"eslint": "^10.4.1",
"playwright": "^1.60.0",
"prettier": "^3.8.3",
"tsdown": "^0.22.1",
"typescript": "^6.0.3",
"vite": "^8.0.16",
"vitest": "^4.1.8"
},
"prettier": "@sxzz/prettier-config",
"scripts": {
"lint": "eslint --cache .",
"lint:fix": "pnpm run lint --fix",
"build": "tsdown",
"dev": "tsdown --watch",
"test": "vitest",
"test:coverage": "vitest --project node --coverage",
"play": "vite playground",
"typecheck": "tsgo --noEmit",
"format": "prettier --cache --write .",
"release": "bumpp"
}
}