diff --git a/src/widgets/customapi/component.jsx b/src/widgets/customapi/component.jsx index dcd238a51..3f1825b25 100644 --- a/src/widgets/customapi/component.jsx +++ b/src/widgets/customapi/component.jsx @@ -4,16 +4,6 @@ import Container from "components/services/widget/container"; import Block from "components/services/widget/block"; import useWidgetAPI from "utils/proxy/use-widget-api"; -function getLength(data) { - if (Array.isArray(data) || typeof data === "string") { - return data.length; - } else if (typeof data === "object" && data !== null) { - return Object.keys(data).length; - } else { - return NaN; - } -} - function getValue(field, data) { let value = data; let lastField = field; @@ -42,6 +32,16 @@ function getValue(field, data) { return value[lastField] ?? null; } +function getSize(data) { + if (Array.isArray(data) || typeof data === "string") { + return data.length; + } else if (typeof data === "object" && data !== null) { + return Object.keys(data).length; + } + + return NaN; +} + function formatValue(t, mapping, rawValue) { let value = rawValue; @@ -101,7 +101,7 @@ function formatValue(t, mapping, rawValue) { }); break; case "size": - value = t("common.number", { value: getLength(value) }); + value = t("common.number", { value: getSize(value) }); break; case "text": default: