View Source UspsEx.Util (usps_ex v2023.1.27)
Utils for UspsEx
.
Link to this section Summary
Functions
Returns true
for nil
, empty strings, and strings only containing
whitespace. Returns false
otherwise.
Converts centimeters to inches.
Converts inches to centimeters.
Converts kilograms to pounds.
Converts pounds to kilograms.
Takes a price and multiplies it by 100. Accepts nil, floats, integers, and strings.
Takes a price and divides it by 100, returning a string representation. This
is used for API calls that require dollars instead of cents. Unlike
price_to_cents
, this only accepts integers and nil. Otherwise, it will
raise an exception.
Returns the given map with keys converted to strings, and the values trimmed (if the values are also strings).
Removes accents/ligatures from letters.
Link to this section Functions
Returns true
for nil
, empty strings, and strings only containing
whitespace. Returns false
otherwise.
iex> Util.blank?(nil)
true
iex> Util.blank?("")
true
iex> Util.blank?(" ")
true
iex> Util.blank?(" \t\r\n ")
true
iex> Util.blank?("Test")
false
iex> Util.blank?(100)
false
Converts centimeters to inches.
iex> Util.cm_to_inches(10)
3.9
iex> Util.cm_to_inches(0)
0.0
Converts inches to centimeters.
iex> Util.inches_to_cm(10)
25.4
iex> Util.inches_to_cm(0)
0.0
Converts kilograms to pounds.
iex> Util.kgs_to_lbs(10)
22.0
iex> Util.kgs_to_lbs(0)
0.0
Converts pounds to kilograms.
iex> Util.lbs_to_kgs(10)
4.5
iex> Util.lbs_to_kgs(0)
0.0
Takes a price and multiplies it by 100. Accepts nil, floats, integers, and strings.
iex> Util.price_to_cents(nil)
0
iex> Util.price_to_cents(0)
0
iex> Util.price_to_cents(28.00)
2800
iex> Util.price_to_cents("28.00")
2800
iex> Util.price_to_cents("28")
2800
iex> Util.price_to_cents(28)
2800
Takes a price and divides it by 100, returning a string representation. This
is used for API calls that require dollars instead of cents. Unlike
price_to_cents
, this only accepts integers and nil. Otherwise, it will
raise an exception.
iex> Util.price_to_dollars(nil)
"0.00"
iex> Util.price_to_dollars(200_00)
"200"
iex> Util.price_to_dollars("20000")
** (FunctionClauseError) no function clause matching in UspsEx.Util.price_to_dollars/1
Returns the given map with keys converted to strings, and the values trimmed (if the values are also strings).
iex> Util.stringify_and_trim(%{foo: " bar "})
%{"foo" => "bar"}
Removes accents/ligatures from letters.
iex> Util.unaccent("Curaçao")
"Curacao"
iex> Util.unaccent("Republic of Foo (the)")
"Republic of Foo (the)"
iex> Util.unaccent("Åland Islands")
"Aland Islands"