<commit_before>import EANReader from './ean_reader';

function EAN2Reader() {
    EANReader.call(this);
}

var properties = {
    FORMAT: {value: 'ean_2', writeable: false},
};

EAN2Reader.prototype = Object.create(EANReader.prototype, properties);
EAN2Reader.prototype.constructor = EAN2Reader;

EAN2Reader.prototype.decode = function(row, start) {
    this._row = row;
    var codeFrequency = 0,
        i = 0,
        offset = start,
        end = this._row.length,
        code,
        result = [],
        decodedCodes = [];

    for (i = 0; i < 2 && offset < end; i++) {
        code = this._decodeCode(offset);
        if (!code) {
            return null;
        }
        decodedCodes.push(code);
        result.push(code.code % 10);
        if (code.code >= this.CODE_G_START) {
            codeFrequency |= 1 << (1 - i);
        }
        if (i !== 1) {
            offset = this._nextSet(this._row, code.end);
            offset = this._nextUnset(this._row, offset);
        }
    }

    if (result.length !== 2 || (parseInt(result.join('')) % 4) !== codeFrequency) {
        return null;
    }
    return {
        code: result.join(''),
        decodedCodes,
        end: code.end,
    };
};

export default EAN2Reader;<commit_msg>ean_2_reader => ts<commit_after>import EANReader from './ean_reader';
import { BarcodeInfo, BarcodePosition, Barcode } from './barcode_reader';

class EAN2Reader extends EANReader {
    FORMAT = 'ean_2';
    _decode(row?: Array<number>, start?: BarcodePosition): Barcode | null {
        this._row = row;
        let offset = start ? start.start : 0;
        let end = this._row.length;
        const decodedCodes: Array<BarcodeInfo> = [];
        const result: Array<number> = [];
        let codeFrequency = 0;
        let code: BarcodeInfo | null = null;
        for (let i = 0; i < 2 && offset < end; i++) {
            code = this._decodeCode(offset) as BarcodeInfo;
            if (!code) {
                return null;
            }
            decodedCodes.push(code);
            result.push(code.code % 10);
            if (code.code >= this.CODE_G_START) {
                codeFrequency |= 1 << (1 - i);
            }
            if (i !== 1) {
                offset = this._nextSet(this._row, code.end);
                offset = this._nextUnset(this._row, offset);
            }
        }
        if (!code || result.length !== 2 || (parseInt(result.join(''), 10) % 4) !== codeFrequency) {
            return null;
        }
        return {
            code: result.join(''),
            decodedCodes,
            end: code.end,
            start: code.start,
            startInfo: start as BarcodePosition,
            format: this.FORMAT,
        };
    }
}

export default EAN2Reader;
{'fraction_non_alphanumeric': 0.13677700982175336, 'fraction_numerical': 0.012731902510003638, 'mean_word_length': 1.8350515463917525, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 9, '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': '4114432', 'n_tokens_mistral': 865, 'n_tokens_neox': 838, 'n_words': 195}