# doormen

> Validate, sanitize and assert: the silver bullet of data!

Latest version **0.15.11** (published 2025-05-30) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 25/100 (F)** — status: maintenance-mode.

Positive: no vulnerabilities.

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

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.15.11 |
| Published | 2025-05-30 |
| First published | 2015-06-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=16.13.0 |
| Dependencies | 2 |
| Unpacked size | 1.2 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Cédric Ronvel |
| Maintainers | cronvel |
| Keywords | doormen, data, validation, validator, sanitize, assert, assertion, bdd, tdd |

## Links

- npm: https://www.npmjs.com/package/doormen
- Repository: https://github.com/cronvel/doormen
- Homepage: https://github.com/cronvel/doormen#readme
- Issues: https://github.com/cronvel/doormen/issues
- npm.io page: https://npm.io/package/doormen

## Dependencies (2)

- [tree-kit](https://npm.io/package/tree-kit.md) ^0.8.8
- [string-kit](https://npm.io/package/string-kit.md) ^0.19.2

## Alternatives

- [@regle/core](https://npm.io/package/@regle/core.md) — 47.0K weekly downloads
- [typeof-arguments](https://npm.io/package/typeof-arguments.md) — 12.5K weekly downloads
- [@lokalise/projects-engine-contracts](https://npm.io/package/@lokalise/projects-engine-contracts.md) — 978 weekly downloads
- [@osjwnpm/nam-laboriosam-quibusdam](https://npm.io/package/@osjwnpm/nam-laboriosam-quibusdam.md) — 70 weekly downloads
- [@oridune/validator](https://npm.io/package/@oridune/validator.md) — 16 weekly downloads

## Recent versions

- 0.15.11 (latest) — 2025-05-30
- 0.15.10 — 2025-03-13
- 0.15.9 — 2025-03-10
- 0.15.8 — 2025-03-10
- 0.15.7 — 2025-03-05
- 0.15.6 — 2024-08-14
- 0.15.5 — 2024-02-28
- 0.15.4 — 2024-02-28
- 0.15.3 — 2023-09-04
- 0.15.2 — 2023-08-17
- 0.15.1 — 2023-08-04
- 0.15.0 — 2023-07-21
- 0.14.9 — 2023-03-22
- 0.14.8 — 2023-03-20
- 0.14.7 — 2023-02-10
- … 201 more at https://npm.io/package/doormen/versions

## README

# Doormen

Validate, sanitize and assert: the silver bullet of data!

Beta version.

**/!\\ This documentation is still a Work In Progress /!\\**



## Basic validation

* sanitize `Array` of `string` the sanitizer's name to apply before any type checking
* optional `boolean` the data can be `null` or `undefined`, if so the data validate immediately
* default (anything) the data can be `null` or `undefined`, if so it is overwritten by the default value and it validates immediately
* type `string` the name of the type checker
* instanceOf
* min
* max
* length
* minLength
* maxLength
* match
* in
* notIn
* when
* properties `object` of schema, it iterates through each properties and checks that they all match their own schema
* elements `Array` same than properties but for arrays
* only `boolean` used in conjunction with *properties* or *elements*, it checks that no properties other than those listed are present
* of `object` contains one schema that will check each elements of an array or each properties



## Type Checkers

Javascript primitive types:

* undefined: the data should be `undefined`
* null: the data should be `null`
* boolean: the data should be a `boolean`, i.e. `true` or `false`
* number: the data should be a `number`. **NOTE** that `Infinity` and `NaN` are ok, so you may consider using *real*/*float*
  instead of *number* in almost all cases
* string: the data should be a `string`
* object: the data should be an `Object`
* function: the data should be a `Function`


Javascript/Node.js built-in types:

* array: the data should be an `Array`
* error: the data should be an instance of `Error`
* date: the data should be an instance of `Date`
* regexp: a regular expression
* buffer: the data should be a Node.js `Buffer`
                                        

Common meta types:

* unset: `null` or `undefined`
* real or float: a `number` that is not `NaN` nor +/- `Infinity`
* integer: a `number` that is not `NaN` nor +/- `Infinity`, and that do not have decimal part
* hex: a `string` representing an hexadecimal number, having only 0-9, a-f and A-F characters
* strictObject: an object that is not an array
* looseObject: object-like: object or function


Internet:

* ipv4: a `string` that is a IPv4 address
* ipv6: a `string` that is a IPv6 address
* ip: an IPv4 or IPv6 address
* hostname: a `string` that is a valid hostname (domain + subdomain)
* host: a hostname or an ip address
* url: a `string` that is a valid URL (generic URL) including the scheme
* weburl: a valid web/internet URL, a subset of the URL type
* email: a `string` that is a valid email address


Misc:

* schema: an `object` which is a valid doormen schema
* mongoId: an `object` which is a MongoDB's `ObjectId` OR a `string` that is a correct `ObjectId` string representation



## Sanitizers

Common cast:

* toNumber: try to convert to a `number` (mostly from `string`)
* toReal or toFloat: try to convert to a float/real (not much difference with `toNumber`)
* toInteger: try to convert to an `integer`, rounding the number if necessary
* toString: try to convert to a `string`
* toBoolean: try to convert to a `boolean` very loosely, so it accepts strings like true/false,
  yes/no, on/off or numbers like 1/0, or fallback to truthy/falsy values.
* toArray: try to convert to an `array`, non-array are converted to an array with a single element
* toDate: try to convert to a `Date` (`number` are timestamp, `string` are parsed, `object` are considered like a Date-object)
* nullToUndefined: transform `null` to `undefined`


String modifiers:

* trim: trim the string, removing whitespace at the beginning and the end
* toUpperCase: transform all characters into their upper-case counterparts
* toLowerCase: transform all characters into theier lower-case counterparts
* capitalize: transform to title case, each word starts with an upper-case
* titleCase: transform to title case, each word starts with an upper-case following lower-case characters (except ALL-CAPS words)
* latinize: transform letter to latin (remove accent, transform modified letters to their latin counterparts)
* dashToCamelCase: transform identifiers having word separated by dash/hyphen to camelCase


Enforcers:

* resize: resize a string if it does not match the required length/minLength/maxLength (truncate,
  or use leftPadding/rightPadding properties of the schema)
* removeExtraProperties: remove extra-properties from the object that are not in the schema (clone it, not in-place)


Misc:

* mongoId: convert a string to a MongoDB's `ObjectId` if possible

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