transform

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 28, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

transform package contains all base functions to transform one string to another

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Circle

func Circle(str string) string

Circle returns all characters inside circles

Example

Converts all characters to circled characters

package main

import (
	"fmt"

	"github.com/guumaster/textifier/pkg/transform"
)

func main() {
	text := transform.Circle("hello")
	fmt.Println(text)

}
Output:

ⓗⓔⓛⓛⓞ

func CircleInverse

func CircleInverse(str string) string

CircleInverse like circle but with filled background

Example

Converts same as Circle but with background

package main

import (
	"fmt"

	"github.com/guumaster/textifier/pkg/transform"
)

func main() {
	text := transform.Circle("hello world")
	fmt.Println(text)

}
Output:

🅗🅔🅛🅛🅞

func Double

func Double(str string) string

Double show each character with a double line

func Emoji

func Emoji(s string) string

Emoji parse emoji codes like Github or Slack. ex: :boom:

Example

Converts emoji codes like GitHub or Slack

package main

import (
	"fmt"

	"github.com/guumaster/textifier/pkg/transform"
)

func main() {
	text := transform.Emoji(":boom: Hello :beer: World! :earth_americas:")
	fmt.Println(text)

}
Output:

💥 Hello 🍺 World! 🌎

func Flip

func Flip(str string) string

Flip turns text upside down

Example

Turns the text upside down

package main

import (
	"fmt"

	"github.com/guumaster/textifier/pkg/transform"
)

func main() {
	text := transform.Flip("Hello World")
	fmt.Println(text)

}
Output:

plɹoM ollǝH

func Reverse

func Reverse(value string) string

Reverse return a string in reverse order

Example

Change direction of the whole text

package main

import (
	"fmt"

	"github.com/guumaster/textifier/pkg/transform"
)

func main() {
	text := transform.Reverse("Hello World")
	fmt.Println(text)

}
Output:

dlroW olleH

func Spacer

func Spacer(s string) string

Spacer add spaces between letters

Example

Add spaces between characters

package main

import (
	"fmt"

	"github.com/guumaster/textifier/pkg/transform"
)

func main() {
	text := transform.Spacer("Hello World")
	fmt.Println(text)

}
Output:

H e l l o  W o r l d

func Square

func Square(str string) string

Square transform characters to squared

Example

Converts all characters to squared characters

package main

import (
	"fmt"

	"github.com/guumaster/textifier/pkg/transform"
)

func main() {
	text := transform.Square("Hello World")
	fmt.Println(text)

}
Output:

🄷🄴🄻🄻🄾 🅆🄾🅁🄻🄳

func SquareInverse

func SquareInverse(str string) string

Square same as Square but with filled background

Example

Same as Square but with filled background

package main

import (
	"fmt"

	"github.com/guumaster/textifier/pkg/transform"
)

func main() {
	text := transform.Square("Hello World")
	fmt.Println(text)

}
Output:

🅷🅴🅻🅻🅾 🆆🅾🆁🅻🅳

Types

type StringFn

type StringFn func(string) string

StringFn is the basic composable function type

func Compose

func Compose(a StringFn, b ...StringFn) StringFn

Compose combine two transformers together

Example

This example show how to compose more than one transformer together

package main

import (
	"fmt"
	"strings"

	"github.com/guumaster/textifier/pkg/transform"
)

func main() {
	tr := transform.Compose(
		transform.Reverse,
		strings.ToUpper, // <- Note that you can use any other function with same signature as StringFn
		transform.SquareInverse,
		transform.Spacer,
		transform.Emoji,
	)
	text := tr(":boom: Hello World")
	fmt.Println(text)

}
Output:

🅳 🅻 🆁 🅾 🆆   🅾 🅻 🅻 🅴 🅷     💥

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL