stdlib

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2024 License: MIT Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Duration = expr.Function(
	"duration",
	func(args ...any) (any, error) {
		val, ok := args[0].(string)
		if !ok {
			return nil, errors.New("input to duration() must be of type 'string'")
		}

		return str2duration.ParseDuration(val)
	},
	str2duration.ParseDuration,
)
View Source
var FilepathDir = expr.Function(
	"filepath_dir",
	func(params ...any) (any, error) {
		if len(params) != 1 {
			return nil, fmt.Errorf("filepath_dir: accepts exactly 1 argument, %d provided", len(params))
		}

		val, ok := params[0].(string)
		if !ok {
			return nil, errors.New("input to filepath_dir must be of type 'string'")
		}

		return filepath.Dir(val), 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) {
		if len(args) != 2 {
			return nil, errors.New("limit_path_depth_to() expect exactly two arguments")
		}

		input, ok := args[0].(string)
		if !ok {
			return nil, errors.New("first input to limit_path_depth_to() must be of type 'string'")
		}

		length, ok := args[1].(int)
		if !ok {
			return nil, errors.New("second input to limit_path_depth_to() must be of type 'int'")
		}

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

		return strings.Join(chunks[0:length-1], "/"), nil
	},
)
View Source
var Uniq = expr.Function(
	"uniq",
	func(params ...any) (any, error) {
		arg := params[0]
		val := reflect.ValueOf(arg)

		switch val.Kind() {
		case reflect.Slice:
			switch val.Type().Elem().Kind() {
			case reflect.Interface:
				var x []string
				for _, v := range arg.([]any) {
					x = append(x, fmt.Sprintf("%s", v))
				}

				return UniqSlice(x), nil

			case reflect.String:
				return UniqSlice(arg.([]string)), nil

			}
		}

		return nil, errors.New("invalid type")
	},
)

Functions

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