MCPcopy
hub / github.com/callumalpass/tasknotes / stringifyUnknown

Function stringifyUnknown

src/utils/stringUtils.ts:1–43  ·  view source on GitHub ↗
(value: unknown)

Source from the content-addressed store, hash-verified

1export function stringifyUnknown(value: unknown): string {
2 if (value === null || value === undefined) {
3 return "";
4 }
5
6 if (typeof value === "string") {
7 return value;
8 }
9
10 if (typeof value === "number") {
11 return Number.prototype.toString.call(value);
12 }
13
14 if (typeof value === "bigint") {
15 return BigInt.prototype.toString.call(value);
16 }
17
18 if (typeof value === "boolean") {
19 return value ? "true" : "false";
20 }
21
22 if (typeof value === "symbol") {
23 return value.description ?? "";
24 }
25
26 if (value instanceof Date) {
27 return value.toISOString();
28 }
29
30 if (Array.isArray(value)) {
31 return value
32 .map((item) => stringifyUnknown(item))
33 .filter((item) => item.length > 0)
34 .join(", ");
35 }
36
37 try {
38 const json = JSON.stringify(value);
39 return typeof json === "string" ? json : "";
40 } catch {
41 return "";
42 }
43}
44
45export function stringifyUnknownArray(value: unknown): string[] {
46 if (Array.isArray(value)) {

Callers 15

handleSaveMethod · 0.90
matchesValueFunction · 0.90
stringifyFmValueMethod · 0.90
convertIsOperatorMethod · 0.90
formatNumericValueMethod · 0.90
parseICSMethod · 0.90
getErrorMessageFunction · 0.90
createTaskMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected