A Java\+Script module that implements {\ttfamily window.\+atob} and {\ttfamily window.\+btoa} according the forgiving-\/base64 algorithm in the \href{https://infra.spec.whatwg.org/\#forgiving-base64}{\texttt{ Infra Standard}}. The original code was forked from \href{https://github.com/w3c/web-platform-tests/blob/master/html/webappapis/atob/base64.html}{\texttt{ w3c/web-\/platform-\/tests}}.

Compatibility\+: Node.\+js version 3+ and all major browsers.

Install with {\ttfamily npm}\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{npm install abab }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_abab_README_autotoc_md2334}{}\doxysection{API}\label{md_sfcode_node_modules_abab_README_autotoc_md2334}
\hypertarget{md_sfcode_node_modules_abab_README_autotoc_md2335}{}\doxysubsection{$<$tt$>$btoa$<$/tt$>$ (base64 encode)}\label{md_sfcode_node_modules_abab_README_autotoc_md2335}

\begin{DoxyCode}{0}
\DoxyCodeLine{const \{ btoa \} = require('abab');}
\DoxyCodeLine{btoa('Hello, world!'); // 'SGVsbG8sIHdvcmxkIQ==' }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_abab_README_autotoc_md2336}{}\doxysubsection{$<$tt$>$atob$<$/tt$>$ (base64 decode)}\label{md_sfcode_node_modules_abab_README_autotoc_md2336}

\begin{DoxyCode}{0}
\DoxyCodeLine{const \{ atob \} = require('abab');}
\DoxyCodeLine{atob('SGVsbG8sIHdvcmxkIQ=='); // 'Hello, world!' }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_abab_README_autotoc_md2337}{}\doxysubsubsection{Valid characters}\label{md_sfcode_node_modules_abab_README_autotoc_md2337}
\href{https://html.spec.whatwg.org/multipage/webappapis.html\#atob:dom-windowbase64-btoa-3}{\texttt{ Per the spec}}, {\ttfamily btoa} will accept strings \char`\"{}containing only characters in the range \`{}\+U+0000\`{} to \`{}\+U+00\+FF\`{}.\char`\"{} If passed a string with characters above {\ttfamily U+00\+FF}, {\ttfamily btoa} will return {\ttfamily null}. If {\ttfamily atob} is passed a string that is not base64-\/valid, it will also return {\ttfamily null}. In both cases when {\ttfamily null} is returned, the spec calls for throwing a {\ttfamily DOMException} of type {\ttfamily Invalid\+Character\+Error}.\hypertarget{md_sfcode_node_modules_abab_README_autotoc_md2338}{}\doxysection{Browsers}\label{md_sfcode_node_modules_abab_README_autotoc_md2338}
If you want to include just one of the methods to save bytes in your client-\/side code, you can {\ttfamily require} the desired module directly.


\begin{DoxyCode}{0}
\DoxyCodeLine{const atob = require('abab/lib/atob');}
\DoxyCodeLine{const btoa = require('abab/lib/btoa'); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_abab_README_autotoc_md2339}{}\doxysection{Development}\label{md_sfcode_node_modules_abab_README_autotoc_md2339}
If you\textquotesingle{}re {\bfseries{submitting a PR}} or {\bfseries{deploying to npm}}, please use the \href{CONTRIBUTING.md\#checklists}{\texttt{ checklists in CONTRIBUTING.\+md}}.\hypertarget{md_sfcode_node_modules_abab_README_autotoc_md2340}{}\doxysection{Remembering what $<$tt$>$atob$<$/tt$>$ and $<$tt$>$btoa$<$/tt$>$ stand for}\label{md_sfcode_node_modules_abab_README_autotoc_md2340}
Base64 comes from IETF \href{https://tools.ietf.org/html/rfc4648\#section-4}{\texttt{ RFC 4648}} (2006).


\begin{DoxyItemize}
\item $\ast$$\ast${\ttfamily btoa}$\ast$$\ast$, the encoder function, stands for {\bfseries{binary}} to {\bfseries{ASCII}}, meaning it converts any binary input into a subset of {\bfseries{ASCII}} (Base64).
\item $\ast$$\ast${\ttfamily atob}$\ast$$\ast$, the decoder function, converts {\bfseries{ASCII}} (or Base64) to its original {\bfseries{binary}} format. 
\end{DoxyItemize}