Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
mongoose-type-phone
Advanced tools
A phone field-type for Mongoose schemas based on mongoose-type-email, mongoose-intl-phone-number and google-libphonenumber.
This will validate phone, correctly:
var mongoose = require('mongoose');
var mongooseTypePhone = require('mongoose-type-phone');
var UserSchema = new mongoose.Schema({
phone: {
work: mongoose.SchemaTypes.Phone,
home: mongoose.SchemaTypes.Phone
}
});
You can also use the stuff in String
type:
var UserSchema = new mongoose.Schema({
phone: {
work: {type: mongoose.SchemaTypes.Phone, required: true},
home: {type: mongoose.SchemaTypes.Phone, required: true},
}
});
You can also use it as an array:
var UserSchema = new mongoose.Schema({
phones: [{type: mongoose.SchemaTypes.Phone}]
});
You can add 'allowBlank: true' in order to allow empty string ('') when the field is not required
var mongoose = require('mongoose');
var mongooseTypePhone = require('mongoose-type-phone');
var UserSchema = new mongoose.Schema({
phone: {
work: { type: mongoose.SchemaTypes.Phone, allowBlank: true }, // allows '' as a value
home: mongoose.SchemaTypes.Phone // throws when the value is ''
}
});
Here is the example with full set of available options:
var mongoose = require('mongoose');
var mongooseTypePhone = require('mongoose-type-phone');
var UserSchema = new mongoose.Schema({
phone: {
type: mongoose.SchemaTypes.Phone,
required: 'Phone number should be set correctly',
allowBlank: false,
allowedNumberTypes: [mongooseTypePhone.PhoneNumberType.MOBILE, mongooseTypePhone.PhoneNumberType.FIXED_LINE_OR_MOBILE],
phoneNumberFormat: mongooseTypePhone.PhoneNumberFormat.INTERNATIONAL, // can be omitted to keep raw input
defaultRegion: 'RU',
parseOnGet: false
}
});
This project needs your contribution! :-)
required
and allowBlank
are written now);cast()
and checkRequired()
?FAQs
A phone field-type for Mongoose schemas
The npm package mongoose-type-phone receives a total of 75 weekly downloads. As such, mongoose-type-phone popularity was classified as not popular.
We found that mongoose-type-phone demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.