Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
@fnando/cnpj
Advanced tools
This package does some CNPJ magic. It allows you to create, validate and format CNPJ documents.
[!NOTE]
This library already supports the new alphanumeric CNPJ algorithm that will be available starting July 2026. For more information, see https://www.gov.br/receitafederal/pt-br/acesso-a-informacao/acoes-e-programas/programas-e-atividades/cnpj-alfanumerico.
HINT: Check out the CPF counter part available at https://github.com/fnando/cpf.
This lib is available as a NPM package. To install it, use the following command:
npm install @fnando/cnpj --save
If you're using Yarn (and you should):
yarn add @fnando/cnpj
// Node.js-specific
const cnpj = require("@fnando/cnpj/commonjs");
// @import
import * as cnpj from "@fnando/cnpj"; // import the whole library
import { isValid as isValidCnpj } from "@fnando/cnpj"; // import just one function
// import via <script>; the lib will available as window.CNPJ
// <script src="cnpj.js"></script>
cnpj.isValid("41.381.074/6738-65");
//=> true
cnpj.isValid("41381074673865");
//=> true
cnpj.strip("41.381.074/6738-65");
//=> 41381074673865
cnpj.format("41381074673865");
//=> 41.381.074/6738-65
cnpj.generate(true); // generate formatted number
//=> 54.385.406/3140-07
cnpj.generate(); // generate unformatted number
//=> 07033324230766
On the web, without transformation, just use web/cnpj.min.js
.
By default, validations will strip any characters you provide. This means that the following is valid, because only numbers will be considered:
cnpj.isValid("41#381#074-----6738\n\n65");
//=> true
cnpj.strip("41#381#074-----6738\n\n65");
//=> 41381074673865
If you want to strict validate strings, use the following signature:
cnpj.isValid(number, strict);
The same example would now return false
:
cnpj.isValid("41#381#074-----6738\n\n65", true);
//=> false
FAQs
Validate, generate and format CNPJ numbers
We found that @fnando/cnpj demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.