Skip to content

Instantly share code, notes, and snippets.

View marcelo-ribeiro's full-sized avatar

Marcelo Ribeiro marcelo-ribeiro

  • Front-End Developer
  • Salvador, Bahia, Brasil
View GitHub Profile
@marcelo-ribeiro
marcelo-ribeiro / search-text.js
Last active August 12, 2024 22:55
javascript searching texts in a array of properties in a list of objects
const list = [
{ name: "Marcelo Ribeiro", short_name: "tchelo" },
{ name: "Leonardo Costa", short_name: "leo" },
{ name: "Victor Tanure", short_name: "vitrola" },
{ name: "Matheus Oliveira", short_name: "rary" }
];
let filteredList = [...list];
const searchProps = ["name", "short_name"];
let timeout = null;
const removeAccents = (text) => { return text; };
@marcelo-ribeiro
marcelo-ribeiro / UseSlugify Example
Last active February 28, 2024 05:37
useSlugify
import { useSlugify } from "./useSlugify";
const slugify = useSlugify();
console.log(slugify("São Paulo"));
@marcelo-ribeiro
marcelo-ribeiro / jest.config.ts
Created March 16, 2022 04:03
Config Jest on ViteJS — Just edit transform property. Source: https://www.youtube.com/watch?v=edXudaVB0Bg&ab_channel=Rocketseat
...
transform: {
'^.+\\.(t|j)sx?$': [
'@swc/jest',
{
jsc: {
parser: {
syntax: 'typescript',
tsx: true,
decorators: true,
const apiURL = "https://brasilapi.com.br/api";
const endpoint = `${apiURL}/cep/v2`;
/**
* @typedef IPayload
* @type {object}
* @property {string} cep
* @property {string} state
* @property {string} city
* @property {string} neighborhood
import api from 'api.js';
export default endpoint => ({
get: (id = "") => api.get(`${endpoint}/${id}`),
create: data => api.post(`${endpoint}`, data),
update: ({ id, ...data }) => api.put(`${endpoint}/${id}`, data),
patch: ({ id, ...data }) => api.patch(`${endpoint}/${id}`, data),
delete: id => api.delete(`${endpoint}/${id}`),
filterBy: params => api.get(`${endpoint}`, { params })
});
@marcelo-ribeiro
marcelo-ribeiro / object-switch.js
Last active July 30, 2021 03:37
JS Simple switch shortcut example
const getColor = () => "red";
const color = getColor();
({
red: () => alert("Vermelho"),
blue: () => alert("Azul")
}[color]?.());
// OR
@marcelo-ribeiro
marcelo-ribeiro / array-create-unique.js
Last active June 17, 2020 03:06
Create Unique Array, Remove Array Duplicates
const products = [
{id: 1, title: "Trim Dress", category: "women", collection: ["new", "featured"]},
{id: 2, title: "Belted Dress", category: "women", collection: ["featured"]},
{id: 3, title: "Fitted Dress", category: "men", collection: ["new"]}
];
const categories = new Set(
products.map(product => product.category)
);
@marcelo-ribeiro
marcelo-ribeiro / countries.html
Created May 18, 2020 13:05
HTML select of countries
<select>
<option>Afghanistan</option>
<option>Akrotiri</option>
<option>Albania</option>
<option>Algeria</option>
<option>American Samoa</option>
<option>Andorra</option>
<option>Angola</option>
<option>Anguilla</option>
<option>Antarctica</option>
@marcelo-ribeiro
marcelo-ribeiro / how-to-detect-a-click-outside-of-an-element-with-vanilla-javascript.markdown
Last active February 3, 2024 12:44
How to detect a click outside of an element with vanilla JavaScript

How to detect a click outside of an element with vanilla JavaScript

A simple way to detect a click outside of an element with vanilla JavaScript

A Pen by Marcelo Ribeiro on CodePen.

License.

@marcelo-ribeiro
marcelo-ribeiro / capitalize.js
Last active August 14, 2019 21:37
Javascript String Capitalize
export const capitalize = value => {
if (!value) return "";
const list = value.toString().trim().split(" ");
list.forEach((item, index) => {
list[index] = item[0].toUpperCase() + item.slice(1).toLowerCase();
});
return list.join(" ");