Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

subtag

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

subtag

Language tag parser

  • 0.5.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
152K
increased by1.38%
Maintainers
1
Weekly downloads
 
Created
Source

subtag

Language tag parser. Parse language tags into subtags.

api

  • subtag(tag) parse tag into subtags object
  • subtag.split(tag) split tag into subtags array
  • subtag.language(tag) get primary language subtag
  • subtag.extlang(tag) get extended language subtag
  • subtag.script(tag) get script subtag
  • subtag.region(tag) get region subtag

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') // {language: 'ja', extlang: '', script: '', region: 'JP'}
subtag('es-AR') // {language: 'es', extlang: '', script: '', region: 'AR'}
arrays
subtag.split('yue') // ["yue"]
subtag.split('es-419') // ["es", "419"]
subtag.split('zh-Hant-HK') // ["zh", "Hant", "HK"]
subtag.split('en-90210') // ["en"] because 90210 is fake
subtags
subtag.language('en') // 'en'
subtag.extlang('en') // ''
subtag.script('en') // ''
subtag.region('en') // ''

subtag.language('en-US') // 'en'
subtag.extlang('en-US') // ''
subtag.script('en-US') // ''
subtag.region('en-US') // 'US'

subtag.language('zh-yue') // 'zh'
subtag.extlang('zh-yue') // 'yue'
subtag.script('zh-yue') // ''
subtag.region('zh-yue') // ''

subtag.language('zh-Hans') // 'zh'
subtag.extlang('zh-Hans') // ''
subtag.script('zh-Hans') // 'Hans'
subtag.region('zh-Hans') // ''

structure

language-extlang-script-region-variant-extension-privateuse

typepatternconvention
language2-letter or 3-letterlowercase
extlang3-letterlowercase
script4-lettertitlecase
region2-letter or 3-numberuppercase

.pattern

Regex patterns are exposed for validation

subtag.language.pattern.test('en') // true
subtag.language.pattern.test('ast') // true
subtag.language.pattern.test('fake') // false
subtag.extlang.pattern.test('yue') // true
subtag.script.pattern.test('Hans') // true
subtag.region.pattern.test('US') // true
subtag.region.pattern.test('005') // true
subtag.region.pattern.test('90210') // false

compatibility

Works in Node.js and ES5+ browsers

Keywords

FAQs

Package last updated on 30 Jul 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc