strman

package module
v0.0.0-...-dcc171c Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2020 License: MIT Imports: 11 Imported by: 0

README

Strman library

A Go string manipulation library. By Rajkumar Palani

License

A Go library for working with Strings. You can learn about all the String utility functions implemented in strman library by reading the documentation.

Installation

go get github.com/rajkumarpal07/strman

Package import

import (
  "github.com/rajkumarpal07/strman"
)

Documentation

Supported Methods
  1. Appends - Appends strings to another string.
  2. AppendsArray - Appends an array of String to a string.
  3. At - Get the character at index.
  4. Base64Decode - Decodes data encoded with MIME base64.
  5. Base64Encode - Encodes data with MIME base64.
  6. Between - Returns an array with strings between start and end.
  7. Capitalize - Converts the first character of string to upper case and the remaining to lower case.
  8. Chars - Returns a String array consisting of the characters in the String.
  9. CharsCount - Counts the number of occurrences of each character in the string.
  10. CollapseWhitespace - Replace consecutive whitespace characters with a single space.
  11. Contains - Verifies that the needle is contained in the value. Case sensitive.
  12. ContainsAll - Verifies that all needles are contained in value. Case insensitive.
  13. ContainsAllCaseSensitive - Verifies that all needles are contained in value. Case sensitive.
  14. ContainsAny - Verifies that one or more of needles are contained in value. Case insensitive.
  15. ContainsAnyCaseSensitive - Verifies that one or more of needles are contained in value.
  16. CountSubstr - Count the number of times substr appears in value. Case Sensitive.
  17. CountSubstring - Count the number of times substr appears in value.
  18. CountsSubstr - Counts the number of times substr appears in value. Allows overlapping.
  19. Dasherize - Converts a underscored or camelized string into an dasherized one.
  20. DecEncode - Convert string chars to decimal unicode (16 digits).
  21. EndsWith - Tests if value ends with search.
  22. EndsWithCase - Tests if value ends with search. Case sensitive.
  23. EnsureLeft - Ensures that the value begins with prefix. If it doesn't exist, it's prepended. Case sensitive.
  24. EnsureLeftWithCase - Ensures that the value begins with prefix. If it doesn't exist, it's prepended.
  25. EnsureRight - Ensures that the value ends with suffix. If it doesn't, it's appended. Case sensitive.
  26. EnsureRightWithCase - Ensures that the value ends with suffix. If it doesn't, it's appended. Case sensitive.
  27. First - Returns the first 3 chars of String(ASCII).
  28. FirstNChars - Returns the first n chars of String(ASCII).
  29. Format - Formats a string using parameters. Will be added in a future release.
  30. FormatNumber - Returns a string where groups of three digits are delimited by comma.
  31. HTMLDecode - Converts all HTML entities to applicable characters.
  32. HTMLEncode - Convert all applicable characters to HTML entities.
  33. Head - Return the first char of String(ASCII).
  34. HexDecode - Convert hexadecimal unicode (4 digits) string to string chars.
  35. HexEncode - Convert string chars to hexadecimal unicode (4 digits).
  36. Humanize - Converts an underscored, camelized, or dasherized string into a humanized one.
  37. IndexOf - Returns the index within the calling String of the first occurrence of the specified value.
  38. Insert - Inserts 'substring' into the 'value' at the 'index' provided.
  39. IsBlank - Checks if string is empty.
  40. IsEnclosedBetween - Verifies whether String is enclosed by same encloser.
  41. IsEnclosedBetweenTwo - Verifies whether String is enclosed by 2 different enclosers.
  42. IsLowerCase - Verifies if String is lowercase.
  43. IsString - Checks whether parameter is String.
  44. IsUpperCase - Verifies if String is uppercase.
  45. Join - concatenates all the elements of the strings array into a single String.
  46. Last - Returns the last n chars of String.
  47. LastIndexOf - returns the index within the calling String object of the last occurrence of the specified value.
  48. LastIndexOfWithCase - returns the index of the last occurrence of the specified value. Case sensitive.
  49. LeftPad - Returns a new string such that the beginning of the string is padded.
  50. LeftPad2Len - Returns a new string of a given length such that the beginning of the string is padded.
  51. LeftTrim - Removes all spaces on left.
  52. Length - Returns length of String. Delegates to len method.
  53. Lines - Split lines to an array.
  54. LowerFirst - Converts the first character of string to lower case.
  55. Prepend - Returns a new String starting with 'prepends' string.
  56. PrependArray - Returns a new String starting with 'prepends' string array.
  57. RemoveEmptyStrings - Remove empty Strings from string array.
  58. RemoveLeft - Returns a new String with the prefix removed, if present. Case sensitive.
  59. RemoveLeftWithCase - Returns a new String with the prefix removed, if present.
  60. RemoveNonWords - Remove all non word characters.
  61. RemoveRight - Returns a new string with the 'suffix' removed, if present. Case sensitive.
  62. RemoveRightWithCase - Returns a new string with the 'suffix' removed, if present.
  63. RemoveSpaces - Removes all spaces.
  64. Repeat - Returns a repeated string given a multiplier.
  65. Replace - Replace all occurrences of 'search' value to 'newvalue'.
  66. Reverse - Reverse the input String.
  67. RightPad - Returns a new string such that the ending of the string is padded.
  68. RightPad2Len - Returns a new string of a given length such that the ending of the string is padded.
  69. RightTrim - Removes all spaces on right.
  70. SafeTruncate - Truncate the string securely, not cutting a word in half.
  71. Shuffle - Returns a string with its characters in random order.
  72. Slice - A substring method.
  73. Slugify - Convert a String to a slug.
  74. Split - Alias to String split function.
  75. Surround - Surrounds a 'value' with the given 'prefix' and 'suffix'.
  76. SwapCase - Returns a copy of the string in which all the case-based characters have had their case swapped.
  77. Tail - Returns tail of the String.
  78. ToCamelCase - Transform to camelCase.
  79. ToDecamelize - Decamelize String.
  80. ToKebabCase - Transform to kebab-case.
  81. ToSnakeCase - Transform to snake_case.
  82. ToStudlyCase - Transform to StudlyCaps.
  83. Transliterate - Remove all non valid characters.
  84. TrimEnd - Removes trailing chars from string.
  85. TrimEndSpaces - Removes trailing whitespace from string.
  86. TrimStart - Removes leading chars from string.
  87. TrimStartSpaces - Removes leading whitespace from string.
  88. Truncate - Truncates the unsecured form string, cutting the independent string of required position.
  89. UnEqual - Tests if two Strings are InEqual.
  90. Underscored - Changes passed in string to all lower case and adds underscore between words.
  91. UpperFirst - Converts the first character of string to upper case.
  92. Words - Splits a String to words.
  93. WordsDelimitedBy - Splits a String to words with a delimiter.
  94. Zip - Aggregates the contents of 2 strings arrays into a single list of tuples.

