From 6df70e89d2cbfb0790e7d2b6e181bfebd29cb929 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 16 Nov 2024 13:03:45 -0400 Subject: data: factor out performAvailabilityCheck --- .../control-flow/helpers/performAvailabilityCheck.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/data/composite/control-flow/helpers/performAvailabilityCheck.js (limited to 'src/data/composite/control-flow/helpers') diff --git a/src/data/composite/control-flow/helpers/performAvailabilityCheck.js b/src/data/composite/control-flow/helpers/performAvailabilityCheck.js new file mode 100644 index 00000000..0e44ab59 --- /dev/null +++ b/src/data/composite/control-flow/helpers/performAvailabilityCheck.js @@ -0,0 +1,19 @@ +import {empty} from '#sugar'; + +export default function performAvailabilityCheck(value, mode) { + switch (mode) { + case 'null': + return value !== undefined && value !== null; + + case 'empty': + return value !== undefined && !empty(value); + + case 'falsy': + return !!value && (!Array.isArray(value) || !empty(value)); + + case 'index': + return typeof value === 'number' && value >= 0; + } + + return undefined; +} -- cgit 1.3.0-6-gf8a5