<commit_before>/**
 * Plugin developed to save html forms data to LocalStorage to restore them after browser crashes, tabs closings
 * and other disasters.
 *
 * @author <NAME> <<EMAIL>>
 */

//$.sisyphus().setOptions({timeout: 15})
( function( $ ) {
  $.sisyphus = function() {
    return Sisyphus.getInstance();
  };

  $.fn.sisyphus = function( options ) {
    var sisyphus = Sisyphus.getInstance();
    sisyphus.setOptions( options );
    sisyphus.protect( this );
    return sisyphus;
  };

  var browserStorage = {};

  /**
   * Check if local storage or other browser storage is available
   *
   * @return Boolean
   */
  browserStorage.isAvailable = function() {
    if ( typeof $.jStorage === "object" ) {
      return true;
    }
    try {
      return localStorage.getItem;
    } catch ( e ) {
      return false;
    }
  };

  /**
   * Set data to browser storage
   *
   * @param [String] key
   * @param [String] value
   *
   * @return Boolean
   */
  browserStorage.set = function( key, value ) {
    if ( typeof $.jStorage === "object" ) {
      $.jStorage.set( key, value + "" );
    } else {
      try {
        localStorage.setItem( key, value + "" );
      } catch (e) {
        //QUOTA_EXCEEDED_ERR
      }
    }
  };

  /**
   * Get data from browser storage by specified key
   *
   * @param [String] key
   *
   * @return string
   */
  browserStorage.get = function( key ) {
    if ( typeof $.jStorage === "object" ) {
      var result = $.jStorage.get( key );
      return result ? result.toString() : result;
    } else {
      return localStorage.getItem( key );
    }
  };

  /**
   * Delete data from browser storage by specified key
   *
   * @param [String] key
   *
   * @return void
   */
  browserStorage.remove = function( key ) {
    if ( typeof $.jStorage === "object" ) {
      $.jStorage.deleteKey( key );
    } else {
      localStorage.removeItem( key );
    }
  };

  Sisyphus = ( function() {
    var params = {
      instantiated: null,
      started: null
    };

    function init () {

      return {
        /**
         * Set plugin initial options
         *
         * @param [Object] options
         *
         * @return void
         */
        setInitialOptions: function ( options ) {
          var defaults = {
            excludeFields: null,
            customKeyPrefix: "",
            timeout: 0,
            autoRelease: true,
            name: null,
            onSave: function() {},
            onBeforeRestore: function() {},
            onRestore: function() {},
            onRelease: function() {}
          };
          this.options = this.options || $.extend( defaults, options );
          this.browserStorage = browserStorage;
        },

        /**
         * Set plugin options
         *
         * @param [Object] options
         *
         * @return void
         */<commit_msg>Fixed issue #20 (Error: Can't convert null to object (or) Uncaught TypeError: Array.prototype.indexOf called on null or undefined).<commit_after>/**
 * Plugin developed to save html forms data to LocalStorage to restore them after browser crashes, tabs closings
 * and other disasters.
 *
 * @author <NAME> <<EMAIL>>
 */

//$.sisyphus().setOptions({timeout: 15})
( function( $ ) {
  $.sisyphus = function() {
    return Sisyphus.getInstance();
  };

  $.fn.sisyphus = function( options ) {
    var sisyphus = Sisyphus.getInstance();
    sisyphus.setOptions( options );
    sisyphus.protect( this );
    return sisyphus;
  };

  var browserStorage = {};

  /**
   * Check if local storage or other browser storage is available
   *
   * @return Boolean
   */
  browserStorage.isAvailable = function() {
    if ( typeof $.jStorage === "object" ) {
      return true;
    }
    try {
      return localStorage.getItem;
    } catch ( e ) {
      return false;
    }
  };

  /**
   * Set data to browser storage
   *
   * @param [String] key
   * @param [String] value
   *
   * @return Boolean
   */
  browserStorage.set = function( key, value ) {
    if ( typeof $.jStorage === "object" ) {
      $.jStorage.set( key, value + "" );
    } else {
      try {
        localStorage.setItem( key, value + "" );
      } catch (e) {
        //QUOTA_EXCEEDED_ERR
      }
    }
  };

  /**
   * Get data from browser storage by specified key
   *
   * @param [String] key
   *
   * @return string
   */
  browserStorage.get = function( key ) {
    if ( typeof $.jStorage === "object" ) {
      var result = $.jStorage.get( key );
      return result ? result.toString() : result;
    } else {
      return localStorage.getItem( key );
    }
  };

  /**
   * Delete data from browser storage by specified key
   *
   * @param [String] key
   *
   * @return void
   */
  browserStorage.remove = function( key ) {
    if ( typeof $.jStorage === "object" ) {
      $.jStorage.deleteKey( key );
    } else {
      localStorage.removeItem( key );
    }
  };

  Sisyphus = ( function() {
    var params = {
      instantiated: null,
      started: null
    };

    function init () {

      return {
        /**
         * Set plugin initial options
         *
         * @param [Object] options
         *
         * @return void
         */
        setInitialOptions: function ( options ) {
          var defaults = {
            excludeFields: [],
            customKeyPrefix: "",
            timeout: 0,
            autoRelease: true,
            name: null,
            onSave: function() {},
            onBeforeRestore: function() {},
            onRestore: function() {},
            onRelease: function() {}
          };
          this.options = this.options || $.extend( defaults, options );
          this.browserStorage = browserStorage;
        },

        /**
         * Set plugin options
         *
         * @param [Object] options
         *
         * @return void
         */
{'fraction_non_alphanumeric': 0.131380609797876, 'fraction_numerical': 0.0013703323055841042, 'mean_word_length': 1.8276029055690073, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '4372645', 'n_tokens_mistral': 1740, 'n_tokens_neox': 1701, 'n_words': 452}