CST

Código de Situação Tributária: the tax situation codes of ICMS, IPI, PIS and COFINS.

  • Parity matrix

Validate

Checks whether a CST code is valid for a tax.

  • options.tax picks the table: icms, ipi, pis or cofins (PIS and COFINS share a table). When options.tax is omitted or unknown, the function accepts a code that exists in any of the tables.
  • For icms the code is one of the 15 Tabela B codes of 2 digits (00, 02, 10, 15, 20, 30, 40, 41, 50, 51, 53, 60, 61, 70, 90), bare as the NF-e CST field carries it next to orig, or the 3-digit form with an origin digit 0-8 before it. 02, 15, 53 and 61 are the monofasia de combustíveis codes that Ajuste SINIEF 39/23 added; 12, 13, 52, 72 and 74 are not codes, because Ajuste SINIEF 20/24 struck them before they took effect.
  • ipi accepts 14 codes of 2 digits: 00-05, 49, 50-55 and 99. pis and cofins accept 33 codes of 2 digits: 01-09, 49, 50-56, 60-67, 70-75, 98 and 99. These taxes have no 3-digit form.
  • Accepts a string or a safe non-negative integer. The 3-digit ICMS form accepts any run of separators (space, ., - or /) right after the origin digit ("1--10", "0 . 10"). A separator anywhere else is rejected ("0-0", "00-", "11-0"). Surrounding whitespace is ignored. Any other string ("abc110") is rejected, its digits are not picked out.
  • A single digit is padded to the 3-digit ICMS form (0 and "0" are 000, also for the other taxes, so a single digit is never an IPI, PIS or COFINS code). A 2-digit value is a Tabela B code, read as written and never as origin plus a digit: isValidCst("10", { tax: "icms" }) is the Tabela B code 10, and "07" is not an ICMS code. The number 7 is read as 007, not as 07.
  • A null or non-object options is read as no options, so every table is checked (until 2.4.0 it made the result false).
  • Until 2.4.0 a 2-digit value was never a valid ICMS code ("10", "00" with tax: "icms" were false) and only one separator was accepted after the origin digit ("1--10" was false). Both changed in 2.5.0.
  • Sources: the ICMS Tabela B of Convênio SINIEF s/nº 1970 as Ajuste SINIEF 39/23 gave it and Ajuste SINIEF 20/24 amended; IPI, PIS and COFINS from Instrução Normativa RFB nº 1.009/2010.
ParameterTypeRequired
valuestring | numberyes
optionsIsValidCstOptionsno
options.tax"icms" | "ipi" | "pis" | "cofins"no
returnsboolean

Check if a CST (Código de Situação Tributária) code is valid for a given tax. Pass the tax through options.tax:

TaxFormatAccepted codes
icms2 digits (Tabela B) or 3 digits (origem + CST)the Tabela B code alone, or origem 0-8 + one of 00, 02, 10, 15, 20, 30, 40, 41, 50, 51, 53, 60, 61, 70, 90
ipi2 digits00, 01, 02, 03, 04, 05, 49, 50, 51, 52, 53, 54, 55, 99
pis2 digits01-09, 49, 50-56, 60-67, 70-75, 98, 99
cofins2 digitssame table as pis
  • Options (IsValidCstOptions): tax picks the table. Omitted, or outside those four values, every table is accepted; a null or non-object options is read as none.
  • Accepts a string with the 2 digits of a Tabela B code or the 3 digits of the ICMS form, or a number. The ICMS form may have any run of separators (space, ., - or /) after the origin digit.
  • A single digit is padded to the 3-digit ICMS form; a 2-digit value is a Tabela B code and is never read as an origin plus a digit ('10' is the Tabela B code 10), while the number 7 is read as the ICMS code 007, which is not in the table, so it is false.
import { isValidCst } from '@brazilian-utils/brazilian-utils';

isValidCst('000', { tax: 'icms' }); // true
isValidCst(0, { tax: 'icms' }); // true (a single digit is padded to the 3 digit form, '000')
isValidCst('0', { tax: 'icms' }); // true (padded the same way a number is)
isValidCst('110', { tax: 'icms' }); // true
isValidCst('002', { tax: 'icms' }); // true (monofasia de combustíveis)
isValidCst('60', { tax: 'icms' }); // true (a bare Tabela B code, as the NF-e CST field carries it)
isValidCst('06', { tax: 'pis' }); // true
isValidCst('99', { tax: 'ipi' }); // true
isValidCst('110'); // true (found in the icms table, tax omitted)
isValidCst('000', { tax: 'nope' }); // true (an unknown tax falls back to every table)
isValidCst('999'); // false (not in any table)
isValidCst('abc110'); // false (not a documented form)
isValidCst(-110); // false (not a non-negative safe integer)

Source: ICMS Tabela B from Anexo I of Convênio SINIEF s/nº 1970 as amended by Ajuste SINIEF 20/24; IPI, PIS and COFINS from IN RFB nº 1.009/2010.

Code: brazilian-utils/javascript
Try it with JavaScript isValidCst
The inputs start with the first shared case. Change one to see the new result.

Runs @brazilian-utils/brazilian-utils 2.5.0 in your browser.

Shared test cases (102) and the result in each library cst.isValid

Official sources

See also CSOSN

Last updated on

On this page