From d66a6aac29a3ca36865b26fc89e50cd677dc263c Mon Sep 17 00:00:00 2001 From: rektide Date: Sun, 28 Feb 2016 23:32:37 -0500 Subject: [PATCH] Add asObject option to return filename: file-content key/value'd objects. --- index.js | 9 ++++++++- test.js | 10 +++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 0b31038..2849893 100755 --- a/index.js +++ b/index.js @@ -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; diff --git a/test.js b/test.js index 26d0893..02e9230 100755 --- a/test.js +++ b/test.js @@ -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( @@ -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',