String Utilities for Go

Overview

String Utilities for Go

GoReportCard GoDocs

"strutil" provides string functions for go applications.

For documentation with examples see GoDoc

Functions

Align (Docs)

Aligns the text to the specified side

" lorem ipsum" ">
strutil.Align("lorem ipsum", strutil.Right, 20) //->"        lorem ipsum" 

AlignCenter (Docs)

Aligns the text to the center

" lorem \n ipsum " ">
strutil.AlignCenter("lorem\nipsum", 10) //->"  lorem   \n  ipsum   " 

AlignLeft (Docs)

Aligns the text to the left

"lorem \nipsum " ">
strutil.AlignLeft("  lorem   \n  ipsum   ") //->"lorem   \nipsum   " 

AlignRight (Docs)

Aligns the text to the right

" lorem\n ipsum" ">
strutil.AlignRight("lorem\nipsum", 10) //-> "     lorem\n     ipsum" 

CountWords (Docs)

Counts the words

"5"">
strutil.CountWords("Lorem ipsum, dolor sit amet") //-> "5"

DrawBox (Docs)

Draws a frame around the string with default character set

strutil.DrawBox("Hello World", 20, strutil.Center)
//┌──────────────────┐
//│   Hello World    │
//└──────────────────┘

DrawCustomBox (Docs)

Draws a frame around the string with custom character set

strutil.DrawCustomBox("Hello World", 20, strutil.Center, strutil.SimpleBox9Slice(), "\n")
//┌──────────────────┐
//│   Hello World    │
//└──────────────────┘

ExpandTabs (Docs)

Converts tabs to the spaces

" lorem\n ipsum\n"">
strutil.ExpandTabs("\tlorem\n\tipsum\n", 2) //-> "  lorem\n  ipsum\n"

Indent (Docs)

Indents every line

") //-> "> lorem\n> ipsum"">
strutil.Indent("lorem\nipsum", "> ") //-> "> lorem\n> ipsum"

IsASCII (Docs)

Checks if all the characters in string are in standard ASCII table

true">
strutil.IsASCII("lorem\nipsum") //-> true

Len (Docs)

Alias of utf8.RuneCountInString which returns the number of runes in string

"3"">
strutil.Len("böt") //-> "3"

MapLines (Docs)

Runs function fn on every line of the string

"lorem\nipsum"">
strutil.MapLines("   lorem      \n    ipsum      ", strings.TrimSpace) //-> "lorem\nipsum"

OSNewLine (Docs)

OSNewLine returns operating systems default new line character

strutil.OSNewLine() //-> "\n"

Pad (Docs)

Left and right pads the string

", "<-") //-> "->->lorem<-<-"">
strutil.Pad("lorem", 11, "->", "<-") //-> "->->lorem<-<-"

PadLeft (Docs)

Left pads the string

") //-> "->->lorem"">
strutil.PadLeft("lorem", 9, "->") //-> "->->lorem"

PadRight (Docs)

Right pads the string

"lorem<-<-"">
strutil.PadRight("lorem", 9, "<-") //-> "lorem<-<-"

Random (Docs)

Creates a random string from a character set

"aciafbeafg"">
strutil.Random("abcdefghi", 10) //-> "aciafbeafg"

RemoveAccents (Docs)

Convert accented letters to ascii counterparts

"resume"">
strutil.RemoveAccents("résumé") //-> "resume"

ReplaceAllToOne (Docs)

Replace all substrings in the text with the specified string

"l.r.m .ps.m"">
strutil.ReplaceAllToOne("lorem ipsum", []string{"o","e","i","u"}, ".") //-> "l.r.m .ps.m"

Reverse (Docs)

Reverses the string

"merol"">
strutil.Reverse("lorem") //-> "merol"

Splice (Docs)

Replaces a part of the string

"lo-x-em"">
strutil.Splice("lorem", "-x-", 2, 3) //-> "lo-x-em"

SplitAndMap (Docs)

Splits the string and runs the function fn on every part

"merol\nmuspi\nrolod"">
strutil.MapLines("lorem-ipsum-dolor", "-",  strutil.Reverse) //-> "merol\nmuspi\nrolod"

Slugify (Docs)

Converts the string to a slug

"lorem-ipsum-dolor"">
strutil.Slugify("Lorem ipsum, dolör") //-> "lorem-ipsum-dolor"

SlugifySpecial (Docs)

Converts the string to a slug with custom delimiter.

"lorem_ipsum_dolor"">
strutil.SlugifySpecial("Lorem ipsum, dolör", "_") //-> "lorem_ipsum_dolor"

SplitCamelCase (Docs)

Splits the words in a camelCase string

[]string{"lorem", "Ipsum"}">
strutil.SplitCamelCase("loremIpsum") //-> []string{"lorem", "Ipsum"}

Substring (Docs)

Gets a part of the string without panics

"l"">
strutil.SafeSubstring("lorem", 0, 1) //-> "l"

MustSubstring (Docs)

Gets a part of the string

"l"">
strutil.Substring("lorem", 0, 1) //-> "l"

Summary (Docs)

Cuts the string to the specified length

"lorem ipsum..."">
strutil.Summary("Lorem ipsum dolor sit amet",  10, "...") //-> "lorem ipsum..."

Tile (Docs)

Repeats the pattern until the result reaches the 'length'

"-৹-৹"">
strutil.Tile("-৹", 4) //-> "-৹-৹"

