1.0.1 • Published 5 years ago

persian-mongoose v1.0.1

Weekly downloads
1
License
ISC
Repository
github
Last release
5 years ago

persian-mongoose

persian localization and validation for mongoose schemas

for persian validation we use persianize as validators.

Installation

npm install persian-mongoose

Persian Validation

A set of validation for persian and Iran usages

FunctionDescription
isMobilecheck if string is following iran's mobile number formats
isCardNumbercheck if string is a real iran bank card number
isPhonecheck if string is iran's phone number format
isPostalCodecheck if string following iran's postal code's format
isShebacheck if string is real sheba number
isMelliCodecheck if string is real melli code

Example :

var mySchema = new mongoose.Schema({
    phone_number : {
      type : String,
      validate: [
        { validator: persianMongoose.isMobile, msg: 'phone number is incorrect'}
      ]
    }
});

Convertors

removeArabicChars

This converts arabic alphabet characters to persian characters

Example (convert arabic chars to persian) :

//Input : فارسي   -> Ouput : فارسی

Schema.plugin(persianMongoose.removeArabicChars,
{
    removeArabicChars:
    {
        fields : ['name']
    }
});

Complete Usage

var mySchema = new mongoose.Schema({
    name: {type: String}
});

mySchema.plugin(persianMongoose.removeArabicChars,
{
    removeArabicChars:
    {
        fields : ['name']
    }
});

var myModel = mongoose.model('myModel', mySchema);

var newName = new myModel({ name : 'علي' });

newName.save(function (err) {

  if (err)
    console.log(err)

  // saved!
});
// will save { name : 'علی' }