diff --git a/client/web/divkit/src/expressions/funcs/dict.ts b/client/web/divkit/src/expressions/funcs/dict.ts index 0fce58d24..e664fa24e 100644 --- a/client/web/divkit/src/expressions/funcs/dict.ts +++ b/client/web/divkit/src/expressions/funcs/dict.ts @@ -94,6 +94,13 @@ function getDictOptDict(ctx: EvalContext, dict: DictValue, ...path: StringValue[ } } +function containsKey(_ext: EvalContext, dict: DictValue, key: StringValue): BooleanValue { + return { + type: BOOLEAN, + value: key.value in dict.value ? 1 : 0 + }; +} + export function registerDict(): void { const STRING_VARARG = { type: STRING, @@ -158,4 +165,5 @@ export function registerDict(): void { registerMethod('getColor', [DICT, STRING_VARARG], getDictColor); registerMethod('getArray', [DICT, STRING_VARARG], getDictArray); registerMethod('getDict', [DICT, STRING_VARARG], getDictDict); + registerMethod('containsKey', [DICT, STRING], containsKey); } diff --git a/test_data/expression_test_data/methods_dict.json b/test_data/expression_test_data/methods_dict.json index c22341080..3d3e1899f 100644 --- a/test_data/expression_test_data/methods_dict.json +++ b/test_data/expression_test_data/methods_dict.json @@ -383,7 +383,8 @@ ], "platforms": [ "android", - "ios" + "ios", + "web" ] }, { @@ -402,7 +403,8 @@ ], "platforms": [ "android", - "ios" + "ios", + "web" ] }, { @@ -423,7 +425,8 @@ ], "platforms": [ "android", - "ios" + "ios", + "web" ] }, { @@ -444,7 +447,8 @@ ], "platforms": [ "android", - "ios" + "ios", + "web" ] }, { @@ -467,7 +471,8 @@ ], "platforms": [ "android", - "ios" + "ios", + "web" ] } ]