modulepackage
0.0.0-20240904191632-aff6f3be89ad
Repository: https://github.com/go-mods/initials.git
Documentation: pkg.go.dev
# README
Generate initials from names
Initials is a Go package that generates initials from names.
Installation
go get github.com/go-mods/initials
Usage
package main
import (
"fmt"
"github.com/go-mods/initials"
)
func main() {
fmt.Println(initials.GetInitials("John Doe")) // Output: JD
fmt.Println(initials.GetInitials("John Doe", WithLength(3), WithCamelCase())) // Output: JDo
fmt.Println(initials.GetInitials("John")) // Output: JO
fmt.Println(initials.GetInitials("John"), WithCamelCase()) // Output: Jo
}
Options
WithLength (Default: 2)
Defines the length of the initials
initials.GetInitials("John Doe", WithLength(3)) // Output: JDO
WithWordLength
Defines the length of the initials to the number of words
initials.GetInitials("John David Dugga", WithWordLength()) // Output: JDD
WithSeparator (default: "")
Set the separator between the initials.
initials.GetInitials("John Doe", WithSeparator(".")) // Output: J.D
WithSensitive (default: false)
If set to true, the initials will be generated with the case of the words.
initials.GetInitials("John doe", WithSensitive()) // Output: Jd
WithLowercase (default: false)
If set to true, the initials will be generated in lowercase.
initials.GetInitials("John Doe", WithLowercase()) // Output: jd
WithUpperCase (default: true)
If set to true, the initials will be generated in uppercase.
initials.GetInitials("John Doe", WithUpperCase()) // Output: JD
WithCamelCase (default: false)
If set to true, the initials will be generated in camel case.
initials.GetInitials("John Doe", WithLength(3), WithCamelCase()) // Output: JDo
# Functions
GetInitials returns the initials of a name.
WithCamelCase sets the initials to be camel case.
WithLength sets the maximum length of the initials.
WithLowercase sets the initials to be lowercase.
WithSensitive sets the initials to be case-sensitive.
WithSeparator sets the separator to use between the initials.
WithUppercase sets the initials to be uppercase.
WithWordLength sets the length to the number of words.
# Type aliases
Option is a function to set the generatorOptions for the initials generator.