<commit_before>const styles = require("./ansi")

module.exports = function (strings, ...values) {
    var v = "", t = "", prev = "", tags = [], vals = [], result = []

    for (var i = 0; i < strings.length; i++) {
        var s = strings[i]

        for (var j = 0; j < s.length; j++) {
            var c = s[j]

            if (c === "<") {
                if (v !== "") {
                    if (tags.length === 0) {
                        result.push(v)
                    } else {
                        if (Array.isArray(vals[vals.length - 1])) {
                            vals[vals.length - 1].push(v)

                        } else {
                            vals.push(v)
                        }
                    }
                    v = ""
                }

                if (prev === c) {
                    throw SyntaxError("Unexpected <")
                }

                prev = c
                continue
            }

            if (c === ">") {
                if (t === "") {
                    throw SyntaxError("Unexpected >")
                }

                if (prev === "/") {
                    const tag = tags.pop()

                    if (tag !== t) {
                        throw SyntaxError("Unxpected tag: " + tag)
                    }

                    const obj = {
                        style: tag,
                        value: Array.isArray(vals[vals.length-1])
                            ? vals.pop()
                            : vals//.slice()
                    }

                    if (tags.length === 0) {
                        result.push(obj)

                        if (Array.isArray(vals[vals.length-1]))
                            delete vals[vals.length-1]
                        else
                            vals = []
                    } else {
                        if (Array.isArray(vals[vals.length - 1])) {
                            vals[vals.length-1].push(obj)
                        } else {
                            vals.push(obj)
                        }
                    }

                } else {
                    if (tags.length > 0) {
                        vals.push([])
                    }
                    tags.push(t)
                }

                prev = c

                t = ""
                continue
            }

            if (c === "/") {
                if (prev === "<") {
                    prev = c
                    continue
                } else {
                    v += c
                }
            }

            if (prev === "<" || prev === "/") {
                t += c
            } else {
                v += c
            }

        }//j

        v += values[i] || ""

    }//i

    if (v !== "") {
        result.push(v)
    }

    const unwrap = obj => Object.values(obj).reduce((s, i) =>
        s + (i.style ? styles[i.style][0] + unwrap(i.value) + styles[i.style][1] : i), "")

    return unwrap(result) + styles.reset[0]
}



<commit_msg>Object.values is not even present in node 6. Fix it.<commit_after>const ansi = require("./ansi")

module.exports = function (strings, ...values) {
    var v = "", t = "", prev = "", tags = [], vals = [], result = []

    for (var i = 0; i < strings.length; i++) {
        var s = strings[i]

        for (var j = 0; j < s.length; j++) {
            var c = s[j]

            if (c === "<") {
                if (v !== "") {
                    if (tags.length === 0) {
                        result.push(v)
                    } else {
                        if (Array.isArray(vals[vals.length - 1])) {
                            vals[vals.length - 1].push(v)

                        } else {
                            vals.push(v)
                        }
                    }
                    v = ""
                }

                if (prev === c) {
                    throw SyntaxError("Unexpected <")
                }

                prev = c
                continue
            }

            if (c === ">") {
                if (t === "") {
                    throw SyntaxError("Unexpected >")
                }

                if (prev === "/") {
                    const tag = tags.pop()

                    if (tag !== t) {
                        throw SyntaxError("Unxpected tag: " + tag)
                    }

                    const obj = {
                        style: tag,
                        value: Array.isArray(vals[vals.length-1])
                            ? vals.pop()
                            : vals//.slice()
                    }

                    if (tags.length === 0) {
                        result.push(obj)

                        if (Array.isArray(vals[vals.length-1]))
                            delete vals[vals.length-1]
                        else
                            vals = []
                    } else {
                        if (Array.isArray(vals[vals.length - 1])) {
                            vals[vals.length-1].push(obj)
                        } else {
                            vals.push(obj)
                        }
                    }

                } else {
                    if (tags.length > 0) {
                        vals.push([])
                    }
                    tags.push(t)
                }

                prev = c

                t = ""
                continue
            }

            if (c === "/") {
                if (prev === "<") {
                    prev = c
                    continue
                } else {
                    v += c
                }
            }

            if (prev === "<" || prev === "/") {
                t += c
            } else {
                v += c
            }

        }//j

        v += values[i] || ""

    }//i

    if (v !== "") {
        result.push(v)
    }

    const unwrap = obj => Object.keys(obj).map(k => obj[k]).reduce((s, i) =>
        s + (i.style ? ansi[i.style][0] + unwrap(i.value) + ansi[i.style][1] : i), "")

    return unwrap(result) + ansi.reset[0]
}






{'fraction_non_alphanumeric': 0.13469119579500657, 'fraction_numerical': 0.005091984231274638, 'mean_word_length': 0.6564200217627857, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 14, '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': '24521', 'n_tokens_mistral': 1660, 'n_tokens_neox': 1482, 'n_words': 312}