converter

package module
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2021 License: MIT Imports: 15 Imported by: 0

README

converter

✂ multiformat data conversion

Build Status GoDoc Coverage Status

dictionary

Usage

converter can be used in the CLI as follow:

foo@bar:~$ converter -h
NAME:
   converter - A new cli application

USAGE:
   converter [global options] command [command options] [arguments...]

AUTHOR:
   Manfred Touron <https://github.com/moul/converter>

COMMANDS:
   base32
   base32-decode
   base58
   base58-decode
   base64
   base64-decode
   csv-decode
   hex
   hex-decode
   hexbase32
   hexbase32-decode
   json
   json-decode
   lower
   md5
   rawurlbase64
   rawurlbase64-decode
   rev
   sha1
   title
   toml
   upper
   urlbase64
   urlbase64-decode
   xml
   xml-decode
   help, h              Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --help, -h  show help
foo@bar:~$ echo -n "Hello World!" | converter _bytes-to-string rev
!dlroW olleH
foo@bar:~$ echo "Hello World!" | converter md5
[141 221 139 228 177 121 165 41 175 165 242 255 174 75 152 88]
foo@bar:~$ echo "Hello World!" | converter md5 md5
[98 213 234 111 247 90 250 37 61 11 160 58 20 171 41 82]
foo@bar:~$ echo "Hello World!" | converter md5 md5 md5
[133 150 171 125 251 139 53 229 243 216 47 103 80 243 191 9]
foo@bar:~$ echo "Hello World!" | converter _bytes-to-string rev _string-to-bytes md5 hex upper rev
26E80BC257BC2EB49316825A8DB8E0C9
foo@bar:~$ echo "Hello World!" | converter _bytes-to-string rev _string-to-bytes md5 hex upper rev base64-decode
[219 161 60 208 16 182 231 176 66 216 64 120 247 125 122 243 110 64 240 48 124 19 64 189]
foo@bar:~$ echo "Hello World!" | converter _bytes-to-string rev _string-to-bytes md5 hex upper rev base64-decode bytes-to-string
ۡ<����B�@x�}z�n@�0|@�

Using with Docker

$ date | docker run --rm moul/converter md5 sha1
67a74306b06d0c01624fe0d0249a570f4d093747

Using as a Golang library

See GoDoc for usage and examples.

Credit

This project is inspired by the transformer by the venerable Juan Benet

License

MIT

Documentation

Overview

message from the author:

+--------------------------------------------------------------+
| * * * ░░░░░░░░░░░░░░░░░░░░  Hello  ░░░░░░░░░░░░░░░░░░░░░░░░░░|
+--------------------------------------------------------------+
|                                                              |
|     ++              ______________________________________   |
|     ++++           /                                      \  |
|      ++++          |                                      |  |
|    ++++++++++      |   Feel free to contribute to this    |  |
|   +++       |      |       project or contact me on       |  |
|   ++         |     |    manfred.life if you like this     |  |
|   +  -==   ==|     |               project!               |  |
|  (   <*>   <*>     |                                      |  |
|   |          |    /|                  :)                  |  |
|   |         _)   / |                                      |  |
|   |      +++    /  \______________________________________/  |
|    \      =+   /                                             |
|     \      +                                                 |
|     |\++++++                                                 |
|     |  ++++      ||//                                        |
|  ___|   |___    _||/__                                     __|
| /    ---    \   \|  |||                   __ _  ___  __ __/ /|
|/  |       |  \    \ /                    /  ' \/ _ \/ // / / |
||  |       |  |    | |                   /_/_/_/\___/\_,_/_/  |
+--------------------------------------------------------------+
Example
package main

import (
	"fmt"

	"moul.io/converter"
)

func main() {
	ret, _ := converter.Chain("hello world", []string{"rev", "upper"})
	fmt.Println(ret)
}
Output:

DLROW OLLEH

Index

Examples

Constants

This section is empty.

Variables

View Source
var Converters = map[string]interface{}{
	"base32":              base32Encode,
	"base32-decode":       base32Decode,
	"base58":              base58Encode,
	"base58-decode":       base58Decode,
	"base64":              base64Encode,
	"base64-decode":       base64Decode,
	"hex":                 hexEncode,
	"hex-decode":          hexDecode,
	"hexbase32":           hexbase32Encode,
	"hexbase32-decode":    hexbase32Decode,
	"lower":               lower,
	"md5":                 md5Sum,
	"rawurlbase64":        rawurlbase64Encode,
	"rawurlbase64-decode": rawurlbase64Decode,
	"rev":                 rev,
	"sha1":                sha1Sum,
	"title":               title,
	"upper":               upper,
	"urlbase64":           urlbase64Encode,
	"urlbase64-decode":    urlbase64Decode,
	"json":                jsonMarshal,
	"toml":                tomlEncode,
	"json-decode":         jsonDecode,
	"csv-decode":          csvDecode,
	"xml":                 xmlEncode,
	"xml-decode":          xmlDecode,

	"_parse-string":      parseString,
	"_bytes-to-string":   bytesToString,
	"_string-to-bytes":   stringToBytes,
	"_int64-to-string":   int64ToString,
	"_string-to-int64":   stringToInt64,
	"_string-to-float64": stringToFloat64,
	"_float64-to-string": float64ToString,
}

Converters is a map containing converters that can be called using a name.

Functions

func Chain

func Chain(input interface{}, converters []string) (interface{}, error)

Types

type Func added in v1.2.0

type Func func(interface{}) (interface{}, error)

func ChainFunc added in v1.2.0

func ChainFunc(converters []string) (Func, error)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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