JavaScript: Clean way to set/remove a bool attribute

With Javascript I often have to do something like this:

   if (predicate) el.setAttribute('data-foo', '')
   else el.removeAttribute('data-foo')

what I would really like to do is this (nice and DRY):

   el.setBoolAttribute('data-foo', predicate)  // Desired function

Its a function I would like to use in the DOM, and web component shadow roots, in many places, so its not really a function I would like to import from a module. Does Javascript have any sort of native way?