<commit_before>'use strict';

var util = require('./util')

function Selector (sel) {
    if (util.type(sel) == 'string') {
        var nodes = util.copyArray(document.querySelectorAll(sel))
        return Dom(nodes)
    } else if (sel instanceof Dom) return sel
    else if (sel instanceof HTMLElement) {
        return Dom([sel])
    } else {
        throw new Error('Unexpect selector !')
    }
}

function Dom (nodes) {
    var ins = {
        find: function (sel) {
            var subs = []
            nodes.forEach(function (n) {
                subs = subs.concat(util.copyArray(n.querySelectorAll(sel)))
            })
            return Dom(subs)
        },
        attr: function (attname, attvalue) {
            var len = arguments.length
            var el = nodes[0]
            if (len > 1) {
                el.setAttribute(attname, attvalue)
            } else if (len == 1) {
                return (el.getAttribute(attname) || '').toString()
            }
            return this
        },
        removeAttr: function (attname) {
            nodes.forEach(function (el) {
                el.removeAttribute(attname)
            })
            return this
        },
        addClass: function (clazz) {
            nodes.forEach(function (el) {
                var classes = util.copyArray(el.classList)
                if (!~classes.indexOf(clazz)) classes.push(clazz)
                el.className = classes.join(' ')
            })
            return this
        },
        removeClass: function (clazz) {
            nodes.forEach(function (el) {
                el.className = classes.reduce(function (r, n) {
                    if (n != clazz) r.push(n)
                    return r
                }, []).join(' ')
            })
            return this
        },
        each: function (fn) {
            nodes.forEach(fn)
            return this
        },
        on: function (type, listener, capture) {
            nodes.forEach(function (el) {
                el.addEventListener(type, listener, capture)
            })
            return this
        },
        off: function (type, listener) {
            nodes.forEach(function (el) {
                el.removeEventListener(type, listener)
            })
            return this
        },
        html: function (html) {
            var len = arguments.length
            if (len >= 1) {
                nodes.forEach(function (el) {
                    el.innerHTML = html
                })
            } else if (nodes.length){
                return nodes[0].innerHTML
            }
            return this
        }
    }
    ins.__proto__ = Dom.prototype
    return ins
}

module.exports = Selector<commit_msg>add get parent DOM man<commit_after>'use strict';

var util = require('./util')

function Selector (sel) {
    if (util.type(sel) == 'string') {
        var nodes = util.copyArray(document.querySelectorAll(sel))
        return Dom(nodes)
    } else if (sel instanceof Dom) return sel
    else if (sel instanceof HTMLElement) {
        return Dom([sel])
    } else {
        throw new Error('Unexpect selector !')
    }
}

function Dom (nodes) {
    var ins = {
        find: function (sel) {
            var subs = []
            nodes.forEach(function (n) {
                subs = subs.concat(util.copyArray(n.querySelectorAll(sel)))
            })
            return Dom(subs)
        },
        attr: function (attname, attvalue) {
            var len = arguments.length
            var el = nodes[0]
            if (len > 1) {
                el.setAttribute(attname, attvalue)
            } else if (len == 1) {
                return (el.getAttribute(attname) || '').toString()
            }
            return this
        },
        removeAttr: function (attname) {
            nodes.forEach(function (el) {
                el.removeAttribute(attname)
            })
            return this
        },
        addClass: function (clazz) {
            nodes.forEach(function (el) {
                var classes = util.copyArray(el.classList)
                if (!~classes.indexOf(clazz)) classes.push(clazz)
                el.className = classes.join(' ')
            })
            return this
        },
        removeClass: function (clazz) {
            nodes.forEach(function (el) {
                el.className = classes.reduce(function (r, n) {
                    if (n != clazz) r.push(n)
                    return r
                }, []).join(' ')
            })
            return this
        },
        each: function (fn) {
            nodes.forEach(fn)
            return this
        },
        on: function (type, listener, capture) {
            nodes.forEach(function (el) {
                el.addEventListener(type, listener, capture)
            })
            return this
        },
        off: function (type, listener) {
            nodes.forEach(function (el) {
                el.removeEventListener(type, listener)
            })
            return this
        },
        html: function (html) {
            var len = arguments.length
            if (len >= 1) {
                nodes.forEach(function (el) {
                    el.innerHTML = html
                })
            } else if (nodes.length){
                return nodes[0].innerHTML
            }
            return this
        },
        parent: function () {
            if (!nodes || !nodes.length) return null
            return Dom([nodes[0].parentNode])
        }
    }
    ins.__proto__ = Dom.prototype
    return ins
}

module.exports = Selector
{'fraction_non_alphanumeric': 0.11105121293800539, 'fraction_numerical': 0.001976639712488769, 'mean_word_length': 1.3191666666666666, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '6379939', 'n_tokens_mistral': 1463, 'n_tokens_neox': 1435, 'n_words': 352}