<commit_before>const hasLocalStorage = () => {
    return typeof(Storage) !== "undefined"
};

const getRecentEpics = () => {
    if (!hasLocalStorage) {
        return
    }
    const rawRecentEpics = localStorage.getItem('recent-epics');
    if (rawRecentEpics) {
        var parsed = [];
        try {
            parsed = JSON.parse(rawRecentEpics);
        } catch (e) {
            console.log('failed to parse recent-epics from local storage: ' + err);
        }
        if (parsed && parsed.constructor === Array) {
            return parsed;
        }
    } else {
        console.log('no recent-epics in local storage');
    }
    return [];
};

const pushRecentEpic = (epic) => {
    if (!hasLocalStorage) {
        return
    }
    var epics = getRecentEpics();
    for (var i = 0; i < epics.length; i++) {
        if (epics[i].key === epic.key) {
            epics.splice(i, 1);
        }
    }
    epics.unshift(epic);
    if (epics.length > 10) {
        epics.pop();
    }
    localStorage.setItem('recent-epics', JSON.stringify(epics));
};

export {
    getRecentEpics,
    pushRecentEpic
};<commit_msg>DRY local storage key<commit_after>const localStorageKey = 'recent-epics';

const hasLocalStorage = () => {
    return typeof(Storage) !== "undefined"
};

const getRecentEpics = () => {
    if (!hasLocalStorage) {
        return
    }
    const rawRecentEpics = localStorage.getItem(localStorageKey);
    if (rawRecentEpics) {
        var parsed = [];
        try {
            parsed = JSON.parse(rawRecentEpics);
        } catch (e) {
            console.log('failed to parse recent-epics from local storage: ' + err);
        }
        if (parsed && parsed.constructor === Array) {
            return parsed;
        }
    } else {
        console.log(`no ${localStorageKey} in local storage`);
    }
    return [];
};

const pushRecentEpic = (epic) => {
    if (!hasLocalStorage) {
        return
    }
    var epics = getRecentEpics();
    for (var i = 0; i < epics.length; i++) {
        if (epics[i].key === epic.key) {
            epics.splice(i, 1);
        }
    }
    epics.unshift(epic);
    if (epics.length > 10) {
        epics.pop();
    }
    localStorage.setItem(localStorageKey, JSON.stringify(epics));
};

export {
    getRecentEpics,
    pushRecentEpic
};
{'fraction_non_alphanumeric': 0.14248366013071895, 'fraction_numerical': 0.003485838779956427, 'mean_word_length': 2.1153324287652646, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1593046', 'n_tokens_mistral': 766, 'n_tokens_neox': 733, 'n_words': 154}