luci-base: add uci.get_bool to allow cleanup of app code
authorEric Fahlgren <[email protected]>
Sat, 8 Feb 2025 16:41:56 +0000 (08:41 -0800)
committerPaul Donald <[email protected]>
Tue, 11 Mar 2025 14:06:09 +0000 (15:06 +0100)
commitdea8d79888f862c82953b775e55f4d0c672cc897
tree4f86e3c7efa93c1930c0b37876cde24f9dc1265a
parent8b00d023b0335783dc459a738a1b1e9c2be9cacc
luci-base: add uci.get_bool to allow cleanup of app code

Any number of apps read boolean values from configuration files, then use
various inconsistent means for checking truth values.  The get_bool function
allows app authors to fetch the value without regard for how it is represented
in the config file.

For example, this

    let enabled = uci.get('system', 'ntp', 'enable_server');
    if (enabled == '1') ...

could become the more natural

    let enabled = uci.get_bool('system', 'ntp', 'enable_server');
    if (enabled) ...

Signed-off-by: Eric Fahlgren <[email protected]>
modules/luci-base/htdocs/luci-static/resources/uci.js