Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

schemaglobin

Package Overview
Dependencies
Maintainers
1
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

schemaglobin - npm Package Compare versions

Comparing version 4.0.5 to 4.0.6

dist/schemas/ColorSchema.d.ts

1

dist/index.d.ts
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);

2

package.json
{
"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";

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc