HEX
Server: Apache
System: Linux webd004.cluster130.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64
User: frenchy (106757)
PHP: 7.4.33
Disabled: _dyuweyrj4,_dyuweyrj4r,dl
Upload Files
File: /home/frenchy/www/french-american.org/releases/20210421135930Z/node_modules/metaparser/index.js
/*jslint node:true, nomen:true*/

(function () {

    'use strict';

    var fs = require('fs'),
        path = require('path'),
        cheerio = require('cheerio'),
        _ = require('underscore'),
        mkdirp = require('mkdirp'),
        async = require('async');

    module.exports = function (params) {

        var options = _.defaults(params || {}, {
            source: null,
            add: null,
            remove: null,
            out: null,
            callback: null
        });

        async.waterfall([
            function (callback) {
              var decodeData = function (error, data) {
                var $ = cheerio.load(data, {
                    decodeEntities: false
                });
                callback(error, $);
              }

              if (options.source) {
                fs.readFile(options.source, decodeData);
              }
              else {
                decodeData(undefined, options.data);
              }
            },
            function ($, callback) {
                if (options.remove) {
                    _.each(typeof options.remove === 'string' ? [options.remove] : options.remove, function (code) {
                        $(code).remove();
                    });
                    callback(null, $);
                } else {
                    callback(null, $);
                }
            },
            function ($, callback) {
                if (options.add) {
                    var target = $('head').length > 0 ? $('head') : $.root();
                    _.each(typeof options.add === 'string' ? [options.add] : options.add, function (code) {
                        target.append(code);
                    });
                    callback(null, $);
                } else {
                    callback(null, $);
                }
            },
            function ($, callback) {
                if (options.out) {
                    mkdirp(path.dirname(options.out), function (error) {
                        if (error) {
                            callback(error, $);
                        } else {
                            fs.writeFile(options.out, $.html(), function (error) {
                                callback(error, $);
                            });
                        }
                    });
                } else {
                    callback(null, $);
                }
            }
        ], function (error, $) {
            if (options.callback) {
                return options.callback(error, $.html().replace(/^\s*[\r\n]/gm, ''));
            }
            if (error) {
                throw error;
            }
            return;
        });

    };

}());