stringfy

Simple string manipulation package for Go

  • Owner: hgsigner/stringfy
  • Platform:
  • License:: MIT License
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

Stringfy Build Status GoDoc

Stringfy is a string manipulation package for GO.


Install:

$ go get github.com/hgsigner/stringfy

Usage:

package main

import (
  	"fmt"
	"github.com/hgsigner/stringfy"
)

func main() {
	es := stringfy.Escape("São Paulo")
 	fmt.Prinln(es) // Sao Paulo
}

Functions:

CamelCase:

package main

import (
  	"fmt"
	"github.com/hgsigner/stringfy"
)

func main() {
	cc := stringfy.CamelCase("fizz_buzz_bazz")  
	fmt.Prinln(cc) // FizzBuzzBazz
}

Escape:

package main

import (
  	"fmt"
	"github.com/hgsigner/stringfy"
)

func main() {
	es := stringfy.Escape("São Paulo")
 	fmt.Prinln(es) // Sao Paulo
}

Parameterize:

package main

import (
  	"fmt"
	"github.com/hgsigner/stringfy"
)

func main() {
	pm := stringfy.Parameterize("São Paulo")
 	fmt.Prinln(pm) // sao-paulo
}

Underscore:

package main

import (
  	"fmt"
	"github.com/hgsigner/stringfy"
)

func main() {
	un := stringfy.Underscore("São Paulo")
 	fmt.Prinln(un) // sao_paulo
}

Plural:

package main

import (
  	"fmt"
	"github.com/hgsigner/stringfy"
)

func main() {
	// Default plural
	pl1 := stringfy.NewPlural()
 	fmt.Println(pl1.Perform(2, "octopus")) // 2 octopi
 	
 	// Custom plural
 	pl2 := stringfy.NewPlural()
 	pl2.Options(stringfy.AddPlural("timesz"))
 	fmt.Println(pl2.Perform(2, "timey")) // 2 timesz
}

Options:

stringfy.AddPlural(string)

Truncate:

package main

import (
  	"fmt"
	"github.com/hgsigner/stringfy"
)

func main() {
	text := "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
 	
 	// Default truncate
 	tr1 := stringfy.NewTruncate()
 	tr1.Perform(text) // Lorem ipsum dolor sit amet,...

 	// Custom truncate
 	tr2 := stringfy.NewTruncate()
 	tr2.Options(stringfy.AddLength(17))
 	tr2.Perform(text) // Lorem ipsum do...

 	tr3 := stringfy.NewTruncate()
 	tr3.Options(stringfy.AddLength(13), stringfy.AddSeparator(" "))
 	tr3.Perform(text) // Lorem ipsum...
}

Options:

stringfy.AddLength(int)       // Default: 30

stringfy.AddOmission(string)  // Default: "..."

stringfy.AddSeparator(string) // Default: ""

Excerpt:

package main

import (
  	"fmt"
	"github.com/hgsigner/stringfy"
)

func main() {
	text := "Lorem ipsum dolor sit amet consectetur adipiscing elit."
 	
 	ex1 := stringfy.NewExcerpt()
 	ex1.Options(stringfy.AddRadius(4))
 	ex1.Perform(text, "sit") // ...lor sit ame...

 	ex2 := stringfy.NewExcerpt()
 	ex2.Options(stringfy.AddRadius(4), stringfy.AddOmission("(...)"))
 	ex2.Perform(text, "sit") // (...)lor sit ame(...)

 	ex3 := stringfy.NewExcerpt()
 	ex3.Options(stringfy.AddRadius(1), stringfy.AddSeparator(" "))
 	ex3.Perform(text, "sit") // ...dolor sit amet...
}

Options:

stringfy.AddRadius(int)       // Default: 100

stringfy.AddOmission(string)  // Default: "..."

stringfy.AddSeparator(string) // Default: ""

WordWrap:

package main

import (
  	"fmt"
	"github.com/hgsigner/stringfy"
)

func main() {
	text := "Lorem ipsum dolor sit amet, consectetur adipiscing elit sil."

	wwr1 := stringfy.NewWordWrap()
 	wwr1.Perform(text) // "Lorem ipsum dolor sit amet, consectetur adipiscing elit sil."

 	wwr2 := stringfy.NewWordWrap()
 	wwr2.Options(stringfy.AddLineWidth(10))
 	wwr2.Perform(text) // "Lorem\nipsum\ndolor sit\namet,\nconsectetur\nadipiscing\nelit sil."

 	wwr3 := stringfy.NewWordWrap()
 	wwr3.Options(stringfy.AddLineWidth(35))
 	wwr3.Perform(text) // "Lorem ipsum dolor sit amet,\nconsectetur adipiscing elit sil."
}

Options:

stringfy.AddLineWidth(int)       // Default: 80

For more information, please refer to the docs. Work in progress. More packages to come.


Licensing

This package is available as open source under the terms of the MIT License.

Main metrics

Overview
Name With Ownerhgsigner/stringfy
Primary LanguageGo
Program languageGo (Language Count: 1)
Platform
License:MIT License
所有者活动
Created At2015-09-10 01:35:30
Pushed At2021-06-25 05:21:39
Last Commit At2021-06-06 14:22:31
Release Count0
用户参与
Stargazers Count102
Watchers Count4
Fork Count6
Commits Count80
Has Issues Enabled
Issues Count1
Issue Open Count1
Pull Requests Count2
Pull Requests Open Count0
Pull Requests Close Count0
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private