Documentation
¶
Overview ¶
Package cuit exports functions for validating, parsing and formatting CUIT and CUIL numbers.
Index ¶
- Constants
- func Compose(kind, id, ver uint64) uint64
- func Format(cuit uint64) string
- func IsValid(cuit uint64) bool
- func Parse(cuit string) (uint64, error)
- func Parts(cuit uint64) (kind, id, ver uint64)
- func Pred(cuit uint64) uint64
- func Random(r *rand.Rand) uint64
- func Succ(cuit uint64) uint64
- func Verifier(cuit uint64) uint64
- type TipoPersona
Examples ¶
Constants ¶
const ( // Min is the minimum valid cuit Min = 20000000001 // Max is the maximum valid cuit Max = 34999999990 )
Variables ¶
This section is empty.
Functions ¶
func Compose ¶ added in v1.4.0
Compose builds a cuit number from its parts.
This function drops the most-significative excess digits of all its input arguments.
Please see the examples.
Example ¶
fmt.Println(Compose(20, 12345678, 1)) // basic case fmt.Println(Compose(20, 123456789, 1)) // excess id fmt.Println(Compose(210, 12345678, 1)) // excess kind fmt.Println(Compose(20, 12345678, 12)) // excess verifier fmt.Println(Compose(1234, 123456789, 1234)) // excess all
Output: 20123456781 20234567891 10123456781 20123456782 34234567894
func Format ¶
Format returns a standard formatted string representation of the provided CUIT number.
This function uses Parts(cuit) to extract the constituent parts of the CUIT number, hence that function behavior regarding digits exceeding the allowed range is maintained.
Example ¶
s := Format(20123456781) fmt.Println(s)
Output: 20-12345678-1
func IsValid ¶
IsValid checks the provided CUIT/CUIL number for validity considering wether the number is in valid range, has a valid kind (20, 23, 24, 27, 30, 33 or 34) and has a correct verifier digit.
Example (Invalid) ¶
v := IsValid(20123456781) fmt.Println(v)
Output: false
Example (Valid) ¶
v := IsValid(33693450239) fmt.Println(v)
Output: true
func Parse ¶
Parse extracts a CUIT number from the string provided using the standard format "DD-DDDDDDDD-D" being "D" any decimal digit and both "-" characters optional.
If the string can not be parsed as a CUIT number the function returns error.
Example ¶
cuit, err := Parse("20-12345678-2") if err != nil { // handle parse error } fmt.Println(cuit)
Output: 20123456782
Example (Nodash) ¶
cuit, err := Parse("20123456782") if err != nil { // handle parse error } fmt.Println(cuit)
Output: 20123456782
func Parts ¶
Parts extracts the kind number, identifier number and verifier digit parts out of the provided CUIT number and returns them as the three return values.
This functions discards any decimal digit exceeding the allowed range.
Example (Basic) ¶
kind, id, ver := Parts(20123456781) fmt.Println(kind, id, ver)
Output: 20 12345678 1
Example (Range) ¶
kind, id, ver := Parts(10020123456781) fmt.Println(kind, id, ver)
Output: 20 12345678 1
func Pred ¶ added in v1.6.0
Pred returns predecessor of cuit unless cuit equals Min in which case it returns Min or cuit is not valid in which case it returns 0.
Example ¶
for _, cuit := range []uint64{ 20000000001, 20242643772, 34999999990, } { fmt.Println(Pred(cuit)) }
Output: 20000000001 20242643764 34999999982
func Random ¶ added in v1.3.0
Random computes and returns random valid cuit numbers.
Example ¶
notrandom := rand.New(rand.NewSource(1)) for i := 0; i < 20; i++ { fmt.Println(Random(notrandom)) }
Output: 24821535510 27897858598 24491673202 20865519568 24350552576 34636692877 27144588369 30381828731 24653598994 27081291395 20381499562 30835156377 27422311098 27938316509 20430747798 24047844432 23879884594 34081375471 27838147157 20733877805
func Succ ¶ added in v1.6.0
Succ returns the successor of cuit unless cuit equals Max in which case it returns Max or cuit is not valid in which case it returns 0.
Example ¶
for _, cuit := range []uint64{ 20000000001, 20242643772, 34999999990, } { fmt.Println(Succ(cuit)) }
Output: 20000000028 20242643780 34999999990
func Verifier ¶ added in v1.4.0
Verifier computes and returns the correct verifier digit for the number supplied in the cuit parameter.
This function ignores the unit digit from the input value (as it is the verifier digit being calculated).
This function ignores digits past the eleventh (10^11).
A return value of 10 means the input cuit number does not exist.
Example ¶
fmt.Println(Verifier(201111111083123)) // bigger number fmt.Println(Verifier(20111111117)) // incorrect verifier fmt.Println(Verifier(20111111112)) // correct verifier fmt.Println(Verifier(20236111)) // smaller number
Output: 8 2 2 6
Types ¶
type TipoPersona ¶ added in v1.5.0
type TipoPersona tipopersona
TipoPersona es un enumerado de los tipos de persona
const ( // PersonaFísica es el tipo de las personas físicas ("humanas") PersonaFísica TipoPersona = iota // PersonaJurídica es el tipo de las personas jurídicas PersonaJurídica )
func TipoPersonaCUIT ¶ added in v1.5.0
func TipoPersonaCUIT(cuit uint64) TipoPersona
TipoPersonaCUIT retorna el TipoPersona que corresponde al cuit suministrado según su rango
Example ¶
// using switch/case show := func(c uint64) { switch TipoPersonaCUIT(c) { case PersonaFísica: fmt.Println("física") // or do anything... case PersonaJurídica: fmt.Println("jurídica") // or do anything... } } show(30123456781) show(20123456781) // Stringer implementation fmt.Println(TipoPersonaCUIT(30123456781)) fmt.Println(TipoPersonaCUIT(20123456781))
Output: jurídica física Persona Jurídica Persona Física
func (TipoPersona) String ¶ added in v1.5.0
func (t TipoPersona) String() string