NAME

App::MineralUtils - Utilities related to mineral supplements

VERSION

This document describes version 0.013 of App::MineralUtils (from Perl distribution App-MineralUtils), released on 2024-07-05.

DESCRIPTION

This distributions provides the following command-line utilities:

FUNCTIONS

convert_calcium_unit

Usage:

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

Convert an iron quantity from one unit to another.

Examples:

  • Show all possible conversions:

    convert_calcium_unit();

    Result:

    [
      200,
      "OK",
      [
        {
          amount  => 1,
          unit    => "mg-ca-elem",
          summary => "Elemental calcium, in milligrams",
        },
        {
          amount  => 2.5,
          unit    => "mg-ca-carbonate",
          summary => "Calcium carbonate (CaCO3), in milligrams",
        },
        {
          amount  => 7.40740740740741,
          unit    => "mg-ca-pidolate",
          summary => "Calcium pidolate (C10H12CaN2O6), in milligrams",
        },
        {
          amount  => 5.43478260869565,
          unit    => "mg-ca-lactate",
          summary => "Calcium lactate (C6H10CaO6), in milligrams",
        },
      ],
      {
        "table.fields"        => ["amount", "unit", "summary"],
        "table.field_formats" => [
                                   ["number", { thousands_sep => "", precision => 3 }],
                                   undef,
                                   undef,
                                 ],
        "table.field_aligns"  => ["number", "left", "left"],
      },
    ]

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_iron_unit

Usage:

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

Convert an iron quantity from one unit to another.

