.
This commit is contained in:
parent
a6b3b14753
commit
e27bcd8e7c
14 changed files with 18 additions and 69 deletions
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
]),
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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]>
|
||||
}
|
||||
|
||||
/* =============================================================================
|
||||
|
|
|
|||
|
|
@ -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 || ""))
|
||||
|
|
|
|||
|
|
@ -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("/")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue