NBS

Nomenclatura Brasileira de Serviços: the service classification codes of the NBS 2.0 table, carried by the national NFS-e.

  • Parity matrix

Validate

Checks whether an NBS code exists in the NBS 2.0 table that the MDIC publishes (Portarias Conjuntas RFB/SCS 1.429/2018 and 2.000/2018).

  • A code has 9 digits, printed as N.NNNN.NN.NN: the digit 1, the chapter, the position, the two subposition levels, the item and the subitem.
  • Accepts the 9 digits, the N.NNNN.NN.NN mask or a safe non-negative integer. The mask accepts any run of separators between the groups: space, ., - or / ("1..0101.11.00" is valid). Whitespace around the value is ignored.
  • Any other string is rejected ("1.0101abc11.00"). The function does not extract its digits. Nothing is padded: every code starts with 1.
  • Only complete codes are valid. The chapter, position and subposition headings ("1.01", "1.0101", "1.0101.1") are not. The table has 920 complete codes.
  • The function follows the MDIC nomenclature. 1.0402.29.00, 1.0403.29.00 and 1.0904.40.00 are valid here, although the NFS-e refuses them. The placeholder 9.9999.99.99 of the NFS-e ANEXO B is not valid.
ParameterTypeRequired
valuestring | numberyes
returnsboolean

Check if an NBS (Nomenclatura Brasileira de Serviços, Intangíveis e Outras Operações que Produzam Variações no Patrimônio) code exists in the official NBS 2.0 table, the code the national NFS-e carries in cNBS.

  • A code has 9 digits, printed as N.NNNN.NN.NN: the digit 1, the chapter, the position, the two subposition levels, the item and the subitem.
  • Accepts a string with the 9 digits or with the mask, 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.
  • Only complete codes are valid: the chapter (1.01), position (1.0101) and subposition (1.0101.1) headings classify nothing by themselves.
  • The ANEXO B of the Sistema Nacional NFS-e lists the same 920 codes except three (1.0402.29.00, 1.0403.29.00 and 1.0904.40.00), so a code valid here can still be refused by the NFS-e.
import { isValidNbs } from '@brazilian-utils/brazilian-utils';

isValidNbs('1.0101.11.00'); // true
isValidNbs('101011100'); // true
isValidNbs(101011100); // true
isValidNbs('1.0101'); // false (a position heading, not a complete code)
isValidNbs('1.9999.99.99'); // false
isValidNbs('1.0101abc11.00'); // false (not a documented form)
Code: brazilian-utils/javascript
Try it with JavaScript isValidNbs
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 (22) and the result in each library nbs.isValid

Format

Formats an NBS code with the mask N.NNNN.NN.NN. Only the structure changes (use nbs.isValid to check the code).

  • The function reads the digits of a string and masks them as far as they go, so a partial code is masked progressively. Other characters and digits after the ninth are dropped.
  • options.pad (default false) first left-pads the digits with zeros to the 9 digits of a complete code: "1" gives 0.0000.00.01. Every NBS code starts with 1, so the padding only serves a caller that wants a fixed width.
  • An empty value, or one without digits, returns an empty string even with pad (it is not padded to the zero mask).
  • A number is read only when it is a safe non-negative integer. Any other number returns an empty string.
ParameterTypeRequired
valuestring | numberyes
optionsFormatNbsOptionsno
options.padbooleanno
returnsstring

Format an NBS (Nomenclatura Brasileira de Serviços) code into the N.NNNN.NN.NN mask the nomenclature prints. Only the structure changes; use isValidNbs to check a code against the table.

  • Options (FormatNbsOptions): pad (default false) first left pads the value with zeros to the 9 digits of a complete code (every NBS code starts with 1, so it only serves a fixed width). An empty value, or one without digits, gives '' even with pad.
  • Same rules as formatCnae otherwise: the mask is applied as far as the value goes, characters outside it are dropped, and a number is read as the string of its digits only when it is a non-negative safe integer; any other number returns ''.
import { formatNbs } from '@brazilian-utils/brazilian-utils';

formatNbs('101011100'); // 1.0101.11.00
formatNbs(101011100); // 1.0101.11.00
formatNbs('10101'); // 1.0101 (masked as far as it goes)
formatNbs('1', { pad: true }); // 0.0000.00.01 (padded to 9 digits first)
formatNbs('abc101011100'); // 1.0101.11.00 (only the digits are read)
formatNbs(-101011100); // '' (not a non-negative safe integer)
Code: brazilian-utils/javascript
Try it with JavaScript formatNbs
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 (26) and the result in each library nbs.format

Parse

Removes NBS formatting and keeps only digits, capped at 9 digits.

  • It does not left-pad anything. A partial code (a chapter, a position or a subposition still being typed) stays as written, because every NBS code starts with 1.
  • 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.
  • Returns an empty string when there is no digit at all.
ParameterTypeRequired
valuestring | numberyes
returnsstring

Remove NBS (Nomenclatura Brasileira de Serviços) formatting, keep only digits, and cap the result to the 9 digits of a complete code.

  • Same rules as parseCbo: nothing is left padded here.
import { parseNbs } from '@brazilian-utils/brazilian-utils';

parseNbs('1.0101.11.00'); // '101011100'
Code: brazilian-utils/javascript
Try it with JavaScript parseNbs
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 (9) and the result in each library nbs.parse

Look up

Looks up an NBS code in the NBS 2.0 table and returns its code and official description.

  • A run of separators between the groups is accepted, as in nbs.isValid ("1..0101.11.00").
  • Same input rules as nbs.isValid. Returns null exactly when that function returns false.
  • The returned code is the 9 bare digits.
ParameterTypeRequired
valuestring | numberyes
returnsNbs | null

Look an NBS (Nomenclatura Brasileira de Serviços) code up and get its official description. The result is an Nbs record: { code, description }.

  • Same rules as isValidNbs. code is the 9 digits, without the mask. Returns null when the code is unknown or the value is not in a documented form.
import { getNbs } from '@brazilian-utils/brazilian-utils';

getNbs('1.0101.11.00');
// { code: '101011100', description: 'Serviços de construção de edificações residenciais de um e dois pavimentos' }

getNbs(126050000); // { code: '126050000', description: 'Serviços domésticos' }
getNbs('1.0101'); // null (a position heading, not a complete code)
getNbs('1.9999.99.99'); // null

Source: NBS 2.0 table published by the MDIC, approved by the Portaria Conjunta RFB/SCS 1.429/2018 and amended by the Portaria Conjunta RFB/SCS 2.000/2018.

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

Official sources

See also Service list (LC 116), NFS-e access key

Last updated on

On this page