npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

validate-rfc

v2.0.3

Published

A simple library to validate Mexican RFCs (Tax IDs)

Downloads

3,307

Readme

Validate RFC

A simple and lightweight library to validate Mexican RFCs (Tax ID).

Install

NodeJS

Use NPM:

$ npm install --save validate-rfc

Or YARN:

$ yarn add validate-rfc

Browser

Add the script to your project:

<!-- Latest version -->
<script src="https://cdn.jsdelivr.net/gh/manuelmhtr/validate-rfc@latest/dist/index.js" type="text/javascript"></script>

<!-- Or specify a version -->
<script src="https://cdn.jsdelivr.net/gh/manuelmhtr/[email protected]/dist/index.js" type="text/javascript"></script>

<!-- This will export a global function "validateRfc": -->
<script type="text/javascript">
  var data = validateRfc('mhtr93041179a');
  console.log(data);
</script>

API

The library only exposes a single function (.validateRfc).

.validateRfc(rfc)

Checks whether a string is a valid RFC and returns validation details.

Parameters

| Parameter | Type | Description | | --------- | ---- | ----------- | |rfc|String|The RFC to be validated.| |options|Object| Settings (Optional).| |options.omitVerificationDigit|Boolean|When true, the Check digit is omitted from the validation (Default: false). This option is useful since there are some RFCs with an invalid Check digit that are recognized as valid by the Mexican authorities (See Known issues).|

Response

It returns a plain object with the values:

| Parameter | Type | Description | | --------- | ---- | ----------- | |isValid|Boolean|Indicates if the string is a valid RFC.| |rfc|String|The formatted RFC (uppercase, with no white spaces or symbols). Returns null when input is an invalid RFC.| |type|String|The classification of the provided RFC. Values can be person for a legal person, company for companies, generic for the generic RFC "XAXX010101000" ir foreign for the RFC "XEXX010101000" which is used by foreign people. Returns null when input is an invalid RFC.| |errors|Array[String]|In case the RFC is invalid, the reasons why the RFC is invalid will be listed here.|

Possible errors values and they description are:

| Error | Descripción | | ----- | ----------- | |INVALID_FORMAT|The format is invalid, that means, the string does not meet with the required length or expected structure. Eg: XYZ because clearly is not an RFC. | |INVALID_DATE|The string may have the correct format, but digits generate an invalid date. Eg: MHTR815511A70 because it refers to month 55.| |INVALID_VERIFICATION_DIGIT|The string has a valid format, but the last character (check digit) is invalid. Eg: MHTR810511A79 ends with 9 but it is expected to end with 2.| |FORBIDDEN_WORD|The string contains one of the inconvenient words that cannot be included in an RFC. Eg: FETO930411792 the initials make the word FETO (fetus, LOL).|

Example

const validateRfc = require('validate-rfc');

const response = validateRfc('mhtr93041179a');
console.log(response);

/*
Prints:

{
  isValid: true,
  rfc: 'MHTR93041179A',
  type: 'person'
}

*/

const response = validateRfc('This is not an RFC');
console.log(response);

/*
Prints:

{
  isValid: false,
  rfc: null,
  type: null,
  errors: ['INVALID_FORMAT']
}

*/

Tests

Run the test with the command:

$ yarn test

Known issues

Check digit mismatches

Some RFCs registered by the SAT (Mexican taxing bureau) does not pass the Check digit validation. For instance, LME060822IH5 is a valid RFC and able to be invoices according the SAT official validator, however its Check digit should be 3 rather than 5. Therefore in those cases, this library returns isValid as false and the error INVALID_VERIFICATION_DIGIT.

Solutions:

  1. If you find one of these cases, add it to the list of valid RFCs. Upper-cased and sorted alphabetically. By adding them to the list you are supporting the documentation of such cases and preventing from returning an error the next time.
  2. Use the option omitVerificationDigit to ignore the Check digit validation. It has the advantage of being a faster solution and covers all the cases, but many invalid RFCs will pass the validation.

References:

  • Issue #10
  • https://es.stackoverflow.com/questions/140420/validacion-de-rfc-con-errores

Used by

Used by tens of successful teams:

| Zenfi | Yotepresto | DeAcero | | :--: | :--: | :--: |

Related

Licencia

MIT