{
  "$schema": "../cases.schema.json",
  "format": 1,
  "domain": "creditCard",
  "title": {
    "en": "Payment card",
    "pt-BR": "Cartão de pagamento"
  },
  "functions": [
    {
      "id": "creditCard.isValid",
      "level": "extended",
      "summary": "Validates a payment card number (credit or debit) with the Luhn algorithm.",
      "description": "Validates a payment card number (credit or debit): 12 to 19 digits and a Luhn check digit.\n\n- The function does not detect the brand, look up the issuer range, or check the expiry or the CVV.\n- The function rejects a number whose digits are all the same, even though it passes Luhn.\n- Accepts a string or a number. The mask characters (whitespace, `.`, `-` and `/`, the set the CPF and CNPJ accept) go between any two digits, a run of them included (`4111 - 1111 - 1111 - 1111`), because the printed grouping changes with the brand (4-4-4-4, 4-6-5, 4-6-4). Whitespace around the value is ignored.\n- Any other character makes the number invalid instead of being dropped: letters (`4111a1111b1111c1111`), `,`, `_`, parentheses, or a mask character that is not between two digits (a leading `-`, a trailing `.`).\n- A number is accepted only when it is a non-negative safe integer. A number above `2^53 - 1` has already been rounded when it arrives, and a negative or fractional one is not a card number, so pass a longer number as a string.",
      "params": [
        {
          "name": "value",
          "type": "string | number"
        }
      ],
      "returns": "boolean",
      "cases": [
        {
          "id": "creditCard.isValid#[\"4111111111111111\"]",
          "args": [
            "4111111111111111"
          ],
          "expect": {
            "returns": true
          }
        },
        {
          "id": "creditCard.isValid#[\"5555555555554444\"]",
          "args": [
            "5555555555554444"
          ],
          "expect": {
            "returns": true
          }
        },
        {
          "id": "creditCard.isValid#15-digits",
          "args": [
            "378282246310005"
          ],
          "expect": {
            "returns": true
          }
        },
        {
          "id": "creditCard.isValid#masked",
          "args": [
            "4111 1111 1111 1111"
          ],
          "expect": {
            "returns": true
          }
        },
        {
          "id": "creditCard.isValid#luhn-fail",
          "args": [
            "4111111111111112"
          ],
          "expect": {
            "returns": false
          }
        },
        {
          "id": "creditCard.isValid#zeros",
          "args": [
            "0000000000000000"
          ],
          "expect": {
            "returns": false
          }
        },
        {
          "id": "creditCard.isValid#too-short",
          "args": [
            "60110000000"
          ],
          "expect": {
            "returns": false
          }
        },
        {
          "id": "creditCard.isValid#letters",
          "args": [
            "abcdabcdabcd"
          ],
          "expect": {
            "returns": false
          }
        },
        {
          "id": "creditCard.isValid#empty",
          "args": [
            ""
          ],
          "expect": {
            "returns": false
          }
        },
        {
          "id": "creditCard.isValid#[\"6011111111111117\"]",
          "args": [
            "6011111111111117"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should return true for the Discover test number 6011111111111117"
        },
        {
          "id": "creditCard.isValid#[4111111111111111]",
          "args": [
            4111111111111111
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should return true for a number input"
        },
        {
          "id": "creditCard.isValid#[\"4111-1111-1111-1111\"]",
          "args": [
            "4111-1111-1111-1111"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should return true for a value with a hyphenated mask"
        },
        {
          "id": "creditCard.isValid#[\"4111.1111.1111.1111\"]",
          "args": [
            "4111.1111.1111.1111"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should return true for a value masked with the other interchangeable separators"
        },
        {
          "id": "creditCard.isValid#[\"4111/1111/1111/1111\"]",
          "args": [
            "4111/1111/1111/1111"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should return true for a value masked with the other interchangeable separators"
        },
        {
          "id": "creditCard.isValid#[\"4111.1111/1111-1111\"]",
          "args": [
            "4111.1111/1111-1111"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should return true for a value masked with the other interchangeable separators"
        },
        {
          "id": "creditCard.isValid#[\"3782-822463-10005\"]",
          "args": [
            "3782-822463-10005"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should return true for a separator between any two digits, since the grouping changes with the brand"
        },
        {
          "id": "creditCard.isValid#[\"4.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1\"]",
          "args": [
            "4.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should return true for a separator between any two digits, since the grouping changes with the brand"
        },
        {
          "id": "creditCard.isValid#[\"4111 - 1111 - 1111 - 1111\"]",
          "args": [
            "4111 - 1111 - 1111 - 1111"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should return true for a value whose digit groups are separated by a run of mask characters"
        },
        {
          "id": "creditCard.isValid#[\"4111  1111  1111  1111\"]",
          "args": [
            "4111  1111  1111  1111"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should return true for a value whose digit groups are separated by a run of mask characters"
        },
        {
          "id": "creditCard.isValid#[\"  4111 1111 1111 1111  \"]",
          "args": [
            "  4111 1111 1111 1111  "
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should return true for a value surrounded by whitespace"
        },
        {
          "id": "creditCard.isValid#[\"601100000004\"]",
          "args": [
            "601100000004"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should return true for the shortest accepted length (12 digits)"
        },
        {
          "id": "creditCard.isValid#[\"1234567890123456785\"]",
          "args": [
            "1234567890123456785"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should return true for the longest accepted length (19 digits)"
        },
        {
          "id": "creditCard.isValid#[\"000000000000\"]",
          "args": [
            "000000000000"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when every digit is the same, even though the Luhn check passes"
        },
        {
          "id": "creditCard.isValid#[\"8888888888888888\"]",
          "args": [
            "8888888888888888"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when every digit is the same, even though the Luhn check passes"
        },
        {
          "id": "creditCard.isValid#[\"0000000000000000000\"]",
          "args": [
            "0000000000000000000"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when every digit is the same, even though the Luhn check passes"
        },
        {
          "id": "creditCard.isValid#[\"0000 0000 0000 0000\"]",
          "args": [
            "0000 0000 0000 0000"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when every digit is the same behind a mask, even though the Luhn check passes"
        },
        {
          "id": "creditCard.isValid#[\"12345678901234567850\"]",
          "args": [
            "12345678901234567850"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when it has more than 19 digits (20 digits)"
        },
        {
          "id": "creditCard.isValid#[\"12345678901234567852\"]",
          "args": [
            "12345678901234567852"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when it has more than 19 digits and would pass the Luhn check on its own"
        },
        {
          "id": "creditCard.isValid#[\"00000000000000000000\"]",
          "args": [
            "00000000000000000000"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when it has more than 19 digits and would still pass the Luhn check on its own"
        },
        {
          "id": "creditCard.isValid#[\"0\"]",
          "args": [
            "0"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when it has fewer than 12 digits and would still pass the Luhn check on its own"
        },
        {
          "id": "creditCard.isValid#[-4111111111111111]",
          "args": [
            -4111111111111111
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when it is a negative number"
        },
        {
          "id": "creditCard.isValid#[411111111111111.1]",
          "args": [
            411111111111111.1
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when it is a number that is not an integer"
        },
        {
          "id": "creditCard.isValid#[\"abc4111111111111111\"]",
          "args": [
            "abc4111111111111111"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when letters are attached before the digits"
        },
        {
          "id": "creditCard.isValid#[\"4111a1111b1111c1111\"]",
          "args": [
            "4111a1111b1111c1111"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when letters are embedded between the digit groups"
        },
        {
          "id": "creditCard.isValid#[\"(41)11-1111 1111 1111\"]",
          "args": [
            "(41)11-1111 1111 1111"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when the mask uses characters outside the interchangeable set"
        },
        {
          "id": "creditCard.isValid#[\"4111,1111,1111,1111\"]",
          "args": [
            "4111,1111,1111,1111"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when the mask uses characters outside the interchangeable set"
        },
        {
          "id": "creditCard.isValid#[\"4111_1111_1111_1111\"]",
          "args": [
            "4111_1111_1111_1111"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when the mask uses characters outside the interchangeable set"
        },
        {
          "id": "creditCard.isValid#[\"-4111111111111111\"]",
          "args": [
            "-4111111111111111"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when a mask character is not between two digits"
        },
        {
          "id": "creditCard.isValid#[\"4111111111111111.\"]",
          "args": [
            "4111111111111111."
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should return false when a mask character is not between two digits"
        },
        {
          "id": "creditCard.isValid#[\"123456789\"]",
          "args": [
            "123456789"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript docs example (too short)"
        },
        {
          "id": "creditCard.isValid#[4111111111111111000]",
          "args": [
            4111111111111111000
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript docs example (above 2^53 - 1, pass it as a string)"
        },
        {
          "id": "creditCard.isValid#[\"4111111111111111111\"]",
          "args": [
            "4111111111111111111"
          ],
          "expect": {
            "returns": false
          },
          "note": "a 19-digit string that fails Luhn (the same digits as the number above, read exactly)"
        }
      ]
    }
  ]
}
