Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add asObject option to return filename: file-content key/value'd objects. #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ module.exports = function readGlob(globPattern, options, cb) {
return;
}

readMultipleFiles(filePaths, options, cb);
var cb2 = options.asObject ? function(err, files) {
var o = {};
for (var i in filePaths) {
o[filePaths[i]] = files[i];
}
cb(null, o);
} : cb;
readMultipleFiles(filePaths, options, cb2);
});

return g;
Expand Down
10 changes: 9 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var test = require('tape');
var xtend = require('xtend');

test('readGlob()', function(t) {
t.plan(13);
t.plan(14);

readGlob('{.git{attributes,ignore},node_*/{glob,xtend}}', 'utf8', function(err, contents) {
t.deepEqual(
Expand All @@ -16,6 +16,14 @@ test('readGlob()', function(t) {
);
});

readGlob('{.git{attributes,ignore},node_*/{glob,xtend}}', {encoding: 'utf8', asObject: true}, function(err, contents) {
t.deepEqual(
[err, contents],
[null, {'.gitattributes': '* text=auto\n', '.gitignore': 'coverage\nnode_modules\n'}],
'should reflect encoding to the asObject result.'
);
});

var options = {
nounique: true,
ignore: '.gitignore',
Expand Down