\href{http://unshift.io}{\texttt{ }}\href{http://browsenpm.org/package/yeast}{\texttt{ }}\href{https://travis-ci.org/unshiftio/yeast}{\texttt{ }}\href{https://david-dm.org/unshiftio/yeast}{\texttt{ }}\href{https://coveralls.io/r/unshiftio/yeast?branch=master}{\texttt{ }}\href{https://webchat.freenode.net/?channels=unshift}{\texttt{ }}

\href{https://saucelabs.com/u/yeast}{\texttt{ }}

Yeast is a unique id generator. It has been primarily designed to generate a unique id which can be used for cache busting. A common practice for this is to use a timestamp, but there are couple of downsides when using timestamps.


\begin{DoxyEnumerate}
\item The timestamp is already 13 chars long. This might not matter for 1 request but if you make hundreds of them this quickly adds up in bandwidth and processing time.
\item It\textquotesingle{}s not unique enough. If you generate two stamps right after each other, they would be identical because the timing accuracy is limited to milliseconds.
\end{DoxyEnumerate}

Yeast solves both of these issues by\+:


\begin{DoxyEnumerate}
\item Compressing the generated timestamp using a custom {\ttfamily encode()} function that returns a string representation of the number.
\item Seeding the id in case of collision (when the id is identical to the previous one).
\end{DoxyEnumerate}

To keep the strings unique it will use the {\ttfamily .} char to separate the generated stamp from the seed.\hypertarget{md_sfcode_node_modules_yeast_README_autotoc_md34778}{}\doxysection{Installation}\label{md_sfcode_node_modules_yeast_README_autotoc_md34778}
The module is intended to be used in browsers as well as in Node.\+js and is therefore released in the npm registry and can be installed using\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{npm install -\/-\/save yeast }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_yeast_README_autotoc_md34779}{}\doxysection{Usage}\label{md_sfcode_node_modules_yeast_README_autotoc_md34779}
All the examples assume that this library is initialized as follow\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{'use strict';}
\DoxyCodeLine{}
\DoxyCodeLine{var yeast = require('yeast'); }

\end{DoxyCode}


To generate an id just call the {\ttfamily yeast} function.


\begin{DoxyCode}{0}
\DoxyCodeLine{console.log(yeast(), yeast(), yeast()); // outputs: KyxidwN KyxidwN.0 KyxidwN.1}
\DoxyCodeLine{}
\DoxyCodeLine{setTimeout(function () \{}
\DoxyCodeLine{  console.log(yeast()); // outputs: KyxidwO}
\DoxyCodeLine{\}); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_yeast_README_autotoc_md34780}{}\doxysubsection{yeast.\+encode(num)}\label{md_sfcode_node_modules_yeast_README_autotoc_md34780}
An helper function that returns a string representing the specified number. The returned string contains only URL safe characters.


\begin{DoxyCode}{0}
\DoxyCodeLine{yeast.encode(+new Date()); // outputs: Kyxjuo1 }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_yeast_README_autotoc_md34781}{}\doxysubsection{yeast.\+decode(str)}\label{md_sfcode_node_modules_yeast_README_autotoc_md34781}
An helper function that returns the integer value specified by the given string. This function can be used to retrieve the timestamp from a {\ttfamily yeast} id.


\begin{DoxyCode}{0}
\DoxyCodeLine{var id = yeast(); // holds the value: Kyxl1OU}
\DoxyCodeLine{}
\DoxyCodeLine{yeast.decode(id); // outputs: 1439816226334 }

\end{DoxyCode}


That\textquotesingle{}s all folks. If you have ideas on how we can further compress the ids please open an issue!\hypertarget{md_sfcode_node_modules_yeast_README_autotoc_md34782}{}\doxysection{License}\label{md_sfcode_node_modules_yeast_README_autotoc_md34782}
\mbox{[}MIT\mbox{]}(LICENSE) 