The `subtag` library, currently at version 0.5.0 (last updated March 2017), provides a lightweight utility for parsing BCP 47 language tags (e.g., `en-US`, `zh-Hant-HK`) into their constituent components like language, extended language, script, and region. It offers methods to parse a tag into a structured object, an array of subtags, or extract individual subtags directly. The parsing logic is implemented using regular expressions, making it efficient for common use cases but it does not perform comprehensive validation against the full IANA language subtag registry. This package differentiates itself through its simplicity and focused parsing capabilities. It supports both Node.js and ES5+ browsers, though its unmaintained status means it may not be suitable for modern applications requiring full BCP 47 compliance or active support.
npm install subtagVerified import paths — ran on the pinned version, not inferred.
Demonstrates parsing various BCP 47 language tags into structured objects, arrays of subtags, extracting specific components, and using the exposed regex patterns for validation.
For production applications or any new development, it is strongly recommended to use an actively maintained BCP 47 language tag parser library (e.g., `language-tags`, `negotiator`, or browser's `Intl.Locale` if supported) to ensure up-to-date standards compliance, security, and ongoing support.
For strict BCP 47 validation, including handling of complex subtag sequences (variants, extensions, privateuse), and robust checking against the official IANA registry, utilize a library specifically designed for such rigorous compliance.
If access to all components of a BCP 47 tag (including variants, extensions, and privateuse) is required, use `subtag.split(tag)` to get an array of all subtags, and then manually process the remaining parts beyond the primary components.
Ensure you are using `import subtag from 'subtag'` for ES Modules or `const subtag = require('subtag')` for CommonJS environments. If using TypeScript, verify that `esModuleInterop` is enabled in your `tsconfig.json` if you are mixing import styles.The library is primarily a basic parser. For applications requiring strict validation against the BCP 47 standard and comprehensive handling of all subtag types (including privateuse, extensions, and valid but uncommon region codes), consider a more robust and actively maintained internationalization library.
No dependency data recorded yet.