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

@humanwhocodes/object-schema

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@humanwhocodes/object-schema

An object schema merger/validator

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is @humanwhocodes/object-schema?

The @humanwhocodes/object-schema package is a utility for validating JavaScript objects against a predefined schema. It allows developers to ensure that objects match a specific structure, types, and constraints, making it easier to enforce data integrity throughout applications.

What are @humanwhocodes/object-schema's main functionalities?

Type Validation

This feature allows for the validation of object properties against specified types. In the example, the schema is defined to expect a property 'name' of type string. The validate method then checks if the provided object matches this schema.

{"const schema = new Schema({name: Schema.string()}); const result = schema.validate({name: 'John Doe'}); if (result.valid) { console.log('Valid!'); } else { console.log('Invalid:', result.errors); }"}

Required Properties

This feature ensures that certain properties are present in the object being validated. In the code sample, the 'name' property is marked as required, and the validation will fail if it is missing.

{"const schema = new Schema({name: Schema.string().required()}); const result = schema.validate({}); if (result.valid) { console.log('Valid!'); } else { console.log('Invalid:', result.errors); }"}

Default Values

This feature allows specifying default values for properties that are not present in the validated object. In the example, if the 'age' property is missing, it will default to 18.

{"const schema = new Schema({age: Schema.number().default(18)}); const result = schema.validate({}); console.log(result.value); // { age: 18 }"}

Other packages similar to @humanwhocodes/object-schema

Keywords

FAQs

Package last updated on 14 Mar 2019

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

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