1.2.0 • Published 3 years ago

@ironche/node-bash v1.2.0

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

Node BASH

This project aims to provide NodeJS implementation of frequently used BASH commands and extend their functionality even further.

AppVeyor AppVeyor tests npm

Installation

npm install @ironche/node-bash

Contents

  • find - search for files and folders in a folder hierarchy
  • grep - find files containing patterns

Function find()

Traverse file system and search for files and folders recursively.

Syntax

Note: All arguments are optional.

ArgumentDescription
pathFolder from where the search begins. If omitted, the default value is the current folder, which is identical to './'
descriptorPass 'f' to search only for files, 'd' to search only for folders/directories, or null (anything else) if the search applies to both.
namePatternsRegular expression (or array of regular expressions) to match names of files and folders and return them as result. Matches all names if omitted.
excludeFoldersRegular expression (or array of regular expressions) to exclude folders and their contents from search results.
depthUsed to limit the depth while traversing file system. Set to 0 to search only current level without entering any folders, 1 to go down one level, and so on. If omitted, traverses whole folder tree.

Return value: array of objects found.

import { find } from '@ironche/node-bash';
let args, results;

// find-example-1.js
args = ['.', 'f', null, /node_modules/];
results = find(...args).map((f) => f.path);
console.log(results);

/* example output
[
  './.gitignore',
  './index.js',
  './package-lock.json',
  './package.json'
]
*/

// find-example-2.js
args = ['.', 'f', /\.json$/, /node_modules/];
results = find(...args).map((f) => f.path);
console.log(results);

/* example output
[
  './package-lock.json',
  './package.json'
]
*/

Function grep()

Read files and return those containing matched patterns.

Syntax

Note: All arguments are optional.

ArgumentDescription
patternsRegular expression (or array of regular expressions) to match content of files and return files as result. Doesn't match any file if omitted.
filesArray of files found by using find function.

Return value: array of files that contain given patterns.

import { find, grep } from '@ironche/node-bash';

// find all files having extension "css"
const files = find('.', 'f', /\.css$/, /node_modules/);
// among supplied files, return only those containing text "white"
const results = grep(/white/, files);
console.log(results);

/* example output
[
  './theme-light.css',
  './button.css',
]
*/
1.2.0

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago