File tree 1 file changed +32
-0
lines changed 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -5772,6 +5772,38 @@ registerContainerHelpers(Handlebars& hbs)
5772
5772
hbs.registerHelper (" del" , del_fn);
5773
5773
hbs.registerHelper (" delete" , del_fn);
5774
5774
5775
+ static auto find_fn = dom::makeInvocable ([](
5776
+ dom::Value range, dom::Value const & val) -> dom::Value {
5777
+ if (range.isArray ())
5778
+ {
5779
+ auto const & arr = range.getArray ();
5780
+ auto const n = static_cast <std::int64_t >(arr.size ());
5781
+ for (std::int64_t i = 0 ; i < n; i++)
5782
+ {
5783
+ if (arr[i] == val)
5784
+ return i;
5785
+ }
5786
+ return static_cast <std::int64_t >(-1 );
5787
+ }
5788
+ else if (range.isObject ())
5789
+ {
5790
+ auto const & obj = range.getObject ();
5791
+ for (auto const & [k, v]: obj)
5792
+ {
5793
+ if (v == val)
5794
+ return k;
5795
+ }
5796
+ return nullptr ;
5797
+ }
5798
+ else
5799
+ {
5800
+ return range;
5801
+ }
5802
+ });
5803
+
5804
+ hbs.registerHelper (" find" , find_fn);
5805
+ hbs.registerHelper (" index_of" , find_fn);
5806
+
5775
5807
static auto has_fn = dom::makeInvocable ([](
5776
5808
dom::Value const & ctx, dom::Value const & prop)
5777
5809
{
You can’t perform that action at this time.
0 commit comments