Inspiration

This library is inspired by dleitee/strman and shekhargulati/strman.

License

strman is licensed under the MIT License - see the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Hm = make(map[string][]string)

Hm is an Ascii map

View Source
var (
	// Version num of strman library
	Version = "1.0.0"
)

Functions

func Appends

func Appends(value string, strs ...string) string

Appends strs to value

func AppendsArray

func AppendsArray(value string, appends []string) string

AppendsArray an array of String to value

func At

func At(value string, index int) string

At :: Get the character at index. This method will take care of negative indexes. The valid value of index is between -(length-1) to (length-1). For values which don't fall under this range empty string will be returned.

func Base64Decode

func Base64Decode(value string) string

Base64Decode Decodes data encoded with MIME base64

func Base64Encode

func Base64Encode(value string) string

Base64Encode Encodes data with MIME base64.

func Between

func Between(value string, start string, end string) ([]string, error)

Between Returns an array with strings between start and end.

func Capitalize

func Capitalize(value string) string

Capitalize Converts the first character of string to upper case and the remaining to lower case.

func Chars

func Chars(value string) ([]string, error)

Chars Returns a String array consisting of the characters in the String.

func CharsCount

func CharsCount(invalue string) map[string]int

CharsCount Counts the number of occurrences of each character in the string

