1.0.27 • Published 5 years ago

adirr v1.0.27

Weekly downloads
4
License
ISC
Repository
github
Last release
5 years ago

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)

  1. description: simple wrap of the readdirSync.
  2. params: notype(string): if (notype = "names") return string of names
  3. return: Names of files and directories in the root
  4. return type: Array of Dirnet || Array of strings
  5. example:
cm(root).dir()

open(name)

  1. description: open folder in the root folder || opens absolute path
  2. params: str(string) - name of the folder to open
  3. return: new handler with updated root
  4. return type: adirr
  5. example:
cm.open(cm(root).dir("names")[1]).dir() //opens the second folder in the root folder and returns its content

mkdir(name, openNewDir)

  1. description: make a directory with the given @param@name
  2. params: name(string)- name of the directory to open, openNewDir(bool/string)- if set to true (or "open") open the new dir
  3. return: handler to the root/ to the new directory
  4. return type: adirr
  5. example:
cm.mkdir("newdir","open").mkdir("anothernewdir").dir() // create "newdir/anothernewdir",display newdir

mkdir(names)

  1. description: make directories with each name of names array
  2. params: names(array)- contain names of the directories
  3. return: same as above
  4. return type: same as above

search(str):

  1. description: recursivesearch for a file name (regex search) in a folders and all of its sub-folders
  2. params: str(string)- a string to search by a regexsearch
  3. return: returns an object called:
    searchedObject {
    path: current path
    members: [files matched to the search -OR- searchedObject for sub-folders]
    }
  1. return type: object
  2. example:
cm.search('test.txt')

save(fname, data):

  1. description: save the data in a (possibly new) file with fname name in the root folder
  2. params: fname- name with extension of the file, (string)data- the data to append
  3. return: -void-
  4. example:
    cm.save("search-results.txt";,JSON.stringify(cm.search('test.txt'),null,1));

files(str = root):

  1. 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
  2. params: str path that's default is root and can be absolute path
  3. return: Array
  4. 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'}):

  1. description: simmple wrapper to readFileSync
  2. params: name- the name of the file, relative to the root options- an object that my contain optional flag and encoding (default to utf8)
  3. return: String||Buffer
  4. 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