summaryrefslogtreecommitdiffstats
path: root/lib/utils
diff options
context:
space:
mode:
Diffstat (limited to 'lib/utils')
-rw-r--r--lib/utils/links.js23
-rw-r--r--lib/utils/string.js26
2 files changed, 47 insertions, 2 deletions
diff --git a/lib/utils/links.js b/lib/utils/links.js
index 808d711..6606bbf 100644
--- a/lib/utils/links.js
+++ b/lib/utils/links.js
@@ -1,6 +1,11 @@
var url = require('url');
var path = require('path');
+// Is the link an external link
+var isExternal = function(href) {
+ return Boolean(url.parse(href).protocol);
+};
+
// Return true if the link is relative
var isRelative = function(href) {
var parsed = url.parse(href);
@@ -26,8 +31,22 @@ var toAbsolute = function(_href, dir, outdir) {
return _href;
};
+// Join links
+
+var join = function() {
+ var _href = path.join.apply(path, arguments);
+
+ if (process.platform === 'win32') {
+ _href = _href.replace(/\\/g, '/');
+ }
+
+ return _href;
+};
+
module.exports = {
isRelative: isRelative,
- toAbsolute: toAbsolute
-}; \ No newline at end of file
+ isExternal: isExternal,
+ toAbsolute: toAbsolute,
+ join: join
+};
diff --git a/lib/utils/string.js b/lib/utils/string.js
new file mode 100644
index 0000000..417d7af
--- /dev/null
+++ b/lib/utils/string.js
@@ -0,0 +1,26 @@
+var _ = require("lodash");
+
+function escapeShellArg(arg) {
+ var ret = '';
+
+ ret = arg.replace(/"/g, '\\"');
+
+ return "\"" + ret + "\"";
+}
+
+function optionsToShellArgs(options) {
+ return _.chain(options)
+ .map(function(value, key) {
+ if (value == null || value == false) return null;
+ if (value == true) return key;
+ return key+"="+escapeShellArg(value);
+ })
+ .compact()
+ .value()
+ .join(" ");
+}
+
+module.exports = {
+ escapeShellArg: escapeShellArg,
+ optionsToShellArgs: optionsToShellArgs
+};