# 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.

Latest version **0.8.2** (published 2016-04-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install map-files
pnpm add map-files
yarn add map-files
bun add map-files
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.8.2 |
| Published | 2016-04-23 |
| First published | 2014-09-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10.0 |
| Dependencies | 4 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 14 |
| Author | Jon Schlinkert |
| Maintainers | jonschlinkert |
| Keywords | dir, directories, directory, dirs, file, filepath, filepaths, files, hash, list, map, mapping, name, object, path, paths |

## Links

- npm: https://www.npmjs.com/package/map-files
- Repository: https://github.com/jonschlinkert/map-files
- Issues: https://github.com/jonschlinkert/map-files/issues
- npm.io page: https://npm.io/package/map-files

## Dependencies (4)

- [vinyl](https://npm.io/package/vinyl.md) ^1.1.1
- [matched](https://npm.io/package/matched.md) ^0.4.1
- [isobject](https://npm.io/package/isobject.md) ^2.0.0
- [lazy-cache](https://npm.io/package/lazy-cache.md) ^1.0.4

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 0.8.2 (latest) — 2016-04-23
- 0.8.1 — 2016-04-23
- 0.8.0 — 2016-04-23
- 0.7.6 — 2016-04-23
- 0.7.5 — 2015-08-21
- 0.7.4 — 2015-04-09
- 0.7.3 — 2015-04-05
- 0.7.2 — 2015-04-05
- 0.7.1 — 2015-04-05
- 0.6.2 — 2015-03-01
- 0.6.1 — 2015-03-01
- 0.6.0 — 2015-03-01
- 0.5.1 — 2015-02-27
- 0.5.0 — 2015-02-27
- 0.4.0 — 2015-02-21
- … 7 more at https://npm.io/package/map-files/versions

## README

# map-files [![NPM version](https://img.shields.io/npm/v/map-files.svg?style=flat)](https://www.npmjs.com/package/map-files) [![NPM downloads](https://img.shields.io/npm/dm/map-files.svg?style=flat)](https://npmjs.org/package/map-files) [![Build Status](https://img.shields.io/travis/jonschlinkert/map-files.svg?style=flat)](https://travis-ci.org/jonschlinkert/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](https://www.npmjs.com/):

```sh
$ npm install map-files --save
```

**Heads up!**

Breaking changes in v0.8.0. See [the history](#history) for details.

## Usage

```js
var mapFiles = require('map-files');
console.log(mapFiles('templates/*.txt'));
```

Returns an object of [vinyl](http://github.com/gulpjs/vinyl) files that looks something like this:

```js
{ 'test/fixtures/a.txt': <File "test/fixtures/a.txt" <Buffer 41 41 41>>,
  'test/fixtures/b.txt': <File "test/fixtures/b.txt" <Buffer 42 42 42>>,
  'test/fixtures/c.txt': <File "test/fixtures/c.txt" <Buffer 43 43 43>> }
```

## Options

### options.cwd

Specify the current working directory

**Params**

Type: `String`

Default: `process.cwd()`

**Example**

```js
files('*.txt', {cwd: 'templates'});
```

### options.renameKey

Rename the key of each file object:

**Params**

Type: `Function`

Default: `file.relative`

**Example**

```js
var files = mapFiles('templates/*.txt', {
  renameKey: function (file) {
    return file.basename;
  }
});
```

Returns something like:

```js
{ 'a.txt': <File "test/fixtures/a.txt" <Buffer 41 41 41>>,
  'b.txt': <File "test/fixtures/b.txt" <Buffer 42 42 42>>,
  'c.txt': <File "test/fixtures/c.txt" <Buffer 43 43 43>> }
```

### options.decorate

Pass an object of methods to decorate as getters onto each file in the results.

```js
var yaml = require('js-yaml');

var files = mapFiles('test/fixtures/*.yml', {
  renameKey: 'stem',
  decorate: {
    yaml: function(file) {
      return yaml.safeLoad(file.contents.toString());
    }
  }
});

console.log(files.a.yaml);
//=> {title: 'AAA'}
```

## History

**v0.8.0**

* `options.name` was removed, use `options.renameKey` instead.
* `options.cache` was removed
* `options.read` was removed
* `options.decorate` was added. See the [decorate docs](#options.decorate).

**v0.5.0**

As of v0.5.0, map-files returns absolute file paths by default. You can achieve the same results by using a custom `name` function as in the [examples](#options-name).

## Related projects

You might also be interested in these projects:

* [export-files](https://www.npmjs.com/package/export-files): node.js utility for exporting a directory of files as modules. | [homepage](https://github.com/jonschlinkert/export-files)
* [file-reader](https://www.npmjs.com/package/file-reader): Read a glob of files, dynamically choosing the reader or requiring the files based on… [more](https://www.npmjs.com/package/file-reader) | [homepage](https://github.com/jonschlinkert/file-reader)
* [filter-files](https://www.npmjs.com/package/filter-files): Recursively read directories and return a list of files, filtered to have only the files… [more](https://www.npmjs.com/package/filter-files) | [homepage](https://github.com/jonschlinkert/filter-files)
* [micromatch](https://www.npmjs.com/package/micromatch): Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch. | [homepage](https://github.com/jonschlinkert/micromatch)

## Contributing

Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/map-files/issues/new).

## Building docs

Generate readme and API documentation with [verb](https://github.com/verbose/verb):

```sh
$ npm install verb && npm run docs
```

Or, if [verb](https://github.com/verbose/verb) is installed globally:

```sh
$ verb
```

## Running tests

Install dev dependencies:

```sh
$ npm install -d && npm test
```

## Author

**Jon Schlinkert**

* [github/jonschlinkert](https://github.com/jonschlinkert)
* [twitter/jonschlinkert](http://twitter.com/jonschlinkert)

## License

Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT license](https://github.com/jonschlinkert/map-files/blob/master/LICENSE).

***

_This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on April 23, 2016._

---
_Source: https://npm.io/package/map-files · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
