Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

lconv

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lconv

lconv is a tiny JavaScript module for converting between ISO 639 language codes, as well as ISO code resolution.

latest
npmnpm
Version
0.0.9
Version published
Weekly downloads
85
-7.61%
Maintainers
1
Weekly downloads
 
Created
Source

lconv

lconv is a tiny JavaScript module for converting between ISO 639 language codes, as well as ISO code resolution.

Say, for example, you're looking up the Cantonese Language code yue, which only exists as an ISO 639-3 language code. Therefore, requesting the ISO 639-1 code for Cantonese would return null. However, Cantonese belongs to the Chinese macro-language, which does have an ISO 639-1 code. If we resolve the Cantonese language code to Chinese, then we'll get zh back instead of null.

Pretty neat, eh?

Using the API

To use lconv is extremely simple. Use it like this:

import { convert } from 'lconv';

convert('English', { from: 'label', to: 2 }); // ==> eng
convert('eng', { from: 3, to: 1 }); // 
convert('yue', { from: 3, to: 1, resolve: true }); // ==> zh

You can also retrieve language objects directly based on a string, optionally and explicitly specifying the format you're using:

import { getLanguage } from 'lconv';

getLanguage('English');
getLanguage("en", 1);

This will return all language codes and a human-readable language name, as well as language type and status.

convert takes three options:

  • from: The ISO code of the given string. Can be either 1, 2, 3, or "label". If it is not provided it will be guessed.
  • to: The ISO code to convert to. Can be either 1, 2, 3, or "label". If it is not provided it will be guessed.
  • resolve: Boolean denoting whether to resolve language codes or not. By default this is set to "false".

Generating Data

If you do for some reason clone this repo, to generate the JSON data file needed for the module to run, just run:

$ pnpm run import

FAQs

Package last updated on 13 Apr 2025

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