stdlib

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Duration = expr.Function(
	"duration",
	func(args ...any) (any, error) {
		return str2duration.ParseDuration(args[0].(string))
	},
	time.ParseDuration,
)

Override built-in duration() function to provide support for additional periods - 'd' (day) - 'w' (week) - 'm' (month)

View Source
var FilepathDir = expr.Function(
	"filepath_dir",
	func(params ...any) (any, error) {
		return filepath.Dir(params[0].(string)), nil
	},
	filepath.Dir,
)
View Source
var FunctionRenamer = expr.Patch(functionRenamer{})
View Source
var LimitPathDepthTo = expr.Function(
	"limit_path_depth_to",
	func(args ...any) (any, error) {
		input := args[0].(string)
		length := args[1].(int)

		chunks := strings.Split(input, "/")
		if len(chunks) <= length {
			return input, nil
		}

		return strings.Join(chunks[0:length-1], "/"), nil
	},
	new(func(string, int) string),
)
View Source
var Since = expr.Function(
	"since",
	func(args ...any) (any, error) {
		return time.Since(args[0].(time.Time)), nil
	},
	time.Since,
)
View Source
var Uniq = expr.Function(
	"uniq",
	func(args ...any) (any, error) {
		switch elements := args[0].(type) {
		case []any:
			var result []string

			for _, element := range elements {
				result = append(result, fmt.Sprintf("%s", element))
			}

			return UniqSlice(result), nil

		case []string:
			return UniqSlice(elements), nil

		default:
			return nil, fmt.Errorf("invalid input, must be an array of [string] or [interface], got %T", args[0])
		}
	},
	new(func([]any) []string),
	new(func([]string) []string),
)

Uniq takes a list of strings or interface{}, sorts them and remove duplicated values

Functions

func ToDuration added in v0.6.0

func ToDuration(input any) time.Duration

func UniqSlice

func UniqSlice[T cmp.Ordered](in []T) []T

Types

This section is empty.

Jump to

Keyboard shortcuts

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