joi-phone-number
Advanced tools
Comparing version 3.0.0 to 3.0.1
@@ -73,2 +73,12 @@ 'use strict'; | ||
it('validates and formats without a country', () => { | ||
const joi = Joi.extend(JoiPhoneNumber); | ||
const schema = joi.string().phoneNumber({ | ||
format: 'e164' | ||
}); | ||
expect(schema.validate('32494322456').error).toBeInstanceOf(Error); | ||
expect(schema.validate('+32494322456').error).toBeNull(); | ||
}); | ||
it('should take multiple countries', () => { | ||
@@ -75,0 +85,0 @@ const joi = Joi.extend(JoiPhoneNumber); |
@@ -44,4 +44,12 @@ 'use strict'; | ||
} catch (err) { | ||
const knownErrors = ['Invalid country calling code', 'The string supplied did not seem to be a phone number']; | ||
// We ignore the next line for line coverage since we should always hit it but if we have a regression in our code we still want to surface that instead of just returning the default error | ||
/* istanbul ignore next */ | ||
if (knownErrors.includes(err.message)) { | ||
// Generate an error, state and options need to be passed | ||
return this.createError('string.phonenumber', {value}, state, options); | ||
return this.createError('string.phonenumber', {value}, state, options); | ||
} | ||
/* istanbul ignore next */ | ||
throw err; | ||
} | ||
@@ -60,3 +68,3 @@ } | ||
*/ | ||
internals.parse = (value, [...countries]) => { | ||
internals.parse = (value, [...countries] = []) => { | ||
const country = countries.shift(); | ||
@@ -63,0 +71,0 @@ try { |
{ | ||
"name": "joi-phone-number", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "Phone number validation rule for Joi", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/Salesflare/joi-phone-number", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10346
156