is-my-file-ready

Small utility to check if a file is ready to be worked with.

Usage no npm install needed!

<script type="module">
  import isMyFileReady from 'https://cdn.skypack.dev/is-my-file-ready';
</script>

README

is-my-file-ready

NPM version build status Test coverage npm download

Small utility to check if a file is ready to be worked with.

Installation

$ npm i is-my-file-ready

Usage

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 !');
}

Documentation

See https://zakodium.github.io/is-my-file-ready

License

MIT