Documentation
¶
Index ¶
- Constants
- Variables
- func AsF(str string) (float64, bool)
- func AsI(str string) (int64, bool)
- func AsU(str string) (uint, bool)
- func BT(str string) string
- func CamelCase(s string) string
- func CharAt(str string, index int) string
- func CheckPassword(hash string, rawPassword string) error
- func Coalesce(strs ...string) string
- func ConcatIfNotEmpty(str, sep string) string
- func Contains(str, substr string) bool
- func Count(str, substr string) int
- func DecodeCB63[T int64orUint64](str string) (T, bool)
- func DecryptAES(encryptedStr, key string, out any) bool
- func DelLeft(str string, n int) string
- func DelRight(str string, n int) string
- func EncodeCB63[T int64orUint64, L constraints.Integer](id T, minLen L) string
- func EncryptAES(in any, key string) (encryptedStr string)
- func EncryptPassword(s string) string
- func EndsWith(str, suffix string) bool
- func Equals(strFirst, strSecond string) bool
- func EqualsIgnoreCase(strFirst, strSecond string) bool
- func FirstIsLower(s string) bool
- func HashPassword(pass string) string
- func If(b bool, yes string) string
- func IfElse(b bool, yes, no string) string
- func IfEmpty(str1, str2 string) string
- func IndexOf(str, sub string) int
- func JsonAsArr(str string) (res []any, ok bool)
- func JsonAsFloatArr(str string) (res []float64, ok bool)
- func JsonAsIntArr(str string) (res []int64, ok bool)
- func JsonAsMap(str string) (res map[string]any, ok bool)
- func JsonAsStrArr(str string) (res []string, ok bool)
- func JsonToArr(str string) (res []any)
- func JsonToIntArr(str string) (res []int64)
- func JsonToMap(str string) (res map[string]any)
- func JsonToObjArr(str string) (res []map[string]any)
- func JsonToStrArr(str string) (res []string)
- func JsonToStrStrMap(str string) (res map[string]string)
- func LastIndexOf(str, sub string) int
- func Left(str string, n int) string
- func LeftN(str string, n int) string
- func LeftOf(str, substr string) string
- func LeftOfLast(str, substr string) string
- func LowerFirst(s string) string
- func MergeMailContactEmails(each_name, str_emails string) []string
- func Mid(str string, left int, length int) string
- func MsgpAsArr(str []byte) (res []any, ok bool)
- func MsgpAsFloatArr(str []byte) (res []float64, ok bool)
- func MsgpAsIntArr(str []byte) (res []int64, ok bool)
- func MsgpAsMap(str []byte) (res map[string]any, ok bool)
- func MsgpAsStrArr(str []byte) (res []string, ok bool)
- func MsgpToArr(str []byte) (res []any)
- func MsgpToIntArr(str []byte) (res []int64)
- func MsgpToMap(str []byte) (res map[string]any)
- func MsgpToObjArr(str []byte) (res []map[string]any)
- func MsgpToStrArr(str []byte) (res []string)
- func MsgpToStrStrMap(str []byte) (res map[string]string)
- func PadLeft(s string, padStr string, lenStr int) string
- func PadRight(s string, padStr string, lenStr int) string
- func PascalCase(s string) string
- func Q(str string) string
- func QQ(str string) string
- func RandomCB63[T constraints.Integer](len T) string
- func RandomPassword(strlen int64) string
- func RemoveCharAt(str string, index int) string
- func RemoveLastN(str string, n int) string
- func Repeat(str string, count int) string
- func Replace(haystack, needle, gold string) string
- func Right(str string, n int) string
- func RightOf(str, substr string) string
- func RightOfLast(str, substr string) string
- func SnakeCase(s string) string
- func Split(str, sep string) []string
- func SplitFunc(str string, fun func(rune) bool) []string
- func SplitN(str string, n int) []string
- func StartsWith(str, prefix string) bool
- func ToF(str string) float64
- func ToI(str string) int64
- func ToInt(str string) int
- func ToLower(str string) string
- func ToTitle(str string) string
- func ToU(str string) uint64
- func ToUpper(str string) string
- func Trim(str string) string
- func TrimChars(str, chars string) string
- func UZ(str string) string
- func UZRAW(str string) string
- func UpperFirst(s string) string
- func ValidateEmail(str string) string
- func ValidateFilename(str string) string
- func ValidateIdent(str string) string
- func ValidateMailContact(str string) string
- func ValidatePhone(str string) string
- func XSS(str string) string
- func XXH3(s string) uint64
- func Z(str string) string
- func ZB(b bool) string
- func ZI(num int64) string
- func ZJ(str string) string
- func ZJJ(str string) string
- func ZJLIKE(str string) string
- func ZLIKE(str string) string
- func ZS(str string) string
- func ZT(strs ...string) string
- func ZT2() string
- func ZU(num uint64) string
- func ZZ(str string) string
Constants ¶
const MaxStrLenCB63 = 11
const WebBR = "\n<br/>"
Variables ¶
var ModCB63 []uint64
Functions ¶
func AsF ¶
AsF convert to float64 with check
S.AsF(`1234.5`) // 1234.5, true S.AsF(`1abc`) // 0.0, false
func BT ¶
BT add backtick quote in the beginning and the end of string, without escaping.
S.Q(`coba`) // "`coba`" S.Q(`123`) // "`123`"
func CharAt ¶
CharAt get character at specific index, utf-8 safe
S.CharAt(`Halo 世界`, 5) // `世` // utf-8 example, if characters not shown, it's probably your font/editor/plugin S.CharAt(`Halo`, 3) // `o`
func CheckPassword ¶
CheckPassword check encrypted password
func Coalesce ¶
Coalesce coalesce, return first non-empty string
S.Coalesce(`1`,`2`) // `1` S.Coalesce(``,`2`) // `2` S.Coalesce(``,``,`3`) // `3`
func ConcatIfNotEmpty ¶
ConcatIfNotEmpty concat if not empty with additional separator
func Contains ¶
Contains check whether the input string (first arg) contains a certain sub string (second arg) or not.
S.Contains(`komputer`,`om`)) // bool(true) S.Contains(`komputer`,`opu`)) // bool(false)
func Count ¶
Count count how many specific character (first arg) that the string (second arg) contains
S.Count(`komputeer`,`e`))// output int(2)
func DecodeCB63 ¶
DecodeCB63 convert custom base-63 encoding to int64
S.DecodeCB63(`--0`) // 1, true S.DecodeCB64(`(*&#$`) // 0, false
func DecryptAES ¶
func DelLeft ¶
DelLeft return remainder after N first characters removed, return empty if N more than len, not unicode-safe
func DelRight ¶
DelRight return remainder after N last characters deleted, return empty if N more than len, not unicode-safe
func EncodeCB63 ¶
func EncodeCB63[T int64orUint64, L constraints.Integer](id T, minLen L) string
EncodeCB63 convert integer to custom base-63 encoding that lexicographically correct, positive integer only
0 - 1..10 0..9 11..36 A..Z 37 _ 38..63 a..z S.EncodeCB63(11,1) // `A` S.EncodeCB63(1,3) // `--0`
func EncryptAES ¶
func EncryptPassword ¶
EncryptPassword hash password (with salt)
func EndsWith ¶
EndsWith check whether the input string (first arg) ends with a certain character (second arg) or not.
S.EndsWith(`adakah`,`ah`)) // bool(true) S.EndsWith(`adakah`,`aka`)) // bool(false)
func Equals ¶
Equals compare two input string (first arg) equal with another input string (second arg).
S.Equals(`komputer`,`komputer`)) // bool(true) S.Equals(`komputer`,`Komputer`)) // bool(false)
func EqualsIgnoreCase ¶
EqualsIgnoreCase compare two input string (first arg) equal with ignoring case another input string (second arg).
S.EqualsIgnoreCase(`komputer`,`komputer`)) // bool(true) S.EqualsIgnoreCase(`komputer`,`Komputer`)) // bool(true)
func FirstIsLower ¶
FirstIsLower check first character is lowercase
func HashPassword ¶
HashPassword hash password with sha256 (without salt)
func If ¶
If simplified ternary operator (bool ? val : 0), returns second argument, if the condition (first arg) is true, returns empty string if not
S.If(true,`a`) // `a` S.If(false,`a`) // ``
func IfElse ¶
IfElse ternary operator (bool ? val1 : val2), returns second argument if the condition (first arg) is true, third argument if not
S.IfElse(true,`a`,`b`) // `a` S.IfElse(false,`a`,`b`) // `b`
func IfEmpty ¶
IfEmpty coalesce, return first non-empty string
S.IfEmpty(``,`2`) // `2` S.IfEmpty(`1`,`2`) // `1`
func JsonAsArr ¶
JsonAsArr convert JSON object to []any with check
jsonStr := `[1,2,['test'],'a']` arr, ok := S.JsonAsArr(jsonStr)
func JsonAsFloatArr ¶
JsonAsFloatArr convert JSON object to []float64 with check
jsonStr := `[1,2,3]` arr, ok := S.JsonAsFloatArr(jsonStr)
func JsonAsIntArr ¶
JsonAsIntArr convert JSON object to []int64 with check
jsonStr := `[1,2,3]` arr, ok := S.JsonAsIntArr(jsonStr)
func JsonAsMap ¶
JsonAsMap convert JSON object to map[string]any with check
jsonStr := `{"test":123,"bla":[1,2,3,4]}` map1, ok := S.JsonAsMap(jsonStr)
func JsonAsStrArr ¶
JsonAsStrArr convert JSON object to []string with check
jsonStr := `["a","b","c"]` arr, ok := S.JsonAsStrArr(jsonStr)
func JsonToArr ¶
JsonToArr convert JSON object to []any, silently print and return empty slice of interface if failed
jsonStr := `[1,2,['test'],'a']` arr := S.JsonToArr(jsonStr)
func JsonToIntArr ¶
JsonToIntArr convert JSON object to []int64, silently print and return empty slice of interface if failed
jsonStr := `[1,2,['test'],'a']` arr := S.JsonToArr(jsonStr)
func JsonToMap ¶
JsonToMap convert JSON object to map[string]any, silently print and return empty map if failed
jsonStr := `{"test":123,"bla":[1,2,3,4]}` map1 := S.JsonToMap(jsonStr)
func JsonToObjArr ¶
JsonToObjArr convert JSON object to []map[string]any, silently print and return empty slice of interface if failed
jsonStr := `[{"x":"foo"},{"y":"bar"}]` arr := S.JsonToObjArr(jsonStr)
func JsonToStrArr ¶
JsonToStrArr convert JSON object to []string, silently print and return empty slice of interface if failed
jsonStr := `["123","456",789]` arr := S.JsonToStrArr(jsonStr)
func JsonToStrStrMap ¶
JsonToStrStrMap convert JSON object to map[string]string, silently print and return empty map if failed
jsonStr := `{"test":123,"bla":[1,2,3,4]}` map1 := S.JsonToMap(jsonStr)
func LeftOfLast ¶
LeftOfLast substring before last `substr`
func MergeMailContactEmails ¶
MergeMailContactEmails return formatted array of mail contact <usr@email>
func MsgpAsArr ¶
MsgpAsArr convert Msgpack object to []any with check
arr, ok := S.MsgpAsArr(msgpStr)
func MsgpAsFloatArr ¶
MsgpAsFloatArr convert Msgpack object to []float64 with check
arr, ok := S.MsgpAsFloatArr(msgpStr)
func MsgpAsIntArr ¶
MsgpAsIntArr convert Msgpack object to []int64 with check
arr, ok := S.MsgpAsIntArr(msgpStr)
func MsgpAsMap ¶
MsgpAsMap convert Msgpack object to map[string]any with check
map1, ok := S.MsgpAsMap(msgpStr)
func MsgpAsStrArr ¶
MsgpAsStrArr convert Msgpack object to []string with check
arr, ok := S.MsgpAsStrArr(msgpStr)
func MsgpToArr ¶
MsgpToArr convert Msgpack object to []any, silently print and return empty slice of interface if failed
arr := S.MsgpToArr(msgpStr)
func MsgpToIntArr ¶
MsgpToIntArr convert Msgpack object to []int64, silently print and return empty slice of interface if failed
arr := S.MsgpToIntArr(msgpStr)
func MsgpToMap ¶
MsgpToMap convert MsgPack object to map[string]any, silently print and return empty map if failed
msgpStr := []byte(`��buah{�angka�dia`) map1 := S.MsgpToMap(msgpStr)
func MsgpToObjArr ¶
MsgpToObjArr convert Msgpack object to []map[string]any, silently print and return empty slice of interface if failed
arr := S.MsgpToObjArr(msgpStr)
func MsgpToStrArr ¶
MsgpToStrArr convert Msgpack object to []string, silently print and return empty slice of interface if failed
arr := S.MsgpToStrArr(msgpStr)
func MsgpToStrStrMap ¶
MsgpToStrStrMap convert Msgpack object to map[string]string, silently print and return empty map if failed
map1 := S.MsgpToStrStrMap(msgpStr)
func PascalCase ¶
PascalCase convert to PascalCase source: https://github.com/iancoleman/strcase
func Q ¶
Q add single quote in the beginning and the end of string, without escaping.
S.Q(`coba`) // `'coba'` S.Q(`123`) // `'123'`
func QQ ¶
QQ add double quote in the beginning and the end of string, without escaping.
S.Q(`coba`) // `"coba"` S.Q(`123`) // `"123"`
func RandomCB63 ¶
func RandomCB63[T constraints.Integer](len T) string
RandomCB63 random CB63 n-times, the result is n*MaxStrLenCB63 bytes
func RandomPassword ¶
RandomPassword create a random password
func RemoveCharAt ¶
RemoveCharAt remove character at specific index, utf-8 safe
S.RemoveCharAt(`Halo 世界`, 5) // `Halo 界` --> utf-8 example, if characters not shown, it's probably your font/editor/plugin S.RemoveCharAt(`Halo`, 3) // `Hal`
func RemoveLastN ¶
RemoveLastN remove last n character, not UTF-8 friendly
func Replace ¶
Replace replace all substring with another substring
S.Replace(`bisa`,`is`,`us`) // `busa`
func RightOfLast ¶
RightOfLast substring after last `substr`
func SnakeCase ¶
SnakeCase convert to snake case source: https://github.com/iancoleman/strcase
func Split ¶
Split split a string (first arg) by characters (second arg) into array of strings (output).
S.Split(`biiiissssa`,func(ch rune) bool { return ch == `i` }) // output []string{"b", "", "", "", "ssssa"}
func StartsWith ¶
StartsWith check whether the input string (first arg) starts with a certain character (second arg) or not.
S.StartsWith(`adakah`,`ad`) // bool(true) S.StartsWith(`adakah`,`bad`) // bool(false)
func ToF ¶
ToF convert string to float64, returns 0 and silently print error if not valid
S.ToF(`1234.5`) // 1234.5 S.ToF(`1a`) // 0.0
func ToI ¶
ToI convert string to int64, returns 0 and silently print error if not valid
S.ToI(`1234`) // 1234 S.ToI(`1a`) // 0
func ToInt ¶
ToInt convert string to int, returns 0 and silently print error if not valid
S.ToInt(`1234`) // 1234 S.ToInt(`1a`) // 0
func ToTitle ¶
ToTitle Change first letter for every word to uppercase
S.ToTitle(`Disa dasi`)) // output "Disa Dasi"
func ToU ¶
ToU convert string to uint64, returns 0 and silently print error if not valid
S.ToU(`1234`) // 1234 S.ToU(`1a`) // 0
func ValidateEmail ¶
ValidateEmail return empty string if str is not a valid email
func ValidateFilename ¶
ValidateFilename validate file name
func ValidateIdent ¶
ValidateIdent return valid identifier (a-zA-Z0-9_)
func ValidateMailContact ¶
ValidateMailContact return valid version of mail contact (part before <usr@email>)
func ValidatePhone ¶
ValidatePhone remove invalid characters of a phone number
func XXH3 ¶
XXH3 fastest 64-bit hash function https://github.com/jacobmarble/go-checksum-benchmark https://github.com/Cyan4973/xxHash
func ZJ ¶
ZJ single quote a json string
hai := `{'test':123,"bla":[1,2,3,4]}` S.ZJ(hai) // "{'test':123,\"bla\":[1,2,3,4]}"
func ZJJ ¶
ZJJ double quote a json string
hai := `{'test':123,"bla":[1,2,3,4]}` S.ZJJ(hai) // "{'test':123,\"bla\":[1,2,3,4]}"
func ZLIKE ¶
ZLIKE replace <, >, ', ", % and gives single quote and %
S.ZLIKE(`coba<`)) // output '%coba<%' S.ZLIKE(`"coba"`)) // output '%"coba"%'
func ZS ¶
ZS replace <, >, ', " and gives single quote (without trimming)
S.Z(`<>'"`) // `<>'"
Types ¶
This section is empty.