JSPM

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

Return an object for a glob of files. Pass a `rename` function for the keys, or a `parse` function for the content, allowing it to be used for readable or require-able files.

Package Exports

  • map-files

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 (map-files) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

map-files NPM version

Return an object for a glob of files. Pass a rename function for the keys, or a parse function for the content, allowing it to be used for readable or require-able files.

Install

Install with npm:

npm i map-files --save-dev

Run tests

npm test

Usage

var mapFiles = require('map-files');
console.log(mapFiles('lib/*.txt'));

Returns an object that looks something like:

{ a: { path: 'test/fixtures/a.txt', contents: 'This is file a.txt.' },
  b: { path: 'test/fixtures/b.txt', contents: 'This is file b.txt.' },
  c: { path: 'test/fixtures/c.txt', contents: 'This is file c.txt.' } }

API

mapFiles

  • patterns {String}: Glob patterns to pass to globby
  • opts {Object}: Options for globby, or pass a custom parse or rename.
  • returns: {Object}

Return an object for all files matching the given patterns and options. The basename of the file is used as the key.

Examples

options.rename

Pass a rename function to be used as the key of each file object:

var files = mapFiles('lib/*.txt', {
  rename: function (filepath) {
    return path.basename(filepath);
  }
});
console.log(files);

Returns something like:

{ 'a.txt': { path: 'test/fixtures/a.txt', contents: 'This is file a.txt.' },
  'b.txt': { path: 'test/fixtures/b.txt', contents: 'This is file b.txt.' },
  'c.txt': { path: 'test/fixtures/c.txt', contents: 'This is file c.txt.' } }

options.parse

Pass a parsing function to change the object returned for each file. The default function reads files and returns a string. This example shows how you might instead require each file.

var files = mapFiles('lib/*.txt', {
  parse: function (filepath) {
    return {
      path: filepath,
      fn: require(path.resolve(filepath))
    }
  }
});
console.log(files);

Returns something like:

{ a: { path: 'test/fixtures/a.js', fn: { foo: [Function: foo] } },
  b: { path: 'test/fixtures/b.js', fn: { bar: [Function: bar] } },
  c: { path: 'test/fixtures/c.js', fn: { baz: [Function: baz] } } }

Author

Jon Schlinkert

License

Copyright (c) 2014 Jon Schlinkert, contributors.
Released under the MIT license


This file was generated by verb-cli on September 20, 2014.