New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mongoose-to-joi-translator

Package Overview
Dependencies
Maintainers
2
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-to-joi-translator

Extracts schema from mongoose and generates an equivilent JOI schema.

  • 2.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
increased by25%
Maintainers
2
Weekly downloads
 
Created
Source

Mongoose-to-joi-translator Logo

mongoose-to-joi-translator

Build Status codecov dependencies Status devDependencies Status

Description

Translates Mongoose schema to Joi. You can use Joi schema to do the validation. The idea is to write database models once and validate everywhere. You may use this package with generic-joi-validator.

Installation

npm install mongoose-to-joi-translator

Supported validations

  1. All types
    • required
    • valid (enum validation)
    • default
  2. Strings
    • min
  3. Arrays
    • items (element types)
  4. Numbers
    • min
    • max
  5. Objects
  6. Dates
  7. ObjectIDs
  8. Booleans
  9. Custom sync validators as documented here

Deeply nested document validation is supported, i.e. Objects within Objects, Arrays within Objects etc.

Testing

npm test

Usage

// Require the library
const getJoiSchema = require('mongoose-to-joi-translator');
const schema = new Schema({ word: { type: String } });
const ModelName = mongoose.model('ModelName', schema);
// Extract schema
const joiSchema = getJoiSchema(ModelName);
// Use Joi to validate
const { error, value } = Joi.validate({ word: 'hello' }, joiSchema);

FAQs

Package last updated on 15 Jan 2018

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