func CollapseWhitespace

func CollapseWhitespace(value string) string

CollapseWhitespace Replace consecutive whitespace characters with a single space.

func Contains

func Contains(value string, needle string, caseSensitive bool) bool

Contains Verifies that the needle is contained in the value. The search is case sensitive

func ContainsAll

func ContainsAll(value string, needles []string) bool

ContainsAll Verifies that all needles are contained in value. The search is case insensitive needs refactoring

func ContainsAllCaseSensitive

func ContainsAllCaseSensitive(value string, needles []string, caseSensitive bool) bool

ContainsAllCaseSensitive Verifies that all needles are contained in value. The search is case sensitive

func ContainsAny

func ContainsAny(value string, needles []string) bool

ContainsAny Verifies that one or more of needles are contained in value. This is case insensitive

func ContainsAnyCaseSensitive

func ContainsAnyCaseSensitive(value string, needles []string, caseSensitive bool) bool

ContainsAnyCaseSensitive Verifies that one or more of needles are contained in value.

func CountSubstr

func CountSubstr(value string, substr string) int

CountSubstr Count the number of times substr appears in value- Case Sensitive

func CountSubstring

func CountSubstring(value string, substr string, caseSensitive bool, allowOverlapping bool) int

CountSubstring Count the number of times substr appears in value

func CountsSubstr

func CountsSubstr(value string, substr string, allowOverlapping bool, count int) int

CountsSubstr Counts the number of times substr appears in value

func Dasherize

func Dasherize(input string) string

Dasherize Converts a underscored or camelized string into an dasherized one.

func DecEncode

func DecEncode(value string) string

DecEncode Convert string chars to decimal unicode (16 digits)

func EndsWith

func EndsWith(value string, search string) bool

EndsWith Test if value ends with search. The search is case sensitive.

func EndsWithCase

func EndsWithCase(value string, search string, caseSensitive bool) bool

EndsWithCase Test if value ends with search. The search is case sensitive.

func EnsureLeft

func EnsureLeft(value string, prefix string) string

EnsureLeft Ensures that the value begins with prefix. If it doesn't exist, it's prepended. It is case sensitive.

func EnsureLeftWithCase

func EnsureLeftWithCase(value string, prefix string, caseSensitive bool) string

EnsureLeftWithCase Ensures that the value begins with prefix. If it doesn't exist, it's prepended.

func EnsureRight

func EnsureRight(value string, suffix string) string

EnsureRight Ensures that the value ends with suffix. If it doesn't, it's appended. This operation is case sensitive.

func EnsureRightWithCase

func EnsureRightWithCase(value string, suffix string, caseSensitive bool) string

EnsureRightWithCase Ensures that the value ends with suffix. If it doesn't, it's appended. This operation is case sensitive.

func First

func First(value string) string

First Returns the first 3 chars of String(ASCII)

func FirstNChars

func FirstNChars(value string, n int) string

FirstNChars Returns the first n chars of String(ASCII)

func Format

func Format(value string, params ...string) string

Format Formats a string using parameters

func FormatNumber

func FormatNumber(number int64) string

FormatNumber Returns a string representation of the number passed in where groups of three digits are delimited by comma

func HTMLDecode

func HTMLDecode(encodedHTML string) string

HTMLDecode Converts all HTML entities to applicable characters. UnescapeString unescapes entities like "&lt;" to become "<". &aacute; unescapes to "á"

func HTMLEncode

func HTMLEncode(plainHTML string) string

HTMLEncode Convert all applicable characters to HTML entities. EscapeString escapes special characters like "<" to become "&lt;" NOTE:: "á" doesnt return currently "&aacute;" but returns "á"

func Head(value string) string

Head Return the first char of String(ASCII)

func HexDecode

