UNPKG

bcp47-validate

Version:

Simple validator for BCP47 locale tags

18 lines (16 loc) 956 B
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.validate = validate; var pattern = exports.pattern = /^(?:(en-GB-oed|i-ami|i-bnn|i-default|i-enochian|i-hak|i-klingon|i-lux|i-mingo|i-navajo|i-pwn|i-tao|i-tay|i-tsu|sgn-BE-FR|sgn-BE-NL|sgn-CH-DE)|(art-lojban|cel-gaulish|no-bok|no-nyn|zh-guoyu|zh-hakka|zh-min|zh-min-nan|zh-xiang))$|^((?:[a-z]{2,3}(?:(?:-[a-z]{3}){1,3})?)|[a-z]{4}|[a-z]{5,8})(?:-([a-z]{4}))?(?:-([a-z]{2}|\d{3}))?((?:-(?:[\da-z]{5,8}|\d[\da-z]{3}))*)?((?:-[\da-wy-z](?:-[\da-z]{2,8})+)*)?(-x(?:-[\da-z]{1,8})+)?$|^(x(?:-[\da-z]{1,8})+)$/i; // eslint-disable-line max-len /** * Validate a locale string to test if it is bcp47 compliant * @param {String} locale The tag locale to parse * @return {Boolean} True if tag is bcp47 compliant false otherwise */ function validate(locale) { if (typeof locale !== 'string') return false; return pattern.test(locale); } //# sourceMappingURL=index.js.map