\href{https://semaphoreci.com/medikoo-org/type}{\texttt{ }} \href{https://ci.appveyor.com/api/project/medikoo/type}{\texttt{ }} \href{https://codecov.io/gh/medikoo/type}{\texttt{ }} \href{https://www.npmjs.com/package/type}{\texttt{ }}\hypertarget{md_sfcode_node_modules_ext_node_modules_type_README_autotoc_md9996}{}\doxysection{type}\label{md_sfcode_node_modules_ext_node_modules_type_README_autotoc_md9996}
\hypertarget{md_sfcode_node_modules_ext_node_modules_type_README_autotoc_md9997}{}\doxysubsection{Runtime validation and processing of Java\+Script types}\label{md_sfcode_node_modules_ext_node_modules_type_README_autotoc_md9997}

\begin{DoxyItemize}
\item Respects language nature and acknowledges its quirks
\item Allows coercion in restricted forms (rejects clearly invalid input, normalizes permissible type deviations)
\item No transpilation implied, written to work in all ECMAScript 3+ engines
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_ext_node_modules_type_README_autotoc_md9998}{}\doxysubsection{Use case}\label{md_sfcode_node_modules_ext_node_modules_type_README_autotoc_md9998}
Validate arguments input in public API endpoints.

{\itshape For validation of more sophisticated input structures (as deeply nested configuration objects) it\textquotesingle{}s recommended to consider more powerful schema based utlities (as \href{https://ajv.js.org/}{\texttt{ AJV}} or \href{https://hapi.dev/family/joi/}{\texttt{ @hapi/joi}})}\hypertarget{md_sfcode_node_modules_ext_node_modules_type_README_autotoc_md9999}{}\doxysubsubsection{Example usage}\label{md_sfcode_node_modules_ext_node_modules_type_README_autotoc_md9999}
Bulletproof input arguments normalization and validation\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{const ensureString        = require('type/string/ensure')}
\DoxyCodeLine{    , ensureDate          = require('type/date/ensure')}
\DoxyCodeLine{    , ensureNaturalNumber = require('type/natural-\/number/ensure')}
\DoxyCodeLine{    , isObject            = require('type/object/is');}
\DoxyCodeLine{}
\DoxyCodeLine{module.exports = (path, options = \{ min: 0 \}) \{}
\DoxyCodeLine{  path = ensureString(path, \{ errorMessage: "{}\%v is not a path"{} \});}
\DoxyCodeLine{  if (!isObject(options)) options = \{\};}
\DoxyCodeLine{  const min = ensureNaturalNumber(options.min, \{ default: 0 \})}
\DoxyCodeLine{      , max = ensureNaturalNumber(options.max, \{ isOptional: true \})}
\DoxyCodeLine{      , startTime = ensureDate(options.startTime, \{ isOptional: true \});}
\DoxyCodeLine{}
\DoxyCodeLine{  // ...logic}
\DoxyCodeLine{\}; }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_ext_node_modules_type_README_autotoc_md10000}{}\doxysubsubsection{Installation}\label{md_sfcode_node_modules_ext_node_modules_type_README_autotoc_md10000}

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

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_ext_node_modules_type_README_autotoc_md10001}{}\doxysubsection{Utilities}\label{md_sfcode_node_modules_ext_node_modules_type_README_autotoc_md10001}
Aside of general \mbox{\hyperlink{md_sfcode_node_modules_ext_node_modules_type_docs_ensure}{\`{}ensure\`{}}} validation util, following kind of utilities for recognized Java\+Script types are provided\+:

\label{md_sfcode_node_modules_ext_node_modules_type_README_autotoc_md10002}%
\Hypertarget{md_sfcode_node_modules_ext_node_modules_type_README_autotoc_md10002}%
\doxysubparagraph*{{\ttfamily $\ast$/coerce}}

Restricted coercion into primitive type. Returns coerced value or {\ttfamily null} if value is not coercible per rules.

\label{md_sfcode_node_modules_ext_node_modules_type_README_autotoc_md10003}%
\Hypertarget{md_sfcode_node_modules_ext_node_modules_type_README_autotoc_md10003}%
\doxysubparagraph*{{\ttfamily $\ast$/is}}

Object type/kind confirmation, returns either {\ttfamily true} or {\ttfamily false}.

\label{md_sfcode_node_modules_ext_node_modules_type_README_autotoc_md10004}%
\Hypertarget{md_sfcode_node_modules_ext_node_modules_type_README_autotoc_md10004}%
\doxysubparagraph*{{\ttfamily $\ast$/ensure}}

Value validation. Returns input value (in primitive cases possibly coerced) or if value doesn\textquotesingle{}t meet the constraints throws {\ttfamily Type\+Error} .

Each {\ttfamily $\ast$/ensure} utility, accepts following options (eventually passed with second argument)\+:


\begin{DoxyItemize}
\item {\ttfamily is\+Optional} -\/ Makes {\ttfamily null} or {\ttfamily undefined} accepted as valid value. In such case instead of {\ttfamily Type\+Error} being thrown, {\ttfamily null} is returned.
\item {\ttfamily default} -\/ A value to be returned if {\ttfamily null} or {\ttfamily undefined} is passed as an input value.
\item {\ttfamily error\+Message} -\/ Custom error message. Following placeholders can be used\+:
\begin{DoxyItemize}
\item {\ttfamily v} -\/ To be replaced with short string representation of invalid value
\item {\ttfamily n} -\/ To be replaced with meaninfgul name (to be passed with {\ttfamily name} option) of validated value. Not effective if {\ttfamily name} option is not present
\end{DoxyItemize}
\item {\ttfamily name} -\/ Meaningful name for validated value, to be used in error message, assuming it contains {\ttfamily n} placeholder
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_ext_node_modules_type_README_autotoc_md10005}{}\doxysubsubsection{Index}\label{md_sfcode_node_modules_ext_node_modules_type_README_autotoc_md10005}
\hypertarget{md_sfcode_node_modules_ext_node_modules_type_README_autotoc_md10006}{}\doxyparagraph{General utils\+:}\label{md_sfcode_node_modules_ext_node_modules_type_README_autotoc_md10006}

\begin{DoxyItemize}
\item \mbox{\hyperlink{md_sfcode_node_modules_ext_node_modules_type_docs_ensure}{\`{}ensure\`{}}}
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_ext_node_modules_type_README_autotoc_md10007}{}\doxyparagraph{Type specific utils\+:}\label{md_sfcode_node_modules_ext_node_modules_type_README_autotoc_md10007}

\begin{DoxyItemize}
\item {\bfseries{Value}}
\begin{DoxyItemize}
\item \href{docs/value.md\#valueis}{\texttt{ {\ttfamily value/is}}}
\item \href{docs/value.md\#valueensure}{\texttt{ {\ttfamily value/ensure}}}
\end{DoxyItemize}
\item {\bfseries{Object}}
\begin{DoxyItemize}
\item \href{docs/object.md\#objectis}{\texttt{ {\ttfamily object/is}}}
\item \href{docs/object.md\#objectensure}{\texttt{ {\ttfamily object/ensure}}}
\item {\bfseries{Plain Object}}
\begin{DoxyItemize}
\item \href{docs/plain-object.md\#plain-objectis}{\texttt{ {\ttfamily plain-\/object/is}}}
\item \href{docs/plain-object.md\#plain-objectensure}{\texttt{ {\ttfamily plain-\/object/ensure}}}
\end{DoxyItemize}
\end{DoxyItemize}
\item {\bfseries{String}}
\begin{DoxyItemize}
\item \href{docs/string.md\#stringcoerce}{\texttt{ {\ttfamily string/coerce}}}
\item \href{docs/string.md\#stringensure}{\texttt{ {\ttfamily string/ensure}}}
\end{DoxyItemize}
\item {\bfseries{Number}}
\begin{DoxyItemize}
\item \href{docs/number.md\#numbercoerce}{\texttt{ {\ttfamily number/coerce}}}
\item \href{docs/number.md\#numberensure}{\texttt{ {\ttfamily number/ensure}}}
\item {\bfseries{Finite Number}}
\begin{DoxyItemize}
\item \href{docs/finite.md\#finitecoerce}{\texttt{ {\ttfamily finite/coerce}}}
\item \href{docs/finite.md\#finiteensure}{\texttt{ {\ttfamily finite/ensure}}}
\end{DoxyItemize}
\item {\bfseries{Integer Number}}
\begin{DoxyItemize}
\item \href{docs/integer.md\#integercoerce}{\texttt{ {\ttfamily integer/coerce}}}
\item \href{docs/integer.md\#integerensure}{\texttt{ {\ttfamily integer/ensure}}}
\end{DoxyItemize}
\item {\bfseries{Safe Integer Number}}
\begin{DoxyItemize}
\item \href{docs/safe-integer.md\#safe-integercoerce}{\texttt{ {\ttfamily safe-\/integer/coerce}}}
\item \href{docs/.md\#safe-integerensure}{\texttt{ {\ttfamily safe-\/integer/ensure}}}
\end{DoxyItemize}
\item {\bfseries{Natural Number}}
\begin{DoxyItemize}
\item \href{docs/natural-number.md\#natural-numbercoerce}{\texttt{ {\ttfamily natural-\/number/coerce}}}
\item \href{docs/natural-number.md\#natural-numberensure}{\texttt{ {\ttfamily natural-\/number/ensure}}}
\end{DoxyItemize}
\item {\bfseries{Array Length}}
\begin{DoxyItemize}
\item \href{docs/array-length.md\#array-lengthcoerce}{\texttt{ {\ttfamily array-\/length/coerce}}}
\item \href{docs/array-length.md\#array-lengthensure}{\texttt{ {\ttfamily array-\/length/ensure}}}
\end{DoxyItemize}
\item {\bfseries{Time Value}}
\begin{DoxyItemize}
\item \href{docs/time-value.md\#time-valuecoerce}{\texttt{ {\ttfamily time-\/value/coerce}}}
\item \href{docs/time-value.md\#time-valueensure}{\texttt{ {\ttfamily time-\/value/ensure}}}
\end{DoxyItemize}
\end{DoxyItemize}
\item {\bfseries{Array Like}}
\begin{DoxyItemize}
\item \href{docs/array-like.md\#array-likeis}{\texttt{ {\ttfamily array-\/like/is}}}
\item \href{docs/array-like.md\#array-likeensure}{\texttt{ {\ttfamily array-\/like/ensure}}}
\item {\bfseries{Array}}
\begin{DoxyItemize}
\item \href{docs/array.md\#arrayis}{\texttt{ {\ttfamily array/is}}}
\item \href{docs/array.md\#arrayensure}{\texttt{ {\ttfamily array/ensure}}}
\end{DoxyItemize}
\end{DoxyItemize}
\item {\bfseries{Iterable}}
\begin{DoxyItemize}
\item \href{docs/iterable.md\#iterableis}{\texttt{ {\ttfamily iterable/is}}}
\item \href{docs/iterable.md\#iterableensure}{\texttt{ {\ttfamily iterable/ensure}}}
\end{DoxyItemize}
\item {\bfseries{Date}}
\begin{DoxyItemize}
\item \href{docs/date.md\#dateis}{\texttt{ {\ttfamily date/is}}}
\item \href{docs/date.md\#dateensure}{\texttt{ {\ttfamily date/ensure}}}
\end{DoxyItemize}
\item {\bfseries{Function}}
\begin{DoxyItemize}
\item \href{docs/function.md\#functionis}{\texttt{ {\ttfamily function/is}}}
\item \href{docs/function.md\#functionensure}{\texttt{ {\ttfamily function/ensure}}}
\item {\bfseries{Plain Function}}
\begin{DoxyItemize}
\item \href{docs/plain-function.md\#plain-functionis}{\texttt{ {\ttfamily plain-\/function/is}}}
\item \href{docs/plain-function.md\#plain-functionensure}{\texttt{ {\ttfamily plain-\/function/ensure}}}
\end{DoxyItemize}
\end{DoxyItemize}
\item {\bfseries{Reg Exp}}
\begin{DoxyItemize}
\item \href{docs/reg-exp.md\#reg-expis}{\texttt{ {\ttfamily reg-\/exp/is}}}
\item \href{docs/.md\#reg-expensure}{\texttt{ {\ttfamily reg-\/exp/ensure}}}
\end{DoxyItemize}
\item {\bfseries{Thenable}}
\begin{DoxyItemize}
\item \href{docs/thenable.md\#thenableis}{\texttt{ {\ttfamily thenable/is}}}
\item \href{docs/thenable.md\#thenableensure}{\texttt{ {\ttfamily thenable/ensure}}}
\item {\bfseries{Promise}}
\begin{DoxyItemize}
\item \href{docs/promise.md\#promiseis}{\texttt{ {\ttfamily promise/is}}}
\item \href{docs/promise.md\#promiseensure}{\texttt{ {\ttfamily promise/ensure}}}
\end{DoxyItemize}
\end{DoxyItemize}
\item {\bfseries{Error}}
\begin{DoxyItemize}
\item \href{docs/error.md\#erroris}{\texttt{ {\ttfamily error/is}}}
\item \href{docs/error.md\#errorensure}{\texttt{ {\ttfamily error/ensure}}}
\end{DoxyItemize}
\item {\bfseries{Prototype}}
\begin{DoxyItemize}
\item \href{docs/prototype.md\#prototypeis}{\texttt{ {\ttfamily prototype/is}}}
\end{DoxyItemize}
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_ext_node_modules_type_README_autotoc_md10008}{}\doxysubsubsection{Tests}\label{md_sfcode_node_modules_ext_node_modules_type_README_autotoc_md10008}
\begin{DoxyVerb}$ npm test
\end{DoxyVerb}
 