<commit_before>import localforage from 'localforage';

/**
 * install : Object -> Function 
 * @description
 * Constructs the install function for the SW
 * 
 * @param {object} opts
 * @param {string} opts.name      REQUIRED: The name of the app
 * @param {number} opts.version   The version number of the cache
 * @param {array}  opts.items     The urls to cache
 */
const install = (opts = {}) => {
  let { name, version, items } = opts;
  if (!name) {
    throw TypeError('Missing required parameter: name');
  }
  items = (!items) ? ['/'] : items;
  version = (version !== 0 && !version) ? 0 : version;

  const cacheName = `${name}-v${version}`;

  return (event) => {
    console.log(`Installing SW: ${cacheName}`);
    // config is a synchronous event
    localforage.config({name, version, driver: localforage.INDEXEDDB});
    event.waitUntil(
      caches.open(cacheName).then(cache => cache.addAll(items))
    );
  };
};

export default install;

<commit_msg>cleaning up the install function<commit_after>import localforage from 'localforage';

/**
 * install : Object -> Function 
 * @description
 * Constructs the install function for the SW
 * 
 * @param {object} opts 
 * @param {string} opts.name      REQUIRED: The name of the app
 * @param {number} opts.version   The version number of the cache
 * @param {array}  opts.items     The urls to cache
 */
const install = ({name, version = 0, items = ['/']}) => {
  if (!name) throw TypeError('Missing required parameter: name');
  const cacheName = `${name}-v${version}`;

  return (event) => {
    console.log(
      'Installing service worker and database. ' +
      `Name: ${name}, Version: ${version}`
    );

    localforage.config({name, version, driver: localforage.INDEXEDDB});
    event.waitUntil(
      new Promise((resolve, reject) => {
        localforage.getItem('state')
          .then(s => (!s) ? localforage.setItem('state', {}) : true)
          .then(() => caches.open(cacheName))
          .then(cache => cache.addAll(items))
          .then(() => resolve(true))
          .catch(err => reject(err));
      }).catch(err => console.error(err))
    );
  };
};

export default install;


{'fraction_non_alphanumeric': 0.1572878228782288, 'fraction_numerical': 0.0013837638376383763, 'mean_word_length': 3.147227533460803, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '1032397', 'n_tokens_mistral': 667, 'n_tokens_neox': 659, 'n_words': 191}