 \href{http://json-schema.org}{\texttt{  }} \href{https://github.com/webpack/webpack}{\texttt{  }} 

\href{https://npmjs.com/package/schema-utils}{\texttt{ }} \href{https://nodejs.org}{\texttt{ }} \href{https://david-dm.org/webpack/schema-utils}{\texttt{ }} \href{https://github.com/webpack/schema-utils/actions}{\texttt{ }} \href{https://codecov.io/gh/webpack/schema-utils}{\texttt{ }} \href{https://gitter.im/webpack/webpack}{\texttt{ }} \href{https://packagephobia.com/result?p=schema-utils}{\texttt{ }}\hypertarget{md_sfcode_node_modules_schema_utils_README_autotoc_md26324}{}\doxysection{schema-\/utils}\label{md_sfcode_node_modules_schema_utils_README_autotoc_md26324}
Package for validate options in loaders and plugins.\hypertarget{md_sfcode_node_modules_schema_utils_README_autotoc_md26325}{}\doxysubsection{Getting Started}\label{md_sfcode_node_modules_schema_utils_README_autotoc_md26325}
To begin, you\textquotesingle{}ll need to install {\ttfamily schema-\/utils}\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{npm install schema-\/utils }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_schema_utils_README_autotoc_md26326}{}\doxysubsection{API}\label{md_sfcode_node_modules_schema_utils_README_autotoc_md26326}
{\bfseries{schema.\+json}}


\begin{DoxyCode}{0}
\DoxyCodeLine{\{}
\DoxyCodeLine{  "{}type"{}: "{}object"{},}
\DoxyCodeLine{  "{}properties"{}: \{}
\DoxyCodeLine{    "{}option"{}: \{}
\DoxyCodeLine{      "{}type"{}: "{}boolean"{}}
\DoxyCodeLine{    \}}
\DoxyCodeLine{  \},}
\DoxyCodeLine{  "{}additionalProperties"{}: false}
\DoxyCodeLine{\} }

\end{DoxyCode}



\begin{DoxyCode}{0}
\DoxyCodeLine{import schema from './path/to/schema.json';}
\DoxyCodeLine{import validate from 'schema-\/utils';}
\DoxyCodeLine{}
\DoxyCodeLine{const options = \{ option: true \};}
\DoxyCodeLine{const configuration = \{ name: 'Loader Name/Plugin Name/Name' \};}
\DoxyCodeLine{}
\DoxyCodeLine{validate(schema, options, configuration); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_schema_utils_README_autotoc_md26327}{}\doxysubsubsection{$<$tt$>$schema$<$/tt$>$}\label{md_sfcode_node_modules_schema_utils_README_autotoc_md26327}
Type\+: {\ttfamily String}

JSON schema.

Simple example of schema\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{\{}
\DoxyCodeLine{  "{}type"{}: "{}object"{},}
\DoxyCodeLine{  "{}properties"{}: \{}
\DoxyCodeLine{    "{}name"{}: \{}
\DoxyCodeLine{      "{}description"{}: "{}This is description of option."{},}
\DoxyCodeLine{      "{}type"{}: "{}string"{}}
\DoxyCodeLine{    \}}
\DoxyCodeLine{  \},}
\DoxyCodeLine{  "{}additionalProperties"{}: false}
\DoxyCodeLine{\} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_schema_utils_README_autotoc_md26328}{}\doxysubsubsection{$<$tt$>$options$<$/tt$>$}\label{md_sfcode_node_modules_schema_utils_README_autotoc_md26328}
Type\+: {\ttfamily Object}

Object with options.


\begin{DoxyCode}{0}
\DoxyCodeLine{validate(}
\DoxyCodeLine{  schema,}
\DoxyCodeLine{  \{}
\DoxyCodeLine{    name: 123,}
\DoxyCodeLine{  \},}
\DoxyCodeLine{  \{ name: 'MyPlugin' \}}
\DoxyCodeLine{); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_schema_utils_README_autotoc_md26329}{}\doxysubsubsection{$<$tt$>$configuration$<$/tt$>$}\label{md_sfcode_node_modules_schema_utils_README_autotoc_md26329}
Allow to configure validator.

There is an alternative method to configure the {\ttfamily name} and{\ttfamily base\+Data\+Path} options via the {\ttfamily title} property in the schema. For example\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{\{}
\DoxyCodeLine{  "{}title"{}: "{}My Loader options"{},}
\DoxyCodeLine{  "{}type"{}: "{}object"{},}
\DoxyCodeLine{  "{}properties"{}: \{}
\DoxyCodeLine{    "{}name"{}: \{}
\DoxyCodeLine{      "{}description"{}: "{}This is description of option."{},}
\DoxyCodeLine{      "{}type"{}: "{}string"{}}
\DoxyCodeLine{    \}}
\DoxyCodeLine{  \},}
\DoxyCodeLine{  "{}additionalProperties"{}: false}
\DoxyCodeLine{\} }

\end{DoxyCode}


The last word used for the {\ttfamily base\+Data\+Path} option, other words used for the {\ttfamily name} option. Based on the example above the {\ttfamily name} option equals {\ttfamily My Loader}, the {\ttfamily base\+Data\+Path} option equals {\ttfamily options}.\hypertarget{md_sfcode_node_modules_schema_utils_README_autotoc_md26330}{}\doxyparagraph{$<$tt$>$name$<$/tt$>$}\label{md_sfcode_node_modules_schema_utils_README_autotoc_md26330}
Type\+: {\ttfamily Object} Default\+: {\ttfamily \char`\"{}\+Object\char`\"{}}

Allow to setup name in validation errors.


\begin{DoxyCode}{0}
\DoxyCodeLine{validate(schema, options, \{ name: 'MyPlugin' \}); }

\end{DoxyCode}



\begin{DoxyCode}{0}
\DoxyCodeLine{Invalid configuration object. MyPlugin has been initialised using a configuration object that does not match the API schema.}
\DoxyCodeLine{ -\/ configuration.optionName should be a integer. }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_schema_utils_README_autotoc_md26331}{}\doxyparagraph{$<$tt$>$base\+Data\+Path$<$/tt$>$}\label{md_sfcode_node_modules_schema_utils_README_autotoc_md26331}
Type\+: {\ttfamily String} Default\+: {\ttfamily \char`\"{}configuration\char`\"{}}

Allow to setup base data path in validation errors.


\begin{DoxyCode}{0}
\DoxyCodeLine{validate(schema, options, \{ name: 'MyPlugin', baseDataPath: 'options' \}); }

\end{DoxyCode}



\begin{DoxyCode}{0}
\DoxyCodeLine{Invalid options object. MyPlugin has been initialised using an options object that does not match the API schema.}
\DoxyCodeLine{ -\/ options.optionName should be a integer. }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_schema_utils_README_autotoc_md26332}{}\doxyparagraph{$<$tt$>$post\+Formatter$<$/tt$>$}\label{md_sfcode_node_modules_schema_utils_README_autotoc_md26332}
Type\+: {\ttfamily Function} Default\+: {\ttfamily undefined}

Allow to reformat errors.


\begin{DoxyCode}{0}
\DoxyCodeLine{validate(schema, options, \{}
\DoxyCodeLine{  name: 'MyPlugin',}
\DoxyCodeLine{  postFormatter: (formattedError, error) => \{}
\DoxyCodeLine{    if (error.keyword === 'type') \{}
\DoxyCodeLine{      return `\$\{formattedError\}\(\backslash\)nAdditional Information.`;}
\DoxyCodeLine{    \}}
\DoxyCodeLine{}
\DoxyCodeLine{    return formattedError;}
\DoxyCodeLine{  \},}
\DoxyCodeLine{\}); }

\end{DoxyCode}



\begin{DoxyCode}{0}
\DoxyCodeLine{Invalid options object. MyPlugin has been initialized using an options object that does not match the API schema.}
\DoxyCodeLine{ -\/ options.optionName should be a integer.}
\DoxyCodeLine{   Additional Information. }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_schema_utils_README_autotoc_md26333}{}\doxysubsection{Examples}\label{md_sfcode_node_modules_schema_utils_README_autotoc_md26333}
{\bfseries{schema.\+json}}


