Compare commits

..

1 commit

Author SHA1 Message Date
e4662fe240 definirDayjsbr 2026-02-19 10:39:01 -03:00
12 changed files with 95 additions and 242 deletions

58
dist-back/dayjs.js Normal file
View file

@ -0,0 +1,58 @@
"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 dayjs_exports = {};
__export(dayjs_exports, {
definirDayjsbr: () => definirDayjsbr
});
module.exports = __toCommonJS(dayjs_exports);
var import_duration = __toESM(require("dayjs/plugin/duration"));
var import_isSameOrAfter = __toESM(require("dayjs/plugin/isSameOrAfter"));
var import_isSameOrBefore = __toESM(require("dayjs/plugin/isSameOrBefore"));
var import_minMax = __toESM(require("dayjs/plugin/minMax"));
var import_relativeTime = __toESM(require("dayjs/plugin/relativeTime"));
var import_timezone = __toESM(require("dayjs/plugin/timezone"));
var import_utc = __toESM(require("dayjs/plugin/utc"));
var import_weekOfYear = __toESM(require("dayjs/plugin/weekOfYear"));
var import_pt_br = require("dayjs/locale/pt-br");
const definirDayjsbr = (dayjsEntrada) => {
dayjsEntrada.locale("pt-br");
dayjsEntrada.extend(import_utc.default);
dayjsEntrada.extend(import_timezone.default);
dayjsEntrada.extend(import_weekOfYear.default);
dayjsEntrada.extend(import_isSameOrBefore.default);
dayjsEntrada.extend(import_isSameOrAfter.default);
dayjsEntrada.extend(import_minMax.default);
dayjsEntrada.extend(import_relativeTime.default);
dayjsEntrada.extend(import_duration.default);
return dayjsEntrada;
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
definirDayjsbr
});

View file

@ -1,49 +0,0 @@
"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 dayjs26_exports = {};
__export(dayjs26_exports, {
defineDayjsBr: () => defineDayjsBr
});
module.exports = __toCommonJS(dayjs26_exports);
const defineDayjsBr = ({
dayjs,
duration,
isSameOrAfter,
isSameOrBefore,
minMax,
relativeTime,
timezone,
utc,
weekOfYear
}) => {
dayjs.extend(utc);
dayjs.extend(timezone);
dayjs.extend(weekOfYear);
dayjs.extend(isSameOrBefore);
dayjs.extend(isSameOrAfter);
dayjs.extend(minMax);
dayjs.extend(relativeTime);
dayjs.extend(duration);
dayjs.locale("pt-br");
return dayjs;
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
defineDayjsBr
});

View file

@ -19,7 +19,7 @@ __reExport(index_exports, require("./aleatorio"), module.exports);
__reExport(index_exports, require("./cacheMemoria"), module.exports);
__reExport(index_exports, require("./constantes"), module.exports);
__reExport(index_exports, require("./consulta"), module.exports);
__reExport(index_exports, require("./dayjs26"), module.exports);
__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("./extensoes"), module.exports);
@ -41,7 +41,7 @@ __reExport(index_exports, require("./variaveisComuns"), module.exports);
...require("./cacheMemoria"),
...require("./constantes"),
...require("./consulta"),
...require("./dayjs26"),
...require("./dayjs"),
...require("./ecosistema"),
...require("./extensoes"),
...require("./extensoes"),

View file

