# `ABSmartly.Utils`
[🔗](https://github.com/absmartly/elixir-sdk/blob/v1.0.0/lib/absmartly/utils.ex#L1)

Utility functions for ABSmartly SDK.

# `base64_url_no_padding`
[🔗](https://github.com/absmartly/elixir-sdk/blob/v1.0.0/lib/absmartly/utils.ex#L66)

Encode binary data as base64url without padding.

    iex> ABSmartly.Utils.base64_url_no_padding("te")
    "dGU"

# `choose_variant`
[🔗](https://github.com/absmartly/elixir-sdk/blob/v1.0.0/lib/absmartly/utils.ex#L114)

Choose a variant based on cumulative split probabilities.

Returns the index of the first variant where cumulative probability >= value.

## Examples

    iex> ABSmartly.Utils.choose_variant([0.0, 1.0], 0.0)
    1

    iex> ABSmartly.Utils.choose_variant([0.0, 1.0], 0.5)
    1

    iex> ABSmartly.Utils.choose_variant([0.5, 0.5], 0.0)
    0

    iex> ABSmartly.Utils.choose_variant([0.5, 0.5], 0.5)
    1

    iex> ABSmartly.Utils.choose_variant([0.33, 0.33, 0.34], 0.66)
    2

# `hash_unit`
[🔗](https://github.com/absmartly/elixir-sdk/blob/v1.0.0/lib/absmartly/utils.ex#L14)

Hash a unit identifier using MD5 and encode as base64url (no padding).

## Examples

    iex> ABSmartly.Utils.hash_unit("bleh@absmartly.com")
    "rcH4hfF5JRm9-sOLmWKubA"

# `numeric?`
[🔗](https://github.com/absmartly/elixir-sdk/blob/v1.0.0/lib/absmartly/utils.ex#L83)

True when the value is a number.

# `object?`
[🔗](https://github.com/absmartly/elixir-sdk/blob/v1.0.0/lib/absmartly/utils.ex#L77)

True when the value is a plain object (a map that is not a struct).

# `promise?`
[🔗](https://github.com/absmartly/elixir-sdk/blob/v1.0.0/lib/absmartly/utils.ex#L89)

True when the value is an asynchronous result (a `Task`), the Elixir
counterpart of a JavaScript promise.

# `to_boolean`
[🔗](https://github.com/absmartly/elixir-sdk/blob/v1.0.0/lib/absmartly/utils.ex#L155)

Convert any value to a boolean.

# `to_number`
[🔗](https://github.com/absmartly/elixir-sdk/blob/v1.0.0/lib/absmartly/utils.ex#L136)

Convert any value to a number (integer or float).
Returns nil if conversion fails.

# `unit_to_string`
[🔗](https://github.com/absmartly/elixir-sdk/blob/v1.0.0/lib/absmartly/utils.ex#L26)

The string form of a unit UID used for hashing. Like the JavaScript SDK
(`value.toFixed(0)`), a numeric UID is rounded to an integer first.

    iex> ABSmartly.Utils.unit_to_string(125.75)
    "126"

# `utf8_bytes`
[🔗](https://github.com/absmartly/elixir-sdk/blob/v1.0.0/lib/absmartly/utils.ex#L72)

The UTF-8 bytes of a string, as a binary.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
