util.js
function(str, filter, settings) {
  // get filter style if provided
  var style;
  if (filter.hasStyle() && settings.style.isOverrideAllowed) {
    style = _.findWhere(settings.styles, { name: filter.style });
  }
  if (_.isUndefined(style)) {
    // if filter style not found, or no filter style set, use main style
    style = settings.style;
  }
  // get replacement grawlix
  var repl;
  if (!settings.isRandom && style.hasFixed(filter.word)) {
    // if in fixed replacement mode and style has a defined fixed replacement 
    // string for the filter's word 
    repl = style.getFixed(filter.word);
  } else {
    // if single-character style
    repl = generateGrawlix(str, filter, style);
  }
  // apply filter template if necessary
  if (filter.hasTemplate()) {
    repl = filter.template(repl);
  }
  // replace the match
  return str.replace(filter.regex, repl);
}
function(str, filter, settings) {
  // get filter style if provided
  var style;
  if (filter.hasStyle() && settings.style.isOverrideAllowed) {
    style = _.findWhere(settings.styles, { name: filter.style });
  }
  if (_.isUndefined(style)) {
    // if filter style not found, or no filter style set, use main style
    style = settings.style;
  }
  // get replacement grawlix
  var repl;
  if (!settings.isRandom && style.hasFixed(filter.word)) {
    // if in fixed replacement mode and style has a defined fixed replacement 
    // string for the filter's word 
    repl = style.getFixed(filter.word);
  } else {
    // if single-character style
    repl = generateGrawlix(str, filter, style);
  }
  // apply filter template if necessary
  if (filter.hasTemplate()) {
    repl = filter.template(repl);
  }
  // replace the match
  return str.replace(filter.regex, repl);
}
function ( str , filter , settings ) { // get filter style if provided var style ; if ( filter . hasStyle ( ) && settings . style . isOverrideAllowed ) { style = _ . findWhere ( settings . styles , { name : filter . style } ) ; } if ( _ . isUndefined ( style ) ) { // if filter style not found, or no filter style set, use main style style = settings . style ; } // get replacement grawlix var repl ; if ( ! settings . isRandom && style . hasFixed ( filter . word ) ) { // if in fixed replacement mode and style has a defined fixed replacement  // string for the filter's word  repl = style . getFixed ( filter . word ) ; } else { // if single-character style repl = generateGrawlix ( str , filter , style ) ; } // apply filter template if necessary if ( filter . hasTemplate ( ) ) { repl = filter . template ( repl ) ; } // replace the match return str . replace ( filter . regex , repl ) ; }
Replaces a filter match in a string
@param  {String}          str      Content string
@param  {GrawlixFilter}   filter   GrawlixFilter object
@param  {GrawlixSettings} settings GrawlixSettings object
@return {String}                   String with replacement applied
Replaces a filter match in a string