How to use the do.filter_map function in do

To help you get started, we’ve selected a few do examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github creationix / node-blog / build.js View on Github external
fs.readdir(path)(function (filepaths) {
    filepaths = filepaths.map(function (filepath) { return path + "/" + filepath; });
    Do.filter_map(filepaths, function (filepath, callback, errback) {
      fs.stat(filepath)(function (stat) {
        if (!stat.isFile()) { callback(); return ; }
        fs.readFile(filepath)(function (data) {
          callback([filepath, data]);
        }, errback);
      }, errback);
    })(function (pairs) {
      callback(pairs.reduce(function (obj, el) {
        var ext = el[0].match(/[^.]*$/)[0];
        var val = Filters[ext] ? Filters[ext](el[1]) : Filters.method_missing(ext, el[1]);
        var name = el[0].match(/([^/]*)\.[^\/]*$/)[1];
        if (typeof val === 'object') {
          val.name = name;
        }
        obj[name] = val;
        return obj;

do

The simplest way to manage asynchronicity

MIT
Latest version published 1 year ago

Package Health Score

52 / 100
Full package analysis