MCPcopy Create free account
hub / github.com/smallfawn/QLScriptPublic / canonicalize

Function canonicalize

wxapp/longfor.js:124–146  ·  view source on GitHub ↗
(data = {})

Source from the content-addressed store, hash-verified

122}
123
124function canonicalize(data = {}) {
125 return Object.keys(data || {})
126 .sort()
127 .map((key) => {
128 let value = data[key];
129 if (Array.isArray(value)) {
130 let text = "[";
131 if (!value.length) text += "]";
132 value.forEach((item, index) => {
133 if (Array.isArray(item)) text += JSON.stringify(item);
134 else if (typeof item === "object" && item !== null) text += `{${canonicalize(item)}}`;
135 else text += item;
136 text += index < value.length - 1 ? "," : "]";
137 });
138 value = text;
139 } else if (typeof value === "object" && value !== null) {
140 value = `{${canonicalize(value)}}`;
141 }
142 return `${value}`.trim() && `${value}` !== "null" ? `${key}=${value}` : "";
143 })
144 .filter(Boolean)
145 .join("|");
146}
147
148function miniSign(data) {
149 const timestamp = Date.now().toString();

Callers 1

miniSignFunction · 0.85

Calls 1

forEachMethod · 0.80

Tested by

no test coverage detected