kgar / foundry-vtt-more-handlebars-helpers

A Foundry VTT Module which registers a some additional handlebars helpers.
MIT License
2 stars 0 forks source link

Request: Split #1

Closed ObsidianTTRPGProject closed 11 months ago

ObsidianTTRPGProject commented 11 months ago

Can you please add:

Split {{split}} Split string by the given character.

Params string {String}: The string to split. returns {String} character: Default is an empty string. Example

Example {{split "a,b,c" ","}}

Helper

helpers.split = function(str, ch) {
  if (!util.isString(str)) return '';
  if (!util.isString(ch)) ch = ',';
  return str.split(ch);
};
kgar commented 11 months ago

Can do!

The code sample in the issue has brought to mind that I need to make some decisions on how to handle when a non-string is provided to string-based helpers.

The sample code provides a fallback for the text and for the separator.

Check out the resulting code and let me know if you have any thoughts on this.

ObsidianTTRPGProject commented 11 months ago

Thank you. This works perfectly!