<commit_before>(defclass local-storage-error (error))

(defun local-storage-supported? ()
  (native-body #{
    try {
      return "localStorage" in window && window["localStorage"] !== null;
    } catch (e) {
      return false;
    }
    #}))

(defun local-storage-get-item ((key string))
  (unless (local-storage-supported?)
    (error (make local-storage-error)))
  #{ localStorage.getItem((~key)) #})

(defun local-storage-set-item ((key string) (value string))
  (unless (local-storage-supported?)
    (error (make local-storage-error)))
  #{ localStorage.setItem((~key), (~value)) #})

(provide "local-storage")<commit_msg>better local-storage<commit_after>;;; Thanks to <NAME> for docs
;;; http://diveintohtml5.org/storage.html

(defclass local-storage-error (error))

(defun local-storage-supported? ()
  "Returns true if local storage is supported, false otherwise."
  (native-body #{
    try {
      return "localStorage" in window && window["localStorage"] !== null;
    } catch (e) {
      return false;
    }
    #}))

(defun local-storage-get-item ((key string))
  "Returns the local storage data associated with key, or nil."
  (unless (local-storage-supported?)
    (error (make local-storage-error)))
  #{ localStorage.getItem((~key)) #})

(defun local-storage-set-item ((key string) (data string))
  "Updates the local storage data associated with key."
  (unless (local-storage-supported?)
    (error (make local-storage-error)))
  #{ localStorage.setItem((~key), (~value)) #}
  nil)

(defun local-storage-remove-item ((key string))
  "Deletes the local storage data associated with key."
  (unless (local-storage-supported?)
    (error (make local-storage-error)))
  #{ localStorage.removeItem((~key)) #}
  nil)

(defun local-storage-length ()
  "Returns the number of local storage items."
  (unless (local-storage-supported?)
    (error (make local-storage-error)))
  #{ localStorage.length #})

(defun local-storage-key ((i small-integer))
  "Returns the key of the local storage item with the given index."
  (unless (local-storage-supported?)
    (error (make local-storage-error)))
  #{ localStorage.key((~i)) #})

(provide "local-storage")
{'fraction_non_alphanumeric': 0.1647438855560683, 'fraction_numerical': 0.00046146746654360867, 'mean_word_length': 4.018518518518518, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '2723691', 'n_tokens_mistral': 683, 'n_tokens_neox': 680, 'n_words': 175}