implentado local valor

This commit is contained in:
Luiz Silva 2025-10-18 16:15:35 -03:00
parent 4637042883
commit 4a319bef73
8 changed files with 392 additions and 290 deletions

View file

@ -23,6 +23,7 @@ __reExport(index_exports, require("./dayjs"), module.exports);
__reExport(index_exports, require("./ecosistema"), module.exports);
__reExport(index_exports, require("./extensoes"), module.exports);
__reExport(index_exports, require("./graficosPilao"), module.exports);
__reExport(index_exports, require("./local"), module.exports);
__reExport(index_exports, require("./logger"), module.exports);
__reExport(index_exports, require("./postgres"), module.exports);
__reExport(index_exports, require("./testes-de-variaveis"), module.exports);
@ -41,6 +42,7 @@ __reExport(index_exports, require("./variaveisComuns"), module.exports);
...require("./ecosistema"),
...require("./extensoes"),
...require("./graficosPilao"),
...require("./local"),
...require("./logger"),
...require("./postgres"),
...require("./testes-de-variaveis"),

46
dist-back/local/index.js Normal file
View file

@ -0,0 +1,46 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var local_exports = {};
__export(local_exports, {
localValor: () => localValor
});
module.exports = __toCommonJS(local_exports);
const localValor = (chave_, valor) => {
const localStorage = globalThis.localStorage;
if (typeof localStorage == "undefined") return null;
const chave = typeof chave_ === "string" ? chave_ : encodeURIComponent(JSON.stringify(chave_));
try {
if (valor !== void 0) {
localStorage.setItem(chave, JSON.stringify(valor));
}
const v2 = localStorage.getItem(chave);
if (v2 === null) return null;
try {
return JSON.parse(v2);
} catch {
return v2;
}
} catch {
return null;
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
localValor
});

View file

@ -111,6 +111,12 @@ declare const graficos_pilao: {
};
};
/**
* LocalStorage Tipado
* ou grava um valor no localStorage, mantendo o tipo genérico <T>.
*/
declare const localValor: <T>(chave_: string | any, valor?: T | null) => T | null;
type tipoLokiObjeto = {
streams: {
stream: {
@ -302,4 +308,4 @@ declare const nomeVariavel: (v: {
[key: string]: any;
}) => string;
export { TipagemRotas, type TipoLoggerSessao, aleatorio, cacheM, cacheMFixo, cacheMemoria, camposComuns, cdn_carro_de_boi, defineCwd, erUuid, esperar, extensoes, graficos_pilao, type interfaceConsulta, logger, nomeVariavel, objetoPg, operadores, paraObjetoRegistroPg, pgObjeto, postLogger, siglas_unidades_medida, texto_busca, tipoArquivo, type tipoFiltro, type tipoLogger, type tipoLoggerLog, type tipoLokiObjeto, tipoUsuarioResiduos, tx, umaFuncao, umaVariavel, unidades_medida, uuid, uuidV3, uuidV4, uuid_null, validarUuid, verCacheM, zFiltro, zOperadores };
export { TipagemRotas, type TipoLoggerSessao, aleatorio, cacheM, cacheMFixo, cacheMemoria, camposComuns, cdn_carro_de_boi, defineCwd, erUuid, esperar, extensoes, graficos_pilao, type interfaceConsulta, localValor, logger, nomeVariavel, objetoPg, operadores, paraObjetoRegistroPg, pgObjeto, postLogger, siglas_unidades_medida, texto_busca, tipoArquivo, type tipoFiltro, type tipoLogger, type tipoLoggerLog, type tipoLokiObjeto, tipoUsuarioResiduos, tx, umaFuncao, umaVariavel, unidades_medida, uuid, uuidV3, uuidV4, uuid_null, validarUuid, verCacheM, zFiltro, zOperadores };

File diff suppressed because one or more lines are too long

View file

@ -1,6 +1,6 @@
{
"name": "p-comuns",
"version": "0.243.0",
"version": "0.246.0",
"description": "",
"main": "./dist-back/index.js",
"module": "./dist-front/index.mjs",
@ -26,15 +26,15 @@
"license": "ISC",
"dependencies": {
"cross-fetch": "4.1.0",
"dayjs": "^1.11.15",
"dayjs": "^1.11.18",
"uuid": "^11.1.0",
"zod": "4.1.4"
},
"devDependencies": {
"@biomejs/biome": "2.1.4",
"@types/node": "^20.19.11",
"@types/node": "^20.19.22",
"tsup": "8.5.0",
"typescript": "~5.9.2",
"typescript": "~5.9.3",
"vitest": "^3.2.4"
}
}

577
pnpm-lock.yaml generated

File diff suppressed because it is too large Load diff

View file

@ -6,6 +6,7 @@ export * from "./dayjs"
export * from "./ecosistema"
export * from "./extensoes"
export * from "./graficosPilao"
export * from "./local"
export * from "./logger"
export * from "./postgres"
export * from "./testes-de-variaveis"

38
src/local/index.ts Normal file
View file

@ -0,0 +1,38 @@
/**
* LocalStorage Tipado
* 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 = globalThis.localStorage
if (typeof localStorage == "undefined") return null
const chave =
typeof chave_ === "string"
? chave_
: encodeURIComponent(JSON.stringify(chave_))
try {
// Grava valor se fornecido
if (valor !== undefined) {
localStorage.setItem(chave, JSON.stringify(valor))
}
// Lê valor
const v2 = localStorage.getItem(chave)
if (v2 === null) return null
try {
return JSON.parse(v2) as T
} catch {
// Caso o valor não seja JSON válido
return v2 as unknown as T
}
} catch {
// Em caso de erro de acesso ao localStorage
return null
}
}