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

This commit is contained in:
AJ ONeal 2015-11-12 00:26:15 +00:00
父節點 a8724cc502
當前提交 fc8e98173e
共有 3 個文件被更改,包括 42 次插入0 次删除

15
lib/utils.js Normal file
查看文件

@ -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
查看文件

@ -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
查看文件