<commit_before>import debug from 'debug'
import { EventEmitter } from 'events'
import { Observable } from 'rx'
import { has } from 'lodash'

const log = debug('observable-socket')

export default function observableSocket (_ws) {
    let ws // init

    // Normalize events between browser and node. Assumes node libs follow the
    // same pattern that "ws" does, i.e. socket.io *does not* work.
    if (has(global, 'WebSocket')) {
        ws = new EventEmitter()

        _ws.addEventListener('open', () => ws.emit('open'))
        _ws.addEventListener('close', () => ws.emit('close'))
        _ws.addEventListener('error', () => ws.emit('error'))
        _ws.addEventListener('message', e => ws.emit('message', e.data))
    } else {
        ws = _ws
    }
<commit_msg>Just arranging stuff<commit_after>import debug from 'debug'
import { EventEmitter } from 'events'
import { Observable } from 'rx'
import { has } from 'lodash'

const log = debug('observable-socket')

export default function observableSocket (_ws) {
    let ws // init

    // Normalize events between browser and node. Assumes node libs follow the
    // same pattern that "ws" does, i.e. socket.io *does not* work.
    if (has(global, 'WebSocket')) {
        ws = new EventEmitter()

        _ws.addEventListener('close', () => ws.emit('close'))
        _ws.addEventListener('error', () => ws.emit('error'))
        _ws.addEventListener('open',  () => ws.emit('open'))

        _ws.addEventListener('message', e => ws.emit('message', e.data))
    } else {
        ws = _ws
    }

{'fraction_non_alphanumeric': 0.15087040618955513, 'fraction_numerical': 0.0, 'mean_word_length': 3.073490813648294, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '462759', 'n_tokens_mistral': 472, 'n_tokens_neox': 451, 'n_words': 136}