-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v2.0.0: options, forbidden words, valid RFC.
- Loading branch information
1 parent
59414aa
commit 0936069
Showing
17 changed files
with
2,457 additions
and
234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,4 @@ | ||
# These are supported funding model platforms | ||
|
||
github: # manuelmhtr | ||
patreon: # Replace with a single Patreon username | ||
open_collective: # Replace with a single Open Collective username | ||
ko_fi: # Replace with a single Ko-fi username | ||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel | ||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry | ||
liberapay: # Replace with a single Liberapay username | ||
issuehunt: # Replace with a single IssueHunt username | ||
otechie: # Replace with a single Otechie username | ||
custom: "https://www.paypal.me/manuelmhtr" | ||
github: manuelmhtr | ||
custom: # "https://www.paypal.me/manuelmhtr" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: Purge CDN cache | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
purge-cache: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: curl | ||
uses: wei/curl@v1 | ||
with: | ||
args: https://purge.jsdelivr.net/gh/manuelmhtr/validate-rfc@latest/dist/index.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Changelog | ||
All notable changes to this project will be documented in this file. | ||
|
||
|
||
## [2.0.0] - 2021-06-12 | ||
### Added | ||
- Accepts an optional second parameter `options`. | ||
- Accepts the options `omitVerificationDigit` to skip the `INVALID_VERIFICATION_DIGIT` error validation. | ||
- Adds the `FORBIDDEN_WORD` error that validates the RFC does not contain one of the "inconvenient" words. | ||
- Add the `valid-rfc.json` list with the list of valid RFCs by the SAT that does not comply with the "verification digit" rule. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,15 +9,34 @@ Una librería sencilla y ligera para validar [RFCs Mexicanos](https://es.wikiped | |
|
||
## Instalación | ||
|
||
### NodeJS | ||
|
||
Usa NPM o YARN: | ||
|
||
```shell | ||
$ npm install validate-rfc | ||
$ npm install --save validate-rfc | ||
``` | ||
|
||
### Navegador | ||
|
||
## API | ||
Añade el siguiente script a tu proyecto: | ||
|
||
```html | ||
<!-- última versión --> | ||
<script src="https://cdn.jsdelivr.net/gh/manuelmhtr/validate-rfc@latest/dist/index.js" type="text/javascript"></script> | ||
|
||
<!-- O especifica una versión --> | ||
<script src="https://cdn.jsdelivr.net/gh/manuelmhtr/[email protected]/dist/index.js" type="text/javascript"></script> | ||
|
||
<!-- Esto va a exportar una función "validateRfc": --> | ||
<script type="text/javascript"> | ||
var data = validateRfc('mhtr93041179a'); | ||
console.log(data); | ||
</script> | ||
``` | ||
|
||
|
||
## API | ||
|
||
La librería expone una sola función (`.validateRfc`). | ||
|
||
|
@@ -33,8 +52,8 @@ Valida que un string sea un RFC válido y entrega detalles sobre la validación. | |
| Parámetro | Tipo | Descripción | | ||
| --------- | ---- | ----------- | | ||
|`rfc`|String|El RFC a validar.| | ||
|`options`|Object| Opciones de la función (Opcional).| | ||
|`options.omitVerificationDigit`|Boolean| Si esta opción es `true`, el dígito verificatdor no será validado. (Default: `false`).| | ||
|`options`|Object| Parámetros de configuración (Opcional).| | ||
|`options.omitVerificationDigit`|Boolean|Si esta opción es `true`, se omite la validación del dígito verificador (Default: `false`).| | ||
|
||
|
||
**Respuesta** | ||
|
@@ -45,7 +64,7 @@ Regresa un objeto plano con los siguientes valores: | |
| Parámetro | Tipo | Descripción | | ||
| --------- | ---- | ----------- | | ||
|`isValid`|Boolean|Indica si el string ingresado es un RFC válido.| | ||
|`rfc`|String|El RFC formateado (en mayúsculas, sin espacios ni simbolos). Regresa `null` en caso de que el RFC sea inválido.| | ||
|`rfc`|String|El RFC formateado (en mayúsculas, sin espacios ni símbolos). Regresa `null` en caso de que el RFC sea inválido.| | ||
|`type`|String|El tipo del RFC ingresado. Los valores pueden ser `person` para personas físicas, `company` para personas morales, `generic` para el RFC genérico "XAXX010101000" o `foreign` para el RFC "XEXX010101000" para residentes en el extranjero. Regresa `null` en caso de que el RFC sea inválido.| | ||
|`errors`|Array[String]|En caso de que el RFC no sea válido, aquí se indican los motivos por los que no fue válido.| | ||
|
||
|
@@ -57,6 +76,7 @@ Los posibles valores que puede contener `errors` y su descripción son: | |
|`INVALID_FORMAT`|El formato es inválido, es decir, no cuenta con la longitud o estructura de caracteres esperado. Ej: `XYZ` porque claramente no es un RFC. | | ||
|`INVALID_DATE`|El string tiene el formato adecuado, pero los dígitos para la fecha generan una fecha inválida. Ej: `MHTR815511A70` porque refiere al mes `55`.| | ||
|`INVALID_VERIFICATION_DIGIT`|El string tiene el formato adecuado, pero el último caracter (dígito verificador) es inválido. Ej: `MHTR810511A79` termina en `9` pero se espera que termine en `2`.| | ||
|`FORBIDDEN_WORD`|El string contiene una de las [palabras inconvenientes](https://solucionfactible.com/sfic/resources/files/palabrasInconvenientes-rfc.pdf) que no pueden formar un RFC. Ej: `FETO930411792` las iniciales forman la palabra `FETO`.| | ||
|
||
|
||
**Ejemplo** | ||
|
@@ -103,6 +123,22 @@ Para correr las pruebas ejecuta el comando: | |
$ npm test | ||
``` | ||
|
||
## Problemas conocidos | ||
|
||
### Discrepancias en el dígito verificador | ||
|
||
Algunos RFC registrados ante el SAT no pasan la validación del dígito verificador. Por ejemplo el RFC `LME060822IH5` es válido y susceptible a recibir facturas según el [validador oficial del SAT](https://agsc.siat.sat.gob.mx/PTSC/ValidaRFC/index.jsf), sin embargo al calcular su dígito verificador este debería terminar en `3` en lugar de `5`. Por lo tanto en estos casos la librería retorna `isValid` como `false` y el error `INVALID_VERIFICATION_DIGIT`. | ||
|
||
Soluciones: | ||
|
||
1. Si encuentras un caso en particular agrega el RFC a la [lista de RFCs válidos](/src/valid-rfcs.json). En **mayúsculas y en orden alfabético**. Al agregarlo a la lista ese RFC ayudas a documentar estos casos y evitar que regrese error. | ||
2. Utiliza la opción `omitVerificationDigit` para ignorar la validación del dígito verificador. Tiene la ventaja de que es una solución más rápida y cubre todos lo casos; pero va a regresar como válidos muchos RFC que no están permitidos. | ||
|
||
Referencias: | ||
- [Issue #10](https://github.com/manuelmhtr/validate-rfc/issues/10) | ||
- https://es.stackoverflow.com/questions/140420/validacion-de-rfc-con-errores | ||
|
||
|
||
## Relacionado | ||
|
||
Además de validar el formato, necesitas validar que un RFC esté registrado en el SAT o no esté en una lista negra? Prueba con [Verifier](https://rapidapi.com/manuelmhtr/api/verifier). | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import babel from '@rollup/plugin-babel'; | ||
import commonjs from '@rollup/plugin-commonjs'; | ||
import json from '@rollup/plugin-json'; | ||
import { uglify } from "rollup-plugin-uglify"; | ||
|
||
export default { | ||
input: 'src/index.js', | ||
output: { | ||
file: 'dist/index.js', | ||
format: 'umd', | ||
name: 'validateRfc', | ||
sourcemap: true | ||
}, | ||
plugins: [ | ||
commonjs(), | ||
json(), | ||
babel({ | ||
babelHelpers: 'bundled', | ||
presets: ['@babel/env'] | ||
}), | ||
uglify() | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
[ | ||
"BUEI", | ||
"BUEY", | ||
"CACA", | ||
"CACO", | ||
"CAGA", | ||
"CAGO", | ||
"CAKA", | ||
"CAKO", | ||
"COGE", | ||
"COJA", | ||
"COJE", | ||
"COJI", | ||
"COJO", | ||
"CULO", | ||
"FETO", | ||
"GUEY", | ||
"JOTO", | ||
"KACA", | ||
"KACO", | ||
"KAGA", | ||
"KAGO", | ||
"KOGE", | ||
"KOJO", | ||
"KAKA", | ||
"KULO", | ||
"MAME", | ||
"MAMO", | ||
"MEAR", | ||
"MEAS", | ||
"MEON", | ||
"MION", | ||
"MOCO", | ||
"MULA", | ||
"PEDA", | ||
"PEDO", | ||
"PENE", | ||
"PUTA", | ||
"PUTO", | ||
"QULO", | ||
"RATA", | ||
"RUIN" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
export default function validateRfc(rfc: string, options?: { omitVerificationDigit?: boolean }): { | ||
export default function validateRfc(rfc: string, options?: { strict?: boolean }): { | ||
isValid: boolean, | ||
type?: 'company' | 'person' | 'foreign' | 'generic', | ||
rfc?: string, | ||
errors?: ('INVALID_FORMAT' | 'INVALID_DATE' | 'INVALID_VERIFICATION_DIGIT')[] | ||
errors?: ('INVALID_FORMAT' | 'INVALID_DATE' | 'INVALID_VERIFICATION_DIGIT' | 'FORBIDDEN_WORD')[] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[ | ||
"DAA020218JY1", | ||
"EDG811007RB3", | ||
"LIM0011098G0", | ||
"LME060822IH5", | ||
"NFS0103297H5" | ||
] |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.