fx54-node

Verify existence or content of files with a hierarchical object

Usage no npm install needed!

<script type="module">
  import fx54Node from 'https://cdn.skypack.dev/fx54-node';
</script>

README

fx54-node

MEAN Module Build Status npm version Node.js Version

Verify the existence or content of files with a hierarchical object.

Installation

yarn add fx54-node

Run tests

yarn test

Example

Assume a directory like this:

- root
  - dir1
    a.txt
  - dir2
    b.txt

Example code:

import validator from 'fx54-node';

try {
  await validator.validateDirectoryAsync('./root', {
    dir1: {
      'a.txt': '<contents of a.txt>', // check the contents of a.txt
      'b.txt': false, // make sure b.txt doesn't exist
    },
    dir2: {
      'b.txt': true, // make sure b.txt exists
    },
  });

  console.log('Validation succeeded');
} catch (err) {
  console.log(`Validation failed: ${err.message}`);
}

API

  • async validateFileAsync(path: string, value: any): validates a file with a possible value.

    • string value: tests equality of the contents of file.
    • boolean value: verifies existence of the file.
  • async validateDirectoryAsync(path: string, obj: any): validates a directory with a hierarchical object. For example:

{
  dirA: {
    subDirA: {
      file1: true,
    },
    subDirB: {
      file2: "<contents>",
    },
  },
  file3: false,
}