-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathutils.js
34 lines (32 loc) · 827 Bytes
/
utils.js
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
33
34
/*
* Sorts the object keys by the file reference.
* There's no guarantee of key iteration in order prior to es6
* but in practice it tends to work out.
*/
function sortObjectKeysByRef(unordered) {
const ordered = {};
Object.keys(unordered).sort((a, b) => {
const refA = unordered[a].comments.reference.toLowerCase();
const refB = unordered[b].comments.reference.toLowerCase();
if (refA < refB) {
return -1;
}
if (refA > refB) {
return 1;
}
return 0;
}).forEach(function(key) {
ordered[key] = unordered[key];
});
return ordered;
}
function stripIndent(str) {
if (str && str.replace && str.trim) {
return str.replace(/(?:\n(?:\s*))+/g, ' ').trim();
}
return str;
}
module.exports = {
stripIndent: stripIndent,
sortObjectKeysByRef: sortObjectKeysByRef,
};