-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathparser.js
27 lines (27 loc) · 822 Bytes
/
parser.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
exports.parse = function (uriPath) {
var serviceName;
var publicName;
var tokens = uriPath.split('/');
var filePath = '';
if (tokens.length > 1) { // .join() is not available (SDK Array type)
for (var i = 1; i < tokens.length; i++) {
filePath += tokens[i];
if (i + 1 !== tokens.length) {
filePath += '/';
}
}
}
tokens = tokens[0].split('.');
if (tokens.length === 1) { // if the service is not mentioned in the URI, eg: safe:maidsafe.net
serviceName = 'www'; // default lookup service
publicName = tokens[0];
} else {
serviceName = tokens[0];
publicName = tokens[1];
}
// Set default file to lookup if filePath is empty
if (!filePath) {
filePath = 'index.html';
}
return {service: serviceName, publicName: publicName, filePath: filePath}
};