# prettyutils

> Utility functions to parse, validate and generate data

Latest version **1.0.15** (published 2022-02-28) · GPL-3.0-or-later license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.15 |
| Published | 2022-02-28 |
| First published | 2021-04-19 |
| Weekly downloads | 0 |
| License | GPL-3.0-or-later |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 64.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Cesar Villalobos |
| Maintainers | cvillalobos |
| Keywords | chile, chilean, chileno, validator, validador, run, rut, cedula, identidad |

## Links

- npm: https://www.npmjs.com/package/prettyutils
- Repository: https://github.com/cesar-villalobos/prettyutil
- Homepage: https://github.com/cesar-villalobos/prettyutil#readme
- Issues: https://github.com/cesar-villalobos/prettyutil/issues
- npm.io page: https://npm.io/package/prettyutils

## 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.15 (latest) — 2022-02-28
- 1.0.14 — 2021-04-21
- 1.0.13 — 2021-04-21
- 1.0.12 — 2021-04-21
- 1.0.11 — 2021-04-19

## README

# PRETTY Utils

Custom validation utils (currently for RUT and Phone)

## Rol Único Tributario (RUT)

Each chilean citizen has its own RUT number, that is unique and unrepeatable number that useful as a method of identification. This consists of an 8-digit number with a verification digit that can be from 0 to 9 or a K.

## Description

The utilities for the use of the RUT number, consist in a set of tools that allow you to verify the validity of the number, give it a format, clean and get verifier digit. The utilities for the use of the phone number, consist in a set of tools that allow you to verify the validity of the number acording to their lenght, give it a format, clean and add a prefix to phone number.

## Tools

## RUT Tools

- Give Format a RUT
- Clean the invalids characters RUT
- Calculate the verifier digit
- Verify if its a valid or invalid RUT

## Phone Tools

- Give Format a phone number
- Clean the invalids characters of phone
- Add a country prefix on a phone number if not exists
- Verify if a phone has a valid lenght (without special characters)

## Installation

```
npm install prettyutils --save
```

### General Use

```javascript
import { rutTools, phoneTools } from 'prettyutils';

rutTools.format((rut: string | undefined | null)); //Return string
rutTools.clean((rut: string | undefined | null)); //Return string
rutTools.calculateDv((rut: string | undefined | null)); //Return string
rutTools.validate((rut: string | undefined | null)); //Return boolean
phoneTools.format(
  (phone: string | undefined | null),
  (prefix: string),
  (large: number),
); //Return string
phoneTools.clean((rut: string | undefined | null)); //Return string
phoneTools.calculateDv((rut: string | undefined | null)); //Return string
phoneTools.validate((rut: string | undefined | null)); //Return boolean
```

## Examples

### Give Format for RUT number

Input: String Rut

```javascript
import { rutTools } from 'prettyutils';

rutTools.format('198765432'); // Returns 19.876.543-2
rutTools.format('19-8765-4-32'); // Returns 19.876.543-2
```

### Clean the invalids characters for a RUT number

Input: String Rut

```javascript
import { rutTools } from 'prettyutils';

rutTools.clean('08084750-5'); // Returns 80847505
rutTools.clean('1-8384889-5'); // Returns 183848895
```

### Calculate the verifier digit

Input: String Rut

```javascript
import { rutTools } from 'prettyutils';

rutTools.calculateDv('16495221'); // Returns 5
rutTools.calculateDv('15280511'); // Returns K
```

### Verify if its a valid or invalid RUT

Input: String Rut

```javascript
import { rutTools } from 'prettyutils';

rutTools.validate('06099089-1'); // Returns true
rutTools.validate('21.44.509.7-6'); // Returns true
rutTools.validate('34566754-K'); // Returns false
```

### Give Format for phone number

Input: String phone

```javascript
import { phoneTools } from 'prettyutils';

phoneTools.format('9 7888 6166'); // Returns 978886166
```

### Clean the invalids characters for a phone number

Input: String Phone

```javascript
import { phoneTools } from 'prettyutils';

phoneTools.clean('+(156) 422 1234'); // Returns 1564221234
phoneTools.clean('35fdlp34/d'); // Returns 3534
```

### Add a prefix to phone number if not exists

Input: String Phone

```javascript
import { phoneTools } from 'prettyutils';

phoneTools.addPrefix('978886666'); // Returns 56978886666
phoneTools.addPrefix('978886666', '1'); // Returns 1978886666
phoneTools.addPrefix('978886666', '13'); // Returns 13978886666
phoneTools.addPrefix('978886666', '14'); // Returns 14978886666
phoneTools.addPrefix('19788', '1', 5); // Returns 19788
phoneTools.addPrefix('9788', '1', 5); // Returns 19788
```

### Verify if its a valid or invalid phone number

Input: String Phone

```javascript
import { phoneTools } from 'prettyutils';

phoneTools.validate('+56 9 7888 6666'); // Returns true
phoneTools.validate('56978886666'); // Returns true
phoneTools.validate('978886666'); // Returns true
phoneTools.validate('123456'); // Returns false
```

### Verify if its a valid or invalid phone number acording with format

Input: String Phone

```javascript
import { phoneTools } from 'prettyutils';

phoneTools.validate('+56 987654321'); // Returns true
phoneTools.validate('56 987654321'); // Returns true
phoneTools.validate('56987654321'); // Returns true
phoneTools.validate('+1 987654321'); // Returns true
phoneTools.validate('56 987sometext654321'); // Returns false
```

## Test

```
npm test
```

## Credits

- [Cesar Villalobos](https://www.cesar.cl)

## License

- [GPL-3.0-or-later](https://github.com/cesar-villalobos/prettyutil/blob/main/LICENSE)

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