···11+name: Tests
22+33+on: [pull_request, push]
44+55+jobs:
66+77+ build:
88+ name: Build
99+ runs-on: ubuntu-latest
1010+ steps:
1111+1212+ - name: Set up Go 1.14
1313+ uses: actions/setup-go@v1
1414+ with:
1515+ go-version: 1.14
1616+ id: go
1717+1818+ - name: Check out code into the Go module directory
1919+ uses: actions/checkout@v2
2020+2121+ - name: Get dependencies
2222+ run: |
2323+ go get -v -t -d ./...
2424+ if [ -f Gopkg.toml ]; then
2525+ curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
2626+ dep ensure
2727+ fi
2828+2929+ - name: Build
3030+ run: go test
+12
LICENSE
···11+Copyright (c) 2020 Eduardo Cuducos
22+All rights reserved.
33+44+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
55+66+1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
77+88+2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
99+1010+3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
1111+1212+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+40
README.md
···11+# Go CNPF []()[](https://godoc.org/github.com/cuducos/go-cnpf)
22+33+A Go module to validate CPF and CNPJ numbers (Brazilian people andcompanies unique identifier for the Federal Revenue).
44+55+> The pseudo-acronym _CNPF_ is a sort of tong-twister and a common typo when developers discuss the implementation of objects that could hold either a CPF or a CNPJ numbers.
66+77+```go
88+package main
99+1010+import "github.com/cuducos/go-cnpf"
1111+1212+1313+func main() {
1414+ // these return true
1515+ cnpf.IsValid("23858488135")
1616+ cnpf.IsValid("238.584.881-35")
1717+ cnpf.IsValid("11222333000181")
1818+ cnpf.IsValid("11.222.333/0001-81")
1919+2020+ // these return false
2121+ cnpf.IsValid("111.111.111-11")
2222+ cnpf.IsValid("11.111.111/1111-11")
2323+ cnpf.IsValid("123.456.769/01")
2424+ cnpf.IsValid("12.345.678 9012-34")
2525+ cnpf.IsValid("ABC.DEF.GHI-JK")
2626+ cnpf.IsValid("AB.CDE.FGH/IJKL-MN")
2727+ cnpf.IsValid("123")
2828+2929+ // these returns 11111111111 and 11111111111111
3030+ cnpf.Unmask("111.111.111-11")
3131+ cnpf.Unmask("11.111.111/1111-11")
3232+3333+ // this returns 111.111.111-11 and 11.111.111/1111-11
3434+ cnpf.Mask("11111111111")
3535+ cnpf.Mask("11111111111111")
3636+3737+}
3838+```
3939+4040+Based on [Go CPF](https://github.com/cuducos/go-cpf) and [Go CPNJ](https://github.com/cuducos/go-cnpj) ❤️
+28
cnpf.go
···11+package cnpf
22+33+import (
44+ cpf "github.com/cuducos/go-cpf"
55+ cnpj "github.com/cuducos/go-cnpj"
66+)
77+88+//Unmask removes any non-digit (numeric) from a CPF or CNPJ number
99+func Unmask(n string) string {
1010+ return cpf.Unmask(n)
1111+}
1212+1313+//Mask returns the CPF or CNPJ number formatted
1414+func Mask(n string) string {
1515+ u := Unmask(n)
1616+ if len(u) == 11 {
1717+ return cpf.Mask(u)
1818+ }
1919+ if len(u) == 14 {
2020+ return cnpj.Mask(u)
2121+ }
2222+ return n
2323+}
2424+2525+//IsValid checks whether a number is a valid CPF or CNPJ number
2626+func IsValid(n string) bool {
2727+ return cpf.IsValid(n) || cnpj.IsValid(n)
2828+}