Skip to content

Commit

Permalink
add some new utilities to simplify core
Browse files Browse the repository at this point in the history
  • Loading branch information
vanetix committed Mar 21, 2013
1 parent 3ddab4b commit 7a024ba
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,32 @@ var splitPaths = utils.splitPaths = function(p) {
return p.split(path.sep);
};

/**
* Return the name of file `p`
*
* @param {String} p
* @return {String}
*/

var fileName = utils.fileName = function(p) {
return path.basename(p, path.extname(p));
};

/**
* Joins paths `a` and `b`, but replaces `b` ext with html
*
* @param {String} a
* @param {String} b
* @return {String}
*/

var joinPaths = utils.joinPaths = function(a, b) {
var f = fileName(b),
b = path.dirname(b);

return path.join(a, b, f + '.html');
};

/**
* Make all directories leading up to `p`
* like a unix `mkdir -p p`
Expand Down Expand Up @@ -113,7 +139,7 @@ var read = utils.read = function(p) {
if(!exists(p)) return false;

try {
return fs.readFileSync(p);
return fs.readFileSync(p, 'utf8');
} catch(e) {
return false;
}
Expand Down

0 comments on commit 7a024ba

Please sign in to comment.