# xyjax-required-value

> Easily reusable data validation and/or mapping

Latest version **1.1.14** (published 2019-09-25) · MIT license · 0 weekly downloads

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

## Install

```sh
npm install xyjax-required-value
pnpm add xyjax-required-value
yarn add xyjax-required-value
bun add xyjax-required-value
```

## Health

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

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.1.14 |
| Published | 2019-09-25 |
| First published | 2019-08-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 4.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | revrulb |
| Maintainers | revrulb |
| Keywords | mapping, validation |

## Links

- npm: https://www.npmjs.com/package/xyjax-required-value
- Repository: https://github.com/revrulb/xyjax
- Homepage: https://github.com/revrulb/xyjax#readme
- Issues: https://github.com/revrulb/xyjax/issues
- npm.io page: https://npm.io/package/xyjax-required-value

## Dependencies (1)

- [@babel/runtime](https://npm.io/package/@babel/runtime.md) latest

## 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.1.14 (latest) — 2019-09-25
- 1.1.13 — 2019-09-14
- 1.1.12 — 2019-09-13
- 1.1.11 — 2019-09-13
- 1.1.10 — 2019-09-11
- 1.1.9 — 2019-09-10
- 1.1.8 — 2019-09-10
- 1.1.7 — 2019-09-09
- 1.1.6 — 2019-08-30
- 1.1.5 — 2019-08-29
- 1.1.4 — 2019-08-28
- 1.1.3 — 2019-08-28
- 1.1.2 — 2019-08-28
- 1.1.1 — 2019-08-28
- 1.1.0 — 2019-08-27
- … 23 more at https://npm.io/package/xyjax-required-value/versions

## README

![npm](https://img.shields.io/npm/v/xyjax-required-value?style=for-the-badge)
![npm bundle size](https://img.shields.io/bundlephobia/min/xyjax-required-value?style=for-the-badge)
![npm](https://img.shields.io/npm/dm/xyjax-required-value?style=for-the-badge)
![NPM](https://img.shields.io/npm/l/xyjax-required-value?style=for-the-badge)

<img src='https://raw.githubusercontent.com/revrulb/xyjax/master/logos/required-value.svg?sanitize=true'></img>

# About
**xyjax-required-value** is the lightweight and standalone package which **provides validation and/or data mapping in easily-reusable way**. This package was originally developed for [Xyjax NPM package](https://www.npmjs.com/package/xyjax).

# Methods

There is one method you can import:

## **1. requiredValue(source, requiredValue, requireCondition)**

Maps, validates or filter given value in a simply-reusable way.

### Arguments description:
- **source** is the source data for check or mapping
- **requiredValue** is the value will be returned in case of requireCondition(source) == true or mapping function. *If requiredValue is mapping function (which is function with one parameter) requiredValue(source) evaluation result will be returned in any case.*
- **requireCondition** is the function with one parameter which determines if source or required value will be returned (if requireCondition returns true requiredValue will be returned, source otherwise). *This parameter does not make any sense if requiredValue is mapping function!*

# Usage example

[Click here to take a look at RunKit + NPM embed example.](https://runkit.com/embed/587k19f9mbty)

```javascript
import { requiredValue } from 'xyjax-required-value'

// required value will be returned in case of source is less than 10
var test1 = requiredValue(2, 5, source => source < 10) //5
// required value will be returned in case of source is greater than 10
var test2 = requiredValue(2, 5, source => source > 10) //2
// if requiredData is a function then mapped source will be returned (source + 10 in this case)
var test3 = requiredValue(2, source => source + 10) //12
// by default requireCondition is:
// source => source == null || source == undefined
var test4 = requiredValue(2, 5) //2
var test5 = requiredValue(null, 5) //5
```

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