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

@effect/schema

Package Overview
Dependencies
Maintainers
0
Versions
335
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@effect/schema

Modeling the schema of data structures as first-class values

  • 0.68.10
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
468K
decreased by-52.06%
Maintainers
0
Weekly downloads
 
Created

What is @effect/schema?

@effect/schema is a TypeScript library for defining and validating schemas. It provides a way to define the structure of data, validate it, and transform it. The library is designed to be type-safe and integrates well with TypeScript's type system.

What are @effect/schema's main functionalities?

Defining Schemas

You can define schemas using the @effect/schema package. In this example, a schema for a user object is defined with 'name' as a string and 'age' as a number.

const { Schema, string, number } = require('@effect/schema');

const userSchema = Schema({
  name: string,
  age: number
});

Validating Data

The @effect/schema package allows you to validate data against a defined schema. In this example, a user object is validated against the userSchema. If the data is valid, it prints the valid user; otherwise, it prints the validation errors.

const { validate } = require('@effect/schema');

const user = { name: 'John Doe', age: 30 };
const result = validate(userSchema, user);

if (result.isValid) {
  console.log('Valid user:', result.value);
} else {
  console.log('Validation errors:', result.errors);
}

Transforming Data

You can also transform data to match the schema. In this example, the age property of the user object is transformed from a string to a number to match the userSchema.

const { transform } = require('@effect/schema');

const user = { name: 'John Doe', age: '30' };
const transformedUser = transform(userSchema, user);

console.log('Transformed user:', transformedUser);

Other packages similar to @effect/schema

FAQs

Package last updated on 26 Jun 2024

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