joi-bcp47 - Joi BCP47 IETF Language Tag Validation
![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Ftjdavey%2Fjoi-bcp47.svg?type=shield)
Provides a Joi rule to validate and parse BCP47 language tags (eg. en-US
, ur-PK
, zh-Hant-TW
).
Note: Only supports Joi 16.x or higher. Does not validate the components of the BCP47 tag (eg. language or region codes), only the structure and syntax.
Installation:
npm: npm install joi-bcp47
yarn: yarn add joi-bcp47
Usage
import BaseJoi from 'joi';
import JoiBcp47 from 'joi-bcp47';
const Joi = BaseJoi.extend(JoiBcp47);
Joi.bcp47().validate('en-US');
Rules
parse
- Parse the BCP47 tag into an object
When added to the validation chain returns a bcp47 parse object which parses the BCP47 tag out to its individual components.
Joi.bcp47().parse().validate('hy-Latn-IT-arevela');
Compatibility
This library is tested for compatibility, and contains peer dependencies with the following versions.
Version | @hapi/joi 16.x | joi 16.x | joi 17.x |
---|
1.1.0 | | ✅ | ✅ |
1.0.0 | ✅ | | |
License
![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Ftjdavey%2Fjoi-bcp47.svg?type=large)