1.0.5 • Published 7 years ago

fx58-node v1.0.5

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

fx58-node

MEAN Module Build Status npm version Node.js Version

An elegant solution to list files

Installation

# yarn
yarn add fx58-node

# npm
npm install --save fx58-node

Run tests:

# yarn
yarn test

# npm
npm test

API

import listAsync from 'fx58-node';
// or Node.js style: const listAsync = require('fx58-node').default;

const files = await listAsync(
  directory,  // the path of directory
  recursive,  // defaults to false
  fileFilter, // file filter, defaults to null
  dirFiler,   // directory filter, defaults to null
);

Example

Assume a directory like this:

data
├── .DS_Store
├── .sys
│   ├── t.json
│   └── t.txt
├── .sys.json
├── a
│   ├── .sys.json
│   ├── t.json
│   └── t.txt
├── t.json
└── t.txt
import listAsync from 'fx58-node';

(async () => {
  let files = [];
  files = await listAsync('./data');
  console.log(files);
  /* 
  [ 'data/.DS_Store',
    'data/.sys.json',
    'data/t.json',
    'data/t.txt' ]
  */

  files = await listAsync('./data', true);
  console.log(files);
  /* 
  [ 'data/.DS_Store',
    'data/.sys.json',
    'data/t.json',
    'data/t.txt',
    'data/.sys/t.json',
    'data/.sys/t.txt',
    'data/a/.sys.json',
    'data/a/t.json',
    'data/a/t.txt' ]
  */

  files = await listAsync('./data', true, (file) => {
    return /.*\.txt$/i.test(file) && !file.startsWith('.');
  });
  console.log(files);
  /*
    [ 'data/t.txt', 'data/.sys/t.txt', 'data/a/t.txt' ]
  */

  files = await listAsync('./data', true,
  (file) => {
    return /.*\.txt$/i.test(file) && !file.startsWith('.');
  },
  (dir) => {
    return !dir.startsWith('.');
  });
  console.log(files);
  /*
    [ 'data/t.txt', 'data/a/t.txt' ]
  */

})();
1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago