Sign In

schema-guard

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

schema-guard

Create lightweight runtime type guards from a plain object schema

latest
Source
npmnpm
Version
2.0.0
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

schema-guard

Create lightweight runtime type guards from a plain object schema

Install

npm install schema-guard

Usage

import schemaGuard from 'schema-guard';

const isUser = schemaGuard({
	name: 'string',
	age: 'number',
	email: 'string?',
	tags: 'string[]',
	active: 'boolean',
});

isUser({name: 'Alice', age: 30, tags: ['admin'], active: true});
//=> true

isUser({name: 123});
//=> false

API

schemaGuard(schema)

Returns a type guard function (value: unknown) => boolean.

schema

Type: object

An object mapping property names to type strings.

Supported types: string, number, boolean, bigint, symbol, function, object, array.

Use ? suffix for optional fields (accepts undefined and null):

{email: 'string?'}

Use [] suffix for typed arrays:

{tags: 'string[]'}

Only declared keys are checked. Extra properties on the input value do not cause failure.

Limitations: Nested object validation is not supported. Use 'object' to check that a property is an object, but its shape will not be validated.

  • is-runtime - Detect the current JavaScript runtime environment

License

MIT

Keywords

schema

FAQs

Package last updated on 16 Feb 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts