<commit_before>// # string
// A few quick string-related utility methods.

// [RequireJS](http://requirejs.org/) boilerplate, dependencies and
// [strict mode](http://mzl.la/1fRhnam)
if (typeof define !== 'function') {
  var define = require('amdefine')(module);
}

define(function() {

  'use strict';

  return {
    // `splice` inserts one string into another at a specified location.
    splice: function(source, location, toInsert) {
      if (location < 0 || location > source.length) {
        throw new Error('location ' + location + ' out of range');
      }
      return source.slice(0, location) + toInsert + source.slice(location);
    },

    // `capitalize` takes the first character of the provided string and makes it
    // uppercase.
    capitalize: function(source) {
      return source.charAt(0).toUpperCase() + source.slice(1);
    },

    // `truncate` returns a string with `limit` characters or less. If the original string
    // was longer than `limit` characters, it will be truncated to fit. Any truncated
    // string will end with an ellipsis ("...") to signify that it's missing info.
    truncate: function(limit, text) {
      var result;
      if (text.length > limit) {
        result = text.substring(0, limit - 3);
        result += '...';
        return result;
      }
      return text;
    },

    // `pluralize` is very simple - it takes a `count` as well as `singular`
    // and `plural` strings. It then returns a string with both the count and the
    // appropriate singular or plural label.
    pluralize: function(count, singular, plural) {
      if (count === 1) {
        return count + ' ' + singular;
      }
      return count + ' ' + plural;
    },

    // `normalizePhoneNumber` takes a number like '(800) 555-3333'
    // and turns it into '+18005553333', which can be used with Twilio.
    normalizePhoneNumber: function(number) {
      number = number.replace(/[() +-]/gi, '');
      if (number.length < 11) {
        number = '1' + number;
      }
      number = '+' + number;
      return number;
    },

    // `formatPhoneNumber` takes a normalized phone number and makes it
    // human-reasonable again.
    formatPhoneNumber: function(number) {
      if (number.length !== 12) {
        return number;
      }
      number = this.splice(number, 2, ' (');
      number = this.splice(number, 7, ') ');
      number = this.splice(number, 12, '-');

      return number;
    },

    // `repeat` repeats the first parameter `n` times.
    repeat: function(target, n) {
      if (n > 0) {
        return target + this.repeat(target, n - 1);
      }
      else {
        return '';
      }
    }
  };
});
<commit_msg>string.repeat now a loop; no longer recursive<commit_after>// # string
// A few quick string-related utility methods.

// [RequireJS](http://requirejs.org/) boilerplate, dependencies and
// [strict mode](http://mzl.la/1fRhnam)
if (typeof define !== 'function') {
  var define = require('amdefine')(module);
}

define(function() {

  'use strict';

  return {
    // `splice` inserts one string into another at a specified location.
    splice: function(source, location, toInsert) {
      if (location < 0 || location > source.length) {
        throw new Error('location ' + location + ' out of range');
      }
      return source.slice(0, location) + toInsert + source.slice(location);
    },

    // `capitalize` takes the first character of the provided string and makes it
    // uppercase.
    capitalize: function(source) {
      return source.charAt(0).toUpperCase() + source.slice(1);
    },

    // `truncate` returns a string with `limit` characters or less. If the original string
    // was longer than `limit` characters, it will be truncated to fit. Any truncated
    // string will end with an ellipsis ("...") to signify that it's missing info.
    truncate: function(limit, text) {
      var result;
      if (text.length > limit) {
        result = text.substring(0, limit - 3);
        result += '...';
        return result;
      }
      return text;
    },

    // `pluralize` is very simple - it takes a `count` as well as `singular`
    // and `plural` strings. It then returns a string with both the count and the
    // appropriate singular or plural label.
    pluralize: function(count, singular, plural) {
      if (count === 1) {
        return count + ' ' + singular;
      }
      return count + ' ' + plural;
    },

    // `normalizePhoneNumber` takes a number like '(800) 555-3333'
    // and turns it into '+18005553333', which can be used with Twilio.
    normalizePhoneNumber: function(number) {
      number = number.replace(/[() +-]/gi, '');
      if (number.length < 11) {
        number = '1' + number;
      }
      number = '+' + number;
      return number;
    },

    // `formatPhoneNumber` takes a normalized phone number and makes it
    // human-reasonable again.
    formatPhoneNumber: function(number) {
      if (number.length !== 12) {
        return number;
      }
      number = this.splice(number, 2, ' (');
      number = this.splice(number, 7, ') ');
      number = this.splice(number, 12, '-');

      return number;
    },

    // `repeat` repeats the first parameter `n` times.
    repeat: function(target, n) {
      if (n <= 0) {
        return '';
      }

      var result = '';
      for (var i = 0, max = n; i < max; i += 1) {
        result += target;
      }

      return result;
    }
  };
});

{'fraction_non_alphanumeric': 0.13661402864487698, 'fraction_numerical': 0.01487330150569225, 'mean_word_length': 2.327428222357972, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6299967', 'n_tokens_mistral': 1688, 'n_tokens_neox': 1583, 'n_words': 526}