\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{Orabig} \pdfinfo{ /Title (jq.pdf) /Creator (Cheatography) /Author (Orabig) /Subject (JQ 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}{0C5BAB} \definecolor{LightBackground}{HTML}{EFF4F9} \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{JQ Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Orabig} via \textcolor{DarkBackground}{\uline{cheatography.com/55627/cs/14790/}}} \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}Orabig \\ \uline{cheatography.com/orabig} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 5th March, 2018.\\ Updated 5th March, 2018.\\ 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*}{3} \begin{tabularx}{5.377cm}{x{1.44333 cm} x{3.53367 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Basic filters}} \tn % Row 0 \SetRowColor{LightBackground} . & IDentity \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} .{\emph{foo}} .{\emph{foo}}? & Value of "{\emph{foo}}" key \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} .{[}{]} .{[}{]}? & Array iterator. Produce each element of an input array, or each value of an object \tn % Row Count 6 (+ 3) % Row 3 \SetRowColor{white} .{[}{\emph{n}}{]} & {\emph{n}}\textasciicircum{}th\textasciicircum{} element of an array ({\emph{n}} can be negative : -1 -\textgreater{} last element...) \tn % Row Count 9 (+ 3) % Row 4 \SetRowColor{LightBackground} .{[}{\emph{n}}:{\emph{m}}{]} & Array slice : array containing {\emph{n}}\textasciicircum{}th\textasciicircum{} (inclusive) to {\emph{m}}\textasciicircum{}th\textasciicircum{} (exclusive) elements \tn % Row Count 12 (+ 3) % Row 5 \SetRowColor{white} {\emph{A}},{\emph{B}} & Produces output of filter {\emph{A}} then {\emph{B}} (both {\emph{A}} and {\emph{B}} are fed with the same input) \tn % Row Count 16 (+ 4) % Row 6 \SetRowColor{LightBackground} {\emph{A}}|{\emph{B}} & Output of {\emph{A}} is sent to {\emph{B}}'s input \tn % Row Count 18 (+ 2) % Row 7 \SetRowColor{white} ( A ) & Grouping operator \tn % Row Count 19 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Types and Values}} \tn % Row 0 \SetRowColor{LightBackground} {[} {]}, \{ \} & Array (resp. Object) construction \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} .. & Recursive descent \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} + - * / \% & Basic arithmetic / string / array / object operators \tn % Row Count 6 (+ 3) % Row 3 \SetRowColor{white} length & string / array / object length \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} keys | \{\{nobreak\}\}keys\_unsorted & The sorted/unsorted set of the input object keys. \tn % Row Count 11 (+ 3) % Row 5 \SetRowColor{white} has( {\emph{KEY}} ) & Whether the input object as the given {\emph{KEY}}. \tn % Row Count 14 (+ 3) % Row 6 \SetRowColor{LightBackground} in( {\emph{A}} ) & Whether the input key is in the given {\emph{A}} object. \tn % Row Count 17 (+ 3) % Row 7 \SetRowColor{white} map ( {\emph{A}} ) & Run the {\emph{A}} filter for each element of the input array. Equivalent to {\bf{{[}.{[}{]} | {\emph{A}}{]}}} \tn % Row Count 22 (+ 5) % Row 8 \SetRowColor{LightBackground} map\_values( {\emph{A}} ) & Run the {\emph{A}} filter for each element of the input object. Equivalent to {\bf{.{[}{]} |={\emph{A}}}} \tn % Row Count 27 (+ 5) % Row 9 \SetRowColor{white} del ( {\emph{x}} ) & Removes a key and its value from an object \tn % Row Count 30 (+ 3) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Types and Values (cont)}} \tn % Row 10 \SetRowColor{LightBackground} select ( {\emph{foo}} ) & Produces input unchanged if {\emph{foo}} is true for that input. \tn % Row Count 3 (+ 3) % Row 11 \SetRowColor{white} type & Returns the type of its argument as a string. \tn % Row Count 6 (+ 3) % Row 12 \SetRowColor{LightBackground} arrays, objects, iterables, booleans, numbers, normals, finites, strings, nulls, values, scalars & These built-ins select only inputs that are arrays, objects, iterables (arrays or objects), booleans, numbers, normal numbers, finite numbers, strings, null, non-null values, and non-iterables, respectively. \tn % Row Count 17 (+ 11) % Row 13 \SetRowColor{white} empty & Produces no output. \tn % Row Count 18 (+ 1) % Row 14 \SetRowColor{LightBackground} \$\_\_loc\_\_ & Produces an object with a "file" key and a "line" key \tn % Row Count 22 (+ 4) % Row 15 \SetRowColor{white} add & Produces the summed elements of the input array \tn % Row Count 25 (+ 3) % Row 16 \SetRowColor{LightBackground} any, any( {\emph{foo}} ) & Produces {\bf{true}} if any of the elements of the input array (resp {\emph{foo}}) is {\bf{true}} \tn % Row Count 30 (+ 5) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Types and Values (cont)}} \tn % Row 17 \SetRowColor{LightBackground} all, all( {\emph{foo}} ) & Produces {\bf{true}} if all of the elements of the input array (resp {\emph{foo}}) is {\bf{true}} \tn % Row Count 5 (+ 5) % Row 18 \SetRowColor{white} range( {[}{\emph{from}} ;{]} upto {[}; {\emph{by}}{]} ) & Produces a range of numbers ({\emph{upto}} is exclusive) \tn % Row Count 8 (+ 3) % Row 19 \SetRowColor{LightBackground} floor, sqrt & Returns the floor (resp square root) of its numeric input \tn % Row Count 11 (+ 3) % Row 20 \SetRowColor{white} tonumber & Converts into to number \tn % Row Count 13 (+ 2) % Row 21 \SetRowColor{LightBackground} infinite, nan, isinfinite, isnan, isfinite, isnormal & Returns {\bf{true}} depending of the input \tn % Row Count 16 (+ 3) % Row 22 \SetRowColor{white} sort | sort\_by( {\emph{foo}} ) & Sorts the input array ({\emph{null}} \textless{} {\emph{false}} \textless{} {\emph{true}} \textless{} numbers \textless{} strings \textless{} arrays \textless{} objects) \tn % Row Count 21 (+ 5) % Row 23 \SetRowColor{LightBackground} group\_by( {\emph{foo}} ) & Groups the elements of the input array having the same {\emph{foo}} value into separate arrays (sorted by {\emph{foo}} values) \tn % Row Count 27 (+ 6) % Row 24 \SetRowColor{white} min | max | min\_by( {\emph{foo}} ) | max\_by({\emph{foo}}) & Finds the minimum (resp maximum) element of the input array \tn % Row Count 30 (+ 3) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Types and Values (cont)}} \tn % Row 25 \SetRowColor{LightBackground} unique, unique\_by( {\emph{foo}} ) & Produces an array of unique element of the input array. \tn % Row Count 3 (+ 3) % Row 26 \SetRowColor{white} reverse & Reverses an array \tn % Row Count 4 (+ 1) % Row 27 \SetRowColor{LightBackground} contains( {\emph{foo}} ) & Produces {\bf{true}} if {\emph{foo}} is completely contained within the input. \tn % Row Count 8 (+ 4) % Row 28 \SetRowColor{white} indices( {\emph{foo}} ) & Outputs an array containing the indices in . where {\emph{foo}} occurs. \tn % Row Count 12 (+ 4) % Row 29 \SetRowColor{LightBackground} inside( {\emph{foo}} ) & produce true if the input is completely contained within {\emph{foo}} \tn % Row Count 16 (+ 4) % Row 30 \SetRowColor{white} combinations & Production all combinations of an array \tn % Row Count 18 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.4977 cm} p{0.4977 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{SQL-Style Operators}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{INDEX} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{JOIN} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{IN} \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.33919 cm} x{2.63781 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{String manipulation}} \tn % Row 0 \SetRowColor{LightBackground} tostring & JSON-encode input as a string \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} "\textbackslash{}({\emph{foo}})" & Interpolates {\emph{foo}} inside a string \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} index( {\emph{foo}}), rindex( {\emph{foo}} ) & Outputs the index of the first (index) or last (rindex) occurrence of {\emph{foo}} in the input. \tn % Row Count 9 (+ 5) % Row 3 \SetRowColor{white} startswith( {\emph{str}} ) & Outputs true if . starts with the given string argument. \tn % Row Count 12 (+ 3) % Row 4 \SetRowColor{LightBackground} endswith( {\emph{str}} ) & Outputs true if . ends with the given string argument. \tn % Row Count 15 (+ 3) % Row 5 \SetRowColor{white} ltrimstr( {\emph{foo}} ), rtrimstr( {\emph{foo}} ) & Outputs its input with the given prefix (resp. suffix) string removed, if it starts (resp. ends) with it. \tn % Row Count 20 (+ 5) % Row 6 \SetRowColor{LightBackground} explode & Converts an input string into an array of the string's codepoint numbers. \tn % Row Count 24 (+ 4) % Row 7 \SetRowColor{white} implode & The inverse of explode. \tn % Row Count 26 (+ 2) % Row 8 \SetRowColor{LightBackground} split( {\emph{foo}} ) & Splits an input string on the separator argument. \tn % Row Count 29 (+ 3) % Row 9 \SetRowColor{white} join( {\emph{foo}} ) & Joins the array of elements given as input, using the argument as separator. \tn % Row Count 33 (+ 4) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{2.33919 cm} x{2.63781 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{String manipulation (cont)}} \tn % Row 10 \SetRowColor{LightBackground} ascii\_downcase, ascii\_upcase & Emit a copy of the input string with its alphabetic characters (a-z and A-Z) converted to the specified case. \tn % Row Count 6 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.9908 cm} x{2.9862 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Path \& object manipulation}} \tn % Row 0 \SetRowColor{LightBackground} path ( {\emph{x}} ) & Output the array representation of {\emph{x}} : (keys/ indices, values) \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} getpath( {\emph{PATHS}} ) & Outputs the values in {\emph{.}} found at each path in {\emph{PATHS}} \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} setpath( {\emph{PATH}}; {\emph{VALUE}} ) & Set the {\emph{PATHS}} in {\emph{.}} to {\emph{VALUE}} \tn % Row Count 8 (+ 2) % Row 3 \SetRowColor{white} delpaths( {\emph{PATHS}} ) & Removes the key at the paths in {\emph{PATHS}} \tn % Row Count 10 (+ 2) % Row 4 \SetRowColor{LightBackground} to\_entries & Converts from object to an array of "key":"value" \tn % Row Count 13 (+ 3) % Row 5 \SetRowColor{white} from\_entries & Converts from an array of "key":"value" to an object \tn % Row Count 16 (+ 3) % Row 6 \SetRowColor{LightBackground} with\_entries( {\emph{foo}} ) & Shortcut for {\bf{to\_entries | map({\emph{foo}}) | from\_entries}} \tn % Row Count 19 (+ 3) % Row 7 \SetRowColor{white} flatten, flatten( {\emph{depth}} ) & Produces a flat array in which all arrays inside the original array have been recursively replaced by their values. \tn % Row Count 24 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.04057 cm} x{2.93643 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Loop control}} \tn % Row 0 \SetRowColor{LightBackground} while(cond; update) & repeatedly apply an update to . until cond is false. \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} until(cond; next) & repeatedly apply the expression next, initially to . then to its own output, until cond is true. \tn % Row Count 8 (+ 5) % Row 2 \SetRowColor{LightBackground} recurse( {\emph{foo}} {[} ,{\emph{cond}} {]} ) & search through a recursive structure, and extract data from all levels. \tn % Row Count 12 (+ 4) % Row 3 \SetRowColor{white} walk( {\emph{foo}} ) & applies {\emph{foo}} recursively to every component of the input entity. \tn % Row Count 15 (+ 3) % Row 4 \SetRowColor{LightBackground} bsearch( {\emph{foo}} ) & conducts a binary search for {\emph{foo}} in the input array. \tn % Row Count 18 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Regular expressions}} \tn % Row 0 \SetRowColor{LightBackground} test( {\emph{RE}} {[}; {\emph{FLAGS}}{]} ) & True if input string matches the given RE \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} match( {\emph{RE}} {[}; {\emph{FLAGS}}{]} ) & outputs an object for each match it finds. \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} capture( {\emph{RE}} {[}; {\emph{FLAGS}}{]} ) & Collects the named captures in a JSON object, with the name of each capture as the key, and the matched string as the corresponding value. \tn % Row Count 13 (+ 7) % Row 3 \SetRowColor{white} scan( {\emph{RE}} {[}; {\emph{FLAGS}}{]} ) & Emit a stream of the non-overlapping substrings of the input that match the regex in accordance with the flags, if any have been specified. \tn % Row Count 20 (+ 7) % Row 4 \SetRowColor{LightBackground} split|splits( {\emph{RE}} {[}; {\emph{FLAGS}}{]} ), splits() & Splits an input string, and provides an array (resp. stream) \tn % Row Count 23 (+ 3) % Row 5 \SetRowColor{white} sub|gsub( {\emph{RE}} ; {\emph{tostring}} {[}; {\emph{FLAGS}}{]}) & Emit the string obtained by replacing the first (resp. all) match of regex in the input string with tostring, after interpolation. \tn % Row Count 30 (+ 7) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{FLAGS is any of "g, i, m, s, p, n, l, x"} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}