<commit_before>const LZString = require('./lib/lz-string')

module.exports = compressionPlugin

function compressionPlugin() {
	return {
		decompress: decompress,
		compress: compress,
	}

	function decompress(_, key) {
		var val = this.get(key)
		if (!val) return val
		return JSON.parse(LZString.decompress(val))
	}

	function compress(_, key, val) {
		var compressed = LZString.compress(JSON.stringify(val))
		this.set(key, compressed)
	}
}<commit_msg>update plugin to use get/set methods<commit_after>const LZString = require('./lib/lz-string')

module.exports = compressionPlugin

function compressionPlugin() {
	return {
		get: get,
		set: set,
	}

	function get(super_fn, key, raw) {
		var val = super_fn(key)
		if (!val || raw) return val
		var decompressed = LZString.decompress(val)
		// fallback to existing values that are not compressed
		return (decompressed == null) ? val : JSON.parse(decompressed)
	}

	function set(super_fn, key, val, raw) {
		if (raw) return super_fn(key, val)
		var compressed = LZString.compress(JSON.stringify(val))
		super_fn(key, compressed)
	}
}
{'fraction_non_alphanumeric': 0.12419503219871206, 'fraction_numerical': 0.0, 'mean_word_length': 4.467336683417085, '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': '3357295', 'n_tokens_mistral': 388, 'n_tokens_neox': 360, 'n_words': 93}