\begin{DoxyCode}{0}
\DoxyCodeLine{\{}
\DoxyCodeLine{  "{}type"{}: "{}object"{},}
\DoxyCodeLine{  "{}properties"{}: \{}
\DoxyCodeLine{    "{}name"{}: \{}
\DoxyCodeLine{      "{}type"{}: "{}string"{}}
\DoxyCodeLine{    \},}
\DoxyCodeLine{    "{}test"{}: \{}
\DoxyCodeLine{      "{}anyOf"{}: [}
\DoxyCodeLine{        \{ "{}type"{}: "{}array"{} \},}
\DoxyCodeLine{        \{ "{}type"{}: "{}string"{} \},}
\DoxyCodeLine{        \{ "{}instanceof"{}: "{}RegExp"{} \}}
\DoxyCodeLine{      ]}
\DoxyCodeLine{    \},}
\DoxyCodeLine{    "{}transform"{}: \{}
\DoxyCodeLine{      "{}instanceof"{}: "{}Function"{}}
\DoxyCodeLine{    \},}
\DoxyCodeLine{    "{}sourceMap"{}: \{}
\DoxyCodeLine{      "{}type"{}: "{}boolean"{}}
\DoxyCodeLine{    \}}
\DoxyCodeLine{  \},}
\DoxyCodeLine{  "{}additionalProperties"{}: false}
\DoxyCodeLine{\} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_schema_utils_README_autotoc_md26334}{}\doxysubsubsection{$<$tt$>$\+Loader$<$/tt$>$}\label{md_sfcode_node_modules_schema_utils_README_autotoc_md26334}

