map-files
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 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.name
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 read
function to change the object returned for each file.
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));
}
});
Author
Jon Schlinkert
License
Copyright (c) 2014 Jon Schlinkert, contributors.
Released under the MIT license
This file was generated by verb-cli on October 10, 2014.