basic test of getDomainInfo, add ./var/.gitkeep

This commit is contained in:
AJ ONeal 2015-11-12 00:26:15 +00:00
vanhempi a8724cc502
commit fc8e98173e
3 muutettua tiedostoa jossa 42 lisäystä ja 0 poistoa

15
lib/utils.js Normal file
Näytä tiedosto

@ -0,0 +1,15 @@
'use strict';
module.exports.getDomainInfo = function (apppath) {
var parts = apppath.split(/[#%]+/);
var hostname = parts.shift();
var pathname = parts.join('/').replace(/\/+/g, '/').replace(/^\//, '');
return {
hostname: hostname
, pathname: pathname
, dirpathname: parts.join('#')
, dirname: apppath
, isRoot: apppath === hostname
};
};

27
tests/utils.js Normal file
Näytä tiedosto

@ -0,0 +1,27 @@
'use strict';
var utils = require('../lib/utils');
// TODO priority should be by arbitrarily, large numbers, not specific numbers of #
[
{ test: "example.com"
, result: { host: "example.com" }
}
, { test: "api.example.com"
, result: { host: "api.example.com" }
}
, { test: "api.example.com#"
, result: { host: "api.example.com" }
}
, { test: "api.example.com##"
, result: { host: "api.example.com" }
}
, { test: "api.example.com###"
, result: { host: "api.example.com" }
}
, { test: "example.com#blah"
, result: { host: "example.com" }
}
].forEach(function (sample) {
console.log(utils.getDomainInfo(sample.test));
});

0
var/.gitkeep Normal file
Näytä tiedosto