diff --git a/src/utils/index.js b/src/utils/index.js new file mode 100644 index 0000000..90c7464 --- /dev/null +++ b/src/utils/index.js @@ -0,0 +1 @@ +export {default as store} from './store' diff --git a/src/utils/store.js b/src/utils/store.js new file mode 100644 index 0000000..ac37611 --- /dev/null +++ b/src/utils/store.js @@ -0,0 +1,25 @@ +const NAMESPACE = 'emoji-picker' + +function update(state) { + for (let key in state) { + let value = state[key] + set(key, value) + } +} + +function set(key, value) { + if (!('localStorage' in window)) return + window.localStorage[`${NAMESPACE}.${key}`] = JSON.stringify(value) +} + +function get(key) { + if (!('localStorage' in window)) return + + var value = window.localStorage[`${NAMESPACE}.${key}`] + + if (value) { + return JSON.parse(value) + } +} + +export default { update, set, get }