{
  "$schema": "../cases.schema.json",
  "format": 1,
  "domain": "caepf",
  "title": {
    "en": "CAEPF",
    "pt-BR": "CAEPF"
  },
  "functions": [
    {
      "id": "caepf.format",
      "level": "extended",
      "summary": "Formats a CAEPF number with the official mask.",
      "description": "Formats a CAEPF with the mask `000.000.000/000-00`.\n\n- The mask is applied as far as the digits go, so a value being typed is masked progressively, and digits beyond the 14th are dropped. `options.pad` first left-pads with zeros to 14 digits.\n- A number is read only when it is a safe non-negative integer. A negative, fractional, non-finite or unsafe number returns an empty string (2.4.0 read the digits of any number, sign and decimal point dropped).\n- An empty value, or one without digits, returns an empty string even with `pad`. Until 2.4.0 `pad` returned the whole zero mask (`000.000.000/000-00`).",
      "params": [
        {
          "name": "value",
          "type": "string | number"
        },
        {
          "name": "options",
          "type": "FormatCaepfOptions",
          "optional": true
        }
      ],
      "returns": "string",
      "cases": [
        {
          "id": "caepf.format#[\"29311861000184\"]",
          "args": [
            "29311861000184"
          ],
          "expect": {
            "returns": "293.118.610/001-84"
          }
        },
        {
          "id": "caepf.format#already-formatted",
          "args": [
            "293.118.610/001-84"
          ],
          "expect": {
            "returns": "293.118.610/001-84"
          }
        },
        {
          "id": "caepf.format#partial",
          "args": [
            "2931"
          ],
          "expect": {
            "returns": "293.1"
          }
        },
        {
          "id": "caepf.format#empty",
          "args": [
            ""
          ],
          "expect": {
            "returns": ""
          }
        },
        {
          "id": "caepf.format#[41142260000101]",
          "args": [
            41142260000101
          ],
          "expect": {
            "returns": "411.422.600/001-01"
          },
          "note": "JavaScript's own test: should format a number input"
        },
        {
          "id": "caepf.format#[\"2\"]",
          "args": [
            "2"
          ],
          "expect": {
            "returns": "2"
          },
          "note": "JavaScript's own test: should format progressively as digits are typed"
        },
        {
          "id": "caepf.format#[\"29\"]",
          "args": [
            "29"
          ],
          "expect": {
            "returns": "29"
          },
          "note": "JavaScript's own test: should format progressively as digits are typed"
        },
        {
          "id": "caepf.format#[\"293\"]",
          "args": [
            "293"
          ],
          "expect": {
            "returns": "293"
          },
          "note": "JavaScript's own test: should format progressively as digits are typed"
        },
        {
          "id": "caepf.format#[\"29311\"]",
          "args": [
            "29311"
          ],
          "expect": {
            "returns": "293.11"
          },
          "note": "JavaScript's own test: should format progressively as digits are typed"
        },
        {
          "id": "caepf.format#[\"293118\"]",
          "args": [
            "293118"
          ],
          "expect": {
            "returns": "293.118"
          },
          "note": "JavaScript's own test: should format progressively as digits are typed"
        },
        {
          "id": "caepf.format#[\"293118610001840000\"]",
          "args": [
            "293118610001840000"
          ],
          "expect": {
            "returns": "293.118.610/001-84"
          },
          "note": "JavaScript's own test: should truncate values longer than 14 digits"
        },
        {
          "id": "caepf.format#[\"184\",{\"pad\":true}]",
          "args": [
            "184",
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": "000.000.000/001-84"
          },
          "note": "JavaScript's own test: should pad the value with leading zeros when options.pad is true"
        },
        {
          "id": "caepf.format#[\"184\"]",
          "args": [
            "184"
          ],
          "expect": {
            "returns": "184"
          },
          "note": "JavaScript's own test: should not pad the value when options.pad is not given"
        },
        {
          "id": "caepf.format#[-1]",
          "args": [
            -1
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: should return an empty string when it is a negative, fractional or unsafe number (#593 number rule)"
        },
        {
          "id": "caepf.format#[1.5]",
          "args": [
            1.5
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: should return an empty string when it is a negative, fractional or unsafe number (#593 number rule)"
        },
        {
          "id": "caepf.format#[9007199254740992]",
          "args": [
            9007199254740992
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: should return an empty string when it is a negative, fractional or unsafe number (#593 number rule)"
        },
        {
          "id": "caepf.format#[\"\",{\"pad\":true}]",
          "args": [
            "",
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": ""
          },
          "note": "changed in 2.5.0 (#615): should return an empty string for a value without digits even when padding; 2.4.0 returned the zero mask"
        },
        {
          "id": "caepf.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"
        },
        {
          "id": "caepf.format#[null,{\"pad\":true}]",
          "args": [
            null,
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": ""
          },
          "note": "a null value gives an empty string even with pad (2.4.0 did the same)"
        },
        {
          "id": "caepf.format#[-249859674386]",
          "args": [
            -249859674386
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript docs example: not a non-negative safe integer"
        }
      ]
    },
    {
      "id": "caepf.isValid",
      "level": "extended",
      "summary": "Checks whether a CAEPF number is valid.",
      "description": "Validates a CAEPF: 14 digits, the 9-digit CPF base of the holder, a 3-digit sequence and 2 check digits. The CAEPF replaced the CEI for individuals who hire employees, such as rural producers.\n\n- Both check digits follow the CNPJ modulus 11. Then the resulting pair is shifted by 12, wrapping around 100.\n- A value whose 12-digit base (the CPF base and the sequence) has all digits the same is rejected.\n- The value may be a number or a string of 14 digits. Between the printed groups (3, 3, 3, 3 and 2 digits) there may be any run of whitespace, `.`, `-` or `/`, and any of those runs may be left out, so `293118.610/00184` is valid. Whitespace around the value is ignored. Anything else, such as another separator, a letter or a separator inside a group, is rejected.\n- A number is read only when it is a safe non-negative integer. A negative, fractional, non-finite or unsafe number is invalid.\n- No official source publishes the check digit rule. Only the 14 positions and the 9-digit CPF base are official (SERPRO's documentation of the Receita Federal cadastro). The IN RFB 1.828/2018 has no check digit, and the eSocial only checks that the number exists in the Receita Federal base. The 3 + 2 split of the last 5 digits and the rule come from third-party reference implementations. They accept SERPRO's example `00000002500171`.\n- A number loses its leading zeros, so a value that starts with `0` is only accepted as a string.",
      "params": [
        {
          "name": "value",
          "type": "string | number"
        }
      ],
      "returns": "boolean",
      "cases": [
        {
          "id": "caepf.isValid#[\"293.118.610/001-84\"]",
          "args": [
            "293.118.610/001-84"
          ],
          "expect": {
            "returns": true
          }
        },
        {
          "id": "caepf.isValid#[\"29311861000184\"]",
          "args": [
            "29311861000184"
          ],
          "expect": {
            "returns": true
          }
        },
        {
          "id": "caepf.isValid#[\"41142260000101\"]",
          "args": [
            "41142260000101"
          ],
          "expect": {
            "returns": true
          }
        },
        {
          "id": "caepf.isValid#wrong-check-digit",
          "args": [
            "29311861000185"
          ],
          "expect": {
            "returns": false
          }
        },
        {
          "id": "caepf.isValid#zeros",
          "args": [
            "00000000000000"
          ],
          "expect": {
            "returns": false
          }
        },
        {
          "id": "caepf.isValid#too-short",
          "args": [
            "1234567890"
          ],
          "expect": {
            "returns": false
          }
        },
        {
          "id": "caepf.isValid#letters",
          "args": [
            "abc.118.610/001-84"
          ],
          "expect": {
            "returns": false
          }
        },
        {
          "id": "caepf.isValid#empty",
          "args": [
            ""
          ],
          "expect": {
            "returns": false
          }
        },
        {
          "id": "caepf.isValid#[\"293118610001840\"]",
          "args": [
            "293118610001840"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when it does not have 14 digits"
        },
        {
          "id": "caepf.isValid#[\"293.118.610/001-84a\"]",
          "args": [
            "293.118.610/001-84a"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when a valid registration is followed or preceded by a letter"
        },
        {
          "id": "caepf.isValid#[\"a293.118.610/001-84\"]",
          "args": [
            "a293.118.610/001-84"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when a valid registration is followed or preceded by a letter"
        },
        {
          "id": "caepf.isValid#[\"293#118#610#001#84\"]",
          "args": [
            "293#118#610#001#84"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when it has 14 digits but an unsupported separator"
        },
        {
          "id": "caepf.isValid#[\"11111111111111\"]",
          "args": [
            "11111111111111"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when every digit is the same"
        },
        {
          "id": "caepf.isValid#[\"00000000000012\"]",
          "args": [
            "00000000000012"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when the 12 digit base is a repeated digit, as isValidCei and isValidCno reject it"
        },
        {
          "id": "caepf.isValid#[\"000.000.000/000-12\"]",
          "args": [
            "000.000.000/000-12"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when the 12 digit base is a repeated digit, as isValidCei and isValidCno reject it"
        },
        {
          "id": "caepf.isValid#[\"11111111111192\"]",
          "args": [
            "11111111111192"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when the 12 digit base is a repeated digit, as isValidCei and isValidCno reject it"
        },
        {
          "id": "caepf.isValid#[\"29311861000100\"]",
          "args": [
            "29311861000100"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when the check digits are zeroed (293.118.610/001-00, Casilhero/brazilian-validators CaepfTest)"
        },
        {
          "id": "caepf.isValid#[\"293.118.610/001-00\"]",
          "args": [
            "293.118.610/001-00"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when the check digits are zeroed (293.118.610/001-00, Casilhero/brazilian-validators CaepfTest)"
        },
        {
          "id": "caepf.isValid#[\"29311861000172\"]",
          "args": [
            "29311861000172"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when the shift of 12 is not applied (29311861000172 instead of 29311861000184)"
        },
        {
          "id": "caepf.isValid#[\"411.422.600/001-01\"]",
          "args": [
            "411.422.600/001-01"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should return true for 411.422.600/001-01 (VitorLuizC/brazilian-values isCAEPF doc example)"
        },
        {
          "id": "caepf.isValid#[\"82620035200115\"]",
          "args": [
            "82620035200115"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should return true for 826.200.352/001-15, whose first modulus 11 remainder is 10"
        },
        {
          "id": "caepf.isValid#[\"70180196300102\"]",
          "args": [
            "70180196300102"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should return true for 701.801.963/001-02, whose second modulus 11 remainder is 10"
        },
        {
          "id": "caepf.isValid#[29311861000184]",
          "args": [
            29311861000184
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should return true for a number input"
        },
        {
          "id": "caepf.isValid#[\" 293 118 610 001 84 \"]",
          "args": [
            " 293 118 610 001 84 "
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should return true for a whitespace mask and surrounding whitespace"
        },
        {
          "id": "caepf.isValid#[-29311861000184]",
          "args": [
            -29311861000184
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when it is a negative or fractional number (#593 number rule)"
        },
        {
          "id": "caepf.isValid#[293118610001.84]",
          "args": [
            293118610001.84
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when it is a negative or fractional number (#593 number rule)"
        },
        {
          "id": "caepf.isValid#[\"00000002500171\"]",
          "args": [
            "00000002500171"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should return true for 00000002500171, the example of SERPRO's documentation of the Receita Federal's CAEPF cadastro"
        },
        {
          "id": "caepf.isValid#[2500171]",
          "args": [
            2500171
          ],
          "expect": {
            "returns": false
          },
          "note": "a number loses its leading zeros, so the 14 digits are not there"
        },
        {
          "id": "caepf.isValid#[\"293118.610/00184\"]",
          "args": [
            "293118.610/00184"
          ],
          "expect": {
            "returns": true
          },
          "note": "a separator may be left out between two groups; run against the JavaScript library"
        }
      ]
    },
    {
      "id": "caepf.parse",
      "level": "extended",
      "summary": "Removes the formatting characters of a CAEPF and returns only the digits.",
      "description": "Removes CAEPF formatting and keeps only digits, capped at 14 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, sign and decimal point dropped).",
      "params": [
        {
          "name": "value",
          "type": "string | number"
        }
      ],
      "returns": "string",
      "cases": [
        {
          "id": "caepf.parse#masked",
          "args": [
            "293.118.610/001-84"
          ],
          "expect": {
            "returns": "29311861000184"
          }
        },
        {
          "id": "caepf.parse#unmasked",
          "args": [
            "29311861000184"
          ],
          "expect": {
            "returns": "29311861000184"
          }
        },
        {
          "id": "caepf.parse#strips-non-digits",
          "args": [
            "293.?ABC118.610/001-84abc"
          ],
          "expect": {
            "returns": "29311861000184"
          }
        },
        {
          "id": "caepf.parse#empty",
          "args": [
            ""
          ],
          "expect": {
            "returns": ""
          }
        },
        {
          "id": "caepf.parse#caps-length",
          "args": [
            "29311861000184999"
          ],
          "expect": {
            "returns": "29311861000184"
          },
          "note": "reference truncates to the 14 characters of the document; asserted by the reference (JS) unit tests"
        },
        {
          "id": "caepf.parse#[29311861000184]",
          "args": [
            29311861000184
          ],
          "expect": {
            "returns": "29311861000184"
          },
          "note": "JavaScript's own test: should read a number as the string of its digits"
        },
        {
          "id": "caepf.parse#[-1]",
          "args": [
            -1
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: should return an empty string when it is a negative, fractional or unsafe number (#593 number rule)"
        },
        {
          "id": "caepf.parse#[1.5]",
          "args": [
            1.5
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: should return an empty string when it is a negative, fractional or unsafe number (#593 number rule)"
        },
        {
          "id": "caepf.parse#[9007199254740992]",
          "args": [
            9007199254740992
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: should return an empty string when it is a negative, fractional or unsafe number (#593 number rule)"
        }
      ]
    }
  ]
}
