mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-20 06:50:47 -07:00
feature: root option allows array of strings
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
const fs = require('fs');
|
||||
|
||||
function readFileAsync(filepath) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
fs.readFile(filepath, 'utf8', function(err, content) {
|
||||
err ? reject(err) : resolve(content);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
function statFileAsync(path) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
fs.stat(path, (err, stat) => err ? reject(err) : resolve(stat))
|
||||
});
|
||||
};
|
||||
|
||||
function pathResolve(root, path) {
|
||||
if (path[0] == '/') return path;
|
||||
|
||||
var arr = root.split('/').concat(path.split('/'));
|
||||
var result = [];
|
||||
arr.forEach(function(slug) {
|
||||
if (slug == '..') result.pop();
|
||||
else if (!slug || slug == '.');
|
||||
else result.push(slug);
|
||||
});
|
||||
return '/' + result.join('/');
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
readFileAsync,
|
||||
pathResolve,
|
||||
statFileAsync
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
const Promise = require('any-promise');
|
||||
|
||||
/*
|
||||
* Call functions in serial until someone resolved.
|
||||
* @param {Array} iterable the array to iterate with.
|
||||
* @param {Array} iteratee returns a new promise.
|
||||
* The iteratee is invoked with three arguments: (value, index, iterable).
|
||||
*/
|
||||
function someSeries(iterable, iteratee) {
|
||||
var ret = Promise.reject(new Error('init'));
|
||||
iterable.forEach(function(item, idx) {
|
||||
ret = ret
|
||||
.then(x => x)
|
||||
.catch(e => iteratee(item, idx, iterable));
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
exports.someSeries = someSeries;
|
||||
@@ -13,7 +13,7 @@ function isString(value) {
|
||||
* Iteratee functions may exit iteration early by explicitly returning false.
|
||||
* @param {Object} object The object to iterate over.
|
||||
* @param {Function} iteratee The function invoked per iteration.
|
||||
* @return {Object} Returs object.
|
||||
* @return {Object} Returns object.
|
||||
*/
|
||||
function forOwn(object, iteratee) {
|
||||
object = object || {};
|
||||
@@ -25,5 +25,10 @@ function forOwn(object, iteratee) {
|
||||
return object;
|
||||
}
|
||||
|
||||
function isArray(value) {
|
||||
return value instanceof Array;
|
||||
}
|
||||
|
||||
exports.isString = isString;
|
||||
exports.isArray = isArray;
|
||||
exports.forOwn = forOwn;
|
||||
|
||||
Reference in New Issue
Block a user