Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mongoose-intl-phone-number

Package Overview
Dependencies
Maintainers
3
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-intl-phone-number

A configurable mongoose.js plugin that parses phone numbers and stores data about them in the document.

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created
Source

mongoose-intl-phone-number

Build Status Coverage Status Dependency Status npm version

This module takes a string of numbers and determines their validity as well as returns data about the phone numbers. This module is based on Google's libphonenumber.

How it works

A phone number is provided on the document, during the pre-save/validate hook (you can specify), it runs the phone number through libphonenumber and stores the data returned onto fields in the document model.

Use Case

Applications that accept international phone numbers should use this plugin to gather and store information about the number such as country code, national format, etc.

Installation

npm install --save mongoose-intl-phone-number

API Reference

mongooseIntlPhoneNumber

Validates a phone number against google's libphonenumber, otherwise returns a validation error.

Example

var mongooseIntlPhoneNumber = require('mongoose-intl-phone-number');
var schema = Schema({...});

schema.plugin(mongooseIntlPhoneNumber, {
    hook: 'validate',
    phoneNumberField: 'phoneNumber',
    nationalFormatField: 'nationalFormat',
    internationalFormat: 'internationalFormat',
    countryCodeField: 'countryCode',
});

Use it with a model...

var Customer = mongoose.model('Customer');

var customer = new Customer({
    firstName: 'test',
    lastName: 'customer',
    customerType: 'testing',
    phoneNumber: '+18888675309',
    email: 'test@testing.com'
});

customer.save();

Resulting document...

{
    "firstName": "test",
    "lastName": "customer",
    "customerType": "testing",
    "phoneNumber": "+18888675309",
    "nationalFormat": "(888) 867-5309",
    "internationalFormat": "+1 888-867-5309"
    "countryCode": "US"
}

mongooseIntlPhoneNumber~mongooseIntlPhoneNumber(schema, [options])

Attaches the mongoose document hook and parses the phone number that is provided.

Kind: inner method of mongooseIntlPhoneNumber

ParamTypeDefaultDescription
schemaobjectMongoose schema
[options]object
[options.hook]string"validate"
[options.phoneNumberField]string"phoneNumber"
[options.nationalFormatField]string"nationalFormat"
[options.internationalFormatField]string"internationalFormat"
[options.countryCodeField]string"countryCode"

Keywords

FAQs

Package last updated on 18 Dec 2017

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