utils

package
v0.0.0-...-8b058bf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 17, 2022 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains(s []string, str string) bool

Checks if a string is present in a slice of strings

func Find

func Find(source []string, match string) (matches []string)

Returns all matches for a string from a slice of strings

func FindIndex

func FindIndex(source []string, match string) (index int)

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

func RemoveIndex[T any](slice []T, index int) (returnSlice []T)

Returns the input slice without the entry at the specified index.

func ValidFileName

func ValidFileName(name string) string

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()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL