# common-middleware

> Common middleware for applications built with base-methods (like assemble, verb, generate, and update)

Latest version **1.0.0** (published 2017-07-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install common-middleware
pnpm add common-middleware
yarn add common-middleware
bun add common-middleware
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2017-07-16 |
| First published | 2015-11-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10.0 |
| Dependencies | 9 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Jon Schlinkert |
| Maintainers | jonschlinkert |
| Keywords | common, front, front-matter, matter, middleware, parse, templates, yaml |

## Links

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

## Dependencies (9)

- [debug](https://npm.io/package/debug.md) ^2.6.8
- [isobject](https://npm.io/package/isobject.md) ^3.0.1
- [mixin-deep](https://npm.io/package/mixin-deep.md) ^1.2.0
- [is-valid-app](https://npm.io/package/is-valid-app.md) ^0.3.0
- [file-is-binary](https://npm.io/package/file-is-binary.md) ^1.0.0
- [define-property](https://npm.io/package/define-property.md) ^1.0.0
- [middleware-utils](https://npm.io/package/middleware-utils.md) ^1.0.0
- [parser-front-matter](https://npm.io/package/parser-front-matter.md) ^1.6.4
- [middleware-rename-file](https://npm.io/package/middleware-rename-file.md) ^1.0.0

## Alternatives

- [monaco-yaml](https://npm.io/package/monaco-yaml.md) — 420.1K weekly downloads
- [@crewx/workflow](https://npm.io/package/@crewx/workflow.md) — 3.1K weekly downloads
- [yaml-cat](https://npm.io/package/yaml-cat.md) — 38 weekly downloads
- [nunjucks-in-yaml](https://npm.io/package/nunjucks-in-yaml.md) — 9 weekly downloads
- [shopify-symlinks](https://npm.io/package/shopify-symlinks.md) — 3 weekly downloads

## Recent versions

- 1.0.0 (latest) — 2017-07-16
- 0.4.1 — 2016-08-04
- 0.4.0 — 2016-08-02
- 0.3.0 — 2016-07-15
- 0.2.11 — 2016-07-13
- 0.2.10 — 2016-06-28
- 0.2.9 — 2016-05-30
- 0.2.8 — 2016-05-27
- 0.2.7 — 2016-05-27
- 0.2.6 — 2016-03-07
- 0.2.5 — 2016-01-21
- 0.2.4 — 2016-01-10
- 0.2.3 — 2016-01-10
- 0.2.2 — 2015-12-20
- 0.2.1 — 2015-12-14
- … 5 more at https://npm.io/package/common-middleware/versions

## README

# common-middleware [![NPM version](https://img.shields.io/npm/v/common-middleware.svg?style=flat)](https://www.npmjs.com/package/common-middleware) [![NPM monthly downloads](https://img.shields.io/npm/dm/common-middleware.svg?style=flat)](https://npmjs.org/package/common-middleware) [![NPM total downloads](https://img.shields.io/npm/dt/common-middleware.svg?style=flat)](https://npmjs.org/package/common-middleware) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/common-middleware.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/common-middleware)

> Common middleware for applications built with base-methods (like assemble, verb, generate, and update)

## Install

Install with [npm](https://www.npmjs.com/):

```sh
$ npm install --save common-middleware
```

## Usage

```js
var middleware = require('common-middleware');
var assemble = require('assemble-core');

// create your app
var app = assemble();

// register the middleware
app.use(middleware());
```

## Middleware

The following middleware are included.

### [front matter](index.js#L48)

Parses front-matter on files that match `options.extRegex` and
adds the resulting data object to `file.data`. This object is
passed as context to the template engine at render time.

### [unescape templates](index.js#L65)

Registers a `.preWrite` middleware for unescaping escaped delimiters.

### [escape templates](index.js#L135)

Uses C-style macros to escape templates with `{%%= foo %}` or
`<%= foo %>` syntax, so they will not be evaluated by a template
engine when `.render` is called.

### [JSON on-load](index.js#L181)

Adds a `json` property to the `file` object when the file extension
matches `options.jsonRegex`. This allows JSON files to be updated
by other middleware or pipeline plugins without having to parse and
stringify with each modification.

### [JSON pre-write](index.js#L214)

If `file.contents` has not already been updated directly, the `file.contents` property
is updated with stringified JSON before writing the file back to the file
system.

## Options

### options.jsonRegex

Customize the regex used for matching JSON files.

**Example**

```js
app.use(middleware({jsonRegex: /\.json$/}));
```

### options.extRegex

Customize the regex used for matching template file extensions.

**Example**

```js
app.use(middleware({jsonRegex: /\.(hbs|tmpl)$/}));
```

### options.escapeRegex

Customize the regex used for matching the extensions of files with templates to escape.

**Example**

```js
app.use(middleware({jsonRegex: /\.(tmpl|hbs)$/}));
```

## About

### Related projects

* [assemble-core](https://www.npmjs.com/package/assemble-core): The core assemble application with no presets or defaults. All configuration is left to the… [more](https://github.com/assemble/assemble-core) | [homepage](https://github.com/assemble/assemble-core "The core assemble application with no presets or defaults. All configuration is left to the implementor.")
* [base](https://www.npmjs.com/package/base): Framework for rapidly creating high quality node.js applications, using plugins like building blocks | [homepage](https://github.com/node-base/base "Framework for rapidly creating high quality node.js applications, using plugins like building blocks")
* [generate](https://www.npmjs.com/package/generate): Command line tool and developer framework for scaffolding out new GitHub projects. Generate offers the… [more](https://github.com/generate/generate) | [homepage](https://github.com/generate/generate "Command line tool and developer framework for scaffolding out new GitHub projects. Generate offers the robustness and configurability of Yeoman, the expressiveness and simplicity of Slush, and more powerful flow control and composability than either.")
* [update](https://www.npmjs.com/package/update): Be scalable! Update is a new, open source developer framework and CLI for automating updates… [more](https://github.com/update/update) | [homepage](https://github.com/update/update "Be scalable! Update is a new, open source developer framework and CLI for automating updates of any kind in code projects.")
* [verb](https://www.npmjs.com/package/verb): Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used… [more](https://github.com/verbose/verb) | [homepage](https://github.com/verbose/verb "Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used on hundreds of projects of all sizes to generate everything from API docs to readmes.")

### Contributing

Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).

### Building docs

_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_

To generate the readme, run the following command:

```sh
$ npm install -g verbose/verb#dev verb-generate-readme && verb
```

### Running tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

```sh
$ npm install && npm test
```

### Author

**Jon Schlinkert**

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

### License

Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT License](LICENSE).

***

_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on July 16, 2017._

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