acc-lang-parser
raw JSON → 1.0.4 verified Sat Apr 25 auth: no javascript maintenance
A simple parser for HTTP Accept-Language headers in Node.js. Version 1.0.4 (last released in 2016) extracts the first language or all language ranges from a header string. Returns objects with 'language' and 'locale' fields. Unlike more modern alternatives like 'accept-language-parser', this package has limited features, no TypeScript support, and is unmaintained. It was originally published under the npm name 'parse-acc-lang' (now deprecated) and later republished as 'acc-lang-parser'.
Common errors
error Error: Cannot find module 'parse-acc-lang' ↓
cause Using require('acc-lang-parser') instead of require('parse-acc-lang').
fix
Use require('parse-acc-lang') in your code, even though the npm package name is 'acc-lang-parser'.
error TypeError: parser.extractFirstLang is not a function ↓
cause Incorrect import path or using a different package version.
fix
Ensure you require('parse-acc-lang') and that the module exports the correct functions.
error Expected an object but got undefined ↓
cause Input header is null, undefined, or an empty string.
fix
Pass a valid Accept-Language header string. For null/undefined, manually handle or return a default.
Warnings
breaking Package name mismatch: npm package is 'acc-lang-parser' but require path uses 'parse-acc-lang'. ↓
fix Use require('parse-acc-lang') in code, not require('acc-lang-parser').
deprecated No TypeScript definitions available. ↓
fix Create your own .d.ts file or use a modern alternative with TypeScript support.
gotcha If extracted language tag has no locale (e.g., 'fr'), the locale field is an empty string ''. ↓
fix Check for empty locale string before use.
gotcha Quality values (q=) are ignored; the parser does not sort by weight. ↓
fix Use a more complete parser like 'accept-language-parser' if you need quality weighting.
Install
npm install acc-lang-parser yarn add acc-lang-parser pnpm add acc-lang-parser Imports
- parse-acc-lang wrong
import parser from 'parse-acc-lang';correctconst parser = require('parse-acc-lang'); - extractFirstLang
const result = parser.extractFirstLang('de-DE'); - extractAllLangs wrong
const results = parser.extractAllLangs('de-DE, en-GB', { strict: true });correctconst results = parser.extractAllLangs('de-DE, en-GB');
Quickstart
const parser = require('parse-acc-lang');
const header = 'de-DE, en-GB;q=0.9, fr;q=0.8';
const first = parser.extractFirstLang(header);
console.log(first); // { language: 'de', locale: 'DE' }
const all = parser.extractAllLangs(header);
console.log(all);
// [
// { language: 'de', locale: 'DE' },
// { language: 'en', locale: 'GB' },
// { language: 'fr', locale: '' }
// ]