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

Return an object for a glob of files. Pass a
renamefunction for the keys, or aparsefunction for the content, allowing it to be used for readable or require-able files.
As of v0.5.0, map-files returns absolute file paths by default. You can achieve the same results by using a custom name function as in the examples.
Install with npm
npm i map-files --saveRunning tests
Install dev dependencies.
npm i -d && npm testUsage
var files = require('map-files');
console.log(files('templates/*.txt'));Returns an object that looks something like:
{ a: { content: 'AAA', path: 'templates/a.txt' },
b: { content: 'BBB', path: 'templates/b.txt' },
c: { content: 'CCC', path: 'templates/c.txt' }}options.cache
Type: Boolean
Default: false
If true, results will be cached in memory so that subsequent lookups for the same cwd and patterns don't repeatedly hit the file system.
options.cwd
Type: String
Default: process.cwd()
Specify the current working directory
files('*.txt', {cwd: 'templates'});options.name
Type: Function
Default: path.basename(fp, path.extname(fp))
Rename the key of each file object:
var templates = files('templates/*.txt', {
name: function (filepath) {
return path.basename(filepath);
}
});Returns something like:
{ 'a.txt': { content: 'AAA', path: 'templates/a.txt' },
'b.txt': { content: 'BBB', path: 'templates/b.txt' },
'c.txt': { content: 'CCC', path: 'templates/c.txt' }}options.read
Pass a custom
readfunction to change the object returned for each file.
Type: Function
Default: fs.readFileSync()
The default function reads files and returns a string, but you can do anything
you want with the function, like require files:
var helpers = files('helpers/*.js', {
read: function (fp) {
return require(path.resolve(fp));
}
});
//=> { a: [Function: foo], b: [Function: bar], c: [Function: baz] }Author
Jon Schlinkert
License
Copyright (c) 2014-2015 Jon Schlinkert
Released under the MIT license
This file was generated by verb-cli on March 01, 2015.