2018-09-18 22:42:38 +02:00
|
|
|
package collections
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"github.com/MontFerret/ferret/pkg/runtime/collections"
|
|
|
|
"github.com/MontFerret/ferret/pkg/runtime/core"
|
|
|
|
"github.com/MontFerret/ferret/pkg/runtime/values"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Length(_ context.Context, inputs ...core.Value) (core.Value, error) {
|
2018-09-22 02:36:33 +02:00
|
|
|
err := core.ValidateArgs(inputs, 1, 1)
|
2018-09-18 22:42:38 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return values.None, err
|
|
|
|
}
|
|
|
|
|
|
|
|
value := inputs[0]
|
|
|
|
err = core.ValidateType(
|
|
|
|
value,
|
|
|
|
core.StringType,
|
|
|
|
core.ArrayType,
|
|
|
|
core.ObjectType,
|
2018-10-06 01:40:09 +02:00
|
|
|
core.HTMLElementType,
|
|
|
|
core.HTMLDocumentType,
|
2018-09-18 22:42:38 +02:00
|
|
|
core.BinaryType,
|
|
|
|
)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return values.None, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return value.(collections.Collection).Length(), nil
|
|
|
|
}
|