MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / stringify

Function stringify

packages/redis/cachable.ts:77–110  ·  view source on GitHub ↗
(obj: unknown)

Source from the content-addressed store, hash-verified

75}
76
77function stringify(obj: unknown): string {
78 if (obj === null) {
79 return 'null';
80 }
81 if (obj === undefined) {
82 return 'undefined';
83 }
84 if (typeof obj === 'boolean') {
85 return obj ? 'true' : 'false';
86 }
87 if (typeof obj === 'number') {
88 return String(obj);
89 }
90 if (typeof obj === 'string') {
91 return obj;
92 }
93 if (typeof obj === 'function') {
94 return obj.toString();
95 }
96
97 if (Array.isArray(obj)) {
98 return `[${obj.map(stringify).join(',')}]`;
99 }
100
101 if (typeof obj === 'object') {
102 const pairs = Object.entries(obj)
103 .sort(([a], [b]) => a.localeCompare(b))
104 .map(([key, value]) => `${key}:${stringify(value)}`);
105 return pairs.join(':');
106 }
107
108 // Fallback for any other types
109 return String(obj);
110}
111
112export interface CacheableOptions {
113 cacheEmptyArray?: boolean;

Callers 1

getKeyFunction · 0.70

Calls 3

joinMethod · 0.80
toStringMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected