/** @format */

interface setStorageProps {
    (name: string, value: any): Error | null;
}
/**
 *
 * @param {string} name 需要存储的key
 * @param {any} value 需要存志的value
 */
export const setLocalStorage: setStorageProps = (name: string, value: any) => {
    let result = null;
    try {
        localStorage.setItem(name, JSON.stringify(value));
    } catch (err) {
        result = err;
    }
    return result;
};
export type storageResponse = [string | null, any];
interface getItemStorageProps {
    (nams: string): storageResponse;
}
/**
 * @param {string} name 需要读取的key
 * @return {array} 返回的值
 */
export const getLocalStorage: getItemStorageProps = (name: string) => {
    let result: [string | null, any] = [null, null];
    try {
        const value = localStorage.getItem(name);
        if (value) {
            const parseValue = JSON.parse(value);
            result = [null, parseValue];
        }
    } catch (error) {
        result = [error.message, null];
    }
    return result;
};
