{
  "$schema": "../cases.schema.json",
  "format": 1,
  "domain": "cpf",
  "title": {
    "en": "CPF",
    "pt-BR": "CPF"
  },
  "functions": [
    {
      "id": "cpf.format",
      "level": "core",
      "summary": "Formats a CPF as `000.000.000-00`.",
      "description": "Formats a CPF as `000.000.000-00`.\n\n- `options.pad` left-pads the value with zeros to 11 digits first.\n- `options.obfuscate` hides the first 3 digits and the 2 check digits with `*`, after padding. This is the rule the Leis de Diretrizes Orçamentárias set for publishing a CPF (Lei nº 14.194/2021, art. 149, and Lei nº 15.321/2025, art. 163).\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 (`-12345678909` gave `123.456.789-09`).\n- A value with no digits (empty, or only letters and symbols) returns an empty string even with `options.pad`. Until 2.4.0 `pad` returned the full zero mask (`000.000.000-00`).\n- Digits beyond the 11th are dropped. A value that is not a string or a number (`null`, `undefined`, an object) returns an empty string.\n- A number loses its leading zeros, so pass a string, or use `options.pad`, for a CPF that starts with `0`.\n- Pending decision (findings §2 #2, #3): the reference (JS) formats only the characters an incomplete value has and returns an empty string for empty or invalid input. Other libraries return `null`.",
      "params": [
        {
          "name": "value",
          "type": "string | number"
        },
        {
          "name": "options",
          "type": "FormatCpfOptions",
          "optional": true
        }
      ],
      "returns": "string",
      "cases": [
        {
          "id": "cpf.format#[\"83159562131\"]",
          "args": [
            "83159562131"
          ],
          "expect": {
            "returns": "831.595.621-31"
          },
          "note": "consensus of 5 libs (go, javascript, python, ruby, rust)"
        },
        {
          "id": "cpf.format#[\"02746891972\"]",
          "args": [
            "02746891972"
          ],
          "expect": {
            "returns": "027.468.919-72"
          },
          "note": "consensus of 5 libs (go, javascript, python, ruby, rust)"
        },
        {
          "id": "cpf.format#[\"52708175602\"]",
          "args": [
            "52708175602"
          ],
          "expect": {
            "returns": "527.081.756-02"
          },
          "note": "consensus of 5 libs (go, javascript, python, ruby, rust)"
        },
        {
          "id": "cpf.format#[\"12345678909\"]",
          "args": [
            "12345678909"
          ],
          "expect": {
            "returns": "123.456.789-09"
          },
          "note": "from the CPF spec test cases (formerly brazilian-utils/docs specs/cpf/test-cases.json)"
        },
        {
          "id": "cpf.format#[\"11144477735\"]",
          "args": [
            "11144477735"
          ],
          "expect": {
            "returns": "111.444.777-35"
          },
          "note": "from the CPF spec test cases (formerly brazilian-utils/docs specs/cpf/test-cases.json)"
        },
        {
          "id": "cpf.format#[\"\"]",
          "args": [
            ""
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: should format CPF with mask"
        },
        {
          "id": "cpf.format#[\"9\"]",
          "args": [
            "9"
          ],
          "expect": {
            "returns": "9"
          },
          "note": "JavaScript's own test: should format CPF with mask"
        },
        {
          "id": "cpf.format#[\"94\"]",
          "args": [
            "94"
          ],
          "expect": {
            "returns": "94"
          },
          "note": "JavaScript's own test: should format CPF with mask"
        },
        {
          "id": "cpf.format#[\"943\"]",
          "args": [
            "943"
          ],
          "expect": {
            "returns": "943"
          },
          "note": "JavaScript's own test: should format CPF with mask"
        },
        {
          "id": "cpf.format#[\"9438\"]",
          "args": [
            "9438"
          ],
          "expect": {
            "returns": "943.8"
          },
          "note": "JavaScript's own test: should format CPF with mask"
        },
        {
          "id": "cpf.format#[\"94389\"]",
          "args": [
            "94389"
          ],
          "expect": {
            "returns": "943.89"
          },
          "note": "JavaScript's own test: should format CPF with mask"
        },
        {
          "id": "cpf.format#[\"943895\"]",
          "args": [
            "943895"
          ],
          "expect": {
            "returns": "943.895"
          },
          "note": "JavaScript's own test: should format CPF with mask"
        },
        {
          "id": "cpf.format#[\"9438957\"]",
          "args": [
            "9438957"
          ],
          "expect": {
            "returns": "943.895.7"
          },
          "note": "JavaScript's own test: should format CPF with mask"
        },
        {
          "id": "cpf.format#[\"94389575\"]",
          "args": [
            "94389575"
          ],
          "expect": {
            "returns": "943.895.75"
          },
          "note": "JavaScript's own test: should format CPF with mask"
        },
        {
          "id": "cpf.format#[\"943895751\"]",
          "args": [
            "943895751"
          ],
          "expect": {
            "returns": "943.895.751"
          },
          "note": "JavaScript's own test: should format CPF with mask"
        },
        {
          "id": "cpf.format#[\"9438957510\"]",
          "args": [
            "9438957510"
          ],
          "expect": {
            "returns": "943.895.751-0"
          },
          "note": "JavaScript's own test: should format CPF with mask"
        },
        {
          "id": "cpf.format#[\"94389575104\"]",
          "args": [
            "94389575104"
          ],
          "expect": {
            "returns": "943.895.751-04"
          },
          "note": "JavaScript's own test: should format CPF with mask"
        },
        {
          "id": "cpf.format#[9]",
          "args": [
            9
          ],
          "expect": {
            "returns": "9"
          },
          "note": "JavaScript's own test: should format number CPF with mask"
        },
        {
          "id": "cpf.format#[94]",
          "args": [
            94
          ],
          "expect": {
            "returns": "94"
          },
          "note": "JavaScript's own test: should format number CPF with mask"
        },
        {
          "id": "cpf.format#[943]",
          "args": [
            943
          ],
          "expect": {
            "returns": "943"
          },
          "note": "JavaScript's own test: should format number CPF with mask"
        },
        {
          "id": "cpf.format#[9438]",
          "args": [
            9438
          ],
          "expect": {
            "returns": "943.8"
          },
          "note": "JavaScript's own test: should format number CPF with mask"
        },
        {
          "id": "cpf.format#[94389]",
          "args": [
            94389
          ],
          "expect": {
            "returns": "943.89"
          },
          "note": "JavaScript's own test: should format number CPF with mask"
        },
        {
          "id": "cpf.format#[943895]",
          "args": [
            943895
          ],
          "expect": {
            "returns": "943.895"
          },
          "note": "JavaScript's own test: should format number CPF with mask"
        },
        {
          "id": "cpf.format#[9438957]",
          "args": [
            9438957
          ],
          "expect": {
            "returns": "943.895.7"
          },
          "note": "JavaScript's own test: should format number CPF with mask"
        },
        {
          "id": "cpf.format#[94389575]",
          "args": [
            94389575
          ],
          "expect": {
            "returns": "943.895.75"
          },
          "note": "JavaScript's own test: should format number CPF with mask"
        },
        {
          "id": "cpf.format#[943895751]",
          "args": [
            943895751
          ],
          "expect": {
            "returns": "943.895.751"
          },
          "note": "JavaScript's own test: should format number CPF with mask"
        },
        {
          "id": "cpf.format#[9438957510]",
          "args": [
            9438957510
          ],
          "expect": {
            "returns": "943.895.751-0"
          },
          "note": "JavaScript's own test: should format number CPF with mask"
        },
        {
          "id": "cpf.format#[94389575104]",
          "args": [
            94389575104
          ],
          "expect": {
            "returns": "943.895.751-04"
          },
          "note": "JavaScript's own test: should format number CPF with mask"
        },
        {
          "id": "cpf.format#[\"\",{\"pad\":true}]",
          "args": [
            "",
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": ""
          },
          "note": "changed in 2.5.0 (#615): a value with no digits gives an empty string even with pad (2.4.0 gave 000.000.000-00)"
        },
        {
          "id": "cpf.format#[\"9\",{\"pad\":true}]",
          "args": [
            "9",
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": "000.000.000-09"
          },
          "note": "JavaScript's own test: should format CPF with mask filling zeroes"
        },
        {
          "id": "cpf.format#[\"94\",{\"pad\":true}]",
          "args": [
            "94",
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": "000.000.000-94"
          },
          "note": "JavaScript's own test: should format CPF with mask filling zeroes"
        },
        {
          "id": "cpf.format#[\"943\",{\"pad\":true}]",
          "args": [
            "943",
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": "000.000.009-43"
          },
          "note": "JavaScript's own test: should format CPF with mask filling zeroes"
        },
        {
          "id": "cpf.format#[\"9438\",{\"pad\":true}]",
          "args": [
            "9438",
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": "000.000.094-38"
          },
          "note": "JavaScript's own test: should format CPF with mask filling zeroes"
        },
        {
          "id": "cpf.format#[\"94389\",{\"pad\":true}]",
          "args": [
            "94389",
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": "000.000.943-89"
          },
          "note": "JavaScript's own test: should format CPF with mask filling zeroes"
        },
        {
          "id": "cpf.format#[\"943895\",{\"pad\":true}]",
          "args": [
            "943895",
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": "000.009.438-95"
          },
          "note": "JavaScript's own test: should format CPF with mask filling zeroes"
        },
        {
          "id": "cpf.format#[\"9438957\",{\"pad\":true}]",
          "args": [
            "9438957",
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": "000.094.389-57"
          },
          "note": "JavaScript's own test: should format CPF with mask filling zeroes"
        },
        {
          "id": "cpf.format#[\"94389575\",{\"pad\":true}]",
          "args": [
            "94389575",
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": "000.943.895-75"
          },
          "note": "JavaScript's own test: should format CPF with mask filling zeroes"
        },
        {
          "id": "cpf.format#[\"943895751\",{\"pad\":true}]",
          "args": [
            "943895751",
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": "009.438.957-51"
          },
          "note": "JavaScript's own test: should format CPF with mask filling zeroes"
        },
        {
          "id": "cpf.format#[\"9438957510\",{\"pad\":true}]",
          "args": [
            "9438957510",
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": "094.389.575-10"
          },
          "note": "JavaScript's own test: should format CPF with mask filling zeroes"
        },
        {
          "id": "cpf.format#[\"94389575104\",{\"pad\":true}]",
          "args": [
            "94389575104",
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": "943.895.751-04"
          },
          "note": "JavaScript's own test: should format CPF with mask filling zeroes"
        },
        {
          "id": "cpf.format#[9,{\"pad\":true}]",
          "args": [
            9,
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": "000.000.000-09"
          },
          "note": "JavaScript's own test: should format number CPF with mask filling zeroes"
        },
        {
          "id": "cpf.format#[94,{\"pad\":true}]",
          "args": [
            94,
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": "000.000.000-94"
          },
          "note": "JavaScript's own test: should format number CPF with mask filling zeroes"
        },
        {
          "id": "cpf.format#[943,{\"pad\":true}]",
          "args": [
            943,
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": "000.000.009-43"
          },
          "note": "JavaScript's own test: should format number CPF with mask filling zeroes"
        },
        {
          "id": "cpf.format#[9438,{\"pad\":true}]",
          "args": [
            9438,
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": "000.000.094-38"
          },
          "note": "JavaScript's own test: should format number CPF with mask filling zeroes"
        },
        {
          "id": "cpf.format#[94389,{\"pad\":true}]",
          "args": [
            94389,
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": "000.000.943-89"
          },
          "note": "JavaScript's own test: should format number CPF with mask filling zeroes"
        },
        {
          "id": "cpf.format#[943895,{\"pad\":true}]",
          "args": [
            943895,
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": "000.009.438-95"
          },
          "note": "JavaScript's own test: should format number CPF with mask filling zeroes"
        },
        {
          "id": "cpf.format#[9438957,{\"pad\":true}]",
          "args": [
            9438957,
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": "000.094.389-57"
          },
          "note": "JavaScript's own test: should format number CPF with mask filling zeroes"
        },
        {
          "id": "cpf.format#[94389575,{\"pad\":true}]",
          "args": [
            94389575,
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": "000.943.895-75"
          },
          "note": "JavaScript's own test: should format number CPF with mask filling zeroes"
        },
        {
          "id": "cpf.format#[943895751,{\"pad\":true}]",
          "args": [
            943895751,
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": "009.438.957-51"
          },
          "note": "JavaScript's own test: should format number CPF with mask filling zeroes"
        },
        {
          "id": "cpf.format#[9438957510,{\"pad\":true}]",
          "args": [
            9438957510,
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": "094.389.575-10"
          },
          "note": "JavaScript's own test: should format number CPF with mask filling zeroes"
        },
        {
          "id": "cpf.format#[94389575104,{\"pad\":true}]",
          "args": [
            94389575104,
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": "943.895.751-04"
          },
          "note": "JavaScript's own test: should format number CPF with mask filling zeroes"
        },
        {
          "id": "cpf.format#[\"94389575104000000\"]",
          "args": [
            "94389575104000000"
          ],
          "expect": {
            "returns": "943.895.751-04"
          },
          "note": "JavaScript's own test"
        },
        {
          "id": "cpf.format#[\"943.?ABC895.751-04abc\"]",
          "args": [
            "943.?ABC895.751-04abc"
          ],
          "expect": {
            "returns": "943.895.751-04"
          },
          "note": "JavaScript's own test: should remove all non numeric characters"
        },
        {
          "id": "cpf.format#[\"94389575104\",{\"obfuscate\":true}]",
          "args": [
            "94389575104",
            {
              "obfuscate": true
            }
          ],
          "expect": {
            "returns": "***.895.751-**"
          },
          "note": "JavaScript's own test: should hide the first 3 digits and the 2 check digits when obfuscate is true"
        },
        {
          "id": "cpf.format#[94389575104,{\"obfuscate\":true}]",
          "args": [
            94389575104,
            {
              "obfuscate": true
            }
          ],
          "expect": {
            "returns": "***.895.751-**"
          },
          "note": "JavaScript's own test: should hide the first 3 digits and the 2 check digits when obfuscate is true"
        },
        {
          "id": "cpf.format#[\"9\",{\"pad\":true,\"obfuscate\":true}]",
          "args": [
            "9",
            {
              "pad": true,
              "obfuscate": true
            }
          ],
          "expect": {
            "returns": "***.000.000-**"
          },
          "note": "JavaScript's own test: should pad before obfuscating"
        },
        {
          "id": "cpf.format#[\"943\",{\"pad\":true,\"obfuscate\":true}]",
          "args": [
            "943",
            {
              "pad": true,
              "obfuscate": true
            }
          ],
          "expect": {
            "returns": "***.000.009-**"
          },
          "note": "JavaScript's own test: should pad before obfuscating"
        },
        {
          "id": "cpf.format#[\"9438\",{\"obfuscate\":true}]",
          "args": [
            "9438",
            {
              "obfuscate": true
            }
          ],
          "expect": {
            "returns": "***.8"
          },
          "note": "JavaScript's own test: should obfuscate a short, unpadded value as far as it goes"
        },
        {
          "id": "cpf.format#[\"94389575104\",{\"obfuscate\":false}]",
          "args": [
            "94389575104",
            {
              "obfuscate": false
            }
          ],
          "expect": {
            "returns": "943.895.751-04"
          },
          "note": "JavaScript's own test: should behave exactly as without the option when obfuscate is false or absent"
        },
        {
          "id": "cpf.format#[\"943\",{\"pad\":true,\"obfuscate\":false}]",
          "args": [
            "943",
            {
              "pad": true,
              "obfuscate": false
            }
          ],
          "expect": {
            "returns": "000.000.009-43"
          },
          "note": "JavaScript's own test: should behave exactly as without the option when obfuscate is false or absent"
        },
        {
          "id": "cpf.format#[123456789.09]",
          "args": [
            123456789.09
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: when it is a negative, fractional or unsafe number; changed in 2.5.0 (#593): a number is read only when it is a non-negative safe integer"
        },
        {
          "id": "cpf.format#[-1]",
          "args": [
            -1
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: when it is a negative, fractional or unsafe number; changed in 2.5.0 (#593): a number is read only when it is a non-negative safe integer"
        },
        {
          "id": "cpf.format#[1.5]",
          "args": [
            1.5
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: when it is a negative, fractional or unsafe number; changed in 2.5.0 (#593): a number is read only when it is a non-negative safe integer"
        },
        {
          "id": "cpf.format#[9007199254740992]",
          "args": [
            9007199254740992
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: when it is a negative, fractional or unsafe number; changed in 2.5.0 (#593): a number is read only when it is a non-negative safe integer"
        },
        {
          "id": "cpf.format#[123456789.09,{\"pad\":true}]",
          "args": [
            123456789.09,
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: when it is a negative, fractional or unsafe number; changed in 2.5.0 (#593): a number is read only when it is a non-negative safe integer"
        },
        {
          "id": "cpf.format#[\"abc\",{\"pad\":true}]",
          "args": [
            "abc",
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: should return an empty string for a value without digits even when padding"
        },
        {
          "id": "cpf.format#[\"746506880\",{\"pad\":true}]",
          "args": [
            "746506880",
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": "007.465.068-80"
          },
          "note": "JavaScript docs example"
        },
        {
          "id": "cpf.format#[\"74650688000\"]",
          "args": [
            "74650688000"
          ],
          "expect": {
            "returns": "746.506.880-00"
          },
          "note": "JavaScript docs example"
        },
        {
          "id": "cpf.format#[\"12345678909\",{\"obfuscate\":true}]",
          "args": [
            "12345678909",
            {
              "obfuscate": true
            }
          ],
          "expect": {
            "returns": "***.456.789-**"
          },
          "note": "JavaScript docs example"
        }
      ]
    },
    {
      "id": "cpf.generate",
      "level": "core",
      "summary": "Generates a valid random CPF.",
      "description": "Generates a valid random CPF: 11 digits, unformatted.\n\n- `state` (a state code such as `SP`) sets the 9th digit, the fiscal region, to the region of that state (see `cpf.getInfo`). The code is read ignoring letter case and surrounding whitespace, so `\"sp\"` and `\" SP \"` are `SP`. 2.4.0 read only the uppercase code and gave a random digit for `\"sp\"`.\n- Without `state`, or with an unknown code, the digit is random.\n- A CPF whose 11 digits are all the same is never returned.",
      "params": [
        {
          "name": "state",
          "type": "string",
          "optional": true
        }
      ],
      "returns": "string",
      "cases": [
        {
          "id": "cpf.generate#generated-is-valid",
          "args": [],
          "expect": {
            "satisfies": "cpf.isValid"
          },
          "repeat": 5,
          "note": "every generated value must pass the lib's own validator"
        },
        {
          "id": "cpf.generate#state-sp",
          "args": [
            "SP"
          ],
          "expect": {
            "matches": "^[0-9]{8}8[0-9]{2}$"
          },
          "repeat": 5,
          "note": "the 9th digit is the fiscal region of the state (8 for SP)"
        },
        {
          "id": "cpf.generate#state-lower-case",
          "args": [
            "sp"
          ],
          "expect": {
            "matches": "^[0-9]{8}8[0-9]{2}$"
          },
          "repeat": 5,
          "note": "changed in 2.5.0 (#604): the state code is read ignoring case"
        },
        {
          "id": "cpf.generate#state-whitespace",
          "args": [
            " rs "
          ],
          "expect": {
            "matches": "^[0-9]{8}0[0-9]{2}$"
          },
          "repeat": 5,
          "note": "changed in 2.5.0 (#604): the state code is read ignoring case and surrounding whitespace"
        }
      ]
    },
    {
      "id": "cpf.getInfo",
      "level": "extended",
      "summary": "Reads the fields of a CPF, including its fiscal region.",
      "description": "Reads the fields of a CPF: the 8-digit base, the fiscal region digit with its states, and the 2 check digits. Accepts the same input as `cpf.isValid` and returns `null` exactly when `cpf.isValid` is `false`.\n\n- `base` is the first 8 digits. `checkDigits` is the last 2.\n- `fiscalRegion` is the 9th digit, as a string: `1` to `9` for the 1st to 9th Região Fiscal of the Receita Federal, and `0` for the 10th.\n- `states` lists the states of that region, sorted by state name: 1 DF, GO, MT, MS, TO; 2 AC, AP, AM, PA, RO, RR; 3 CE, MA, PI; 4 AL, PB, PE, RN; 5 BA, SE; 6 MG; 7 ES, RJ; 8 SP; 9 PR, SC; 0 RS.\n- The digit is the fiscal region of the address given at the first registration. It is not the place of birth or of residence.\n- In a region with more than one state, the number does not say which one.\n- Returns `null` for a reserved number such as `00000000000` and for any value that is not a string.\n- Returns a new object, with a new `states` list, on every call.",
      "params": [
        {
          "name": "value",
          "type": "string"
        }
      ],
      "returns": "CpfInfo?",
      "cases": [
        {
          "id": "cpf.getInfo#[\"123.456.789-09\"]",
          "args": [
            "123.456.789-09"
          ],
          "expect": {
            "returns": {
              "base": "12345678",
              "fiscalRegion": "9",
              "states": [
                "PR",
                "SC"
              ],
              "checkDigits": "09"
            }
          },
          "note": "from the maintainer briefing, #558"
        },
        {
          "id": "cpf.getInfo#[\"12345678900\"]",
          "args": [
            "12345678900"
          ],
          "expect": {
            "returns": null
          },
          "note": "from the maintainer briefing, #558 (wrong check digit)"
        },
        {
          "id": "cpf.getInfo#[\"12345678909\"]",
          "args": [
            "12345678909"
          ],
          "expect": {
            "returns": {
              "base": "12345678",
              "fiscalRegion": "9",
              "states": [
                "PR",
                "SC"
              ],
              "checkDigits": "09"
            }
          },
          "note": "same result without the mask"
        },
        {
          "id": "cpf.getInfo#[\"40152673113\"]",
          "args": [
            "40152673113"
          ],
          "expect": {
            "returns": {
              "base": "40152673",
              "fiscalRegion": "1",
              "states": [
                "DF",
                "GO",
                "MT",
                "MS",
                "TO"
              ],
              "checkDigits": "13"
            }
          },
          "note": "JavaScript's own test: should return the fields of the CPF, for 40152673113, of the região fiscal 1"
        },
        {
          "id": "cpf.getInfo#[\"73091462200\"]",
          "args": [
            "73091462200"
          ],
          "expect": {
            "returns": {
              "base": "73091462",
              "fiscalRegion": "2",
              "states": [
                "AC",
                "AP",
                "AM",
                "PA",
                "RO",
                "RR"
              ],
              "checkDigits": "00"
            }
          },
          "note": "JavaScript's own test: should return the fields of the CPF, for 73091462200, of the região fiscal 2"
        },
        {
          "id": "cpf.getInfo#[\"20581746317\"]",
          "args": [
            "20581746317"
          ],
          "expect": {
            "returns": {
              "base": "20581746",
              "fiscalRegion": "3",
              "states": [
                "CE",
                "MA",
                "PI"
              ],
              "checkDigits": "17"
            }
          },
          "note": "JavaScript's own test: should return the fields of the CPF, for 20581746317, of the região fiscal 3"
        },
        {
          "id": "cpf.getInfo#[\"91827364483\"]",
          "args": [
            "91827364483"
          ],
          "expect": {
            "returns": {
              "base": "91827364",
              "fiscalRegion": "4",
              "states": [
                "AL",
                "PB",
                "PE",
                "RN"
              ],
              "checkDigits": "83"
            }
          },
          "note": "JavaScript's own test: should return the fields of the CPF, for 91827364483, of the região fiscal 4"
        },
        {
          "id": "cpf.getInfo#[\"56473829598\"]",
          "args": [
            "56473829598"
          ],
          "expect": {
            "returns": {
              "base": "56473829",
              "fiscalRegion": "5",
              "states": [
                "BA",
                "SE"
              ],
              "checkDigits": "98"
            }
          },
          "note": "JavaScript's own test: should return the fields of the CPF, for 56473829598, of the região fiscal 5"
        },
        {
          "id": "cpf.getInfo#[\"37192048631\"]",
          "args": [
            "37192048631"
          ],
          "expect": {
            "returns": {
              "base": "37192048",
              "fiscalRegion": "6",
              "states": [
                "MG"
              ],
              "checkDigits": "31"
            }
          },
          "note": "JavaScript's own test: should return the fields of the CPF, for 37192048631, of the região fiscal 6"
        },
        {
          "id": "cpf.getInfo#[\"84620513717\"]",
          "args": [
            "84620513717"
          ],
          "expect": {
            "returns": {
              "base": "84620513",
              "fiscalRegion": "7",
              "states": [
                "ES",
                "RJ"
              ],
              "checkDigits": "17"
            }
          },
          "note": "JavaScript's own test: should return the fields of the CPF, for 84620513717, of the região fiscal 7"
        },
        {
          "id": "cpf.getInfo#[\"15937264819\"]",
          "args": [
            "15937264819"
          ],
          "expect": {
            "returns": {
              "base": "15937264",
              "fiscalRegion": "8",
              "states": [
                "SP"
              ],
              "checkDigits": "19"
            }
          },
          "note": "JavaScript's own test: should return the fields of the CPF, for 15937264819, of the região fiscal 8"
        },
        {
          "id": "cpf.getInfo#[\"60248175920\"]",
          "args": [
            "60248175920"
          ],
          "expect": {
            "returns": {
              "base": "60248175",
              "fiscalRegion": "9",
              "states": [
                "PR",
                "SC"
              ],
              "checkDigits": "20"
            }
          },
          "note": "JavaScript's own test: should return the fields of the CPF, for 60248175920, of the região fiscal 9"
        },
        {
          "id": "cpf.getInfo#[\"48301692065\"]",
          "args": [
            "48301692065"
          ],
          "expect": {
            "returns": {
              "base": "48301692",
              "fiscalRegion": "0",
              "states": [
                "RS"
              ],
              "checkDigits": "65"
            }
          },
          "note": "JavaScript's own test: should return the fields of the CPF, for 48301692065, of the região fiscal 0"
        },
        {
          "id": "cpf.getInfo#[\"280012389-38\"]",
          "args": [
            "280012389-38"
          ],
          "expect": {
            "returns": {
              "base": "28001238",
              "fiscalRegion": "9",
              "states": [
                "PR",
                "SC"
              ],
              "checkDigits": "38"
            }
          },
          "note": "JavaScript's own test: should return the fields of the CPF, for the worked example of the e-Financeira manual (280012389-38)"
        },
        {
          "id": "cpf.getInfo#[\" 111 444 777 35\\n\"]",
          "args": [
            " 111 444 777 35\n"
          ],
          "expect": {
            "returns": {
              "base": "11144477",
              "fiscalRegion": "7",
              "states": [
                "ES",
                "RJ"
              ],
              "checkDigits": "35"
            }
          },
          "note": "JavaScript's own test: should return the fields of the CPF, for a value with whitespace around and between the groups"
        },
        {
          "id": "cpf.getInfo#[\"00000000000\"]",
          "args": [
            "00000000000"
          ],
          "expect": {
            "returns": null
          },
          "note": "JavaScript's own test: should return null when every digit is the same"
        },
        {
          "id": "cpf.getInfo#[\"111.111.111-11\"]",
          "args": [
            "111.111.111-11"
          ],
          "expect": {
            "returns": null
          },
          "note": "JavaScript's own test: should return null when every digit is the same"
        },
        {
          "id": "cpf.getInfo#[\"1234567890\"]",
          "args": [
            "1234567890"
          ],
          "expect": {
            "returns": null
          },
          "note": "JavaScript's own test: should return null when it is shorter than 11 digits"
        },
        {
          "id": "cpf.getInfo#[\"123456789090\"]",
          "args": [
            "123456789090"
          ],
          "expect": {
            "returns": null
          },
          "note": "JavaScript's own test: should return null when it is longer than 11 digits"
        },
        {
          "id": "cpf.getInfo#[\"123.456.789-09a\"]",
          "args": [
            "123.456.789-09a"
          ],
          "expect": {
            "returns": null
          },
          "note": "JavaScript's own test: should return null when it carries a character outside the mask"
        },
        {
          "id": "cpf.getInfo#[\"123_456_789_09\"]",
          "args": [
            "123_456_789_09"
          ],
          "expect": {
            "returns": null
          },
          "note": "JavaScript's own test: should return null when it carries a character outside the mask"
        },
        {
          "id": "cpf.getInfo#[\"\"]",
          "args": [
            ""
          ],
          "expect": {
            "returns": null
          },
          "note": "JavaScript's own test: should return null when it is an empty string"
        },
        {
          "id": "cpf.getInfo#[\"__proto__\"]",
          "args": [
            "__proto__"
          ],
          "expect": {
            "returns": null
          },
          "note": "JavaScript's own test: should return null when it is a key of the prototype chain"
        }
      ]
    },
    {
      "id": "cpf.isValid",
      "level": "core",
      "summary": "Checks whether a CPF is valid.",
      "description": "Validates a CPF: 9 base digits and 2 modulus 11 check digits (REGRA_VALIDA_CPF of the Receita Federal).\n\n- Rejects a reserved number (all 11 digits the same, for example `00000000000`).\n- A value that does not have exactly 11 digits, or the wrong check digits, is invalid.\n- Empty, blank or non-numeric input is invalid.\n- Sources: the norm of the CPF, IN RFB nº 2.172/2024, does not define the check digits. The rule and the worked example `280.012.389-38` come from the Receita Federal Manual de Preenchimento da e-Financeira (REGRA_VALIDA_CPF). The reserved numbers come from the Receita Federal DJE layout, which lists the 10 numbers with all digits the same (`000.000.000-00` to `999.999.999-99`) as not valid.\n- Pending decision (findings §2 #1): the reference (JS) ignores the formatting characters (`.`, `-`) and whitespace around and between groups. Other libraries accept digits only.",
      "params": [
        {
          "name": "cpf",
          "type": "string"
        }
      ],
      "returns": "boolean",
      "cases": [
        {
          "id": "cpf.isValid#[\"83159562131\"]",
          "args": [
            "83159562131"
          ],
          "expect": {
            "returns": true
          },
          "note": "consensus of 5 libs (go, javascript, python, ruby, rust)"
        },
        {
          "id": "cpf.isValid#[\"83159562132\"]",
          "args": [
            "83159562132"
          ],
          "expect": {
            "returns": false
          },
          "note": "consensus of 5 libs (go, javascript, python, ruby, rust)"
        },
        {
          "id": "cpf.isValid#[\"00000000000\"]",
          "args": [
            "00000000000"
          ],
          "expect": {
            "returns": false
          },
          "note": "consensus of 5 libs (go, javascript, python, ruby, rust)"
        },
        {
          "id": "cpf.isValid#[\"02746891972\"]",
          "args": [
            "02746891972"
          ],
          "expect": {
            "returns": true
          },
          "note": "consensus of 5 libs (go, javascript, python, ruby, rust)"
        },
        {
          "id": "cpf.isValid#[\"02746891973\"]",
          "args": [
            "02746891973"
          ],
          "expect": {
            "returns": false
          },
          "note": "consensus of 5 libs (go, javascript, python, ruby, rust)"
        },
        {
          "id": "cpf.isValid#[\"52708175602\"]",
          "args": [
            "52708175602"
          ],
          "expect": {
            "returns": true
          },
          "note": "consensus of 5 libs (go, javascript, python, ruby, rust)"
        },
        {
          "id": "cpf.isValid#[\"52708175603\"]",
          "args": [
            "52708175603"
          ],
          "expect": {
            "returns": false
          },
          "note": "consensus of 5 libs (go, javascript, python, ruby, rust)"
        },
        {
          "id": "cpf.isValid#[\"\"]",
          "args": [
            ""
          ],
          "expect": {
            "returns": false
          },
          "note": "consensus of 5 libs (go, javascript, python, ruby, rust)"
        },
        {
          "id": "cpf.isValid#[\"   \"]",
          "args": [
            "   "
          ],
          "expect": {
            "returns": false
          },
          "note": "consensus of 5 libs (go, javascript, python, ruby, rust)"
        },
        {
          "id": "cpf.isValid#[\"abc\"]",
          "args": [
            "abc"
          ],
          "expect": {
            "returns": false
          },
          "note": "consensus of 5 libs (go, javascript, python, ruby, rust)"
        },
        {
          "id": "cpf.isValid#[\"12345678909\"]",
          "args": [
            "12345678909"
          ],
          "expect": {
            "returns": true
          },
          "note": "from the CPF spec test cases (formerly brazilian-utils/docs specs/cpf/test-cases.json)"
        },
        {
          "id": "cpf.isValid#[\"11144477735\"]",
          "args": [
            "11144477735"
          ],
          "expect": {
            "returns": true
          },
          "note": "from the CPF spec test cases (formerly brazilian-utils/docs specs/cpf/test-cases.json)"
        },
        {
          "id": "cpf.isValid#[\"12345678900\"]",
          "args": [
            "12345678900"
          ],
          "expect": {
            "returns": false
          },
          "note": "from the CPF spec test cases (formerly brazilian-utils/docs specs/cpf/test-cases.json)"
        },
        {
          "id": "cpf.isValid#[\"11144477700\"]",
          "args": [
            "11144477700"
          ],
          "expect": {
            "returns": false
          },
          "note": "from the CPF spec test cases (formerly brazilian-utils/docs specs/cpf/test-cases.json)"
        },
        {
          "id": "cpf.isValid#[\"11111111111\"]",
          "args": [
            "11111111111"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when every digit is the same"
        },
        {
          "id": "cpf.isValid#[\"22222222222\"]",
          "args": [
            "22222222222"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when every digit is the same"
        },
        {
          "id": "cpf.isValid#[\"33333333333\"]",
          "args": [
            "33333333333"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when every digit is the same"
        },
        {
          "id": "cpf.isValid#[\"44444444444\"]",
          "args": [
            "44444444444"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when every digit is the same"
        },
        {
          "id": "cpf.isValid#[\"55555555555\"]",
          "args": [
            "55555555555"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when every digit is the same"
        },
        {
          "id": "cpf.isValid#[\"66666666666\"]",
          "args": [
            "66666666666"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when every digit is the same"
        },
        {
          "id": "cpf.isValid#[\"77777777777\"]",
          "args": [
            "77777777777"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when every digit is the same"
        },
        {
          "id": "cpf.isValid#[\"88888888888\"]",
          "args": [
            "88888888888"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when every digit is the same"
        },
        {
          "id": "cpf.isValid#[\"99999999999\"]",
          "args": [
            "99999999999"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when every digit is the same"
        },
        {
          "id": "cpf.isValid#[\"123456\"]",
          "args": [
            "123456"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false"
        },
        {
          "id": "cpf.isValid#[\"abcabcabcde\"]",
          "args": [
            "abcabcabcde"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when contains only letters or special characters"
        },
        {
          "id": "cpf.isValid#[\"11257245286\"]",
          "args": [
            "11257245286"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when is a CPF invalid"
        },
        {
          "id": "cpf.isValid#[\"foo391.838.38test0-66\"]",
          "args": [
            "foo391.838.38test0-66"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when is a CPF invalid test numbers with letters"
        },
        {
          "id": "cpf.isValid#[\"!40364478829\"]",
          "args": [
            "!40364478829"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when there is garbage before the digits, since the format is anchored at the start"
        },
        {
          "id": "cpf.isValid#[\"40364478829!\"]",
          "args": [
            "40364478829!"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when there is garbage after the digits, since the format is anchored at the end"
        },
        {
          "id": "cpf.isValid#[\"40364478837\"]",
          "args": [
            "40364478837"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when only the first check digit is wrong, even though the second would then match"
        },
        {
          "id": "cpf.isValid#[\"40364478829\"]",
          "args": [
            "40364478829"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should return true when is a CPF valid without mask"
        },
        {
          "id": "cpf.isValid#[\"962.718.458-60\"]",
          "args": [
            "962.718.458-60"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should return true when is a CPF valid with mask"
        },
        {
          "id": "cpf.isValid#[\"123 456 789 09\"]",
          "args": [
            "123 456 789 09"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should return true when is a CPF valid with a whitespace mask"
        },
        {
          "id": "cpf.isValid#[\" 12345678909\"]",
          "args": [
            " 12345678909"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should return true when is a CPF valid with leading/trailing whitespace"
        },
        {
          "id": "cpf.isValid#[\"12345678909 \"]",
          "args": [
            "12345678909 "
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should return true when is a CPF valid with leading/trailing whitespace"
        },
        {
          "id": "cpf.isValid#[\"28001238938\"]",
          "args": [
            "28001238938"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should return true when it is the worked example the RFB Manual da e-Financeira prints"
        },
        {
          "id": "cpf.isValid#[\"280.012.389-38\"]",
          "args": [
            "280.012.389-38"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should return true when it is the worked example the RFB Manual da e-Financeira prints"
        }
      ]
    },
    {
      "id": "cpf.parse",
      "level": "extended",
      "summary": "Removes the formatting characters of a CPF and returns only the digits.",
      "description": "Removes CPF formatting and keeps only digits, capped at 11 digits.\n\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.\n- A value that is not a string or a number (`null`, `undefined`, an object) returns an empty string.",
      "params": [
        {
          "name": "value",
          "type": "string | number"
        }
      ],
      "returns": "string",
      "cases": [
        {
          "id": "cpf.parse#masked",
          "args": [
            "943.895.751-04"
          ],
          "expect": {
            "returns": "94389575104"
          }
        },
        {
          "id": "cpf.parse#unmasked",
          "args": [
            "94389575104"
          ],
          "expect": {
            "returns": "94389575104"
          }
        },
        {
          "id": "cpf.parse#strips-non-digits",
          "args": [
            "943.?ABC895.751-04abc"
          ],
          "expect": {
            "returns": "94389575104"
          }
        },
        {
          "id": "cpf.parse#empty",
          "args": [
            ""
          ],
          "expect": {
            "returns": ""
          }
        },
        {
          "id": "cpf.parse#caps-length",
          "args": [
            "94389575104123"
          ],
          "expect": {
            "returns": "94389575104"
          },
          "note": "reference truncates to the 11 characters of the document; asserted by the reference (JS) unit tests"
        },
        {
          "id": "cpf.parse#[\"83159562131\"]",
          "args": [
            "83159562131"
          ],
          "expect": {
            "returns": "83159562131"
          },
          "note": "consensus of 3 libs (python, ruby, rust)"
        },
        {
          "id": "cpf.parse#[\"83159562132\"]",
          "args": [
            "83159562132"
          ],
          "expect": {
            "returns": "83159562132"
          },
          "note": "consensus of 3 libs (python, ruby, rust)"
        },
        {
          "id": "cpf.parse#[\"00000000000\"]",
          "args": [
            "00000000000"
          ],
          "expect": {
            "returns": "00000000000"
          },
          "note": "consensus of 3 libs (python, ruby, rust)"
        },
        {
          "id": "cpf.parse#[\"02746891972\"]",
          "args": [
            "02746891972"
          ],
          "expect": {
            "returns": "02746891972"
          },
          "note": "consensus of 3 libs (python, ruby, rust)"
        },
        {
          "id": "cpf.parse#[\"02746891973\"]",
          "args": [
            "02746891973"
          ],
          "expect": {
            "returns": "02746891973"
          },
          "note": "consensus of 3 libs (python, ruby, rust)"
        },
        {
          "id": "cpf.parse#[\"52708175602\"]",
          "args": [
            "52708175602"
          ],
          "expect": {
            "returns": "52708175602"
          },
          "note": "consensus of 3 libs (python, ruby, rust)"
        },
        {
          "id": "cpf.parse#[\"52708175603\"]",
          "args": [
            "52708175603"
          ],
          "expect": {
            "returns": "52708175603"
          },
          "note": "consensus of 3 libs (python, ruby, rust)"
        },
        {
          "id": "cpf.parse#[\"831.595.621-31\"]",
          "args": [
            "831.595.621-31"
          ],
          "expect": {
            "returns": "83159562131"
          },
          "note": "consensus of 3 libs (python, ruby, rust)"
        },
        {
          "id": "cpf.parse#[\"027.468.919-72\"]",
          "args": [
            "027.468.919-72"
          ],
          "expect": {
            "returns": "02746891972"
          },
          "note": "consensus of 3 libs (python, ruby, rust)"
        },
        {
          "id": "cpf.parse#[\"527.081.756-02\"]",
          "args": [
            "527.081.756-02"
          ],
          "expect": {
            "returns": "52708175602"
          },
          "note": "consensus of 3 libs (python, ruby, rust)"
        },
        {
          "id": "cpf.parse#[\"123.456.789-09\"]",
          "args": [
            "123.456.789-09"
          ],
          "expect": {
            "returns": "12345678909"
          },
          "note": "from the CPF spec test cases (formerly brazilian-utils/docs specs/cpf/test-cases.json)"
        },
        {
          "id": "cpf.parse#[\"111.444.777-35\"]",
          "args": [
            "111.444.777-35"
          ],
          "expect": {
            "returns": "11144477735"
          },
          "note": "from the CPF spec test cases (formerly brazilian-utils/docs specs/cpf/test-cases.json)"
        },
        {
          "id": "cpf.parse#[\"12345678909\"]",
          "args": [
            "12345678909"
          ],
          "expect": {
            "returns": "12345678909"
          },
          "note": "from the CPF spec test cases (formerly brazilian-utils/docs specs/cpf/test-cases.json)"
        },
        {
          "id": "cpf.parse#[\"11144477735\"]",
          "args": [
            "11144477735"
          ],
          "expect": {
            "returns": "11144477735"
          },
          "note": "from the CPF spec test cases (formerly brazilian-utils/docs specs/cpf/test-cases.json)"
        },
        {
          "id": "cpf.parse#[12345678909]",
          "args": [
            12345678909
          ],
          "expect": {
            "returns": "12345678909"
          },
          "note": "a non-negative safe integer is read as the string of its digits"
        },
        {
          "id": "cpf.parse#[-12345678909]",
          "args": [
            -12345678909
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: when it is a negative, fractional or unsafe number; changed in 2.5.0 (#593): a number is read only when it is a non-negative safe integer"
        },
        {
          "id": "cpf.parse#[1.5]",
          "args": [
            1.5
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: when it is a negative, fractional or unsafe number; changed in 2.5.0 (#593): a number is read only when it is a non-negative safe integer"
        },
        {
          "id": "cpf.parse#[9007199254740992]",
          "args": [
            9007199254740992
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: when it is a negative, fractional or unsafe number; changed in 2.5.0 (#593): a number is read only when it is a non-negative safe integer"
        }
      ]
    }
  ]
}
