Socket
Socket
Sign inDemoInstall

mongoose-types-ext

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    mongoose-types-ext

A package of mongoose types extensions


Version published
Weekly downloads
4
increased by100%
Maintainers
1
Install size
19.8 kB
Created
Weekly downloads
 

Changelog

Source

0.2.0 (2015-05-20)

Features
  • exact-length: adapt to mongoose 4 validator syntax (99a72122)
  • exclusive-min: adapt to mongoose 4 validator syntax (d87b294f)
  • max-length: remove maxlength, it is now a mongoose builtin (ac52c945)
  • min-length: remove minlength, it is now a mongoose builtin (e6b5a49c)

<a name"0.1.0"></a>

Readme

Source

npm version Build Status Coverage Status

mongoose-types-ext

A package of mongoose types extensions.

Instalation

With npm

    npm install --save mongoose-types-ext

Runing tests

	gulp test

Usage

Just require the extensions before load your mongoose models:

var mongoose = require('mongoose');
require('mongoose-types-ext')(mongoose);
var YourSchemaDefinition = new mongooseSchema({
	someField: {
		type: String,
		maxLength: 10
	},
	/* (...) */
});
var YourModel = mongoose.model('YourModel', YourSchemaDefinition);

Supported extentions

String

  • exactLength: Sets a exact length string validator.

Custom error messages: You can also configure custom error messages and use the special token {EXACT_LENGTH} which will be replaced with the invalid value. Ex:

var rule = [4, 'The length of path `{PATH}` ({VALUE}) should be equal {EXACT_LENGTH}.'];
var schema = new Schema({ n: { type: String, exactLength: rule })
var M = mongoose.model('Measurement', schema);
var s= new M({ n: 'teste' });
s.validate(function (err) {
	console.log(String(err)); // ValidationError: The length of path `n` (test) should be equal 4.
})

Number

  • exclusivemin: Sets a minimum number validator not including the configurated value.

Custom error messages: You can also configure custom error messages and use the special token {EXCLUSIVE_MIN} which will be replaced with the invalid value. Ex:

var rule = [10, 'The value of path `{PATH}` ({VALUE}) should be greater than ({EXCLUSIVE_MIN}).'];
var schema = new Schema({ n: { type: Number, exclusivemin: rule })
var M = mongoose.model('Measurement', schema);
var s= new M({ n: 10 });
s.validate(function (err) {
	console.log(String(err)); // ValidationError: The value of path `n` (10) should be greater than 10.
});

How to contribute

I am very glad to see this project living with pull requests.

LICENSE

Copyright (c) 2015 Daniel Campos

Licensed under the MIT license.

Keywords

FAQs

Last updated on 20 May 2015

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc