JavaScript的智能持久層:basil.js

jopen 10年前發布 | 11K 次閱讀 basil.js JavaScript開發

basil.js是一個JavaScript的智能持久層。

基本用法

basil = new window.Basil(options);

// basic methods basil.set('foo', 'bar'); // store 'bar' value under 'foo' key basil.get('foo'); // returns 'bar' basil.remove('foo'); // remove 'foo' value

// advanced methods basil.check('local'); // boolean. Test if localStorage is available basil.reset(); // reset all stored values under namespace for current storage</pre>

高級用法

basil = new window.Basil(options);

// force storage on the go through basil // set 'bar' value under 'foo' key in localStorage basil.set('foo', 'bar', { 'storage': 'local' });

// Access native storages // With basil API, but without namespace nor JSON parsing for values

// cookies basil.cookie.get(key); basil.cookie.set(key, value, { 'days': days, 'domain': 'mydomain.com' });

// localStorage basil.localStorage.get(key); basil.localStorage.set(key, value);

// sessionStorage basil.sessionStorage.get(key); basil.sessionStorage.set(key, value);</pre>

配置

Here is the whole options object that you could give to Basil:

options = {
  // Namespace. Namespace you Basil stored data
  // default: 'b45i1'
  namespace: 'foo',

  // storages. Specify all Basil supported storages and priority order
  // default: `['local', 'cookie', 'session', 'memory']`
  storages: ['cookie', 'local']

  // storage. Specify the default storage to use
  // default: detect best available storage among the supported ones
  storage: 'cookie'
};

項目主頁:http://www.baiduhome.net/lib/view/home/1406454696309

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!