summaryrefslogtreecommitdiffstats
path: root/lib/utils/path.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-01-27 10:24:06 +0100
committerSamy Pessé <samypesse@gmail.com>2016-01-27 10:24:06 +0100
commitf305d57ab7702c3ca10fd6e32366d19e524ee1f0 (patch)
tree381ccb09c7cedc72cdf8ad6c98b681b72f4d1bc0 /lib/utils/path.js
parent877f2e477b010f9f37a9044606f110a90f077680 (diff)
downloadgitbook-f305d57ab7702c3ca10fd6e32366d19e524ee1f0.zip
gitbook-f305d57ab7702c3ca10fd6e32366d19e524ee1f0.tar.gz
gitbook-f305d57ab7702c3ca10fd6e32366d19e524ee1f0.tar.bz2
Add more classes structures
Diffstat (limited to 'lib/utils/path.js')
-rw-r--r--lib/utils/path.js12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/utils/path.js b/lib/utils/path.js
index dc97d5d..2d722a5 100644
--- a/lib/utils/path.js
+++ b/lib/utils/path.js
@@ -1,6 +1,11 @@
var _ = require('lodash');
var path = require('path');
+// Normalize a filename
+function normalizePath(filename) {
+ return path.normalize(filename);
+}
+
// Return true if file path is inside a folder
function isInRoot(root, filename) {
filename = path.normalize(filename);
@@ -17,10 +22,10 @@ function resolveInRoot(root) {
.slice(1)
.reduce(function(current, p) {
// Handle path relative to book root ("/README.md")
- if (p[0] == "/" || p[0] == "\\") return p.slice(1);
+ if (p[0] == '/' || p[0] == '\\') return p.slice(1);
return current? path.join(current, p) : path.normalize(p);
- }, "")
+ }, '')
.value();
result = path.resolve(root, input);
@@ -36,5 +41,6 @@ function resolveInRoot(root) {
module.exports = {
isInRoot: isInRoot,
- resolveInRoot: resolveInRoot
+ resolveInRoot: resolveInRoot,
+ normalize: normalizePath
};