1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-12-25 23:37:06 +02:00
Files
ferret/pkg/stdlib/objects/values.go
Tim Voronov 24752c0f48 Updated ANTLR and other dependencies. Upgraded Go version (#796)
* Updated ANTLR and other dependencies. Upgraded Go version

* Updated unit tests

* Updated CodeQL

* Fixed linting errors

* Updated build pipeline

* Reverted refactoring of build pipeline

* Removed outdated examples from E2E tests
2025-05-07 10:50:17 -04:00

44 lines
877 B
Go

package objects
import (
"context"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
"github.com/MontFerret/ferret/pkg/runtime/values/types"
)
// VALUES return the attribute values of the object as an array.
// @param {Object} object - Target object.
// @return {Any[]} - Values of document returned in any order.
func Values(_ 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.Object)
if err != nil {
return values.None, err
}
obj := args[0].(*values.Object)
vals := values.NewArray(0)
obj.ForEach(func(val core.Value, _ string) bool {
cloneable, ok := val.(core.Cloneable)
if ok {
val = cloneable.Clone()
}
vals.Push(val)
return true
})
return vals, nil
}