JSFiddle - React, Tailwind, and code Playground
by neonDog
JavaScript
const parseGifskiProgress = function (terminalOutput) {
// Regular expressions to match the frame numbers and time
const obj = {};
const frameRegex = /Frame (\d+) \/ (\d+)/;
const timeRegex = /(\d+)([ms])$/;
const frameMatch = terminalOutput.match(frameRegex);
const timeMatch = terminalOutput.match(timeRegex);
if (frameMatch) {
obj.currentFrame = parseInt(frameMatch[1]);
obj.totalFrames = parseInt(frameMatch[2]);
obj.percent = obj.currentFrame / obj.totalFrames;
}
if (timeMatch) {
obj.timeValue = parseInt(timeMatch[1]);
obj.timeUnit = timeMatch[2];
}
// Check for the presence of file size
const fileSizeRegex = /(\d+(\.\d+)?)MB GIF;/;
const fileSizeMatch = terminalOutput.match(fileSizeRegex);
if (fileSizeMatch) {
obj.fileSize = parseFloat(fileSizeMatch[1]);
}
return obj;
}
parseGifskiProgress("11MB GIF; Frame 148 / 148 ################################################## ");