fmap

package
v0.0.0-...-d0bb578 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultFMap = template.FuncMap{
		"string": func(i interface {
			String() string
		}) string {
			return i.String()
		},
		"json": func(v interface{}) string {
			a, err := json.Marshal(v)
			if err != nil {
				return err.Error()
			}
			return string(a)
		},
		"prettyjson": func(v interface{}) string {
			a, err := json.MarshalIndent(v, "", "  ")
			if err != nil {
				return err.Error()
			}
			return string(a)
		},
		"splitArray": func(sep string, s string) []interface{} {
			var r []interface{}
			t := strings.Split(s, sep)
			for i := range t {
				if t[i] != "" {
					r = append(r, t[i])
				}
			}
			return r
		},
		"first": func(a []string) string {
			return a[0]
		},
		"last": func(a []string) string {
			return a[len(a)-1]
		},
		"concat": func(a string, b ...string) string {
			return strings.Join(append([]string{a}, b...), "")
		},
		"join": func(sep string, a ...string) string {
			return strings.Join(a, sep)
		},
		"upperFirst": func(s string) string {
			return strings.ToUpper(s[:1]) + s[1:]
		},
		"lowerFirst": func(s string) string {
			return strings.ToLower(s[:1]) + s[1:]
		},
		"camelCase": func(s string) string {
			if len(s) > 1 {
				return xstrings.ToCamelCase(s)
			}

			return strings.ToUpper(s[:1])
		},
		"lowerCamelCase": func(s string) string {
			if len(s) > 1 {
				s = xstrings.ToCamelCase(s)
			}

			return strings.ToLower(s[:1]) + s[1:]
		},
		"kebabCase": func(s string) string {
			return strings.Replace(xstrings.ToSnakeCase(s), "_", "-", -1)
		},
		"contains": func(sub, s string) bool {
			return strings.Contains(s, sub)
		},
		"trimstr": func(cutset, s string) string {
			return strings.Trim(s, cutset)
		},
		"index": func(array interface{}, i int32) interface{} {
			slice := reflect.ValueOf(array)
			if slice.Kind() != reflect.Slice {
				panic("Error in index(): given a non-slice type")
			}
			if i < 0 || int(i) >= slice.Len() {
				panic("Error in index(): index out of bounds")
			}
			return slice.Index(int(i)).Interface()
		},
		"add": func(a int, b int) int {
			return a + b
		},
		"subtract": func(a int, b int) int {
			return a - b
		},
		"multiply": func(a int, b int) int {
			return a * b
		},
		"divide": func(a int, b int) int {
			if b == 0 {
				panic("psssst ... little help here ... you cannot divide by 0")
			}
			return a / b
		},

		"snakeCase": xstrings.ToSnakeCase,

		"set":                      Set,
		"get":                      Get,
		"allSettings":              AllSettings,
		"allKeys":                  AllKeys,
		"configFileUsed":           ConfigFileUsed,
		"supportedExts":            SupportedExts,
		"isSet":                    IsSet,
		"supportedRemoteProviders": SupportedRemoteProviders,
	}
)

Functions

func AllKeys

func AllKeys() []string

func AllSettings

func AllSettings() map[string]interface{}

func ConfigFileUsed

func ConfigFileUsed() string

func FormatID

func FormatID(base string, formatted string) string

func Get

func Get(key string) interface{}

func GetPackageTypeName

func GetPackageTypeName(s string) string

func GoNormalize

func GoNormalize(s string) string

func IsSet

func IsSet(key string) bool

func LowerGoNormalize

func LowerGoNormalize(s string) string

func ReplaceDict

func ReplaceDict(src string, dict map[string]interface{}) string

func Set

func Set(key string, o interface{}) string

func SupportedExts

func SupportedExts() []string

func SupportedRemoteProviders

func SupportedRemoteProviders() []string

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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