Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/iso639_1/mod.ts>isLanguageCode

Type-safe ISO 639-1 language code (a.k.a. two-letter codes) for TypeScript
Latest
function isLanguageCode
import { isLanguageCode } from "https://deno.land/x/iso639_1@1.2.20090901/mod.ts";

A predicate function to narrow down the string type to the LanguageCode type if the given string is a valid language code.

const code: string | null = prompt("Enter a two-letter language code:");
if (isLanguageCode(code)) {
  // code is now narrowed down to LanguageCode
  console.log("The language you chose is", authoritativeLabels[code].en);
}

Parameters

code: string | null | undefined

The string expected to be a language code.

Returns

code is LanguageCode

true if the given string is a valid language code, false.