# nest-optional-validation-pipes

> A NestJS addon that provides validation pipes for the simple data types with the option of optionality. E.g. a ParseBoolOptionalPipe that validates & transforms @Query parameters that are then either true, false or undefined/null or throw an error.

Latest version **1.1.0** (published 2022-03-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install nest-optional-validation-pipes
pnpm add nest-optional-validation-pipes
yarn add nest-optional-validation-pipes
bun add nest-optional-validation-pipes
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2022-03-28 |
| First published | 2022-02-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 29.8 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Jonas Feld |
| Maintainers | jonasfeld |
| Keywords | nest, nestjs, pipes, nestjs-pipes, nest-pipes, optional, optional pipes |

## Links

- npm: https://www.npmjs.com/package/nest-optional-validation-pipes
- Repository: https://github.com/jonasfeld/nest-optional-validation-pipes
- Homepage: https://github.com/jonasfeld/nest-optional-validation-pipes#readme
- Issues: https://github.com/jonasfeld/nest-optional-validation-pipes/issues
- npm.io page: https://npm.io/package/nest-optional-validation-pipes

## Dependencies (1)

- [@nestjs/common](https://npm.io/package/@nestjs/common.md) ^8.0.0

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2022-03-28
- 1.0.5 — 2022-03-02
- 1.0.4 — 2022-03-02
- 1.0.3 — 2022-02-18
- 1.0.2 — 2022-02-18
- 1.0.1 — 2022-02-16
- 1.0.0 — 2022-02-16

## README

# Nest Optional Validation Pipes

## What is this?

This package provides the same validation & transformation pipes as [@nestjs/common](https://www.npmjs.com/package/@nestjs/common) does, but with optionality.

This means, for example, a `ParseBoolOptionalPipe` will validate & transform string parameters of the form `"true"` and `"false"` into proper booleans `true` and `false` but return `undefined`, if `null` or `undefined` is passed as input.

## When would I use this?

This is especially useful in the case of optional `@Query` parameters: Let's say you wanted to add some kind of optional filtering for a resource in your api, so you add a flag as a `@Query` parameter - using the default `ParseBoolPipe` will throw an error if the flag is not provided on every request.

This package addresses this exact shortcoming: using a `ParseBoolOptionalPipe` instead of a `ParseBoolPipe` will mean the validation will not fail on "no flag provided" - it will return `undefined` instead, building a bridge.

## How do I use this?

Exactly the same way you would use the [@nestjs/common](https://www.npmjs.com/package/@nestjs/common) Built-in Pipes. See the official [nestjs docs](https://docs.nestjs.com/pipes#built-in-pipes) for further info.

## Credits

Approximately 90% of the code is taken directly from [@nestjs/common](https://www.npmjs.com/package/@nestjs/common), I only put my own spin on their already awesome built-in pipes.

So go check them out! (If you don't know them, how did you end up here?)

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