<commit_before>import { always, merge, objOf, pipe } from 'ramda';
import { Clear, Delete, Read, Write } from '../commands/local_storage';
import { constructMessage, safeParse, safeStringify } from '../util';

const get = (() => (
  typeof window === 'undefined' ? always('<running outside browser context>') :
    window && window.localStorage && window.localStorage.getItem.bind(window.localStorage)
)());

export default new Map([
  [Read, ({ key, result }, dispatch) => pipe(
    get, safeParse, objOf('value'), merge({ key }), constructMessage(result), dispatch
  )(key)],
  [Write, ({ key, value }) => window.localStorage.setItem(key, safeStringify(value))],
  [Delete, ({ key }) => window.localStorage.removeItem(key)],
  [Clear, () => window.localStorage.clear()],
]);<commit_msg>Fix syntax for factorying local storage function<commit_after>import { always, merge, objOf, pipe } from 'ramda';
import { Clear, Delete, Read, Write } from '../commands/local_storage';
import { constructMessage, safeParse, safeStringify } from '../util';

const get = (() => (
  typeof window === 'undefined' ? always('<running outside browser context>') :
    window && window.localStorage && window.localStorage.getItem.bind(window.localStorage)
))();

export default new Map([
  [Read, ({ key, result }, dispatch) => pipe(
    get, safeParse, objOf('value'), merge({ key }), constructMessage(result), dispatch
  )(key)],
  [Write, ({ key, value }) => window.localStorage.setItem(key, safeStringify(value))],
  [Delete, ({ key }) => window.localStorage.removeItem(key)],
  [Clear, () => window.localStorage.clear()],
]);
{'fraction_non_alphanumeric': 0.18497827436374922, 'fraction_numerical': 0.0, 'mean_word_length': 5.176245210727969, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '6691830', 'n_tokens_mistral': 466, 'n_tokens_neox': 463, 'n_words': 124}