From fc8e98173e9baf02becbb48a6047b1460d7e91bf Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 12 Nov 2015 00:26:15 +0000 Subject: [PATCH] basic test of getDomainInfo, add ./var/.gitkeep --- lib/utils.js | 15 +++++++++++++++ tests/utils.js | 27 +++++++++++++++++++++++++++ var/.gitkeep | 0 3 files changed, 42 insertions(+) create mode 100644 lib/utils.js create mode 100644 tests/utils.js create mode 100644 var/.gitkeep 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