.
This commit is contained in:
parent
a6b3b14753
commit
e27bcd8e7c
14 changed files with 18 additions and 69 deletions
|
|
@ -2,18 +2,11 @@
|
|||
* LocalStorage Tipado
|
||||
* Lê ou grava um valor no localStorage, mantendo o tipo genérico <T>.
|
||||
*/
|
||||
export const localValor = <T>(
|
||||
chave_: string | any,
|
||||
valor?: T | null,
|
||||
): T | null => {
|
||||
const localStorage =
|
||||
"localStorage" in globalThis ? (globalThis as any).localStorage : undefined
|
||||
export const localValor = <T>(chave_: string | any, valor?: T | null): T | null => {
|
||||
const localStorage = "localStorage" in globalThis ? (globalThis as any).localStorage : undefined
|
||||
if (typeof localStorage == "undefined") return null
|
||||
|
||||
const chave =
|
||||
typeof chave_ === "string"
|
||||
? chave_
|
||||
: encodeURIComponent(JSON.stringify(chave_))
|
||||
const chave = typeof chave_ === "string" ? chave_ : encodeURIComponent(JSON.stringify(chave_))
|
||||
|
||||
try {
|
||||
// Grava valor se fornecido
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue