Documentation ¶
Index ¶
- func Contains(s []string, str string) bool
- func Find(source []string, match string) (matches []string)
- func FindIndex(source []string, match string) (index int)
- func RemoveIndex[T any](slice []T, index int) (returnSlice []T)
- func ValidFileName(name string) string
- func ValidFileNameWithOptions(name string, options ValidFileNameOptions) (slugified string)
- type ValidFileNameOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FindIndex ¶
Looks in a slice of strings to see if any of them match; if so, returns the index of the match in the slice. If no members of the slice match, returns -1.
func RemoveIndex ¶
Returns the input slice without the entry at the specified index.
func ValidFileName ¶
Returns a valid utf-8 string, downcased and with special characters replaced or removed which might prevent the name from being a valid file name. It also replaces spaces with dashes.
func ValidFileNameWithOptions ¶
func ValidFileNameWithOptions(name string, options ValidFileNameOptions) (slugified string)
Returns a valid utf-8 string, processed with the specified options. Useful in particular for when you want to limit the length of the filename, localize symbol substitutions, or prevent the file name from being downcased.
Types ¶
type ValidFileNameOptions ¶
type ValidFileNameOptions struct { // Language sets the language to use for slug creation. If unknown or unspecified, defaults to "en" Language string // CustomSub stores custom substitution map CustomSub *map[string]string // CustomRuneSub stores custom rune substitution map CustomRuneSub *map[rune]string // MaxLength stores maximum slug length. // It's smart so it will cat slug after full word. // By default slugs aren't shortened. // If MaxLength is smaller than length of the first word, then returned // slug will contain only substring from the first word truncated // after MaxLength. MaxLength int // Lowercase defines if the resulting slug is transformed to lowercase. // Default is true. Lowercase bool // Persistant defines whether the options should be reset after use of not. // If Persistant is true, the options will not be reset. Persistant bool }
Defines the options that can be passed to ValidFileNameWithOptions()