subtag
Language tag parser. Parse language tags into subtags.
api
notes
- parsing is done via regex
- unpresent subtags will be an empty string
- separator can be dashes (standard) or underscores
setup
install via npm or yarn
npm install subtag --save
yarn add subtag
usage
require
usage
var subtag = require('subtag')
import
usage
import subtag from 'subtag'
examples
objects
subtag('ja-JP')
subtag('es-AR')
arrays
subtag.split('yue')
subtag.split('es-419')
subtag.split('zh-Hant-HK')
subtag.split('en-90210')
subtags
subtag.language('en')
subtag.extlang('en')
subtag.script('en')
subtag.region('en')
subtag.language('en-US')
subtag.extlang('en-US')
subtag.script('en-US')
subtag.region('en-US')
subtag.language('zh-yue')
subtag.extlang('zh-yue')
subtag.script('zh-yue')
subtag.region('zh-yue')
subtag.language('zh-Hans')
subtag.extlang('zh-Hans')
subtag.script('zh-Hans')
subtag.region('zh-Hans')
structure
language-extlang-script-region-variant-extension-privateuse
type | pattern | convention |
---|
language | 2-letter or 3-letter | lowercase |
extlang | 3-letter | lowercase |
script | 4-letter | titlecase |
region | 2-letter or 3-number | uppercase |
.pattern
Regex patterns are exposed for validation
subtag.language.pattern.test('en')
subtag.language.pattern.test('ast')
subtag.language.pattern.test('fake')
subtag.extlang.pattern.test('yue')
subtag.script.pattern.test('Hans')
subtag.region.pattern.test('US')
subtag.region.pattern.test('005')
subtag.region.pattern.test('90210')
compatibility
Works in Node.js and ES5+ browsers