Small utility to check if a file is ready to be worked with.
$ npm i is-my-file-ready
import isMyFileReady, { sameSize, endsWithStr } from 'is-my-file-ready';
const expectedSize = 4242;
const expectedEnds = 'sit amet.';
const result = await isMyFileReady('./myfile.txt', [
sameSize(expectedSize),
endsWithStr(expectedEnds),
]);
if (!result.isReady) {
result.checks
.filter((check) => !check.isReady)
.forEach((check) => {
let toPrint = '';
toPrint += `${check.name} failed. `;
switch (check.name) {
case 'sameSize':
toPrint += `Expected "${expectedSize}", got "${check.size}."`;
break;
case 'endsWithStr':
toPrint += `Expected "${expectedEnds}", got "${check.endsWith}."`;
break;
}
console.log(toPrint);
});
} else {
console.log('File is ready !');
}