JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4
  • Score
    100M100P100Q29842F
  • License MIT

Pull-stream file and path helpers

Package Exports

  • fpath

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (fpath) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

fpath

The fpath module is a simple module that provides some useful helpers when working with pull-streams and the file system.

entries(targetPath, opts)

A pull-stream source that generates provides the full path of files in the specified target path:

pull(
  fpath.entries(__dirname),
  pull.collect(function(err, entries) {
    console.log('found ' + entries.length + ' entries');
  })
);

filter(test)

The filter function provides a through stream that will only pass through those files that pass a truth test. As it's usually handy to have more information on the file than just it's name, the fs.stat function is called on each file before being passed to the test function.

The following example demonstrates how you could only pass through directories from an entries source stream:

pull(
  fpath.entries(__dirname),
  fpath.filter(function(filename, stats) {
    return stats.isDirectory()
  }),
  pull.collect(function(err, items) {
    // items will contain the directory names
  })
);

Additionally, a filter shortcut is available if you just want to call one of the many "is*" methods available on an fs.Stats object:

pull(
  fpath.entries(__dirname),
  fpath.filter('isDirectory'),
  pull.collect(function(err, items) {
    // items will contain directory names only
  })
);

In the case when the filter function is called without a test function provided all files will be dropped from the stream:

pull(
  fpath.entries(__dirname),
  fpath.filter(),
  pull.collect(function(err, items) {
    // no items
  })
);