Skip to content

Instantly share code, notes, and snippets.

import { FC } from "react";
import { Box, Text } from "grommet";
interface LoadingPlaceholderProps {
label?: string;
}
const LoadingPlaceholder: FC<LoadingPlaceholderProps> = ({
label = "Carregando",
}) => {

🧼 Função removeUndefinedFields

Remove campos com valor undefined de objetos (e opcionalmente arrays/objetos vazios) de forma recursiva.

✨ Opções (CleanOptions)

type CleanOptions = {
  removeEmptyArrays?: boolean;
  removeEmptyObjects?: boolean;
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);
}
@rb-cesar
rb-cesar / README.md
Created November 26, 2024 12:48 — forked from lopspower/README.md
Hexadecimal color code for transparency

Hexadecimal color code for transparency

Twitter

How to set transparency with hex value ?

For example, you want to set 40% alpha transparence to #000000 (black color), you need to add 66 like this #66000000.

Download This sample on Google Play Store

const image = new Image();
image.src = imageSrc;
console.log({
width: image.width,
height: image.height,
});
@rb-cesar
rb-cesar / htmlDecode.ts
Last active April 17, 2024 21:13
Get characters in string HTML code without executing the same
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));
@rb-cesar
rb-cesar / entryKeys.ts
Created May 4, 2023 18:10
Get specific keys from an object
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 = {
@rb-cesar
rb-cesar / validate.ts
Last active September 1, 2025 19:39
List of validators
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[] = [];