Documentation ¶
Overview ¶
Package strings implements helper functions for working with strings
Index ¶
- func IsAffirmative(s string) bool
- func MaskLeft(mask rune, keep int, text string) string
- func MaskRight(mask rune, keep int, text string) string
- func StripHTMLTags(s string) string
- func ToValidUTF8Trimmed(s string) string
- func TruncateLeft(text string, length int, ellipsis string) string
- func TruncateRight(text string, length int, ellipsis string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsAffirmative ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.