GithubHelp home page GithubHelp logo

go-str's Introduction

Go String (goStr)

Introduction

goStr is a Go package that provides functions for string manipulation, you are free to use them in your own applications if you find them convenient.

Installation

To use goStr in your Go project, you can install it using the go get command:

go get github.com/bhaktibuana/go-str

Available Functions

Examples

After

After method returns everything after the given value in a string. The entire string will be returned if the value does not exist within the string.

/*
 * @param input string
 * @param substr string
 * @returns string
 */
func After(input, substr string) string
  • usage
import "github.com/bhaktibuana/go-str"

goStr.After("The quick brown fox jumps over the lazy dog", "brown")

// " fox jumps over the lazy dog"

AfterLast

AfterLast method returns everything after the last occurrence of the given value in a string. The entire string will be returned if the value does not exist within the string.

/*
 * @param input string
 * @param substr string
 * @returns string
 */
func AfterLast(input, substr string) string
  • usage
import "github.com/bhaktibuana/go-str"

goStr.AfterLast("https://www.example.com/user/profile", "/")

// "profile"

APA

APA method converts the given string to title case following the APA guidelines. (Supported language: English)

/*
 * @param input string
 * @returns string
 */
func APA(input string) string
  • usage
import "github.com/bhaktibuana/go-str"

goStr.APA("createing a project")

// "Creating a Project"

Ascii

Ascii method will attempt to transliterate the string into an ASCII value.

/*
 * @param input string
 * @returns string
 */
func Ascii(input string) string
  • usage
import "github.com/bhaktibuana/go-str"

goStr.Ascii("û")

// "u"

Before

Before method returns everything before the given value in a string.

/*
 * @param input string
 * @param substr string
 * @returns string
 */
func Before(input, substr string) string
  • usage
import "github.com/bhaktibuana/go-str"

goStr.Before("The quick brown fox jumps over the lazy dog", "fox")

// "The quick brown "

BeforeLast

BeforeLast method returns everything before the last occurrence of the given value in a string.

/*
 * @param input string
 * @param substr string
 * @returns string
 */
func BeforeLast(input, substr string) string
  • usage
import "github.com/bhaktibuana/go-str"

goStr.BeforeLast("www.example.com/user/profile", "/")

// "www.example.com/user"

Camel

Camel method converts the given string to camelCase.

/*
 * @param input string
 * @returns string
 */
func Camel(input string) string
  • usage
import "github.com/bhaktibuana/go-str"

goStr.Camel("foo_bar")

// "fooBar"

Currency

Currency method will convert an amount of number or string into selected country code currency format.

/*
 * @param amount interface{} (int | float64 | string)
 * @param code CurrencyCode (string)
 * @param options ...bool (useDecimal true, dotSeparator false, useSpacer true)
 * @returns string
 */
func Currency(amount interface{}, code CurrencyCode, options ...bool) string
  • usage
import "github.com/bhaktibuana/go-str"

goStr.Currency(77.5, CURRENCY_USD)

// "$ 77.50"

goStr.Currency(77.5, CURRENCY_USD, true, false, false)

// "$77.50"

goStr.Currency(12500, CURRENCY_IDR, true, true)

// "Rp 12.500,00"

Headline

Headline method will convert strings delimited by casing, hyphens, or underscores into a space delimited string with each word's first letter capitalized.

/*
 * @param input string
 * @returns string
 */
func Headline(input string) string
  • usage
import "github.com/bhaktibuana/go-str"

goStr.Headline("HelloWorld")

// "Hello World"

goStr.Headline("foo_bar")

// "Foo Bar"

Limit

Limit method truncates the given string to the specified length.

/*
 * @param input string
 * @param length int
 * @param appendStr string
 * @returns string
 */
func Limit(input string, length int, appendStr ...string) string
  • usage
import "github.com/bhaktibuana/go-str"

goStr.Limit("The quick brown fox jumps over the lazy dog", 20)

// The quick brown fox...

You may pass a third argument to the method to change the string that will be appended to the end of the truncated string

import "github.com/bhaktibuana/go-str"

goStr.Limit("The quick brown fox jumps over the lazy dog", 20, " (...)")

// The quick brown fox (...)

Snake

Snake method converts the given string to snake_case.

/*
 * @param input string
 * @returns string
 */
func Snake(input string) string
  • usage
import "github.com/bhaktibuana/go-str"

goStr.Snake("myName-is john")

// "my_name_is_john"

Ucfirst

Ucfirst method returns the given string with the first character capitalized.

/*
 * @param input string
 * @returns string
 */
func Ucfirst(input string) string
  • usage
import "github.com/bhaktibuana/go-str"

goStr.Ucfirst("foo bar")

// "Foo bar"

Ucsplit

Ucsplit method splits the given string into a collection by uppercase characters.

/*
 * @param input string
 * @returns []string
 */
func Ucsplit(input string) []string
  • usage
import "github.com/bhaktibuana/go-str"

goStr.Ucsplit("HelloWorld")

// ["Hello", "World"]

go-str's People

Contributors

bhaktibuana avatar ersazhafrina avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.