@amjs/utils-fs

0.1.4 • Public • Published

@amjs/utils-fs 0.1.4

Statements Branches Functions Lines

Provides set of top-level utilities for filesystem management

Installation

$ npm i @amjs/utils-fs

Usage

Given the following tre:

/
    folder/
        file.txt
        index.html

make-folder

Creates a folder following a complete path address.

const { makeFolder } = require('@amjs/utils-fs');
const path = require('path');

const root = path.join('/', 'folder', 'new-folder'); // '/folder/new-folder'
makeFolder(root);

Will output following tree:

/
    folder/
        new-folder/
        file.txt
        index.html

scan-dir

Scans a folder returning an array with all contained file paths.

const { scanDir } = require('@amjs/utils-fs');
const path = require('path');

const root = path.join('/', 'folder');
let files = scanDir(root);
console.log(files); // [ '/folder/file.txt', '/folder/index.html' ]

// Use second argument to exclude files from output
files = scanDir(root, [ path.join(root, 'file.txt') ];
console.log(files); // [ '/folder/index.html' ]

// Use third argument to filter output by a regular expression
files = scanDir(root, [], /.+\.m?js$/);
console.log(files); // []

Package Sidebar

Install

npm i @amjs/utils-fs

Weekly Downloads

1

Version

0.1.4

License

MIT

Unpacked Size

26 kB

Total Files

15

Last publish

Collaborators

  • amjs