1.1.1 • Published 6 years ago

mongoose-intl-phone-number v1.1.1

Weekly downloads
130
License
Apache-2.0
Repository
github
Last release
6 years ago

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
optionsobject
options.hookstring"validate"
options.phoneNumberFieldstring"phoneNumber"
options.nationalFormatFieldstring"nationalFormat"
options.internationalFormatFieldstring"internationalFormat"
options.countryCodeFieldstring"countryCode"
1.1.1

6 years ago

1.1.0

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.4.4

8 years ago

0.4.3

8 years ago

0.4.2

8 years ago

0.4.1

8 years ago

0.4.0

8 years ago

0.3.1

9 years ago

0.3.0

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago