Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/wachunei/rutcl

A set of chilean RUT utility functions for Deno
https://github.com/wachunei/rutcl

chile deno rut

Last synced: 2 months ago
JSON representation

A set of chilean RUT utility functions for Deno

Awesome Lists containing this project

README

        

rutcl


A set of chilean RUT utility functions for Deno



ci

```ts
import {
clean,
format,
getDigit,
isValid,
validate,
} from "https://deno.land/x/rutcl/mod.ts";

try {
validate("123456789");
} catch (error) {
console.error(error.message); // "RUT is not valid"
}

isValid("123456785"); // => true
getDigit(12345678); // => "5"
clean("12.345.678-5"); // => "123456785"
format("123456785"); // => "12.345.678-5"
```


## Usage

Import functions from `https://deno.land/x/rutcl/mod.ts`

```ts
import { format, validate } from "https://deno.land/x/rutcl/mod.ts";
```

Or import a single function from `/lib/`

```ts
import clean from "https://deno.land/x/rutcl/lib/clean.ts";
```

## Functions

- [isValid](#functions-isvalid)
- [validate](#functions-validate)
- [getDigit](#functions-getdigit)
- [format](#functions-format)
- [clean](#functions-clean)

### `isValid(dirtyRut: string | number): boolean`

Returns a boolean, `true` if RUT is valid, `false` otherwise.

```ts
import isValid from "https://deno.land/x/rutcl/lib/isValid.ts";

isValid(123456789); // => false
isValid("18591404-6"); // => true
```

### `validate(dirtyRut: string | number): void`

Throws an `InvalidRUTException` if RUT is not valid.

```ts
import validate from "https://deno.land/x/rutcl/lib/validate.ts";

validate(123456789); // => Throws InvalidRUTException
validate("18591404-6"); // => undefined
```

### `getDigit(partialDirtyRut: string | number): string`

Returns a valid verification digit for given partial RUT

```ts
import getDigit from "https://deno.land/x/rutcl/lib/getDigit.ts";

getDigit("18591404"); // => "6"
```

### `format(dirtyRut: string | number): string`

Returns a formatted RUT

```ts
import format from "https://deno.land/x/rutcl/lib/format.ts";

format("185914046"); // => "18.591.404-6"
```

### `clean(dirtyRut: string | number): string`

Returns a clean RUT, only digits.

```ts
import clean from "https://deno.land/x/rutcl/lib/clean.ts";

clean("0018*591.404*6"); // => "185914046"
```

## CLI

`TODO`

### Install CLI

`TODO`