Skip to content

Commit

Permalink
refactor: move async foreach to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
ph1p committed Feb 18, 2019
1 parent bbe7a0e commit 56473a8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
13 changes: 1 addition & 12 deletions cmds/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const chalk = require('chalk');

const vueSidebar = require('../helpers/vue-sidebar');
const parseVuepressComment = require('../helpers/comment-parser');
const { checkExtension, getFilename } = require('../helpers/utils');
const { checkExtension, getFilename, asyncForEach } = require('../helpers/utils');

const fileTree = [];

Expand Down Expand Up @@ -193,17 +193,6 @@ async function generate(argv) {
});
}

/**
* Async foreach loop
* @param {array} array
* @param {function} callback
*/
async function asyncForEach(array, callback) {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array);
}
}

module.exports = {
generate,
plugin: (options, ctx) => ({
Expand Down
11 changes: 11 additions & 0 deletions helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,14 @@ exports.getFilename = path =>
.pop()
.substring(0, path.lastIndexOf('.'))) ||
'';

/**
* Async foreach loop
* @param {array} array
* @param {function} callback
*/
exports.asyncForEach = async function(array, callback) {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array);
}
};

0 comments on commit 56473a8

Please sign in to comment.