mirror of
https://github.com/MontFerret/ferret.git
synced 2025-03-21 21:47:43 +02:00
34 lines
809 B
Go
34 lines
809 B
Go
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"
|
|
)
|
|
|
|
// Separate separates the path into a directory and filename component.
|
|
// @param path (String) - The path
|
|
// @returns (Array) - First item is a directory component, and second is a filename component.
|
|
func Separate(_ context.Context, args ...core.Value) (core.Value, error) {
|
|
err := core.ValidateArgs(args, 1, 1)
|
|
|
|
if err != nil {
|
|
return values.None, err
|
|
}
|
|
|
|
err = core.ValidateType(args[0], types.String)
|
|
|
|
if err != nil {
|
|
return values.None, err
|
|
}
|
|
|
|
pattern, name := path.Split(args[0].String())
|
|
|
|
arr := values.NewArrayWith(values.NewString(pattern), values.NewString(name))
|
|
|
|
return arr, nil
|
|
}
|