# lux-unless

> Conditionally add a middleware to Lux with some common patterns.

Latest version **0.1.1** (published 2016-11-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install lux-unless
pnpm add lux-unless
yarn add lux-unless
bun add lux-unless
```

## 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.1.1 |
| Published | 2016-11-03 |
| First published | 2016-11-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 6.0 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Nick Schot |
| Maintainers | nickschot |
| Keywords | condition, conditional, lux, lux-middleware |

## Links

- npm: https://www.npmjs.com/package/lux-unless
- Repository: https://github.com/nickschot/lux-unless
- Homepage: https://github.com/nickschot/lux-unless#readme
- Issues: https://github.com/nickschot/lux-unless/issues
- npm.io page: https://npm.io/package/lux-unless

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.1.1 (latest) — 2016-11-03
- 0.1.0 — 2016-11-02

## README

Conditionally skip a middleware when a condition is met.

[![Build Status](https://travis-ci.org/nickschot/lux-unless.svg?branch=master)](https://travis-ci.org/nickschot/lux-unless) [![Coverage Status](https://coveralls.io/repos/github/nickschot/lux-unless/badge.svg?branch=master)](https://coveralls.io/github/nickschot/lux-unless?branch=master) [![npm version](https://badge.fury.io/js/lux-unless.svg)](https://badge.fury.io/js/lux-unless)

This is a port of [express-unless](https://github.com/jfromaniello/express-unless) to the [Lux](https://github.com/postlight/lux) API framework.

## Install

	npm i lux-unless --save

## Usage

You can use lux-unless in Lux with a middleware called `myMiddleware` as follows:

```javascript
import unless from 'lux-unless';

class ApplicationController extends Controller {
    beforeAction = [
        unless({path: ['/users/login']}, myMiddleware)
    ];
}
```

## Current options

-  `method` it could be an string or an array of strings. If the request method match the middleware will not run.
-  `path` it could be an string, a regexp or an array of any of those. It also could be an array of object which is url and methods key-pairs. If the request path or path and method match, the middleware will not run. Check [Examples](#examples) for usage.
-  `ext` it could be an string or an array of strings. If the request path ends with one of these extensions the middleware will not run.
-  `custom` it must be a function that accepts `req` and returns `true` / `false`. If the function returns true for the given request, the middleware will not run.


## Examples

Require authentication for every request unless the path is index.html.

```javascript
unless({
  path: [
    '/index.html',
    { url: '/', methods: ['GET', 'PUT']  }
  ]
}, requiresAuth);
```

Avoid a fstat for request to routes which don't end with a given extension.

```javascript
unless(function (req) {
  var ext = url.parse(req.originalUrl).pathname.substr(-4);
  return !~['.jpg', '.html', '.css', '.js'].indexOf(ext);
}, static);
```

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