Skip to content

Commit 9dbf579

Browse files
committed
fix: sort comments properly, store arrays directly
1 parent d943100 commit 9dbf579

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

scripts/utils.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,18 @@ export function sortKeys(obj = {}) {
2121
const keys = Object.keys(obj);
2222
if (!keys.length) return undefined;
2323
const sorted = {};
24-
keys.sort().forEach(
24+
keys.sort(
25+
(a, b) => uncomment(a).localeCompare(uncomment(b)),
26+
).forEach(
2527
(key) => {
2628
const value = obj[key];
29+
if (Array.isArray(value)) {
30+
sorted[key] = value;
31+
// value.forEach((val, index) => {
32+
// sorted[`${key}.${index + 1}`] = val;
33+
// });
34+
return;
35+
}
2736
sorted[key] = typeof value === 'object' ? sortKeys(value) : value;
2837
},
2938
);
@@ -37,3 +46,10 @@ export function sortKeys(obj = {}) {
3746
export function isMain({ url }) {
3847
return nodePath.normalize(url).endsWith(process.argv[1]);
3948
}
49+
50+
function uncomment(string = '') {
51+
if (string.startsWith('//')) {
52+
return string.substring(2);
53+
}
54+
return string;
55+
}

0 commit comments

Comments
 (0)