-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
32 lines (25 loc) · 732 Bytes
/
test.js
File metadata and controls
32 lines (25 loc) · 732 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const normalize = (val) => {
if (val == null) return "";
let str = String(val).trim();
// 🔴 FIX: normalize boolean strings (case-insensitive)
const lower = str.toLowerCase();
if (lower === "true" || lower === "false") {
return lower; // always compare as "true" / "false"
}
try {
const parsed = JSON.parse(str);
// Normalize booleans coming from JSON.parse
if (typeof parsed === "boolean") {
return parsed.toString(); // "true" / "false"
}
if (typeof parsed === "object") {
return JSON.stringify(parsed);
}
return String(parsed);
} catch {
return str;
}
};
const input = "[1, 2, 3, 5]";
console.log(normalize(input));
console.log(typeof(normalize(input)));