NCM
Nomenclatura Comum do Mercosul: the goods classification codes published by Siscomex.
Validate
Checks whether an NCM code exists in the current table that Siscomex publishes.
- A value written as bare digits, as a string or as a number, is left-padded with zeros to 8:
1012100,"1012100"and"01012100"are the same code. A masked value is read as written (101.21.00is invalid). - Same input rules as
cbo.isValid, with 8 digits and theNNNN.NN.NNmask, including a run of separators between the groups:2203..00.00is valid. Until 2.4.0 a single separator was accepted and2203..00.00was rejected. - The table is the file "Vigente em 26/09/2026" of the Portal Único Siscomex (Resolução Gecex nº 926/2026), with 10,515 codes.
Check if an NCM (Nomenclatura Comum do Mercosul) code exists in the current table published by Siscomex/MDIC.
- Same rules as
isValidCbo, with 8 digits and theNNNN.NN.NNmask.
import { isValidNcm } from '@brazilian-utils/brazilian-utils';
isValidNcm('8471.30.12'); // true
isValidNcm('84713012'); // true
isValidNcm(1012100); // true (padded to 8 digits, so this is '01012100')
isValidNcm('1012100'); // true (padded the same way a number is)
isValidNcm('00000000'); // false
isValidNcm('abc01012100'); // false (not a documented form)
isValidNcm(-84713012); // false (not a non-negative safe integer)Source: NCM nomenclature published by the Portal Único Siscomex; the bundled 10,515 codes are those of the file "Vigente em 26/09/2026" (Resolução Gecex nº 926/2026).
Shared test cases (19) and the result in each library ncm.isValid
Format
Formats an NCM code with the mask NNNN.NN.NN. Only the structure changes (use ncm.isValid to check the code).
- Same rules as
cnae.format.options.padfirst left-pads the value with zeros to 8 digits. A value without digits, andnullorundefined, returns an empty string even withpad; until 2.4.0padturned an empty value into the zero mask (0000.00.00). - 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 (2.4.0 read the digits of any number, sign and decimal point dropped).
Format an NCM (Nomenclatura Comum do Mercosul) code. Only the structure changes; use isValidNcm to check a code against the table.
- Options (
FormatNcmOptions):pad(defaultfalse) first left pads the value with zeros to the 8 digits of a complete code. An empty value, or one without digits, gives''even withpad. - Same rules as
formatCnae, with theNNNN.NN.NNmask.
import { formatNcm } from '@brazilian-utils/brazilian-utils';
formatNcm('84713012'); // 8471.30.12
formatNcm('8471'); // 8471 (masked as far as it goes)
formatNcm('847130'); // 8471.30
formatNcm('8471', { pad: true }); // 0000.84.71 (padded to 8 digits first)
formatNcm('abc8471'); // 8471 (only the digits are read)
formatNcm(-84713012); // '' (not a non-negative safe integer)Shared test cases (31) and the result in each library ncm.format
Parse
Removes NCM formatting and keeps only digits, capped at 8 digits.
- The function does not left-pad the value. It keeps a partial code as written.
- Returns an empty string when there is no digit at all (
nullandundefinedincluded). - 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 (2.4.0 read the digits of any number, sign and decimal point dropped).
Remove NCM (Nomenclatura Comum do Mercosul) formatting, keep only digits, and cap the result to the 8 digits of a complete code.
- Same rules as
parseCbo: nothing is left padded here.
import { parseNcm } from '@brazilian-utils/brazilian-utils';
parseNcm('8471.30.12'); // '84713012'
parseNcm('8471'); // '8471' (a partial code is kept as written)Shared test cases (10) and the result in each library ncm.parse
Official sources
Last updated on
