This commit is contained in:
Luiz Silva 2026-06-08 14:14:43 -03:00
parent 1e219ad657
commit 7e06927ca6
8 changed files with 119 additions and 4 deletions

View file

@ -38,6 +38,7 @@ __reExport(index_exports, require("./uuid"), module.exports);
__reExport(index_exports, require("./variaveisComuns"), module.exports);
__reExport(index_exports, require("./zCoordenadas"), module.exports);
__reExport(index_exports, require("./zDocumento"), module.exports);
__reExport(index_exports, require("./zodCustomizados"), module.exports);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
...require("./aleatorio"),
@ -62,5 +63,6 @@ __reExport(index_exports, require("./zDocumento"), module.exports);
...require("./uuid"),
...require("./variaveisComuns"),
...require("./zCoordenadas"),
...require("./zDocumento")
...require("./zDocumento"),
...require("./zodCustomizados")
});

View file

@ -0,0 +1,56 @@
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var zodCustomizados_exports = {};
__export(zodCustomizados_exports, {
zNumero: () => zNumero,
zNumeroInteiro: () => zNumeroInteiro,
zNumeroPositivo: () => zNumeroPositivo
});
module.exports = __toCommonJS(zodCustomizados_exports);
var import_zod = __toESM(require("zod"));
const zPreprocessarNumero = (p) => {
if (typeof p === "number") return p;
if (typeof p !== "string") return p;
let p2 = p;
if (p2.includes(",")) {
p2 = p2.replace(/\./g, "").replace(",", ".");
}
p2 = p2.replace(/[^0-9.]/g, "");
if (p2 == "") return null;
return Number(p2);
};
const zNumero = import_zod.default.preprocess(zPreprocessarNumero, import_zod.default.number());
const zNumeroPositivo = import_zod.default.preprocess(zPreprocessarNumero, import_zod.default.number().positive());
const zNumeroInteiro = import_zod.default.preprocess(zPreprocessarNumero, import_zod.default.number().int());
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
zNumero,
zNumeroInteiro,
zNumeroPositivo
});

View file

@ -580,4 +580,21 @@ declare const zDocCnpj: z.ZodString;
declare const zDocCpf: z.ZodString;
declare const zDocumento: z.ZodUnion<[z.ZodString, z.ZodString]>;
export { Produtos, TipagemRotas, type TipoPayloadAuditoria, aleatorio, cacheM, cacheMFixo, cacheMemoria, camposComuns, criarFiltroDelta, defineDayjsBr, erUuid, esperar, extensoes, iniciarDayjsBr, iniciarFiltroDelta, type interfaceConsulta, link_paiol, localValor, nomeVariavel, objetoPg, operadorFiltroDeltaDetalhes, operadores, paraObjetoRegistroPg, pgObjeto, siglas_unidades_medida, texto_busca, tipoArquivo, type tipoColunaFiltroDelta, type tipoCondicaoFiltroDelta, type tipoCondicaoFiltroDeltaTipado, type tipoFiltro, type tipoFiltroDelta, type tipoFiltroDeltaColunaTipada, type tipoOperadorFiltroDelta, tipoUsuarioResiduos, tiposSituacoesElicencie, tx, umaFuncao, umaVariavel, unidades_medida, uuid, uuidV3, uuidV4, uuid_null, validarUuid, verCacheM, zColunaFiltroDelta, zCondicaoFiltroDelta, zCoordenadas, zDocCnpj, zDocCpf, zDocumento, zFiltro, zFiltroDelta, zOperadorFiltroDelta, zOperadores };
/**
* Schema numérico que aceita strings legadas e normaliza para `number`.
*
* O campo **é** um número. O `preprocess` resolve compatibilidade com dados
* antigos onde o frontend enviava strings formatadas (BR ou monetária).
*
* Formatos de entrada aceitos:
* - `10` → number direto
* - `10.1` → ponto decimal
* - `10,1` → vírgula decimal (BR)
* - `1.000,1` → milhar com ponto + vírgula decimal (BR)
* - `R$ 10,01` → prefixo monetário legado
*/
declare const zNumero: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodNumber>;
declare const zNumeroPositivo: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodNumber>;
declare const zNumeroInteiro: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodNumber>;
export { Produtos, TipagemRotas, type TipoPayloadAuditoria, aleatorio, cacheM, cacheMFixo, cacheMemoria, camposComuns, criarFiltroDelta, defineDayjsBr, erUuid, esperar, extensoes, iniciarDayjsBr, iniciarFiltroDelta, type interfaceConsulta, link_paiol, localValor, nomeVariavel, objetoPg, operadorFiltroDeltaDetalhes, operadores, paraObjetoRegistroPg, pgObjeto, siglas_unidades_medida, texto_busca, tipoArquivo, type tipoColunaFiltroDelta, type tipoCondicaoFiltroDelta, type tipoCondicaoFiltroDeltaTipado, type tipoFiltro, type tipoFiltroDelta, type tipoFiltroDeltaColunaTipada, type tipoOperadorFiltroDelta, tipoUsuarioResiduos, tiposSituacoesElicencie, tx, umaFuncao, umaVariavel, unidades_medida, uuid, uuidV3, uuidV4, uuid_null, validarUuid, verCacheM, zColunaFiltroDelta, zCondicaoFiltroDelta, zCoordenadas, zDocCnpj, zDocCpf, zDocumento, zFiltro, zFiltroDelta, zNumero, zNumeroInteiro, zNumeroPositivo, zOperadorFiltroDelta, zOperadores };

File diff suppressed because one or more lines are too long

View file

@ -1,6 +1,6 @@
{
"name": "p-comuns",
"version": "0.347.0",
"version": "0.348.0",
"description": "",
"main": "./dist-front/index.mjs",
"module": "./dist-front/index.mjs",

Binary file not shown.

View file

@ -21,3 +21,4 @@ export * from "./uuid"
export * from "./variaveisComuns"
export * from "./zCoordenadas"
export * from "./zDocumento"
export * from "./zodCustomizados"

39
src/zodCustomizados.ts Normal file
View file

@ -0,0 +1,39 @@
import z from "zod"
const zPreprocessarNumero = (p: unknown) => {
if (typeof p === "number") return p
if (typeof p !== "string") return p
let p2 = p
if (p2.includes(",")) {
// ponto de milhar → remove; vírgula decimal → troca por ponto
p2 = p2.replace(/\./g, "").replace(",", ".")
}
// remove tudo que não seja dígito ou ponto decimal
p2 = p2.replace(/[^0-9.]/g, "")
if (p2 == "") return null
return Number(p2)
}
/**
* Schema numérico que aceita strings legadas e normaliza para `number`.
*
* O campo **é** um número. O `preprocess` resolve compatibilidade com dados
* antigos onde o frontend enviava strings formatadas (BR ou monetária).
*
* Formatos de entrada aceitos:
* - `10` → number direto
* - `10.1` → ponto decimal
* - `10,1` → vírgula decimal (BR)
* - `1.000,1` → milhar com ponto + vírgula decimal (BR)
* - `R$ 10,01` → prefixo monetário legado
*/
export const zNumero = z.preprocess(zPreprocessarNumero, z.number())
export const zNumeroPositivo = z.preprocess(zPreprocessarNumero, z.number().positive())
export const zNumeroInteiro = z.preprocess(zPreprocessarNumero, z.number().int())