From e3e49ec926a85eee7889023f8d5a3d7819f56e59 Mon Sep 17 00:00:00 2001 From: 4eb0da <4eb0da@yandex-team.com> Date: Tue, 22 Jul 2025 15:44:47 +0300 Subject: [PATCH] len function commit_hash:bbac89dd05c977d0917c267464ba0774a751fed8 --- client/web/divkit/src/expressions/funcs/dict.ts | 10 ++++++++++ .../expression_test_data/function_signatures_dict.json | 3 ++- test_data/expression_test_data/functions_dict.json | 9 ++++++--- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/client/web/divkit/src/expressions/funcs/dict.ts b/client/web/divkit/src/expressions/funcs/dict.ts index 792e062db..9829a6504 100644 --- a/client/web/divkit/src/expressions/funcs/dict.ts +++ b/client/web/divkit/src/expressions/funcs/dict.ts @@ -1,3 +1,4 @@ +import { toBigInt } from '../bigint'; import { ARRAY, BOOLEAN, COLOR, DICT, INTEGER, NUMBER, STRING, URL } from '../const'; import type { BooleanValue, DictValue, EvalContext, EvalTypes, EvalTypesWithoutDatetime, EvalValue, IntegerValue, NumberValue, StringValue } from '../eval'; import { checkUrl, convertJsValueToDivKit, transformColorValue } from '../utils'; @@ -110,6 +111,13 @@ function isEmpty(_ext: EvalContext, dict: DictValue): BooleanValue { }; } +function len(_ext: EvalContext, dict: DictValue): IntegerValue { + return { + type: INTEGER, + value: toBigInt(Object.keys(dict.value).length) + }; +} + export function registerDict(): void { const STRING_VARARG = { type: STRING, @@ -176,4 +184,6 @@ export function registerDict(): void { registerMethod('getDict', [DICT, STRING_VARARG], getDictDict); registerMethod('containsKey', [DICT, STRING], containsKey); registerMethod('isEmpty', [DICT], isEmpty); + + registerFunc('len', [DICT], len); } diff --git a/test_data/expression_test_data/function_signatures_dict.json b/test_data/expression_test_data/function_signatures_dict.json index 95feba2ac..32bdff260 100644 --- a/test_data/expression_test_data/function_signatures_dict.json +++ b/test_data/expression_test_data/function_signatures_dict.json @@ -780,7 +780,8 @@ "result_type": "integer", "platforms": [ "android", - "ios" + "ios", + "web" ] }, { diff --git a/test_data/expression_test_data/functions_dict.json b/test_data/expression_test_data/functions_dict.json index c5eb31198..6df48c544 100644 --- a/test_data/expression_test_data/functions_dict.json +++ b/test_data/expression_test_data/functions_dict.json @@ -1479,7 +1479,8 @@ ], "platforms": [ "android", - "ios" + "ios", + "web" ] }, { @@ -1499,7 +1500,8 @@ ], "platforms": [ "android", - "ios" + "ios", + "web" ] }, { @@ -1521,7 +1523,8 @@ ], "platforms": [ "android", - "ios" + "ios", + "web" ] }, {