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 / javascript-remove-accents.js
Last active August 13, 2024 19:35 — forked from fabiofdsantos/angularJS_removeAccents.js
An Javascript function to remove accents and others characters from an input string.
// Example: https://codepen.io/marcelo-ribeiro/pen/OJmVOyW
const accentsMap = new Map([
["A", "Á|À|Ã|Â|Ä"],
["a", "á|à|ã|â|ä"],
["E", "É|È|Ê|Ë"],
["e", "é|è|ê|ë"],
["I", "Í|Ì|Î|Ï"],
["i", "í|ì|î|ï"],
["O", "Ó|Ò|Ô|Õ|Ö"],
@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 / 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 / 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,
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 })
});
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
@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>