CEST

Código Especificador da Substituição Tributária: the 7-digit codes of Convênio ICMS 142/18 for goods under ICMS tax substitution.

  • Parity matrix

Validate

Checks whether a CEST is listed in the annexes of Convênio ICMS 142/18 (Anexos II to XXVI of the consolidated text, last amended by Convênio ICMS 180/24).

  • A CEST has 7 digits: the first two digits are the segment, digits 3 to 5 are the item and the last two are the specification of the item (cláusula sexta, IV of the Convênio).
  • Accepted string forms: 7 digits, or NN.NNN.NN with any run of separators (space, ., - or /) between the groups, or none, and optional surrounding whitespace. Any other string is invalid: its digits are not picked out.
  • Bare digits are left-padded with zeros to 7, as a string or as a number, because segments 01 to 09 start with zero: 100100, "100100" and "0100100" are the same code. A masked value is read as written.
  • A number is read only when it is a safe non-negative integer. A negative, fractional, non-finite or unsafe number is invalid.
  • Revoked items are invalid, for example 01.110.00, 03.001.00, 03.002.00, 03.004.00, 03.010.03, 03.014.00, 03.016.00, 10.023.00, 17.049.08, 17.049.09 and 20.035.01.
  • The table has 1,040 codes in 25 segments (Anexo I). Segments 15, 18 and 27 do not exist.
  • The NCM/SH column of the annexes is not loaded, and there is no CEST×NCM cross-check. By cláusula sétima, the description is what decides.
  • Whether a state applies ICMS-ST to the code depends on state law and is out of scope. MVA/PMPF and Anexo XXVII are out of scope too.
ParameterTypeRequired
valuestring | numberyes
returnsboolean

Check if a CEST (Código Especificador da Substituição Tributária) is listed in the annexes of Convênio ICMS 142/18, the consolidated text in force.

  • Only the items in force count: an item the annexes mark as revoked is rejected.
  • The check is about the code alone: it does not tell whether the code suits a given NCM, nor whether a state applies the substituição tributária regime to it.
  • A CEST has 7 digits: the first two are the segment, the third to the fifth the item of the segment and the last two the specification of the item (cláusula sexta, IV).
  • Accepts a string with the 7 digits or with the NN.NNN.NN form the annexes print, with any run of separators (space, ., - or /) between the groups and optional surrounding whitespace, or a non-negative safe integer. Any other string is rejected instead of having its digits picked out.
  • The leading zero of segments 01 to 09 is part of the code, so a value written as bare digits is left padded with zeros to 7, as a string or as a number: 100100, '100100' and '0100100' are the same code. A masked value is read as written.
import { isValidCest } from '@brazilian-utils/brazilian-utils';

isValidCest('01.001.00'); // true
isValidCest('0100100'); // true
isValidCest(100100); // true (padded to 7 digits, so this is '0100100')
isValidCest('03.001.00'); // false (a revoked item)
isValidCest('0000000'); // false
isValidCest('abc0100100'); // false (not a documented form)
isValidCest(-100100); // false (not a non-negative safe integer)
Code: brazilian-utils/javascript
Try it with JavaScript isValidCest
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 (30) and the result in each library cest.isValid

Format

Formats a CEST with the mask NN.NNN.NN (segment, item, specification), the form the annexes print. Only the structure changes (use cest.isValid to check the code).

  • The mask is progressive: a partial value is masked as far as it goes (01001 gives 01.001). Characters that are not digits are dropped, and digits after the 7th are ignored.
  • options.pad first left-pads the value with zeros to 7 digits. Without it, a number that lost its leading zero shifts the mask: 100100 gives 10.010.0, and 01.001.00 with pad.
  • A value with no digits, and null or undefined, gives an empty string even with pad.
  • A number is read only when it is a safe non-negative integer. A negative, fractional, non-finite or unsafe number returns an empty string.
ParameterTypeRequired
valuestring | numberyes
optionsFormatCestOptionsno
options.padbooleanno
returnsstring

