@pixul/joi-country
Advanced tools
Comparing version 0.0.1 to 1.0.0
@@ -9,16 +9,24 @@ 'use strict'; | ||
base: joi.string(), | ||
type: 'country', | ||
type: 'string', | ||
messages: { | ||
'country.base': '{{#label}} needs to be a valid ISO 3166-1 alpha-2 country code' | ||
'country.invalid': '{{#label}} needs to be a valid ISO 3166-1 alpha-2 country code' | ||
}, | ||
validate: (value, helpers) => { | ||
rules: { | ||
country: { | ||
method(options) { | ||
if (Countries.isValid(value)) { | ||
return this.$_addRule('country'); | ||
}, | ||
validate(value, helpers) { | ||
return { value: value.toUpperCase() }; | ||
if (Countries.isValid(value)) { | ||
return value.toUpperCase(); | ||
} | ||
return helpers.error('country.invalid'); | ||
} | ||
} | ||
return { value, errors: helpers.error('country.base') }; | ||
} | ||
}; | ||
}; |
{ | ||
"name": "@pixul/joi-country", | ||
"version": "0.0.1", | ||
"version": "1.0.0", | ||
"description": "ISO Country extension for Joi", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -20,3 +20,3 @@ 'use strict'; | ||
const customJoi = Joi.extend(JoiCountry); | ||
expect(customJoi._types.has('country')).to.equal(true); | ||
expect(customJoi.string().country).to.be.a.function(); | ||
} | ||
@@ -32,3 +32,3 @@ catch (err) { | ||
const customJoi = Joi.extend(JoiCountry); | ||
const schema = customJoi.country(); | ||
const schema = customJoi.string().country(); | ||
const result = await schema.validateAsync('GB'); | ||
@@ -41,3 +41,3 @@ expect(result).to.equal('GB'); | ||
const customJoi = Joi.extend(JoiCountry); | ||
const schema = customJoi.country(); | ||
const schema = customJoi.string().country(); | ||
const result = await schema.validateAsync('de'); | ||
@@ -50,3 +50,3 @@ expect(result).to.equal('DE'); | ||
const customJoi = Joi.extend(JoiCountry); | ||
const schema = customJoi.country(); | ||
const schema = customJoi.string().country(); | ||
await expect(schema.validateAsync('Denmark')).to.reject(ValidationError, '"value" needs to be a valid ISO 3166-1 alpha-2 country code'); | ||
@@ -58,4 +58,4 @@ }); | ||
const customJoi = Joi.extend(JoiCountry); | ||
const schema = customJoi.country(); | ||
const schema = customJoi.string().country(); | ||
await expect(schema.validateAsync(123)).to.reject(ValidationError, '"value" must be a string'); | ||
}); |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
4732
94
0