/** * 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 }