# typescript-validation

> A simple typescript library to validate strings

Latest version **0.0.4** (published 2021-05-30) · MIT license · 0 weekly downloads

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

## Install

```sh
npm install typescript-validation
pnpm add typescript-validation
yarn add typescript-validation
bun add typescript-validation
```

## Health

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

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2021-05-30 |
| First published | 2021-05-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | biewdev |
| Maintainers | biewdev |
| Keywords | typescript-validation, typescript-validator, typescript-validate, validation, validator, validate |

## Links

- npm: https://www.npmjs.com/package/typescript-validation
- Repository: https://github.com/biewdev/typescript-validation
- Homepage: https://github.com/biewdev/
- Issues: https://github.com/biewdev/typescript-validation/issues
- npm.io page: https://npm.io/package/typescript-validation

## 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.0.4 (latest) — 2021-05-30
- 0.0.3 — 2021-05-30
- 0.0.2 — 2021-05-30
- 0.0.1 — 2021-05-26

## README

# typescript-validation

A simple typescript library to validate strings

## Installing

### Using npm

```sh
npm install typescript-validation
```

### Using yarn

```sh
yarn add typescript-validation
```

## Usage

### Importing package

```typescript
import validation from "typescript-validation";
```

### Validating

```typescript
validation.validate("example@exmail.com", {
  isEmail: {
    need: true,
    message: "Invalid e-mail",
  },
});
```

### Checking if the validations were successfull

#### Get error functions:

**getErrors()** - Get all errors (Return String[])

**getLastError()** - Get last error (Return String)

```typescript
if (validation.success()) {
  // Success methods here
} else {
  // Unsuccess methods here
  console.log(validation.getLastError());
}
```

### Full code example

```typescript
import validation from "typescript-validation";

validation.validate("example@exmail.com", {
  isEmail: {
    need: true,
    message: "Invalid e-mail",
  },
});

if (validation.success()) {
  // Success methods here
} else {
  // Unsuccess methods here
  console.log(validation.getLastError());
}
```

### Validations

**need (Boolean):**
The final expected value (Default value: false)

**message (String)**:
Message if the result is not as expected

```typescript
isAlpha: { need: false, message: "These are not alphabetic characters"}
isEmail: { need: false, message: "This is not an e-mail"}
isEmpty: { need: true, message: "This is empty"}
isNumeric: { need: false, message: "These are not numeric characters"}
```

**min (Number):**
Minimum characters value

**max (Number):**
Maximum characters value

```typescript
isLength: { need: true, min: 5, max: 10, message: "This must be between 5 and 10 characters"}
```

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