<commit_before>'use strict';

import {EventEmitter} from 'events';
import pcsclite from 'pcsclite';
import Device from './Device';


const pcsc = pcsclite();


class Devices extends EventEmitter {
    constructor() {
        super();
        //console.log(`new Devices()`);
        this.pcsc = pcsclite();
        this.devices = {};

        this.pcsc.on('reader', (reader) => {
            const device = new Device(reader);
            this.devices[reader.name] = device;
            this.emit('device-activated', {device, devices: this.listDevices()});
            reader.on('end', () => {
                delete this.devices[reader.name];
                this.emit('device-deactivated', {device, devices: this.listDevices()});
            });
            reader.on('error', (error) => {
                this.emit('error', {reader, error});
            });
        });

        this.pcsc.on('error', (error) => {
            this.emit('error', {error});
        });
    }

    listDevices() {
        return Object.keys(this.devices).map((k) => this.devices[k])
    };

    lookup(name) {
        return this.devices[name];
    };

    toString() {
        return `Devices('${this.listDevices()}')`;
    }
}


module.exports = Devices;

<commit_msg>activate promise<commit_after>'use strict';

import {EventEmitter} from 'events';
import pcsclite from 'pcsclite';
import Device from './Device';


const pcsc = pcsclite();


class Devices extends EventEmitter {
    constructor() {
        super();
        //console.log(`new Devices()`);
        this.pcsc = pcsclite();
        this.devices = {};

        this.pcsc.on('reader', (reader) => {
            const device = new Device(reader);
            this.devices[reader.name] = device;
            this.emit('device-activated', {device, devices: this.listDevices()});
            reader.on('end', () => {
                delete this.devices[reader.name];
                this.emit('device-deactivated', {device, devices: this.listDevices()});
            });
            reader.on('error', (error) => {
                this.emit('error', {reader, error});
            });
        });

        this.pcsc.on('error', (error) => {
            this.emit('error', {error});
        });
    }

    onActivated() {
      return new Promise((resolve, reject) => {
          this.on('device-activated', event => resolve(event));
      });
    };

    listDevices() {
        return Object.keys(this.devices).map((k) => this.devices[k])
    };

    lookup(name) {
        return this.devices[name];
    };

    toString() {
        return `Devices('${this.listDevices()}')`;
    }
}


module.exports = Devices;


{'fraction_non_alphanumeric': 0.17425668046669177, 'fraction_numerical': 0.0, 'mean_word_length': 2.0728323699421964, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '6293068', 'n_tokens_mistral': 801, 'n_tokens_neox': 771, 'n_words': 145}