Skip to content

Instantly share code, notes, and snippets.

View xbrunosousa's full-sized avatar
🏠

Bruno Sousa xbrunosousa

🏠
  • Brasília, Brazil.
View GitHub Profile
@xbrunosousa
xbrunosousa / format-brazil-phone-number.js
Last active October 11, 2021 09:54
Formata número de celular com DDI
const formatPhone = phone =>
phone
.replace(/\D/g, "") // Remove all NaN chars
.replace(/^(\d{2})(\d)/g, "+$1 $2") // Insert + in ddi and space on the end
.replace(/(\d{2})(\d)/, "($1) $2 ") // Insert () in ddd and space on the end
.replace(/(\d)(\d{4})$/, "$1-$2"); // Insert hyphen before 10º char
console.log("phone => ", formatPhone("5521999999999"));
@xbrunosousa
xbrunosousa / index.js
Created December 11, 2020 11:29
Remove accents from string | Javascript
const remove = str => str.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
@xbrunosousa
xbrunosousa / App.jsx
Created August 16, 2020 12:56
ExemploGrupoReactFb
import React, { useState, useRef } from "react";
export default () => {
const [state, setState] = useState({
animate: false,
inputValue: "",
inputActive: false
});
const inputRef = useRef(null);
import React, { useEffect, useState } from 'react';
export default () => {
const [isLoading, setLoading] = useState(true);
useEffect(() => {
setTimeout(() => setLoading(false), 2000);
}, []);
return (
@xbrunosousa
xbrunosousa / index.html
Created November 20, 2019 02:55
Reset form inputs
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<button onclick="reset()">Reset</button>
getGreetings = () => {
const h = new Date().getHours();
if (h <= 11) {
return 'Bom dia';
} else if (h >= 12 && h <= 17) {
return 'Boa tarde';
} else if (h >= 18 && h <= 23) {
return 'Boa noite';
}
};
import React, { Component } from 'react';
import fetchJsonp from 'fetch-jsonp';
class App extends Component {
send() {
fetchJsonp('https://www.receitaws.com.br/v1/cnpj/25336753000101')
.then(res => res.json())
.then(res => console.log(res));
}
render() {