1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-07-15 01:25:00 +02:00

Add Path functions (#505)

* Add Path functions

* Add unit tests
This commit is contained in:
Aleksandr Yakimenko
2020-05-13 05:19:41 +03:00
committed by GitHub
parent 311d07ad40
commit ed8e43e4c6
18 changed files with 676 additions and 0 deletions

31
pkg/stdlib/path/ext.go Normal file
View File

@ -0,0 +1,31 @@
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.
// @params path (String) - The path.
// @returns (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
}