lib/superstring/index.js
function (regex, fn) {
        var replacements = 0; // maintain a count of tokens replaced

        // to ensure we do not perform needless operations in the replacement, we use multiple replacement functions
        // after validating the parameters
        this.value = (this.value.replace(regex, _.isFunction(fn) ? function () {
            replacements += 1;
            return fn.apply(this, arguments);
        } : function () { // this case is returned when replacer is not a function (ensures we do not need to check it)
            replacements += 1;
            return fn;
        }));

        this.replacements = replacements; // store the last replacements
        replacements && (this.substitutions += 1); // if any replacement is done, count that some substitution was made
        return this;
    }
function (regex, fn) {
        var replacements = 0; // maintain a count of tokens replaced

        // to ensure we do not perform needless operations in the replacement, we use multiple replacement functions
        // after validating the parameters
        this.value = (this.value.replace(regex, _.isFunction(fn) ? function () {
            replacements += 1;
            return fn.apply(this, arguments);
        } : function () { // this case is returned when replacer is not a function (ensures we do not need to check it)
            replacements += 1;
            return fn;
        }));

        this.replacements = replacements; // store the last replacements
        replacements && (this.substitutions += 1); // if any replacement is done, count that some substitution was made
        return this;
    }
function ( regex , fn ) { var replacements = 0 ; // maintain a count of tokens replaced // to ensure we do not perform needless operations in the replacement, we use multiple replacement functions // after validating the parameters this . value = ( this . value . replace ( regex , _ . isFunction ( fn ) ? function ( ) { replacements += 1 ; return fn . apply ( this , arguments ) ; } : function ( ) { // this case is returned when replacer is not a function (ensures we do not need to check it) replacements += 1 ; return fn ; } ) ) ; this . replacements = replacements ; // store the last replacements replacements && ( this . substitutions += 1 ) ; // if any replacement is done, count that some substitution was made return this ; }
Equivalent to string replace but performs additional tracking of the number of tokens replaced

@param {RegExp|String} regex
@param {Function|String} fn
@returns {SuperString}
Equivalent to string replace but performs additional tracking of the number of tokens replaced