Skip to content

Commit

Permalink
Added coverage badge and modified the workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
raarevalo96 committed Jan 18, 2024
1 parent 323da4e commit b03ae85
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 46 deletions.
28 changes: 24 additions & 4 deletions .github/workflows/npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ jobs:

strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
node-version: [18.x, 20.x]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

Expand All @@ -31,10 +31,30 @@ jobs:

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
if: matrix.node-version == '20.x'
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

publish:
needs: build

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Use Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 20.x

- name: Install dependencies
run: npm install

- name: Build
run: npm run build

- name: Publish to npm
run: npm publish
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
6 changes: 5 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
src
node_modules
coverage
nyc_output
nyc_output
.mocharc.json
.nyc_output
tests
.github
51 changes: 31 additions & 20 deletions README.es.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
# idSV-js

[![codecov](https://codecov.io/gh/avalon-tech/idsv-js/graph/badge.svg?token=TUNXRWZ5W1)](https://codecov.io/gh/avalon-tech/idsv-js)

[This documentation is also available in English.](https://github.com/avalon-tech/idsv-js/blob/main/README.md)

## Introducción

idSV es una herramienta para la validación y formateo de números de identidad comunes en El Salvador, como el DUI y el NIT.

## Aviso importante

Desde el 17 de diciembre de 2021, los DUIs son NITs válidos para personas naturales, por lo que cualquier DUI es un NIT válido. Esto significa que puedes usar el mismo número para ambas validaciones en el contexto de una persona natural (es decir, una persona con un DUI).

Las entidades legales no se ven afectadas por este cambio, por lo que aún debes usar la validación de NIT para ellas.

También hay una opción para anular este comportamiento en la biblioteca cuando sea necesario.

## Instalación

Puedes instalar el paquete a través de npm:

```bash
Expand All @@ -22,67 +27,73 @@ npm install @avalontechsv/idsv
## Uso

### Validación

```javascript
import { isValidDUI, isValidNIT } from '@avalontechsv/idsv';
import { isValidDUI, isValidNIT } from "@avalontechsv/idsv";

// Validar un DUI
// Los DUIs formateados correctamente, con o sin guiones o espacios al principio o al final, son válidos.
isValidDUI('00000000-0'); // true
isValidDUI('000000000'); // true
isValidDUI(' 00000000-0 '); // true
isValidDUI("00000000-0"); // true
isValidDUI("000000000"); // true
isValidDUI(" 00000000-0 "); // true

// También, la biblioteca completa con ceros a la izquierda si es más corto que 9 dígitos. Esto es útil para validar DUIs que se almacenan en una base de datos como enteros.
isValidDUI('00'); // true
isValidDUI("00"); // true

// Validar un NIT
// Los DUIs y NITs formateados correctamente, con o sin guiones o espacios al principio o al final, son válidos.
isValidNIT('00000000-0'); // true
isValidNIT('0000-000000-000-0'); // true
isValidNIT("00000000-0"); // true
isValidNIT("0000-000000-000-0"); // true

// Los DUIs son NITs válidos por defecto, pero puedes anular este comportamiento pasando false como segundo parámetro.
isValidNIT('00000000-0', false); // false
isValidNIT("00000000-0", false); // false

// También, la biblioteca completa con ceros a la izquierda si es más corto que 14 dígitos. Esto es útil para validar NITs que se almacenan en una base de datos como enteros.
isValidNIT('00'); // true
isValidNIT("00"); // true
```

### Formateo

```javascript
import { formatDUI, formatNIT } from '@avalontechsv/idsv';
import { formatDUI, formatNIT } from "@avalontechsv/idsv";

// Formatear un DUI
// Funciona de la misma manera que la validación, pero devuelve el DUI formateado.
formatDUI('00000000-0'); // '00000000-0'
formatDUI('000000000'); // '00000000-0'
formatDUI(' 00000000-0 '); // '00000000-0'
formatDUI('00'); // '00000000-0'
formatDUI("00000000-0"); // '00000000-0'
formatDUI("000000000"); // '00000000-0'
formatDUI(" 00000000-0 "); // '00000000-0'
formatDUI("00"); // '00000000-0'

// Los DUI inválidos devuelven un error.
formatDUI('00000000-1'); // Error: Invalid DUI
formatDUI("00000000-1"); // Error: Invalid DUI

// Formatear un NIT
// Funciona de la misma manera que la validación, pero devuelve el NIT formateado. Por defecto, los DUIs son NITs válidos, pero puedes anular este comportamiento pasando false como segundo parámetro.

formatNIT('00000001-8'); // '00000001-8' (DUI)
formatNIT('0000-000000-000-0'); // '0000-000000-000-0'
formatNIT(' 0000-000000-000-0 '); // '0000-000000-000-0'
formatNIT("00000001-8"); // '00000001-8' (DUI)
formatNIT("0000-000000-000-0"); // '0000-000000-000-0'
formatNIT(" 0000-000000-000-0 "); // '0000-000000-000-0'

formatNIT('00000001-8', false); // Devuelve un error porque '00000001-8' es un DUI válido, pero no un NIT válido.
formatNIT("00000001-8", false); // Devuelve un error porque '00000001-8' es un DUI válido, pero no un NIT válido.

// Los NIT inválidos devuelven un error.
formatNIT('0000-000000-000-1'); // Error: Invalid NIT
formatNIT("0000-000000-000-1"); // Error: Invalid NIT
```

## Pruebas

Puedes ejecutar las pruebas con el siguiente comando:

```bash
npm run test
```

## Otros lenguajes

Esta biblioteca también está disponible en otros lenguajes:

- [PHP](https://github.com/avalon-tech/idSV) (instalable a través de Composer)

## Licencia

Este paquete es software de código abierto bajo la licencia [GNU General Public License v3.0](https://opensource.org/licenses/GPL-3.0).
52 changes: 31 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
# idSV-js

[![codecov](https://codecov.io/gh/avalon-tech/idsv-js/graph/badge.svg?token=TUNXRWZ5W1)](https://codecov.io/gh/avalon-tech/idsv-js)

[Esta documentación tambien está disponible en español.](https://github.com/avalon-tech/idsv-js/blob/main/README.es.md)

## Introduction

idSV is a tool for validation and formatting of common identity numbers in El Salvador, such as DUI and NIT.

## Important notice

Since December 17th, 2021, DUIs are valid NITs for natural persons, so any DUI is a valid NIT. This means that you can use the same number for both validations in the context of a natural person (i.e. a person with a DUI).

Legal entities are not affected by this change, so you should still use the NIT validation for them.

There is also an option to override this functionality in the library when required.

## Installation

You can install the package via npm:

```bash
Expand All @@ -22,68 +27,73 @@ npm install @avalontechsv/idsv
## Usage

### Validation

```javascript
import { isValidDUI, isValidNIT } from '@avalontechsv/idsv';
import { isValidDUI, isValidNIT } from "@avalontechsv/idsv";

// Validate a DUI
// Properly formatted DUIs, with or without dashes or spaces at the beginning or end, are valid.
isValidDUI('00000000-0'); // true
isValidDUI('000000000'); // true
isValidDUI(' 00000000-0 '); // true
isValidDUI("00000000-0"); // true
isValidDUI("000000000"); // true
isValidDUI(" 00000000-0 "); // true

// Also, the library pads the DUI with zeros to the left if it's shorter than 9 digits. This is useful for validating DUIs that are stored in a database as integers.
isValidDUI('00'); // true
isValidDUI("00"); // true

// Validate a NIT
// Properly formatted DUIs and NITs, with or without dashes or spaces at the beginning or end, are valid.
isValidNIT('00000000-0'); // true
isValidNIT('0000-000000-000-0'); // true
isValidNIT("00000000-0"); // true
isValidNIT("0000-000000-000-0"); // true

// DUIs are valid NITs by default, but you can override this behavior passing false as the second parameter.
isValidNIT('00000000-0', false); // false
isValidNIT("00000000-0", false); // false

// Also, the library pads the NIT with zeros to the left if it's shorter than 14 digits. This is useful for validating NITs that are stored in a database as integers.
isValidNIT('00'); // true
isValidNIT("00"); // true
```

### Formatting

```javascript
import { formatDUI, formatNIT } from '@avalontechsv/idsv';
import { formatDUI, formatNIT } from "@avalontechsv/idsv";

// Format a DUI
// Same as validation, but it returns the formatted DUI instead of a boolean.
formatDUI('00000000-0'); // '00000000-0'
formatDUI('000000000'); // '00000000-0'
formatDUI(' 00000000-0 '); // '00000000-0'
formatDUI('00'); // '00000000-0'

formatDUI("00000000-0"); // '00000000-0'
formatDUI("000000000"); // '00000000-0'
formatDUI(" 00000000-0 "); // '00000000-0'
formatDUI("00"); // '00000000-0'

// Invalid DUIs throw an error.
formatDUI('00000000-1'); // Error: Invalid DUI
formatDUI("00000000-1"); // Error: Invalid DUI

// Format a NIT
// Same as validation, but it returns the formatted NIT instead of a boolean. By default, valid DUIs are also valid NITs, but you can override this behavior passing false as the second parameter.

formatNIT('00000001-8'); // '00000001-8' (DUI)
formatNIT('0000-000000-000-0'); // '0000-000000-000-0'
formatNIT(' 0000-000000-000-0 '); // '0000-000000-000-0'
formatNIT("00000001-8"); // '00000001-8' (DUI)
formatNIT("0000-000000-000-0"); // '0000-000000-000-0'
formatNIT(" 0000-000000-000-0 "); // '0000-000000-000-0'

formatNIT('00000001-8', false); // Throws an error because '00000001-8' is a valid DUI but not a valid NIT.
formatNIT("00000001-8", false); // Throws an error because '00000001-8' is a valid DUI but not a valid NIT.

// Invalid NITs throw an error.
formatNIT('0000-000000-000-1'); // Error: Invalid NIT
formatNIT("0000-000000-000-1"); // Error: Invalid NIT
```

## Testing

You can run the tests with npm:

```bash
npm run test
```

## Other languages

This library is also available in other languages:

- [PHP](https://github.com/avalon-tech/idSV) (installable via Composer)

## License

This package is open-sourced software licensed under the [GNU General Public License v3.0](https://opensource.org/licenses/GPL-3.0).

0 comments on commit b03ae85

Please sign in to comment.