{
  "$schema": "../cases.schema.json",
  "format": 1,
  "domain": "nfseKey",
  "title": {
    "en": "NFS-e access key",
    "pt-BR": "Chave de acesso NFS-e"
  },
  "functions": [
    {
      "id": "nfseKey.getInfo",
      "level": "extended",
      "summary": "Splits a national NFS-e access key (chave de acesso) into its fields.",
      "description": "Parses a national NFS-e access key into its fields. It accepts the same input as `nfseKey.isValid` and returns `null` exactly when that function returns `false`.\n\n- The separators between fields are accepted as in `nfseKey.isValid`. The `NFS` prefix must touch the key. Only a string is read: any other type returns `null`.\n- Fields: `municipalityCode` (7 digits, a string), `stateCode` (the 2-letter UF read from the first 2 digits of the municipality code), `generatorEnvironment` (1 municipality, 2 Sistema Nacional NFS-e), `taxIdType` (`cpf` or `cnpj`), `taxId`, `number` (the NFS-e number, a number from 1 to 9999999999999), `year`, `month` (1 to 12), `code` (the numeric code, a string) and `checkDigit` (a number).\n- The tax id is the 11-digit CPF without the `000` padding of the key, or the 14-character CNPJ, numeric or alphanumeric, in upper case.\n- The year is 2000 plus the 2 digits of the key. The numeric code keeps its 9 digits, leading zeros included.",
      "params": [
        {
          "name": "value",
          "type": "string"
        }
      ],
      "returns": "NfseKeyInfo?",
      "cases": [
        {
          "id": "nfseKey.getInfo#[\"43149021100040364478829000000000105725120484407255\"]",
          "args": [
            "43149021100040364478829000000000105725120484407255"
          ],
          "expect": {
            "returns": {
              "municipalityCode": "4314902",
              "stateCode": "RS",
              "generatorEnvironment": 1,
              "taxIdType": "cpf",
              "taxId": "40364478829",
              "number": 1057,
              "year": 2025,
              "month": 12,
              "code": "048440725",
              "checkDigit": 5
            }
          },
          "note": "from the maintainer briefing, #565"
        },
        {
          "id": "nfseKey.getInfo#[\"35503082258716523000119000000000001226011357924683\"]",
          "args": [
            "35503082258716523000119000000000001226011357924683"
          ],
          "expect": {
            "returns": {
              "municipalityCode": "3550308",
              "stateCode": "SP",
              "generatorEnvironment": 2,
              "taxIdType": "cnpj",
              "taxId": "58716523000119",
              "number": 12,
              "year": 2026,
              "month": 1,
              "code": "135792468",
              "checkDigit": 3
            }
          },
          "note": "JavaScript's own test: should return the parsed access key for a synthetic key of a CNPJ issuer generated by the Sistema Nacional NFS-e (São Paulo)"
        },
        {
          "id": "nfseKey.getInfo#[\"35503082212ABC34501DE35000000000001226091357924682\"]",
          "args": [
            "35503082212ABC34501DE35000000000001226091357924682"
          ],
          "expect": {
            "returns": {
              "municipalityCode": "3550308",
              "stateCode": "SP",
              "generatorEnvironment": 2,
              "taxIdType": "cnpj",
              "taxId": "12ABC34501DE35",
              "number": 12,
              "year": 2026,
              "month": 9,
              "code": "135792468",
              "checkDigit": 2
            }
          },
          "note": "JavaScript's own test: should return the parsed access key for a key of an alphanumeric CNPJ issuer (the Receita Federal example 12.ABC.345/01DE-35)"
        },
        {
          "id": "nfseKey.getInfo#[\"nfs35503082212abc34501de35000000000001226091357924682\"]",
          "args": [
            "nfs35503082212abc34501de35000000000001226091357924682"
          ],
          "expect": {
            "returns": {
              "municipalityCode": "3550308",
              "stateCode": "SP",
              "generatorEnvironment": 2,
              "taxIdType": "cnpj",
              "taxId": "12ABC34501DE35",
              "number": 12,
              "year": 2026,
              "month": 9,
              "code": "135792468",
              "checkDigit": 2
            }
          },
          "note": "JavaScript's own test: should return the parsed access key upper casing the CNPJ of a key written in lower case"
        },
        {
          "id": "nfseKey.getInfo#[\"NFS35503082258716523000119000000000001226011357924683\"]",
          "args": [
            "NFS35503082258716523000119000000000001226011357924683"
          ],
          "expect": {
            "returns": {
              "municipalityCode": "3550308",
              "stateCode": "SP",
              "generatorEnvironment": 2,
              "taxIdType": "cnpj",
              "taxId": "58716523000119",
              "number": 12,
              "year": 2026,
              "month": 1,
              "code": "135792468",
              "checkDigit": 3
            }
          },
          "note": "JavaScript's own test: should return the parsed access key accepting the NFS prefix of the XML Id attribute, in any case, and surrounding whitespace"
        },
        {
          "id": "nfseKey.getInfo#[\"  NFS35503082258716523000119000000000001226011357924683\\n\"]",
          "args": [
            "  NFS35503082258716523000119000000000001226011357924683\n"
          ],
          "expect": {
            "returns": {
              "municipalityCode": "3550308",
              "stateCode": "SP",
              "generatorEnvironment": 2,
              "taxIdType": "cnpj",
              "taxId": "58716523000119",
              "number": 12,
              "year": 2026,
              "month": 1,
              "code": "135792468",
              "checkDigit": 3
            }
          },
          "note": "JavaScript's own test: should return the parsed access key accepting the NFS prefix of the XML Id attribute, in any case, and surrounding whitespace"
        },
        {
          "id": "nfseKey.getInfo#[\"35503082258716523000119999999999999926011357924686\"]",
          "args": [
            "35503082258716523000119999999999999926011357924686"
          ],
          "expect": {
            "returns": {
              "municipalityCode": "3550308",
              "stateCode": "SP",
              "generatorEnvironment": 2,
              "taxIdType": "cnpj",
              "taxId": "58716523000119",
              "number": 9999999999999,
              "year": 2026,
              "month": 1,
              "code": "135792468",
              "checkDigit": 6
            }
          },
          "note": "JavaScript's own test: should return the parsed access key for the largest nNFSe, which a JavaScript number still holds exactly"
        },
        {
          "id": "nfseKey.getInfo#[\"35503082258716523000119000000000001200011357924681\"]",
          "args": [
            "35503082258716523000119000000000001200011357924681"
          ],
          "expect": {
            "returns": {
              "municipalityCode": "3550308",
              "stateCode": "SP",
              "generatorEnvironment": 2,
              "taxIdType": "cnpj",
              "taxId": "58716523000119",
              "number": 12,
              "year": 2000,
              "month": 1,
              "code": "135792468",
              "checkDigit": 1
            }
          },
          "note": "JavaScript's own test: should return the parsed access key for years 00 and 99 of the two digit year"
        },
        {
          "id": "nfseKey.getInfo#[\"35503082258716523000119000000000001226010000000004\"]",
          "args": [
            "35503082258716523000119000000000001226010000000004"
          ],
          "expect": {
            "returns": {
              "municipalityCode": "3550308",
              "stateCode": "SP",
              "generatorEnvironment": 2,
              "taxIdType": "cnpj",
              "taxId": "58716523000119",
              "number": 12,
              "year": 2026,
              "month": 1,
              "code": "000000000",
              "checkDigit": 4
            }
          },
          "note": "JavaScript's own test: should return the parsed access key keeping the leading zeros of a numeric code of all zeros"
        },
        {
          "id": "nfseKey.getInfo#[\"35503082258716523000119000000000001226011234567831\"]",
          "args": [
            "35503082258716523000119000000000001226011234567831"
          ],
          "expect": {
            "returns": {
              "municipalityCode": "3550308",
              "stateCode": "SP",
              "generatorEnvironment": 2,
              "taxIdType": "cnpj",
              "taxId": "58716523000119",
              "number": 12,
              "year": 2026,
              "month": 1,
              "code": "123456783",
              "checkDigit": 1
            }
          },
          "note": "JavaScript's own test: should return the parsed access key for check digit 0 out of remainders 0 and 1, and check digit 1 out of remainder 10"
        },
        {
          "id": "nfseKey.getInfo#empty",
          "args": [
            ""
          ],
          "expect": {
            "returns": null
          },
          "note": "JavaScript's own test: should return null when it is an empty string"
        },
        {
          "id": "nfseKey.getInfo#[\"not-a-key\"]",
          "args": [
            "not-a-key"
          ],
          "expect": {
            "returns": null
          },
          "note": "JavaScript's own test: should return null when it is otherwise not a key"
        },
        {
          "id": "nfseKey.getInfo#[\"NFSe35503082258716523000119000000000001226011357924683\"]",
          "args": [
            "NFSe35503082258716523000119000000000001226011357924683"
          ],
          "expect": {
            "returns": null
          },
          "note": "JavaScript's own test: should return null when there is anything before or after the 50 digits"
        },
        {
          "id": "nfseKey.getInfo#[\"3550308 2 2 58716523000119 0000000000012 2601 135792468 3\"]",
          "args": [
            "3550308 2 2 58716523000119 0000000000012 2601 135792468 3"
          ],
          "expect": {
            "returns": {
              "municipalityCode": "3550308",
              "stateCode": "SP",
              "generatorEnvironment": 2,
              "taxIdType": "cnpj",
              "taxId": "58716523000119",
              "number": 12,
              "year": 2026,
              "month": 1,
              "code": "135792468",
              "checkDigit": 3
            }
          },
          "note": "a mask between the fields is accepted. JavaScript's own test: should read a key split at the boundaries of its fields, as isValidNfseKey does"
        },
        {
          "id": "nfseKey.getInfo#[\"35503082258716523000119000000000001226011357924684\"]",
          "args": [
            "35503082258716523000119000000000001226011357924684"
          ],
          "expect": {
            "returns": null
          },
          "note": "JavaScript's own test: should return null when the check digit does not match"
        },
        {
          "id": "nfseKey.getInfo#[\"99503082258716523000119000000000001226011357924680\"]",
          "args": [
            "99503082258716523000119000000000001226011357924680"
          ],
          "expect": {
            "returns": null
          },
          "note": "JavaScript's own test: should return null when the municipality code does not start with an IBGE UF code, even with a matching check digit"
        },
        {
          "id": "nfseKey.getInfo#[\"35503083258716523000119000000000001226011357924680\"]",
          "args": [
            "35503083258716523000119000000000001226011357924680"
          ],
          "expect": {
            "returns": null
          },
          "note": "JavaScript's own test: should return null when ambGer is 0 or 3, even with a matching check digit"
        },
        {
          "id": "nfseKey.getInfo#[\"35503082358716523000119000000000001226011357924681\"]",
          "args": [
            "35503082358716523000119000000000001226011357924681"
          ],
          "expect": {
            "returns": null
          },
          "note": "JavaScript's own test: should return null when the registration type is 0 or 3, even with a matching check digit"
        },
        {
          "id": "nfseKey.getInfo#[\"35503082158716523000119000000000001226011357924685\"]",
          "args": [
            "35503082158716523000119000000000001226011357924685"
          ],
          "expect": {
            "returns": null
          },
          "note": "JavaScript's own test: should return null when the registration type says CPF and the registration is a CNPJ"
        },
        {
          "id": "nfseKey.getInfo#[\"35503082110040364478829000000000001226011357924689\"]",
          "args": [
            "35503082110040364478829000000000001226011357924689"
          ],
          "expect": {
            "returns": null
          },
          "note": "JavaScript's own test: should return null when a valid CPF is not left padded with 000"
        },
        {
          "id": "nfseKey.getInfo#[\"43149021100040364478820000000000105725120484407258\"]",
          "args": [
            "43149021100040364478820000000000105725120484407258"
          ],
          "expect": {
            "returns": null
          },
          "note": "JavaScript's own test: should return null when the check digits of the CPF or of the CNPJ do not match, even with a matching key check digit"
        },
        {
          "id": "nfseKey.getInfo#[\"35503082258716523000119000000000000026011357924683\"]",
          "args": [
            "35503082258716523000119000000000000026011357924683"
          ],
          "expect": {
            "returns": null
          },
          "note": "JavaScript's own test: should return null when nNFSe is all zeros, even with a matching check digit"
        },
        {
          "id": "nfseKey.getInfo#[\"35503082258716523000119000000000001226001357924686\"]",
          "args": [
            "35503082258716523000119000000000001226001357924686"
          ],
          "expect": {
            "returns": null
          },
          "note": "JavaScript's own test: should return null when the month is 00 or 13, even with a matching check digit"
        },
        {
          "id": "nfseKey.getInfo#[\"35503082212ABC34501DE36000000000001226091357924689\"]",
          "args": [
            "35503082212ABC34501DE36000000000001226091357924689"
          ],
          "expect": {
            "returns": null
          },
          "note": "JavaScript's own test: should return null when an alphanumeric CNPJ has wrong check digits of its own, even with a matching key check digit"
        },
        {
          "id": "nfseKey.getInfo#[\"355030 82258716523000119000000000001226011357924683\"]",
          "args": [
            "355030 82258716523000119000000000001226011357924683"
          ],
          "expect": {
            "returns": null
          },
          "note": "JavaScript's own test: when a separator sits inside a field or between the NFS prefix and the key"
        },
        {
          "id": "nfseKey.getInfo#[\"NFS 35503082258716523000119000000000001226011357924683\"]",
          "args": [
            "NFS 35503082258716523000119000000000001226011357924683"
          ],
          "expect": {
            "returns": null
          },
          "note": "JavaScript's own test: when a separator sits inside a field or between the NFS prefix and the key"
        },
        {
          "id": "nfseKey.getInfo#[null]",
          "args": [
            null
          ],
          "expect": {
            "returns": null
          },
          "note": "from the JS docs and code"
        },
        {
          "id": "nfseKey.getInfo#[123]",
          "args": [
            123
          ],
          "expect": {
            "returns": null
          },
          "note": "from the JS docs and code"
        }
      ]
    },
    {
      "id": "nfseKey.isValid",
      "level": "extended",
      "summary": "Checks whether a national NFS-e access key (chave de acesso) is valid.",
      "description": "Validates the 50-digit access key of a national NFS-e: municipality code (7), generator environment `ambGer` (1), tax id type (1), tax id (14), NFS-e number `nNFSe` (13), year and month `AAMM` (4), numeric code (9) and check digit (1).\n\n- The key may start with `NFS`, the prefix of the XML `Id` attribute, in any case. Whitespace around the value is ignored.\n- The DANFSe prints the key as a single block, so it has no printed mask (there is no `nfseKey.format`). The 8 fields (municipality code, `ambGer`, tax id type, tax id, `nNFSe`, `AAMM`, numeric code and check digit) may be written apart: any run of whitespace, `.`, `-` or `/` is accepted between two fields, as `cpf.isValid` reads its mask. A separator inside a field, or between the `NFS` prefix and the key, makes the value invalid.\n- Only a string is read. Any other type returns `false`.\n- The municipality code must start with an IBGE state code. The function checks only that prefix and does not look the municipality up.\n- `ambGer` must be 1 (municipality system) or 2 (Sistema Nacional NFS-e).\n- Tax id type 1 is a CPF, left-padded with `000`. Type 2 is a CNPJ. The CPF or CNPJ must have valid check digits of its own.\n- An alphanumeric CNPJ is accepted with type 2, as `cnpj.isValid` with version 2 reads it: letters only in the 14 tax id positions, in any case. The alphanumeric schema comes from the restricted-production (RTC) package of 2026-07-27. The service has handled the alphanumeric CNPJ in production since 2026-08-10, while the production XSD of 2026-02-09 still types the key as digits only.\n- The letters of an alphanumeric CNPJ stand in the 14 positions of the tax id (10 to 23 of the key), as `TSIdNFSe` of the schema bundle of 2026-07-27 types them.\n- The NFS-e number cannot be all zeros. The month must be 01 to 12.\n- The check digit is a modulus 11 over the first 49 characters, weights 2 to 9 from the right. A remainder of 0 or 1 gives 0. A letter counts as its ASCII code minus 48 (`A` is 17), by analogy with NT Conjunta 2025.001.\n- No official document states the weights or the remainder rule; the documents only say \"módulo 11\". The rule was confirmed against more than a hundred NFS-e keys from public repositories, from both environments, with remainders 0, 1 and 10 among them.\n- The example key in item 9.1 of the Guia do Emissor v1.2 is not valid: its check digit does not match and its CNPJ is invalid.\n- The keys of the municipal NFS-e models that are not the national standard are out of scope, and so is the 44-digit DF-e key (use `nfeKey.isValid`).",
      "params": [
        {
          "name": "value",
          "type": "string"
        }
      ],
      "returns": "boolean",
      "cases": [
        {
          "id": "nfseKey.isValid#[\"35503082258716523000119000000000001226011357924683\"]",
          "args": [
            "35503082258716523000119000000000001226011357924683"
          ],
          "expect": {
            "returns": true
          },
          "note": "from the maintainer briefing, #565"
        },
        {
          "id": "nfseKey.isValid#nfs-prefix",
          "args": [
            "NFS35503082258716523000119000000000001226011357924683"
          ],
          "expect": {
            "returns": true
          },
          "note": "from the maintainer briefing, #565"
        },
        {
          "id": "nfseKey.isValid#[\"43149021100040364478829000000000105725120484407255\"]",
          "args": [
            "43149021100040364478829000000000105725120484407255"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should return true for a synthetic key of a CPF issuer generated by the municipality"
        },
        {
          "id": "nfseKey.isValid#[\"nfs43149021100040364478829000000000105725120484407255\"]",
          "args": [
            "nfs43149021100040364478829000000000105725120484407255"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should return true when it has the NFS prefix found in the XML Id attribute, in any case"
        },
        {
          "id": "nfseKey.isValid#[\" 35503082258716523000119000000000001226011357924683\\n\"]",
          "args": [
            " 35503082258716523000119000000000001226011357924683\n"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should return true when it has surrounding whitespace"
        },
        {
          "id": "nfseKey.isValid#[\"35503082212ABC34501DE35000000000001226091357924682\"]",
          "args": [
            "35503082212ABC34501DE35000000000001226091357924682"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should return true for a key of an alphanumeric CNPJ issuer, the letters worth their ASCII code minus 48"
        },
        {
          "id": "nfseKey.isValid#[\"35503082212abc34501de35000000000001226091357924682\"]",
          "args": [
            "35503082212abc34501de35000000000001226091357924682"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should return true for a key of an alphanumeric CNPJ written in lower case, read in upper case as isValidCnpj reads it"
        },
        {
          "id": "nfseKey.isValid#[\"35503081212ABC34501DE35000000000001226091357924685\"]",
          "args": [
            "35503081212ABC34501DE35000000000001226091357924685"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should return true for an alphanumeric CNPJ key generated by the municipality, with the check digit recalculated"
        },
        {
          "id": "nfseKey.isValid#empty",
          "args": [
            ""
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when it is an empty string"
        },
        {
          "id": "nfseKey.isValid#[\"35503082258716523000119000000000001226011357924684\"]",
          "args": [
            "35503082258716523000119000000000001226011357924684"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when the check digit does not match"
        },
        {
          "id": "nfseKey.isValid#[\"3550308225871652300011900000000000122601135792468\"]",
          "args": [
            "3550308225871652300011900000000000122601135792468"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when it does not have 50 digits"
        },
        {
          "id": "nfseKey.isValid#[\"355030822587165230001190000000000012260113579246833\"]",
          "args": [
            "355030822587165230001190000000000012260113579246833"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when it does not have 50 digits"
        },
        {
          "id": "nfseKey.isValid#[\"3550308 2 2 58716523000119 0000000000012 2601 135792468 3\"]",
          "args": [
            "3550308 2 2 58716523000119 0000000000012 2601 135792468 3"
          ],
          "expect": {
            "returns": true
          },
          "note": "a mask between the fields is accepted. JavaScript's own test: should accept the mask characters isValidCpf reads at the boundaries of its fields"
        },
        {
          "id": "nfseKey.isValid#[\"3550308.2.2.58716523000119.0000000000012.2601.135792468-3\"]",
          "args": [
            "3550308.2.2.58716523000119.0000000000012.2601.135792468-3"
          ],
          "expect": {
            "returns": true
          },
          "note": "a mask between the fields is accepted. JavaScript's own test: should accept the mask characters isValidCpf reads at the boundaries of its fields"
        },
        {
          "id": "nfseKey.isValid#[\"35170458716523000119550010000000121000123458\"]",
          "args": [
            "35170458716523000119550010000000121000123458"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false for the 44 digit key of an NF-e"
        },
        {
          "id": "nfseKey.isValid#guia-do-emissor-example",
          "args": [
            "31062001251235800000112230000000173023019580208160"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false for the example of the Guia do Emissor Público Nacional Web v1.2, item 9.1, an illustrative key whose check digit does not match and whose issuer CNPJ 51235800000112 is not valid either"
        },
        {
          "id": "nfseKey.isValid#[\"35503082258716523000119000000000001226131357924684\"]",
          "args": [
            "35503082258716523000119000000000001226131357924684"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when the month is 13, even with a matching check digit"
        },
        {
          "id": "nfseKey.isValid#[\"35503082258716523000110000000000001226011357924686\"]",
          "args": [
            "35503082258716523000110000000000001226011357924686"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when the issuer CNPJ has wrong check digits, even with a matching key check digit"
        },
        {
          "id": "nfseKey.isValid#[\"35503082212ABC34501DE35000000000001226091357924680\"]",
          "args": [
            "35503082212ABC34501DE35000000000001226091357924680"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when the check digit of an alphanumeric key reads a letter as its base 36 value (A = 10) instead of its ASCII code minus 48"
        },
        {
          "id": "nfseKey.isValid#[\"35503082112ABC34501DE35000000000001226091357924684\"]",
          "args": [
            "35503082112ABC34501DE35000000000001226091357924684"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when the registration type says CPF and the registration carries letters, even with a matching key check digit"
        },
        {
          "id": "nfseKey.isValid#[\"35503082212ABC34501DE3500000000000A226091357924686\"]",
          "args": [
            "35503082212ABC34501DE3500000000000A226091357924686"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when a letter stands outside the registration, even with a matching key check digit"
        },
        {
          "id": "nfseKey.isValid#[\"355030A2258716523000119000000000001226011357924680\"]",
          "args": [
            "355030A2258716523000119000000000001226011357924680"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when a letter stands outside the registration, even with a matching key check digit"
        },
        {
          "id": "nfseKey.isValid#number-all-zeros",
          "args": [
            "35503082258716523000119000000000000026011357924683"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test (getNfseKeyInfo): should return null when nNFSe is all zeros, even with a matching check digit"
        },
        {
          "id": "nfseKey.isValid#[\"355030 82258716523000119000000000001226011357924683\"]",
          "args": [
            "355030 82258716523000119000000000001226011357924683"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: when a separator sits inside a field"
        },
        {
          "id": "nfseKey.isValid#[\"35503082258716523000119000000000001226011357924 683\"]",
          "args": [
            "35503082258716523000119000000000001226011357924 683"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: when a separator sits inside a field"
        },
        {
          "id": "nfseKey.isValid#[\"3550308--2//2 . 58716523000119 0000000000012 2601 135792468 3\"]",
          "args": [
            "3550308--2//2 . 58716523000119 0000000000012 2601 135792468 3"
          ],
          "expect": {
            "returns": true
          },
          "note": "a run of separators is accepted between two fields"
        },
        {
          "id": "nfseKey.isValid#[\"NFS 35503082258716523000119000000000001226011357924683\"]",
          "args": [
            "NFS 35503082258716523000119000000000001226011357924683"
          ],
          "expect": {
            "returns": false
          },
          "note": "a separator between the NFS prefix and the key is not accepted"
        },
        {
          "id": "nfseKey.isValid#[3.550308225871652e+49]",
          "args": [
            3.550308225871652e+49
          ],
          "expect": {
            "returns": false
          },
          "note": "only a string is read"
        },
        {
          "id": "nfseKey.isValid#[null]",
          "args": [
            null
          ],
          "expect": {
            "returns": false
          },
          "note": "only a string is read"
        }
      ]
    },
    {
      "id": "nfseKey.parse",
      "level": "extended",
      "summary": "Removes the formatting characters of a national NFS-e access key (chave de acesso).",
      "description": "Removes the formatting of a national NFS-e access key and keeps digits and upper-case letters, capped at 50 characters.\n\n- Letters before the first digit are dropped, the `NFS` prefix of the XML `Id` attribute included. Letters after it are kept in upper case, because an alphanumeric CNPJ carries them. `nfseKey.isValid` checks where they stand.\n- Every other character is removed. A partial key is kept as far as it goes.\n- A number is read only when it is a safe non-negative integer. Any other number returns an empty string.\n- The result is the single block the DANFSe prints, so there is no `nfseKey.format`.",
      "params": [
        {
          "name": "value",
          "type": "string | number"
        }
      ],
      "returns": "string",
      "cases": [
        {
          "id": "nfseKey.parse#number-too-large",
          "args": [
            1e+21
          ],
          "expect": {
            "returns": ""
          },
          "note": "from the maintainer briefing, #565"
        },
        {
          "id": "nfseKey.parse#[\"35503082258716523000119000000000001226011357924683\"]",
          "args": [
            "35503082258716523000119000000000001226011357924683"
          ],
          "expect": {
            "returns": "35503082258716523000119000000000001226011357924683"
          },
          "note": "JavaScript's own test: should keep a bare access key as it is"
        },
        {
          "id": "nfseKey.parse#nfs-prefix",
          "args": [
            "NFS35503082258716523000119000000000001226011357924683"
          ],
          "expect": {
            "returns": "35503082258716523000119000000000001226011357924683"
          },
          "note": "JavaScript's own test: should strip the NFS prefix of the XML Id attribute"
        },
        {
          "id": "nfseKey.parse#[\"  nfs35503082258716523000119000000000001226011357924683\"]",
          "args": [
            "  nfs35503082258716523000119000000000001226011357924683"
          ],
          "expect": {
            "returns": "35503082258716523000119000000000001226011357924683"
          },
          "note": "JavaScript's own test: should strip the NFS prefix of the XML Id attribute"
        },
        {
          "id": "nfseKey.parse#[\"nfs3550308 2 2 12.abc.345/01de-35 0000000000012 2609 135792468 2\"]",
          "args": [
            "nfs3550308 2 2 12.abc.345/01de-35 0000000000012 2609 135792468 2"
          ],
          "expect": {
            "returns": "35503082212ABC34501DE35000000000001226091357924682"
          },
          "note": "JavaScript's own test: should keep the letters of an alphanumeric CNPJ, upper cased"
        },
        {
          "id": "nfseKey.parse#[\"chave 35503082258716523000119000000000001226011357924683\"]",
          "args": [
            "chave 35503082258716523000119000000000001226011357924683"
          ],
          "expect": {
            "returns": "35503082258716523000119000000000001226011357924683"
          },
          "note": "JavaScript's own test: should drop every letter in front of the first digit, since the key opens with digits"
        },
        {
          "id": "nfseKey.parse#[\"NF\"]",
          "args": [
            "NF"
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: should drop every letter in front of the first digit, since the key opens with digits"
        },
        {
          "id": "nfseKey.parse#masked",
          "args": [
            "3550308 2 2 58716523000119 0000000000012 2601 135792468 3"
          ],
          "expect": {
            "returns": "35503082258716523000119000000000001226011357924683"
          },
          "note": "JavaScript's own test: should remove the characters that are neither digits nor letters"
        },
        {
          "id": "nfseKey.parse#[\"3550308.2.2.58716523000119/0000000000012-2601-135792468-3\"]",
          "args": [
            "3550308.2.2.58716523000119/0000000000012-2601-135792468-3"
          ],
          "expect": {
            "returns": "35503082258716523000119000000000001226011357924683"
          },
          "note": "JavaScript's own test: should remove the characters that are neither digits nor letters"
        },
        {
          "id": "nfseKey.parse#[\"35503082258716523000119000000000001226011357924683999\"]",
          "args": [
            "35503082258716523000119000000000001226011357924683999"
          ],
          "expect": {
            "returns": "35503082258716523000119000000000001226011357924683"
          },
          "note": "JavaScript's own test: should ignore digits after the 50 of an access key"
        },
        {
          "id": "nfseKey.parse#partial",
          "args": [
            "3550308 2 2"
          ],
          "expect": {
            "returns": "355030822"
          },
          "note": "JavaScript's own test: should keep a partial access key as written"
        },
        {
          "id": "nfseKey.parse#[355030822]",
          "args": [
            355030822
          ],
          "expect": {
            "returns": "355030822"
          },
          "note": "JavaScript's own test: should read a number as the string of its digits"
        },
        {
          "id": "nfseKey.parse#[\"NFS\"]",
          "args": [
            "NFS"
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: should return an empty string when there is no digit"
        },
        {
          "id": "nfseKey.parse#empty",
          "args": [
            ""
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: should return an empty string when there is no digit"
        },
        {
          "id": "nfseKey.parse#[-1]",
          "args": [
            -1
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: when it is a negative, fractional or unsafe number"
        },
        {
          "id": "nfseKey.parse#[1.5]",
          "args": [
            1.5
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: when it is a negative, fractional or unsafe number"
        }
      ]
    }
  ]
}
