{"id":18745638,"url":"https://github.com/jsstuff/xschema","last_synced_at":"2025-07-23T01:31:39.960Z","repository":{"id":23901301,"uuid":"27281174","full_name":"jsstuff/xschema","owner":"jsstuff","description":"High performance and extensible data processing, schema builder, validator, and sanitizer.","archived":false,"fork":false,"pushed_at":"2018-10-20T19:20:13.000Z","size":266,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-07-08T02:50:10.590Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jsstuff.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-11-28T20:27:51.000Z","updated_at":"2024-09-09T20:43:14.000Z","dependencies_parsed_at":"2022-08-22T07:31:06.044Z","dependency_job_id":null,"html_url":"https://github.com/jsstuff/xschema","commit_stats":null,"previous_names":["exjs/xschema"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jsstuff/xschema","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsstuff%2Fxschema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsstuff%2Fxschema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsstuff%2Fxschema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsstuff%2Fxschema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jsstuff","download_url":"https://codeload.github.com/jsstuff/xschema/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsstuff%2Fxschema/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266602658,"owners_count":23954693,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T16:18:58.275Z","updated_at":"2025-07-23T01:31:39.907Z","avatar_url":"https://github.com/jsstuff.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"xschema.js\n==========\n\nHigh performance and extensible data processing, schema builder, validator, and sanitizer.\n\n  * [Official Repository: jsstuff/xschema](https://github.com/jsstuff/xschema)\n  * [Official Fiddler](http://kobalicek.com/fiddle-xschema.html)\n  * [Public Domain (https://unlicense.org)](https://unlicense.org)\n\nThe xschema library is a high performance data processing and validation library based on an extensible model/schema builder. It allows to build a schema that can be then used to process and validate any kind of JavaScript data (the root variable can be object, array, or any other primitive type). The library is designed for critical areas where the performance is important and even a minor overhead at validation side can cause service delays. The data validation and processing has been moved into extreme by using a JavaScript code-generator that generates the best possible data processing and validating functions for any user-defined schema. The most used JavaScript engines today have built-in JIT compiler so the code generated by xschema is then compiled by the VM into a machine code that will execute very fast and outperform all JavaScript data processing libraries that don't use such technique.\n\nThe performance is not the only aspect and feature offered by xschema. The library has been designed in a way that it should be very straightforward to define a schema, to reuse or inherit the existing one, and to create your own types that will extend the built-in functionality. There is no library that could satisfy all possible needs and use-cases so the possibility to extend the library is important. The library provides the most important types as full-featured built-ins.\n\nThe schema structure is always declarative and most of the schemas can be serialized back to JSON (xschema calls it a normalized JSON). The library also allows to associate a custom information called `metadata` with any field. Metadata is completely ignored by xschema library, but other tools can take advantage of it (for example you can associate a SQL table names with your entities and use them in your DB layer).\n\nAdditionally, xschema has several data processing options that help to deal with common problems like implementing data insertion, updating, deletion, and querying. Processing options can also be used to filter out objects' properties that are not defined (useful when extracting information from request's body or from more objects mixed together) and to accumulate all validation errors to have complete report of the validation.\n\n\nDisclaimer\n----------\n\nThe xschema library has been designed to solve common, but also very specific problems. It's very fast and the support for metadata allows to simply extend it by new features. All built-in features are used in production and you will find many of them handy when implementing web services that do CRUD operations, because a single schema can be used to validate data that is inserted, updated, queried, or deleted. The library has been designed to be very fast, but is also very complete and configurable.\n\n\nIntroduction\n------------\n\nthe xschema library uses a declarative approach to build schemas, but it comes with its own syntax instead of relying on existing solutions like JSONSchema. The main reason for such move was to simplify the way schemas are defined by introducing shortcuts and directives that start with `$` character. Shortcuts are used to simplify declaration of the most common concepts (for example an array of integers can be written as `$type: \"int[]\"`) and directives are used to configure the type itself. Object's members are always defined without a `$` prefix, but it's possible to define also members that start with `$` by escaping it as `\\\\$` (escaping and schema normalization is explained later).\n\n```js\nvar PersonSchema = xschema.schema({\n  firstName  : { $type: \"text\", $maxLength: 64 },\n  lastName   : { $type: \"text\", $maxLength: 64 },\n  dateOfBirth: { $type: \"date\", $leapYear: false },\n\n  active     : { $type: \"bool\" },\n  score      : { $type: \"int\", $min: 0 },\n  keywords   : { $type: \"text[]\" },\n  bashrc     : { $type: \"string\", $maxLength: 4096 },\n\n  address: {\n    line1    : { $type: \"text\" },\n    line2    : { $type: \"text\" },\n    city     : { $type: \"text\" },\n    zip      : { $type: \"text\" },\n    country  : { $type: \"text\" }\n  }\n});\n```\n\nThe example above defines a schema called `PersonSchema`, which is an `object` holding properties of various types specified by `$type` directive. Careful readers have noticed that the root object and nested `address` object have omitted the `$type` directive. It automatically uses `object` if no `$type` is provided, which allows to remove some verbosity in the schema declaration. Other directives like `$min`, `$max`, `$leapYear`, ..., are used to configure the type itself.\n\nConfused by `string` vs `text` type? Well, `string` is _any_ string in JavaScript in contrast to `text`, which is a string that doesn't contain `\\u0000-\\u0008`, `\\u000B-\\u000C`, and `\\u000E-\\u001F` characters. These characters have special meaning and in many cases their presence in your application's data is unwanted and may be dangerous.\n\nConfused by `[]` suffix in `keywords` member? It's a xschema shortcut that defines an array, which can also be defined by using `array` type like this:\n\n```js\nvar KeywordsSchema = xschema.schema({\n  $type: \"array\",\n  $data: {\n    $type: \"text\"\n  }\n});\n\nvar KeywordsSchema = xschema.schema({\n  $type: \"text[]\"\n});\n```\n\nBoth schemas defined above are equivalent and internally normalized into the same structure.\n\n\nData Processing Concepts\n------------------------\n\nThe library comes with two base concepts that are used to work with data.\n\n  - **`xschema.process(...)`** is a concept used to create a new data based on existing data. It's very useful in cases that more entities are mixed together in a single object and you need to separate/extract their content into independent objects. This happens for example in a request-body object. Data processing does not just validate the input data, but it can also sanity it before creating the output. If configured, you can trim/simplify input text, remove unknown properties, or insert fields having default values if they are not present.\n\n  - **`xschema.test(...)`** is a concept used to test whether the given data conforms to the schema, but without using sanitizers.\n\n\nData Processing Options\n-----------------------\n\nSeveral data processing options exist that allow to use a single schema for multiple purposes. The default `xschema.kNoOptions` specifies no options and the schema is processed in a default way (i.e. strict mode).\n\nThe additional options are used to control:\n\n  - **Extraction Mode** - Options `xschema.kExtractTop`, `xschema.kExtractNested`, and `xschema.kExtractTop` are used to control data extraction. Data extraction means extracting only specified properties from objects that can contain more properties that are not defined in the schema. It's useful when extracting parameters from a request body or to extract data that is known by schema, but without failing in cases that there is something that is not not known.\n\n  - **Delta Mode** - Option `xschema.kDeltaMode` can be used to force nearly all properties to be optional. This is used in cases that you allow delta updates, but you still require some properties that specify DB keys to be present.\n\n  - **Error Accumulation** - Option `xschema.kAccumulateErrors` is used in case that you want to get all errors that happened during data processing, but just the first one.\n\nData extraction options:\n\n  - **`xschema.kExtractTop`** - Extract from top-level object only.\n  - **`xschema.kExtractNested`** - Extract from nested object(s) only.\n  - **`xschema.kExtractAll`** - Combination of `xschema.kExtractTop` and `xschema.kExtractNested`, which results in extraction from any `\"object\"`.\n\nTODO\n\n\nBuilt-In Data Types\n-------------------\n\nThe following data types are built-in:\n\nType-Name and Aliases    | JS Type    | Description\n:----------------------- | :--------- | :---------------------------------------\n`any`                    | `any`      | Any type (variant)\n`array`                  | `array`    | Array type\n`map`                    | `object`   | Map type\n`object`                 | `object`   | Object type (default)\n`boolean`, `bool`        | `boolean`  | Boolean\n`double`, `number`       | `number`   | Double precision floating point number\n`numeric`                | `number`   | Double precision, used to distinguish from `number` when specifying a DB columns\n`int8`                   | `number`   | 8-bit signed integer\n`uint8`                  | `number`   | 8-bit unsigned integer\n`int16`, `short`         | `number`   | 16-bit signed integer\n`uint16`, `ushort`       | `number`   | 16-bit unsigned integer\n`int24`                  | `number`   | 24-bit signed integer\n`uint24`                 | `number`   | 24-bit unsigned integer\n`int32`                  | `number`   | 32-bit signed integer\n`uint32`                 | `number`   | 32-bit unsigned integer\n`int53`                  | `number`   | 53-bit signed integer (safe integer)\n`uint53`                 | `number`   | 53-bit unsigned integer (safe integer)\n`int`, `integer`         | `number`   | signed integer (unsafe integer)\n`uint`                   | `number`   | unsigned integer (unsafe integer)\n`lat`, `latitude`        | `number`   | Latitude value (-90...90)\n`lon`, `longitude`       | `number`   | Longitude value (-180...180)\n`char`                   | `string`   | String containing exactly 1 character\n`string`                 | `string`   | Any string\n`text`                   | `string`   | Restricted multi-line string\n`textline`               | `string`   | Restricted single-line string\n`bigint`                 | `string`   | String that contains integer of unlimited precision\n`int64`                  | `string`   | Bigint limited to 64 bits (signed)\n`uint64`                 | `string`   | Bigint limited to 64-bits (unsigned)\n`time`                   | `string`   | Time without milliseconds\n`time-ms`                | `string`   | Time with milliseconds (ms)\n`time-us`                | `string`   | Time with microseconds (μs)\n`date`                   | `string`   | Date\n`datetime`               | `string`   | Date and time without milliseconds\n`datetime-ms`            | `string`   | Date and time with milliseconds (ms)\n`datetime-us`            | `string`   | Date and time with microseconds (μs)\n`color`                  | `string`   | Color values specified by `\"#RGB\"`, `\"#RRGGBB\"`, or a CSS name\n`creditcard`             | `string`   | Credit-card number\n`mac`                    | `string`   | MAC address\n`ip`                     | `string`   | IP address\n`isbn`                   | `string`   | ISBN identifier (either ISBN-10 or ISBN-13)\n`isbn10`                 | `string`   | ISBN-10 identifier\n`isbn13`                 | `string`   | ISBN-13 identifier\n`uuid`                   | `string`   | UUID or GUID\n\n\nAny\n---\n\nAny `$type` is specified as `any`.\n\nAny type directives:\n\nDirective Name           | Value      | Default | Description\n:----------------------- | :--------- | :------ | :-----------------------------\n`$null`                  | `bool`     | `false` | Specifies if the value can be `null`\n`$allowed`               | `any[]`    | `null`  | Array of values that are allowed. Any type allows to put anything into the `$allowed` array. If an array or object is put in there a deep comparison will be performed to verify if the input data conforms to it\n\n\nBoolean\n-------\n\nBoolean `$type` is specified as `bool` or `boolean`.\n\nBoolean type directives:\n\nDirective Name           | Value      | Default | Description\n:----------------------- | :--------- | :------ | :-----------------------------\n`$null`                  | `bool`     | `false` | Specifies if the value can be `null`\n`$allowed`               | `bool[]`   | `null`  | Array of boolean values that are allowed. This is useful to restrict the value to be always `true` or `false`, but it does nothing if the array is empty or both `true` and `false` values are specified.\n\n\nNumber and Integer\n------------------\n\nNumber type `$type` is specified by the following type names and properties:\n\nType and Aliases         | Minimum Value     | Maximum Value    | Description\n:----------------------- | :---------------- | :--------------- | :-------------\n`double`, `number`       | None              | None             | Double precision floating point\n`numeric`                | None              | None             | Numeric value (alias to double, but can be used to distinguish between double and numeric in case of describing DB schema)\n`int8`                   | -128              | 127              | 8-bit signed integer\n`uint8`                  | 0                 | 255              | 8-bit unsigned integer\n`int16`, `short`         | -32768            | 32767            | 16-bit signed integer\n`uint16`, `ushort`       | 0                 | 65535            | 16-bit unsigned integer\n`int32`                  | -2147483648       | 2147483647       | 32-bit signed integer\n`uint32`                 | 0                 | 4294967295       | 32-bit unsigned integer\n`int`, `integer`         | -9007199254740991 | 9007199254740991 | 53-bit signed integer, matches `Number.isSafeInteger()` behavior\n`uint`                   | 0                 | 9007199254740991 | 53-bit unsigned integer, matches `Number.isSafeInteger()` behavior\n`lat`, `latitude`        | -90               | 90               | Latitude (double precision)\n`lon`, `longitude`       | -180              | 180              | Longitude (double precision)\n\nNumber type directives:\n\nDirective Name           | Value      | Default | Description\n:----------------------- | :--------- | :------ | :-----------------------------\n`$null`                  | `bool`     | `false` | Specifies if the value can be `null`\n`$allowed`               | `number[]` | `null`  | Array of numbers that are allowed. If this directive is used it cancels all directives that specify minimum, maximum, or any other number related constraints\n`$min`                   | `number`   | `null`  | Minimum value (the number has to be greater or equal than `$min`)\n`$max`                   | `number`   | `null`  | Maximum value (the number has to be lesser or equal than `$max`)\n`$minExclusive`          | `number`   | `false` | Minimum value is exclusive\n`$maxExclusive`          | `number`   | `false` | Maximum value is exclusive\n`$multipleOf`            | `int`      | `null`  | Restrict the number to multiple of this value `(input % $multipleOf) === 0`\n`$multipleBase`          | `int`      | `null`  | If used with `$multipleOf` it changes the expression to `(input % $multipleOf) === $multipleBase`\n\n\nCharacter\n---------\n\nCharacter `$type` is specified as `char` and it's a string that has length equal to one (that is, one character long string).\n\nCharacter type directives:\n\nDirective Name           | Value      | Default | Description\n:----------------------- | :--------- | :------ | :-----------------------------\n`$null`                  | `bool`     | `false` | Specifies if the value can be `null`\n`$empty`                 | `bool`     | `false` | Specifies if the char can be an empty string\n`$allowed`               | `char[]`   | `null`  | Array of characters that are allowed\n\n\nString and Text\n---------------\n\nString `$type` is specified as `string`, `text`, or `textline`. If type `string` is specified any JavaScript string passes, however, if `text` type is specified the validator only passes if the string doesn't contain `\\u0000-\\u0008`, `\\u000B-\\u000C`, and `\\u000E-\\u001F` characters. Use `text` to disallow these characters that have special meaning and are in most cases unwanted (especially the `\\u0000` character). The `textline` type restricts text from using line and paragraph delimiter characters.\n\nString/Text type directives:\n\nDirective Name           | Value      | Default | Description\n:----------------------- | :--------- | :------ | :-----------------------------\n`$null`                  | `bool`     | `false` | Specifies if the value can be `null`\n`$empty`                 | `bool`     | `true`  | Specifies if the string can be an empty\n`$allowed`               | `string[]` | `null`  | Array of strings that are allowed. If this directive is used it cancels all directives related to string length validation, except `$empty` directive, which always applies, regardless of other constraints\n`$length`                | `number`   | `null`  | Exact string length\n`$minLength`             | `number`   | `null`  | Minimum string length\n`$maxLength`             | `number`   | `null`  | Maximum string length\n`$re`                    | `RegExp`   | `null`  | Regular expression\n\n\nBigInt\n------\n\nBigInt `$type` is specified as `bigint`. BigInt is a string that contains only ASCII digits (characters from `0` to `9`) and an optional minus sign at the beginning. It allows to validate whether the number represented as a string doesn't overflow 64 bits and also allows to set a possible minimum and maximum value (also as string). BigInt can also be configured to allow more than 64-bits by using `$min` and `$max` directives, described below.\n\nBigInt type directives:\n\nDirective Name           | Value      | Default | Description\n:----------------------- | :--------- | :------ | :-----------------------------\n`$null`                  | `bool`     | `false` | Specifies if the value can be `null`\n`$empty`                 | `bool`     | `false` | Specifies if the string can be an empty\n`$allowed`               | `string[]` | `null`  | Array of strings that are allowed. If this directive is used it cancels `$min` and `$max` constraints\n`$min`                   | `string`   | `null`  | Minimum value (as string)\n`$max`                   | `string`   | `null`  | Maximum value (as string)\n`$minExclusive`          | `bool`     | `false` | Minimum value is exclusive\n`$maxExclusive`          | `bool`     | `false` | Maximum value is exclusive\n\nOptionally, you can use `xschema.misc.isBigInt(s, min, max)` function to check whether a string value matches BigInt with optional `min` and `max` constraints. This function doesn't require a schema instance.\n\n\nColor\n-----\n\nColor `$type` is specified as `color`. Color is a string that matches `#RGB`, `#RRGGBB` or `color-name` format. It supports all color names that are defined by CSS specification and allows to include a dictionary having extra color names that you need to allow. Color names are case-insensitive by default.\n\nColor type directives:\n\nDirective Name           | Value      | Default | Description\n:----------------------- | :--------- | :------ | :-----------------------------\n`$null`                  | `bool`     | `false` | Specifies if the value can be `null`\n`$empty`                 | `bool`     | `false` | Specifies if the string can be an empty\n`$cssNames`              | `bool`     | `true`  | Specifies if CSS color names are allowed\n`$extraNames`            | `set`      | `null`  | A set (dictionary having `key: true`) that contains extra color names that are allowed\n\n\nCredit Card\n-----------\n\nCredit card `$type` is specified as `creditcard`. It checks whether the string is a valid credit card number by using a LUHN algorithm. The validator doesn't accept dashes or any other characters used as separators.\n\nCredit card type directives:\n\nDirective Name           | Value      | Default | Description\n:----------------------- | :--------- | :------ | :-----------------------------\n`$null`                  | `bool`     | `false` | Specifies if the value can be `null`\n`$empty`                 | `bool`     | `false` | Specifies if the string can be an empty\n\n\nISBN\n----\n\nISBN `$type` is specified as `isbn`. It checks whether the string is a valid ISBN number.\n\nISBN type directives:\n\nDirective Name           | Value      | Default | Description\n:----------------------- | :--------- | :------ | :-----------------------------\n`$null`                  | `bool`     | `false` | Specifies if the value can be `null`\n`$empty`                 | `bool`     | `false` | Specifies if the string can be an empty\n`$format`                | `string`   | `\"\"`    | Specifies the ISBN format to accept. The default value `null` (or alternatively `\"\"`) is used to accept any valid ISBN number. To restrict to a particular format use `\"10\"` or `\"13\"`.\n\n\nMAC Address\n-----------\n\nMAC address `$type` is specified as `mac`. MAC address is a string in form `XX:XX:XX:XX:XX:XX` that specifies a network MAC address.\n\nMAC address type directives:\n\nDirective Name           | Value      | Default | Description\n:----------------------- | :--------- | :------ | :-----------------------------\n`$null`                  | `bool`     | `false` | Specifies if the value can be `null`\n`$empty`                 | `bool`     | `false` | Specifies if the string can be an empty\n`$separator`             | `char`     | `:`     | Specifies separator used between MAC address components\n\n\nIP Address\n----------\n\nIP address `$type` is specified as `ip`. IP address is a string specifying a network IP address.\n\nIP address type directives:\n\nDirective Name           | Value      | Default | Description\n:----------------------- | :--------- | :------ | :-----------------------------\n`$null`                  | `bool`     | `false` | Specifies if the value can be `null`\n`$empty`                 | `bool`     | `false` | Specifies if the string can be an empty\n`$format`                | `string`   | `\"any\"` | Specifies the IP address format - `\"any\"`, `\"ipv4\"`, and `\"ipv6\"`.\n`$port`                  | `bool`     | `false` | Specifies if the IP address can contain a port number\n\n\nUUID\n----\n\nUUID `$type` is specified as `uuid`. UUID validator is used to check whether the string contains a valid UUID number, that can be optionally surrounded by curly braces.\n\nUUID type directives:\n\nDirective Name           | Value      | Default | Description\n:----------------------- | :--------- | :------ | :-----------------------------\n`$null`                  | `bool`     | `false` | Specifies if the value can be `null`\n`$empty`                 | `bool`     | `false` | Specifies if the string can be an empty\n`$format`                | `string`   | `\"rfc\"` | Specifies the UUID format. It can be `\"rfc\"` to accept UUIDs in a `\"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX\"` format, `\"windows\"` to accept UUIDs surrounded by curly brackets, or `\"any\"` to accept either RFC or WINDOWS format. If not specified or `null` `\"rfc\"` format is used.\n`$version`               | `string`   | `null`  | Specifies the version of UUID to accept. Version is a string from `\"1\"` to `\"5\"`. It can contain an optional `\"+\"` sign (like `\"3+\"`) to accept UUIDs of a particular version and all newer.\n\n\nDateTime\n--------\n\nDateTime `$type` is specified as `date`, `datetime`, `datetime-ms`, and `datetime-us`. It's a formatted string that contains date, time, or date+time components. The validator extracts these components and validates whether they are correct. Leap years and leap seconds support is built-in and can be configured through directives.\n\nDateTime defaults:\n\nDate Type                | Format                       | Description\n:----------------------- | :--------------------------- | :---------------------\n`date`                   | `YYYY-MM-DD`                 | Date only\n`datetime`               | `YYYY-MM-DD HH:mm:ss`        | Date+time\n`datetime-ms`            | `YYYY-MM-DD HH:mm:ss.SSS`    | Date+time+ms\n`datetime-us`            | `YYYY-MM-DD HH:mm:ss.SSSSSS` | Date+time+μs\n\nDateTime format options:\n\nFormat Option            |Fixed Length| Range           | Description\n:----------------------- | :----------| :-------------- | :---------------------\n`Y`                      | `false`    | `1-9999`        | Year (1-4 digits)\n`YY`                     | `true`     | `00-99`         | Year (2 digits)\n`YYYY`                   | `true`     | `0001-9999`     | Year (4 digits)\n`M`                      | `false`    | `1-12`          | Month (1-2 digits)\n`MM`                     | `true`     | `01-12`         | Month (2 digits)\n`D`                      | `false`    | `1-31`          | Day (1-2 digits)\n`DD`                     | `true`     | `01-31`         | Day (2 digits)\n`H`                      | `false`    | `0-23`          | Hour (1-2 digits)\n`HH`                     | `true`     | `00-23`         | Hour (2 digits)\n`m`                      | `false`    | `0-59`          | Minute (1-2 digits)\n`mm`                     | `true`     | `00-59`         | Minute (2 digits)\n`s`                      | `false`    | `0-60`          | Second (1-2 digits)\n`ss`                     | `true`     | `00-60`         | Second (2 digits)\n`SSS`                    | `true`     | `000-999`       | Millisecond (3 digits)\n`SSSSSS`                 | `true`     | `000000-999999` | Microsecond (6 digits)\n`?`                      | `true`     |                 | Any other character requires exact match of that character, for example `-`, `/`, `.`, `,`, etc...\n\nDateTime type directives:\n\nDirective Name           | Value      | Default | Description\n:----------------------- | :--------- | :------ | :-----------------------------\n`$null`                  | `bool`     | `false` | Specifies if the value can be `null`\n`$empty`                 | `bool`     | `false` | Specifies if the string can be an empty\n`$format`                | `string`   | `null`  | Specifies date+time format, see format options above\n`$leapYear`              | `bool`     | `true`  | Specifies whether to allow leap year date\n`$leapSecond`            | `bool`     | `false` | Specifies whether to allow leap second date+time\n\n\nMap\n---\n\n\nMap `$type` is specified as `map`. It's an object where all keys are strings and all values have the same type specified by `$data` directive.\n\nMap type directives:\n\nDirective Name           | Value      | Default | Description\n:----------------------- | :--------- | :------ | :-----------------------------\n`$null`                  | `bool`     | `false` | Specifies if the map can be `null`\n`$data`                  | `object`   | `null`  | Specifies the schema of all map values.\n\nObject\n------\n\nObject `$type` is specified as `object` or can be omitted completely. Object is a special type that allows to specify its members by using unprefixed keys (keys that don't start with `\"$\"`). For example the following specifies an object that has mandatory members (keys) `\"a\"` and `\"b\"`:\n\n```js\nvar Schema = xschema({\n  a: { $type: \"int\" },\n  b: { $type: \"int\", $optional: true }\n});\n\n// These will pass.\nxschema.test({ a: 1       }, Schema);\nxschema.test({ a: 1, b: 2 }, Schema);\n```\n\nObject's directives and members can be mixed in the same definition, for example the following schema defines an object that has a nested object, which is optional:\n\n```js\nvar Schema = xschema({\n  nested: {\n    $optional: true,\n\n    a: { $type: \"int\" },\n    b: { $type: \"int\", $optional: true }\n  }\n});\n\n// These will pass.\nxschema.test({                        }, Schema);\nxschema.test({ nested: { a: 1       } }, Schema);\nxschema.test({ nested: { a: 1, b: 2 } }, Schema);\n```\n\nTODO\n\nObject type directives:\n\nDirective Name           | Value      | Default | Description\n:----------------------- | :--------- | :------ | :-----------------------------\n`$null`                  | `bool`     | `false` | Specifies if the value can be `null`\n\n\nArray\n-----\n\nArray `$type` is specified as `array` or by `[]` suffix (shortcut).\n\nArray type directives:\n\nDirective Name           | Value      | Default | Description\n:----------------------- | :--------- | :------ | :-----------------------------\n`$null`                  | `bool`     | `false` | Specifies if the array can be `null`\n`$length`                | `int`      | `null`  | Specifies an exact length of the array.\n`$minLength`             | `int`      | `null`  | Specifies the minimum length of the array.\n`$maxLength`             | `int`      | `null`  | Specifies the maximum length of the array.\n`$data`                  | `object`   | `null`  | Specifies the schema of all array items.\n\n\nCustom Types\n------------\n\nTODO\n\n\nGlobal Directives\n-----------------\n\nGlobal directives can be applied to any `$type`:\n\nDirective Name           | Value      | Default | Description\n:----------------------- | :--------- | :------ | :-----------------------------\n`$null`                  | `bool`     | `false` | Specifies if the value can be `null`\n`$fn`                    | `function` | `null`  | A user-defined validation function. It should return `true` or `\"\"` on success and false or `\"ErrorCode\"` on failure. The function is always called on a processed object, if posible. For example, if an object is transformed to object containing less members, the user-function will be called with that object, not the input one.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsstuff%2Fxschema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjsstuff%2Fxschema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsstuff%2Fxschema/lists"}