Skip to content

nikitaksv/strmask

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

strmask

Godoc Reference Coverage Status FOSSA Status

Easy mask for string

Install

go get github.com/nikitaksv/strmask

Usage

package main

import (
	"fmt"

	"github.com/nikitaksv/strmask"
)

func main() {
	// Ex. phone number
	maskedValue, _ := strmask.Apply("+0 (000) 000-00-00", "12345678900")
	fmt.Println(maskedValue) // out: +1 (234) 567-89-00

	// Ex. phone number with err
	maskedValue, err := strmask.Apply("+0 (000) 000-00-00", "12345")
	if err != nil {
		fmt.Println(err) // out: invalid value
	}
	fmt.Println(maskedValue) // but maskedValue out: +1 (234) 5

	// Ex. ID
	maskedValue, _ = strmask.Apply("####-####-####-####", "1234qwerasdfzxcv")
	fmt.Println(maskedValue) // out: 1234-qwer-asdf-zxcv

	// Ex. Passport
	maskedValue, _ = strmask.Apply("00 0000000", "123456789")
	fmt.Println(maskedValue) // out: 12 3456789
	
	// Ex. code
	maskedValue, _ = strmask.Apply("G-UUUUUU", "q1w2e3")
	fmt.Println(maskedValue) // out: G-Q1W2E3
}

Mask Symbols

Symbol Meaning
# Requires a unicode letter or digit at this position
0 Requires a digit at this position
L Requires a unicode letter (will be lower) or digit at this position
l Requires a unicode letter (will be lower) at this position
U Requires a unicode letter (will be upper) or digit at this position
u Requires a unicode letter (will be upper) at this position

License

FOSSA Status