diff --git a/lib/utils.js b/lib/utils.js new file mode 100644 index 0000000..33a844a --- /dev/null +++ b/lib/utils.js @@ -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 + }; +}; diff --git a/tests/utils.js b/tests/utils.js new file mode 100644 index 0000000..976421f --- /dev/null +++ b/tests/utils.js @@ -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)); +}); diff --git a/var/.gitkeep b/var/.gitkeep new file mode 100644 index 0000000..e69de29