@gjsify/util 0.4.20 → 0.4.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/esm/compat.js +1 -0
- package/lib/esm/format.js +1 -0
- package/lib/esm/index.js +1 -4
- package/lib/esm/inspect.js +4 -0
- package/lib/esm/legacy-predicates.js +1 -0
- package/lib/types/compat.d.ts +26 -0
- package/lib/types/format.d.ts +18 -0
- package/lib/types/index.d.ts +8 -74
- package/lib/types/inspect.d.ts +18 -0
- package/lib/types/legacy-predicates.d.ts +15 -0
- package/package.json +4 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";const e=Symbol.for(`nodejs.util.promisify.custom`);function promisify(t){if(typeof t!=`function`)throw TypeError(`The "original" argument must be of type Function`);let n=t[e];if(typeof n==`function`)return n;function promisified(...e){return new Promise((n,r)=>{t.call(this,...e,(e,...t)=>{e?r(e):t.length<=1?n(t[0]):n(t)})})}return Object.setPrototypeOf(promisified,Object.getPrototypeOf(t)),Object.defineProperty(promisified,e,{value:promisified}),promisified}promisify.custom=e;function callbackify(e){if(typeof e!=`function`)throw TypeError(`The "original" argument must be of type Function`);return function(...t){let n=t.pop();if(typeof n!=`function`)throw TypeError(`The last argument must be of type Function`);e.apply(this,t).then(e=>Promise.resolve().then(()=>n(null,e)),e=>Promise.resolve().then(()=>n(e||Error())))}}function deprecate(e,t,n){let r=!1;function deprecated(...i){if(!r){r=!0;let e=n?`[${n}] ${t}`:t;console.warn(`DeprecationWarning: ${e}`)}return e.apply(this,i)}return Object.setPrototypeOf(deprecated,e),deprecated}function debuglog(e){let debug;return(...t)=>{if(debug===void 0){let t=typeof globalThis.process?.env?.NODE_DEBUG==`string`?globalThis.process.env.NODE_DEBUG:``;if(RegExp(`\\b${e}\\b`,`i`).test(t)){let t=typeof globalThis.process?.pid==`number`?globalThis.process.pid:0;debug=(...n)=>{console.error(`${e.toUpperCase()} ${t}:`,...n)}}else debug=()=>{}}debug(...t)}}function inherits(e,t){if(e==null){let t=TypeError(`The "ctor" argument must be of type Function. Received `+String(e));throw t.code=`ERR_INVALID_ARG_TYPE`,t}if(t==null){let e=TypeError(`The "superCtor" argument must be of type Function. Received `+String(t));throw e.code=`ERR_INVALID_ARG_TYPE`,e}if(t.prototype===void 0){let e=TypeError(`The "superCtor.prototype" property must not be undefined`);throw e.code=`ERR_INVALID_ARG_TYPE`,e}Object.defineProperty(e,"super_",{value:t,writable:!0,configurable:!0}),Object.setPrototypeOf(e.prototype,t.prototype)}function isDeepStrictEqual(e,t){if(Object.is(e,t))return!0;if(typeof e!=typeof t||e===null||t===null||typeof e!=`object`)return!1;let n=e,r=t;if(Array.isArray(n)&&Array.isArray(r)){if(n.length!==r.length)return!1;for(let e=0;e<n.length;e++)if(!isDeepStrictEqual(n[e],r[e]))return!1;return!0}if(Array.isArray(n)!==Array.isArray(r))return!1;if(n instanceof Date&&r instanceof Date)return n.getTime()===r.getTime();if(n instanceof RegExp&&r instanceof RegExp)return n.source===r.source&&n.flags===r.flags;let i=Object.keys(n),a=Object.keys(r);if(i.length!==a.length)return!1;for(let e of i)if(!Object.prototype.hasOwnProperty.call(r,e)||!isDeepStrictEqual(n[e],r[e]))return!1;return!0}function toUSVString(e){return typeof e.toWellFormed==`function`?e.toWellFormed():e.replace(/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g,`�`)}function aborted(e,t){return e==null||typeof e.aborted!=`boolean`?Promise.reject(TypeError(`The "signal" argument must be an instance of AbortSignal`)):typeof t!=`object`||!t?Promise.reject(TypeError(`The "resource" argument must be an non-null object`)):e.aborted?Promise.resolve():new Promise(t=>{let onAbort=()=>{e.removeEventListener(`abort`,onAbort),t()};e.addEventListener(`abort`,onAbort,{once:!0})})}export{aborted,callbackify,debuglog,deprecate,inherits,isDeepStrictEqual,promisify,toUSVString};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{inspect as e}from"./inspect.js";function format(t,...n){if(t===void 0&&n.length===0)return``;if(typeof t!=`string`){if(n.length===0)return e(t);let r=[e(t)];for(let t of n)r.push(e(t));return r.join(` `)}let r=0,i=``,a=0;for(let o=0;o<t.length-1;o++){if(t[o]!==`%`)continue;o>a&&(i+=t.slice(a,o));let s=t[o+1];if(s===`%`){i+=`%`,a=o+2,o++;continue}if(r>=n.length){i+=`%`+s,a=o+2,o++;continue}let c=n[r];switch(s){case`s`:if(typeof c==`bigint`)i+=`${c}n`;else if(typeof c==`symbol`)i+=c.toString();else if(typeof c==`number`&&Object.is(c,-0))i+=`-0`;else if(typeof c==`object`&&c)if(Object.getPrototypeOf(c)===null||typeof c.toString==`function`&&c.toString!==Object.prototype.toString&&c.toString!==Array.prototype.toString)try{let t=c.toString();typeof t==`string`&&t!==`[object Object]`?i+=t:i+=e(c,{depth:0})}catch{i+=e(c,{depth:0})}else i+=e(c,{depth:0});else i+=String(c);r++;break;case`d`:if(typeof c==`bigint`)i+=`${c}n`;else if(typeof c==`symbol`)i+=`NaN`;else{let e=Number(c);i+=Object.is(e,-0)?`-0`:String(e)}r++;break;case`i`:if(typeof c==`bigint`)i+=`${c}n`;else if(typeof c==`symbol`)i+=`NaN`;else{let e=Number(c);if(!isFinite(e))i+=`NaN`;else{let t=Math.trunc(e);i+=Object.is(t,-0)?`-0`:String(t)}}r++;break;case`f`:if(typeof c==`bigint`)i+=Number(c).toString();else if(typeof c==`symbol`)i+=`NaN`;else{let e=parseFloat(String(c));i+=Object.is(e,-0)?`-0`:String(e)}r++;break;case`j`:try{i+=JSON.stringify(n[r++])}catch{i+=`[Circular]`}break;case`o`:i+=e(n[r++],{showHidden:!0,depth:4});break;case`O`:i+=e(n[r++],{depth:4});break;default:i+=`%`+s;break}a=o+2,o++}for(a<t.length&&(i+=t.slice(a));r<n.length;r++){let t=n[r];typeof t==`string`?i+=` `+t:i+=` `+e(t)}return i}function formatWithOptions(e,t,...n){return format(t,...n)}const t=RegExp(`[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/\\#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/\\#&.:=?%@~_]*)*)?(?:\\u0007|\\u001B\\u005C|\\u009C))|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))`,`g`);function stripVTControlCharacters(e){if(typeof e!=`string`)throw TypeError(`The "str" argument must be of type string. Received `+typeof e);return e.indexOf(`\x1B`)===-1&&e.indexOf(``)===-1?e:e.replace(t,``)}function styleText(t,n,r){if(typeof n!=`string`)throw TypeError(`The "text" argument must be of type string. Received `+typeof n);if((r?.validateStream??!0)&&!(r?.stream??globalThis.process?.stdout)?.isTTY)return n;let i=Array.isArray(t)?t:[t],a=``,o=``;for(let t of i){if(t===`none`)continue;let n=e.colors[t];if(n===void 0)throw TypeError(`The "format" argument must be one of: ${Object.keys(e.colors).join(`, `)}. Received '${t}'`);a+=`\x1b[${n[0]}m`,o=`\x1b[${n[1]}m`+o}return`${a}${n}${o}`}export{format,formatWithOptions,stripVTControlCharacters,styleText};
|
package/lib/esm/index.js
CHANGED
|
@@ -1,4 +1 @@
|
|
|
1
|
-
import"./
|
|
2
|
-
`)}\n]`}}let c=`[ ${a.join(`, `)} ]`;return c.length<=o?c:`[\n${a.map(e=>` `+e).join(`,
|
|
3
|
-
`)}\n]`}function inspectObject(e,t,n){let r=t.showHidden?Object.getOwnPropertyNames(e):Object.keys(e);if(t.sorted&&r.sort(),r.length===0){let t=Object.prototype.toString.call(e);return t===`[object Object]`?`{}`:t}let i=r.map(r=>`${r}: ${inspectValue(e[r],t,n+1)}`),a=t.breakLength??72,o=`{ ${i.join(`, `)} }`;return o.length<=a?o:`{\n${i.map(e=>` `+e).join(`,
|
|
4
|
-
`)}\n}`}function inspect(e,t){let n=typeof t==`boolean`?{showHidden:t}:{...t};return n.colors===void 0&&(n.colors=!1),inspectValue(e,n,0)}inspect.custom=r,inspect.defaultOptions={showHidden:!1,depth:2,colors:!1,maxArrayLength:100,maxStringLength:1e4,breakLength:72,compact:3,sorted:!1},inspect.colors={reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],blink:[5,25],inverse:[7,27],hidden:[8,28],strikethrough:[9,29],doubleunderline:[21,24],black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],framed:[51,54],overlined:[53,55],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39],bgBlackBright:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]},inspect.styles={special:`cyan`,number:`yellow`,bigint:`yellow`,boolean:`yellow`,undefined:`grey`,null:`bold`,string:`green`,symbol:`green`,date:`magenta`,regexp:`red`,module:`underline`};function format(e,...t){if(e===void 0&&t.length===0)return``;if(typeof e!=`string`){if(t.length===0)return inspect(e);let n=[inspect(e)];for(let e of t)n.push(inspect(e));return n.join(` `)}let n=0,r=``,i=0;for(let a=0;a<e.length-1;a++){if(e[a]!==`%`)continue;a>i&&(r+=e.slice(i,a));let o=e[a+1];if(o===`%`){r+=`%`,i=a+2,a++;continue}if(n>=t.length){r+=`%`+o,i=a+2,a++;continue}let s=t[n];switch(o){case`s`:if(typeof s==`bigint`)r+=`${s}n`;else if(typeof s==`symbol`)r+=s.toString();else if(typeof s==`number`&&Object.is(s,-0))r+=`-0`;else if(typeof s==`object`&&s)if(Object.getPrototypeOf(s)===null||typeof s.toString==`function`&&s.toString!==Object.prototype.toString&&s.toString!==Array.prototype.toString)try{let e=s.toString();typeof e==`string`&&e!==`[object Object]`?r+=e:r+=inspect(s,{depth:0})}catch{r+=inspect(s,{depth:0})}else r+=inspect(s,{depth:0});else r+=String(s);n++;break;case`d`:if(typeof s==`bigint`)r+=`${s}n`;else if(typeof s==`symbol`)r+=`NaN`;else{let e=Number(s);r+=Object.is(e,-0)?`-0`:String(e)}n++;break;case`i`:if(typeof s==`bigint`)r+=`${s}n`;else if(typeof s==`symbol`)r+=`NaN`;else{let e=Number(s);if(!isFinite(e))r+=`NaN`;else{let t=Math.trunc(e);r+=Object.is(t,-0)?`-0`:String(t)}}n++;break;case`f`:if(typeof s==`bigint`)r+=Number(s).toString();else if(typeof s==`symbol`)r+=`NaN`;else{let e=parseFloat(String(s));r+=Object.is(e,-0)?`-0`:String(e)}n++;break;case`j`:try{r+=JSON.stringify(t[n++])}catch{r+=`[Circular]`}break;case`o`:r+=inspect(t[n++],{showHidden:!0,depth:4});break;case`O`:r+=inspect(t[n++],{depth:4});break;default:r+=`%`+o;break}i=a+2,a++}for(i<e.length&&(r+=e.slice(i));n<t.length;n++){let e=t[n];typeof e==`string`?r+=` `+e:r+=` `+inspect(e)}return r}function formatWithOptions(e,t,...n){return format(t,...n)}const i=RegExp(`[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/\\#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/\\#&.:=?%@~_]*)*)?(?:\\u0007|\\u001B\\u005C|\\u009C))|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))`,`g`);function stripVTControlCharacters(e){if(typeof e!=`string`)throw TypeError(`The "str" argument must be of type string. Received `+typeof e);return e.indexOf(`\x1B`)===-1&&e.indexOf(``)===-1?e:e.replace(i,``)}function styleText(e,t,n){if(typeof t!=`string`)throw TypeError(`The "text" argument must be of type string. Received `+typeof t);if((n?.validateStream??!0)&&!(n?.stream??globalThis.process?.stdout)?.isTTY)return t;let r=Array.isArray(e)?e:[e],i=``,a=``;for(let e of r){if(e===`none`)continue;let t=inspect.colors[e];if(t===void 0)throw TypeError(`The "format" argument must be one of: ${Object.keys(inspect.colors).join(`, `)}. Received '${e}'`);i+=`[${t[0]}m`,a=`[${t[1]}m`+a}return`${i}${t}${a}`}const a=Symbol.for(`nodejs.util.promisify.custom`);function promisify(e){if(typeof e!=`function`)throw TypeError(`The "original" argument must be of type Function`);let t=e[a];if(typeof t==`function`)return t;function promisified(...t){return new Promise((n,r)=>{e.call(this,...t,(e,...t)=>{e?r(e):t.length<=1?n(t[0]):n(t)})})}return Object.setPrototypeOf(promisified,Object.getPrototypeOf(e)),Object.defineProperty(promisified,a,{value:promisified}),promisified}promisify.custom=a;function callbackify(e){if(typeof e!=`function`)throw TypeError(`The "original" argument must be of type Function`);return function(...t){let n=t.pop();if(typeof n!=`function`)throw TypeError(`The last argument must be of type Function`);e.apply(this,t).then(e=>Promise.resolve().then(()=>n(null,e)),e=>Promise.resolve().then(()=>n(e||Error())))}}function deprecate(e,t,n){let r=!1;function deprecated(...i){if(!r){r=!0;let e=n?`[${n}] ${t}`:t;console.warn(`DeprecationWarning: ${e}`)}return e.apply(this,i)}return Object.setPrototypeOf(deprecated,e),deprecated}function debuglog(e){let debug;return(...t)=>{if(debug===void 0){let t=typeof globalThis.process?.env?.NODE_DEBUG==`string`?globalThis.process.env.NODE_DEBUG:``;if(RegExp(`\\b${e}\\b`,`i`).test(t)){let t=typeof globalThis.process?.pid==`number`?globalThis.process.pid:0;debug=(...n)=>{console.error(`${e.toUpperCase()} ${t}:`,...n)}}else debug=()=>{}}debug(...t)}}function inherits(e,t){if(e==null){let t=TypeError(`The "ctor" argument must be of type Function. Received `+String(e));throw t.code=`ERR_INVALID_ARG_TYPE`,t}if(t==null){let e=TypeError(`The "superCtor" argument must be of type Function. Received `+String(t));throw e.code=`ERR_INVALID_ARG_TYPE`,e}if(t.prototype===void 0){let e=TypeError(`The "superCtor.prototype" property must not be undefined`);throw e.code=`ERR_INVALID_ARG_TYPE`,e}Object.defineProperty(e,`super_`,{value:t,writable:!0,configurable:!0}),Object.setPrototypeOf(e.prototype,t.prototype)}function isBoolean(e){return typeof e==`boolean`}function isNull(e){return e===null}function isNullOrUndefined(e){return e==null}function isNumber(e){return typeof e==`number`}function isString(e){return typeof e==`string`}function isSymbol(e){return typeof e==`symbol`}function isUndefined(e){return e===void 0}function isObject(e){return typeof e==`object`&&!!e}function isError(e){return e instanceof Error}function isFunction(e){return typeof e==`function`}function isRegExp(e){return e instanceof RegExp}function isArray(e){return Array.isArray(e)}function isPrimitive(e){return e===null||typeof e!=`object`&&typeof e!=`function`}function isDate(e){return e instanceof Date}function isBuffer(e){return e instanceof Uint8Array&&e.constructor?.name===`Buffer`}const o=globalThis.TextDecoder,s=globalThis.TextEncoder;function isDeepStrictEqual(e,t){if(Object.is(e,t))return!0;if(typeof e!=typeof t||e===null||t===null||typeof e!=`object`)return!1;let n=e,r=t;if(Array.isArray(n)&&Array.isArray(r)){if(n.length!==r.length)return!1;for(let e=0;e<n.length;e++)if(!isDeepStrictEqual(n[e],r[e]))return!1;return!0}if(Array.isArray(n)!==Array.isArray(r))return!1;if(n instanceof Date&&r instanceof Date)return n.getTime()===r.getTime();if(n instanceof RegExp&&r instanceof RegExp)return n.source===r.source&&n.flags===r.flags;let i=Object.keys(n),a=Object.keys(r);if(i.length!==a.length)return!1;for(let e of i)if(!Object.prototype.hasOwnProperty.call(r,e)||!isDeepStrictEqual(n[e],r[e]))return!1;return!0}function toUSVString(e){return typeof e.toWellFormed==`function`?e.toWellFormed():e.replace(/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g,`�`)}function aborted(e,t){return e==null||typeof e.aborted!=`boolean`?Promise.reject(TypeError(`The "signal" argument must be an instance of AbortSignal`)):typeof t!=`object`||!t?Promise.reject(TypeError(`The "resource" argument must be an non-null object`)):e.aborted?Promise.resolve():new Promise(t=>{let onAbort=()=>{e.removeEventListener(`abort`,onAbort),t()};e.addEventListener(`abort`,onAbort,{once:!0})})}var c={format,formatWithOptions,styleText,stripVTControlCharacters,inspect,promisify,callbackify,deprecate,debuglog,inherits,types:n,isBoolean,isNull,isNullOrUndefined,isNumber,isString,isSymbol,isUndefined,isObject,isError,isFunction,isRegExp,isArray,isPrimitive,isDate,isBuffer,isDeepStrictEqual,toUSVString,aborted,TextDecoder:globalThis.TextDecoder,TextEncoder:globalThis.TextEncoder,getSystemErrorName:t,getSystemErrorMap:e};export{o as TextDecoder,s as TextEncoder,aborted,callbackify,debuglog,c as default,deprecate,format,formatWithOptions,e as getSystemErrorMap,t as getSystemErrorName,inherits,inspect,isArray,isBoolean,isBuffer,isDate,isDeepStrictEqual,isError,isFunction,isNull,isNullOrUndefined,isNumber,isObject,isPrimitive,isRegExp,isString,isSymbol,isUndefined,promisify,stripVTControlCharacters,styleText,toUSVString,n as types};
|
|
1
|
+
import{aborted as e,callbackify as t,debuglog as n,deprecate as r,inherits as i,isDeepStrictEqual as a,promisify as o,toUSVString as s}from"./compat.js";import{getSystemErrorMap as c,getSystemErrorName as l}from"./errors.js";import{inspect as u,kCustomInspect as d}from"./inspect.js";import{format as f,formatWithOptions as p,stripVTControlCharacters as m,styleText as h}from"./format.js";import{types_exports as g}from"./types.js";import{isArray as _,isBoolean as v,isBuffer as y,isDate as b,isError as x,isFunction as S,isNull as C,isNullOrUndefined as w,isNumber as T,isObject as E,isPrimitive as D,isRegExp as O,isString as k,isSymbol as A,isUndefined as j}from"./legacy-predicates.js";const M=globalThis.TextDecoder,N=globalThis.TextEncoder;var P={format:f,formatWithOptions:p,styleText:h,stripVTControlCharacters:m,inspect:u,promisify:o,callbackify:t,deprecate:r,debuglog:n,inherits:i,types:g,isBoolean:v,isNull:C,isNullOrUndefined:w,isNumber:T,isString:k,isSymbol:A,isUndefined:j,isObject:E,isError:x,isFunction:S,isRegExp:O,isArray:_,isPrimitive:D,isDate:b,isBuffer:y,isDeepStrictEqual:a,toUSVString:s,aborted:e,TextDecoder:globalThis.TextDecoder,TextEncoder:globalThis.TextEncoder,getSystemErrorName:l,getSystemErrorMap:c};export{M as TextDecoder,N as TextEncoder,e as aborted,t as callbackify,n as debuglog,P as default,r as deprecate,f as format,p as formatWithOptions,c as getSystemErrorMap,l as getSystemErrorName,i as inherits,u as inspect,_ as isArray,v as isBoolean,y as isBuffer,b as isDate,a as isDeepStrictEqual,x as isError,S as isFunction,C as isNull,w as isNullOrUndefined,T as isNumber,E as isObject,D as isPrimitive,O as isRegExp,k as isString,A as isSymbol,j as isUndefined,d as kCustomInspect,o as promisify,m as stripVTControlCharacters,h as styleText,s as toUSVString,g as types};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";const e=Symbol.for(`nodejs.util.inspect.custom`);function inspectValue(t,n,r){if(t===null)return n.colors?`\x1B[1mnull\x1B[22m`:`null`;if(t===void 0)return n.colors?`\x1B[90mundefined\x1B[39m`:`undefined`;let i=n.depth??2;if(typeof t==`string`){let e=t.replace(/\\/g,`\\\\`);if(t.includes(`'`)&&!t.includes(`"`)){let t=e.replace(/"/g,`\\"`);return n.colors?`\x1b[32m"${t}"\x1b[39m`:`"${t}"`}let r=e.replace(/'/g,`\\'`);return n.colors?`\x1b[32m'${r}'\x1b[39m`:`'${r}'`}if(typeof t==`number`)return n.colors?`\x1b[33m${t}\x1b[39m`:String(t);if(typeof t==`bigint`)return n.colors?`\x1b[33m${t}n\x1b[39m`:`${t}n`;if(typeof t==`boolean`)return n.colors?`\x1b[33m${t}\x1b[39m`:String(t);if(typeof t==`symbol`)return n.colors?`\x1b[32m${t.toString()}\x1b[39m`:t.toString();if(typeof t==`function`){let e=t.name?`: ${t.name}`:``;return n.colors?`\x1b[36m[Function${e}]\x1b[39m`:`[Function${e}]`}if(typeof t==`object`&&t&&e in t){let i=t[e];if(typeof i==`function`){let e=i.call(t,r,n);return typeof e==`string`?e:inspectValue(e,n,r)}}if(t instanceof Date)return t.toISOString();if(t instanceof RegExp)return n.colors?`\x1b[31m${t.toString()}\x1b[39m`:t.toString();if(t instanceof Error)return t.stack||t.toString();if(r>i)return Array.isArray(t)?`[Array]`:`[Object]`;if(Array.isArray(t))return inspectArray(t,n,r);if(t instanceof Map){let e=[...t.entries()].map(([e,t])=>`${inspectValue(e,n,r+1)} => ${inspectValue(t,n,r+1)}`);return`Map(${t.size}) { ${e.join(`, `)} }`}if(t instanceof Set){let e=[...t].map(e=>inspectValue(e,n,r+1));return`Set(${t.size}) { ${e.join(`, `)} }`}if(ArrayBuffer.isView(t)&&!(t instanceof DataView)){let e=t.constructor?.name||`TypedArray`,n=Array.from(t);return`${e}(${n.length}) [ ${n.join(`, `)} ]`}return inspectObject(t,n,r)}function inspectArray(e,t,n){let r=t.maxArrayLength??100,i=Math.min(e.length,r),a=[];for(let r=0;r<i;r++)a.push(inspectValue(e[r],t,n+1));e.length>r&&a.push(`... ${e.length-r} more items`),t.showHidden&&a.push(`[length]: ${e.length}`);let o=t.breakLength??72,s=t.compact??3;if(typeof s==`number`&&s>0&&e.length>s){let stripAnsi=e=>e.replace(/\x1b\[[0-9;]*m/g,``),e=Math.max(...a.map(e=>stripAnsi(e).length)),t=Math.max(e-2,1),n=a.length,r=Math.min(Math.round(Math.sqrt(2.5*t*n)/t),Math.floor((o-2)/t),Math.floor((2.5+n-1)/2),15);if(r>1){let e=[];for(let t=0;t<n;t+=r)e.push(` `+a.slice(t,Math.min(t+r,n)).join(`, `));return`[\n${e.join(`,
|
|
2
|
+
`)}\n]`}}let c=`[ ${a.join(`, `)} ]`;return c.length<=o?c:`[\n${a.map(e=>` `+e).join(`,
|
|
3
|
+
`)}\n]`}function inspectObject(e,t,n){let r=t.showHidden?Object.getOwnPropertyNames(e):Object.keys(e);if(t.sorted&&r.sort(),r.length===0){let t=Object.prototype.toString.call(e);return t===`[object Object]`?`{}`:t}let i=r.map(r=>`${r}: ${inspectValue(e[r],t,n+1)}`),a=t.breakLength??72,o=`{ ${i.join(`, `)} }`;return o.length<=a?o:`{\n${i.map(e=>` `+e).join(`,
|
|
4
|
+
`)}\n}`}function inspect(e,t){let n=typeof t==`boolean`?{showHidden:t}:{...t};return n.colors===void 0&&(n.colors=!1),inspectValue(e,n,0)}inspect.custom=e,inspect.defaultOptions={showHidden:!1,depth:2,colors:!1,maxArrayLength:100,maxStringLength:1e4,breakLength:72,compact:3,sorted:!1},inspect.colors={reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],blink:[5,25],inverse:[7,27],hidden:[8,28],strikethrough:[9,29],doubleunderline:[21,24],black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],framed:[51,54],overlined:[53,55],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39],bgBlackBright:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]},inspect.styles={special:`cyan`,number:`yellow`,bigint:`yellow`,boolean:`yellow`,undefined:`grey`,null:`bold`,string:`green`,symbol:`green`,date:`magenta`,regexp:`red`,module:`underline`};export{inspect,e as kCustomInspect};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";function isBoolean(e){return typeof e==`boolean`}function isNull(e){return e===null}function isNullOrUndefined(e){return e==null}function isNumber(e){return typeof e==`number`}function isString(e){return typeof e==`string`}function isSymbol(e){return typeof e==`symbol`}function isUndefined(e){return e===void 0}function isObject(e){return typeof e==`object`&&!!e}function isError(e){return e instanceof Error}function isFunction(e){return typeof e==`function`}function isRegExp(e){return e instanceof RegExp}function isArray(e){return Array.isArray(e)}function isPrimitive(e){return e===null||typeof e!=`object`&&typeof e!=`function`}function isDate(e){return e instanceof Date}function isBuffer(e){return e instanceof Uint8Array&&e.constructor?.name===`Buffer`}export{isArray,isBoolean,isBuffer,isDate,isError,isFunction,isNull,isNullOrUndefined,isNumber,isObject,isPrimitive,isRegExp,isString,isSymbol,isUndefined};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
declare const kCustomPromisify: unique symbol;
|
|
2
|
+
export declare function promisify<T extends (...args: unknown[]) => void>(fn: T): (...args: unknown[]) => Promise<unknown>;
|
|
3
|
+
export declare namespace promisify {
|
|
4
|
+
var custom: typeof kCustomPromisify;
|
|
5
|
+
}
|
|
6
|
+
export declare function callbackify<T>(fn: () => Promise<T>): (callback: (err: Error | null, result?: T) => void) => void;
|
|
7
|
+
export declare function callbackify<T>(fn: (...args: unknown[]) => Promise<T>): (...args: unknown[]) => void;
|
|
8
|
+
export declare function deprecate<T extends (...args: unknown[]) => unknown>(fn: T, msg: string, code?: string): T;
|
|
9
|
+
export declare function debuglog(section: string): (...args: unknown[]) => void;
|
|
10
|
+
export declare function inherits(ctor: Function, superCtor: Function): void;
|
|
11
|
+
export declare function isDeepStrictEqual(a: unknown, b: unknown): boolean;
|
|
12
|
+
export declare function toUSVString(string: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Returns a Promise that resolves once `signal` aborts. The optional
|
|
15
|
+
* `resource` argument is accepted for Node compatibility — Node uses it
|
|
16
|
+
* for experimental "resource cleanup" tracking; we ignore it (no-op),
|
|
17
|
+
* which matches the observable behavior of `util.aborted()` for the
|
|
18
|
+
* documented use case.
|
|
19
|
+
*
|
|
20
|
+
* Reference: https://nodejs.org/api/util.html#utilabortedsignal-resource
|
|
21
|
+
*
|
|
22
|
+
* @param signal An `AbortSignal` to wait on.
|
|
23
|
+
* @param resource Any non-null object — accepted for Node parity.
|
|
24
|
+
*/
|
|
25
|
+
export declare function aborted(signal: AbortSignal, resource: object): Promise<void>;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { InspectOptions } from 'node:util';
|
|
2
|
+
export declare function format(fmt: string, ...args: unknown[]): string;
|
|
3
|
+
export declare function formatWithOptions(inspectOptions: InspectOptions, fmt: string, ...args: unknown[]): string;
|
|
4
|
+
export declare function stripVTControlCharacters(str: string): string;
|
|
5
|
+
interface StyleTextOptions {
|
|
6
|
+
validateStream?: boolean;
|
|
7
|
+
stream?: {
|
|
8
|
+
isTTY?: boolean;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Apply ANSI styling to text, using the format names from `inspect.colors`.
|
|
13
|
+
* Per Node's spec, when `validateStream` is true (default) and the target
|
|
14
|
+
* stream is not a TTY, return the unstyled text. We use `process.stdout` as
|
|
15
|
+
* the default stream — the same as Node.
|
|
16
|
+
*/
|
|
17
|
+
export declare function styleText(format: string | string[], text: string, options?: StyleTextOptions): string;
|
|
18
|
+
export {};
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,66 +1,15 @@
|
|
|
1
|
-
import type { InspectOptions } from 'node:util';
|
|
2
1
|
import * as types from './types.js';
|
|
3
2
|
import { getSystemErrorName, getSystemErrorMap } from './errors.js';
|
|
3
|
+
import { inspect, kCustomInspect } from './inspect.js';
|
|
4
|
+
import { format, formatWithOptions, stripVTControlCharacters, styleText } from './format.js';
|
|
5
|
+
import { promisify, callbackify, deprecate, debuglog, inherits, isDeepStrictEqual, toUSVString, aborted } from './compat.js';
|
|
6
|
+
import { isBoolean, isNull, isNullOrUndefined, isNumber, isString, isSymbol, isUndefined, isObject, isError, isFunction, isRegExp, isArray, isPrimitive, isDate, isBuffer } from './legacy-predicates.js';
|
|
4
7
|
export { types };
|
|
5
8
|
export { getSystemErrorName, getSystemErrorMap };
|
|
6
|
-
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
var defaultOptions: {
|
|
11
|
-
showHidden: boolean;
|
|
12
|
-
depth: number;
|
|
13
|
-
colors: boolean;
|
|
14
|
-
maxArrayLength: number;
|
|
15
|
-
maxStringLength: number;
|
|
16
|
-
breakLength: number;
|
|
17
|
-
compact: number;
|
|
18
|
-
sorted: boolean;
|
|
19
|
-
};
|
|
20
|
-
var colors: Record<string, [number, number]>;
|
|
21
|
-
var styles: Record<string, string>;
|
|
22
|
-
}
|
|
23
|
-
export declare function format(fmt: string, ...args: unknown[]): string;
|
|
24
|
-
export declare function formatWithOptions(inspectOptions: InspectOptions, fmt: string, ...args: unknown[]): string;
|
|
25
|
-
export declare function stripVTControlCharacters(str: string): string;
|
|
26
|
-
interface StyleTextOptions {
|
|
27
|
-
validateStream?: boolean;
|
|
28
|
-
stream?: {
|
|
29
|
-
isTTY?: boolean;
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Apply ANSI styling to text, using the format names from `inspect.colors`.
|
|
34
|
-
* Per Node's spec, when `validateStream` is true (default) and the target
|
|
35
|
-
* stream is not a TTY, return the unstyled text. We use `process.stdout` as
|
|
36
|
-
* the default stream — the same as Node.
|
|
37
|
-
*/
|
|
38
|
-
export declare function styleText(format: string | string[], text: string, options?: StyleTextOptions): string;
|
|
39
|
-
declare const kCustomPromisify: unique symbol;
|
|
40
|
-
export declare function promisify<T extends (...args: unknown[]) => void>(fn: T): (...args: unknown[]) => Promise<unknown>;
|
|
41
|
-
export declare namespace promisify {
|
|
42
|
-
var custom: typeof kCustomPromisify;
|
|
43
|
-
}
|
|
44
|
-
export declare function callbackify<T>(fn: () => Promise<T>): (callback: (err: Error | null, result?: T) => void) => void;
|
|
45
|
-
export declare function callbackify<T>(fn: (...args: unknown[]) => Promise<T>): (...args: unknown[]) => void;
|
|
46
|
-
export declare function deprecate<T extends (...args: unknown[]) => unknown>(fn: T, msg: string, code?: string): T;
|
|
47
|
-
export declare function debuglog(section: string): (...args: unknown[]) => void;
|
|
48
|
-
export declare function inherits(ctor: Function, superCtor: Function): void;
|
|
49
|
-
export declare function isBoolean(value: unknown): value is boolean;
|
|
50
|
-
export declare function isNull(value: unknown): value is null;
|
|
51
|
-
export declare function isNullOrUndefined(value: unknown): value is null | undefined;
|
|
52
|
-
export declare function isNumber(value: unknown): value is number;
|
|
53
|
-
export declare function isString(value: unknown): value is string;
|
|
54
|
-
export declare function isSymbol(value: unknown): value is symbol;
|
|
55
|
-
export declare function isUndefined(value: unknown): value is undefined;
|
|
56
|
-
export declare function isObject(value: unknown): value is object;
|
|
57
|
-
export declare function isError(value: unknown): value is Error;
|
|
58
|
-
export declare function isFunction(value: unknown): value is Function;
|
|
59
|
-
export declare function isRegExp(value: unknown): value is RegExp;
|
|
60
|
-
export declare function isArray(value: unknown): value is unknown[];
|
|
61
|
-
export declare function isPrimitive(value: unknown): boolean;
|
|
62
|
-
export declare function isDate(value: unknown): value is Date;
|
|
63
|
-
export declare function isBuffer(value: unknown): boolean;
|
|
9
|
+
export { inspect, kCustomInspect };
|
|
10
|
+
export { format, formatWithOptions, stripVTControlCharacters, styleText };
|
|
11
|
+
export { promisify, callbackify, deprecate, debuglog, inherits, isDeepStrictEqual, toUSVString, aborted, };
|
|
12
|
+
export { isBoolean, isNull, isNullOrUndefined, isNumber, isString, isSymbol, isUndefined, isObject, isError, isFunction, isRegExp, isArray, isPrimitive, isDate, isBuffer, };
|
|
64
13
|
export declare const TextDecoder: {
|
|
65
14
|
new (label?: string, options?: TextDecoderOptions): TextDecoder;
|
|
66
15
|
prototype: TextDecoder;
|
|
@@ -69,21 +18,6 @@ export declare const TextEncoder: {
|
|
|
69
18
|
new (): TextEncoder;
|
|
70
19
|
prototype: TextEncoder;
|
|
71
20
|
};
|
|
72
|
-
export declare function isDeepStrictEqual(a: unknown, b: unknown): boolean;
|
|
73
|
-
export declare function toUSVString(string: string): string;
|
|
74
|
-
/**
|
|
75
|
-
* Returns a Promise that resolves once `signal` aborts. The optional
|
|
76
|
-
* `resource` argument is accepted for Node compatibility — Node uses it
|
|
77
|
-
* for experimental "resource cleanup" tracking; we ignore it (no-op),
|
|
78
|
-
* which matches the observable behavior of `util.aborted()` for the
|
|
79
|
-
* documented use case.
|
|
80
|
-
*
|
|
81
|
-
* Reference: https://nodejs.org/api/util.html#utilabortedsignal-resource
|
|
82
|
-
*
|
|
83
|
-
* @param signal An `AbortSignal` to wait on.
|
|
84
|
-
* @param resource Any non-null object — accepted for Node parity.
|
|
85
|
-
*/
|
|
86
|
-
export declare function aborted(signal: AbortSignal, resource: object): Promise<void>;
|
|
87
21
|
declare const _default: {
|
|
88
22
|
format: typeof format;
|
|
89
23
|
formatWithOptions: typeof formatWithOptions;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { InspectOptions } from 'node:util';
|
|
2
|
+
export declare const kCustomInspect: unique symbol;
|
|
3
|
+
export declare function inspect(value: unknown, opts?: boolean | InspectOptions): string;
|
|
4
|
+
export declare namespace inspect {
|
|
5
|
+
var custom: typeof kCustomInspect;
|
|
6
|
+
var defaultOptions: {
|
|
7
|
+
showHidden: boolean;
|
|
8
|
+
depth: number;
|
|
9
|
+
colors: boolean;
|
|
10
|
+
maxArrayLength: number;
|
|
11
|
+
maxStringLength: number;
|
|
12
|
+
breakLength: number;
|
|
13
|
+
compact: number;
|
|
14
|
+
sorted: boolean;
|
|
15
|
+
};
|
|
16
|
+
var colors: Record<string, [number, number]>;
|
|
17
|
+
var styles: Record<string, string>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare function isBoolean(value: unknown): value is boolean;
|
|
2
|
+
export declare function isNull(value: unknown): value is null;
|
|
3
|
+
export declare function isNullOrUndefined(value: unknown): value is null | undefined;
|
|
4
|
+
export declare function isNumber(value: unknown): value is number;
|
|
5
|
+
export declare function isString(value: unknown): value is string;
|
|
6
|
+
export declare function isSymbol(value: unknown): value is symbol;
|
|
7
|
+
export declare function isUndefined(value: unknown): value is undefined;
|
|
8
|
+
export declare function isObject(value: unknown): value is object;
|
|
9
|
+
export declare function isError(value: unknown): value is Error;
|
|
10
|
+
export declare function isFunction(value: unknown): value is Function;
|
|
11
|
+
export declare function isRegExp(value: unknown): value is RegExp;
|
|
12
|
+
export declare function isArray(value: unknown): value is unknown[];
|
|
13
|
+
export declare function isPrimitive(value: unknown): boolean;
|
|
14
|
+
export declare function isDate(value: unknown): value is Date;
|
|
15
|
+
export declare function isBuffer(value: unknown): boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/util",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.22",
|
|
4
4
|
"description": "Node.js util module for Gjs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "lib/esm/index.js",
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
"util"
|
|
38
38
|
],
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@gjsify/cli": "^0.4.
|
|
41
|
-
"@gjsify/unit": "^0.4.
|
|
40
|
+
"@gjsify/cli": "^0.4.22",
|
|
41
|
+
"@gjsify/unit": "^0.4.22",
|
|
42
42
|
"@types/inherits": "^2.0.0",
|
|
43
|
-
"@types/node": "^25.
|
|
43
|
+
"@types/node": "^25.9.1",
|
|
44
44
|
"typescript": "^6.0.3"
|
|
45
45
|
}
|
|
46
46
|
}
|