Skip to content

Instantly share code, notes, and snippets.

View thyagodias's full-sized avatar
🤹‍♂️
"Programming is the art of doing one thing at a time"

Thyago Dias thyagodias

🤹‍♂️
"Programming is the art of doing one thing at a time"
View GitHub Profile
const options = { year: "numeric", month: "long", day: "numeric" };
const date = new Date(2020, 11, 31) // 2020-12-31T03:00:00.000Z
console.log(date.toLocaleDateString("pt-br", options))
// 31 de dezembro de 2020
console.log(date.toLocaleDateString("pt-br", { ...options, month: 'numeric'}))
// 31/12/2020
const regex = /^([0-9]{4})[-](0[1-9]|1[0-2])[-](0[0-9]|1[0-9]|2[0-9]|3[0-1])/gm
const dateRx = new Date(2020, 11, 31) // 2020-12-31T03:00:00.000Z
@thyagodias
thyagodias / valor-mais-proximo.js
Created July 28, 2020 14:25
Encontra o valor mais aproximado dentro de uma matriz de valores numéricos
const valores = [
100,
200,
300,
350,
];
const valor = 120;
const maisProximo = valores.reduce(function (anterior, corrente) {
@thyagodias
thyagodias / node-debug.json
Created July 15, 2020 14:48
Arquivo para fazer debbug de aplicações NodeJS no VScode
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Typescript Node",
"restart": true,
"type": "node",
"request": "attach",
"protocol": "inspector",
"skipFiles": ["<node_internals>/**"]
@thyagodias
thyagodias / filter.js
Created March 7, 2020 15:02
Filtro com array.filter
const estados = [
{ nome: 'Acre' },
{ nome: 'Alagoas' },
{ nome: 'Amapá' },
{ nome: 'Amazonas' },
{ nome: 'Bahia' },
{ nome: 'Ceará' },
{ nome: 'Distrito Federal' },
{ nome: 'Espírito Santo' },
{ nome: 'Goiás' },
@thyagodias
thyagodias / ValidateCPF.js
Last active March 3, 2020 18:39
Validador de CPF
class ValidateCPF {
constructor (cpf) {
this.cpf = cpf.replace(/\D/g, '')
}
isValid () {
if (this.cpfWithRepeatedNumbers(this.cpf)) {
console.table({
valid: false,
cpf: this.cpf,