file-checker
Simple module to check for file status
Last updated 4 years ago by ok3x .
ISC · Original npm · Tarball · package.json
$ cnpm install file-checker 
SYNC missed versions from official npm registry.

File checker module

Simple module to check for file status. This is an initial version, more features to come!

Installation

In your project folder run:

npm install --save file-checker

Note: The module code uses few ES6 features, so at least 4.4.5 version of Node is required.

Usage

First, you need to include the file checker.

const checker = require('file-checker').create();

Second, specify the files (or directories) that need to be checked.

checker.addRule('/path/to/file'); By default, the checker only checks whether the given file exists.

However, you can pass additional options to fine-tune the assertion rules:

checker.addRule('/path/to/file', { exists: true }); // equivalent to above

Note: It is strongly recommended to use absolute file paths, but the checker also works with relative ones.

List of supported options (all options are optional):

  • exists - whether the file/directory exists
  • isFile - whether the path is file
  • isDirectory - whether the path is directory
  • size - filesize in bytes
  • accessed - time when file data last accessed (numeric value)
  • modified - time when file data last modified
  • changed - time when file status was last changed
  • created - time of file creation

For example, let's check if a file exists and fits specific size:

checker.addRule('/path/to/file', {
    exists: true,
    isFile: true,
    size: (size) => {
        // custom assertion logic
        return size < 1024*1024; // 1 MB
    }
});

Third, process the rules and review results.

checker.run() // returns promise
.then((results) => {
    console.log('results', results);
})
.catch((error) => {
    console.log('unexpected error occured', error);
});

Current Tags

  • 1.0.1                                ...           latest (4 years ago)

2 Versions

  • 1.0.1                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 2
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |