# froid

> Froid is a sanity checker

Latest version **1.3.3** (published 2017-06-15) · GPL-2.0 license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

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

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.3.3 |
| Published | 2017-06-15 |
| First published | 2015-11-17 |
| Weekly downloads | 0 |
| License | GPL-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+3 in 1 direct dependencies) |
| Install scripts | no |
| Author | MySidesTheyAreGone |
| Maintainers | mysidestheyaregone |
| Keywords | froid, sanity, sanity check |

## Links

- npm: https://www.npmjs.com/package/froid
- Repository: https://gitlab.com/egeria/froid
- Homepage: https://gitlab.com/egeria/egeria
- Issues: https://gitlab.com/egeria/egeria/issues
- npm.io page: https://npm.io/package/froid

## Dependencies (4)

- [ramda](https://npm.io/package/ramda.md) 0.24.1
- [moment](https://npm.io/package/moment.md) 2.18.1
- [valid-url](https://npm.io/package/valid-url.md) 1.0.9
- [cron-parser](https://npm.io/package/cron-parser.md) 2.4.0

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

- 1.3.3 (latest) — 2017-06-15
- 1.3.2 — 2017-01-09
- 1.3.1 — 2016-11-14
- 1.3.0 — 2016-08-25
- 1.2.5 — 2016-05-13
- 1.2.4 — 2016-04-12
- 1.2.3 — 2016-03-29
- 1.2.2 — 2016-03-14
- 1.2.1 — 2016-02-25
- 1.2.0 — 2016-02-17
- 1.1.3 — 2016-02-17
- 1.1.2 — 2016-02-12
- 1.1.1 — 2016-02-11
- 1.1.0 — 2016-02-11
- 1.0.0 — 2016-02-10
- … 14 more at https://npm.io/package/froid/versions

## README

# [![Froid](https://gitlab.com/egeria/froid/raw/master/logo/logo_small.png)](https://gitlab.com/egeria/froid) Froid

[![NPM version](http://img.shields.io/npm/v/froid.svg)](https://www.npmjs.com/package/froid)
[![Downloads](https://img.shields.io/npm/dm/froid.svg)](https://www.npmjs.com/package/froid)

[![NPM](https://nodei.co/npm/froid.png?downloads=true&stars=true)](https://nodei.co/npm/froid/)

## Changelog (latest relevant releases)

### v1.2.2
 - Added check `after`

### v1.2.0
 - Breaking change: renamed `children` to `fields`
 - Added `requireOne` check to specify alternatives

### v1.1.3
 - Added `depends` check


## About

Be careful using my stuff: I'm an amateur.

Froid is a sanity checker, just like Freud, but more French: "Froid" is the pronunciation of "Freud" written as if it was an Italian word, but it also happens to be a French word that has an entirely different meaning. I have no idea why I'm writing this.

## Sanity in theory

The `sanity` of an object (from now on `loony`) is defined in object form. It has one field for every field the `loony` has, named exactly the same.

Assuming that all of `loony`'s fields are supposed to hold a simple value such as a constructed object (Date, Function, MyCrazyClass, etc.), an Array, a String or a Number, the value of each of `sanity`'s fields is a `test` object.

`test`s have a field for each `check` the test needs to perform; the value of each `check` defines what is valid and/or what isn't.

As for the fields `loony` may have that are not constructed objects, meaning they are object literals, the corresponding fields in `sanity` will not hold a `test` object; they will hold an identical object literal instead. `loony`s object literals are treated as other loonies, and their corresponding part of `sanity` will be treated as their sanity check.

`froid` `check`s the `loony`'s fields according to the `test`s. If something is wrong, it produces a moderately helpful message such as "'type' must be one of \['one', 'two'\], got 'three' instead". Finally, all of the error messages are concatenated and returned.

If the `loony` passes all of the `test`s, `froid` simply leaves his house, returning a sad `null`.

At the moment `froid` can perform a rather limited number of `check`s. I add new ones as needed.

## Sanity in practice

In the following example a couple of silly loonies have forgotten part or all of their address. Froid quickly reprimands them. Notice how Joe's appreciation of pickles is completely ignored - Froid can't be distracted easily.

```js
var froid = require('froid');

var sanity = {
    address: { mandatory: true, type: String }
};

var loonieJoe = {
    pickles: 'tasty'
};

console.log(froid(sanity, loonieJoe));
// => "address" is mandatory, got undefined instead

var loonieMark = {
    address: 5
};

console.log(froid(sanity, loonieMark));
// => "address" must be a String, got Number instead
```

High-functioning psychos Brad and Colin may know how to fake, but they are still no match for Froid's recursive inspection:

```js
var froid = require('froid');

var sanity = {
    address: {
        mandatory: true,
        fields: {
            road: { type: String, mandatory: true },
            number: { type: Number, greaterThan: 0, mandatory: true },
            city: { type: String, mandatory: true }
        }
    }
};

var loonieBrad = {
    address: 'somewhere'
};

console.log(froid(sanity, loonieBrad));
// => "address" must be a Object, got String instead


var loonieColin = {
    address: {
        road: 5,
        number: 'Bedlam Avenue'
    }
};

console.log(froid(sanity, loonieColin));
// => (in a single unbroken string)
// => "address.road" must be a String, got Number instead;
// => "address.number" must be a Number, got String instead;
// => "address.number" must be greater than 0, got Bedlam Avenue instead;
// => "address.city" is mandatory, got undefined instead
```

As you can see from the messages about `address.number`, if a field violates more than one sanity rule Froid will report all of the failures rather than stop at the first one. This may help you fix all of the problems at once before testing again. It doesn't happen in the first case, when the entire `address` object Froid is supposed to check is missing; in that case he simply calls you an idiot and leaves.

Sometimes people are perfectly sane:

```js
var froid = require('froid');

var sanity = {
    everything: String
};

var coolGuy = {
    everything: 'OK'
};

console.log(froid(sanity, coolGuy));
// => null
```

## Checks currently supported

I'll add a bit to this section every day until I've documented everything. If you're reading this on NPM, come check this readme on [github](https://github.com/MySidesTheyAreGone/froid), where I can update it without releasing a new version after every change.

Have fun!

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