github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/path/separate.go (about) 1 package path 2 3 import ( 4 "context" 5 "path" 6 7 "github.com/MontFerret/ferret/pkg/runtime/core" 8 "github.com/MontFerret/ferret/pkg/runtime/values" 9 "github.com/MontFerret/ferret/pkg/runtime/values/types" 10 ) 11 12 // SEPARATE separates the path into a directory and filename component. 13 // @param {String} path - The path 14 // @return {Any[]} - First item is a directory component, and second is a filename component. 15 func Separate(_ context.Context, args ...core.Value) (core.Value, error) { 16 err := core.ValidateArgs(args, 1, 1) 17 18 if err != nil { 19 return values.None, err 20 } 21 22 err = core.ValidateType(args[0], types.String) 23 24 if err != nil { 25 return values.None, err 26 } 27 28 pattern, name := path.Split(args[0].String()) 29 30 arr := values.NewArrayWith(values.NewString(pattern), values.NewString(name)) 31 32 return arr, nil 33 }