createWebStorage.js.flow 630 B

1234567891011121314151617181920212223
  1. // @flow
  2. import getStorage from './getStorage'
  3. export default function createWebStorage(type: string) {
  4. let storage = getStorage(type)
  5. return {
  6. getItem: (key: string): Promise<string> => {
  7. return new Promise((resolve, reject) => {
  8. resolve(storage.getItem(key))
  9. })
  10. },
  11. setItem: (key: string, item: string): Promise<void> => {
  12. return new Promise((resolve, reject) => {
  13. resolve(storage.setItem(key, item))
  14. })
  15. },
  16. removeItem: (key: string): Promise<void> => {
  17. return new Promise((resolve, reject) => {
  18. resolve(storage.removeItem(key))
  19. })
  20. },
  21. }
  22. }