<commit_before>'use strict';

var css = require('css');
var fs = require('fs');
var through = require('through2');
var gutil = require('gulp-util');
var PluginError = gutil.PluginError;

var PLUGIN_NAME = 'gulp-avoidfoit';

function avoidfoit(cssContent, options) {
  var jsCode = '',
    defaultOptions = {
      className: 'fonts-loaded',
      legacy: true
    },
    fontfaceobserver = options.legacy ? 'node_modules/gulp-avoidfoit/node_modules/fontfaceobserver/fontfaceobserver.standalone.js' : 'node_modules/gulp-avoidfoit/node_modules/fontfaceobserver/fontfaceobserver.js';

  // Manage plugin options
  options = options || defaultOptions;
  options.className = options.className !== "undefined" ? options.className : defaultOptions.className;
  options.legacy = options.legacy !== "undefined" ? options.legacy : defaultOptions.legacy;

  // Get fontfaceobserver.js content
  jsCode += fs.readFileSync(fontfaceobserver, 'utf8'); // Yep, this is ugly :(

  // Generates the custom js code
  (function () {
    var webFonts = [],
      promiseAll = [];
    jsCode += '(function (w){if( w.document.documentElement.className.indexOf( "' + options.className + '") > -1){return;}';
    // Scan and parse all css to json
    css.parse(cssContent)
      // Filter to get only @font-face rules
      .stylesheet.rules.filter(function (el) {
        return el.type === 'font-face';
      })
      // Generates the FontFaceObserver parameters
      .forEach(function (font, fontIndex) {
        webFonts.push(['', {}]);
        font = font.declarations.forEach(function (theProperty) {
          if (theProperty.property === 'font-family') {
            webFonts[fontIndex][0] = theProperty.value;
          }
          if (theProperty.property === 'font-style' && theProperty.value !== 'normal') {
            webFonts[fontIndex][1].style = theProperty.value;
          }
          if (theProperty.property === 'font-weight' && theProperty.value !== 'normal' && theProperty.value !== '400') {
            webFonts[fontIndex][1].weight = theProperty.value;
          }
        });
      });
    // Generates a FontFaceObserver instace for each webfont
    webFonts.forEach(function (font, fontIndex) {<commit_msg>Yeah, finish<commit_after>'use strict';

var css = require('css');
var fs = require('fs');
var through = require('through2');
var gutil = require('gulp-util');
var PluginError = gutil.PluginError;

var PLUGIN_NAME = 'gulp-avoidfoit';

function avoidfoit(cssContent, options) {
  var jsCode = '',
    defaultOptions = {
      className: 'fonts-loaded',
      legacy: true
    },
    fontfaceobserver = '';

  // Manage plugin options
  options = options || defaultOptions;
  options.className = options.className !== "undefined" ? options.className : defaultOptions.className;
  options.legacy = options.legacy !== "undefined" ? options.legacy : defaultOptions.legacy;

  // Get fontfaceobserver.js content
  fontfaceobserver = options.legacy ? 'node_modules/gulp-avoidfoit/node_modules/fontfaceobserver/fontfaceobserver.standalone.js' : 'node_modules/gulp-avoidfoit/node_modules/fontfaceobserver/fontfaceobserver.js';
  jsCode += fs.readFileSync(fontfaceobserver, 'utf8'); // Yep, this is ugly :(

  // Generates the custom js code
  (function () {
    var webFonts = [],
      promiseAll = [];
    jsCode += '(function (w){if( w.document.documentElement.className.indexOf( "' + options.className + '") > -1){return;}';
    // Scan and parse all css to json
    css.parse(cssContent)
      // Filter to get only @font-face rules
      .stylesheet.rules.filter(function (el) {
        return el.type === 'font-face';
      })
      // Generates the FontFaceObserver parameters
      .forEach(function (font, fontIndex) {
        webFonts.push(['', {}]);
        font = font.declarations.forEach(function (theProperty) {
          if (theProperty.property === 'font-family') {
            webFonts[fontIndex][0] = theProperty.value;
          }
          if (theProperty.property === 'font-style' && theProperty.value !== 'normal') {
            webFonts[fontIndex][1].style = theProperty.value;
          }
          if (theProperty.property === 'font-weight' && theProperty.value !== 'normal' && theProperty.value !== '400') {
            webFonts[fontIndex][1].weight = theProperty.value;
          }
        });
      });
    // Generates a FontFaceObserver instace for each webfont
    webFonts.forEach(function (font, fontIndex) {
{'fraction_non_alphanumeric': 0.14378937893789379, 'fraction_numerical': 0.004050405040504051, 'mean_word_length': 3.1815616180620885, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6128072', 'n_tokens_mistral': 1333, 'n_tokens_neox': 1297, 'n_words': 274}