Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

map-files

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

map-files - npm Package Compare versions

Comparing version 0.4.0 to 0.5.0

56

index.js

@@ -9,7 +9,7 @@ 'use strict';

var path = require('path');
var relative = require('relative');
var globby = require('globby');
/**
* Return an object for all files matching the given `patterns`
* and `options`. The full filepath of the file is used as the key.
* and `opts`. The full filepath of the file is used as the key.
*

@@ -22,38 +22,42 @@ * @param {String} `patterns` Glob patterns to pass to [globby]

module.exports = function mapFiles(patterns, options) {
var files = glob(patterns, options);
var cwd = options && options.cwd || process.cwd();
module.exports = function mapFiles(patterns, opts) {
var files = glob(patterns, opts);
var cwd = opts && opts.cwd || process.cwd();
return files.reduce(function (cache, filepath) {
filepath = relative(path.resolve(cwd, filepath));
var key = name(filepath, cache, options);
var str = read(filepath, cache, options);
return files.reduce(function (acc, fp) {
fp = path.resolve(cwd, fp);
var key = name(fp, acc, opts);
var str = read(fp, acc, opts);
cache[key] = str;
return cache;
acc[key] = str;
return acc;
}, {});
};
function glob(patterns, options) {
if (options && options.glob) {
return options.glob(patterns, options);
function glob(patterns, opts) {
if (opts && opts.glob) {
return opts.glob(patterns, opts);
}
var globby = require('globby');
return globby.sync(patterns, options);
return globby.sync(patterns, opts);
}
function name(filepath, cache, options) {
if (options && options.name) {
return options.name(filepath, cache, options);
function name(fp, acc, opts) {
if (opts && opts.name) {
return opts.name(fp, acc, opts);
}
var ext = path.extname(filepath);
return path.basename(filepath, ext);
var ext = path.extname(fp);
return path.basename(fp, ext);
}
function read(filepath, cache, options) {
if (options && options.read) {
return options.read(filepath, cache, options);
function read(fp, acc, opts) {
fp = path.resolve(fp);
if (opts && opts.read) {
return opts.read(fp, acc, opts);
}
var str = fs.readFileSync(filepath, 'utf8');
return {path: filepath, content: str};
var res = {};
res.content = fs.readFileSync(fp, 'utf8');
res.path = fp;
return res;
}
{
"name": "map-files",
"description": "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.",
"version": "0.4.0",
"version": "0.5.0",
"homepage": "https://github.com/jonschlinkert/map-files",

@@ -26,8 +26,9 @@ "author": {

"dependencies": {
"globby": "^1.1.0",
"relative": "^2.0.0"
"globby": "^1.1.0"
},
"devDependencies": {
"extend-shallow": "^1.1.1",
"gray-matter": "^1.0.1",
"mocha": "*",
"relative": "^2.0.0",
"should": "^5.0.0"

@@ -34,0 +35,0 @@ },

@@ -1,2 +0,2 @@

# map-files [![NPM version](https://badge.fury.io/js/map-files.svg)](http://badge.fury.io/js/map-files)
# map-files [![NPM version](https://badge.fury.io/js/map-files.svg)](http://badge.fury.io/js/map-files) [![Build Status](https://travis-ci.org/jonschlinkert/map-files.svg)](https://travis-ci.org/jonschlinkert/map-files)

@@ -88,8 +88,8 @@ > 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.

Copyright (c) 2014-2015 Jon Schlinkert
Released under the license
Released under the MIT license
***
_This file was generated by [verb](https://github.com/assemble/verb) on February 20, 2015._
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on February 27, 2015._
[globby]: https://github.com/sindresorhus/globby
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc