Skip to content

Instantly share code, notes, and snippets.

View talitaoliveira's full-sized avatar

Talita Oliveira talitaoliveira

View GitHub Profile
@talitaoliveira
talitaoliveira / main-component-share.js
Last active July 20, 2020 15:45
Share component to render ShareNative (using web share api) or ShareLinks (with the specific links)
import React, { useState, useEffect } from 'react'
import ShareNative from '../ShareNative'
import ShareLinks from '../ShareLinks'
import * as S from './styled';
const hasShareNative = () => {
if (typeof navigator !== `undefined`) {
if (navigator.share) {
const frutas = ['banana', 'maçã', 'abacaxi', 'mamão']
frutas.forEach(fruta => console.log(`Eu preciso comer mais ${fruta}`));
/*
Após executar:
Eu preciso comer mais banana
Eu preciso comer mais maçã
Eu preciso comer mais abacaxi
Eu preciso comer mais mamão
@talitaoliveira
talitaoliveira / chain-of-responsibility.js
Created April 22, 2020 20:02
Testing Chain of Responsibility Design pattern
class ProcessValidations {
/**
* Create concrete element
* @param {Array} validators
*/
constructor(transaction) {
this.validators = []
this.transaction = transaction
}
@talitaoliveira
talitaoliveira / rest-properties-object.js
Created December 1, 2018 14:49
Using the new feature of ES9: Rest Properties for objects
/**
* REST PROPERTIES
* Using the REST operator "..." to extract properties from an object
* */
const { website, ...moreInfo } = {
website: 'http://rec.jsday.com.br/',
day: 1,
month: 12,
@talitaoliveira
talitaoliveira / regexp-named-group.js
Created December 1, 2018 14:46
Using the new feature of ES9: Regexp named group
const RE_DATE = /(?<year>[0-9]{4})-(?<month>[0-9]{2})-(?<day>[0-9]{2})/;
const matchObj = RE_DATE.exec('2018-12-01');
console.log(matchObj);
/**
* [
* 0: "2018-12-01",
* 1: "2018",
@talitaoliveira
talitaoliveira / asynchronousIterator.js
Created December 1, 2018 14:45
Using the new feature of ES9: Asynchronous Iterator (for-await-of)
/**
* ASYNCHRONOUS ITERATION
* - Specifies an asynchronous version of the "for-of"loop.
* - With the "for-await-of" loop allows you to iterate
* promises and return them on the order that they were called.
*/
/**
* Let's imagine that we have 4 promises that they will
@talitaoliveira
talitaoliveira / exponentiation-operator.js
Created November 27, 2018 01:31
Using the new feature of ES7: Exponentiation Operator
/**
* EXPONENTIATION OPERATOR
* - Is the same as Math.pow()
* - Don't need to use the library Math
*/
// using Math library
let newNumber1 = Math.pow(4, 2);
console.log(newNumber1); // 16
@talitaoliveira
talitaoliveira / stringPaddingComplete.js
Last active November 27, 2018 01:32
Using the new feature of ES8: String Padding. Examples of use padStart() and padEnd()
/**
* STRING PADDING
* - When you need a string to reach a specific length.
* - Two ways to add characters: padStart() and padEnd()
* - Basic usage:
*
* padStart(finalLength, padString)
* padEnd(finalLength, padString)
*/
@talitaoliveira
talitaoliveira / finally.js
Last active November 27, 2018 01:32
Using the new feature of ES9: promise.prototype.finally()
/**
* PROMISE.PROTOTYPE.FINALLY()
* - Always executed
* - Allow to execute some code if the promise is successful or not successful
* - Similar to finally {} on synchronous code (try/catch/finally)
*/
// example
fetch('https://randomuser.me/api/?results=1')
.then(data => data.json())
@talitaoliveira
talitaoliveira / stringPadding.js
Last active November 14, 2018 03:08
Using String padding - ES8 (padStart and padEnd) by length of previous line.
const firstLine = '=======================================================';
const lastLine = firstLine;
const lenghtLines = firstLine.length;
let welcomeText = '⭐️ Hello World! Webpack + Babel! ⭐️';
const lengthText = welcomeText.length;
const leftToComplete = lenghtLines - lengthText;
const halfComplete = leftToComplete/2;
welcomeText = welcomeText.padStart(lenghtLines-halfComplete, '~');