Examples:

  • Show all possible conversions:

    convert_iron_unit();

    Result:

    [
      200,
      "OK",
      [
        {
          amount  => 1,
          unit    => "mg-fe-elem",
          summary => "Elemental iron, in milligrams",
        },
        {
          amount  => 4.97512437810945,
          unit    => "mg-ferrous-sulfate-heptahydrate",
          summary => "Ferrous sulphate heptahydrate (FeSO4.7H2O), in milligrams",
        },
      ],
      {
        "table.field_formats" => [
                                   ["number", { precision => 3, thousands_sep => "" }],
                                   undef,
                                   undef,
                                 ],
        "table.fields"        => ["amount", "unit", "summary"],
        "table.field_aligns"  => ["number", "left", "left"],
      },
    ]

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_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  => 6.17283950617284,
          unit    => "mg-trimagnesium-dicitrate",
          summary => "Magnesium citrate a.k.a trimagnesium dicitrate (C12H10Mg3O14), in milligrams",
        },
        {
          amount  => 8.84955752212389,
          unit    => "mg-magnesium-citrate-dibasic",
          summary => "Magnesium citrate dibasic (C6H6MgO7), in milligrams",
        },
        {
          amount  => 6.28930817610063,
          unit    => "mg-mg-citrate-anhydrous",
          summary => "Magnesium citrate anhydrous ((C6H5O7)2Mg3, C12H16Mg3O14), in milligrams",
        },
        {
          amount  => 6.89655172413793,
          unit    => "mg-mg-citrate-anhydrous-nowfoods",
          summary => "Magnesium citrate in NOW Foods supplement (anhydrous, C12H16Mg3O14, 90.9% pure, contains citric acid etc), in milligrams",
        },
        {
          amount  => 25,
          unit    => "mg-mg-citrate-nonahydrate",
          summary => "Magnesium citrate nonahydrate ((C6H5O7)2Mg3 \xB7 9H2O, C12H28Mg3O23) [most common hydrate form of Mg-citrate at room temp], in milligrams",
        },
        {
          amount  => 7.09219858156028,
          unit    => "mg-mg-glycinate-anhydrous",
          summary => "Magnesium glycinate/bisglycinate anhydrous (C4H8MgN2O4) [most common hydrate form of Mg-glycinate], in milligrams",
        },
        {
          amount  => 7.09219858156028,
          unit    => "mg-mg-bisglycinate-anhydrous",
          summary => "Magnesium glycinate/bisglycinate (C4H8MgN2O4) [most common hydrate form of Mg-glycinate], 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-dihydrate",
          summary => "Magnesium ascorbate hydrate (C12H14MgO12) [anhydrous and dihydrate are the most common hydrate forms of Mg-ascorbate at room temp], 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-anhydrous",
          summary => "Magnesium oxide anhydrous (MgO) [most common hydrate form of MgO at room temp], in milligrams",
        },
        {
          amount  => 8.33333333333333,
          unit    => "mg-mg-lactate-anhydrous",
          summary => "Magnesium lactate dihydrate (C6H10MgO6), 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",
        },
        {
          amount  => 4.95049504950495,
          unit    => "mg-mg-sulfate-anhydrous",
          summary => "Magnesium sulfate anhydrous (MgSO4), in milligrams",
        },
        {
          amount  => 5.68181818181818,
          unit    => "mg-mg-sulfate-monohydrate",
          summary => "Magnesium sulfate monohydrate (MgSO4.H2O), in milligrams",
        },
        {
          amount  => 10.1010101010101,
          unit    => "mg-mg-sulfate-heptahydrate",
          summary => "Magnesium sulfate heptahydrate (MgSO4.7H2O) a.k.a. Epsom salt, in milligrams",
        },
        {
          amount  => 3.47222222222222,
          unit    => "mg-mg-carbonate-anhydrous",
          summary => "Magnesium carbonate anhydrous (MgCO3), in milligrams",
        },
        {
          amount  => 6.02409638554217,
          unit    => "mg-mg-carbonate-trihydrate",
          summary => "Magnesium carbonate trihydrate (MgCO3.3H2O), in milligrams",
        },
        {
          amount  => 2.39808153477218,
          unit    => "mg-mg-hydroxide-anhydrous",
          summary => "Magnesium hydroxide anhydrous (Mg(OH)2), in milligrams",
        },
        {
          amount  => 5.68181818181818,
          unit    => "mg-mg-hydroxide-pentahydrate",
          summary => "Magnesium hydroxide pentahydrate (Mg(OH)2.5H2O), in milligrams",
        },
        {
          amount  => 5.84795321637427,
          unit    => "mg-mg-acetate-anhydrous",
          summary => "Magnesium acetate anhydrous (Mg(CH3COO)2), in milligrams",
        },
        {
          amount  => 8.84955752212389,
          unit    => "mg-mg-acetate-tetrahydrate",
          summary => "Magnesium acetate tetrahydrate (Mg(CH3COO)2.4H2O), in milligrams",
        },
        {
          amount  => 18.5185185185185,
          unit    => "mg-mg-gluconate-dihydrate",
          summary => "Magnesium gluconate dihydrate (C12H26MgO16), in milligrams",
        },
        {
          amount  => 17.8571428571429,
          unit    => "mg-mg-gluconate-hydrate",
          summary => "Magnesium gluconate dihydrate (C12H26MgO16), in milligrams",
        },
        {
          amount  => 8,
          unit    => "mg-mg-glycerophosphate-anhydrous",
          summary => "Magnesium glycerophosphate anhydrous (C\x{2083}H\x{2087}MgO\x{2086}P), in milligrams",
        },
        {
          amount  => 8.7719298245614,
          unit    => "mg-mg-glycerophosphate-hydrate",
          summary => "Magnesium glycerophosphate anhydrous (C\x{2083}H\x{2087}MgO\x{2086}P.H2O, C3H9MgO7P), in milligrams",
        },
        {
          amount  => 11.2359550561798,
          unit    => "mg-mg-taurate",
          summary => "Magnesium taurate (C4H12MgN2O6S2), 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 magnesium oxide provides 350 mg of elemental magnesium?:

    convert_magnesium_unit(quantity => "350 mg-mg-oxide-anhydrous", to_unit => "mg-mg-elem");

    Result:

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

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-anhydrous",
          summary => "Potassium chloride (KCl) anhydrous [most common hydrate form of KCl at room temp], in milligrams",
        },
        {
          amount  => 2.82485875706215,
          unit    => "mg-k-chloride-dihydrate",
          summary => "Potassium chloride dihydrate (KCl.2H2O) [unstable at room temp], in milligrams",
        },
        {
          amount  => 2.61096605744125,
          unit    => "mg-k-citrate-anhydrous",
          summary => "Tripotassium citrate anhydrous (K3C6H5O7), in milligrams",
        },
        {
          amount  => 2.76243093922652,
          unit    => "mg-k-citrate-monohydrate",
          summary => "Tripotassium citrate monohydrate (K3C6H5O7.H2O) [most common hydrate form of K-citrate at room temp], in milligrams",
        },
        {
          amount  => 1.76678445229682,
          unit    => "mg-k-carbonate-anhydrous",
          summary => "Potassium carbonate anhydrous (K2CO3), in milligrams",
        },
        {
          amount  => 2.2271714922049,
          unit    => "mg-k-carbonate-dihydrate",
          summary => "Potassium carbonate dihydrate (K2CO3.2H2O) [most common hydrate form of K-carbonate at room temp], in milligrams",
        },
        {
          amount  => 2.55754475703325,
          unit    => "mg-k-bicarbonate-anhydrous",
          summary => "Potassium bicarbonate anhydrous (KHCO3) [most common hydrate form of K-bicarbonate at room temp], in milligrams",
        },
        {
          amount  => 2.51256281407035,
          unit    => "mg-k-acetate-anhydrous",
          summary => "Potassium acetate anhydrous (C2H3O2K), in milligrams",
        },
        {
          amount  => 2.9673590504451,
          unit    => "mg-k-acetate-monohydrate",
          summary => "Potassium acetate monohydrate (C2H9KO5) [most common hydrate form of K-acetate at room temp], in milligrams",
        },
        {
          amount  => 3.89105058365759,
          unit    => "mg-k-acetate-trihydrate",
          summary => "Potassium acetate trihydrate (C2H9KO5), in milligrams",
        },
      ],
      {
        "table.field_aligns"  => ["number", "left", "left"],
        "table.field_formats" => [
                                   ["number", { thousands_sep => "", precision => 3 }],
                                   undef,
                                   undef,
                                 ],
        "table.fields"        => ["amount", "unit", "summary"],
      },
    ]
  • How much of potassium chloride provides 1000 mg of elemental potassium?:

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

    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-anhydrous", to_unit => "mg-k-elem");

    Result:

    [200, "OK", 524, {}]
  • A tablet supplement called KSR contains 600mg of potassium chloride; how much elemental potassium is that?:

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

    Result:

    [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-anhydrous");

    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.