{
  "$schema": "../cases.schema.json",
  "format": 1,
  "domain": "cnae",
  "title": {
    "en": "CNAE",
    "pt-BR": "CNAE"
  },
  "functions": [
    {
      "id": "cnae.format",
      "level": "extended",
      "summary": "Formats a CNAE subclass code.",
      "description": "Formats a CNAE subclass code with the mask `NNNN-N/NN`. Only the structure changes (use `cnae.isValid` to check the code).\n\n- The mask is applied as far as the digits go, so a value being typed is masked progressively.\n- `options.pad` (default `false`) first left-pads the value with zeros to 7 digits. A number is treated as the string of its digits, so it is padded only with `pad`.\n- A string is read for its digits: other characters are dropped and digits after the last one of the mask are ignored.\n- An empty value, or one without digits, returns an empty string even with `pad`. `null` and `undefined` return an empty string too. Until 2.4.0 `pad` returned the whole zero mask (`0000-0/00`).\n- 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).",
      "params": [
        {
          "name": "value",
          "type": "string | number"
        },
        {
          "name": "options",
          "type": "FormatCnaeOptions",
          "optional": true
        }
      ],
      "returns": "string",
      "cases": [
        {
          "id": "cnae.format#[\"6201501\"]",
          "args": [
            "6201501"
          ],
          "expect": {
            "returns": "6201-5/01"
          }
        },
        {
          "id": "cnae.format#already-formatted",
          "args": [
            "6201-5/01"
          ],
          "expect": {
            "returns": "6201-5/01"
          }
        },
        {
          "id": "cnae.format#partial",
          "args": [
            "62015"
          ],
          "expect": {
            "returns": "6201-5"
          }
        },
        {
          "id": "cnae.format#empty",
          "args": [
            ""
          ],
          "expect": {
            "returns": ""
          }
        },
        {
          "id": "cnae.format#[6201501]",
          "args": [
            6201501
          ],
          "expect": {
            "returns": "6201-5/01"
          },
          "note": "JavaScript's own test: should format a CNAE code given as a number"
        },
        {
          "id": "cnae.format#[\"0000000\"]",
          "args": [
            "0000000"
          ],
          "expect": {
            "returns": "0000-0/00"
          },
          "note": "JavaScript's own test: should not validate whether the code exists in the official table"
        },
        {
          "id": "cnae.format#[\"6\"]",
          "args": [
            "6"
          ],
          "expect": {
            "returns": "6"
          },
          "note": "JavaScript's own test: should mask a partial value progressively by default"
        },
        {
          "id": "cnae.format#[\"62\"]",
          "args": [
            "62"
          ],
          "expect": {
            "returns": "62"
          },
          "note": "JavaScript's own test: should mask a partial value progressively by default"
        },
        {
          "id": "cnae.format#[\"620\"]",
          "args": [
            "620"
          ],
          "expect": {
            "returns": "620"
          },
          "note": "JavaScript's own test: should mask a partial value progressively by default"
        },
        {
          "id": "cnae.format#[\"6201\"]",
          "args": [
            "6201"
          ],
          "expect": {
            "returns": "6201"
          },
          "note": "JavaScript's own test: should mask a partial value progressively by default"
        },
        {
          "id": "cnae.format#[\"620150\"]",
          "args": [
            "620150"
          ],
          "expect": {
            "returns": "6201-5/0"
          },
          "note": "JavaScript's own test: should mask a partial value progressively by default"
        },
        {
          "id": "cnae.format#[62]",
          "args": [
            62
          ],
          "expect": {
            "returns": "62"
          },
          "note": "JavaScript's own test: should mask a partial number progressively by default"
        },
        {
          "id": "cnae.format#[111301]",
          "args": [
            111301
          ],
          "expect": {
            "returns": "1113-0/1"
          },
          "note": "JavaScript's own test: should mask a partial number progressively by default"
        },
        {
          "id": "cnae.format#[\"62015010000\"]",
          "args": [
            "62015010000"
          ],
          "expect": {
            "returns": "6201-5/01"
          },
          "note": "JavaScript's own test: should not add digits after the CNAE length"
        },
        {
          "id": "cnae.format#[\"\",{\"pad\":true}]",
          "args": [
            "",
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": ""
          },
          "note": "changed in 2.5.0 (#615): a value without digits gives an empty string even with pad (2.4.0: \"0000-0/00\"). JavaScript's own test: pad option should left pad a short code with zeros up to the full CNAE length"
        },
        {
          "id": "cnae.format#[\"1\",{\"pad\":true}]",
          "args": [
            "1",
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": "0000-0/01"
          },
          "note": "JavaScript's own test: pad option should left pad a short code with zeros up to the full CNAE length"
        },
        {
          "id": "cnae.format#[\"62\",{\"pad\":true}]",
          "args": [
            "62",
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": "0000-0/62"
          },
          "note": "JavaScript's own test: pad option should left pad a short code with zeros up to the full CNAE length"
        },
        {
          "id": "cnae.format#[\"501\",{\"pad\":true}]",
          "args": [
            "501",
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": "0000-5/01"
          },
          "note": "JavaScript's own test: pad option should left pad a short code with zeros up to the full CNAE length"
        },
        {
          "id": "cnae.format#[\"62015\",{\"pad\":true}]",
          "args": [
            "62015",
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": "0062-0/15"
          },
          "note": "JavaScript's own test: pad option should left pad a short code with zeros up to the full CNAE length"
        },
        {
          "id": "cnae.format#[\"6201501\",{\"pad\":true}]",
          "args": [
            "6201501",
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": "6201-5/01"
          },
          "note": "JavaScript's own test: pad option should left pad a short code with zeros up to the full CNAE length"
        },
        {
          "id": "cnae.format#[62,{\"pad\":true}]",
          "args": [
            62,
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": "0000-0/62"
          },
          "note": "JavaScript's own test: pad option should left pad a number the same way as its digits"
        },
        {
          "id": "cnae.format#[111301,{\"pad\":true}]",
          "args": [
            111301,
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": "0111-3/01"
          },
          "note": "JavaScript's own test: pad option should left pad a number the same way as its digits"
        },
        {
          "id": "cnae.format#[\"62\",{\"pad\":false}]",
          "args": [
            "62",
            {
              "pad": false
            }
          ],
          "expect": {
            "returns": "62"
          },
          "note": "JavaScript's own test: pad option should mask progressively for an explicit false"
        },
        {
          "id": "cnae.format#[\"abc6201501\"]",
          "args": [
            "abc6201501"
          ],
          "expect": {
            "returns": "6201-5/01"
          },
          "note": "JavaScript's own test: should read only the digits of a value with other characters, like formatCpf"
        },
        {
          "id": "cnae.format#[\"62.01-5/01\"]",
          "args": [
            "62.01-5/01"
          ],
          "expect": {
            "returns": "6201-5/01"
          },
          "note": "JavaScript's own test: should read only the digits of a value with other characters, like formatCpf"
        },
        {
          "id": "cnae.format#[-6201501]",
          "args": [
            -6201501
          ],
          "expect": {
            "returns": ""
          },
          "note": "changed in 2.5.0 (#593): a negative or fractional number is not a non-negative safe integer, so it gives \"\"; 2.4.0 read the digits of its string. JavaScript's own test: should return an empty string when it is a negative, fractional or unsafe number"
        },
        {
          "id": "cnae.format#[620150.1]",
          "args": [
            620150.1
          ],
          "expect": {
            "returns": ""
          },
          "note": "changed in 2.5.0 (#593): a negative or fractional number is not a non-negative safe integer, so it gives \"\"; 2.4.0 read the digits of its string. JavaScript's own test: should return an empty string when it is a negative, fractional or unsafe number"
        },
        {
          "id": "cnae.format#[9007199254740992]",
          "args": [
            9007199254740992
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: should return an empty string when it is a negative, fractional or unsafe number (2 ** 53; 2.4.0 gave \"9007-1/99\")"
        },
        {
          "id": "cnae.format#[-6201501,{\"pad\":true}]",
          "args": [
            -6201501,
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: should return an empty string when it is a negative, fractional or unsafe number, even with pad"
        },
        {
          "id": "cnae.format#[null]",
          "args": [
            null
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: should return an empty string for null and undefined"
        },
        {
          "id": "cnae.format#[null,{\"pad\":true}]",
          "args": [
            null,
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: should return an empty string for null and undefined even under pad, instead of a zero-filled code"
        },
        {
          "id": "cnae.format#[\"abc\",{\"pad\":true}]",
          "args": [
            "abc",
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": ""
          },
          "note": "an input with no digit stays empty under pad"
        }
      ]
    },
    {
      "id": "cnae.get",
      "level": "extended",
      "summary": "Looks up a CNAE subclass code in the official CNAE-Subclasses 2.3 table.",
      "description": "Looks up a CNAE subclass code in the CNAE-Subclasses 2.3 table and returns its code (7 bare digits) and official description.\n\nThis table is the current subclass revision of CNAE 2.0.\n\n- Same input rules as `cbo.get`, with 7 digits and the `NNNN-N/NN` mask, including a run of separators between the groups (`6201--5//01` gives the entry).\n- Returns `null` for an unknown code or a value not in an accepted form.\n- It returns `null` exactly when `cnae.isValid` returns `false`.",
      "params": [
        {
          "name": "value",
          "type": "string | number"
        }
      ],
      "returns": "Cnae?",
      "cases": [
        {
          "id": "cnae.get#[\"6201501\"]",
          "args": [
            "6201501"
          ],
          "expect": {
            "returns": {
              "code": "6201501",
              "description": "DESENVOLVIMENTO DE PROGRAMAS DE COMPUTADOR SOB ENCOMENDA"
            }
          }
        },
        {
          "id": "cnae.get#masked",
          "args": [
            "6201-5/01"
          ],
          "expect": {
            "returns": {
              "code": "6201501",
              "description": "DESENVOLVIMENTO DE PROGRAMAS DE COMPUTADOR SOB ENCOMENDA"
            }
          }
        },
        {
          "id": "cnae.get#leading-zero",
          "args": [
            "0111-3/01"
          ],
          "expect": {
            "returns": {
              "code": "0111301",
              "description": "CULTIVO DE ARROZ"
            }
          }
        },
        {
          "id": "cnae.get#[\"0000000\"]",
          "args": [
            "0000000"
          ],
          "expect": {
            "returns": null
          }
        },
        {
          "id": "cnae.get#too-short",
          "args": [
            "620150"
          ],
          "expect": {
            "returns": null
          }
        },
        {
          "id": "cnae.get#empty",
          "args": [
            ""
          ],
          "expect": {
            "returns": null
          }
        },
        {
          "id": "cnae.get#[6201501]",
          "args": [
            6201501
          ],
          "expect": {
            "returns": {
              "code": "6201501",
              "description": "DESENVOLVIMENTO DE PROGRAMAS DE COMPUTADOR SOB ENCOMENDA"
            }
          },
          "note": "JavaScript's own test: should return the CNAE entry for a known code as a number"
        },
        {
          "id": "cnae.get#[\"111-3/01\"]",
          "args": [
            "111-3/01"
          ],
          "expect": {
            "returns": null
          },
          "note": "JavaScript's own test: should not pad a masked value, which already carries its separators"
        },
        {
          "id": "cnae.get#[\"0111abc301\"]",
          "args": [
            "0111abc301"
          ],
          "expect": {
            "returns": null
          },
          "note": "JavaScript's own test: should return null for a string that is not written in a documented form"
        },
        {
          "id": "cnae.get#[\"62-01501\"]",
          "args": [
            "62-01501"
          ],
          "expect": {
            "returns": null
          },
          "note": "JavaScript's own test: should return null for a string that is not written in a documented form"
        },
        {
          "id": "cnae.get#[-111301]",
          "args": [
            -111301
          ],
          "expect": {
            "returns": null
          },
          "note": "JavaScript's own test: should return null for a number that is not a non-negative safe integer"
        },
        {
          "id": "cnae.get#[6201.501]",
          "args": [
            6201.501
          ],
          "expect": {
            "returns": null
          },
          "note": "JavaScript's own test: should return null for a number that is not a non-negative safe integer"
        },
        {
          "id": "cnae.get#[\"6201--5//01\"]",
          "args": [
            "6201--5//01"
          ],
          "expect": {
            "returns": {
              "code": "6201501",
              "description": "DESENVOLVIMENTO DE PROGRAMAS DE COMPUTADOR SOB ENCOMENDA"
            }
          },
          "note": "changed in 2.5.0 (#615): a run of separators between the groups is accepted (2.4.0 gave null). same rule as cnae.isValid"
        }
      ]
    },
    {
      "id": "cnae.isValid",
      "level": "extended",
      "summary": "Checks whether a CNAE subclass code exists in the official CNAE-Subclasses 2.3 table.",
      "description": "Checks whether a CNAE subclass code exists in the CNAE-Subclasses 2.3 table (the current subclass revision of CNAE 2.0).\n\n- Same input rules as `cbo.isValid`, with 7 digits and the `NNNN-N/NN` mask. Bare digits are left-padded to 7, a masked value is read as written, and other strings are rejected.\n- Any run of separators (space, `.`, `-` or `/`) is accepted at each boundary between the groups, or none: `6201--5//01` is valid. Whitespace around the value is ignored. Until 2.4.0 a single separator was accepted and `6201--5//01` was rejected.\n- A number is read only when it is a safe non-negative integer, and is left-padded to 7 digits like bare digits (`111301` is `0111301`). A negative, fractional or unsafe number is rejected.",
      "params": [
        {
          "name": "value",
          "type": "string | number"
        }
      ],
      "returns": "boolean",
      "cases": [
        {
          "id": "cnae.isValid#[\"6201501\"]",
          "args": [
            "6201501"
          ],
          "expect": {
            "returns": true
          }
        },
        {
          "id": "cnae.isValid#masked",
          "args": [
            "6201-5/01"
          ],
          "expect": {
            "returns": true
          }
        },
        {
          "id": "cnae.isValid#leading-zero",
          "args": [
            "0111301"
          ],
          "expect": {
            "returns": true
          }
        },
        {
          "id": "cnae.isValid#zeros",
          "args": [
            "0000000"
          ],
          "expect": {
            "returns": false
          }
        },
        {
          "id": "cnae.isValid#too-short",
          "args": [
            "620150"
          ],
          "expect": {
            "returns": false
          }
        },
        {
          "id": "cnae.isValid#too-long",
          "args": [
            "62015011"
          ],
          "expect": {
            "returns": false
          }
        },
        {
          "id": "cnae.isValid#letters",
          "args": [
            "abcdefg"
          ],
          "expect": {
            "returns": false
          }
        },
        {
          "id": "cnae.isValid#empty",
          "args": [
            ""
          ],
          "expect": {
            "returns": false
          }
        },
        {
          "id": "cnae.isValid#[6201501]",
          "args": [
            6201501
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should validate a CNAE code given as a number"
        },
        {
          "id": "cnae.isValid#[111301]",
          "args": [
            111301
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should pad a value with leading zeros before looking it up, as a number or as a string"
        },
        {
          "id": "cnae.isValid#[\"111301\"]",
          "args": [
            "111301"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should pad a value with leading zeros before looking it up, as a number or as a string"
        },
        {
          "id": "cnae.isValid#[\"111-3/01\"]",
          "args": [
            "111-3/01"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should not pad a masked value, which already carries its separators"
        },
        {
          "id": "cnae.isValid#[\"0111-3/01\"]",
          "args": [
            "0111-3/01"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should not pad a masked value, which already carries its separators"
        },
        {
          "id": "cnae.isValid#[\" 6201501 \"]",
          "args": [
            " 6201501 "
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should validate a CNAE code with surrounding whitespace"
        },
        {
          "id": "cnae.isValid#[\"6201--5//01\"]",
          "args": [
            "6201--5//01"
          ],
          "expect": {
            "returns": true
          },
          "note": "changed in 2.5.0 (#615): a run of separators between the groups is accepted (2.4.0 rejected it). JavaScript's own test: should accept a group boundary written with a run of separators (6201--5//01)"
        },
        {
          "id": "cnae.isValid#[\"       \"]",
          "args": [
            "       "
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false for whitespace only"
        },
        {
          "id": "cnae.isValid#[\"6201 5 01\"]",
          "args": [
            "6201 5 01"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should accept the separators the mask uses between the three groups"
        },
        {
          "id": "cnae.isValid#[\"6201.5.01\"]",
          "args": [
            "6201.5.01"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should accept the separators the mask uses between the three groups"
        },
        {
          "id": "cnae.isValid#[\"0111abc301\"]",
          "args": [
            "0111abc301"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false for a string that is not written in a documented form"
        },
        {
          "id": "cnae.isValid#[\"62-01501\"]",
          "args": [
            "62-01501"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false for a string that is not written in a documented form"
        },
        {
          "id": "cnae.isValid#[\"+6201501\"]",
          "args": [
            "+6201501"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false for a string that is not written in a documented form"
        },
        {
          "id": "cnae.isValid#[-111301]",
          "args": [
            -111301
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false for a number that is not a non-negative safe integer"
        },
        {
          "id": "cnae.isValid#[6201.501]",
          "args": [
            6201.501
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false for a number that is not a non-negative safe integer"
        }
      ]
    },
    {
      "id": "cnae.parse",
      "level": "extended",
      "summary": "Removes the formatting characters of a CNAE code and returns only the digits.",
      "description": "Removes CNAE formatting and keeps only digits, capped at 7 digits.\n\n- It does not left-pad anything. A partial code stays as written.\n- Returns an empty string when there is no digit at all (`null` and `undefined` included).\n- 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).",
      "params": [
        {
          "name": "value",
          "type": "string | number"
        }
      ],
      "returns": "string",
      "cases": [
        {
          "id": "cnae.parse#masked",
          "args": [
            "6201-5/01"
          ],
          "expect": {
            "returns": "6201501"
          }
        },
        {
          "id": "cnae.parse#unmasked",
          "args": [
            "6201501"
          ],
          "expect": {
            "returns": "6201501"
          }
        },
        {
          "id": "cnae.parse#strips-non-digits",
          "args": [
            "62?ABC01-5/01abc"
          ],
          "expect": {
            "returns": "6201501"
          }
        },
        {
          "id": "cnae.parse#empty",
          "args": [
            ""
          ],
          "expect": {
            "returns": ""
          }
        },
        {
          "id": "cnae.parse#caps-length",
          "args": [
            "6201501999"
          ],
          "expect": {
            "returns": "6201501"
          },
          "note": "reference truncates to the 7 characters of the document; asserted by the reference (JS) unit tests"
        },
        {
          "id": "cnae.parse#[6201501]",
          "args": [
            6201501
          ],
          "expect": {
            "returns": "6201501"
          },
          "note": "JavaScript's own test: should read a number as the string of its digits"
        },
        {
          "id": "cnae.parse#[\"62\"]",
          "args": [
            "62"
          ],
          "expect": {
            "returns": "62"
          },
          "note": "JavaScript's own test: should keep a partial code as written, without padding it"
        },
        {
          "id": "cnae.parse#[-1]",
          "args": [
            -1
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: should return an empty string when it is a negative, fractional or unsafe number (#593 number rule)"
        },
        {
          "id": "cnae.parse#[1.5]",
          "args": [
            1.5
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: should return an empty string when it is a negative, fractional or unsafe number (#593 number rule)"
        },
        {
          "id": "cnae.parse#[9007199254740992]",
          "args": [
            9007199254740992
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: should return an empty string when it is a negative, fractional or unsafe number (#593 number rule)"
        }
      ]
    }
  ]
}
