# defender

> Defending inputs across the land.

Latest version **0.1.1** (published 2013-12-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install defender
pnpm add defender
yarn add defender
bun add defender
```

## 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 | 2013-12-10 |
| First published | 2013-11-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 9 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 27 |
| Author | Simon Richardson |
| Maintainers | stickupkid |

## Links

- npm: https://www.npmjs.com/package/defender
- Repository: https://github.com/SimonRichardson/fantasy-world
- Homepage: https://github.com/SimonRichardson/defender
- npm.io page: https://npm.io/package/defender

## Dependencies (9)

- [daggy](https://npm.io/package/daggy.md) 0.0.x
- [fantasy-io](https://npm.io/package/fantasy-io.md) 0.0.x
- [fantasy-states](https://npm.io/package/fantasy-states.md) 0.2.x
- [fantasy-tuples](https://npm.io/package/fantasy-tuples.md) 0.0.x
- [fantasy-eithers](https://npm.io/package/fantasy-eithers.md) 0.0.x
- [fantasy-helpers](https://npm.io/package/fantasy-helpers.md) 0.0.x
- [fantasy-options](https://npm.io/package/fantasy-options.md) 0.0.x
- [fantasy-combinators](https://npm.io/package/fantasy-combinators.md) 0.0.x
- [fantasy-validations](https://npm.io/package/fantasy-validations.md) 0.0.x

## Recent versions

- 0.1.1 (latest) — 2013-12-10
- 0.0.1 — 2013-11-05

## README

# Defender

### Defending inputs across the land.

![](https://raw.github.com/fantasyland/fantasy-land/master/logo.png)

* * *

### Build

#### Browser 

You have a lot of alternatives (requirejs, AMD), but to get started
quickly you can use [commonjseverywhere](https://github.com/michaelficarra/commonjs-everywhere).

```
cjsify defenders.js --no-node --export defenders --source-map defenders.browser.js.map >defenders.browser.js
```

* * *

#### Demo

Example of sort code validation in different guises using [defender](http://simonrichardson.github.io/defender/)

* * *

#### Soothsayer

The Soothsayer is interlinked to the Fortune teller, but the basic
idea is that you create a Soothsayer and give it a pattern that 
can be parsed and replaced by other things (RegExp, DOM elements).

The Soothsayer is not restricted by the bounds of the validator,
just what you pass in for the look up of the pattern. If nothing
is found an error is thrown.

To help with this we have Runes, which make it easier to work with
Regular Expressions.

* * *

##### Example

The following example creates a Soothsayer and generates a possible
future of regular expressions.

```javascript
var pattern = IO(function() {
  return '##-##-##';
});
var sayer = soothsayer({
    '#': /^[0-9]/,
    '-': /^-/
})(pattern);
```

* * *

#### Guardian

The Guardians job in the flow is to remove any items from the input
that you don't want to be validated by the Defender. In turn
guarding the Defender.

It's a simple premise of using a regular expression to attempt to
normalise the user input as much as possible, such as trimming 
the white space front and back or removing comments.

* * *

##### Example

The following example creates a Guardian which will guard against
white space.

```javascript
var guard = guardian(/^\s/);
```

* * *

#### Defender

The Defenders job is go through the Soothsayers runes and check
the input against those runes. The result is either a failure or
a success.

If the result is a failure a stack trace of where the input failed
is passed back along with the position. This should make it easier
to see what failed and where.

* * *

##### Example

The following example creates a Defender that when called uses
the Guardian to guard the input.

```javascript
var defend = defender(sayer);
defend(guard(io));
```

* * *

#### Fortune Teller

The Fortune Tellers job is to decipher what the input field could
possibly look like on key down, before the text has been entered.
From there it should be possible to pipe this into the Defenders
to then work out if a input is permitted. 

The role of a Fortune Teller is highly specialized and because of
this a lot more information is required to do the job at hand.

* * *

##### Example

The following uses a value of the current input field, it then
grabs what the event is along with any key information (unicode
characters etc...) and then finally the selection upon where the
new character needs to be added, removed etc.

```javascript
fortune(value)(fromEvent(e), selection);
```

* * *

### Steward

A Steward attends over the processing of a value, by looking in to
the value, attending to it's various needs before putting the value
back into it's original type.

The role of the Steward is to preside over internal modifications
of a value.

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