<commit_before>define('localStorage', ['dispatcher'], function (dispatcher) {
    var ls = (function () {
        var api = {
                events: {
                    WARNING: 'localStorage:warning',
                    ERROR: 'localStorage:error'
                },
                UNSUPPORTED: "LOCAL_STORAGE_NOT_SUPPORTED"
            },
            // pfx = 'global',
            // prefix = pfx + ':';
            prefix = "";

        // Checks the browser to see if local storage is supported
        function browserSupportsLocalStorage() {
            try {
                return ('localStorage' in window && window.localStorage !== null);
            } catch (e) {
                api.dispatch(api.events.ERROR, e.Description);
                return false;
            }
        }

        function localStorageEnabled() {
            try {
                var has = browserSupportsLocalStorage(), key = '__localStorageSupportTest__', r;
                if (has) {
                    // now we need to determine if it works. Because Safari Private Browsing will say it is there
                    // but it won't work.
                    r = Date.now().toString();
                    localStorage.setItem(key, r);
                    return localStorage.getItem(key) === r;
                }
            } catch (e) {
                api.dispatch(api.events.ERROR, e.Description);
                return false;
            }
        }

        // Directly adds a value to local storage
        // If local storage is not available in the browser use cookies
        // Example use: localStorage.add('library','angular');
        function addToLocalStorage(key, value) {

            // If this browser does not support local storage use cookies
            if (!browserSupportsLocalStorage()) {
                api.dispatch(api.events.WARNING, api.UNSUPPORTED);
                return false;
            }

            // 0 and "" is allowed as a value but let's limit other falsey values like "undefined"
            if (!value && value !== 0 && value !== "") return false;

            try {
                localStorage.setItem(prefix + key, JSON.stringify(value));
            } catch (e) {
                api.dispatch(api.events.ERROR, e.Description);
                return false;
            }
            return true;
        }

        // Directly get a value from local storage
        // Example use: localStorage.get('library'); // returns 'angular'
        function getFromLocalStorage(key) {
            if (!browserSupportsLocalStorage()) {
                api.dispatch(api.events.WARNING, api.UNSUPPORTED);
                return false;
            }

            var item = localStorage.getItem(prefix + key);
            if (!item) return null;
            return JSON.parse(item);
        }

        // Remove an item from local storage
        // Example use: localStorage.remove('library'); // removes the key/value pair of library='angular'
        function removeFromLocalStorage(key) {
            if (!browserSupportsLocalStorage()) {
                api.dispatch(api.events.WARNING, api.UNSUPPORTED);
                return false;
            }

            try {
                localStorage.removeItem(prefix + key);
            } catch (e) {
                api.dispatch(api.events.ERROR, e.Description);
                return false;
            }
            return true;
        }

        function getAllFromLocalStorageByPrefix(localPrefix) {
            if (!browserSupportsLocalStorage()) {
                api.dispatch(api.events.WARNING, api.UNSUPPORTED);
                return false;
            }

            var prefixKey = prefix + (localPrefix || ''),
                prefixKeyLength = prefixKey.length,
                prefixLength = prefix.length,
                localKey,
                result = {};

            for (var key in localStorage) {
                // Only remove items that are for this app
                if (localStorage.hasOwnProperty(key) && key.substr(0, prefixKeyLength) === prefixKey) {
                    localKey = key.substr(prefixLength);
                    result[localKey] = getFromLocalStorage(localKey);
                }
            }
            return result;
        }

        // Remove all data for this app from local storage
        // Example use: localStorage.clearAll();
        // Should be used mostly for development purposes
        function clearAllFromLocalStorage(pattern) {

            if (!browserSupportsLocalStorage()) {
                api.dispatch(api.events.WARNING, api.UNSUPPORTED);
                return false;
            }

            var prefixLength = prefix.length;

            for (var key in localStorage) {
                // Only remove items that are for this app
                if (localStorage.hasOwnProperty(key) && key.substr(0, prefixLength) === prefix && (!pattern || key.substr(prefixLength).match(pattern))) {
                    try {
                        removeFromLocalStorage(key.substr(prefixLength));
                    } catch (e) {
                        api.dispatch(api.events.ERROR, e.Description);
                        return false;
                    }
                }
            }
            return true;
        }

        // api.prefix = function (value) {
        //     if (value) {
        //         pfx = value;
        //         prefix = pfx + ':';
        //     }
        //     return pfx;
        // };
        api.isSupported = browserSupportsLocalStorage;
        api.enabled = localStorageEnabled;
        api.put = addToLocalStorage;
        api.get = getFromLocalStorage;
        api.getAll = getAllFromLocalStorageByPrefix;
        api.remove = removeFromLocalStorage;
        api.clearAll = clearAllFromLocalStorage;

        dispatcher(api);

        return api;
    }());

    return ls;
});
<commit_msg>localStorage changed up to support custom prefix<commit_after>define('localStorage', function () {

    function LocalStorage(prefix) {
        this.prefix = prefix ? prefix + ':' : '';
    }

    var LocalStorageProto = LocalStorage.prototype;
    // Checks the browser to see if local storage is supported
    LocalStorageProto.isSupported = function () {
        try {
            return ('localStorage' in window && window.localStorage !== null);
        } catch (e) {
            return false;
        }
    };

    LocalStorageProto.isEnabled = function () {
        try {
            var has = this.isSupported(), key = '__localStorageSupportTest__', r;
            if (has) {
                // now we need to determine if it works. Because Safari Private Browsing will say it is there
                // but it won't work.
                r = Date.now().toString();
                localStorage.setItem(key, r);
                return localStorage.getItem(key) === r;
            }
        } catch (e) {
            return false;
        }
    };

    // Directly adds a value to local storage
    // If local storage is not available in the browser use cookies
    // Example use: localStorage.add('library','angular');
    LocalStorageProto.set = function (key, value) {

        var prefix = this.prefix;

        // If this browser does not support local storage use cookies
        if (!this.isSupported()) {
            return false;
        }

        // 0 and "" is allowed as a value but let's limit other falsey values like "undefined"
        if (!value && value !== 0 && value !== "") {
            return false;
        }

        try {
            localStorage.setItem(prefix + key, JSON.stringify(value));
        } catch (e) {
            return false;
        }
        return true;
    };

    // legacy support
    LocalStorageProto.put = LocalStorageProto.set;

    // Directly get a value from local storage
    // Example use: localStorage.get('library'); // returns 'angular'
    LocalStorageProto.get = function (key) {
        var prefix = this.prefix;

        if (!this.isSupported()) {
            return false;
        }

        var item = localStorage.getItem(prefix + key);
        if (!item) {
            return null;
        }
        return JSON.parse(item);
    };

    // Remove an item from local storage
    // Example use: localStorage.remove('library'); // removes the key/value pair of library='angular'
    LocalStorageProto.remove = function (key) {
        var prefix = this.prefix;

        if (!this.isSupported()) {
            return false;
        }

        try {
            localStorage.removeItem(prefix + key);
        } catch (e) {
            return false;
        }
        return true;
    };

    LocalStorageProto.getAll = function (localPrefix) {
        var prefix = this.prefix;

        if (!this.isSupported()) {
            return false;
        }

        var prefixKey = prefix + (localPrefix || ''),
            prefixKeyLength = prefixKey.length,
            prefixLength = prefix.length,
            localKey,
            result = {};

        for (var key in localStorage) {
            // Only remove items that are for this app
            if (localStorage.hasOwnProperty(key) && key.substr(0, prefixKeyLength) === prefixKey) {
                localKey = key.substr(prefixLength);
                result[localKey] = this.get(localKey);
            }
        }
        return result;
    };

    // Remove all data for this app from local storage
    // Example use: localStorage.clearAll();
    // Should be used mostly for development purposes
    LocalStorageProto.clearAll = function (pattern) {
        var prefix = this.prefix;

        if (!this.isSupported()) {
            return false;
        }

        var prefixLength = prefix.length;

        for (var key in localStorage) {
            // Only remove items that are for this app
            if (localStorage.hasOwnProperty(key) && key.substr(0, prefixLength) === prefix && (!pattern || key.substr(prefixLength).match(pattern))) {
                try {
                    this.remove(key.substr(prefixLength));
                } catch (e) {
                    return false;
                }
            }
        }
        return true;
    };

    var stores = {};
    return function (prefix) {
        var store = stores[prefix];
        if (!store) {
            store = stores[prefix] = new LocalStorage(prefix);
        }
        return store;
    };
});

{'fraction_non_alphanumeric': 0.10144927536231885, 'fraction_numerical': 0.000767828006526538, 'mean_word_length': 1.5266731328806984, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2994738', 'n_tokens_mistral': 2614, 'n_tokens_neox': 2491, 'n_words': 707}