This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const remove = str => str.normalize("NFD").replace(/[\u0300-\u036f]/g, ""); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { useState, useRef } from "react"; | |
| export default () => { | |
| const [state, setState] = useState({ | |
| animate: false, | |
| inputValue: "", | |
| inputActive: false | |
| }); | |
| const inputRef = useRef(null); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { useEffect, useState } from 'react'; | |
| export default () => { | |
| const [isLoading, setLoading] = useState(true); | |
| useEffect(() => { | |
| setTimeout(() => setLoading(false), 2000); | |
| }, []); | |
| return ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'; | |
| } | |
| }; |