Giter Site home page Giter Site logo

strutil's Introduction

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

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

AlignCenter (Docs)

Aligns the text to the center

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

AlignLeft (Docs)

Aligns the text to the left

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

AlignRight (Docs)

Aligns the text to the right

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

CountWords (Docs)

Counts the words

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

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

Indent (Docs)

Indents every line

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

IsASCII (Docs)

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

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

Len (Docs)

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

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

MapLines (Docs)

Runs function fn on every line of the string

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

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

PadLeft (Docs)

Left pads the string

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

PadRight (Docs)

Right pads the string

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

Random (Docs)

Creates a random string from a character set

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

RemoveAccents (Docs)

Convert accented letters to ascii counterparts

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

ReplaceAllToOne (Docs)

Replace all substrings in the text with the specified string

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

Reverse (Docs)

Reverses the string

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

Splice (Docs)

Replaces a part of the string

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

SplitAndMap (Docs)

Splits the string and runs the function fn on every part

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

Slugify (Docs)

Converts the string to a slug

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

SlugifySpecial (Docs)

Converts the string to a slug with custom delimiter.

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

SplitCamelCase (Docs)

Splits the words in a camelCase string

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

Substring (Docs)

Gets a part of the string without panics

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

MustSubstring (Docs)

Gets a part of the string

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

Summary (Docs)

Cuts the string to the specified length

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

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

ToCamelCase (Docs)

Converts the string to camelCase

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

Words (Docs)

Returns the words inside the text

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

WordWrap (Docs)

Wraps the lines in the text

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

strutil's People

Contributors

ferhatelmas avatar ozgio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

strutil's Issues

Slice versions

Is there any plan to add functions to operate on string slice, instead of one string?

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.