NAME
    App::MineralUtils - Utilities related to mineral supplements

VERSION
    This document describes version 0.012 of App::MineralUtils (from Perl
    distribution App-MineralUtils), released on 2024-03-22.

DESCRIPTION
    This distributions provides the following command-line utilities:

    *   convert-magnesium-unit

    *   convert-potassium-unit

    *   convert-sodium-unit

FUNCTIONS
  convert_magnesium_unit
    Usage:

     convert_magnesium_unit(%args) -> [$status_code, $reason, $payload, \%result_meta]

    Convert a magnesium quantity from one unit to another.

    Examples:

    *   Show all possible conversions:

         convert_magnesium_unit();

        Result:

         [
           200,
           "OK",
           [
             {
               amount  => 1,
               unit    => "mg-mg-elem",
               summary => "Elemental magnesium, in milligrams",
             },
             {
               amount  => 8.84955752212389,
               unit    => "mg-mg-citrate",
               summary => "Magnesium citrate (C6H6MgO7), in milligrams",
             },
             {
               amount  => 6.28930817610063,
               unit    => "mg-mg-citrate-ah",
               summary => "Magnesium citrate anhydrous (C6H5Mg3O7), in milligrams",
             },
             {
               amount  => 6.89655172413793,
               unit    => "mg-mg-citrate-ah-nowfoods",
               summary => "Magnesium citrate in NOW Foods supplement (anhydrous, C6H5Mg3O7, 90.9% pure, contains citric acid etc), in milligrams",
             },
             {
               amount  => 7.09219858156028,
               unit    => "mg-mg-glycinate",
               summary => "Magnesium glycinate/bisglycinate (C4H8MgN2O4), in milligrams",
             },
             {
               amount  => 7.09219858156028,
               unit    => "mg-mg-bisglycinate",
               summary => "Magnesium glycinate/bisglycinate (C4H8MgN2O4), in milligrams",
             },
             {
               amount  => 10,
               unit    => "mg-mg-bisglycinate-nowfoods",
               summary => "Magnesium bisglycinate in NOW Foods supplement (C4H8MgN2O4, 70.5% pure, contains citric acid etc), in milligrams",
             },
             {
               amount  => 15.3846153846154,
               unit    => "mg-mg-ascorbate",
               summary => "Magnesium ascorbate (C12H14MgO12), in milligrams",
             },
             {
               amount  => 11.4942528735632,
               unit    => "mg-mg-pidolate",
               summary => "Magnesium pidolate (C10H12MgN2O6), in milligrams",
             },
             {
               amount  => 12.0481927710843,
               unit    => "mg-mg-l-threonate",
               summary => "Magnesium L-threonate (C8H14MgO10), in milligrams",
             },
             {
               amount  => 1.65837479270315,
               unit    => "mg-mg-oxide",
               summary => "Magnesium oxide (MgO), in milligrams",
             },
             {
               amount  => 9.80392156862745,
               unit    => "mg-mg-lactate-dihydrate",
               summary => "Magnesium lactate dihydrate (C6H14MgO8), in milligrams",
             },
             {
               amount  => 3.92156862745098,
               unit    => "mg-mg-chloride-ah",
               summary => "Magnesium chloride (anhydrous, MgCl2), in milligrams",
             },
             {
               amount  => 8.33333333333333,
               unit    => "mg-mg-chloride-hexahydrate",
               summary => "Magnesium chloride (hexahydrate, H12Cl2MgO6), in milligrams",
             },
             {
               amount  => 6.45161290322581,
               unit    => "mg-mg-malate",
               summary => "Magnesium malate (C4H4MgO5), in milligrams",
             },
             {
               amount  => 8.62068965517241,
               unit    => "mg-mg-malate-trihydrate",
               summary => "Magnesium malate (MgC4H4O5.3H2O), in milligrams",
             },
           ],
           {
             "table.field_aligns"  => ["number", "left", "left"],
             "table.fields"        => ["amount", "unit", "summary"],
             "table.field_formats" => [
                                        ["number", { precision => 3, thousands_sep => "" }],
                                        undef,
                                        undef,
                                      ],
           },
         ]

    *   Find out how many milligrams of elemental magnesium is in 1000mg of
        pure magnesium l-threonate (but note that a supplement product might
        not contain 100%-pure compound):

         convert_magnesium_unit(quantity => "1000 mg-mg-l-threonate", to_unit => "mg-mg-elem");

        Result:

         [200, "OK", 83, {}]

    *   Find out how many milligrams of elemental magnesium is in 3g (1
        recommended serving) of NOW Foods magnesium citrate powder
        (magnesium content is as advertised on the label):

         convert_magnesium_unit(
           quantity => "3000 mg-mg-citrate-ah-nowfoods",
           to_unit  => "mg-mg-elem"
         );

        Result:

         [200, "OK", 435, {}]

    *   Find out how many milligrams of elemental magnesium is in 2.5g (1
        recommended serving) of NOW Foods magnesium bisglycinate powder
        (magnesium content is as advertised on the label):

         convert_magnesium_unit(
           quantity => "2500 mg-mg-bisglycinate-nowfoods",
           to_unit  => "mg-mg-elem"
         );

        Result:

         [200, "OK", 250, {}]

    *   If I want to supplement 350mg elemental magnesium, how much of each
        compound should we use? (This does not yet take bioavailability into
        account):

         convert_magnesium_unit(quantity => "350 mg-mg-elem");

        Result:

         [
           200,
           "OK",
           [
             {
               amount  => 350,
               unit    => "mg-mg-elem",
               summary => "Elemental magnesium, in milligrams",
             },
             {
               amount  => 3097.34513274336,
               unit    => "mg-mg-citrate",
               summary => "Magnesium citrate (C6H6MgO7), in milligrams",
             },
             {
               amount  => 2201.25786163522,
               unit    => "mg-mg-citrate-ah",
               summary => "Magnesium citrate anhydrous (C6H5Mg3O7), in milligrams",
             },
             {
               amount  => 2413.79310344828,
               unit    => "mg-mg-citrate-ah-nowfoods",
               summary => "Magnesium citrate in NOW Foods supplement (anhydrous, C6H5Mg3O7, 90.9% pure, contains citric acid etc), in milligrams",
             },
             {
               amount  => 2482.2695035461,
               unit    => "mg-mg-glycinate",
               summary => "Magnesium glycinate/bisglycinate (C4H8MgN2O4), in milligrams",
             },
             {
               amount  => 2482.2695035461,
               unit    => "mg-mg-bisglycinate",
               summary => "Magnesium glycinate/bisglycinate (C4H8MgN2O4), in milligrams",
             },
             {
               amount  => 3500,
               unit    => "mg-mg-bisglycinate-nowfoods",
               summary => "Magnesium bisglycinate in NOW Foods supplement (C4H8MgN2O4, 70.5% pure, contains citric acid etc), in milligrams",
             },
             {
               amount  => 5384.61538461538,
               unit    => "mg-mg-ascorbate",
               summary => "Magnesium ascorbate (C12H14MgO12), in milligrams",
             },
             {
               amount  => 4022.98850574713,
               unit    => "mg-mg-pidolate",
               summary => "Magnesium pidolate (C10H12MgN2O6), in milligrams",
             },
             {
               amount  => 4216.86746987952,
               unit    => "mg-mg-l-threonate",
               summary => "Magnesium L-threonate (C8H14MgO10), in milligrams",
             },
             {
               amount  => 580.431177446103,
               unit    => "mg-mg-oxide",
               summary => "Magnesium oxide (MgO), in milligrams",
             },
             {
               amount  => 3431.37254901961,
               unit    => "mg-mg-lactate-dihydrate",
               summary => "Magnesium lactate dihydrate (C6H14MgO8), in milligrams",
             },
             {
               amount  => 1372.54901960784,
               unit    => "mg-mg-chloride-ah",
               summary => "Magnesium chloride (anhydrous, MgCl2), in milligrams",
             },
             {
               amount  => 2916.66666666667,
               unit    => "mg-mg-chloride-hexahydrate",
               summary => "Magnesium chloride (hexahydrate, H12Cl2MgO6), in milligrams",
             },
             {
               amount  => 2258.06451612903,
               unit    => "mg-mg-malate",
               summary => "Magnesium malate (C4H4MgO5), in milligrams",
             },
             {
               amount  => 3017.24137931034,
               unit    => "mg-mg-malate-trihydrate",
               summary => "Magnesium malate (MgC4H4O5.3H2O), in milligrams",
             },
           ],
           {
             "table.field_aligns"  => ["number", "left", "left"],
             "table.fields"        => ["amount", "unit", "summary"],
             "table.field_formats" => [
                                        ["number", { precision => 3, thousands_sep => "" }],
                                        undef,
                                        undef,
                                      ],
           },
         ]

    *   How much elemental magnesium is in 1000mg (1g) of magnesium chloride
        powder in capsule form? The chloride is in the common hexahydrate
        form:

         convert_magnesium_unit(
           quantity => "1000 mg-mg-chloride-hexahydrate",
           to_unit  => "mg-mg-elem"
         );

        Result:

         [200, "OK", 120, {}]

    If target unit is not specified, will show all known conversions.

    This function is not exported.

    Arguments ('*' denotes required arguments):

    *   quantity => *str* (default: "1 mg")

        (No description)

    *   to_unit => *str*

        (No description)

    Returns an enveloped result (an array).

    First element ($status_code) is an integer containing HTTP-like status
    code (200 means OK, 4xx caller error, 5xx function error). Second
    element ($reason) is a string containing error message, or something
    like "OK" if status is 200. Third element ($payload) is the actual
    result, but usually not present when enveloped result is an error
    response ($status_code is not 2xx). Fourth element (%result_meta) is
    called result metadata and is optional, a hash that contains extra
    information, much like how HTTP response headers provide additional
    metadata.

    Return value: (any)

  convert_potassium_unit
    Usage:

     convert_potassium_unit(%args) -> [$status_code, $reason, $payload, \%result_meta]

    Convert a potassium quantity from one unit to another.

    Examples:

    *   Show all possible conversions:

         convert_potassium_unit();

        Result:

         [
           200,
           "OK",
           [
             {
               amount  => 1,
               unit    => "mg-k-elem",
               summary => "Elemental potassium, in milligrams",
             },
             {
               amount  => 1.90839694656489,
               unit    => "mg-k-chloride",
               summary => "Potassium chloride (KCl), in milligrams",
             },
             {
               amount  => 1.90839694656489,
               unit    => "mg-k-cl",
               summary => "Potassium chloride (KCl), in milligrams",
             },
             {
               amount  => 2.61096605744125,
               unit    => "mg-k-citrate",
               summary => "Potassium citrate (K3C6H5O7), in milligrams",
             },
           ],
           {
             "table.field_formats" => [
                                        ["number", { precision => 3, thousands_sep => "" }],
                                        undef,
                                        undef,
                                      ],
             "table.fields"        => ["amount", "unit", "summary"],
             "table.field_aligns"  => ["number", "left", "left"],
           },
         ]

    *   How much of potassium chloride provides 1000 mg of elemental
        potassium?:

         convert_potassium_unit(quantity => "1000 mg-k-elem", to_unit => "mg-k-cl");

        Result:

         [200, "OK", 1908.39694656489, {}]

    *   How much elemental potassium is in 1000mg (1g) of potassium chloride
        powder in capsule form?:

         convert_potassium_unit(quantity => "1000 mg-k-chloride", to_unit => "mg-k-chloride");

        Result:

         [200, "OK", 1000, {}]

    *   A tablet supplement called KSR contains 600mg of potassium chloride;
        how much elemental potassium is that?:

         convert_potassium_unit(quantity => "600 mg-k-chloride", to_unit => "mg-k-elem"); # -> [200, "OK", 314.4, {}]

    *   Recommended daily intake (DV) of (elemental) potassium for adults
        and children 4 years or older is 4,700mg according to US FDA; how
        much is that equivalent to in KCl? Note that it is *NOT* recommended
        (and most probably dangerous) to take KCl supplement that much as
        potassium is contained in other sources too:

         convert_potassium_unit(quantity => "4700 mg-k-elem", to_unit => "mg-k-chloride");

        Result:

         [200, "OK", 8969.46564885496, {}]

    If target unit is not specified, will show all known conversions.

    This function is not exported.

    Arguments ('*' denotes required arguments):

    *   quantity => *str* (default: "1 mg")

        (No description)

    *   to_unit => *str*

        (No description)

    Returns an enveloped result (an array).

    First element ($status_code) is an integer containing HTTP-like status
    code (200 means OK, 4xx caller error, 5xx function error). Second
    element ($reason) is a string containing error message, or something
    like "OK" if status is 200. Third element ($payload) is the actual
    result, but usually not present when enveloped result is an error
    response ($status_code is not 2xx). Fourth element (%result_meta) is
    called result metadata and is optional, a hash that contains extra
    information, much like how HTTP response headers provide additional
    metadata.

    Return value: (any)

  convert_sodium_unit
    Usage:

     convert_sodium_unit(%args) -> [$status_code, $reason, $payload, \%result_meta]

    Convert a sodium quantity from one unit to another.

    Examples:

    *   Show all possible conversions:

         convert_sodium_unit();

        Result:

         [
           200,
           "OK",
           [
             {
               amount  => 1,
               unit    => "mg-na-elem",
               summary => "Elemental sodium, in milligrams",
             },
             {
               amount  => 2.54452926208651,
               unit    => "mg-na-chloride",
               summary => "Sodium chloride (NaCl), in milligrams",
             },
             {
               amount  => 2.54452926208651,
               unit    => "mg-na-cl",
               summary => "Sodium chloride (NaCl), in milligrams",
             },
             {
               amount  => 11.2359550561798,
               unit    => "mg-na-citrate",
               summary => "Sodium citrate (Na3C6H5O7), in milligrams",
             },
           ],
           {
             "table.field_aligns"  => ["number", "left", "left"],
             "table.fields"        => ["amount", "unit", "summary"],
             "table.field_formats" => [
                                        ["number", { thousands_sep => "", precision => 3 }],
                                        undef,
                                        undef,
                                      ],
           },
         ]

    *   How much of sodium chloride provides 1000 mg of elemental sodium?:

         convert_sodium_unit(quantity => "1000 mg-na-elem", to_unit => "mg-na-cl");

        Result:

         [200, "OK", 2544.52926208651, {}]

    If target unit is not specified, will show all known conversions.

    This function is not exported.

    Arguments ('*' denotes required arguments):

    *   quantity => *str* (default: "1 mg")

        (No description)

    *   to_unit => *str*

        (No description)

    Returns an enveloped result (an array).

    First element ($status_code) is an integer containing HTTP-like status
    code (200 means OK, 4xx caller error, 5xx function error). Second
    element ($reason) is a string containing error message, or something
    like "OK" if status is 200. Third element ($payload) is the actual
    result, but usually not present when enveloped result is an error
    response ($status_code is not 2xx). Fourth element (%result_meta) is
    called result metadata and is optional, a hash that contains extra
    information, much like how HTTP response headers provide additional
    metadata.

    Return value: (any)

