npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@aleksejdix/ally-bcp47

v1.1.0

Published

TypeScript package for working with BCP-47 language tags

Readme

ally-bcp-47

npm version

A comprehensive TypeScript library for validating, parsing, and working with BCP-47 language tags according to RFC 5646.

Links

Features

  • Complete BCP-47 syntax validation - Validates against the full ABNF grammar
  • Detailed parsing - Breaks down language tags into their component subtags
  • Helpful error messages - Clear, actionable error reporting
  • No dependencies - Lightweight and focused
  • TypeScript-first - Full type definitions included

Installation

npm install @aleksejdix/ally-bcp47

Usage

Basic Validation

import { isValid, isWellFormed } from "@aleksejdix/ally-bcp47";

// Check if a tag is well-formed (syntax only)
isWellFormed("en-US"); // true
isWellFormed("en--US"); // false

// Check if a tag is valid (syntax + registry validation)
isValid("en-US"); // true
isValid("xy-ZZ"); // false (invalid subtags)

Detailed Validation

import { validateLanguageTag } from "@aleksejdix/ally-bcp47";

const result = validateLanguageTag("en-US");
console.log(result);
/* Output:
{
  isWellFormed: true,
  isValid: true,
  tag: {
    tag: "en-us",
    language: "en",
    region: "us"
  }
}
*/

const invalidResult = validateLanguageTag("en-a");
console.log(invalidResult);
/* Output:
{
  isWellFormed: false,
  isValid: false,
  errors: [{
    type: "invalid_extension",
    message: "Extension singleton a must be followed by at least one extension subtag",
    subtag: "a",
    subtagType: "extension",
    position: 3
  }]
}
*/

Parsing Tags

import { parseTag } from "@aleksejdix/ally-bcp47";

const tag = parseTag("zh-Hans-CN-x-private");
console.log(tag);
/* Output:
{
  tag: "zh-hans-cn-x-private",
  language: "zh",
  script: "hans",
  region: "cn",
  privateuse: ["private"]
}
*/

Validation Options

The validateLanguageTag function accepts options to customize the validation:

import { validateLanguageTag } from "@aleksejdix/ally-bcp47";

validateLanguageTag("en-US", {
  checkRegistry: true, // Whether to validate against the registry (default: true)
  warnOnDeprecated: true, // Whether to return warnings for deprecated subtags (default: true)
  warnOnRedundantScript: true, // Whether to warn about redundant scripts (default: true)
});

Tag Components

The library breaks down language tags into their component parts:

  • language - Primary language subtag (e.g., 'en', 'fr')
  • extlang - Extended language subtags (e.g., 'cmn')
  • script - Script subtag (e.g., 'Latn', 'Cyrl')
  • region - Region subtag (e.g., 'US', '001')
  • variants - Variant subtags (e.g., '1996')
  • extensions - Extension subtags (e.g., 'u-ca-gregory')
  • privateuse - Private use subtags (e.g., 'x-private')

Roadmap

  • [ ] Registry validation
  • [ ] Canonicalization
  • [ ] Registry update mechanism
  • [ ] More extensive validation options
  • [ ] Tag generation from components

European Accessibility Act Compliance

This library includes comprehensive testing for all European language tags to support compliance with the European Accessibility Act (Directive (EU) 2019/882).

Features for EAA Compliance

  • Validation of all 24 official EU language tags
  • Support for regional and minority language tags
  • Validation of accessibility-related extensions (number formatting, calendar systems, etc.)
  • Specific handling of common errors like country codes used as language codes (e.g., ch-DE)

Running European-specific Tests

# Test all European language tags
npm run test:european

# Test accessibility extensions
npm run test:accessibility

# Run the ch-DE specific test cases
npm run test:ch-de

# Demo of European language tag validation
npm run demo:european

For more details, see the European Accessibility Act Compliance Documentation.

Americans with Disabilities Act (ADA) Compliance

This library includes comprehensive testing for US language tags to support compliance with the Americans with Disabilities Act (ADA) requirements for web accessibility.

Features for ADA Compliance

  • Validation of US English and other common US language tags
  • Support for languages commonly spoken in the US
  • Validation of accessibility-related extensions (time formats, number systems, measurement units)
  • Private use extensions for screen readers and assistive technologies
  • Case normalization according to BCP-47 standards

Running ADA-specific Tests

# Test all ADA-related language tags
npm run test:ada

# Demo of ADA-related language tag validation
npm run demo:ada

For more details, see the Americans with Disabilities Act Compliance Documentation.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT