All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dev.cheleb.ziolaminartapir.Storage.scala Maven / Gradle / Ivy

package dev.cheleb.ziolaminartapir

import zio.json.*

import org.scalajs.dom

object Storage {

  def set[A: JsonCodec](key: String, value: A): Unit =
    dom.window.localStorage.setItem(key, value.toJson)

  def get[A: JsonCodec](key: String): Option[A] =
    Option(dom.window.localStorage.getItem(key))
      .filter(_.nonEmpty)
      .flatMap(_.fromJson[A].toOption)

  def remove(key: String): Unit =
    dom.window.localStorage.removeItem(key)

  def removeAll(): Unit =
    dom.window.localStorage.clear()

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy