schemaglobin
Advanced tools
Comparing version 4.0.5 to 4.0.6
export * from "./Schema"; | ||
export * from "./schemas/ArraySchema"; | ||
export * from "./schemas/BooleanSchema"; | ||
export * from "./schemas/ColorSchema"; | ||
export * from "./schemas/DateSchema"; | ||
@@ -5,0 +6,0 @@ export * from "./schemas/EmailSchema"; |
@@ -18,2 +18,3 @@ "use strict"; | ||
__exportStar(require("./schemas/BooleanSchema"), exports); | ||
__exportStar(require("./schemas/ColorSchema"), exports); | ||
__exportStar(require("./schemas/DateSchema"), exports); | ||
@@ -20,0 +21,0 @@ __exportStar(require("./schemas/EmailSchema"), exports); |
{ | ||
"name": "schemaglobin", | ||
"description": "Validate user-entered data.", | ||
"version": "4.0.5", | ||
"version": "4.0.6", | ||
"repository": "https://github.com/dhoulb/schemaglobin", | ||
@@ -6,0 +6,0 @@ "author": "Dave Houlbrooke <dave@shax.com>", |
@@ -158,2 +158,3 @@ # Schemaglobin: Validate unknown user input against schemas | ||
const numberSchema = number({ required: true, ...etc }); | ||
const colorSchema = color({ required: true, ...etc }); | ||
const dateSchema = date({ required: true, ...etc }); | ||
@@ -172,2 +173,3 @@ const emailSchema = email({ required: true, ...etc }); | ||
numberSchema.validate(12345); // Returns "123" | ||
colorSchema.validate("#00CCFF"); // Returns "#00CCFF" | ||
dateSchema.validate("1995"); // Returns "1995-01-01" | ||
@@ -186,2 +188,3 @@ emailSchema.validate("me@x.com"); // Returns "me@x.com" | ||
dateSchema.validate("aaaaaaa"); // Returns Invalid("Invalid date") | ||
colorSchema.validate(true); // Returns Invalid("Must be string or null") | ||
emailSchema.validate("111111"); // Returns Invalid("Invalid email format") | ||
@@ -400,2 +403,16 @@ phoneSchema.validate("aaaaaa"); // Returns Invalid("Invalid phone number") | ||
### `color()` | ||
The `color()` creator function creates a `ColorSchema` instance that can validate hexadecimal color strings: | ||
- Strings in hex color format are valid, e.g. `#00CCFF` | ||
- Whitespace is trimmed automatically. | ||
- Falsy values are converted to `null` | ||
- `null` is an invalid value if `options.required` is truthy. | ||
`color()` also allows the following options: | ||
- `options.value: Date = null` - The default value which will be used if the value is `undefined` | ||
- `options.required: boolean = false` - If true, then null values will return `Invalid("Required")` | ||
### `email()` | ||
@@ -543,2 +560,4 @@ | ||
url.optional.validate(null); | ||
color.required.validate("#00CCFF"); | ||
color.optional.validate(null); | ||
``` | ||
@@ -545,0 +564,0 @@ |
@@ -7,2 +7,3 @@ // Export schema. | ||
export * from "./schemas/BooleanSchema"; | ||
export * from "./schemas/ColorSchema"; | ||
export * from "./schemas/DateSchema"; | ||
@@ -9,0 +10,0 @@ export * from "./schemas/EmailSchema"; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
246120
73
5096
581