@@ -1,1 +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`}function i(r,i,a,o,s,c,l){let u=n=>{let o,s,c,d,f=(...t)=>{if(!f.enabled)return;let n=Date.now();f.diff=n-(o||n),f.prev=o,f.curr=n,o=n,t[0]=e(t[0]),typeof t[0]!=`string`&&t.unshift(`%O`);let r=0;t[0]=t[0].replace(/%([a-z%])/gi,(e,n)=>{if(e===`%%`)return`%`;r++;let i=u.formatters[n];if(typeof i==`function`){let n=t[r];e=i.call(f,n),t.splice(r,1),r--}return e}),u.formatArgs.call(f,t),(f.log||u.log).apply(f,t)};function p(e,t=`:`){let n=u(this.namespace+t+e);return n.log=this.log,n}return f.namespace=n,f.useColors=r,f.color=t(i,n),f.extend=p,f.log=a,Object.defineProperty(f,`enabled`,{enumerable:!0,configurable:!1,get:()=>s==null?(c!==u.namespaces&&(c=u.namespaces,d=u.enabled(n)),d):s,set:e=>{s=e}}),l&&l(f),f};function d(e){s(e),u.namespaces=e,u.names=[],u.skips=[];let t=e.trim().replace(/\s+/g,`,`).split(`,`).filter(Boolean);for(let e of t)e[0]===`-`?u.skips.push(e.slice(1)):u.names.push(e)}function f(){let e=[...u.names,...u.skips.map(e=>`-${e}`)].join(`,`);return u.enable(``),e}function p(e){for(let t of u.skips)if(n(e,t))return!1;for(let t of u.names)if(n(e,t))return!0;return!1}return u.namespaces=``,u.names=[],u.skips=[],u.enable=d,u.disable=f,u.enabled=p,u.selectColor=e=>t(i,e),u.formatArgs=c,u.log=a,u.formatters={},u.enable(o()),u}const a=`#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 o(){return!0}function s(e){let{useColors:t}=this;if(e[0]=`${(t?`%c`:``)+this.namespace+(t?` %c`:` `)+e[0]+(t?`%c `:` `)}+${r(this.diff)}`,!t)return;let n=`color: ${this.color}`;e.splice(1,0,n,`color: inherit`);let i=0,a=0;e[0].replace(/%[a-z%]/gi,e=>{e!==`%%`&&(i++,e===`%c`&&(a=i))}),e.splice(a,0,n)}const c=console.debug||console.log||(()=>{});function l(){try{return localStorage}catch(e){}}const u=l();function d(e){try{e?u.setItem(`debug`,e):u.removeItem(`debug`)}catch(e){}}function f(){let e;try{e=u.getItem(`debug`)||u.getItem(`DEBUG`)}catch(e){}return!e&&typeof process<`u`&&`env`in process&&(e=process.env.DEBUG),e||``}const p=i(o(),a,c,f,d,s);p.formatters.j=function(e){try{return JSON.stringify(e)}catch(e){return`[UnexpectedJSONParseError]: ${e.message}`}};var m=p;p.default=p,p.debug=p;export{p as createDebug,p as "module.exports",m as default,s as formatArgs,c as log}; | ||
| 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`}function i(r,i,a,o,s,c,l){let u=n=>{let o,s,c,d,f=(...t)=>{if(!f.enabled)return;let n=Date.now();f.diff=n-(o||n),f.prev=o,f.curr=n,o=n,t[0]=e(t[0]),typeof t[0]!=`string`&&t.unshift(`%O`);let r=0;t[0]=t[0].replace(/%([a-z%])/gi,(e,n)=>{if(e===`%%`)return`%`;r++;let i=u.formatters[n];if(typeof i==`function`){let n=t[r];e=i.call(f,n),t.splice(r,1),r--}return e}),u.formatArgs.call(f,t),(f.log||u.log).apply(f,t)};function p(e,t=`:`){let n=u(this.namespace+t+e);return n.log=this.log,n}return f.namespace=n,f.useColors=r,f.color=t(i,n),f.extend=p,f.log=a,Object.defineProperty(f,`enabled`,{enumerable:!0,configurable:!1,get:()=>s==null?(c!==u.namespaces&&(c=u.namespaces,d=u.enabled(n)),d):s,set:e=>{s=e}}),l&&l(f),f};function d(e){s(e),u.namespaces=e,u.names=[],u.skips=[];let t=e.trim().replace(/\s+/g,`,`).split(`,`).filter(Boolean);for(let e of t)e[0]===`-`?u.skips.push(e.slice(1)):u.names.push(e)}function f(){let e=[...u.names,...u.skips.map(e=>`-${e}`)].join(`,`);return u.enable(``),e}function p(e){for(let t of u.skips)if(n(e,t))return!1;for(let t of u.names)if(n(e,t))return!0;return!1}return u.namespaces=``,u.formatters={},u.enable=d,u.disable=f,u.enabled=p,u.names=[],u.skips=[],u.selectColor=e=>t(i,e),u.formatArgs=c,u.log=a,u.enable(o()),u}const a=`#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 o(){return!0}function s(e){let{useColors:t}=this;if(e[0]=`${(t?`%c`:``)+this.namespace+(t?` %c`:` `)+e[0]+(t?`%c `:` `)}+${r(this.diff)}`,!t)return;let n=`color: ${this.color}`;e.splice(1,0,n,`color: inherit`);let i=0,a=0;e[0].replace(/%[a-z%]/gi,e=>{e!==`%%`&&(i++,e===`%c`&&(a=i))}),e.splice(a,0,n)}const c=console.debug||console.log||(()=>{});function l(){try{return localStorage}catch(e){}}const u=l();function d(e){try{e?u.setItem(`debug`,e):u.removeItem(`debug`)}catch(e){}}function f(){let e;try{e=u.getItem(`debug`)||u.getItem(`DEBUG`)}catch(e){}return!e&&typeof process<`u`&&`env`in process&&(e=process.env.DEBUG),e||``}const p=i(o(),a,c,f,d,s);p.formatters.j=function(e){try{return JSON.stringify(e)}catch(e){return`[UnexpectedJSONParseError]: ${e.message}`}};var m=p;p.default=p,p.debug=p;export{p as createDebug,p as "module.exports",m as default,s as formatArgs,c as log}; |
+3
-3
@@ -117,11 +117,11 @@ function coerce(value) { | ||
| createDebug.namespaces = ""; | ||
| createDebug.names = []; | ||
| createDebug.skips = []; | ||
| createDebug.formatters = {}; | ||
| createDebug.enable = enable; | ||
| createDebug.disable = disable; | ||
| createDebug.enabled = enabled; | ||
| createDebug.names = []; | ||
| createDebug.skips = []; | ||
| createDebug.selectColor = (ns) => selectColor(colors, ns); | ||
| createDebug.formatArgs = formatArgs; | ||
| createDebug.log = log; | ||
| createDebug.formatters = {}; | ||
| createDebug.enable(load()); | ||
@@ -128,0 +128,0 @@ return createDebug; |
+32
-6
@@ -16,7 +16,16 @@ import { InspectOptions } from "node:util"; | ||
| extend: (namespace: string, delimiter?: string) => Debugger; | ||
| /** @private */ | ||
| /** | ||
| * @internal | ||
| * @deprecated It will removed in the next major version. This is internal cache. | ||
| */ | ||
| diff?: number; | ||
| /** @private */ | ||
| /** | ||
| * @internal | ||
| * @deprecated It will removed in the next major version. This is internal cache. | ||
| */ | ||
| prev?: number; | ||
| /** @private */ | ||
| /** | ||
| * @internal | ||
| * @deprecated It will removed in the next major version. This is internal cache. | ||
| */ | ||
| curr?: number; | ||
@@ -43,11 +52,28 @@ } | ||
| enabled: (namespaces: string) => boolean; | ||
| formatters: Formatters; | ||
| inspectOpts?: InspectOptions$1; | ||
| /** | ||
| * @deprecated It will removed in the next major version. | ||
| */ | ||
| formatArgs: (this: Debugger, args: [string, ...any[]]) => void; | ||
| /** | ||
| * @deprecated It will removed in the next major version. | ||
| */ | ||
| selectColor: (namespace: string) => string | number; | ||
| /** | ||
| * @deprecated It will removed in the next major version. | ||
| */ | ||
| log: (...args: any[]) => void; | ||
| selectColor: (namespace: string) => string | number; | ||
| /** | ||
| * @internal | ||
| * @deprecated It will removed in the next major version. This is internal cache. | ||
| */ | ||
| names: string[]; | ||
| /** | ||
| * @internal | ||
| * @deprecated It will removed in the next major version. This is internal cache. | ||
| */ | ||
| skips: string[]; | ||
| formatters: Formatters; | ||
| inspectOpts?: InspectOptions$1; | ||
| } | ||
| //#endregion | ||
| export { InspectOptions$1 as i, Debugger as n, Formatters as r, Debug as t }; |
+1
-1
| { | ||
| "name": "obug", | ||
| "version": "0.1.3", | ||
| "version": "1.0.0", | ||
| "description": "A lightweight JavaScript debugging utility, forked from debug, featuring TypeScript and ESM support.", | ||
@@ -5,0 +5,0 @@ "type": "module", |
+51
-0
@@ -9,2 +9,7 @@ # obug | ||
| > [!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. | ||
| > | ||
| > The upcoming 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` | ||
@@ -30,2 +35,48 @@ | ||
| ## Refactor Plan | ||
| The obug package is currently a direct fork of the debug package with minimal modifications. The following refactor plan outlines the intended changes to be made in future releases. | ||
| ```ts | ||
| import { createDebug, disable, enable, enabled, namespaces } from 'obug' | ||
| // Get the currently enabled namespaces | ||
| console.log(namespaces()) | ||
| // createDebug has no extra properties or methods. | ||
| const debug = createDebug('my-namespace', { | ||
| // All options are optional | ||
| useColors: true, // false, true, 'auto' | ||
| 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' | ||
| ``` | ||
| For more details, please refer to the [src/types-v2.ts](./src/types-v2.ts). | ||
| ## Original Authors | ||
@@ -32,0 +83,0 @@ |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
22506
11.59%513
5.34%1
-50%113
82.26%