blob: b20feba3ba83f4d012c79ca9baab21e9d31f5d00 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
/**
* Gets the address data from local storage.
*
* @returns {object} - Returns the address data as an object, or an empty object if not found.
*/
const getAddress = () => {
if (typeof window !== 'undefined' && window.localStorage) {
const address = localStorage.getItem('address')
if (address) return JSON.parse(address)
}
return {}
}
/**
* Sets the address data to local storage.
*
* @param {object} address - The address data to be stored as an object.
* @returns {boolean} - Returns `true` if the address data is successfully stored, `false` otherwise.
*/
const setAddress = (address) => {
if (typeof window !== 'undefined' && window.localStorage) {
localStorage.setItem('address', JSON.stringify(address))
return true
}
return false
}
/**
* Gets the value of a specific key from the address data.
*
* @param {string} key - The key of the address data to be retrieved.
* @returns {*} - The value of the specified key, or false if the key does not exist.
*/
const getItemAddress = (key) => {
let address = getAddress()
return address[key] || false
}
/**
* Updates the value of a specific key in the address data.
*
* @param {string} key - The key of the address data to be updated.
* @param {*} value - The new value to be set for the specified key.
* @returns {boolean} - Returns `true`
*/
const updateItemAddress = (key, value) => {
let address = getAddress()
address[key] = value
setAddress(address)
return true
}
export { getItemAddress, updateItemAddress }
|