\begin{DoxyCode}{0}
\DoxyCodeLine{import \{ getOptions \} from 'loader-\/utils';}
\DoxyCodeLine{import validateOptions from 'schema-\/utils';}
\DoxyCodeLine{}
\DoxyCodeLine{import schema from 'path/to/schema.json';}
\DoxyCodeLine{}
\DoxyCodeLine{function loader(src, map) \{}
\DoxyCodeLine{  const options = getOptions(this) || \{\};}
\DoxyCodeLine{}
\DoxyCodeLine{  validateOptions(schema, options, \{}
\DoxyCodeLine{    name: 'Loader Name',}
\DoxyCodeLine{    baseDataPath: 'options',}
\DoxyCodeLine{  \});}
\DoxyCodeLine{}
\DoxyCodeLine{  // Code...}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{export default loader; }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_schema_utils_README_autotoc_md26335}{}\doxysubsubsection{$<$tt$>$\+Plugin$<$/tt$>$}\label{md_sfcode_node_modules_schema_utils_README_autotoc_md26335}

\begin{DoxyCode}{0}
\DoxyCodeLine{import validateOptions from 'schema-\/utils';}
\DoxyCodeLine{}
\DoxyCodeLine{import schema from 'path/to/schema.json';}
\DoxyCodeLine{}
\DoxyCodeLine{class Plugin \{}
\DoxyCodeLine{  constructor(options) \{}
\DoxyCodeLine{    validateOptions(schema, options, \{}
\DoxyCodeLine{      name: 'Plugin Name',}
\DoxyCodeLine{      baseDataPath: 'options',}
\DoxyCodeLine{    \});}
\DoxyCodeLine{}
\DoxyCodeLine{    this.options = options;}
\DoxyCodeLine{  \}}
\DoxyCodeLine{}
\DoxyCodeLine{  apply(compiler) \{}
\DoxyCodeLine{    // Code...}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{export default Plugin; }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_schema_utils_README_autotoc_md26336}{}\doxysubsection{Contributing}\label{md_sfcode_node_modules_schema_utils_README_autotoc_md26336}
Please take a moment to read our contributing guidelines if you haven\textquotesingle{}t yet done so.

./.github/\+CONTRIBUTING.\+md \char`\"{}\+CONTRIBUTING\char`\"{}\hypertarget{md_sfcode_node_modules_schema_utils_README_autotoc_md26337}{}\doxysubsection{License}\label{md_sfcode_node_modules_schema_utils_README_autotoc_md26337}
\href{./LICENSE}{\texttt{ MIT}} 