@choksheak/ts-utils 0.3.3 → 0.3.5
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/README.md +9 -3
- package/asNumber.cjs +6 -6
- package/asNumber.d.mts +1 -1
- package/asNumber.d.ts +1 -1
- package/asNumber.min.cjs +1 -1
- package/asNumber.min.cjs.map +1 -1
- package/asNumber.min.mjs +1 -1
- package/asNumber.min.mjs.map +1 -1
- package/asNumber.mjs +6 -6
- package/capLength.cjs +80 -0
- package/capLength.d.mts +3 -0
- package/capLength.d.ts +3 -0
- package/capLength.min.cjs +6 -0
- package/capLength.min.cjs.map +1 -0
- package/capLength.min.mjs +6 -0
- package/capLength.min.mjs.map +1 -0
- package/capLength.mjs +53 -0
- package/{iterators.cjs → concatIterators.cjs} +4 -4
- package/{iterators.min.cjs → concatIterators.min.cjs} +1 -1
- package/concatIterators.min.cjs.map +1 -0
- package/{iterators.min.mjs → concatIterators.min.mjs} +1 -1
- package/concatIterators.min.mjs.map +1 -0
- package/{iterators.mjs → concatIterators.mjs} +1 -1
- package/duration.min.cjs +1 -1
- package/duration.min.mjs +1 -1
- package/kvStore.cjs +230 -239
- package/kvStore.d.mts +142 -44
- package/kvStore.d.ts +142 -44
- package/kvStore.min.cjs +1 -1
- package/kvStore.min.cjs.map +1 -1
- package/kvStore.min.mjs +1 -1
- package/kvStore.min.mjs.map +1 -1
- package/kvStore.mjs +229 -237
- package/localStore.cjs +187 -186
- package/localStore.d.mts +135 -34
- package/localStore.d.ts +135 -34
- package/localStore.min.cjs +1 -1
- package/localStore.min.cjs.map +1 -1
- package/localStore.min.mjs +1 -1
- package/localStore.min.mjs.map +1 -1
- package/localStore.mjs +186 -184
- package/mean.cjs +6 -6
- package/mean.min.cjs +1 -1
- package/mean.min.cjs.map +1 -1
- package/mean.min.mjs +1 -1
- package/mean.min.mjs.map +1 -1
- package/mean.mjs +6 -6
- package/median.cjs +7 -7
- package/median.min.cjs +1 -1
- package/median.min.cjs.map +1 -1
- package/median.min.mjs +1 -1
- package/median.min.mjs.map +1 -1
- package/median.mjs +7 -7
- package/package.json +67 -82
- package/round.cjs +2 -10
- package/round.d.mts +2 -8
- package/round.d.ts +2 -8
- package/round.min.cjs +1 -1
- package/round.min.cjs.map +1 -1
- package/round.min.mjs +1 -1
- package/round.min.mjs.map +1 -1
- package/round.mjs +1 -8
- package/{safeParseInt.cjs → roundToString.cjs} +19 -9
- package/roundToString.d.mts +8 -0
- package/roundToString.d.ts +8 -0
- package/roundToString.min.cjs +2 -0
- package/roundToString.min.cjs.map +1 -0
- package/roundToString.min.mjs +2 -0
- package/roundToString.min.mjs.map +1 -0
- package/roundToString.mjs +16 -0
- package/safeBtoa.d.mts +7 -0
- package/safeBtoa.d.ts +7 -0
- package/safeBtoa.min.cjs.map +1 -1
- package/safeBtoa.min.mjs.map +1 -1
- package/sum.cjs +6 -6
- package/sum.min.cjs +1 -1
- package/sum.min.cjs.map +1 -1
- package/sum.min.mjs +1 -1
- package/sum.min.mjs.map +1 -1
- package/sum.mjs +6 -6
- package/timer.cjs +19 -24
- package/timer.d.mts +9 -6
- package/timer.d.ts +9 -6
- package/timer.min.cjs +1 -1
- package/timer.min.cjs.map +1 -1
- package/timer.min.mjs +1 -1
- package/timer.min.mjs.map +1 -1
- package/timer.mjs +19 -23
- package/toReadableString.cjs +69 -0
- package/toReadableString.d.mts +10 -0
- package/toReadableString.d.ts +10 -0
- package/toReadableString.min.cjs +6 -0
- package/toReadableString.min.cjs.map +1 -0
- package/toReadableString.min.mjs +6 -0
- package/toReadableString.min.mjs.map +1 -0
- package/toReadableString.mjs +44 -0
- package/average.cjs +0 -55
- package/average.d.mts +0 -7
- package/average.d.ts +0 -7
- package/average.min.cjs +0 -2
- package/average.min.cjs.map +0 -1
- package/average.min.mjs +0 -2
- package/average.min.mjs.map +0 -1
- package/average.mjs +0 -28
- package/iterators.min.cjs.map +0 -1
- package/iterators.min.mjs.map +0 -1
- package/logging.cjs +0 -47
- package/logging.d.mts +0 -4
- package/logging.d.ts +0 -4
- package/logging.min.cjs +0 -2
- package/logging.min.cjs.map +0 -1
- package/logging.min.mjs +0 -2
- package/logging.min.mjs.map +0 -1
- package/logging.mjs +0 -21
- package/safeParseFloat.cjs +0 -33
- package/safeParseFloat.d.mts +0 -6
- package/safeParseFloat.d.ts +0 -6
- package/safeParseFloat.min.cjs +0 -2
- package/safeParseFloat.min.cjs.map +0 -1
- package/safeParseFloat.min.mjs +0 -2
- package/safeParseFloat.min.mjs.map +0 -1
- package/safeParseFloat.mjs +0 -8
- package/safeParseInt.d.mts +0 -6
- package/safeParseInt.d.ts +0 -6
- package/safeParseInt.min.cjs +0 -2
- package/safeParseInt.min.cjs.map +0 -1
- package/safeParseInt.min.mjs +0 -2
- package/safeParseInt.min.mjs.map +0 -1
- package/safeParseInt.mjs +0 -8
- /package/{iterators.d.mts → concatIterators.d.mts} +0 -0
- /package/{iterators.d.ts → concatIterators.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
# @choksheak/ts-utils
|
|
2
2
|
|
|
3
|
-
This package is a
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
This package is a time-tested collection of Typescript utilities that I have
|
|
4
|
+
personally needed in almost every project that I have worked in. Making this an
|
|
5
|
+
open source, public npm package allows me to share this code freely with others
|
|
6
|
+
as well as using it for my own personal and professional projects. Feel free to
|
|
7
|
+
use it in your own projects without any restrictions.
|
|
8
|
+
|
|
9
|
+
The code supports full tree-shaking. Therefore your code will only grow in size
|
|
10
|
+
by whatever you use. Any code that you are not using will not contribute to
|
|
11
|
+
your code size.
|
|
6
12
|
|
|
7
13
|
Source code: https://github.com/choksheak/ts-utils
|
|
8
14
|
|
package/asNumber.cjs
CHANGED
|
@@ -23,15 +23,15 @@ __export(asNumber_exports, {
|
|
|
23
23
|
asNumber: () => asNumber
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(asNumber_exports);
|
|
26
|
-
function asNumber(u) {
|
|
26
|
+
function asNumber(u, defaultValue = 0) {
|
|
27
|
+
if (typeof u === "number") {
|
|
28
|
+
return isFinite(u) ? u : defaultValue;
|
|
29
|
+
}
|
|
30
|
+
u = Number(u);
|
|
27
31
|
if (typeof u === "number" && isFinite(u)) {
|
|
28
32
|
return u;
|
|
29
33
|
}
|
|
30
|
-
|
|
31
|
-
if (typeof n === "number" && isFinite(n)) {
|
|
32
|
-
return n;
|
|
33
|
-
}
|
|
34
|
-
return 0;
|
|
34
|
+
return defaultValue;
|
|
35
35
|
}
|
|
36
36
|
// Annotate the CommonJS export names for ESM import in node:
|
|
37
37
|
0 && (module.exports = {
|
package/asNumber.d.mts
CHANGED
package/asNumber.d.ts
CHANGED
package/asNumber.min.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var t=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var o=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var p=(n,r)=>{for(var i in r)t(n,i,{get:r[i],enumerable:!0})},s=(n,r,i,b)=>{if(r&&typeof r=="object"||typeof r=="function")for(let e of o(r))!f.call(n,e)&&e!==i&&t(n,e,{get:()=>r[e],enumerable:!(b=m(r,e))||b.enumerable});return n};var y=n=>s(t({},"__esModule",{value:!0}),n);var N={};p(N,{asNumber:()=>F});module.exports=y(N);function F(n,r=0){return typeof n=="number"?isFinite(n)?n:r:(n=Number(n),typeof n=="number"&&isFinite(n)?n:r)}0&&(module.exports={asNumber});
|
|
2
2
|
//# sourceMappingURL=asNumber.min.cjs.map
|
package/asNumber.min.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/asNumber.ts"],"sourcesContent":["/**\n * Coerce `u` into a number if possible, otherwise just return 0.\n */\nexport function asNumber(u: unknown): number {\n //
|
|
1
|
+
{"version":3,"sources":["../src/asNumber.ts"],"sourcesContent":["/**\n * Coerce `u` into a number if possible, otherwise just return 0.\n */\nexport function asNumber(u: unknown, defaultValue = 0): number {\n // If u is a valid number, return it.\n if (typeof u === \"number\") {\n return isFinite(u) ? u : defaultValue;\n }\n\n // Try to make into a number if not already a number.\n u = Number(u);\n\n // If u is a valid number, return it.\n if (typeof u === \"number\" && isFinite(u)) {\n return u;\n }\n\n // Return `defaultValue` for everything else. This is usually ok if want to\n // just ignore all other noise.\n return defaultValue;\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,cAAAE,IAAA,eAAAC,EAAAH,GAGO,SAASE,EAASE,EAAYC,EAAe,EAAW,CAE7D,OAAI,OAAOD,GAAM,SACR,SAASA,CAAC,EAAIA,EAAIC,GAI3BD,EAAI,OAAOA,CAAC,EAGR,OAAOA,GAAM,UAAY,SAASA,CAAC,EAC9BA,EAKFC,EACT","names":["asNumber_exports","__export","asNumber","__toCommonJS","u","defaultValue"]}
|
package/asNumber.min.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function
|
|
1
|
+
function e(n,r=0){return typeof n=="number"?isFinite(n)?n:r:(n=Number(n),typeof n=="number"&&isFinite(n)?n:r)}export{e as asNumber};
|
|
2
2
|
//# sourceMappingURL=asNumber.min.mjs.map
|
package/asNumber.min.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/asNumber.ts"],"sourcesContent":["/**\n * Coerce `u` into a number if possible, otherwise just return 0.\n */\nexport function asNumber(u: unknown): number {\n //
|
|
1
|
+
{"version":3,"sources":["../src/asNumber.ts"],"sourcesContent":["/**\n * Coerce `u` into a number if possible, otherwise just return 0.\n */\nexport function asNumber(u: unknown, defaultValue = 0): number {\n // If u is a valid number, return it.\n if (typeof u === \"number\") {\n return isFinite(u) ? u : defaultValue;\n }\n\n // Try to make into a number if not already a number.\n u = Number(u);\n\n // If u is a valid number, return it.\n if (typeof u === \"number\" && isFinite(u)) {\n return u;\n }\n\n // Return `defaultValue` for everything else. This is usually ok if want to\n // just ignore all other noise.\n return defaultValue;\n}\n"],"mappings":"AAGO,SAASA,EAASC,EAAYC,EAAe,EAAW,CAE7D,OAAI,OAAOD,GAAM,SACR,SAASA,CAAC,EAAIA,EAAIC,GAI3BD,EAAI,OAAOA,CAAC,EAGR,OAAOA,GAAM,UAAY,SAASA,CAAC,EAC9BA,EAKFC,EACT","names":["asNumber","u","defaultValue"]}
|
package/asNumber.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// src/asNumber.ts
|
|
2
|
-
function asNumber(u) {
|
|
2
|
+
function asNumber(u, defaultValue = 0) {
|
|
3
|
+
if (typeof u === "number") {
|
|
4
|
+
return isFinite(u) ? u : defaultValue;
|
|
5
|
+
}
|
|
6
|
+
u = Number(u);
|
|
3
7
|
if (typeof u === "number" && isFinite(u)) {
|
|
4
8
|
return u;
|
|
5
9
|
}
|
|
6
|
-
|
|
7
|
-
if (typeof n === "number" && isFinite(n)) {
|
|
8
|
-
return n;
|
|
9
|
-
}
|
|
10
|
-
return 0;
|
|
10
|
+
return defaultValue;
|
|
11
11
|
}
|
|
12
12
|
export {
|
|
13
13
|
asNumber
|
package/capLength.cjs
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/capLength.ts
|
|
21
|
+
var capLength_exports = {};
|
|
22
|
+
__export(capLength_exports, {
|
|
23
|
+
capLength: () => capLength
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(capLength_exports);
|
|
26
|
+
|
|
27
|
+
// src/toReadableString.ts
|
|
28
|
+
function toReadableString(u, options) {
|
|
29
|
+
if (typeof u === "string") {
|
|
30
|
+
return u;
|
|
31
|
+
}
|
|
32
|
+
if (u instanceof Error) {
|
|
33
|
+
const error = u;
|
|
34
|
+
let result = "";
|
|
35
|
+
const errorName = error.name || "Error";
|
|
36
|
+
const errorMessage = error.message || "An error occurred with no message provided.";
|
|
37
|
+
result += `${errorName}: ${errorMessage}`;
|
|
38
|
+
if (options?.includeStack && error.stack) {
|
|
39
|
+
const stack = error.stack.replace(new RegExp(`^${errorName}:.*\\n?`), "").trim();
|
|
40
|
+
if (stack) {
|
|
41
|
+
result += `
|
|
42
|
+
Stack Trace:
|
|
43
|
+
${stack}`;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (options?.includeErrorProps) {
|
|
47
|
+
const customProps = error;
|
|
48
|
+
const additionalInfo = Object.keys(customProps).filter(
|
|
49
|
+
(key) => key !== "name" && key !== "message" && key !== "stack" && typeof customProps[key] !== "function" && typeof customProps[key] !== "object"
|
|
50
|
+
).map((key) => `
|
|
51
|
+
- ${key}: ${customProps[key]}`);
|
|
52
|
+
if (additionalInfo.length > 0) {
|
|
53
|
+
result += `
|
|
54
|
+
Additional Data:${additionalInfo.join("")}`;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
|
+
if (u !== null && typeof u === "object" && u.toString !== Object.prototype.toString) {
|
|
60
|
+
return u.toString();
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
return JSON.stringify(u);
|
|
64
|
+
} catch {
|
|
65
|
+
return String(u);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// src/capLength.ts
|
|
70
|
+
function capLength(u, maxLength = 400) {
|
|
71
|
+
const s = toReadableString(u);
|
|
72
|
+
if (s.length <= maxLength) {
|
|
73
|
+
return s;
|
|
74
|
+
}
|
|
75
|
+
return s.slice(0, maxLength) + ` ... (${s.length - maxLength} more)`;
|
|
76
|
+
}
|
|
77
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
78
|
+
0 && (module.exports = {
|
|
79
|
+
capLength
|
|
80
|
+
});
|
package/capLength.d.mts
ADDED
package/capLength.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";var s=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var u=(r,t)=>{for(var n in t)s(r,n,{get:t[n],enumerable:!0})},m=(r,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of p(t))!d.call(r,e)&&e!==n&&s(r,e,{get:()=>t[e],enumerable:!(i=g(t,e))||i.enumerable});return r};var S=r=>m(s({},"__esModule",{value:!0}),r);var $={};u($,{capLength:()=>b});module.exports=S($);function f(r,t){if(typeof r=="string")return r;if(r instanceof Error){let n=r,i="",e=n.name||"Error",l=n.message||"An error occurred with no message provided.";if(i+=`${e}: ${l}`,t?.includeStack&&n.stack){let c=n.stack.replace(new RegExp(`^${e}:.*\\n?`),"").trim();c&&(i+=`
|
|
2
|
+
Stack Trace:
|
|
3
|
+
${c}`)}if(t?.includeErrorProps){let c=n,a=Object.keys(c).filter(o=>o!=="name"&&o!=="message"&&o!=="stack"&&typeof c[o]!="function"&&typeof c[o]!="object").map(o=>`
|
|
4
|
+
- ${o}: ${c[o]}`);a.length>0&&(i+=`
|
|
5
|
+
Additional Data:${a.join("")}`)}return i}if(r!==null&&typeof r=="object"&&r.toString!==Object.prototype.toString)return r.toString();try{return JSON.stringify(r)}catch{return String(r)}}function b(r,t=400){let n=f(r);return n.length<=t?n:n.slice(0,t)+` ... (${n.length-t} more)`}0&&(module.exports={capLength});
|
|
6
|
+
//# sourceMappingURL=capLength.min.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/capLength.ts","../src/toReadableString.ts"],"sourcesContent":["import { toReadableString } from \"./toReadableString\";\n\nexport function capLength(u: unknown, maxLength = 400): string {\n const s = toReadableString(u);\n\n if (s.length <= maxLength) {\n return s;\n }\n\n return s.slice(0, maxLength) + ` ... (${s.length - maxLength} more)`;\n}\n","/**\n * Make the given argument of unknown type into something human-readable.\n * For Error objects, you can specify options to make the string more verbose.\n */\nexport function toReadableString(\n u: unknown,\n options?: { includeStack?: boolean; includeErrorProps?: boolean },\n): string {\n if (typeof u === \"string\") {\n return u;\n }\n\n if (u instanceof Error) {\n const error = u as Error;\n let result = \"\";\n\n // Always include the name and message\n const errorName = error.name || \"Error\";\n const errorMessage =\n error.message || \"An error occurred with no message provided.\";\n\n result += `${errorName}: ${errorMessage}`;\n\n // Optionally include the stack trace\n if (options?.includeStack && error.stack) {\n // Clean up the stack trace to start on a new line,\n // removing potential duplicate header lines if the browser adds them.\n const stack = error.stack\n // Remove the first line if it duplicates the name/message\n .replace(new RegExp(`^${errorName}:.*\\\\n?`), \"\")\n .trim();\n\n if (stack) {\n result += `\\nStack Trace:\\n${stack}`;\n }\n }\n\n // Add any potential custom error properties (e.g., HTTP status code)\n if (options?.includeErrorProps) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const customProps: { [key: string]: unknown } = error as any;\n\n const additionalInfo = Object.keys(customProps)\n .filter(\n (key) =>\n key !== \"name\" &&\n key !== \"message\" &&\n key !== \"stack\" &&\n typeof customProps[key] !== \"function\" &&\n typeof customProps[key] !== \"object\",\n )\n .map((key) => `\\n- ${key}: ${customProps[key]}`);\n\n if (additionalInfo.length > 0) {\n result += `\\nAdditional Data:${additionalInfo.join(\"\")}`;\n }\n }\n\n return result;\n }\n\n // If the object has a custom toString(), then use it.\n if (\n u !== null &&\n typeof u === \"object\" &&\n u.toString !== Object.prototype.toString\n ) {\n return u.toString();\n }\n\n try {\n // Attempt to JSON stringify the object for inspection.\n return JSON.stringify(u);\n } catch {\n // Fallback if the object cannot be stringified (e.g., circular references).\n return String(u);\n }\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,eAAAE,IAAA,eAAAC,EAAAH,GCIO,SAASI,EACdC,EACAC,EACQ,CACR,GAAI,OAAOD,GAAM,SACf,OAAOA,EAGT,GAAIA,aAAa,MAAO,CACtB,IAAME,EAAQF,EACVG,EAAS,GAGPC,EAAYF,EAAM,MAAQ,QAC1BG,EACJH,EAAM,SAAW,8CAKnB,GAHAC,GAAU,GAAGC,CAAS,KAAKC,CAAY,GAGnCJ,GAAS,cAAgBC,EAAM,MAAO,CAGxC,IAAMI,EAAQJ,EAAM,MAEjB,QAAQ,IAAI,OAAO,IAAIE,CAAS,SAAS,EAAG,EAAE,EAC9C,KAAK,EAEJE,IACFH,GAAU;AAAA;AAAA,EAAmBG,CAAK,GAEtC,CAGA,GAAIL,GAAS,kBAAmB,CAE9B,IAAMM,EAA0CL,EAE1CM,EAAiB,OAAO,KAAKD,CAAW,EAC3C,OACEE,GACCA,IAAQ,QACRA,IAAQ,WACRA,IAAQ,SACR,OAAOF,EAAYE,CAAG,GAAM,YAC5B,OAAOF,EAAYE,CAAG,GAAM,QAChC,EACC,IAAKA,GAAQ;AAAA,IAAOA,CAAG,KAAKF,EAAYE,CAAG,CAAC,EAAE,EAE7CD,EAAe,OAAS,IAC1BL,GAAU;AAAA,kBAAqBK,EAAe,KAAK,EAAE,CAAC,GAE1D,CAEA,OAAOL,CACT,CAGA,GACEH,IAAM,MACN,OAAOA,GAAM,UACbA,EAAE,WAAa,OAAO,UAAU,SAEhC,OAAOA,EAAE,SAAS,EAGpB,GAAI,CAEF,OAAO,KAAK,UAAUA,CAAC,CACzB,MAAQ,CAEN,OAAO,OAAOA,CAAC,CACjB,CACF,CD3EO,SAASU,EAAUC,EAAYC,EAAY,IAAa,CAC7D,IAAMC,EAAIC,EAAiBH,CAAC,EAE5B,OAAIE,EAAE,QAAUD,EACPC,EAGFA,EAAE,MAAM,EAAGD,CAAS,EAAI,SAASC,EAAE,OAASD,CAAS,QAC9D","names":["capLength_exports","__export","capLength","__toCommonJS","toReadableString","u","options","error","result","errorName","errorMessage","stack","customProps","additionalInfo","key","capLength","u","maxLength","s","toReadableString"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
function a(r,o){if(typeof r=="string")return r;if(r instanceof Error){let t=r,i="",c=t.name||"Error",f=t.message||"An error occurred with no message provided.";if(i+=`${c}: ${f}`,o?.includeStack&&t.stack){let e=t.stack.replace(new RegExp(`^${c}:.*\\n?`),"").trim();e&&(i+=`
|
|
2
|
+
Stack Trace:
|
|
3
|
+
${e}`)}if(o?.includeErrorProps){let e=t,s=Object.keys(e).filter(n=>n!=="name"&&n!=="message"&&n!=="stack"&&typeof e[n]!="function"&&typeof e[n]!="object").map(n=>`
|
|
4
|
+
- ${n}: ${e[n]}`);s.length>0&&(i+=`
|
|
5
|
+
Additional Data:${s.join("")}`)}return i}if(r!==null&&typeof r=="object"&&r.toString!==Object.prototype.toString)return r.toString();try{return JSON.stringify(r)}catch{return String(r)}}function p(r,o=400){let t=a(r);return t.length<=o?t:t.slice(0,o)+` ... (${t.length-o} more)`}export{p as capLength};
|
|
6
|
+
//# sourceMappingURL=capLength.min.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/toReadableString.ts","../src/capLength.ts"],"sourcesContent":["/**\n * Make the given argument of unknown type into something human-readable.\n * For Error objects, you can specify options to make the string more verbose.\n */\nexport function toReadableString(\n u: unknown,\n options?: { includeStack?: boolean; includeErrorProps?: boolean },\n): string {\n if (typeof u === \"string\") {\n return u;\n }\n\n if (u instanceof Error) {\n const error = u as Error;\n let result = \"\";\n\n // Always include the name and message\n const errorName = error.name || \"Error\";\n const errorMessage =\n error.message || \"An error occurred with no message provided.\";\n\n result += `${errorName}: ${errorMessage}`;\n\n // Optionally include the stack trace\n if (options?.includeStack && error.stack) {\n // Clean up the stack trace to start on a new line,\n // removing potential duplicate header lines if the browser adds them.\n const stack = error.stack\n // Remove the first line if it duplicates the name/message\n .replace(new RegExp(`^${errorName}:.*\\\\n?`), \"\")\n .trim();\n\n if (stack) {\n result += `\\nStack Trace:\\n${stack}`;\n }\n }\n\n // Add any potential custom error properties (e.g., HTTP status code)\n if (options?.includeErrorProps) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const customProps: { [key: string]: unknown } = error as any;\n\n const additionalInfo = Object.keys(customProps)\n .filter(\n (key) =>\n key !== \"name\" &&\n key !== \"message\" &&\n key !== \"stack\" &&\n typeof customProps[key] !== \"function\" &&\n typeof customProps[key] !== \"object\",\n )\n .map((key) => `\\n- ${key}: ${customProps[key]}`);\n\n if (additionalInfo.length > 0) {\n result += `\\nAdditional Data:${additionalInfo.join(\"\")}`;\n }\n }\n\n return result;\n }\n\n // If the object has a custom toString(), then use it.\n if (\n u !== null &&\n typeof u === \"object\" &&\n u.toString !== Object.prototype.toString\n ) {\n return u.toString();\n }\n\n try {\n // Attempt to JSON stringify the object for inspection.\n return JSON.stringify(u);\n } catch {\n // Fallback if the object cannot be stringified (e.g., circular references).\n return String(u);\n }\n}\n","import { toReadableString } from \"./toReadableString\";\n\nexport function capLength(u: unknown, maxLength = 400): string {\n const s = toReadableString(u);\n\n if (s.length <= maxLength) {\n return s;\n }\n\n return s.slice(0, maxLength) + ` ... (${s.length - maxLength} more)`;\n}\n"],"mappings":"AAIO,SAASA,EACdC,EACAC,EACQ,CACR,GAAI,OAAOD,GAAM,SACf,OAAOA,EAGT,GAAIA,aAAa,MAAO,CACtB,IAAME,EAAQF,EACVG,EAAS,GAGPC,EAAYF,EAAM,MAAQ,QAC1BG,EACJH,EAAM,SAAW,8CAKnB,GAHAC,GAAU,GAAGC,CAAS,KAAKC,CAAY,GAGnCJ,GAAS,cAAgBC,EAAM,MAAO,CAGxC,IAAMI,EAAQJ,EAAM,MAEjB,QAAQ,IAAI,OAAO,IAAIE,CAAS,SAAS,EAAG,EAAE,EAC9C,KAAK,EAEJE,IACFH,GAAU;AAAA;AAAA,EAAmBG,CAAK,GAEtC,CAGA,GAAIL,GAAS,kBAAmB,CAE9B,IAAMM,EAA0CL,EAE1CM,EAAiB,OAAO,KAAKD,CAAW,EAC3C,OACEE,GACCA,IAAQ,QACRA,IAAQ,WACRA,IAAQ,SACR,OAAOF,EAAYE,CAAG,GAAM,YAC5B,OAAOF,EAAYE,CAAG,GAAM,QAChC,EACC,IAAKA,GAAQ;AAAA,IAAOA,CAAG,KAAKF,EAAYE,CAAG,CAAC,EAAE,EAE7CD,EAAe,OAAS,IAC1BL,GAAU;AAAA,kBAAqBK,EAAe,KAAK,EAAE,CAAC,GAE1D,CAEA,OAAOL,CACT,CAGA,GACEH,IAAM,MACN,OAAOA,GAAM,UACbA,EAAE,WAAa,OAAO,UAAU,SAEhC,OAAOA,EAAE,SAAS,EAGpB,GAAI,CAEF,OAAO,KAAK,UAAUA,CAAC,CACzB,MAAQ,CAEN,OAAO,OAAOA,CAAC,CACjB,CACF,CC3EO,SAASU,EAAUC,EAAYC,EAAY,IAAa,CAC7D,IAAMC,EAAIC,EAAiBH,CAAC,EAE5B,OAAIE,EAAE,QAAUD,EACPC,EAGFA,EAAE,MAAM,EAAGD,CAAS,EAAI,SAASC,EAAE,OAASD,CAAS,QAC9D","names":["toReadableString","u","options","error","result","errorName","errorMessage","stack","customProps","additionalInfo","key","capLength","u","maxLength","s","toReadableString"]}
|
package/capLength.mjs
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// src/toReadableString.ts
|
|
2
|
+
function toReadableString(u, options) {
|
|
3
|
+
if (typeof u === "string") {
|
|
4
|
+
return u;
|
|
5
|
+
}
|
|
6
|
+
if (u instanceof Error) {
|
|
7
|
+
const error = u;
|
|
8
|
+
let result = "";
|
|
9
|
+
const errorName = error.name || "Error";
|
|
10
|
+
const errorMessage = error.message || "An error occurred with no message provided.";
|
|
11
|
+
result += `${errorName}: ${errorMessage}`;
|
|
12
|
+
if (options?.includeStack && error.stack) {
|
|
13
|
+
const stack = error.stack.replace(new RegExp(`^${errorName}:.*\\n?`), "").trim();
|
|
14
|
+
if (stack) {
|
|
15
|
+
result += `
|
|
16
|
+
Stack Trace:
|
|
17
|
+
${stack}`;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (options?.includeErrorProps) {
|
|
21
|
+
const customProps = error;
|
|
22
|
+
const additionalInfo = Object.keys(customProps).filter(
|
|
23
|
+
(key) => key !== "name" && key !== "message" && key !== "stack" && typeof customProps[key] !== "function" && typeof customProps[key] !== "object"
|
|
24
|
+
).map((key) => `
|
|
25
|
+
- ${key}: ${customProps[key]}`);
|
|
26
|
+
if (additionalInfo.length > 0) {
|
|
27
|
+
result += `
|
|
28
|
+
Additional Data:${additionalInfo.join("")}`;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
if (u !== null && typeof u === "object" && u.toString !== Object.prototype.toString) {
|
|
34
|
+
return u.toString();
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
return JSON.stringify(u);
|
|
38
|
+
} catch {
|
|
39
|
+
return String(u);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// src/capLength.ts
|
|
44
|
+
function capLength(u, maxLength = 400) {
|
|
45
|
+
const s = toReadableString(u);
|
|
46
|
+
if (s.length <= maxLength) {
|
|
47
|
+
return s;
|
|
48
|
+
}
|
|
49
|
+
return s.slice(0, maxLength) + ` ... (${s.length - maxLength} more)`;
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
capLength
|
|
53
|
+
};
|
|
@@ -17,12 +17,12 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
|
-
// src/
|
|
21
|
-
var
|
|
22
|
-
__export(
|
|
20
|
+
// src/concatIterators.ts
|
|
21
|
+
var concatIterators_exports = {};
|
|
22
|
+
__export(concatIterators_exports, {
|
|
23
23
|
concatIterators: () => concatIterators
|
|
24
24
|
});
|
|
25
|
-
module.exports = __toCommonJS(
|
|
25
|
+
module.exports = __toCommonJS(concatIterators_exports);
|
|
26
26
|
function* concatIterators(...iterators) {
|
|
27
27
|
for (const iterator of iterators) {
|
|
28
28
|
yield* iterator;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use strict";var n=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var i=Object.prototype.hasOwnProperty;var s=(t,o)=>{for(var e in o)n(t,e,{get:o[e],enumerable:!0})},T=(t,o,e,a)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of f(o))!i.call(t,r)&&r!==e&&n(t,r,{get:()=>o[r],enumerable:!(a=c(o,r))||a.enumerable});return t};var d=t=>T(n({},"__esModule",{value:!0}),t);var p={};s(p,{concatIterators:()=>l});module.exports=d(p);function*l(...t){for(let o of t)yield*o}0&&(module.exports={concatIterators});
|
|
2
|
-
//# sourceMappingURL=
|
|
2
|
+
//# sourceMappingURL=concatIterators.min.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/concatIterators.ts"],"sourcesContent":["/** Memory-efficient way to concat two or more iterators. */\nexport function* concatIterators<T>(...iterators: Generator<T>[]) {\n for (const iterator of iterators) {\n yield* iterator;\n }\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,IAAA,eAAAC,EAAAH,GACO,SAAUE,KAAsBE,EAA2B,CAChE,QAAWC,KAAYD,EACrB,MAAOC,CAEX","names":["concatIterators_exports","__export","concatIterators","__toCommonJS","iterators","iterator"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
function*r(...o){for(let t of o)yield*t}export{r as concatIterators};
|
|
2
|
-
//# sourceMappingURL=
|
|
2
|
+
//# sourceMappingURL=concatIterators.min.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/concatIterators.ts"],"sourcesContent":["/** Memory-efficient way to concat two or more iterators. */\nexport function* concatIterators<T>(...iterators: Generator<T>[]) {\n for (const iterator of iterators) {\n yield* iterator;\n }\n}\n"],"mappings":"AACO,SAAUA,KAAsBC,EAA2B,CAChE,QAAWC,KAAYD,EACrB,MAAOC,CAEX","names":["concatIterators","iterators","iterator"]}
|
package/duration.min.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var l=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var x=(o,n)=>{for(var r in n)l(o,r,{get:n[r],enumerable:!0})},_=(o,n,r,e)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of S(n))!M.call(o,t)&&t!==r&&l(o,t,{get:()=>n[t],enumerable:!(e=g(n,t))||e.enumerable});return o};var T=o=>_(l({},"__esModule",{value:!0}),o);var I={};x(I,{DURATION_STYLE_SUFFIX_MAP:()=>p,DURATION_TYPE_SEQUENCE:()=>f,durationOrMsToMs:()=>O,durationToMs:()=>D,elapsed:()=>A,formatDuration:()=>d,msToDuration:()=>m,readableDuration:()=>h});module.exports=T(I);var f=["days","hours","minutes","seconds","milliseconds"],p={days:{short:"day",shorts:"days",long:"day",longs:"days",narrow:"d"},hours:{short:"hr",shorts:"hrs",long:"hour",longs:"hours",narrow:"h"},minutes:{short:"min",shorts:"mins",long:"minute",longs:"minutes",narrow:"m"},seconds:{short:"sec",shorts:"secs",long:"second",longs:"seconds",narrow:"s"},milliseconds:{short:"ms",shorts:"ms",long:"millisecond",longs:"milliseconds",narrow:"ms"}};function U(o){return o=="short"?"shorts":o==="long"?"longs":o}function w(o){return o==="narrow"?"":" "}function N(o){return o==="narrow"?" ":", "}function m(o,n){if(o===0)return n=n??"milliseconds",{[n]:0};let r={};for(let e=0;e<1;e++){let t=Math.floor(o/1e3),u=o-t*1e3;if(u>0&&(r.milliseconds=u),t===0)break;let i=Math.floor(t/60);if(t-=i*60,t>0&&(r.seconds=t),i===0)break;let s=Math.floor(i/60);if(i-=s*60,i>0&&(r.minutes=i),s===0)break;let a=Math.floor(s/24);s-=a*24,s>0&&(r.hours=s),a>0&&(r.days=a)}return r}function D(o){let n=(o.days??0)*864e5,r=(o.hours??0)*36e5,e=(o.minutes??0)*6e4,t=(o.seconds??0)*1e3,u=o.milliseconds??0;return n+r+e+t+u}function O(o){return typeof o=="number"?o:D(o)}function d(o,n){n=n??"short";let r=U(n),e=w(n),t=[];for(let i of f){let s=o[i];if(s===void 0)continue;let a=p[i],y=s===1?a[n]:a[r];t.push(s+e+y)}let u=N(n);return t.join(u)}function h(o,n){let r=m(o,n?.durationTypeForZero);return d(r,n?.style)}function A(o){return o>6e4?h(o):o>100?`${(o/1e3).toFixed(3)}s`:o+"ms"}0&&(module.exports={DURATION_STYLE_SUFFIX_MAP,DURATION_TYPE_SEQUENCE,durationOrMsToMs,durationToMs,elapsed,formatDuration,msToDuration,readableDuration});
|
|
2
2
|
//# sourceMappingURL=duration.min.cjs.map
|
package/duration.min.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var d=["days","hours","minutes","seconds","milliseconds"],h={days:{short:"day",shorts:"days",long:"day",longs:"days",narrow:"d"},hours:{short:"hr",shorts:"hrs",long:"hour",longs:"hours",narrow:"h"},minutes:{short:"min",shorts:"mins",long:"minute",longs:"minutes",narrow:"m"},seconds:{short:"sec",shorts:"secs",long:"second",longs:"seconds",narrow:"s"},milliseconds:{short:"ms",shorts:"ms",long:"millisecond",longs:"milliseconds",narrow:"ms"}};function y(o){return o=="short"?"shorts":o==="long"?"longs":o}function g(o){return o==="narrow"?"":" "}function S(o){return o==="narrow"?" ":", "}function M(o,n){if(o===0)return n=n??"milliseconds",{[n]:0};let r={};for(let i=0;i<1;i++){let t=Math.floor(o/1e3),u=o-t*1e3;if(u>0&&(r.milliseconds=u),t===0)break;let e=Math.floor(t/60);if(t-=e*60,t>0&&(r.seconds=t),e===0)break;let s=Math.floor(e/60);if(e-=s*60,e>0&&(r.minutes=e),s===0)break;let a=Math.floor(s/24);s-=a*24,s>0&&(r.hours=s),a>0&&(r.days=a)}return r}function x(o){let n=(o.days??0)*864e5,r=(o.hours??0)*36e5,i=(o.minutes??0)*6e4,t=(o.seconds??0)*1e3,u=o.milliseconds??0;return n+r+i+t+u}function R(o){return typeof o=="number"?o:x(o)}function _(o,n){n=n??"short";let r=y(n),i=g(n),t=[];for(let e of d){let s=o[e];if(s===void 0)continue;let a=h[e],c=s===1?a[n]:a[r];t.push(s+i+c)}let u=S(n);return t.join(u)}function T(o,n){let r=M(o,n?.durationTypeForZero);return _(r,n?.style)}function P(o){return o>6e4?T(o):o>100?`${(o/1e3).toFixed(3)}s`:o+"ms"}export{h as DURATION_STYLE_SUFFIX_MAP,d as DURATION_TYPE_SEQUENCE,R as durationOrMsToMs,x as durationToMs,P as elapsed,_ as formatDuration,M as msToDuration,T as readableDuration};
|
|
2
2
|
//# sourceMappingURL=duration.min.mjs.map
|