# validations-js

> Simple DSL for performing simple validations.

Latest version **1.0.1** (published 2016-06-30) · ISC license · 0 weekly downloads

## Install

```sh
npm install validations-js
pnpm add validations-js
yarn add validations-js
bun add validations-js
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2016-06-30 |
| First published | 2016-06-29 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jesús Martínez |
| Maintainers | jesus.a.martinez.v |
| Keywords | validations |

## Links

- npm: https://www.npmjs.com/package/validations-js
- Repository: https://github.com/adminMesfix/validations-js
- Homepage: https://github.com/adminMesfix/validations-js#readme
- Issues: https://github.com/adminMesfix/validations-js/issues
- npm.io page: https://npm.io/package/validations-js

## 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.0.1 (latest) — 2016-06-30
- 1.0.0 — 2016-06-29

## README

# README

This document explains how to use the library.

### Usage ###

First, you need to import the package into your code:

```
require('validations-js');

...
```

Then, follow these instructions for each function:

#### isEven(number)

Checks if a number is even.

**Parameters:**

  * **number**: int value. 

  
**Examples:**
  

```
>> isEven(2)
>> true

>> isEven(1)
>> false
```


#### isOdd(number)
    
Checks if a number is odd.

**Parameters:**

  * **number**: int value. 

  
**Examples:**
  

```
>> isOdd(2)
>> false

>> isOdd(1)
>> true
```

#### isPositive(number)

Checks if a number is positive or zero.

**Parameters:**

  * **number**: numeric value. 

  
**Examples:**

```
>> isPositive(2)
>> true

>> isPositive(0.0)
>> true

>> isPositive(-3.1)
>> false
```


#### nonPositive(number)

Checks if a number is strictly negative

**Parameters:**

  * **number**: numeric value. 

  
**Examples:**

```
>> nonPositive(2)
>> false

>> nonPositive(0.0)
>> false

>> nonPositive(-3.1)
>> true
```


#### isAlphabetic(string)

Checks if an string contains only letters.

**Parameters:**

  * **string**: string value. 

  
**Examples:**

```
>> isAlphabetic("Hello world")
>> true

>> isAlphabetic("This w11l be f4ls3")
>> false
```



#### isAlphanumeric(string)
    
Checks if a string contains only letters and numbers.
    
**Parameters:**

  * **string**: string value. 

  
**Examples:**

```
>> isAlphanumeric("Hello world")
>> true

>> isAlphanumeric("This w0n'7 be f4ls3")
>> true

>> isAlphanumeric("?????")
>> false
```

#### isNumeric(string)

Checks if a string contains only numbers.
    
**Parameters:**

  * **string**: string value. 

  
**Examples:**

```
>> isNumeric("Hello world")
>> false

>> isNumeric("This w111 be f4ls3")
>> false

>> isNumeric("1234")
>> true

>> isNumeric("3.1415")
>> false
```


#### isValidPercentage(number)

Checks that a number that represents a percentage is within the proper bounds.

**Parameters:**

  * **number**: numeric value. 

  
**Examples:**

```
>> isValidPercentage(2)
>> false

>> isValidPercentage(0.0)
>> true

>> isValidPercentage(1.)
>> true

>> isValidPercentage(50.0)
>> false
```


#### isValidTimestamp(date, unit):

Checks that a number that represents a date as milliseconds or seconds is correct.
    
**Parameters:**

  * **date**: int.
  * **unit**: String. 'millis' if **date** is in milliseconds, 'seconds' if **date** is in seconds.

  
**Examples:**

```
>> isValidTimestamp(2, "seconds")
>> false

>> isValidTimestamp(1234567890, "millis")
>> false

>> isValidTimestamp(1465496168, "seconds")
>> true

>> isValidTimestamp(1465496168000, unit="millis")
>> true
```



#### present(field_name, dictionary)
    
Checks if a field is present in an object.

**Parameters:**

  * **field_name**: string.
  * **dictionary**: object instance.

  
**Examples:**

```
dictionary = {'a': 1, 'b': 2}
>> present('c', dictionary)
>> false

>> present('a', dictionary)
>> true
```



#### isEmpty(iterable)
    
Checks if an iterable is empty
    
**Parameters:**

  * **iterable**: Iterable instance (an array or object).

  
**Examples:**

```
>> isEmpty([])
>> true

>> isEmpty([1,2,3])
>> false

>> isEmpty({'a': 1})
>> false

>> isEmpty({})
>> true
```


#### nonEmpty(iterable)

Checks if an iterable has at least one element.

**Parameters:**

  * **iterable**: Iterable instance (an array or object).

  
**Examples:**

```
>> nonEmpty([])
>> false

>> nonEmpty([1,2,3])
>> true

>> nonEmpty({'a': 1})
>> true

>> nonEmpty({})
>> false
```

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