1.0.27 • Published 5 years ago
adirr v1.0.27
This module is meant to handle usage of folders with simple functions.
1. Usage:
1.1 Install
npm i adirr
1.2 call the module:
let root = "a valid root";
let cm = require("adirr").adirr(root);
there is an option to call adirr(root,true) which will console.log details like where an operation is taking place
1.3 functions:
dir(notype)
- description: simple wrap of the readdirSync.
- params:
notype(string)
: if (notype = "names") return string of names - return: Names of files and directories in the root
- return type: Array of Dirnet || Array of strings
- example:
cm(root).dir()
open(name)
- description: open folder in the root folder || opens absolute path
- params:
str(string)
- name of the folder to open - return: new handler with updated root
- return type:
adirr
- example:
cm.open(cm(root).dir("names")[1]).dir() //opens the second folder in the root folder and returns its content
mkdir(name, openNewDir)
- description: make a directory with the given @param@name
- params:
name(string)
- name of the directory to open,openNewDir(bool/string)
- if set totrue
(or "open") open the new dir - return: handler to the root/ to the new directory
- return type:
adirr
- example:
cm.mkdir("newdir","open").mkdir("anothernewdir").dir() // create "newdir/anothernewdir",display newdir
mkdir(names)
- description: make directories with each name of names array
- params:
names(array)
- contain names of the directories - return: same as above
- return type: same as above
search(str):
- description: recursivesearch for a file name (regex search) in a folders and all of its sub-folders
- params:
str(string)
- a string to search by a regexsearch - return: returns an object called:
searchedObject {
path: current path
members: [files matched to the search -OR- searchedObject for sub-folders]
}
- return type: object
- example:
cm.search('test.txt')
save(fname, data):
- description: save the
data
in a (possibly new) file withfname
name in the root folder - params:
fname
- name with extension of the file,(string)data
- the data to append - return: -void-
- example:
cm.save("search-results.txt";,JSON.stringify(cm.search('test.txt'),null,1));
files(str = root):
- description: gives an array of all the files (include double names) in that path and all sub directories, makes it very easy to handle and search in massive folder
- params:
str
path that's default is root and can be absolute path - return:
Array
- example: the following function will print only txt files, in the order of the shortest name first.
console.log(cm.files().filter(ele=>{
return path.extname(ele)==".txt";
}).sort((a,b)=> a.length>b.length));
read(name,options = {encoding:'utf8'}):
- description: simmple wrapper to readFileSync
- params:
name
- the name of the file, relative to the rootoptions
- an object that my contain optional flag and encoding (default to utf8) - return:
String
||Buffer
- example:
data = cm.read('mytextfile.txt');
1.0.27
5 years ago
1.0.26
5 years ago
1.0.25
5 years ago
1.0.24
5 years ago
1.0.23
5 years ago
1.0.22
5 years ago
1.0.21
5 years ago
1.0.20
5 years ago
1.0.19
5 years ago
1.0.18
5 years ago
1.0.17
5 years ago
1.0.16
5 years ago
1.0.15
5 years ago
1.0.14
5 years ago
1.0.13
5 years ago
1.0.12
5 years ago
1.0.11
5 years ago
1.0.10
5 years ago
1.0.9
5 years ago
1.0.8
5 years ago
1.0.6
5 years ago
1.0.5
5 years ago
1.0.4
5 years ago
1.0.3
5 years ago
1.0.2
5 years ago
1.0.1
5 years ago
1.0.0
5 years ago