Really Fast Deep Clone

\href{https://travis-ci.org/davidmarkclements/rfdc}{\texttt{ }} \href{https://codecov.io/gh/davidmarkclements/rfdc}{\texttt{ }} \href{http://standardjs.com/}{\texttt{ }}\hypertarget{md_sfcode_node_modules_rfdc_readme_autotoc_md24915}{}\doxysection{Usage}\label{md_sfcode_node_modules_rfdc_readme_autotoc_md24915}

\begin{DoxyCode}{0}
\DoxyCodeLine{const clone = require('rfdc')()}
\DoxyCodeLine{clone(\{a: 1, b: \{c: 2\}\}) // => \{a: 1, b: \{c: 2\}\} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_rfdc_readme_autotoc_md24916}{}\doxysection{API}\label{md_sfcode_node_modules_rfdc_readme_autotoc_md24916}
\hypertarget{md_sfcode_node_modules_rfdc_readme_autotoc_md24917}{}\doxysubsection{‘require(\textquotesingle{}rfdc’)(opts = \{ proto\+: false, circles\+: false \}) =$>$ clone(obj) =$>$ obj2\`{}}\label{md_sfcode_node_modules_rfdc_readme_autotoc_md24917}
\hypertarget{md_sfcode_node_modules_rfdc_readme_autotoc_md24918}{}\doxysubsubsection{$<$tt$>$proto$<$/tt$>$ option}\label{md_sfcode_node_modules_rfdc_readme_autotoc_md24918}
Copy prototype properties as well as own properties into the new object.

It\textquotesingle{}s marginally faster to allow enumerable properties on the prototype to be copied into the cloned object (not onto it\textquotesingle{}s prototype, directly onto the object).

To explain by way of code\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{require('rfdc')(\{ proto: false \})(Object.create(\{a: 1\})) // => \{\}}
\DoxyCodeLine{require('rfdc')(\{ proto: true \})(Object.create(\{a: 1\})) // => \{a: 1\} }

\end{DoxyCode}


Setting {\ttfamily proto} to {\ttfamily true} will provide an additional 2\% performance boost.\hypertarget{md_sfcode_node_modules_rfdc_readme_autotoc_md24919}{}\doxysubsubsection{$<$tt$>$circles$<$/tt$>$ option}\label{md_sfcode_node_modules_rfdc_readme_autotoc_md24919}
Keeping track of circular references will slow down performance with an additional 25\% overhead. Even if an object doesn\textquotesingle{}t have any circular references, the tracking overhead is the cost. By default if an object with a circular reference is passed to {\ttfamily rfdc}, it will throw (similar to how {\ttfamily JSON.\+stringify} \textbackslash{} would throw).

Use the {\ttfamily circles} option to detect and preserve circular references in the object. If performance is important, try removing the circular reference from the object (set to {\ttfamily undefined}) and then add it back manually after cloning instead of using this option.\hypertarget{md_sfcode_node_modules_rfdc_readme_autotoc_md24920}{}\doxysubsection{Types}\label{md_sfcode_node_modules_rfdc_readme_autotoc_md24920}
{\ttfamily rdfc} clones all JSON types\+:


\begin{DoxyItemize}
\item {\ttfamily Object}
\item {\ttfamily Array}
\item {\ttfamily Number}
\item {\ttfamily String}
\item {\ttfamily null}
\end{DoxyItemize}

With additional support for\+:


\begin{DoxyItemize}
\item {\ttfamily Date} (copied)
\item {\ttfamily undefined} (copied)
\item {\ttfamily Function} (referenced)
\item {\ttfamily Async\+Function} (referenced)
\item {\ttfamily Generator\+Function} (referenced)
\item {\ttfamily arguments} (copied to a normal object)
\end{DoxyItemize}

All other types have output values that match the output of {\ttfamily JSON.\+parse(JSON.\+stringify(o))}.

For instance\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{const rdfc = require('rdfc')()}
\DoxyCodeLine{const err = Error()}
\DoxyCodeLine{err.code = 1}
\DoxyCodeLine{JSON.parse(JSON.stringify(e)) // \{code: 1\}}
\DoxyCodeLine{rdfc(e) // \{code: 1\}}
\DoxyCodeLine{}
\DoxyCodeLine{JSON.parse(JSON.stringify(new Uint8Array([1, 2, 3]))) //  \{'0': 1, '1': 2, '2': 3 \}}
\DoxyCodeLine{rdfc(new Uint8Array([1, 2, 3])) //  \{'0': 1, '1': 2, '2': 3 \}}
\DoxyCodeLine{}
\DoxyCodeLine{JSON.parse(JSON.stringify(\{rx: /foo/\})) // \{rx: \{\}\}}
\DoxyCodeLine{rdfc(\{rx: /foo/\}) // \{rx: \{\}\} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_rfdc_readme_autotoc_md24921}{}\doxysection{Benchmarks}\label{md_sfcode_node_modules_rfdc_readme_autotoc_md24921}

\begin{DoxyCode}{0}
\DoxyCodeLine{npm run bench }

\end{DoxyCode}



\begin{DoxyCode}{0}
\DoxyCodeLine{benchDeepCopy*100: 549.618ms}
\DoxyCodeLine{benchLodashCloneDeep*100: 1461.134ms}
\DoxyCodeLine{benchFastCopy*100: 878.146ms}
\DoxyCodeLine{benchRfdc*100: 323.899ms}
\DoxyCodeLine{benchRfdcProto*100: 314.136ms}
\DoxyCodeLine{benchRfdcCircles*100: 384.561ms}
\DoxyCodeLine{benchRfdcCirclesProto*100: 381.775ms }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_rfdc_readme_autotoc_md24922}{}\doxysection{Tests}\label{md_sfcode_node_modules_rfdc_readme_autotoc_md24922}

\begin{DoxyCode}{0}
\DoxyCodeLine{npm test }

\end{DoxyCode}



\begin{DoxyCode}{0}
\DoxyCodeLine{169 passing (342.514ms) }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_rfdc_readme_autotoc_md24923}{}\doxysubsection{Coverage}\label{md_sfcode_node_modules_rfdc_readme_autotoc_md24923}

\begin{DoxyCode}{0}
\DoxyCodeLine{npm run cov }

\end{DoxyCode}



\begin{DoxyCode}{0}
\DoxyCodeLine{-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/|-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/|-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/|-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/|-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/|-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/|}
\DoxyCodeLine{File      |  \% Stmts | \% Branch |  \% Funcs |  \% Lines | Uncovered Line \#s |}
\DoxyCodeLine{-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/|-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/|-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/|-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/|-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/|-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/|}
\DoxyCodeLine{All files |      100 |      100 |      100 |      100 |                   |}
\DoxyCodeLine{ index.js |      100 |      100 |      100 |      100 |                   |}
\DoxyCodeLine{-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/|-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/|-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/|-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/|-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/|-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/| }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_rfdc_readme_autotoc_md24924}{}\doxysection{License}\label{md_sfcode_node_modules_rfdc_readme_autotoc_md24924}
MIT 