func HexDecode(value string) string

HexDecode Convert hexadecimal unicode (4 digits) string to string chars

func HexEncode

func HexEncode(value string) string

HexEncode Convert string chars to hexadecimal unicode (4 digits)

func Humanize

func Humanize(input string) string

Humanize Converts an underscored, camelized, or dasherized string into a humanized one. Also removes beginning and ending whitespace.

func IndexOf

func IndexOf(value string, needle string, caseSensitive bool) int

IndexOf The indexOf() method returns the index within the calling String of the first occurrence of the specified value, starting the search at fromIndex. Returns -1 if the value is not found.

func Insert

func Insert(value string, substring string, index int) string

Insert Inserts 'substring' into the 'value' at the 'index' provided.

func IsBlank

func IsBlank(value string) bool

IsBlank Checks if string is empty.

func IsEnclosedBetween

func IsEnclosedBetween(value string, encloser string) bool

IsEnclosedBetween Verifies whether String is enclosed by same encloser

func IsEnclosedBetweenTwo

func IsEnclosedBetweenTwo(value string, leftEncloser string, rightEncloser string) bool

IsEnclosedBetweenTwo Verifies whether String is enclosed by 2 different enclosers

func IsLowerCase

func IsLowerCase(value string) bool

IsLowerCase Verifies if String is lowercase

func IsString

func IsString(value interface{}) bool

IsString Checks whether parameter is String

func IsUpperCase

func IsUpperCase(value string) bool

IsUpperCase Verifies if String is uppercase

func Join

func Join(strarr []string, separator string) string

Join concatenates all the elements of the strings array into a single String. The separator string is placed between elements in the resulting string.

func Last

func Last(value string, n int) string

Last Return the last n chars of String

func LastIndexOf

func LastIndexOf(value string, needle string) int

LastIndexOf returns the index within the calling String object of the last occurrence of the specified value Returns -1 if the value is not found. The search starts from the end and case sensitive.

func LastIndexOfWithCase

func LastIndexOfWithCase(value string, needle string, caseSensitive bool) int

LastIndexOfWithCase returns the index within the calling String object of the last occurrence of the specified value Returns -1 if the value is not found. The search starts from the end and case sensitive.

func LeftPad

func LeftPad(value string, padStr string, pLen int) string

LeftPad Returns a new string of a given length such that the beginning of the string is padded.

func LeftPad2Len

func LeftPad2Len(value string, padStr string, overallLen int) string

LeftPad2Len Left pad a string with padStr If the overallLen is shorter than the original string length the string will be shortened to this length (substr)

func LeftTrim

func LeftTrim(value string) string

LeftTrim Removes all spaces on left

func Length

func Length(value string) int

Length Returns length of String. Delegates to len method.

func Lines

func Lines(input string) []string

Lines Split lines to an array

func LoadMapArrays

func LoadMapArrays()

LoadMapArrays .....

func LowerFirst

func LowerFirst(value string) string

LowerFirst Converts the first character of string to lower case.//

func Prepend

func Prepend(value string, prepends ...string) string

Prepend Return a new String starting with prepends

func PrependArray

func PrependArray(value string, prepends []string) string

PrependArray Return a new String starting with prepends

func RemoveEmptyStrings

func RemoveEmptyStrings(stringsArr []string) ([]string, error)

RemoveEmptyStrings Remove empty Strings from string array

func RemoveLeft

func RemoveLeft(value string, prefix string) string

RemoveLeft Returns a new String with the prefix removed, if present. This is case sensitive.

func RemoveLeftWithCase

func RemoveLeftWithCase(value string, prefix string, caseSensitive bool) string

RemoveLeftWithCase Returns a new String with the prefix removed, if present.

func RemoveNonWords

func RemoveNonWords(value string) string

RemoveNonWords Remove all non word characters. ACCENTED CHARS are removed including whitespace

func RemoveRight

func RemoveRight(value string, suffix string) string

RemoveRight Returns a new string with the 'suffix' removed, if present. Search is case sensitive.

