fs-sort

0.1.0 • Public • Published

fs-sort

Build Status Coverage Status npm version

fs-sort recursivly finds all files in path and create a list of all of those files orderded by the filter function provided

Installation

$ npm i fs-sort

Get sorted files

Params:

  • path - Path to get files from
  • ignores - Array of file names to ignore
  • sortingFunction - The function that "chooses" what file property to use for sorting. sortingFunction receive the parameter fileObject which is in the form of:
{
  fileName: "Name of the file, including the extension",
  fileStats: "File stats that dependes on the version of node you are running and the OS",
  fileFullPath: "Full file path to system root folder"
}
  • callback - A callback in the form of function(err, orderedFileList)
Example:
var fs_sort = require('fs-sort')
 
var sortingFunction = function (fileObject) {
  return fileObject.fileName
}
 
fs_sort('/data', [], sortingFunction, function (err, list) {
  if (err) throw err
  for (var file in list) {
    console.log(list[file])
    // Will print something like this:
    // {
    //  fileName: '8.tmp',
    //  fileStats:
    //  {
    //    dev: 16777220,
    //    mode: 33188,
    //    nlink: 1,
    //    uid: 502,
    //    gid: 20,
    //    rdev: 0,
    //    blksize: 4096,
    //    ino: 21894243,
    //    size: 8230522,
    //    blocks: 16080,
    //    atime: Thu Jun 11 2015 03:27:26 GMT+0300 (IDT),
    //    mtime: Thu Jun 11 2015 03:27:26 GMT+0300 (IDT),
    //    ctime: Thu Jun 11 2015 03:27:26 GMT+0300 (IDT)
    //   },
    //   fileFullPath: '/Users/username/folder/data/8.tmp',
    //   mainAttribute: '8.tmp'
    // }
  }
})

Testing

In order to test you need to install mocha globaly on your machine

cd /"module-path"/fs-sort
$ mocha

License

MIT

Package Sidebar

Install

npm i fs-sort

Weekly Downloads

3

Version

0.1.0

License

MIT

Last publish

Collaborators

  • bejavu
  • oleiba
  • thehobbit85