@ -1,14 +1,6 @@
import z, { z as z$1 } from 'zod';
import _dayjs from 'dayjs';
import dayjs from 'dayjs';
export { Dayjs, ManipulateType } from 'dayjs';
import _duration from 'dayjs/plugin/duration';
import _isSameOrAfter from 'dayjs/plugin/isSameOrAfter';
import _isSameOrBefore from 'dayjs/plugin/isSameOrBefore';
import _minMax from 'dayjs/plugin/minMax';
import _relativeTime from 'dayjs/plugin/relativeTime';
import _timezone from 'dayjs/plugin/timezone';
import _utc from 'dayjs/plugin/utc';
import _weekOfYear from 'dayjs/plugin/weekOfYear';
import { v4 } from 'uuid';
declare const aleatorio: (tamanho?: number) => string;
@ -101,69 +93,7 @@ declare const zFiltro: z.ZodObject<{
ou: z.ZodOptional<z.ZodBoolean>;
}, z.core.$strip>;
/**
* Utilitário de configuração do Dayjs focado em compatibilidade com SSR.
*
* PROBLEMA:
* A importação direta do `dayjs` e seus plugins frequentemente causa conflitos em ambientes
* de Renderização do Lado do Servidor (SSR), como Nuxt ou Next.js, devido a discrepâncias
* na resolução de módulos (ESM vs CJS) e instabilidades de importação.
*
* SOLUÇÃO:
* Este módulo utiliza o padrão de Injeção de Dependência. Ele expõe apenas tipagens e
* uma função de configuração (`defineDayjsBr`). A responsabilidade de importar as
* bibliotecas "vivas" é delegada à aplicação consumidora (o cliente da função).
*
* Isso permite que o bundler da aplicação principal (Vite, Webpack, etc.) gerencie as
* instâncias, garantindo consistência e evitando erros de "module not found" ou
* instâncias duplicadas/não inicializadas adequadamente.
*/
/**
* Inicializa e configura o Dayjs com o locale 'pt-br' e plugins essenciais.
*
* MODO DE USO:
* Importe os pacotes reais na sua aplicação e passe-os para esta função.
*
* @example
* ```ts
* // Em seu arquivo de configuração (ex: plugins/dayjs.ts):
* import dayjs from "dayjs"
* import duration from "dayjs/plugin/duration"
* import isSameOrAfter from "dayjs/plugin/isSameOrAfter"
* import isSameOrBefore from "dayjs/plugin/isSameOrBefore"
* import minMax from "dayjs/plugin/minMax"
* import relativeTime from "dayjs/plugin/relativeTime"
* import timezone from "dayjs/plugin/timezone"
* import utc from "dayjs/plugin/utc"
* import weekOfYear from "dayjs/plugin/weekOfYear"
* import { defineDayjsBr } from "p-comuns"
* import "dayjs/locale/pt-br" // Importante: importar o locale!
* export const dayjsbr = defineDayjsBr({
* dayjs,
* duration,
* isSameOrAfter,
* isSameOrBefore,
* minMax,
* relativeTime,
* timezone,
* utc,
* weekOfYear,
* })
* ```
*/
declare const defineDayjsBr: ({ dayjs, duration, isSameOrAfter, isSameOrBefore, minMax, relativeTime, timezone, utc, weekOfYear, }: {
dayjs: typeof _dayjs;
duration: typeof _duration;
isSameOrAfter: typeof _isSameOrAfter;
isSameOrBefore: typeof _isSameOrBefore;
minMax: typeof _minMax;
relativeTime: typeof _relativeTime;
timezone: typeof _timezone;
utc: typeof _utc;
weekOfYear: typeof _weekOfYear;
}) => typeof _dayjs;
declare const definirDayjsbr: (dayjsEntrada: typeof dayjs) => typeof dayjs;
declare const link_paiol = "https://paiol.idz.one";
@ -537,4 +467,4 @@ declare const nomeVariavel: (v: {
[key: string]: any;
}) => string;
export { Produtos, TipagemRotas, agrupadores26, aleatorio, cacheM, cacheMFixo, cacheMemoria, camposComuns, criarFiltro26, defineDayjsBr, erUuid, esperar, extensoes, type interfaceConsulta, link_paiol, localValor, nomeVariavel, objetoPg, operadores, operadores26, paraObjetoRegistroPg, pgObjeto, siglas_unidades_medida, texto_busca, tipoArquivo, type tipoFiltro, type tipoFiltro26, tipoUsuarioResiduos, tiposSituacoesElicencie, tx, umaFuncao, umaVariavel, unidades_medida, uuid, uuidV3, uuidV4, uuid_null, validarUuid, verCacheM, zFiltro, zFiltro26, zOperadores };
export { Produtos, TipagemRotas, agrupadores26, aleatorio, cacheM, cacheMFixo, cacheMemoria, camposComuns, criarFiltro26, definirDayjsbr, erUuid, esperar, extensoes, type interfaceConsulta, link_paiol, localValor, nomeVariavel, objetoPg, operadores, operadores26, paraObjetoRegistroPg, pgObjeto, siglas_unidades_medida, texto_busca, tipoArquivo, type tipoFiltro, type tipoFiltro26, tipoUsuarioResiduos, tiposSituacoesElicencie, tx, umaFuncao, umaVariavel, unidades_medida, uuid, uuidV3, uuidV4, uuid_null, validarUuid, verCacheM, zFiltro, zFiltro26, zOperadores };

File diff suppressed because one or more lines are too long

View file

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

Binary file not shown.

29
src/dayjs.ts Executable file
View file

@ -0,0 +1,29 @@
import type dayjs from "dayjs"
import type { Dayjs } from "dayjs"
export type { ManipulateType } from "dayjs"
import duration from "dayjs/plugin/duration"
import isSameOrAfter from "dayjs/plugin/isSameOrAfter"
import isSameOrBefore from "dayjs/plugin/isSameOrBefore"
import minMax from "dayjs/plugin/minMax"
import relativeTime from "dayjs/plugin/relativeTime"
import timezone from "dayjs/plugin/timezone"
import utc from "dayjs/plugin/utc"
import weekOfYear from "dayjs/plugin/weekOfYear"
import "dayjs/locale/pt-br"
export const definirDayjsbr = (dayjsEntrada: typeof dayjs) => {
dayjsEntrada.locale("pt-br")
dayjsEntrada.extend(utc)
dayjsEntrada.extend(timezone)
dayjsEntrada.extend(weekOfYear)
dayjsEntrada.extend(isSameOrBefore)
dayjsEntrada.extend(isSameOrAfter)
dayjsEntrada.extend(minMax)
dayjsEntrada.extend(relativeTime)
dayjsEntrada.extend(duration)
return dayjsEntrada
}
export type { Dayjs }

