grab-url 1.0.15 → 1.0.17
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/dist/download.cjs.js +1 -1
- package/dist/download.cjs.js.map +1 -1
- package/dist/download.d.ts +0 -0
- package/dist/download.es.js +1 -3713
- package/dist/download.es.js.map +1 -1
- package/dist/grab-api.cjs.js +1 -1
- package/dist/grab-api.cjs.js.map +1 -1
- package/dist/grab-api.d.ts +4 -5
- package/dist/grab-api.es.js +1 -353
- package/dist/grab-api.es.js.map +1 -1
- package/dist/grab-api.umd.js +0 -0
- package/dist/grab-api.umd.js.map +227 -1
- package/dist/icons.cjs.js +0 -0
- package/dist/icons.cjs.js.map +0 -0
- package/dist/icons.d.ts +0 -0
- package/dist/icons.es.js +1 -113
- package/dist/icons.es.js.map +1 -1
- package/dist/log.cjs.js +0 -0
- package/dist/log.cjs.js.map +0 -0
- package/dist/log.d.ts +0 -0
- package/dist/log.es.js +1 -298
- package/dist/log.es.js.map +1 -1
- package/package.json +2 -1
- package/readme.md +1 -1
- package/src/grab-api.ts +10 -16
- package/src/grab-url.js +0 -0
- package/src/icons/cli/spinners.js +0 -0
- package/src/icons/svg/index.ts +0 -0
- package/src/icons/svg/loading-bouncy-ball.svg +0 -0
- package/src/icons/svg/loading-double-ring.svg +0 -0
- package/src/icons/svg/loading-eclipse.svg +0 -0
- package/src/icons/svg/loading-ellipsis.svg +0 -0
- package/src/icons/svg/loading-floating-search.svg +0 -0
- package/src/icons/svg/loading-gears.svg +0 -0
- package/src/icons/svg/loading-infinity.svg +0 -0
- package/src/icons/svg/loading-orbital.svg +0 -0
- package/src/icons/svg/loading-pacman.svg +0 -0
- package/src/icons/svg/loading-pulse-bars.svg +0 -0
- package/src/icons/svg/loading-red-blue-ball.svg +0 -0
- package/src/icons/svg/loading-reload-arrow.svg +0 -0
- package/src/icons/svg/loading-ring.svg +0 -0
- package/src/icons/svg/loading-ripple.svg +0 -0
- package/src/icons/svg/loading-spinner-oval.svg +0 -0
- package/src/icons/svg/loading-spinner.svg +0 -0
- package/src/icons/svg/loading-square-blocks.svg +0 -0
- package/src/log-json.ts +0 -0
package/dist/log.es.js
CHANGED
|
@@ -1,299 +1,2 @@
|
|
|
1
|
-
function log(
|
|
2
|
-
let {
|
|
3
|
-
color,
|
|
4
|
-
style = "color:rgb(54, 165, 220); font-size: 10pt;",
|
|
5
|
-
hideInProduction = void 0,
|
|
6
|
-
startSpinner = false,
|
|
7
|
-
stopSpinner = false
|
|
8
|
-
} = options;
|
|
9
|
-
const colors = getColors();
|
|
10
|
-
if (typeof hideInProduction === "undefined")
|
|
11
|
-
hideInProduction = typeof window !== "undefined" && window?.location.hostname.includes("localhost");
|
|
12
|
-
if (typeof message === "object")
|
|
13
|
-
message = printJSONStructure(message) + "\n\n" + JSON.stringify(message, null, 2);
|
|
14
|
-
if (Array.isArray(color) && color.length == 1) color = color[0];
|
|
15
|
-
if (color && typeof process !== void 0) {
|
|
16
|
-
if (message.includes("%c") && Array.isArray(color))
|
|
17
|
-
message = message.replace(/%c/g, (match, index) => colors[color[index]] || "");
|
|
18
|
-
else if (color && typeof color === "string")
|
|
19
|
-
message = (colors[color] || "") + message + colors.reset;
|
|
20
|
-
}
|
|
21
|
-
var i = 0;
|
|
22
|
-
if (startSpinner)
|
|
23
|
-
(global || globalThis).interval = setInterval(() => {
|
|
24
|
-
process.stdout.write(
|
|
25
|
-
(Array.isArray(color) ? colors[color[0]] : colors[color] || "") + "\r" + "⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏".split("")[i = ++i % 10] + " " + message + colors.reset
|
|
26
|
-
);
|
|
27
|
-
}, 50);
|
|
28
|
-
else if (stopSpinner) {
|
|
29
|
-
clearInterval((global || globalThis).interval);
|
|
30
|
-
process.stdout.write(
|
|
31
|
-
"\r" + (message || " ") + " ".repeat(message.length + 20) + "\n"
|
|
32
|
-
);
|
|
33
|
-
} else if (typeof style === "string") {
|
|
34
|
-
if (style.split(" ").length == 1 || color) {
|
|
35
|
-
style = `color: ${color || style}; font-size: 11pt;`;
|
|
36
|
-
} else {
|
|
37
|
-
if (style.match(/^#[0-9a-fA-F]{6}$/)) {
|
|
38
|
-
style = `color: ${style}; font-size: 11pt;`;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
if (hideInProduction)
|
|
42
|
-
console.debug((style ? "%c" : "") + (message || ""), style);
|
|
43
|
-
else console.log((style ? "%c" : "") + (message || ""), style);
|
|
44
|
-
} else if (typeof style === "object") console.log(message, ...style);
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
47
|
-
var ColorName = /* @__PURE__ */ ((ColorName2) => {
|
|
48
|
-
ColorName2["RESET"] = "reset";
|
|
49
|
-
ColorName2["BLACK"] = "black";
|
|
50
|
-
ColorName2["RED"] = "red";
|
|
51
|
-
ColorName2["GREEN"] = "green";
|
|
52
|
-
ColorName2["YELLOW"] = "yellow";
|
|
53
|
-
ColorName2["BLUE"] = "blue";
|
|
54
|
-
ColorName2["MAGENTA"] = "magenta";
|
|
55
|
-
ColorName2["CYAN"] = "cyan";
|
|
56
|
-
ColorName2["WHITE"] = "white";
|
|
57
|
-
ColorName2["GRAY"] = "gray";
|
|
58
|
-
ColorName2["BRIGHT_RED"] = "brightRed";
|
|
59
|
-
ColorName2["BRIGHT_GREEN"] = "brightGreen";
|
|
60
|
-
ColorName2["BRIGHT_YELLOW"] = "brightYellow";
|
|
61
|
-
ColorName2["BRIGHT_BLUE"] = "brightBlue";
|
|
62
|
-
ColorName2["BRIGHT_MAGENTA"] = "brightMagenta";
|
|
63
|
-
ColorName2["BRIGHT_CYAN"] = "brightCyan";
|
|
64
|
-
ColorName2["BRIGHT_WHITE"] = "brightWhite";
|
|
65
|
-
ColorName2["BG_RED"] = "bgRed";
|
|
66
|
-
ColorName2["BG_GREEN"] = "bgGreen";
|
|
67
|
-
ColorName2["BG_YELLOW"] = "bgYellow";
|
|
68
|
-
ColorName2["BG_BLUE"] = "bgBlue";
|
|
69
|
-
ColorName2["BG_MAGENTA"] = "bgMagenta";
|
|
70
|
-
ColorName2["BG_CYAN"] = "bgCyan";
|
|
71
|
-
ColorName2["BG_WHITE"] = "bgWhite";
|
|
72
|
-
ColorName2["BG_GRAY"] = "bgGray";
|
|
73
|
-
ColorName2["BG_BLACK"] = "bgBlack";
|
|
74
|
-
ColorName2["BG_BRIGHT_RED"] = "bgBrightRed";
|
|
75
|
-
ColorName2["BG_BRIGHT_GREEN"] = "bgBrightGreen";
|
|
76
|
-
ColorName2["BG_BRIGHT_YELLOW"] = "bgBrightYellow";
|
|
77
|
-
ColorName2["BG_BRIGHT_BLUE"] = "bgBrightBlue";
|
|
78
|
-
ColorName2["BG_BRIGHT_MAGENTA"] = "bgBrightMagenta";
|
|
79
|
-
ColorName2["BG_BRIGHT_CYAN"] = "bgBrightCyan";
|
|
80
|
-
ColorName2["BG_BRIGHT_WHITE"] = "bgBrightWhite";
|
|
81
|
-
return ColorName2;
|
|
82
|
-
})(ColorName || {});
|
|
83
|
-
const colorMap = {
|
|
84
|
-
[
|
|
85
|
-
"reset"
|
|
86
|
-
/* RESET */
|
|
87
|
-
]: [0, "000000"],
|
|
88
|
-
[
|
|
89
|
-
"black"
|
|
90
|
-
/* BLACK */
|
|
91
|
-
]: [30, "000000"],
|
|
92
|
-
[
|
|
93
|
-
"red"
|
|
94
|
-
/* RED */
|
|
95
|
-
]: [31, "ff0000"],
|
|
96
|
-
[
|
|
97
|
-
"green"
|
|
98
|
-
/* GREEN */
|
|
99
|
-
]: [32, "00ff00"],
|
|
100
|
-
[
|
|
101
|
-
"yellow"
|
|
102
|
-
/* YELLOW */
|
|
103
|
-
]: [33, "ffff00"],
|
|
104
|
-
[
|
|
105
|
-
"blue"
|
|
106
|
-
/* BLUE */
|
|
107
|
-
]: [34, "0000ff"],
|
|
108
|
-
[
|
|
109
|
-
"magenta"
|
|
110
|
-
/* MAGENTA */
|
|
111
|
-
]: [35, "ff00ff"],
|
|
112
|
-
[
|
|
113
|
-
"cyan"
|
|
114
|
-
/* CYAN */
|
|
115
|
-
]: [36, "00ffff"],
|
|
116
|
-
[
|
|
117
|
-
"white"
|
|
118
|
-
/* WHITE */
|
|
119
|
-
]: [37, "ffffff"],
|
|
120
|
-
[
|
|
121
|
-
"gray"
|
|
122
|
-
/* GRAY */
|
|
123
|
-
]: [90, "808080"],
|
|
124
|
-
[
|
|
125
|
-
"brightRed"
|
|
126
|
-
/* BRIGHT_RED */
|
|
127
|
-
]: [91, "ff5555"],
|
|
128
|
-
[
|
|
129
|
-
"brightGreen"
|
|
130
|
-
/* BRIGHT_GREEN */
|
|
131
|
-
]: [92, "55ff55"],
|
|
132
|
-
[
|
|
133
|
-
"brightYellow"
|
|
134
|
-
/* BRIGHT_YELLOW */
|
|
135
|
-
]: [93, "ffff55"],
|
|
136
|
-
[
|
|
137
|
-
"brightBlue"
|
|
138
|
-
/* BRIGHT_BLUE */
|
|
139
|
-
]: [94, "5555ff"],
|
|
140
|
-
[
|
|
141
|
-
"brightMagenta"
|
|
142
|
-
/* BRIGHT_MAGENTA */
|
|
143
|
-
]: [95, "ff55ff"],
|
|
144
|
-
[
|
|
145
|
-
"brightCyan"
|
|
146
|
-
/* BRIGHT_CYAN */
|
|
147
|
-
]: [96, "55ffff"],
|
|
148
|
-
[
|
|
149
|
-
"brightWhite"
|
|
150
|
-
/* BRIGHT_WHITE */
|
|
151
|
-
]: [97, "ffffff"],
|
|
152
|
-
[
|
|
153
|
-
"bgBlack"
|
|
154
|
-
/* BG_BLACK */
|
|
155
|
-
]: [40, "000000"],
|
|
156
|
-
[
|
|
157
|
-
"bgRed"
|
|
158
|
-
/* BG_RED */
|
|
159
|
-
]: [41, "ff0000"],
|
|
160
|
-
[
|
|
161
|
-
"bgGreen"
|
|
162
|
-
/* BG_GREEN */
|
|
163
|
-
]: [42, "00ff00"],
|
|
164
|
-
[
|
|
165
|
-
"bgYellow"
|
|
166
|
-
/* BG_YELLOW */
|
|
167
|
-
]: [43, "ffff00"],
|
|
168
|
-
[
|
|
169
|
-
"bgBlue"
|
|
170
|
-
/* BG_BLUE */
|
|
171
|
-
]: [44, "0000ff"],
|
|
172
|
-
[
|
|
173
|
-
"bgMagenta"
|
|
174
|
-
/* BG_MAGENTA */
|
|
175
|
-
]: [45, "ff00ff"],
|
|
176
|
-
[
|
|
177
|
-
"bgCyan"
|
|
178
|
-
/* BG_CYAN */
|
|
179
|
-
]: [46, "00ffff"],
|
|
180
|
-
[
|
|
181
|
-
"bgWhite"
|
|
182
|
-
/* BG_WHITE */
|
|
183
|
-
]: [47, "ffffff"],
|
|
184
|
-
[
|
|
185
|
-
"bgGray"
|
|
186
|
-
/* BG_GRAY */
|
|
187
|
-
]: [100, "808080"],
|
|
188
|
-
[
|
|
189
|
-
"bgBrightRed"
|
|
190
|
-
/* BG_BRIGHT_RED */
|
|
191
|
-
]: [101, "ff8888"],
|
|
192
|
-
[
|
|
193
|
-
"bgBrightGreen"
|
|
194
|
-
/* BG_BRIGHT_GREEN */
|
|
195
|
-
]: [102, "88ff88"],
|
|
196
|
-
[
|
|
197
|
-
"bgBrightYellow"
|
|
198
|
-
/* BG_BRIGHT_YELLOW */
|
|
199
|
-
]: [103, "ffff88"],
|
|
200
|
-
[
|
|
201
|
-
"bgBrightBlue"
|
|
202
|
-
/* BG_BRIGHT_BLUE */
|
|
203
|
-
]: [104, "8888ff"],
|
|
204
|
-
[
|
|
205
|
-
"bgBrightMagenta"
|
|
206
|
-
/* BG_BRIGHT_MAGENTA */
|
|
207
|
-
]: [105, "ff88ff"],
|
|
208
|
-
[
|
|
209
|
-
"bgBrightCyan"
|
|
210
|
-
/* BG_BRIGHT_CYAN */
|
|
211
|
-
]: [106, "88ffff"],
|
|
212
|
-
[
|
|
213
|
-
"bgBrightWhite"
|
|
214
|
-
/* BG_BRIGHT_WHITE */
|
|
215
|
-
]: [107, "ffffff"]
|
|
216
|
-
};
|
|
217
|
-
function getColors(format = "ansi") {
|
|
218
|
-
const colors = {};
|
|
219
|
-
for (const [name, [ansiCode, hexCode]] of Object.entries(colorMap)) {
|
|
220
|
-
colors[name] = format === "html" ? "#" + hexCode : "\x1B[" + ansiCode + "m";
|
|
221
|
-
}
|
|
222
|
-
return colors;
|
|
223
|
-
}
|
|
224
|
-
function getColorForType(value) {
|
|
225
|
-
const colors = getColors();
|
|
226
|
-
if (typeof value === "string") return colors.yellow;
|
|
227
|
-
if (typeof value === "number") return colors.cyan;
|
|
228
|
-
if (typeof value === "boolean") return colors.magenta;
|
|
229
|
-
if (typeof value === "function") return colors.red;
|
|
230
|
-
if (value === null) return colors.gray;
|
|
231
|
-
if (Array.isArray(value)) return colors.blue;
|
|
232
|
-
if (typeof value === "object") return colors.green;
|
|
233
|
-
return colors.white;
|
|
234
|
-
}
|
|
235
|
-
function getTypeString(value) {
|
|
236
|
-
if (typeof value === "string") return '""';
|
|
237
|
-
if (typeof value === "number") return "number";
|
|
238
|
-
if (typeof value === "boolean") return "bool";
|
|
239
|
-
if (typeof value === "function") return "function";
|
|
240
|
-
if (value === null) return "null";
|
|
241
|
-
if (Array.isArray(value)) {
|
|
242
|
-
if (value.length) return "[" + getTypeString(value[0]) + "]";
|
|
243
|
-
else return "[]";
|
|
244
|
-
}
|
|
245
|
-
if (typeof value === "object") return "{...}";
|
|
246
|
-
return typeof value;
|
|
247
|
-
}
|
|
248
|
-
function printJSONStructure(obj, indent = 0, colorFormat = "ansi") {
|
|
249
|
-
const colors = getColors(colorFormat);
|
|
250
|
-
const pad = " ".repeat(indent);
|
|
251
|
-
var result = "";
|
|
252
|
-
if (typeof obj !== "object" || obj === null) {
|
|
253
|
-
const color = getColorForType(obj);
|
|
254
|
-
return color + getTypeString(obj) + colors.reset;
|
|
255
|
-
}
|
|
256
|
-
if (Array.isArray(obj)) {
|
|
257
|
-
result = colors.blue + "[" + colors.reset;
|
|
258
|
-
if (obj.length) result += "\n";
|
|
259
|
-
if (obj.every((item) => typeof item === typeof obj[0])) {
|
|
260
|
-
result += pad + " " + printJSONStructure(obj[0], indent + 1);
|
|
261
|
-
result += ",";
|
|
262
|
-
result += "\n";
|
|
263
|
-
} else {
|
|
264
|
-
obj.forEach((item, idx) => {
|
|
265
|
-
result += pad + " " + printJSONStructure(item, indent + 1);
|
|
266
|
-
if (idx < obj.length - 1) result += ",";
|
|
267
|
-
result += "\n";
|
|
268
|
-
});
|
|
269
|
-
result += pad + colors.blue + "]" + colors.reset;
|
|
270
|
-
return result;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
result = colors.green + "{" + colors.reset;
|
|
274
|
-
const keys = Object.keys(obj);
|
|
275
|
-
if (keys.length) result += "\n";
|
|
276
|
-
keys.forEach((key, index) => {
|
|
277
|
-
const value = obj[key];
|
|
278
|
-
const color = getColorForType(value);
|
|
279
|
-
result += pad + " ";
|
|
280
|
-
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
281
|
-
result += color + key + colors.reset + ": " + printJSONStructure(value, indent + 1);
|
|
282
|
-
} else if (Array.isArray(value)) {
|
|
283
|
-
result += color + key + colors.reset + ": " + printJSONStructure(value, indent + 1);
|
|
284
|
-
} else {
|
|
285
|
-
result += color + key + ": " + getTypeString(value) + colors.reset;
|
|
286
|
-
}
|
|
287
|
-
if (index < keys.length - 1) result += ",";
|
|
288
|
-
result += "\n";
|
|
289
|
-
});
|
|
290
|
-
result += pad + colors.green + "}" + colors.reset;
|
|
291
|
-
return result;
|
|
292
|
-
}
|
|
293
|
-
export {
|
|
294
|
-
ColorName,
|
|
295
|
-
getColors,
|
|
296
|
-
log,
|
|
297
|
-
printJSONStructure
|
|
298
|
-
};
|
|
1
|
+
function e(e="",t={}){let{color:r,style:n="color:rgb(54, 165, 220); font-size: 10pt;",hideInProduction:o,startSpinner:l=!1,stopSpinner:i=!1}=t;const a=f();void 0===o&&(o="undefined"!=typeof window&&window?.location.hostname.includes("localhost")),"object"==typeof e&&(e=g(e)+"\n\n"+JSON.stringify(e,null,2)),Array.isArray(r)&&1==r.length&&(r=r[0]),r&&void 0!==typeof process&&(e.includes("%c")&&Array.isArray(r)?e=e.replace(/%c/g,(e,t)=>a[r[t]]||""):r&&"string"==typeof r&&(e=(a[r]||"")+e+a.reset));var b=0;return l?(global||globalThis).interval=setInterval(()=>{process.stdout.write((Array.isArray(r)?a[r[0]]:a[r]||"")+"\r"+"⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏".split("")[b=++b%10]+" "+e+a.reset)},50):i?(clearInterval((global||globalThis).interval),process.stdout.write("\r"+(e||" ")+" ".repeat(e.length+20)+"\n")):"string"==typeof n?(1==n.split(" ").length||r?n=`color: ${r||n}; font-size: 11pt;`:n.match(/^#[0-9a-fA-F]{6}$/)&&(n=`color: ${n}; font-size: 11pt;`),o?console.debug((n?"%c":"")+(e||""),n):console.log((n?"%c":"")+(e||""),n)):"object"==typeof n&&console.log(e,...n),!0}var t=/* @__PURE__ */(e=>(e.RESET="reset",e.BLACK="black",e.RED="red",e.GREEN="green",e.YELLOW="yellow",e.BLUE="blue",e.MAGENTA="magenta",e.CYAN="cyan",e.WHITE="white",e.GRAY="gray",e.BRIGHT_RED="brightRed",e.BRIGHT_GREEN="brightGreen",e.BRIGHT_YELLOW="brightYellow",e.BRIGHT_BLUE="brightBlue",e.BRIGHT_MAGENTA="brightMagenta",e.BRIGHT_CYAN="brightCyan",e.BRIGHT_WHITE="brightWhite",e.BG_RED="bgRed",e.BG_GREEN="bgGreen",e.BG_YELLOW="bgYellow",e.BG_BLUE="bgBlue",e.BG_MAGENTA="bgMagenta",e.BG_CYAN="bgCyan",e.BG_WHITE="bgWhite",e.BG_GRAY="bgGray",e.BG_BLACK="bgBlack",e.BG_BRIGHT_RED="bgBrightRed",e.BG_BRIGHT_GREEN="bgBrightGreen",e.BG_BRIGHT_YELLOW="bgBrightYellow",e.BG_BRIGHT_BLUE="bgBrightBlue",e.BG_BRIGHT_MAGENTA="bgBrightMagenta",e.BG_BRIGHT_CYAN="bgBrightCyan",e.BG_BRIGHT_WHITE="bgBrightWhite",e))(t||{});const r={reset:[0,"000000"],black:[30,"000000"],red:[31,"ff0000"],green:[32,"00ff00"],yellow:[33,"ffff00"],blue:[34,"0000ff"],magenta:[35,"ff00ff"],cyan:[36,"00ffff"],white:[37,"ffffff"],gray:[90,"808080"],brightRed:[91,"ff5555"],brightGreen:[92,"55ff55"],brightYellow:[93,"ffff55"],brightBlue:[94,"5555ff"],brightMagenta:[95,"ff55ff"],brightCyan:[96,"55ffff"],brightWhite:[97,"ffffff"],bgBlack:[40,"000000"],bgRed:[41,"ff0000"],bgGreen:[42,"00ff00"],bgYellow:[43,"ffff00"],bgBlue:[44,"0000ff"],bgMagenta:[45,"ff00ff"],bgCyan:[46,"00ffff"],bgWhite:[47,"ffffff"],bgGray:[100,"808080"],bgBrightRed:[101,"ff8888"],bgBrightGreen:[102,"88ff88"],bgBrightYellow:[103,"ffff88"],bgBrightBlue:[104,"8888ff"],bgBrightMagenta:[105,"ff88ff"],bgBrightCyan:[106,"88ffff"],bgBrightWhite:[107,"ffffff"]};function f(e="ansi"){const t={};for(const[f,[n,o]]of Object.entries(r))t[f]="html"===e?"#"+o:"["+n+"m";return t}function n(e){const t=f();return"string"==typeof e?t.yellow:"number"==typeof e?t.cyan:"boolean"==typeof e?t.magenta:"function"==typeof e?t.red:null===e?t.gray:Array.isArray(e)?t.blue:"object"==typeof e?t.green:t.white}function o(e){return"string"==typeof e?'""':"number"==typeof e?"number":"boolean"==typeof e?"bool":"function"==typeof e?"function":null===e?"null":Array.isArray(e)?e.length?"["+o(e[0])+"]":"[]":"object"==typeof e?"{...}":typeof e}function g(e,t=0,r="ansi"){const l=f(r),i=" ".repeat(t);var a="";if("object"!=typeof e||null===e){return n(e)+o(e)+l.reset}if(Array.isArray(e)){if(a=l.blue+"["+l.reset,e.length&&(a+="\n"),!e.every(t=>typeof t==typeof e[0]))return e.forEach((r,f)=>{a+=i+" "+g(r,t+1),f<e.length-1&&(a+=","),a+="\n"}),a+=i+l.blue+"]"+l.reset;a+=i+" "+g(e[0],t+1),a+=",",a+="\n"}a=l.green+"{"+l.reset;const b=Object.keys(e);return b.length&&(a+="\n"),b.forEach((r,f)=>{const s=e[r],y=n(s);a+=i+" ","object"!=typeof s||null===s||Array.isArray(s)?Array.isArray(s)?a+=y+r+l.reset+": "+g(s,t+1):a+=y+r+": "+o(s)+l.reset:a+=y+r+l.reset+": "+g(s,t+1),f<b.length-1&&(a+=","),a+="\n"}),a+=i+l.green+"}"+l.reset}export{t as ColorName,f as getColors,e as log,g as printJSONStructure};
|
|
299
2
|
//# sourceMappingURL=log.es.js.map
|
package/dist/log.es.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.es.js","sources":["../src/log-json.ts"],"sourcesContent":["/**\n * ### Colorized Log With JSON Structure\n * \n * Logs messages to the console with custom styling,\n * prints JSON with description of structure layout,\n * and showing debug output in development only.\n * @param {string|object} message - The message to log. If an object is provided, it will be stringified.\n * @param {string|string[]} [options.style] default='color: blue; font-size: 11pt;' - CSS style string\n * @param {boolean} [options.hideInProduction] - default = auto-detects based on hostname.\n * If true, uses `console.debug` (hidden in production). If false, uses `console.log`.\n *\n */\nexport function log(message: string|object = \"\", options: LogOptions = {}) {\n let {\n color,\n style = \"color:rgb(54, 165, 220); font-size: 10pt;\",\n hideInProduction = undefined,\n startSpinner = false,\n stopSpinner = false,\n } = options;\n const colors = getColors();\n\n // Auto-detect if we should hide logs in production based on hostname\n if (typeof hideInProduction === \"undefined\")\n hideInProduction =\n typeof window !== \"undefined\" &&\n window?.location.hostname.includes(\"localhost\");\n\n // For objects, print both the structure visualization and full JSON\n if (typeof message === \"object\")\n message =\n printJSONStructure(message) + \"\\n\\n\" + JSON.stringify(message, null, 2);\n\n // change color: [red] to color: red if only one\n if (Array.isArray(color) && color.length == 1) color = color[0];\n\n //colorize in terminal (%c is only in browser but we polyfill it)\n if (color && typeof process !== undefined)\n if (message.includes(\"%c\") && Array.isArray(color)) // replace each c with color[i]\n message = message.replace(/%c/g, (match, index) => colors[color[index]] || \"\");\n else if (color && typeof color === \"string\")\n message = (colors[color] || \"\") + message + colors.reset;\n\n\n\n // Displays an animated spinner in the terminal with the provided text.\n var i = 0;\n\n if (startSpinner)\n (global || globalThis).interval = setInterval(() => {\n process.stdout.write(\n (Array.isArray(color) ? colors[color[0]] : colors[color] || \"\") +\n \"\\r\" +\n \"⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏\".split(\"\")[(i = ++i % 10)] +\n \" \" +\n message +\n colors.reset\n );\n }, 50);\n else if (stopSpinner) {\n clearInterval((global || globalThis).interval);\n process.stdout.write(\n \"\\r\" + (message || \" \") + \" \".repeat(message.length + 20) + \"\\n\"\n );\n } else if (typeof style === \"string\") {\n // check if style is a one word color code or named color\n //test if style is valid as a CSS color name\n if (style.split(\" \").length == 1 || color) {\n style = `color: ${color || style}; font-size: 11pt;`;\n } else {\n // check if style is valid as a CSS color code\n if (style.match(/^#[0-9a-fA-F]{6}$/)) {\n style = `color: ${style}; font-size: 11pt;`;\n }\n }\n // Use console.debug for production-hidden logs, console.log otherwise\n if (hideInProduction)\n console.debug((style ? \"%c\" : \"\") + (message || \"\"), style);\n else console.log((style ? \"%c\" : \"\") + (message || \"\"), style);\n } else if (typeof style === \"object\") console.log(message, ...(style as any));\n return true;\n}\n\nexport interface LogOptions {\n /** CSS style string or array of CSS strings for browser console styling */\n style?: string | string[];\n /** Optional color name or code for terminal environments */\n color?: ColorName | ColorName[] | string | string[] ;\n /** If true, hides log in production (auto-detects by hostname if undefined) */\n hideInProduction?: boolean;\n /** Start a spinner (for CLI tools, optional) */\n startSpinner?: boolean;\n /** Stop a spinner (for CLI tools, optional) */\n stopSpinner?: boolean;\n}\n\n/**\n * Available color names\n */\nexport enum ColorName {\n RESET = 'reset',\n BLACK = 'black',\n RED = 'red',\n GREEN = 'green',\n YELLOW = 'yellow',\n BLUE = 'blue',\n MAGENTA = 'magenta',\n CYAN = 'cyan',\n WHITE = 'white',\n GRAY = 'gray',\n BRIGHT_RED = 'brightRed',\n BRIGHT_GREEN = 'brightGreen',\n BRIGHT_YELLOW = 'brightYellow',\n BRIGHT_BLUE = 'brightBlue',\n BRIGHT_MAGENTA = 'brightMagenta',\n BRIGHT_CYAN = 'brightCyan',\n BRIGHT_WHITE = 'brightWhite',\n BG_RED = 'bgRed',\n BG_GREEN = 'bgGreen',\n BG_YELLOW = 'bgYellow',\n BG_BLUE = 'bgBlue',\n BG_MAGENTA = 'bgMagenta',\n BG_CYAN = 'bgCyan',\n BG_WHITE = 'bgWhite',\n BG_GRAY = 'bgGray',\n BG_BLACK = 'bgBlack',\n BG_BRIGHT_RED = 'bgBrightRed',\n BG_BRIGHT_GREEN = 'bgBrightGreen',\n BG_BRIGHT_YELLOW = 'bgBrightYellow',\n BG_BRIGHT_BLUE = 'bgBrightBlue',\n BG_BRIGHT_MAGENTA = 'bgBrightMagenta',\n BG_BRIGHT_CYAN = 'bgBrightCyan',\n BG_BRIGHT_WHITE = 'bgBrightWhite',\n}\n\n/**\n * Color mapping with ANSI codes and HTML hex values\n * @type {Record<ColorName, [number, string]>}\n * @description Maps color names to [ansiCode, hexValue] pairs\n * - ansiCode: ANSI escape sequence number for terminal colors\n * - hexValue: Hex color value (without #) for HTML/CSS\n */\nconst colorMap: Record<ColorName, [number, string]> = {\n [ColorName.RESET]: [0, '000000'],\n [ColorName.BLACK]: [30, '000000'],\n [ColorName.RED]: [31, 'ff0000'],\n [ColorName.GREEN]: [32, '00ff00'],\n [ColorName.YELLOW]: [33, 'ffff00'],\n [ColorName.BLUE]: [34, '0000ff'],\n [ColorName.MAGENTA]: [35, 'ff00ff'],\n [ColorName.CYAN]: [36, '00ffff'],\n [ColorName.WHITE]: [37, 'ffffff'],\n [ColorName.GRAY]: [90, '808080'],\n [ColorName.BRIGHT_RED]: [91, 'ff5555'],\n [ColorName.BRIGHT_GREEN]: [92, '55ff55'],\n [ColorName.BRIGHT_YELLOW]: [93, 'ffff55'],\n [ColorName.BRIGHT_BLUE]: [94, '5555ff'],\n [ColorName.BRIGHT_MAGENTA]: [95, 'ff55ff'],\n [ColorName.BRIGHT_CYAN]: [96, '55ffff'],\n [ColorName.BRIGHT_WHITE]: [97, 'ffffff'],\n [ColorName.BG_BLACK]: [40, '000000'],\n [ColorName.BG_RED]: [41, 'ff0000'],\n [ColorName.BG_GREEN]: [42, '00ff00'],\n [ColorName.BG_YELLOW]: [43, 'ffff00'],\n [ColorName.BG_BLUE]: [44, '0000ff'],\n [ColorName.BG_MAGENTA]: [45, 'ff00ff'],\n [ColorName.BG_CYAN]: [46, '00ffff'],\n [ColorName.BG_WHITE]: [47, 'ffffff'],\n [ColorName.BG_GRAY]: [100, '808080'],\n [ColorName.BG_BRIGHT_RED]: [101, 'ff8888'],\n [ColorName.BG_BRIGHT_GREEN]: [102, '88ff88'],\n [ColorName.BG_BRIGHT_YELLOW]: [103, 'ffff88'],\n [ColorName.BG_BRIGHT_BLUE]: [104, '8888ff'],\n [ColorName.BG_BRIGHT_MAGENTA]: [105, 'ff88ff'],\n [ColorName.BG_BRIGHT_CYAN]: [106, '88ffff'],\n [ColorName.BG_BRIGHT_WHITE]: [107, 'ffffff'],\n};\n\n/**\n * Returns color codes based on the specified format\n * @param format - Output format for colors\n * - 'ansi': Returns ANSI escape codes (e.g., '\\x1b[31m')\n * - 'html': Returns HTML hex colors (e.g., '#ff0000')\n * @returns Object with color names as keys and color codes as values\n */\nexport function getColors(format: 'html' | 'ansi' = 'ansi'): Record<ColorName, string> {\n const colors: Record<ColorName, string> = {} as Record<ColorName, string>;\n for (const [name, [ansiCode, hexCode]] of Object.entries(colorMap)) {\n colors[name] = format === 'html' ? '#' + hexCode : '\\x1b[' + ansiCode + 'm';\n }\n return colors;\n}\n\n/**\n * Determines the appropriate color code for a given value type\n * Used for consistent color coding in the structure visualization\n */\nfunction getColorForType(value) {\n const colors = getColors();\n if (typeof value === \"string\") return colors.yellow;\n if (typeof value === \"number\") return colors.cyan;\n if (typeof value === \"boolean\") return colors.magenta;\n if (typeof value === \"function\") return colors.red;\n if (value === null) return colors.gray;\n if (Array.isArray(value)) return colors.blue;\n if (typeof value === \"object\") return colors.green;\n return colors.white;\n}\n\n/**\n * Returns a string representation of the value's type\n * Used to show simplified type information in the structure visualization\n */\nfunction getTypeString(value) {\n if (typeof value === \"string\") return '\"\"';\n if (typeof value === \"number\") return \"number\";\n if (typeof value === \"boolean\") return \"bool\";\n if (typeof value === \"function\") return \"function\";\n if (value === null) return \"null\";\n if (Array.isArray(value)) {\n if (value.length) return \"[\" + getTypeString(value[0]) + \"]\";\n else return \"[]\";\n }\n if (typeof value === \"object\") return \"{...}\";\n return typeof value;\n}\n\n/**\n * Creates a colored visualization of a JSON object's structure\n * Shows the shape and types of the data rather than actual values\n * Recursively processes nested objects and arrays\n * @param {object} obj - The JSON object to visualize\n * @param {number} indent - The number of spaces to indent the object\n * @param {ColorFormat} colorFormat - The color format to use\n * @returns {string} The colored visualization of the JSON object\n */\nexport function printJSONStructure(obj, indent = 0, colorFormat: 'html' | 'ansi' = 'ansi') {\n const colors = getColors(colorFormat);\n const pad = \" \".repeat(indent);\n var result = \"\";\n // Handle primitive values and null\n if (typeof obj !== \"object\" || obj === null) {\n const color = getColorForType(obj);\n return color + getTypeString(obj) + colors.reset;\n }\n // Handle arrays with special bracket formatting\n if (Array.isArray(obj)) {\n result = colors.blue + \"[\" + colors.reset;\n if (obj.length) result += \"\\n\";\n // if array has items all of the same type or object types, print only once\n if (obj.every((item) => typeof item === typeof obj[0])) {\n result += pad + \" \" + printJSONStructure(obj[0], indent + 1);\n result += \",\";\n result += \"\\n\";\n } else {\n obj.forEach((item, idx) => {\n result += pad + \" \" + printJSONStructure(item, indent + 1);\n if (idx < obj.length - 1) result += \",\";\n result += \"\\n\";\n });\n result += pad + colors.blue + \"]\" + colors.reset;\n return result;\n }\n }\n\n // Handle objects with special brace and property formatting\n result = colors.green + \"{\" + colors.reset;\n const keys = Object.keys(obj);\n if (keys.length) result += \"\\n\";\n keys.forEach((key, index) => {\n const value = obj[key];\n const color = getColorForType(value);\n result += pad + \" \";\n\n // Handle nested objects recursively\n if (typeof value === \"object\" && value !== null && !Array.isArray(value)) {\n result +=\n color +\n key +\n colors.reset +\n \": \" +\n printJSONStructure(value, indent + 1);\n }\n // Handle nested arrays recursively\n else if (Array.isArray(value)) {\n result +=\n color +\n key +\n colors.reset +\n \": \" +\n printJSONStructure(value, indent + 1);\n }\n // Handle primitive values\n else {\n result += color + key + \": \" + getTypeString(value) + colors.reset;\n }\n if (index < keys.length - 1) result += \",\";\n result += \"\\n\";\n });\n result += pad + colors.green + \"}\" + colors.reset;\n\n // Only log at top level of recursion\n if (indent === 0) {\n // console.log(result);\n }\n return result;\n}\n\n"],"names":["ColorName"],"mappings":"AAYO,SAAS,IAAI,UAA0B,IAAI,UAAsB,CAAA,GAAI;AAC1E,MAAI;AAAA,IACF;AAAA,IACA,QAAQ;AAAA,IACR,mBAAmB;AAAA,IACnB,eAAe;AAAA,IACf,cAAc;AAAA,EAAA,IACZ;AACJ,QAAM,SAAS,UAAA;AAGf,MAAI,OAAO,qBAAqB;AAC9B,uBACE,OAAO,WAAW,eAClB,QAAQ,SAAS,SAAS,SAAS,WAAW;AAGlD,MAAI,OAAO,YAAY;AACrB,cACE,mBAAmB,OAAO,IAAI,SAAS,KAAK,UAAU,SAAS,MAAM,CAAC;AAG1E,MAAI,MAAM,QAAQ,KAAK,KAAK,MAAM,UAAU,EAAG,SAAQ,MAAM,CAAC;AAG9D,MAAI,SAAS,OAAO,YAAY,QAAA;AAC9B,QAAI,QAAQ,SAAS,IAAI,KAAK,MAAM,QAAQ,KAAK;AAC/C,gBAAU,QAAQ,QAAQ,OAAO,CAAC,OAAO,UAAU,OAAO,MAAM,KAAK,CAAC,KAAK,EAAE;AAAA,aACtE,SAAS,OAAO,UAAU;AACjC,iBAAW,OAAO,KAAK,KAAK,MAAM,UAAU,OAAO;AAAA,EAAA;AAKvD,MAAI,IAAI;AAER,MAAI;AACF,KAAC,UAAU,YAAY,WAAW,YAAY,MAAM;A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OAAO,SAAS,CAAC;AAAA,IACxC,WAES,MAAM,QAAQ,KAAK,GAAG;AAC7B,gBACE,QACA,MACA,OAAO,QACP,OACA,mBAAmB,OAAO,SAAS,CAAC;AAAA,IACxC,OAEK;AACH,gBAAU,QAAQ,MAAM,OAAO,cAAc,KAAK,IAAI,OAAO;AAAA,IAC/D;AACA,QAAI,QAAQ,KAAK,SAAS,EAAG,WAAU;AACvC,cAAU;AAAA,EACZ,CAAC;AACD,YAAU,MAAM,OAAO,QAAQ,MAAM,OAAO;AAM5C,SAAO;AACT;"}
|
|
1
|
+
{"version":3,"file":"log.es.js","sources":["../src/log-json.ts"],"sourcesContent":["/**\n * ### Colorized Log With JSON Structure\n * \n * Logs messages to the console with custom styling,\n * prints JSON with description of structure layout,\n * and showing debug output in development only.\n * @param {string|object} message - The message to log. If an object is provided, it will be stringified.\n * @param {string|string[]} [options.style] default='color: blue; font-size: 11pt;' - CSS style string\n * @param {boolean} [options.hideInProduction] - default = auto-detects based on hostname.\n * If true, uses `console.debug` (hidden in production). If false, uses `console.log`.\n *\n */\nexport function log(message: string|object = \"\", options: LogOptions = {}) {\n let {\n color,\n style = \"color:rgb(54, 165, 220); font-size: 10pt;\",\n hideInProduction = undefined,\n startSpinner = false,\n stopSpinner = false,\n } = options;\n const colors = getColors();\n\n // Auto-detect if we should hide logs in production based on hostname\n if (typeof hideInProduction === \"undefined\")\n hideInProduction =\n typeof window !== \"undefined\" &&\n window?.location.hostname.includes(\"localhost\");\n\n // For objects, print both the structure visualization and full JSON\n if (typeof message === \"object\")\n message =\n printJSONStructure(message) + \"\\n\\n\" + JSON.stringify(message, null, 2);\n\n // change color: [red] to color: red if only one\n if (Array.isArray(color) && color.length == 1) color = color[0];\n\n //colorize in terminal (%c is only in browser but we polyfill it)\n if (color && typeof process !== undefined)\n if (message.includes(\"%c\") && Array.isArray(color)) // replace each c with color[i]\n message = message.replace(/%c/g, (match, index) => colors[color[index]] || \"\");\n else if (color && typeof color === \"string\")\n message = (colors[color] || \"\") + message + colors.reset;\n\n\n\n // Displays an animated spinner in the terminal with the provided text.\n var i = 0;\n\n if (startSpinner)\n (global || globalThis).interval = setInterval(() => {\n process.stdout.write(\n (Array.isArray(color) ? colors[color[0]] : colors[color] || \"\") +\n \"\\r\" +\n \"⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏\".split(\"\")[(i = ++i % 10)] +\n \" \" +\n message +\n colors.reset\n );\n }, 50);\n else if (stopSpinner) {\n clearInterval((global || globalThis).interval);\n process.stdout.write(\n \"\\r\" + (message || \" \") + \" \".repeat(message.length + 20) + \"\\n\"\n );\n } else if (typeof style === \"string\") {\n // check if style is a one word color code or named color\n //test if style is valid as a CSS color name\n if (style.split(\" \").length == 1 || color) {\n style = `color: ${color || style}; font-size: 11pt;`;\n } else {\n // check if style is valid as a CSS color code\n if (style.match(/^#[0-9a-fA-F]{6}$/)) {\n style = `color: ${style}; font-size: 11pt;`;\n }\n }\n // Use console.debug for production-hidden logs, console.log otherwise\n if (hideInProduction)\n console.debug((style ? \"%c\" : \"\") + (message || \"\"), style);\n else console.log((style ? \"%c\" : \"\") + (message || \"\"), style);\n } else if (typeof style === \"object\") console.log(message, ...(style as any));\n return true;\n}\n\nexport interface LogOptions {\n /** CSS style string or array of CSS strings for browser console styling */\n style?: string | string[];\n /** Optional color name or code for terminal environments */\n color?: ColorName | ColorName[] | string | string[] ;\n /** If true, hides log in production (auto-detects by hostname if undefined) */\n hideInProduction?: boolean;\n /** Start a spinner (for CLI tools, optional) */\n startSpinner?: boolean;\n /** Stop a spinner (for CLI tools, optional) */\n stopSpinner?: boolean;\n}\n\n/**\n * Available color names\n */\nexport enum ColorName {\n RESET = 'reset',\n BLACK = 'black',\n RED = 'red',\n GREEN = 'green',\n YELLOW = 'yellow',\n BLUE = 'blue',\n MAGENTA = 'magenta',\n CYAN = 'cyan',\n WHITE = 'white',\n GRAY = 'gray',\n BRIGHT_RED = 'brightRed',\n BRIGHT_GREEN = 'brightGreen',\n BRIGHT_YELLOW = 'brightYellow',\n BRIGHT_BLUE = 'brightBlue',\n BRIGHT_MAGENTA = 'brightMagenta',\n BRIGHT_CYAN = 'brightCyan',\n BRIGHT_WHITE = 'brightWhite',\n BG_RED = 'bgRed',\n BG_GREEN = 'bgGreen',\n BG_YELLOW = 'bgYellow',\n BG_BLUE = 'bgBlue',\n BG_MAGENTA = 'bgMagenta',\n BG_CYAN = 'bgCyan',\n BG_WHITE = 'bgWhite',\n BG_GRAY = 'bgGray',\n BG_BLACK = 'bgBlack',\n BG_BRIGHT_RED = 'bgBrightRed',\n BG_BRIGHT_GREEN = 'bgBrightGreen',\n BG_BRIGHT_YELLOW = 'bgBrightYellow',\n BG_BRIGHT_BLUE = 'bgBrightBlue',\n BG_BRIGHT_MAGENTA = 'bgBrightMagenta',\n BG_BRIGHT_CYAN = 'bgBrightCyan',\n BG_BRIGHT_WHITE = 'bgBrightWhite',\n}\n\n/**\n * Color mapping with ANSI codes and HTML hex values\n * @type {Record<ColorName, [number, string]>}\n * @description Maps color names to [ansiCode, hexValue] pairs\n * - ansiCode: ANSI escape sequence number for terminal colors\n * - hexValue: Hex color value (without #) for HTML/CSS\n */\nconst colorMap: Record<ColorName, [number, string]> = {\n [ColorName.RESET]: [0, '000000'],\n [ColorName.BLACK]: [30, '000000'],\n [ColorName.RED]: [31, 'ff0000'],\n [ColorName.GREEN]: [32, '00ff00'],\n [ColorName.YELLOW]: [33, 'ffff00'],\n [ColorName.BLUE]: [34, '0000ff'],\n [ColorName.MAGENTA]: [35, 'ff00ff'],\n [ColorName.CYAN]: [36, '00ffff'],\n [ColorName.WHITE]: [37, 'ffffff'],\n [ColorName.GRAY]: [90, '808080'],\n [ColorName.BRIGHT_RED]: [91, 'ff5555'],\n [ColorName.BRIGHT_GREEN]: [92, '55ff55'],\n [ColorName.BRIGHT_YELLOW]: [93, 'ffff55'],\n [ColorName.BRIGHT_BLUE]: [94, '5555ff'],\n [ColorName.BRIGHT_MAGENTA]: [95, 'ff55ff'],\n [ColorName.BRIGHT_CYAN]: [96, '55ffff'],\n [ColorName.BRIGHT_WHITE]: [97, 'ffffff'],\n [ColorName.BG_BLACK]: [40, '000000'],\n [ColorName.BG_RED]: [41, 'ff0000'],\n [ColorName.BG_GREEN]: [42, '00ff00'],\n [ColorName.BG_YELLOW]: [43, 'ffff00'],\n [ColorName.BG_BLUE]: [44, '0000ff'],\n [ColorName.BG_MAGENTA]: [45, 'ff00ff'],\n [ColorName.BG_CYAN]: [46, '00ffff'],\n [ColorName.BG_WHITE]: [47, 'ffffff'],\n [ColorName.BG_GRAY]: [100, '808080'],\n [ColorName.BG_BRIGHT_RED]: [101, 'ff8888'],\n [ColorName.BG_BRIGHT_GREEN]: [102, '88ff88'],\n [ColorName.BG_BRIGHT_YELLOW]: [103, 'ffff88'],\n [ColorName.BG_BRIGHT_BLUE]: [104, '8888ff'],\n [ColorName.BG_BRIGHT_MAGENTA]: [105, 'ff88ff'],\n [ColorName.BG_BRIGHT_CYAN]: [106, '88ffff'],\n [ColorName.BG_BRIGHT_WHITE]: [107, 'ffffff'],\n};\n\n/**\n * Returns color codes based on the specified format\n * @param format - Output format for colors\n * - 'ansi': Returns ANSI escape codes (e.g., '\\x1b[31m')\n * - 'html': Returns HTML hex colors (e.g., '#ff0000')\n * @returns Object with color names as keys and color codes as values\n */\nexport function getColors(format: 'html' | 'ansi' = 'ansi'): Record<ColorName, string> {\n const colors: Record<ColorName, string> = {} as Record<ColorName, string>;\n for (const [name, [ansiCode, hexCode]] of Object.entries(colorMap)) {\n colors[name] = format === 'html' ? '#' + hexCode : '\\x1b[' + ansiCode + 'm';\n }\n return colors;\n}\n\n/**\n * Determines the appropriate color code for a given value type\n * Used for consistent color coding in the structure visualization\n */\nfunction getColorForType(value) {\n const colors = getColors();\n if (typeof value === \"string\") return colors.yellow;\n if (typeof value === \"number\") return colors.cyan;\n if (typeof value === \"boolean\") return colors.magenta;\n if (typeof value === \"function\") return colors.red;\n if (value === null) return colors.gray;\n if (Array.isArray(value)) return colors.blue;\n if (typeof value === \"object\") return colors.green;\n return colors.white;\n}\n\n/**\n * Returns a string representation of the value's type\n * Used to show simplified type information in the structure visualization\n */\nfunction getTypeString(value) {\n if (typeof value === \"string\") return '\"\"';\n if (typeof value === \"number\") return \"number\";\n if (typeof value === \"boolean\") return \"bool\";\n if (typeof value === \"function\") return \"function\";\n if (value === null) return \"null\";\n if (Array.isArray(value)) {\n if (value.length) return \"[\" + getTypeString(value[0]) + \"]\";\n else return \"[]\";\n }\n if (typeof value === \"object\") return \"{...}\";\n return typeof value;\n}\n\n/**\n * Creates a colored visualization of a JSON object's structure\n * Shows the shape and types of the data rather than actual values\n * Recursively processes nested objects and arrays\n * @param {object} obj - The JSON object to visualize\n * @param {number} indent - The number of spaces to indent the object\n * @param {ColorFormat} colorFormat - The color format to use\n * @returns {string} The colored visualization of the JSON object\n */\nexport function printJSONStructure(obj, indent = 0, colorFormat: 'html' | 'ansi' = 'ansi') {\n const colors = getColors(colorFormat);\n const pad = \" \".repeat(indent);\n var result = \"\";\n // Handle primitive values and null\n if (typeof obj !== \"object\" || obj === null) {\n const color = getColorForType(obj);\n return color + getTypeString(obj) + colors.reset;\n }\n // Handle arrays with special bracket formatting\n if (Array.isArray(obj)) {\n result = colors.blue + \"[\" + colors.reset;\n if (obj.length) result += \"\\n\";\n // if array has items all of the same type or object types, print only once\n if (obj.every((item) => typeof item === typeof obj[0])) {\n result += pad + \" \" + printJSONStructure(obj[0], indent + 1);\n result += \",\";\n result += \"\\n\";\n } else {\n obj.forEach((item, idx) => {\n result += pad + \" \" + printJSONStructure(item, indent + 1);\n if (idx < obj.length - 1) result += \",\";\n result += \"\\n\";\n });\n result += pad + colors.blue + \"]\" + colors.reset;\n return result;\n }\n }\n\n // Handle objects with special brace and property formatting\n result = colors.green + \"{\" + colors.reset;\n const keys = Object.keys(obj);\n if (keys.length) result += \"\\n\";\n keys.forEach((key, index) => {\n const value = obj[key];\n const color = getColorForType(value);\n result += pad + \" \";\n\n // Handle nested objects recursively\n if (typeof value === \"object\" && value !== null && !Array.isArray(value)) {\n result +=\n color +\n key +\n colors.reset +\n \": \" +\n printJSONStructure(value, indent + 1);\n }\n // Handle nested arrays recursively\n else if (Array.isArray(value)) {\n result +=\n color +\n key +\n colors.reset +\n \": \" +\n printJSONStructure(value, indent + 1);\n }\n // Handle primitive values\n else {\n result += color + key + \": \" + getTypeString(value) + colors.reset;\n }\n if (index < keys.length - 1) result += \",\";\n result += \"\\n\";\n });\n result += pad + colors.green + \"}\" + colors.reset;\n\n // Only log at top level of recursion\n if (indent === 0) {\n // console.log(result);\n }\n return result;\n}\n\n"],"names":["log","message","options","color","style","hideInProduction","startSpinner","stopSpinner","colors","getColors","window","location","hostname","includes","printJSONStructure","JSON","stringify","Array","isArray","length","process","replace","match","index","reset","i","global","globalThis","interval","setInterval","stdout","write","split","clearInterval","repeat","console","debug","ColorName","colorMap","black","red","green","yellow","blue","magenta","cyan","white","gray","brightRed","brightGreen","brightYellow","brightBlue","brightMagenta","brightCyan","brightWhite","bgBlack","bgRed","bgGreen","bgYellow","bgBlue","bgMagenta","bgCyan","bgWhite","bgGray","bgBrightRed","bgBrightGreen","bgBrightYellow","bgBrightBlue","bgBrightMagenta","bgBrightCyan","bgBrightWhite","format","name","ansiCode","hexCode","Object","entries","getColorForType","value","getTypeString","obj","indent","colorFormat","pad","result","every","item","forEach","idx","keys","key"],"mappings":"AAYO,SAASA,EAAIC,EAA0B,GAAIC,EAAsB,CAAA,GACtE,IAAIC,MACFA,EAAAC,MACAA,EAAQ,4CAAAC,iBACRA,EAAmBC,aACnBA,GAAe,EAAAC,YACfA,GAAc,GACZL,EACJ,MAAMM,EAASC,SAGiB,IAArBJ,IACTA,EACoB,oBAAXK,QACPA,QAAQC,SAASC,SAASC,SAAS,cAGhB,iBAAZZ,IACTA,EACEa,EAAmBb,GAAW,OAASc,KAAKC,UAAUf,EAAS,KAAM,IAGrEgB,MAAMC,QAAQf,IAA0B,GAAhBA,EAAMgB,SAAahB,EA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GAAUD,EAAM,KAAOrE,EAAmBwE,EAAML,EAAS,GACrDO,EAAMR,EAAI7D,OAAS,IAAGiE,GAAU,KACpCA,GAAU,OAEZA,GAAUD,EAAM3E,EAAOmC,KAAO,IAAMnC,EAAOgB,MATzC4D,GAAUD,EAAM,KAAOrE,EAAmBkE,EAAI,GAAIC,EAAS,GAC3DG,GAAU,IACVA,GAAU,IAUd,CAGAA,EAAS5E,EAAOiC,MAAQ,IAAMjC,EAAOgB,MACrC,MAAMiE,EAAOd,OAAOc,KAAKT,GAsCzB,OArCIS,EAAKtE,SAAQiE,GAAU,MAC3BK,EAAKF,QAAQ,CAACG,EAAKnE,KACjB,MAAMuD,EAAQE,EAAIU,GACZvF,EAAQ0E,EAAgBC,GAC9BM,GAAUD,EAAM,KAGK,iBAAVL,GAAgC,OAAVA,GAAmB7D,MAAMC,QAAQ4D,GASzD7D,MAAMC,QAAQ4D,GACrBM,GACEjF,EACAuF,EACAlF,EAAOgB,MACP,KACAV,EAAmBgE,EAAOG,EAAS,GAIrCG,GAAUjF,EAAQuF,EAAM,KAAOX,EAAcD,GAAStE,EAAOgB,MAlB7D4D,GACEjF,EACAuF,EACAlF,EAAOgB,MACP,KACAV,EAAmBgE,EAAOG,EAAS,GAenC1D,EAAQkE,EAAKtE,OAAS,IAAGiE,GAAU,KACvCA,GAAU,OAEZA,GAAUD,EAAM3E,EAAOiC,MAAQ,IAAMjC,EAAOgB,KAO9C"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "grab-url",
|
|
3
3
|
"description": "📥 Generate Request to API from Browser",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "1.0.
|
|
5
|
+
"version": "1.0.17",
|
|
6
6
|
"author": "vtempest",
|
|
7
7
|
"license": "rights.institute/prosper",
|
|
8
8
|
"repository": {
|
|
@@ -76,6 +76,7 @@
|
|
|
76
76
|
"http"
|
|
77
77
|
],
|
|
78
78
|
"dependencies": {
|
|
79
|
+
"@types/node": "^25.0.3",
|
|
79
80
|
"chalk": "^5.6.2",
|
|
80
81
|
"cli-progress": "^3.12.0",
|
|
81
82
|
"cli-spinners": "^3.2.1",
|
package/readme.md
CHANGED
package/src/grab-api.ts
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* ### GRAB: Generate Request to API from Browser
|
|
9
|
-
* 
|
|
10
10
|
*
|
|
11
11
|
* 1. **GRAB is the FBEST Request Manager: Functionally Brilliant, Elegantly Simple Tool**: One Function, no dependencies,
|
|
12
12
|
* minimalist syntax, [more features than alternatives](https://grab.js.org/docs/Comparisons)
|
|
@@ -67,16 +67,16 @@ import {
|
|
|
67
67
|
*/
|
|
68
68
|
export default async function grab<TResponse = any, TParams = any>(
|
|
69
69
|
path: string,
|
|
70
|
-
options
|
|
70
|
+
options?: GrabOptions<TResponse, TParams>
|
|
71
71
|
): Promise<GrabResponse<TResponse>> {
|
|
72
72
|
var {
|
|
73
73
|
headers,
|
|
74
74
|
response = {} as any, // Pre-initialized object to set the response in. isLoading and error are also set on this object.
|
|
75
|
-
method = options
|
|
75
|
+
method = options?.post // set post: true for POST, omit for GET
|
|
76
76
|
? "POST"
|
|
77
|
-
: options
|
|
77
|
+
: options?.put
|
|
78
78
|
? "PUT"
|
|
79
|
-
: options
|
|
79
|
+
: options?.patch
|
|
80
80
|
? "PATCH"
|
|
81
81
|
: "GET",
|
|
82
82
|
cache = false, // Enable/disable frontend caching
|
|
@@ -112,7 +112,7 @@ export default async function grab<TResponse = any, TParams = any>(
|
|
|
112
112
|
// Destructure options with defaults, merging with any globally set defaults
|
|
113
113
|
...(typeof window !== "undefined"
|
|
114
114
|
? window?.grab?.defaults
|
|
115
|
-
: (
|
|
115
|
+
: (globalThis)?.grab?.defaults || {}),
|
|
116
116
|
...options,
|
|
117
117
|
};
|
|
118
118
|
|
|
@@ -151,8 +151,8 @@ export default async function grab<TResponse = any, TParams = any>(
|
|
|
151
151
|
if (options?.setDefaults) {
|
|
152
152
|
if (typeof window !== "undefined")
|
|
153
153
|
window.grab.defaults = { ...options, setDefaults: undefined };
|
|
154
|
-
else if (typeof
|
|
155
|
-
|
|
154
|
+
else if (typeof globalThis.grab !== "undefined")
|
|
155
|
+
globalThis.grab.defaults = {
|
|
156
156
|
...options,
|
|
157
157
|
setDefaults: undefined,
|
|
158
158
|
};
|
|
@@ -534,12 +534,6 @@ if (typeof window !== "undefined") {
|
|
|
534
534
|
document.querySelector(paginateElement).scrollTop = scrollTop;
|
|
535
535
|
document.querySelector(paginateElement).scrollLeft = scrollLeft;
|
|
536
536
|
});
|
|
537
|
-
} else if (typeof global !== "undefined") {
|
|
538
|
-
grab.log = [];
|
|
539
|
-
grab.mock = {};
|
|
540
|
-
grab.defaults = {};
|
|
541
|
-
global.log = log;
|
|
542
|
-
global.grab = grab.instance();
|
|
543
537
|
} else if (typeof globalThis !== "undefined") {
|
|
544
538
|
grab.log = [];
|
|
545
539
|
grab.mock = {};
|
|
@@ -740,7 +734,7 @@ export interface GrabGlobal {
|
|
|
740
734
|
export interface GrabFunction {
|
|
741
735
|
/**
|
|
742
736
|
* ### GRAB: Generate Request to API from Browser
|
|
743
|
-
* 
|
|
744
738
|
* Make API request with path
|
|
745
739
|
* @returns {Promise<Object>} The response object with resulting data or .error if error.
|
|
746
740
|
* @author [vtempest (2025)](https://github.com/vtempest/GRAB-URL)
|
|
@@ -752,7 +746,7 @@ export interface GrabFunction {
|
|
|
752
746
|
|
|
753
747
|
/**
|
|
754
748
|
* ### GRAB: Generate Request to API from Browser
|
|
755
|
-
* 
|
|
756
750
|
* Make API request with path and options/parameters
|
|
757
751
|
* @returns {Promise<Object>} The response object with resulting data or .error if error.
|
|
758
752
|
* @author [vtempest (2025)](https://github.com/vtempest/GRAB-URL)
|
package/src/grab-url.js
CHANGED
|
File without changes
|
|
File without changes
|
package/src/icons/svg/index.ts
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/src/log-json.ts
CHANGED
|
File without changes
|