Utility functions for ABSmartly SDK.
Summary
Functions
Encode binary data as base64url without padding.
Choose a variant based on cumulative split probabilities.
Hash a unit identifier using MD5 and encode as base64url (no padding).
True when the value is a number.
True when the value is a plain object (a map that is not a struct).
True when the value is an asynchronous result (a Task), the Elixir
counterpart of a JavaScript promise.
Convert any value to a boolean.
Convert any value to a number (integer or float). Returns nil if conversion fails.
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.
The UTF-8 bytes of a string, as a binary.
Functions
Encode binary data as base64url without padding.
iex> ABSmartly.Utils.base64_url_no_padding("te")
"dGU"
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 a unit identifier using MD5 and encode as base64url (no padding).
Examples
iex> ABSmartly.Utils.hash_unit("bleh@absmartly.com")
"rcH4hfF5JRm9-sOLmWKubA"
True when the value is a number.
True when the value is a plain object (a map that is not a struct).
True when the value is an asynchronous result (a Task), the Elixir
counterpart of a JavaScript promise.
Convert any value to a boolean.
Convert any value to a number (integer or float). Returns nil if conversion fails.
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"
The UTF-8 bytes of a string, as a binary.