Socket
Socket
Sign inDemoInstall

@sapphire/shapeshift

Package Overview
Dependencies
Maintainers
3
Versions
444
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sapphire/shapeshift

Blazing fast input validation and transformation ⚡


Version published
Weekly downloads
209K
increased by3.94%
Maintainers
3
Weekly downloads
 
Created

What is @sapphire/shapeshift?

@sapphire/shapeshift is a powerful validation library for JavaScript and TypeScript. It allows developers to define schemas for their data and validate it against these schemas. The library is designed to be highly flexible and easy to use, making it suitable for a wide range of applications.

What are @sapphire/shapeshift's main functionalities?

Basic Validation

This feature allows you to define a schema and validate an object against it. In this example, the schema expects an object with a 'name' string and an 'age' number.

const { s } = require('@sapphire/shapeshift');

const schema = s.object({
  name: s.string,
  age: s.number
});

const data = { name: 'John', age: 30 };
const result = schema.parse(data);
console.log(result); // { name: 'John', age: 30 }

Optional Fields

This feature allows you to define optional fields in your schema. In this example, the 'age' field is optional.

const { s } = require('@sapphire/shapeshift');

const schema = s.object({
  name: s.string,
  age: s.number.optional
});

const data = { name: 'John' };
const result = schema.parse(data);
console.log(result); // { name: 'John' }

Array Validation

This feature allows you to validate arrays. In this example, the schema expects an array of strings.

const { s } = require('@sapphire/shapeshift');

const schema = s.array(s.string);

const data = ['apple', 'banana', 'cherry'];
const result = schema.parse(data);
console.log(result); // ['apple', 'banana', 'cherry']

Nested Objects

This feature allows you to validate nested objects. In this example, the schema expects an object with a 'user' object that contains 'name' and 'age' fields.

const { s } = require('@sapphire/shapeshift');

const schema = s.object({
  user: s.object({
    name: s.string,
    age: s.number
  })
});

const data = { user: { name: 'John', age: 30 } };
const result = schema.parse(data);
console.log(result); // { user: { name: 'John', age: 30 } }

Other packages similar to @sapphire/shapeshift

Keywords

FAQs

Package last updated on 29 Apr 2022

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