<commit_before>var Random = require('random-js')

var localStorage;

module.exports = new function () {

    this.init = function (fname) {

        // We at least get ./j.conf as default.

        // Open local storage
        if (typeof localStorage === "undefined" || localStorage === null) {

            var LocalStorage = require('node-localstorage').LocalStorage;
            localStorage = new LocalStorage(fname);
        }

        if (localStorage.getItem('deviceId') === null) {
            var random = new Random(Random.engines.mt19937().autoSeed());
            localStorage.setItem('deviceId', random.uuid4());
        }
    }

    this.getItem = function (key) {
        return localStorage.getItem(key);
    }

    this.setItem = function (key, value) {
        localStorage.setItem(key, value);
    }
}<commit_msg>Added detailed comments<commit_after>const Random = require('random-js');

var localStorage;

module.exports = function(){
	this.init = function(fname){
		/* create a local storage if there's not one
		 * using the file name specified by fname
		 */
		if(typeof localStorage === 'undefined' || localStorage === null){
			var LocalStorage = require('node-localstorage').LocalStorage;
			localStorage = new LocalStorage(fname);
		}
		/* assign a randomly-generated value to the deviceId field of the local storage
		 * if it is not set
		 */
		if(localStorage.getItem('deviceId') === null){
			var random = new Random(Random.engines.mt19937().autoSeed());
			localStorage.setItem('deviceId', random.uuid4());
		}
	}

	/* get the value associated with key stored in local storage */
	this.getItem = function(key){
		return localStorage.getItem(key);
	}

	/* set a key-value pair in local storage */
	this.setItem = function(key, value){
		localStorage.setItem(key, value);
	}
}
{'fraction_non_alphanumeric': 0.1306032097399004, 'fraction_numerical': 0.006640841173215274, 'mean_word_length': 3.109090909090909, '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': '5771845', 'n_tokens_mistral': 550, 'n_tokens_neox': 514, 'n_words': 141}