0.0.3 • Published 7 years ago

grob-files v0.0.3

Weekly downloads
3
License
ISC
Repository
github
Last release
7 years ago

Install

$ npm install --save find-file

Usage

const Grob = require('find-file');
const mdfiles = Grob.getFiles(["./filelists"],'md',true);
//Then you will get all markdown files

Parameters

(1)source

The first paramter is source folder to search file with special suffix. It can be an array or an object. When it is an object ,we will only care about value of object while key is omitted!

(2)suffix

To search file with this suffix, such as "md" or "js/jsx" and so on.

(3)isObject

When this one is set true, then we will get something like bellow with file structure of this:

npm.io

{ filelists:
   { hello: 'filelists/hello.md',
     index: 'filelists/index.md',
     md:
      { fol: { 
        index: 'filelists/md/fol/index.md'
         },
        index: 'filelists/md/index.md' 
     }
 }
}

When this paramter is false, we will get something like that:

[ 'filelists/hello.md',
  'filelists/index.md',
  'filelists/md/fol/index.md',
  'filelists/md/index.md',
]

API

(1)getFiles

Get files with special suffix

(2)traverse

Get filename with path prefixed , it is a inverse operation of getFiles.

Grob.traverse(files,function(filename){
  if(!filename)
  console.log(filename);
 //  filelists/hello.md
  // filelists/index.md
  // filelists/md/fol/index.md
  // filelists/md/index.md
})

(3)getRequiredFile(source,suffix)

Source and suffix as described above. Invoke this method you will get something like bellow:

 {
  'filelists': {
    'hello': require('C:/Users/Administrator/Desktop/find-files/filelists/hello.md'),
    'index': require('C:/Users/Administrator/Desktop/find-files/filelists/index.md'),
    'md': {
      'fol': {
        'index': require('C:/Users/Administrator/Desktop/find-files/filelists/md/fol/index.md')
      },
      'index': require('C:/Users/Administrator/Desktop/find-files/filelists/md/index.md')
    }
  }
}