npm.io
1.1.0 • Published 6 years ago

node-file-navigator

Licence
MIT
Version
1.1.0
Deps
0
Size
9 kB
Vulns
0
Weekly
0

Node file navigator

Build Status

This simple application will enable you to navigate through a directory; recursively if required, filtering files and directories and applying custom processing on the file selected.

Required

Stable NodeJS version

Dependencies

None

How to add to your application

Add this module to your application as a dependency

npm i node-file-navigator
const fileNavigator = require('node-file-navigator');

API Reference

Method invocation
fileNavigator({ directory, fileSkipPattern, isRecursive, directorySkipPattern, callback, ...other })
Paramaters
Parameter Type Usage Example
direcorty String directory for navigation '/user/home/app'
fileSkipPattern Function : ({ path, stat }) If returns true processing of the file is skipped ({path}) => (/.css$/.test(path))
isRecursive Boolean should navigate nested directories true
directorySkipPattern Function : ({ path, stat }) If returns true navigation of the directory is skipped ({path}) => (/node_modules$/.test(path))
callback Function: ({ path, stat}) Define the file opration ({ path }) => { console.log(path); }
other Object N/A N/A
Example
/**
 * An application to navigate through all .js files in the working directory
 * and nested directories and print the paths in the terminal without going through node_modules folder.
 *
*/
// Import 
const fileNavigator = require('node-file-navigator');

const directory = __dirname;
const fileSkipPattern = ({ path }) => !/.js$/.test(path);
const isRecursive = true;
const directorySkipPattern = ({ path }) => /node_modules/.test(path);
const callback = ({ path }) => { console.log(path); }

// Invoke
await fileNavigator({ directory, fileSkipPattern, isRecursive, directorySkipPattern, callback });

Keywords