Format a CEST (Código Especificador da Substituição Tributária) in the NN.NNN.NN form the annexes of Convênio ICMS 142/18 print. Only the structure changes; use isValidCest to check a code against the annexes.

  • Options (FormatCestOptions): pad (default false) first left pads the value with zeros to the 7 digits of a complete code. An empty value, or one without digits, gives '' even with pad.
  • Same rules as formatNcm: without pad the mask is applied as far as the value goes, which is what an input being typed into needs, characters outside it are dropped, and a number is read as the string of its digits, so it is only padded under pad: true. A number is only read when it is a non-negative safe integer; any other number returns ''.
import { formatCest } from '@brazilian-utils/brazilian-utils';

formatCest('0100100'); // 01.001.00
formatCest(2899900); // 28.999.00
formatCest('01001'); // 01.001 (masked as far as it goes)
formatCest(100100, { pad: true }); // 01.001.00 (padded to 7 digits first)
formatCest('abc0100100'); // 01.001.00 (only the digits are read)
formatCest(-2899900); // '' (not a non-negative safe integer)
Code: brazilian-utils/javascript
Try it with JavaScript formatCest
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 (27) and the result in each library cest.format

Parse

Removes CEST formatting and keeps only digits, capped at 7.

  • The function does not left-pad the value. It keeps a partial code as written, so the leading zero of segments 01 to 09 has to be written out. cest.isValid and cest.get do pad bare digits.
  • Returns an empty string when there is no digit at all (null and undefined included).
  • A number is read only when it is a safe non-negative integer. A negative, fractional, non-finite or unsafe number returns an empty string.
ParameterTypeRequired
valuestring | numberyes
returnsstring

Remove CEST (Código Especificador da Substituição Tributária) formatting, keep only digits, and cap the result to the 7 digits of a complete code.

  • Same rules as parseCbo: nothing is left padded here, so the leading zero of segments 01 to 09 has to be written out. Use isValidCest or getCest, which do pad a bare numeric code, to look a code up.
import { parseCest } from '@brazilian-utils/brazilian-utils';

parseCest('01.001.00'); // '0100100'
parseCest('28.999'); // '28999' (a partial code is kept as written)
Code: brazilian-utils/javascript
Try it with JavaScript parseCest
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 (10) and the result in each library cest.parse

Look up

Looks up a CEST in the annexes of Convênio ICMS 142/18 and returns its code, description and segment. Returns null exactly when cest.isValid is false.

  • Same input rules as cest.isValid (including a run of separators between the groups, 05..001.00): a revoked item, an unknown code and a value not in an accepted form return null.
  • code is the 7 digits, without mask. description is the wording in force of the annex. segment is the name of the segment in Anexo I.
  • Returns a new object on every call.
  • The NCM/SH codes the annexes pair each CEST with are not part of the entry.
ParameterTypeRequired
valuestring | numberyes
returnsCest | null

Look a CEST (Código Especificador da Substituição Tributária) up and get the description of the goods and the name of its segment, as Anexos I to XXVI of Convênio ICMS 142/18 word them. The result is a Cest record: { code, description, segment }.

  • Same rules as isValidCest. Returns null for an unknown, revoked or malformed code.
  • The NCM/SH codes the annexes pair each CEST with are not part of the entry.
import { getCest } from '@brazilian-utils/brazilian-utils';

getCest('05.001.00'); // { code: '0500100', description: 'Cimento', segment: 'Cimentos' }
getCest(500100); // { code: '0500100', description: 'Cimento', segment: 'Cimentos' }
getCest('03.001.00'); // null (a revoked item)
getCest('0000000'); // null
getCest('abc0500100'); // null (not a documented form)

Source: consolidated Convênio ICMS 142/18, last amended by Convênio ICMS 180/24.

Code: brazilian-utils/javascript
Try it with JavaScript getCest
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 (27) and the result in each library cest.get

Official sources

See also NCM

Last updated on

On this page