forked from VimCommando/fx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpaths.js
More file actions
31 lines (27 loc) · 742 Bytes
/
paths.js
File metadata and controls
31 lines (27 loc) · 742 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
'use strict'
const arrayEqual = require('array-equal')
exports.equal = function equal(path1, path2) {
if (!Array.isArray(path1) || !Array.isArray(path2)) {
return path1 === path2
}
return arrayEqual(path1, path2)
}
// TODO: escaping bad characters like '.', '[', ']', '-'
exports.toHumanReadableString = function toHumanReadableString(path) {
let result = ''
for (let component of path) {
if (typeof component == 'number') {
result += '[' + component + ']'
} else {
result += '.' + component
}
}
return result
}
exports.toZeroSeparatedString = function toZeroSeparatedString(path) {
let result = ''
for (let component of path) {
result += '\0' + component
}
return result.substr(1)
}