parrier
Version:
This is a package that lists everything inside the provided "path" (or the full tree structure if "recurse" is set), asynchronously.
57 lines • 2.21 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.parrier = void 0;
const util_1 = require("util");
const fs_1 = require("fs");
const functions_1 = require("./functions");
const readdir = util_1.promisify(fs_1.readdir);
/**
* Lists everything inside the provided \"path\" (or the full tree structure if \"recurse\" is set), asynchronously.
*
* @param path - The path from where to get content
* @param options - The options input
* @param options.recurse - The recurse option which lets us get full tree
* @example
* ```typescript
* // common usage:
* // prints files & folders inside path
* parrier('the/path/').then(console.log);
* ```
* @example
* ```typescript
* // Recursive usage:
* // prints full tree structure
* parrier('the/path/', { recurse: true }).then(console.log);
* ```
* @example
* ```typescript
* // Getting './' content:
* // prints files & folders inside './'
* parrier().then(console.log);
* ```
*
*/
function parrier(path = './', options = { recurse: false }) {
return __awaiter(this, void 0, void 0, function* () {
const { recurse } = options;
const filesNames = yield readdir(path);
const files = yield Promise.all(filesNames.map((fname) => functions_1.getFileAsync(path, fname)));
if (recurse) {
return yield Promise.all(files.map(functions_1.fillChildrenAsync));
}
else {
return files;
}
});
}
exports.parrier = parrier;
//# sourceMappingURL=parrier.js.map