This commit is contained in:
MarcioJRGodoi 2026-04-14 13:57:56 -03:00
commit 8bc2127e6c
23 changed files with 869 additions and 279 deletions

View file

@ -12,11 +12,7 @@ const _cache: {
;(globalThis as any).cacheMemoria_cache = _cache
export const cacheM = <T>(
chave: any,
valor?: T,
validadeSeg?: number,
): T | undefined => {
export const cacheM = <T>(chave: any, valor?: T, validadeSeg?: number): T | undefined => {
// converte a chave e string
const txChave: string =
typeof chave == "string"

View file

@ -30,17 +30,7 @@ export type interfaceConsulta = {
apenasContagem?: boolean
}
export const zOperadores = z.enum([
"=",
"!=",
">",
">=",
"<",
"<=",
"like",
"in",
"isNull",
])
export const zOperadores = z.enum(["=", "!=", ">", ">=", "<", "<=", "like", "in", "isNull"])
export const zFiltro = z.object({
coluna: z.string(),

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

@ -162,9 +162,7 @@ export const extensoes: {
* @param nomeArquivo
* @returns
*/
export const tipoArquivo = (
nomeArquivo: string | null | undefined,
): tiposArquivo => {
export const tipoArquivo = (nomeArquivo: string | null | undefined): tiposArquivo => {
// extenssão do arquivo
const extArquivo = String(nomeArquivo || "")
.toLocaleLowerCase()

View file

@ -2,18 +2,11 @@
* 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 =
"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

View file

@ -14,9 +14,7 @@ export const paraObjetoRegistroPg = (entrada: {
k,
v === undefined || v == null
? v
: typeof v == "string" ||
typeof v == "number" ||
typeof v == "boolean"
: typeof v == "string" || typeof v == "number" || typeof v == "boolean"
? v
: JSON.stringify(v, null, 2),
]),

View file

@ -63,9 +63,7 @@ export class TipagemRotas<T extends { [q: string]: any }> {
*/
endereco(query: T, usarComoHash?: boolean) {
const win =
(typeof globalThis !== "undefined" && (globalThis as any).window) ||
undefined
const win = (typeof globalThis !== "undefined" && (globalThis as any).window) || undefined
const url = new URL(win ? win.location.href : "http://localhost")
url.pathname = this.caminho
@ -96,9 +94,7 @@ export class TipagemRotas<T extends { [q: string]: any }> {
if (this._acaoIr) {
this._acaoIr(this.endereco({ ...query }))
} else {
const win =
(typeof globalThis !== "undefined" && (globalThis as any).window) ||
undefined
const win = (typeof globalThis !== "undefined" && (globalThis as any).window) || undefined
if (win) {
win.location.href = this.endereco({ ...query })
}
@ -124,9 +120,7 @@ export class TipagemRotas<T extends { [q: string]: any }> {
// pegar hash
const hash = url.hash
if (hash) {
const hashObj = Object.fromEntries(
new URLSearchParams(hash.slice(1)).entries(),
)
const hashObj = Object.fromEntries(new URLSearchParams(hash.slice(1)).entries())
queryObj = { ...queryObj, ...hashObj } as T
}

View file

@ -164,9 +164,7 @@ type IsPlainObject<T> = T extends object
============================================================================= */
type FiltroCampos<T> = {
[K in keyof T]?: IsPlainObject<T[K]> extends true
? tipoFiltro26<T[K]>
: PgOpsFor<T[K]>
[K in keyof T]?: IsPlainObject<T[K]> extends true ? tipoFiltro26<T[K]> : PgOpsFor<T[K]>
}
/* =============================================================================

View file

@ -6,8 +6,7 @@ import { NIL, v3, v4 } from "uuid"
* @param valor - A string que será validada.
* @returns booleano indicando se é um UUID válido.
*/
export const erUuid =
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i
export const erUuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i
export const validarUuid = (uuid: string | number | undefined | null) => {
const retorno = erUuid.test(String(uuid || ""))

View file

@ -1,7 +1,5 @@
export const esperar = (ms: number): Promise<true> =>
new Promise((resolve: (r: true) => void) =>
setTimeout(() => resolve(true), ms),
)
new Promise((resolve: (r: true) => void) => setTimeout(() => resolve(true), ms))
/**
* Usado para retronat o no de uma variável, deve ser usado dentro de um objeto
* const nomex = {a: 1, b: 2}
@ -9,5 +7,4 @@ export const esperar = (ms: number): Promise<true> =>
* @param v
* @returns
*/
export const nomeVariavel = (v: { [key: string]: any }) =>
Object.keys(v).join("/")
export const nomeVariavel = (v: { [key: string]: any }) => Object.keys(v).join("/")