1.1.1 • Published 5 years ago

objectify-fs v1.1.1

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

objectify-fs

objectify-fs is a node module that creates a JS object containing information about a directory and its children from an input root.

The return value is an array containin objects representing directories and files.

Directories objects contain their name, relative path and directory contents in an array.

File objects contain information about the name, relative path, size in bytes and the file contents.

Example file structure

{ 
    name: 'LICENSE',
    file: true,
    path: 'LICENSE',
    content: <Buffer 4d 49 54 20 4c 69... >,
    size: 1078 
}

Example directory structure

{ 
    name: '.git',
    dir: true,
    path: '.git',
    contents: [ 
        /* Array of objects in directory */ 
    ]
}

Objectify Synchronously

The objectifySync function returns an object containing data about the input directory synchronously.

The inputs are the the path to the directory as a string and an object containing options. This options object can contain an array of file extensions as strings, or an array of RegExps to match file names against.

Usage examples

const objectifyFs = require("objectify-fs");

const directoryData = objectifyFs.objectifySync("path/to/directory");

const cFiles = objectifyFs.objectifySync("path/to/directory", {
    extensions:[".c"]
});

const numberNames = objectifyFs.objectifySync("path/to/directory", {
    patterns:[new RegExp("^[0-9]+$")]
});

Objectify Asynchronously

The objectifySync function returns a promise. If no error occurs, the promise is resolved with the object representing input directory.

The inputs are the the path to the directory as a string. The options are currently not supported in the async objectify function in this version.

Usage example

const objectifyFs = require("objectify-fs");

const directoryData = objectifyFs.objectify("path/to/directory").then(console.log);

To do

The module needs:

  • Tests
  • RegExp/Extension matching on async version.