View file

@ -1,107 +0,0 @@
/**
* Utilitário de configuração do Dayjs focado em compatibilidade com SSR.
*
* PROBLEMA:
* A importação direta do `dayjs` e seus plugins frequentemente causa conflitos em ambientes
* de Renderização do Lado do Servidor (SSR), como Nuxt ou Next.js, devido a discrepâncias
* na resolução de módulos (ESM vs CJS) e instabilidades de importação.
*
* SOLUÇÃO:
* Este módulo utiliza o padrão de Injeção de Dependência. Ele expõe apenas tipagens e
* uma função de configuração (`defineDayjsBr`). A responsabilidade de importar as
* bibliotecas "vivas" é delegada à aplicação consumidora (o cliente da função).
*
* Isso permite que o bundler da aplicação principal (Vite, Webpack, etc.) gerencie as
* instâncias, garantindo consistência e evitando erros de "module not found" ou
* instâncias duplicadas/não inicializadas adequadamente.
*/
import type _dayjs from "dayjs"
import type { Dayjs } from "dayjs"
export type { ManipulateType } from "dayjs"
// Importação apenas de TIPOS para evitar bundling indesejado neste arquivo
import type _duration from "dayjs/plugin/duration"
import type _isSameOrAfter from "dayjs/plugin/isSameOrAfter"
import type _isSameOrBefore from "dayjs/plugin/isSameOrBefore"
import type _minMax from "dayjs/plugin/minMax"
import type _relativeTime from "dayjs/plugin/relativeTime"
import type _timezone from "dayjs/plugin/timezone"
import type _utc from "dayjs/plugin/utc"
import type _weekOfYear from "dayjs/plugin/weekOfYear"
/**
* Inicializa e configura o Dayjs com o locale 'pt-br' e plugins essenciais.
*
* MODO DE USO:
* Importe os pacotes reais na sua aplicação e passe-os para esta função.
*
* @example
* ```ts
* // Em seu arquivo de configuração (ex: plugins/dayjs.ts):
* import dayjs from "dayjs"
* import duration from "dayjs/plugin/duration"
* import isSameOrAfter from "dayjs/plugin/isSameOrAfter"
* import isSameOrBefore from "dayjs/plugin/isSameOrBefore"
* import minMax from "dayjs/plugin/minMax"
* import relativeTime from "dayjs/plugin/relativeTime"
* import timezone from "dayjs/plugin/timezone"
* import utc from "dayjs/plugin/utc"
* import weekOfYear from "dayjs/plugin/weekOfYear"
* import { defineDayjsBr } from "p-comuns"
* import "dayjs/locale/pt-br" // Importante: importar o locale!
* export const dayjsbr = defineDayjsBr({
* dayjs,
* duration,
* isSameOrAfter,
* isSameOrBefore,
* minMax,
* relativeTime,
* timezone,
* utc,
* weekOfYear,
* })
* ```
*/
const defineDayjsBr = ({
dayjs,
duration,
isSameOrAfter,
isSameOrBefore,
minMax,
relativeTime,
timezone,
utc,
weekOfYear,
}: {
dayjs: typeof _dayjs
duration: typeof _duration
isSameOrAfter: typeof _isSameOrAfter
isSameOrBefore: typeof _isSameOrBefore
minMax: typeof _minMax
relativeTime: typeof _relativeTime
timezone: typeof _timezone
utc: typeof _utc
weekOfYear: typeof _weekOfYear
}) => {
// Extensão da biblioteca com os plugins fornecidos
dayjs.extend(utc)
dayjs.extend(timezone)
dayjs.extend(weekOfYear)
dayjs.extend(isSameOrBefore)
dayjs.extend(isSameOrAfter)
dayjs.extend(minMax)
dayjs.extend(relativeTime)
dayjs.extend(duration)
// Definição do locale global
dayjs.locale("pt-br")
return dayjs
}
export { defineDayjsBr }
export type { Dayjs }

View file

@ -2,7 +2,7 @@ export * from "./aleatorio"
export * from "./cacheMemoria"
export * from "./constantes"
export * from "./consulta"
export * from "./dayjs26"
export * from "./dayjs"
export * from "./ecosistema"
export * from "./extensoes"
export * from "./extensoes"

View file

@ -18,10 +18,6 @@ export const tsup_config_back: Options = {
minify: false, // Geralmente não minificamos o código do backend em produção, mas você pode mudar
platform: "node",
outExtension: () => ({ js: ".js" }),
loader: {
".svg": "text",
".md": "text",
},
}
// Exporta a configuração padrão usando defineConfig

View file

@ -19,10 +19,6 @@ export const tsup_config_front: Options = {
external: ['dayjs', 'cross-fetch', 'uuid', 'zod'],
outExtension: () => ({ js: ".mjs" }),
shims: false,
loader: {
".svg": "text",
".md": "text",
},
}
// Exporta a configuração padrão usando defineConfig