项目作者: R-H-T

项目描述 :
IndexedDB Manager is made to simplify IndexedDB.
高级语言: JavaScript
项目地址: git://github.com/R-H-T/idb-man.git
创建时间: 2019-05-10T03:00:46Z
项目社区:https://github.com/R-H-T/idb-man

开源协议:MIT License

下载


idb-man

IndexedDB Manager is made to simplify IndexedDB.

Why use IndexedDB instead of LocalStorage?

Simple answer: It all depends on your project’s needs. If you’ll be using a shared preference with your Service Worker, then this is a good place for IndexedDB.

Getting started

Copy the idb-man folder in src to your project’s source and import it. E.g.:

  1. import IDBManager from './utility/idb-man';
  2. // Config
  3. const IDBM_DB_NAME = 'my-db-name';
  4. const IDBM_DB_VERSION = 1;
  5. const IDBM_OSKEY_USER_PREFERENCES = 'user-preferences';
  6. const osKeys = [{ key: IDBM_OSKEY_USER_PREFERENCES }];
  7. const idbm = new IDBManager(IDBM_DB_NAME, IDBM_DB_VERSION, osKeys);
  8. // Helpers
  9. const userPreferencesGetItem = async key => idbm.getItem(IDBM_OSKEY_USER_PREFERENCES, key);
  10. const userPreferencesSetItem = async (key, value) =>
  11. idbm.setItem(IDBM_OSKEY_USER_PREFERENCES, key, value);
  12. // User Preferences Keys
  13. const USER_PREFERENCES_DARK_MODE = 'dark-mode';
  14. /*...*/
  15. const toggleDarkMode = async () => {
  16. try {
  17. const oldValue = await userPreferencesGetItem(USER_PREFERENCES_DARK_MODE);
  18. await userPreferencesSetItem(USER_PREFERENCES_DARK_MODE, !oldValue);
  19. } catch (error) {
  20. console.error('Error:', error.message);
  21. }
  22. };

Contributions

Contributions are welcome. There are more features in IndexedDB to include.

License

MIT


Copyright ©2019 – Roberth Hansson-Tornéus (github.com/R-H-T)