strings

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: BSD-2-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package strings implements helper functions for working with strings

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAffirmative

func IsAffirmative(s string) bool

IsAffirmative returns true if the string represents a true-ish value. This function is case insensitive.

Inspired by https://github.com/jonschlinkert/is-affirmative and https://github.com/jonschlinkert/affirmative

These are the current affirmative words:

'absolutely',
'affirmative',
'all right',
'amen',
'aye',
'beyond a doubt',
'by all means',
'certainly',
'definitely',
'even so',
'exactly',
'fine',
'gladly',
'good enough',
'good',
'granted',
'i accept',
'i concur',
'i guess',
'if you must',
'indubitably',
'just so',
'most assuredly',
'naturally',
'of course',
'ok',
'okay',
'positively',
'precisely',
'right on',
'righto',
'sure thing',
'sure',
'surely',
'true',
'undoubtedly',
'unquestionably',
'very well',
'whatever',
'willingly',
'without fail',
'y',
'ya',
'yea',
'yeah',
'yep',
'yes',
'yessir',
'yup'

func MaskLeft

func MaskLeft(mask rune, keep int, text string) string

MaskLeft masks a sensitive string, such as an API Key, so that it can be safely logged all of the data will be masked with the provided rune (mask) except the last (keep) runes

Keep is the number of runes to keep. If keep is zero or less than, all of the text is masked

This function operates on runes to remain Unicode safe

NOTE: len([]rune{}) is safe, otherwise use utf8.RuneCountInString(string) as equivalent for strings

func MaskRight

func MaskRight(mask rune, keep int, text string) string

MaskRight masks a sensitive string, such as an API Key, so that it can be safely logged all of the data will be masked with the provided rune (mask) except the first (keep) runes

Keep is the number of runes to keep. If keep is zero or less than, all of the text is masked

This function operates on runes to remain Unicode safe

NOTE: len([]rune{}) is safe, otherwise use utf8.RuneCountInString(string) as equivalent for strings

func StripHTMLTags

func StripHTMLTags(s string) string

StripHTMLTags will strip HTML tags from a string input and return the stripped output Content between certain tags, like script and style tags, are also remove Certain characters are converted to HTML entities, such as > becoming >

Recommendation: use "github.com/microcosm-cc/bluemonday" if you want greater control

This is pure

func ToValidUTF8Trimmed

func ToValidUTF8Trimmed(s string) string

ToValidUTF8Trimmed removes each run of invalid UTF-8 byte sequences from the string s, with all leading and trailing white space removed, as defined by Unicode.

func TruncateLeft

func TruncateLeft(text string, length int, ellipsis string) string

TruncateLeft will truncate a string, keeping the string starting from the end, and return a new string that is exactly the "length" provided, with the beginning part of the string that was replaced now being the provided "ellipsis". If "length" is greater than or equal to the length of "text" (in runes), then "text" is returned as is.

This function operates on runes to remain Unicode safe.

func TruncateRight

func TruncateRight(text string, length int, ellipsis string) string

TruncateRight will truncate a string, keeping the string starting from the beginning, and return a new string that is exactly the "length" of runes provided, with the final part of the string that was replaced now being the provided "ellipsis". If "length" is greater than or equal to the length of "text" (in runes), then "text" is returned as is. If "length" is less than or equal to the length of "ellipsis", then only "length" runes of "ellipsis" is returned.

This function operates on runes to remain Unicode safe.

Types

This section is empty.

Jump to

Keyboard shortcuts

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