\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{fersasil} \pdfinfo{ /Title (ts.pdf) /Creator (Cheatography) /Author (fersasil) /Subject (Ts Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{1C68A3} \definecolor{LightBackground}{HTML}{F0F5F9} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Ts Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{fersasil} via \textcolor{DarkBackground}{\uline{cheatography.com/136671/cs/28551/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}fersasil \\ \uline{cheatography.com/fersasil} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 13th July, 2021.\\ Updated 13th July, 2021.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{4} \begin{tabularx}{3.833cm}{x{1.7165 cm} x{1.7165 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Sem For}} \tn % Row 0 \SetRowColor{LightBackground} array.slice(inicio, fim?) & Cria uma nova lista \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} array.map(fn(item, index)) & Aplica a função fn para todos os items e retorna algo \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} \seqsplit{array.filter(fn(item))} & Filtra a array. Fn deve retornar true para o item que devera ser filtrado \tn % Row Count 9 (+ 4) % Row 3 \SetRowColor{white} \seqsplit{array.reduce(fn(accumulator}, current), valorInicial) & Para cada item na lista, a função é aplicada, retornando ao fim o valor total do acummulator \tn % Row Count 14 (+ 5) % Row 4 \SetRowColor{LightBackground} \seqsplit{array.forEach(fn(item}, index)) & Aplica a função fn para cada item do array \tn % Row Count 17 (+ 3) % Row 5 \SetRowColor{white} \seqsplit{array.join(delimitador)} & Transforma a array em uma string \tn % Row Count 19 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.54485 cm} x{1.88815 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Strings}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{str.split(delimitador)} & Retorna uma lista contendo os elementos da string separados pelo demilitador \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} str.toUpperCase() & Retorna a string com todos os caracteres maiusculos \tn % Row Count 7 (+ 3) % Row 2 \SetRowColor{LightBackground} str.toLowerCase() & Retorna a string com todos os caracteres minusculos \tn % Row Count 10 (+ 3) % Row 3 \SetRowColor{white} `Eu sou uma \$\{varialvelQualquer\}` & Interpolação de string \tn % Row Count 12 (+ 2) % Row 4 \SetRowColor{LightBackground} str + str 2 & Junta as duas strings \tn % Row Count 13 (+ 1) % Row 5 \SetRowColor{white} const str = "ola" & armazena a string ola dentro da constante str \tn % Row Count 16 (+ 3) % Row 6 \SetRowColor{LightBackground} const str = " ola '1' " & armazena a string ola '1' dentro da constante str \tn % Row Count 19 (+ 3) % Row 7 \SetRowColor{white} const str = ' ola "1" ' & armazena a string ola "1" dentro da constante str \tn % Row Count 22 (+ 3) % Row 8 \SetRowColor{LightBackground} \textbackslash{} & Caracter de escape \tn % Row Count 23 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.61351 cm} x{1.81949 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Funções}} \tn % Row 0 \SetRowColor{LightBackground} (parametro1, parametro2) =\textgreater{} \{\} & Cria uma nova arrow function \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{function(parametro1}, parametro2) \{\} & Cria uma nova função \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} () =\textgreater{} (\{key: valor\}) & cria uma arrow function de uma linha que retorna um objeto \tn % Row Count 7 (+ 3) % Row 3 \SetRowColor{white} () =\textgreater{} "ola" & Cria uma arrow function que retorna a string ola. Caso a arrow function possua apenas uma linha, não precisa de \{\} \tn % Row Count 13 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.7165 cm} x{1.7165 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Classes}} \tn % Row 0 \SetRowColor{LightBackground} class Oi \{\} & cria uma nova classe Oi \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} new Oi() & Instancia a classe Oi \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} constructor\{\} & Pode-se ser colocado dentro da classe para ter um construtor \tn % Row Count 7 (+ 3) % Row 3 \SetRowColor{white} Oi.metodo() & chama um novo metodo \tn % Row Count 8 (+ 1) % Row 4 \SetRowColor{LightBackground} class \seqsplit{ClassWithPrivateField} \{ \#privateField; \} & Cria uma classe com um campo privado. Serve para metodos ou atributos. Só precisa colocar \# antes \tn % Row Count 13 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.7165 cm} x{1.7165 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Coisas legais}} \tn % Row 0 \SetRowColor{LightBackground} const newObject = \{...oldObject\} & Cria um novo objeto igual ao anterior \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} const newList = {[}...oldList{]} & Cria uma lista igual a anterior \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} const {[}primeiro, segundo, terceiro{]} = {[}1, 2, 3{]} & Desconstroi a lista em três constantes \tn % Row Count 7 (+ 3) % Row 3 \SetRowColor{white} const {[}primeiro, segundo, terceiro{]} = obj & Desconstroi um obj para as constantes. O Objeto precisa ter as chaves iguais para funcionar! \tn % Row Count 12 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.27021 cm} x{2.16279 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Encontre o que procura}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{array.find(fn(item))} & Retorna o primeiro item encontrado ou undefined \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{array.indexOf(fn(item))} & Retorna o indice do primeiro item encontrado ou -1 \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \seqsplit{array.includes(item)} & Retornar True ou False \tn % Row Count 6 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.44186 cm} x{1.99114 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Regex no javascript}} \tn % Row 0 \SetRowColor{LightBackground} const regex = /novoRegex/gmi & Cria uma nova expressão regex que pode ser usada posteriormente \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \seqsplit{str.replace(regex}, novoValor) & Substitui o que foi encontrado na string pelo novoValor \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} regex.test(str) & Retorna verdadeiro caso de um match ou falso caso não \tn % Row Count 9 (+ 3) % Row 3 \SetRowColor{white} \seqsplit{regex.exec(string)} & Retorna null em caso de não encontrar nada, retorna uma lista dos matchs e grupos de captura \tn % Row Count 14 (+ 5) % Row 4 \SetRowColor{LightBackground} \seqsplit{str.match(regex)} & Retorna uma lista com todos os items (Não suporta grupo de captura) \tn % Row Count 17 (+ 3) % Row 5 \SetRowColor{white} \seqsplit{str.matchAll(regex)} & Retorna um iterator que pode ser usado com for de todos os matchs(Suporta lista de captura) \tn % Row Count 21 (+ 4) % Row 6 \SetRowColor{LightBackground} {[}...str.matchAll(regex){]} & Lista de todos os matchs (suporta grupo de captura) \tn % Row Count 24 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.7165 cm} x{1.7165 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Objetos}} \tn % Row 0 \SetRowColor{LightBackground} const obj = \{\} & Criando um novo objeto \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} const obj = \{chaveUnica: 'valorQualquer'\} & Criar objeto com valor inicial \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} obj.chaveUniva ou obj{[}'chaveUnica'{]} & Acessar o valor de um objeto \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} delete obj.chaveUnica & Deleta uma chave \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} Object.keys(obj) & Retornar um array de todas as chaves de um elemento \tn % Row Count 12 (+ 3) % Row 5 \SetRowColor{white} Object.keys(obj),map(key =\textgreater{} obj{[}key{]}) & Acessando todos os valores de um objeto \tn % Row Count 14 (+ 2) % Row 6 \SetRowColor{LightBackground} Object.values(obj) & Retornar um array de todos os valores de um objeto \tn % Row Count 17 (+ 3) % Row 7 \SetRowColor{white} Object.assign(\{\}, ...listaDeObjetos) & Cria um novo object mesclando todos os objetos da lista \tn % Row Count 20 (+ 3) % Row 8 \SetRowColor{LightBackground} Object.freeze(obj); & Torna um objeto imutável \tn % Row Count 22 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{Objetos são como dicionários (python). Eles possuem uma chave única (key) e um valor (Qualquer coisa). Podemos cirar um objeto com a seguinte sintaxe:} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.7165 cm} x{1.7165 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Listas}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{array.push(novoItem)} & Adiciona um novo item ao array \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} array.pop() & Remove o último elemento do array \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} array.shift() & Remove o primeiro elemento do array \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} array.unshift(item) & Adiciona um item ao inicio do array \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} \seqsplit{array.splice(indexParaRemover}, \seqsplit{numeroDeItemsParaRemover)} & Remove um item de determinada posição de um array \tn % Row Count 11 (+ 3) % Row 5 \SetRowColor{white} fruits.slice() & Copia o array \tn % Row Count 12 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.7165 cm} x{1.7165 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Promessas}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{promise.then(function} resolve(res)).catch(function reject(error)) & Caso de sucesso, a função dentro do then sera executada. Em de erro, a função dentro do catch sera executada \tn % Row Count 6 (+ 6) % Row 1 \SetRowColor{white} async function fn()\{\} & Sugar sintatico que permite a utilização do await \tn % Row Count 9 (+ 3) % Row 2 \SetRowColor{LightBackground} await promise & Faz com que todo o código abaixo do await espere para ser executado. Por baixo dos panos, coloca tudo que esta abaixo dentro de um then. \tn % Row Count 16 (+ 7) % Row 3 \SetRowColor{white} \seqsplit{Promise.all(listaDePromessas)} & Executa todas as promises em paralelo e só executa o código abaixo quando todas são executas e bem-sucedidas. Retorna uma lista com o resultado das promessas \tn % Row Count 25 (+ 9) % Row 4 \SetRowColor{LightBackground} \seqsplit{Promise.allSettled(listaDePromessas)} & Executa todas as promises em paralelo e só executa o código abaixo quando todas são executas, com ou sem erro. Retorna uma lista com o resultado das promessas \tn % Row Count 34 (+ 9) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{x{1.7165 cm} x{1.7165 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Promessas (cont)}} \tn % Row 5 \SetRowColor{LightBackground} new Promise((resolve, reject) =\textgreater{} \{\}) & Cria uma nova promesa. Chame resolve e passe o resultado em caso de sucesso. Chame o reject em caso de falha. \tn % Row Count 6 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{Uma promessa é um código assincrono, que sera mandado ao event loop. O resultado só estara disponível depois, mas a aplicação continuara executando o código. Ele é nãp bloqueante} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}