<commit_before>// A `yarn` is a `String` that knows how to display itself stylishly.
return (function(){ var yarn, csi;
  yarn = new(Object);
  
  yarn.errors = {
    unknownStyle: new(Error)("That is an invalid style")
  };
  
  // Constructs a new `yarn`, given a style and some other `String`s or
  // `yarns`.
  // 
  // Accepts a style (or an array of styles), followed by one or more `String`
  // or `yarn` children. Order of children is preserved.
  yarn.constructor = function (styles, element1, element2) {
    arguments = Array.prototype.slice.call(arguments);
    styles = arguments.shift() || new(Array);
    
    this.elements = arguments;
    this.strip();
    styles.forEach(function (style) { this.style(style) });
  };
  
  // Applies a new style
  yarn.style = function (style) {
    if (yarn.ansiCodes[style] === 'undefined') {
      throw(yarn.errors.unknownStyle) };
    
    this.styles.push(style);
  };
  
  // Clears all styles
  yarn.strip = function () { this.styles = new(Array) };
  
  // Where the magic happens. Converts a `yarn` into a plain `String`,
  // converting styles into ANSI codes.
  //--
  // TODO: Support output to HTML, for inserting into a document as debugging
  //       info.
  yarn.toString = function (containing) { var used, out;
    out = new(Array), used = new(Array);
    
    this.styles.forEach(function (style) { var code;
      if (typeof containing === 'undefined' ||
          !containing.some(function (cStyle) {
        if (Array.isArray(cStyle)) { return(cStyle.indexOf(style) !== -1) }
                              else { return(cStyle === style) }
        })) {
          used.push(style);
          code = yarn.ansiCodes[style];
          out.push(csi + (Array.isArray(code) ? code[0] : code) + sgr);
    } });
    
    this.elements.forEach(function (element) {
      out.push(element.toString());
    });
    
    used.forEach(function (style) { var code;
      code = yarn.ansiCodes[style];
      out.push(csi + (Array.isArray(code) ? code[1] : yarn.ansiCodes['reset']) + sgr);
    });
    
    return out.join('');
  };
  
  csi = "\033[";
  sgr = 'm';
  yarn.ansiCodes = { 'reset': 0,
    'bold':          [1, 22],
    'underline':     [4, 24],
    'blink':         [5, 25],
    'negative':      [7, 27],
    'inverse':       [7, 27],
    
    'black':      30, 'bg-black':      40,
    'black-hi':   90, 'bg-black-hi':   100,<commit_msg>More intelligently handling `containing`<commit_after>// A `yarn` is a `String` that knows how to display itself stylishly.
return (function(){ var yarn, csi;
  yarn = new(Object);
  
  yarn.errors = {
    unknownStyle: new(Error)("That is an invalid style")
  };
  
  // Constructs a new `yarn`, given a style and some other `String`s or
  // `yarns`.
  // 
  // Accepts a style (or an array of styles), followed by one or more `String`
  // or `yarn` children. Order of children is preserved.
  yarn.constructor = function (styles, element1, element2) {
    arguments = Array.prototype.slice.call(arguments);
    styles = arguments.shift() || new(Array);
    
    this.elements = arguments;
    this.strip();
    styles.forEach(function (style) { this.style(style) });
  };
  
  // Applies a new style
  yarn.style = function (style) {
    if (yarn.ansiCodes[style] === 'undefined') {
      throw(yarn.errors.unknownStyle) };
    
    this.styles.push(style);
  };
  
  // Clears all styles
  yarn.strip = function () { this.styles = new(Array) };
  
  // Where the magic happens. Converts a `yarn` into a plain `String`,
  // converting styles into ANSI codes.
  //--
  // TODO: Support output to HTML, for inserting into a document as debugging
  //       info.
  yarn.toString = function (containing) { var used, out;
    out = new(Array), used = new(Array), containing = containing || new(Array);
    
    this.styles.forEach(function (style) { var code;
      if (!containing.some(function (container) {
            return(container.styles.indexOf(style) !== -1) } )) {
        used.push(style);
        code = yarn.ansiCodes[style];
        out.push(csi + (Array.isArray(code) ? code[0] : code) + sgr);
    } });
    
    containing.push(this);
    this.elements.forEach(function (element) {
      out.push(element.toString(containing));
    });
    containing.pop();
    
    used.forEach(function (style) { var code;
      code = yarn.ansiCodes[style];
      out.push(csi + (Array.isArray(code) ? code[1] : yarn.ansiCodes['reset']) + sgr);
    });
    
    return out.join('');
  };
  
  csi = "\033[";
  sgr = 'm';
  yarn.ansiCodes = { 'reset': 0,
    'bold':          [1, 22],
    'underline':     [4, 24],
    'blink':         [5, 25],
    'negative':      [7, 27],
    'inverse':       [7, 27],
    
    'black':      30, 'bg-black':      40,
    'black-hi':   90, 'bg-black-hi':   100,
{'fraction_non_alphanumeric': 0.1608144608352379, 'fraction_numerical': 0.013712861001454394, 'mean_word_length': 2.4312188168210978, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1507919', 'n_tokens_mistral': 1639, 'n_tokens_neox': 1590, 'n_words': 413}