...

Text file src/github.com/go-task/slim-sprig/v3/docs/conversion.md

Documentation: github.com/go-task/slim-sprig/v3/docs

     1# Type Conversion Functions
     2
     3The following type conversion functions are provided by Sprig:
     4
     5- `atoi`: Convert a string to an integer.
     6- `float64`: Convert to a `float64`.
     7- `int`: Convert to an `int` at the system's width.
     8- `int64`: Convert to an `int64`.
     9- `toDecimal`: Convert a unix octal to a `int64`.
    10- `toString`: Convert to a string.
    11- `toStrings`: Convert a list, slice, or array to a list of strings.
    12
    13Only `atoi` requires that the input be a specific type. The others will attempt
    14to convert from any type to the destination type. For example, `int64` can convert
    15floats to ints, and it can also convert strings to ints.
    16
    17## toStrings
    18
    19Given a list-like collection, produce a slice of strings.
    20
    21```
    22list 1 2 3 | toStrings
    23```
    24
    25The above converts `1` to `"1"`, `2` to `"2"`, and so on, and then returns
    26them as a list.
    27
    28## toDecimal
    29
    30Given a unix octal permission, produce a decimal.
    31
    32```
    33"0777" | toDecimal
    34```
    35
    36The above converts `0777` to `511` and returns the value as an int64.

View as plain text