Home
An immutable class to represent CPF documents.
Evaluable
- [iterator]
- at
- checkValidity
- equals
- format
- getValidity
- hashCode
- toArray
- toJSON
- toString
- with
- create
- from
- getCheckDigit
• new CPF(numbers?
): CPF
Creates a new immutable instance of CPF.
Name | Type | Default value |
---|---|---|
numbers |
Iterable <number > |
[] |
• Private
#digits: number
[] = []
• Private
#hashCode: null
| number
= null
▪ Static
Private
#seed: number
▪ Static
Readonly
Nil: CPF
An empty instance of CPF.
• get
length(): number
The number of digits in the CPF.
number
• get
size(): number
The number of digits in the CPF.
number
Deprecated
Use length
property instead
See
▸ [iterator](): Generator
<number
, void
, void
>
Iterates over the digits of the CPF.
Generator
<number
, void
, void
>
▸ at(index
): undefined
| number
Returns the digit located at the specified index. Negative integers count back from the last digit in the current CPF.
Name | Type |
---|---|
index |
number |
undefined
| number
▸ checkValidity(): boolean
Returns true
if the CPF is valid, false
otherwise. A CPF is valid if
they have 11 digits and the two last digits satisfies the
validation algorithm.
boolean
▸ equals(other
): boolean
Returnstrue
if the given value is equal to this CPF, false
otherwise.
Two CPFs are equal if they have the same sequence of digits.
Name | Type |
---|---|
other |
unknown |
boolean
Evaluable.equals
▸ format(): string
Formats the CPF in the standard pattern "###.###.###-##".
string
▸ getValidity(): CPFValidityStateFlags
Returns an object that represents the state of validity of the CPF.
See
▸ hashCode(): number
number
Evaluable.hashCode
▸ toArray(): number
[]
Returns the CPF digits in an array.
number
[]
▸ toJSON(): string
Serializes the digits of the CPF into JSON string.
string
▸ toString(): string
Returns a string representation of an object.
string
▸ with(index
, digit
): CPF
Returns a copy of the CPF with the digit at the provided index overwritten
with the given value. If the index is negative, then it replaces from the
end of the array. If the index after normalization is out of bounds,
a RangeError
is thrown.
Name | Type |
---|---|
index |
number |
digit |
number |
▸ create(): CPF
Creates new valid CPF instance of random numbers.
▸ from(formatted
): CPF
Creates a CPF instance from an string. The string can be formatted or not. If not enough digits are found on the string, an incomplete CPF will be returned.
Name | Type |
---|---|
formatted |
string |
▸ getCheckDigit(digits
, start?
, end?
): number
Returns the CPF check digit from interval of the given digits.
Name | Type | Default value |
---|---|---|
digits |
readonly number [] |
undefined |
start |
number |
0 |
end |
number |
digits.length |
number
Ƭ CPFValidityStateFlags: Object
Represents the state of validity of the CPF.
Name | Type | Description |
---|---|---|
tooShort |
boolean |
Flagged as true if the count of CPF digits between, inclusively, one and ten. |
typeMismatch |
boolean |
Flagged as true if the number of digits is eleven but the check digit algorithm fails. |
valueMissing |
boolean |
Flagged as true if the count of CPF digits is zero. |