texttools

package module
v0.0.0-...-256c512 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2019 License: MIT Imports: 7 Imported by: 1

README

go-texttools

A collection of tools for manipulating texts in Go

Shorten tries to create the most sensible (to a human) shortened text.
If possible, it will try to cut at a non-word char.
It will strip newlines and carriage returns.

Shorten(str string, length int, appendStr string) (shorter string)

SpecialCharsToStandard replaces all kinds of non-ascii chars with transliterations.

SpecialCharsToStandard(str string) string

Slug will convert a string to a slug.
It will also do transliteration of non-ascii chars.

Slug(str string) string

UnCase takes a string in any "case" (kebab-case, snake_case, etc.) and creates a "normal" string.
E.g. my-slug-string -> "My slug string"

UnCase(str string) string

SnakeCase will convert a string to snake_case.

SnakeCase(str string) string

KebabCase will convert a string to kebab-case.

KebabCase(str string) string

CamelCase will convert a string to camelCase.

CamelCase(str string) string

PascalCase will convert a string to PascalCase.
This is the same as camelCase, but with the first letter capitalized.

PascalCase(str string) string

StringInSlice will check if a string is in a slice and return true if it is.

StringInSlice(searchStr string, strs []string) bool

HTMLToText converts HTML to standard text.

HTMLToText(html string) (text string)

TextSanitizer converts HTML to standard text, but also replaces some special chars and escapings.

SanitizeText(txt string) (newTxt string)

CP1258ToUTF8 converts a CP1258 byte array to a UTF-8 string.

CP1258ToUTF8(txt []byte) (utf8Txt string)

RandomString creates a secure pseudorandom string using the crypto rand package.

RandomString(n int) (str string)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CP1258ToUTF8

func CP1258ToUTF8(txt []byte) (utf8Txt string)

CP1258ToUTF8 converts a CP1258 byte array to a UTF-8 string.

func CamelCase

func CamelCase(str string) string

CamelCase will convert a string to camelCase

func HTMLToText

func HTMLToText(html string) (text string)

HTMLToText converts HTML to standard text.

func KebabCase

func KebabCase(str string) string

KebabCase will convert a string to kebab-case

func PascalCase

func PascalCase(str string) string

PascalCase will convert a string to PascalCase. This is the same as camelCase, but with the first letter capitalized.

func RandomString

func RandomString(n int) (str string)

RandomString creates a secure pseudorandom string using the crypto rand package.

func SanitizeText

func SanitizeText(txt string) (newTxt string)

TextSanitizer converts HTML to standard text, but also replaces some special chars and escapings.

func Shorten

func Shorten(str string, length int, appendStr string) (shorter string)

Shorten tries to create the most sensible (to a human) shortened text. If possible, it will try to cut at a non-word char. It will strip newlines and carriage returns.

func Slug

func Slug(str string) string

Slug will convert a string to a slug. It will also do transliteration of non-ascii chars.

func SnakeCase

func SnakeCase(str string) string

SnakeCase will convert a string to snake_case

func SpecialCharsToStandard

func SpecialCharsToStandard(str string) string

SpecialCharsToStandard replaces all kinds of non-ascii chars with transliterations.

func StringInSlice

func StringInSlice(searchStr string, strs []string) bool

StringInSlice will check if a string is in a slice and return true if it is.

func UnCase

func UnCase(str string) string

UnCase takes a string in any "case" (kebab-case, snake_case, etc.) and creates a "normal" string. E.g. my-slug-string -> "My slug string"

Types

This section is empty.

Jump to

Keyboard shortcuts

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