| 1 | package execution |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "github.com/tomwright/dasel/v3/model" |
| 6 | ) |
| 7 | |
| 8 | // FuncLen is a function that returns the length of the given value. |
| 9 | var FuncLen = NewFunc( |
| 10 | "len", |
| 11 | func(ctx context.Context, data *model.Value, args model.Values) (*model.Value, error) { |
| 12 | arg := args[0] |
| 13 | |
| 14 | l, err := arg.Len() |
| 15 | if err != nil { |
| 16 | return nil, err |
| 17 | } |
| 18 | |
| 19 | return model.NewIntValue(int64(l)), nil |
| 20 | }, |
| 21 | ValidateArgsExactly(1), |
| 22 | ) |