file-converter-nodejs
Version:
A powerful Node.js package for converting files between various formats, splitting and merging files, and automating complex file operations. Backed by LibreOffice and Python, this tool makes file processing seamless for developers.
31 lines (30 loc) • 1.47 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.processInChunks = void 0;
const processInChunks = (tasks, chunkSize) => __awaiter(void 0, void 0, void 0, function* () {
const chunkArray = (arr, size) => arr.reduce((chunks, item, index) => {
const chunkIndex = Math.floor(index / size);
if (!chunks[chunkIndex])
chunks[chunkIndex] = [];
chunks[chunkIndex].push(item);
return chunks;
}, []);
const chunks = chunkArray(tasks, chunkSize);
const results = [];
for (const chunk of chunks) {
console.log({ chunk });
const chunkResults = yield Promise.all(chunk);
results.push(...chunkResults);
}
return results;
});
exports.processInChunks = processInChunks;