<commit_before>var _ = require('lodash');

var inspectors = [
    inspectLinks,
    inspectImages
];

function inspect(dom) {
    var pageInfo = inspectHelper(dom, {});
    Object.keys(pageInfo).forEach(function(infoType) {
        pageInfo[infoType] = _.unique(pageInfo[infoType]);
    });
    return pageInfo;

    function inspectHelper(dom, pageAttributes) {
        return dom.reduce(function(pageAttributes, domNode) {
            inspectors.forEach(function(inspector) {
                inspector(pageAttributes, domNode);
            });

            if (domNode.children) {
                pageAttributes = inspectHelper(domNode.children, pageAttributes);
            }
            return pageAttributes;
        }, pageAttributes);
    }
}

function inspectLinks(pageAttributes, domNode) {
    if (domNode.name && domNode.name === 'a' &&
        domNode.attribs && domNode.attribs.href) {
        var href = domNode.attribs.href;
        if (pageAttributes.links) {
            pageAttributes.links.push(href);
        } else {
            pageAttributes.links = [href];
        }
    }
}

function inspectImages(pageAttributes, domNode) {
    if (domNode.name && domNode.name === 'img' &&
        domNode.attribs) {
        var image = domNode.attribs;
        if (pageAttributes.images) {
            pageAttributes.images.push(image);
        } else {
            pageAttributes.images = [image];
        }
    }
}

module.exports = {
    inspect: inspect
};<commit_msg>Can now inspect script nodes<commit_after>var _ = require('lodash');

var inspectors = [
    inspectLinks,
    inspectImages,
    inspectScript
];

function inspect(dom) {
    var pageInfo = inspectHelper(dom, {});
    Object.keys(pageInfo).forEach(function(infoType) {
        pageInfo[infoType] = _.unique(pageInfo[infoType]);
    });
    return pageInfo;

    function inspectHelper(dom, pageAttributes) {
        return dom.reduce(function(pageAttributes, domNode) {
            inspectors.forEach(function(inspector) {
                inspector(pageAttributes, domNode);
            });

            if (domNode.children) {
                pageAttributes = inspectHelper(domNode.children, pageAttributes);
            }
            return pageAttributes;
        }, pageAttributes);
    }
}

function inspectLinks(pageAttributes, domNode) {
    if (domNode.name && domNode.name === 'a' &&
        domNode.attribs && domNode.attribs.href) {
        var href = domNode.attribs.href;
        if (pageAttributes.links) {
            pageAttributes.links.push(href);
        } else {
            pageAttributes.links = [href];
        }
    }
}

function inspectImages(pageAttributes, domNode) {
    if (domNode.name && domNode.name === 'img' &&
        domNode.attribs && !_.isEmpty(domNode.attribs)) {
        var image = domNode.attribs;
        if (pageAttributes.images) {
            pageAttributes.images.push(image);
        } else {
            pageAttributes.images = [image];
        }
    }
}

function inspectScript(pageAttributes, domNode) {
    if (domNode.type && domNode.type === 'script' &&
        domNode.attribs && !_.isEmpty(domNode.attribs)) {
        var script = domNode.attribs;
        if (pageAttributes.scripts) {
            pageAttributes.scripts.push(script);
        } else {
            pageAttributes.scripts = [script];
        }
    }
}

module.exports = {
    inspect: inspect
};
{'fraction_non_alphanumeric': 0.12117647058823529, 'fraction_numerical': 0.0, 'mean_word_length': 2.2987390882638215, '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': '6233757', 'n_tokens_mistral': 979, 'n_tokens_neox': 975, 'n_words': 166}