1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-03-19 21:28:32 +02:00

32 lines
708 B
Go
Raw Normal View History

package path
import (
"context"
"path"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
"github.com/MontFerret/ferret/pkg/runtime/values/types"
)
// EXT returns the extension of the last component of path.
// @param {String} path - The path.
// @return {String} - The extension of the last component of path.
func Ext(_ context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 1, 1)
if err != nil {
return values.EmptyString, err
}
err = core.ValidateType(args[0], types.String)
if err != nil {
return values.None, err
}
pathText := args[0].String()
return values.NewString(path.Ext(pathText)), nil
}