const MamiSettingsWebStorage = function(storage, prefix) {
    if(!(storage instanceof Storage))
        throw 'storage must be an instance of window.Storage';
    if(typeof prefix !== 'string')
        prefix = '';

    return {
        name: () => `webstorage:${prefix}`,
        delete: name => storage.removeItem(prefix + name),
        set: (name, value) => storage.setItem(prefix + name, value === undefined ? null : JSON.stringify(value)),
        get: name => {
            try {
                return JSON.parse(storage.getItem(prefix + name));
            } catch(ex) {
                return null;
            }
        },
    };
};
