1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-03-19 21:28:32 +02:00
Tim Voronov 24d8eedd4c
Feature/doc markup ()
* Added release notes

*  fixedOCOD typo

* Updated values

* Updated comments

* Changed stdlib docs format

* Changed format of array in docs

* Use 'any' instead of 'value' in docs

* New format for optional params

* Updated docs for testing package

* Added namespace information
2020-08-07 21:49:29 -04:00

46 lines
957 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"
)
// MATCH reports whether name matches the pattern.
// @param {String} pattern - The pattern.
// @param {String} name - The name.
// @return {Boolean} - True if the name matches the pattern.
func Match(_ context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 2, 2)
if err != nil {
return values.False, err
}
err = core.ValidateType(args[0], types.String)
if err != nil {
return values.False, err
}
err = core.ValidateType(args[1], types.String)
if err != nil {
return values.False, err
}
pattern := args[0].String()
name := args[1].String()
matched, err := path.Match(pattern, name)
if err != nil {
return values.False, core.Error(err, "match")
}
return values.NewBoolean(matched), nil
}