ToSnakeCase (Docs)

Converts the string to snake_case

"snake_case"">
strutil.ToSnakeCase("Snake Case") //-> "snake_case"

ToCamelCase (Docs)

Converts the string to camelCase

"camelCase"">
strutil.ToCamelCase("Camel Case") //-> "camelCase"

Words (Docs)

Returns the words inside the text

[]string{"Lorem", "ipsum", "dolor", "sit", "amet"}">
strutil.Words("Lorem ipsum, dolor sit amet") //-> []string{"Lorem", "ipsum", "dolor", "sit", "amet"}

WordWrap (Docs)

Wraps the lines in the text

"Lorem ipsum\ndolor sit amet"">
strutil.WordWrap("Lorem ipsum dolor sit amet", 15, false) //-> "Lorem ipsum\ndolor sit amet"

Install

Prequsities:

  • Go 1.10+

Install with

go get github.com/ozgio/strutil
Issues
Owner
Ozgur Erdem
Ozgur Erdem
Utilities for interacting with Dockerfiles

go-dockerfile Golang utilities for interacting with Dockerfiles. This is not a place of honor. No esteemed source code is commemorated here. Don't tak

Jake Sanders 16 Dec 18, 2021
CUE utilities and helpers for working with tree based objects in any combination of CUE, Yaml, and JSON.

Cuetils CUE utilities and helpers for working with tree based objects in any combination of CUE, Yaml, and JSON. Using As a command line binary The cu

_Hofstadter 16 Dec 29, 2021
Simple utilities for creating ascii text in Go

Simple utilities for creating ascii text in Go

Reinaldy Rafli 3 Oct 30, 2021
golden provides utilities for golden file tests.

golden provides utilities for golden file tests.

Takuya Ueda 9 Nov 13, 2021
Source Repo for utilities used in Atlas

Atlas-Utilities Source Repo for utilities used in Atlas filepicker Simple file picker in Go using go-common-file-dialog This returns the path of a fil

AtlasOS 6 Jan 15, 2022
Utilities and immutable collections for functional programming in Golang

Utilities and immutable collections for functional programming in Golang. This is an experimental library to play with the new Generics Feature in Go 1.18.

Peter Zeller 3 Jan 3, 2022
List-Utils - 🔧 Utilities for maintaining the list of repost sites

SMR List Utils This is a Go CLI tool that helps with managing the StopModReposts blacklist. Install Use GitHub Releases and download binary. Linux Qui

Stop Mod Reposts 0 Jan 3, 2022
Utilities for processing Wikipedia dumps in Go

Utilities for processing Wikipedia dumps in Go A Go package providing utilities for processing Wikipedia dumps. Features: Supports Wikidata entities J

null 0 Jan 10, 2022
Utilities for rounding and truncating floating point numbers.

Rounders Provides utilities for rounding and truncating floating point numbers. Example: rounders.RoundToDecimals(12.48881, 2)

Konnor Klashinsky 0 Jan 6, 2022
Go-path - A helper package that provides utilities for parsing and using ipfs paths

go-path is a helper package that provides utilities for parsing and using ipfs paths

y 0 Jan 18, 2022
Go library that provides fuzzy string matching optimized for filenames and code symbols in the style of Sublime Text, VSCode, IntelliJ IDEA et al.

Go library that provides fuzzy string matching optimized for filenames and code symbols in the style of Sublime Text, VSCode, IntelliJ IDEA et al. This library is external dependency-free. It only depends on the Go standard library.

Sahil Muthoo 1.1k Jan 12, 2022
Package strnaming is used to Convert string to camelCase, snake_case, kebab-case.

strnaming Package strnaming is used to Convert string to camelCase, snake_case, kebab-case. Contents strnaming Contents API Examples Install Quick sta

null 2 Oct 24, 2021
💪 Helper Utils For The Go: string, array/slice, map, format, cli, env, filesystem, test and more.

?? Helper Utils For The Go: string, array/slice, map, format, cli, env, filesystem, test and more. Go 的一些工具函数,格式化,特殊处理,常用信息获取等等

Gookit 475 Jan 15, 2022
encLib is a simple golang package for quickly encoding and decoding string data in hex

encLib is a simple golang package for quickly encoding and decoding string data in hex

null 0 Nov 1, 2021
Cell is a Go package that creates new instances by string in running time.

Cell Cell is a Go package that creates new instances by string in running time. Getting Started Installing To start using CELL, install Go and run go

null 0 Dec 20, 2021
Deduplicated and GC-friendly string store

This library helps to store big number of strings in structure with small number of pointers to make it friendly to Go garbage collector.

Bastrykov Evgeniy 2 Nov 10, 2021
ms - 'my story' creates a secure password string which can be memorized with a technique shared by Max.

On 23.12.21 20:22, Stefan Claas wrote: [...] > > Yes, I am aware of that, but how can one memorize a key when traveling > and not taking any devices

Stefan Claas 0 Dec 24, 2021
Q2entities - Parse the entities string from a Quake 2 .bsp map file. Written in Go

Q2Entities A simple command-line utility to extract the entities string from a Quake 2 map file. Entities? Binary Space Partitioning maps (.bsp) conta

null 0 Jan 1, 2022
Generates a random alphanumeric string of a given length.

randstring randstring.Create () is fast and has minimal memory allocation. It returns a random alphanumeric string of a given length. Install go get g

null 0 Jan 7, 2022