file-reader
Advanced tools
Comparing version 0.2.1 to 0.2.2
44
index.js
@@ -19,4 +19,7 @@ /*! | ||
read: function(fp) { | ||
fp = path.resolve(fp); | ||
return reader(path.extname(fp))(fp); | ||
var ext = path.extname(fp); | ||
if (!reader.hasOwnProperty(ext)) { | ||
ext = '.txt'; | ||
} | ||
return reader[ext](path.resolve(fp)); | ||
} | ||
@@ -35,23 +38,18 @@ }, options)); | ||
function reader(ext) { | ||
switch (ext) { | ||
// Requireable files | ||
case '.js': | ||
case '.json': | ||
return require; | ||
var reader = { | ||
// Functions | ||
'.js' : require, | ||
// Strings | ||
case '.txt': | ||
case '.md': | ||
case '.hbs': | ||
return fs.readFileSync; | ||
// Strings | ||
'.hbs' : fs.readFileSync, | ||
'.md' : fs.readFileSync, | ||
'.tmpl': fs.readFileSync, | ||
'.txt' : fs.readFileSync, | ||
// Data | ||
case '.yml': | ||
case '.yaml': | ||
return fs.readYAMLSync; | ||
} | ||
} | ||
// Objects | ||
'.json': require, | ||
'.yaml': fs.readYAMLSync, | ||
'.yml' : fs.readYAMLSync, | ||
}; | ||
/** | ||
@@ -66,8 +64,12 @@ * Camelcase rename function to pass to [map-files]. | ||
var str = path.basename(fp, path.extname(fp)); | ||
if (/\./.test(str)) { | ||
str = str.split('.')[0]; | ||
} | ||
if (str.length === 1) { | ||
return str; | ||
} | ||
return str.toLowerCase().replace(/[-_.](\w|$)/g, function (_, ch) { | ||
str = str.replace(/^[-_.\s]+/, '').toLowerCase(); | ||
return str.replace(/[-_.]+(\w|$)/g, function (_, ch) { | ||
return ch.toUpperCase(); | ||
}); | ||
} |
{ | ||
"name": "file-reader", | ||
"description": "Read a glob of files, dynamically choosing the reader or requiring the files based on the file extension.", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"homepage": "https://github.com/jonschlinkert/file-reader", | ||
@@ -6,0 +6,0 @@ "author": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8020
102
3