<commit_before>import EventEmitter from 'events';
import _ from 'underscore';
import rest from 'rest';
import mime from 'rest/interceptor/mime';
import AppDispatcher from '../dispatcher/AppDispatcher';
import SearchConstants from '../constants/SearchConstants';
import Item from '../class/Item';

const client = rest.wrap(mime);
const EVENTS = {
    CHANGE_RESULT: 'CHANGE_RESULT',
};
const items = [];
let results = [];

const ItemsStore = Object.assign({}, EventEmitter.prototype, {
    result() {
        return results;
    },
    emitChangeResult() {
        this.emit(EVENTS.CHANGE_RESULT);
    },
    addChangeResultListener(callback) {
        this.on(EVENTS.CHANGE_RESULT, callback);
    },
    removeChangeResultListener(callback) {
        this.removeListener(EVENTS.CHANGE_RESULT, callback);
    },
});

const filterResult = (criteria) => {
    const value = criteria.toUpperCase();
    results = _.filter(items, (item) => {
        return item.name.toUpperCase().includes(value) || item.description.toUpperCase().includes(value) || item.status.toUpperCase().includes(value);
    });
    ItemsStore.emitChangeResult();
};


const loadJson = (criteria) => {
    client('items.json').then((response) => {
        _.map(response.entity, (item) => {
            items.push(new Item(item));
        });
        filterResult(criteria);
    });
};

const loadGoogleSpreadsheets = (criteria) => {
    const cbname = 'spreadsheets';
    const script = document.createElement('script');
    script.id = 'spreadsheets';
    script.src = `https://spreadsheets.google.com/feeds/list/112MlfyXSlIQ8nae85Te_xWDBP136GRaYeHlDdKgYyPo/1/public/values?alt=json-in-script&callback=${cbname}`;

    if (document.getElementById(script.id) === null) {
        window[cbname] = ((jsonData) => {
            delete window[cbname];<commit_msg>Filter results with Regular Expression instead of UpperCase method.<commit_after>import EventEmitter from 'events';
import _ from 'underscore';
import rest from 'rest';
import mime from 'rest/interceptor/mime';
import AppDispatcher from '../dispatcher/AppDispatcher';
import SearchConstants from '../constants/SearchConstants';
import Item from '../class/Item';

const client = rest.wrap(mime);
const EVENTS = {
    CHANGE_RESULT: 'CHANGE_RESULT',
};
const items = [];
let results = [];

const ItemsStore = Object.assign({}, EventEmitter.prototype, {
    result() {
        return results;
    },
    emitChangeResult() {
        this.emit(EVENTS.CHANGE_RESULT);
    },
    addChangeResultListener(callback) {
        this.on(EVENTS.CHANGE_RESULT, callback);
    },
    removeChangeResultListener(callback) {
        this.removeListener(EVENTS.CHANGE_RESULT, callback);
    },
});

const filterResult = (criteria) => {
    const rx = new RegExp(criteria, 'i');
    results = _.filter(items, (item) => {
        return rx.test(item.name) || rx.test(item.description) || rx.test(item.status);
    });
    ItemsStore.emitChangeResult();
};


const loadJson = (criteria) => {
    client('items.json').then((response) => {
        _.map(response.entity, (item) => {
            items.push(new Item(item));
        });
        filterResult(criteria);
    });
};

const loadGoogleSpreadsheets = (criteria) => {
    const cbname = 'spreadsheets';
    const script = document.createElement('script');
    script.id = 'spreadsheets';
    script.src = `https://spreadsheets.google.com/feeds/list/112MlfyXSlIQ8nae85Te_xWDBP136GRaYeHlDdKgYyPo/1/public/values?alt=json-in-script&callback=${cbname}`;

    if (document.getElementById(script.id) === null) {
        window[cbname] = ((jsonData) => {
            delete window[cbname];
{'fraction_non_alphanumeric': 0.15034293552812072, 'fraction_numerical': 0.0054869684499314125, 'mean_word_length': 3.6505102040816326, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 2, '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': '2858159', 'n_tokens_mistral': 1136, 'n_tokens_neox': 1107, 'n_words': 201}