HOMEPAGE
    Please visit the project's homepage at
    <https://metacpan.org/release/App-MineralUtils>.

SOURCE
    Source repository is at
    <https://github.com/perlancar/perl-App-MineralUtils>.

SEE ALSO
    App::VitaminUtils

    Physics::Unit

AUTHOR
    perlancar <perlancar@cpan.org>

CONTRIBUTING
    To contribute, you can send patches by email/via RT, or send pull
    requests on GitHub.

    Most of the time, you don't need to build the distribution yourself. You
    can simply modify the code, then test via:

     % prove -l

    If you want to build the distribution (e.g. to try to install it locally
    on your system), you can install Dist::Zilla,
    Dist::Zilla::PluginBundle::Author::PERLANCAR,
    Pod::Weaver::PluginBundle::Author::PERLANCAR, and sometimes one or two
    other Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps
    required beyond that are considered a bug and can be reported to me.

COPYRIGHT AND LICENSE
    This software is copyright (c) 2024, 2022, 2021 by perlancar
    <perlancar@cpan.org>.

    This is free software; you can redistribute it and/or modify it under
    the same terms as the Perl 5 programming language system itself.

BUGS
    Please report any bugs or feature requests on the bugtracker website
    <https://rt.cpan.org/Public/Dist/Display.html?Name=App-MineralUtils>

    When submitting a bug or request, please include a test-file or a patch
    to an existing test-file that illustrates the bug or desired feature.