Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
20 lines
954 B
Plaintext
20 lines
954 B
Plaintext
/**
|
|
* Safely stringify a value and truncate it to a maximum length.
|
|
*
|
|
* Converts any value to a JSON string representation and truncates the resulting
|
|
* string if it exceeds the maximum length. If truncation occurs, an ellipsis (…)
|
|
* is appended to indicate incomplete output.
|
|
*
|
|
* @param value - The value to stringify (can be any type including objects, arrays, primitives)
|
|
* @param maxLength - The maximum character length of the output string
|
|
* @returns A JSON string representation, truncated with "…" if it exceeds maxLength
|
|
*/export function stringifyTruncated(value, maxLength) {
|
|
const stringifiedJSON = JSON.stringify(value);
|
|
const totalChars = stringifiedJSON.length;
|
|
// Only truncate if the string is significantly longer (>1.5x the max length)
|
|
if (totalChars / maxLength > 1.5) {
|
|
return `${stringifiedJSON.substring(0, maxLength)}\u2026`;
|
|
}
|
|
return stringifiedJSON;
|
|
}
|
|
//# sourceMappingURL=stringifyTruncated.js.map |