index.js
function helper(pluginOptions, doValidation) {
  const options = mergeOptions(pluginOptions);

  return through.obj((file, encoding, callback) => {
    let oldContent;
    let newContent;
    let type = null;

    if (file.isNull()) {
      callback(null, file);
      return;
    }

    if (file.isStream()) {
      callback(new PluginError(PLUGIN_NAME, 'Streaming not supported'));
      return;
    }

    // Check if current file should be treated as JavaScript, HTML, CSS or if it should be ignored
    ['js', 'css', 'html'].some((value) => {
      // Check if at least one element in 'file_types' is suffix of file basename
      if (options[value].file_types.some(suffix => path.basename(file.path).endsWith(suffix))) {
        type = value;
        return true;
      }

      return false;
    });

    // Initialize properties for reporter
    file.jsbeautify = {};
    file.jsbeautify.type = type;
    file.jsbeautify.beautified = false;
    file.jsbeautify.canBeautify = false;

    if (type) {
      oldContent = file.contents.toString('utf8');
      newContent = beautify[type](oldContent, options);

      if (oldContent.toString() !== newContent.toString()) {
        if (doValidation) {
          file.jsbeautify.canBeautify = true;
        } else {
          file.contents = Buffer.from(newContent);
          file.jsbeautify.beautified = true;
        }
      }
    }

    callback(null, file);
  });
}
function helper(pluginOptions, doValidation) {
  const options = mergeOptions(pluginOptions);

  return through.obj((file, encoding, callback) => {
    let oldContent;
    let newContent;
    let type = null;

    if (file.isNull()) {
      callback(null, file);
      return;
    }

    if (file.isStream()) {
      callback(new PluginError(PLUGIN_NAME, 'Streaming not supported'));
      return;
    }

    // Check if current file should be treated as JavaScript, HTML, CSS or if it should be ignored
    ['js', 'css', 'html'].some((value) => {
      // Check if at least one element in 'file_types' is suffix of file basename
      if (options[value].file_types.some(suffix => path.basename(file.path).endsWith(suffix))) {
        type = value;
        return true;
      }

      return false;
    });

    // Initialize properties for reporter
    file.jsbeautify = {};
    file.jsbeautify.type = type;
    file.jsbeautify.beautified = false;
    file.jsbeautify.canBeautify = false;

    if (type) {
      oldContent = file.contents.toString('utf8');
      newContent = beautify[type](oldContent, options);

      if (oldContent.toString() !== newContent.toString()) {
        if (doValidation) {
          file.jsbeautify.canBeautify = true;
        } else {
          file.contents = Buffer.from(newContent);
          file.jsbeautify.beautified = true;
        }
      }
    }

    callback(null, file);
  });
}
function helper ( pluginOptions , doValidation ) { const options = mergeOptions ( pluginOptions ) ; return through . obj ( ( file , encoding , callback ) => { let oldContent ; let newContent ; let type = null ; if ( file . isNull ( ) ) { callback ( null , file ) ; return ; } if ( file . isStream ( ) ) { callback ( new PluginError ( PLUGIN_NAME , 'Streaming not supported' ) ) ; return ; } // Check if current file should be treated as JavaScript, HTML, CSS or if it should be ignored [ 'js' , 'css' , 'html' ] . some ( ( value ) => { // Check if at least one element in 'file_types' is suffix of file basename if ( options [ value ] . file_types . some ( suffix => path . basename ( file . path ) . endsWith ( suffix ) ) ) { type = value ; return true ; } return false ; } ) ; // Initialize properties for reporter file . jsbeautify = { } ; file . jsbeautify . type = type ; file . jsbeautify . beautified = false ; file . jsbeautify . canBeautify = false ; if ( type ) { oldContent = file . contents . toString ( 'utf8' ) ; newContent = beautify [ type ] ( oldContent , options ) ; if ( oldContent . toString ( ) !== newContent . toString ( ) ) { if ( doValidation ) { file . jsbeautify . canBeautify = true ; } else { file . contents = Buffer . from ( newContent ) ; file . jsbeautify . beautified = true ; } } } callback ( null , file ) ; } ) ; }
Beautify files or perform validation
@param  {Object} pluginOptions The gulp-jsbeautifier parameter options
@param  {boolean} doValidation Specifies whether perform validation only
@return {Object} The object stream
Beautify files or perform validation