Skip to content

younisshah/sting

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sting

A Golang string manipulation library. Inspired by https://github.com/dleitee/strman


Install

Get sting

go get github.com/younisshah/sting

Available Functions (so far)

Append - Appends strings to a single string

Append("f", "o", "o") // => "foo"

AppendArray - Append an slice to the string

AppendArray("f", []string{"o", "o", "b", "a", "r"}) // => "foobar"

At - Gets the string at index value

At("foobar", 1) // => "o"

Chars - Gets the string as a character array

Chars("foobar") // => ["f", "o", "o", "b", "a", "r"]

CollapseWhiteSpace - Removes all the whitespaces between string fields

Chars("foo      bar") // => "foo bar"

ContainsAll - Checks whether the haystack contains all the needles with inline whitespaces taken care of.

ContainsAll("foo     bar baz", []string{"foo", "baz", "bar"}) // => true

EndsWith - Case-insensitive HasSuffix

EndsWith("foo bar", "BAR") // => true

Base64Encode - Encodes string with MIME base64 according to RFC 4648

Base64Encode("sting") // => "c3Rpbmc="

Base64Decode - Decodes string with MIME base64 according to RFC 4648

Base64Decode("c3Rpbmc=") // => "sting"

First - Returns the first n chars of the give string

First("foobar", 3) // => "foo"

Head - Returns the first character of a string

Head("foobar") // => "f"

Insert - Insert a 'string' at 'index' into the given 'string'

NOTE: indexing/counting starts at 0

Insert("foobarqooz", "baz", 5) // => "foobarbazqooz"

LeftPad - Returns a new string of a given length left-padded with the given symbol

LeftPad("1", "0", 5) // => "00001"

RightPad - Returns a new string of a given length right-padded with the given symbol

RightPad("1", "0", 5) // => "10000"

Reverse - Reverses a given string 'gnits' => 'sting'

Reverse("gnits") // => "sting"

CamelCase - Returns the string as "camelCase'd"

CamelCase("CamelCase") // => "camelCase"

KebabCase - Returns the string as "kebab-case'd"

KebabCase("kebab Case") // => "kebab-case"

SnakeCase - Returns the string as "snake_case'd"

SnakeCase("snake Case") // => "snake_case"

Transliterate - Removes all invalid characters. ā => a, ب => b, etc

Transliterate("stἵnĝ") // => "sting"

More functions to come 👷

About

A Golang string manipulation library. Inspired by https://github.com/dleitee/strman

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages