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

mongoose-integer

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-integer

Mongoose plugin to validate integer values within a Mongoose schema

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

mongoose-integer

mongoose-integer is a plugin to validate integer values within a Mongoose Schema.

I was really tired of casting or validating my Number fields to an integer value. So I created this easy-to-use plugin that takes all the work from you.

Usage

npm install mongoose-integer

Then, simply apply the plugin to your schema:

var mongoose = require('mongoose');
var integerValidator = require('mongoose-integer');

var mySchema = new mongoose.Schema({
	value: {
		type: Number,
		integer: true
	}
});

mySchema.plugin(integerValidator);

Custom Error Messages

You can pass through a custom error message as part of the optional options argument:

mySchema.plugin(integerValidator, { message: 'Error, expected {PATH} to be an integer.' });

You can also pass a specific error message as a string in your field declaration:

var mySchema = new mongoose.Schema({
	value: {
		type: Number,
		integer: 'Value must be an integer.'
	}
});

You have access to all of the standard Mongoose error message templating:

  • {PATH}
  • {VALUE}
  • {TYPE}

Tests

To run the tests you need a local MongoDB instance available. Run with:

npm test

Issues

Please use the GitHub issue tracker to raise any problems or feature requests.

If you would like to submit a pull request with any changes you make, please feel free!

Keywords

FAQs

Package last updated on 29 Dec 2015

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