handlebars-helpers icon indicating copy to clipboard operation
handlebars-helpers copied to clipboard

Array helper: concat

Open ericcornelissen opened this issue 5 years ago • 1 comments

Hey, awesome project. I just wanted to ask if anyone besides me is interested in a concat helper for arrays (and possibly other types as well, such as strings?). If so I would be interested in creating a PR for that.

Since I'm already using this helper myself, here is the code for it:

module.exports = function(arrayA, arrayB, options) {
  if (Array.isArray(arrayA) && !Array.isArray(arrayB)) {
    return arrayA;
  } else if (Array.isArray(arrayA) && Array.isArray(arrayB)) {
    return arrayA.concat(arrayB);
  } else {
    return [];
  }
}

ericcornelissen avatar Sep 27 '18 09:09 ericcornelissen

Thanks for the issue! A PR would be great and we can discuss any details in there.

Thanks!

doowb avatar Sep 27 '18 10:09 doowb