Remove campos com valor undefined de objetos (e opcionalmente arrays/objetos vazios) de forma recursiva.
type CleanOptions = {
removeEmptyArrays?: boolean;
removeEmptyObjects?: boolean;| import { FC } from "react"; | |
| import { Box, Text } from "grommet"; | |
| interface LoadingPlaceholderProps { | |
| label?: string; | |
| } | |
| const LoadingPlaceholder: FC<LoadingPlaceholderProps> = ({ | |
| label = "Carregando", | |
| }) => { |
| export class Email { | |
| private readonly raw: string; | |
| constructor(raw: string) { | |
| this.raw = raw.trim(); | |
| } | |
| public get value(): string { | |
| return this.raw; | |
| } |
| export class CNPJ { | |
| private readonly raw: string; | |
| private readonly cleaned: string; | |
| constructor(raw: string) { | |
| this.raw = raw; | |
| this.cleaned = this.extractDigits(raw); | |
| } |
| const image = new Image(); | |
| image.src = imageSrc; | |
| console.log({ | |
| width: image.width, | |
| height: image.height, | |
| }); |
| export function htmlDecode(value: string) { | |
| const doc = new DOMParser().parseFromString(value, 'text/html'); | |
| return doc.documentElement.textContent; | |
| } |
| import { useEffect } from 'react'; | |
| export function useResizeObserver( | |
| elementRef: React.RefObject<HTMLElement> | null, | |
| callback?: (entries: ResizeObserverEntry[]) => void, | |
| ) { | |
| useEffect(() => { | |
| if (!elementRef?.current) return; | |
| const resizeObserver = new ResizeObserver(entries => callback?.(entries)); |
| type Nullable<T> = { | |
| [K in keyof T]: T[K] | null; | |
| }; | |
| export type ReturnOnly<OBJ, KeyName extends keyof OBJ> = { | |
| [K in KeyName]: OBJ[KeyName]; | |
| }; | |
| export function entryKeys<T extends any, K extends keyof T>(data: T, keys: K[]) { | |
| const ref = { |
| export type ValidationResult = { | |
| error: boolean; | |
| message: string; | |
| }; | |
| export type ValidationFunc<T> = (data: T) => ValidationResult | Promise<ValidationResult>; | |
| export async function validate<T extends any>(data: T, cbs: ValidationFunc<T>[]) { | |
| const results: ValidationResult[] = []; |