func RemoveRightWithCase

func RemoveRightWithCase(value string, suffix string, caseSensitive bool) string

RemoveRightWithCase Returns a new string with the 'suffix' removed, if present.

func RemoveSpaces

func RemoveSpaces(value string) string

RemoveSpaces Removes all spaces

func Repeat

func Repeat(value string, multiplier int) string

Repeat Returns a repeated string given a multiplier.

func Replace

func Replace(value string, search string, newValue string, caseSensitive bool) string

Replace Replace all occurrences of 'search' value to 'newvalue'. Uses ReplaceAllString method.

func Reverse

func Reverse(value string) string

Reverse Reverse the input String

func RightPad

func RightPad(value string, pad string, length int) string

RightPad Returns a new string of a given length such that the ending of the string is padded.

func RightPad2Len

func RightPad2Len(value string, padStr string, overallLen int) string

RightPad2Len Right pad a string with padStr If the overallLen is shorter than the original string length the string will be shortened to this length (substr)

func RightTrim

func RightTrim(value string) string

RightTrim Remove all spaces on right.

func SafeTruncate

func SafeTruncate(value string, length int, filler string) string

SafeTruncate Truncate the string securely, not cutting a word in half. It always returns the last full word.

func Shuffle

func Shuffle(value string) string

Shuffle It returns a string with its characters in random order.

func Slice

func Slice(value string, begin int, end int) string

Slice A substring method

func Slugify

func Slugify(value string) string

Slugify Convert a String to a slug

func Split

func Split(value string, delimiterregex string) []string

Split Alias for String split function. Defined only for completeness.

func Surround

func Surround(value string, prefix string, suffix string) string

Surround Surrounds a 'value' with the given 'prefix' and 'suffix'.

func SwapCase

func SwapCase(input string) string

SwapCase Returns a copy of the string in which all the case-based characters have had their case swapped.

func Tail

func Tail(value string) string

Tail Return tail of the String

func ToCamelCase

func ToCamelCase(value string) string

ToCamelCase Transform to camelCase

func ToDecamelize

func ToDecamelize(value string, chr string) string

ToDecamelize Decamelize String

func ToKebabCase

func ToKebabCase(value string) string

ToKebabCase Transform to kebab-case.

func ToSnakeCase

func ToSnakeCase(value string) string

ToSnakeCase Transform to snake_case.

func ToStudlyCase

func ToStudlyCase(value string) string

ToStudlyCase Transform to StudlyCaps.

func Transliterate

func Transliterate(value string) string

Transliterate Remove all non valid characters.

func TrimEnd

func TrimEnd(value string, chars string) string

TrimEnd Removes trailing chars from string.

func TrimEndSpaces

func TrimEndSpaces(value string) string

TrimEndSpaces Removes trailing whitespace from string.

func TrimStart

func TrimStart(value string, chars string) string

TrimStart Removes leading chars from string.

func TrimStartSpaces

func TrimStartSpaces(value string) string

TrimStartSpaces Removes leading whitespace from string.

func Truncate

func Truncate(value string, length int, filler string) string

Truncate Truncates the unsecured form string, cutting the independent string of required position.

func UnEqual

func UnEqual(first string, second string) bool

UnEqual Tests if two Strings are InEqual

func Underscored

func Underscored(value string) string

Underscored Changes passed in string to all lower case and adds underscore between words.

func UpperFirst

func UpperFirst(value string) string

UpperFirst Converts the first character of string to upper case.

func Words

func Words(value string) []string

Words Splits a String to words

func WordsDelimitedBy

func WordsDelimitedBy(value string, delimiter string) []string

WordsDelimitedBy Splits a String to words

Types

type StrTuple

type StrTuple struct {
	// contains filtered or unexported fields
}

StrTuple is a string tuple for use in the Zip function.

func Zip

func Zip(a, b []string) ([]StrTuple, error)

Zip Aggregates the contents of 2 strings arrays into a single list of tuples.

Jump to

Keyboard shortcuts

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