github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/types/to_array.go (about)

     1  package types
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/MontFerret/ferret/pkg/runtime/core"
     7  	"github.com/MontFerret/ferret/pkg/runtime/values"
     8  )
     9  
    10  // TO_ARRAY takes an input value of any type and convert it into an array value.
    11  // None is converted to an empty array
    12  // Boolean values, numbers and strings are converted to an array containing the original value as its single element
    13  // Arrays keep their original value
    14  // Objects / HTML nodes are converted to an array containing their attribute values as array elements.
    15  // @param {Any} input - Input value of arbitrary type.
    16  // @return {Any[]} - An array value.
    17  func ToArray(ctx context.Context, args ...core.Value) (core.Value, error) {
    18  	err := core.ValidateArgs(args, 1, 1)
    19  
    20  	if err != nil {
    21  		return values.None, err
    22  	}
    23  
    24  	return values.ToArray(ctx, args[0]), nil
    25  }