Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dahlia/iso639-1
Type-safe ISO 639-1 language code (a.k.a. two-letter codes) for TypeScript
https://github.com/dahlia/iso639-1
deno iso639-1 language-codes typescript
Last synced: 20 days ago
JSON representation
Type-safe ISO 639-1 language code (a.k.a. two-letter codes) for TypeScript
- Host: GitHub
- URL: https://github.com/dahlia/iso639-1
- Owner: dahlia
- License: mit
- Created: 2023-09-13T07:42:54.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-09-19T13:15:09.000Z (about 1 year ago)
- Last Synced: 2024-10-04T16:36:44.638Z (about 1 month ago)
- Topics: deno, iso639-1, language-codes, typescript
- Language: TypeScript
- Homepage: https://deno.land/x/iso639_1
- Size: 58.6 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Type-safe [ISO 639-1] language code for TypeScript
==================================================[![deno.land/x/iso639_1][Deno module badge]][Deno module]
[![MIT License][License badge]](./LICENSE)
[![GitHub Actions][GitHub Actions badge]][GitHub Actions]
[![Codecov][Codecov badge]][Codecov]This library provides a set of functions to work with [ISO 639-1] language
codes, a.k.a. two-letter language codes, in very type-safe way.Although it does not introduce any new runtime types, it provides
the [`LanguageCode`] type, which is a narrowed-down version of
the `string` type that contains only valid two-letter language codes
defined in the ISO 639-1.There are three ways to narrow down the `string` type to the
[`LanguageCode`] type: [`isLanguageCode`], [`parseLanguageCode`],
and [`validateLanguageCode`]. The following example shows how to narrow
down a string value to the [`LanguageCode`] type:~~~~ typescript
import {
authoritativeLabels,
isLanguageCode,
} from "https://deno.land/x/iso639_1/mod.ts";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);
} else {
console.error("Invalid language code:", code);
}
~~~~For details, see the [API references].
[Deno module badge]: https://shield.deno.dev/x/iso639_1
[Deno module]: https://deno.land/x/iso639_1
[License badge]: https://img.shields.io/github/license/dahlia/iso639-1
[GitHub Actions badge]: https://github.com/dahlia/iso639-1/actions/workflows/test.yaml/badge.svg
[GitHub Actions]: https://github.com/dahlia/iso639-1/actions/workflows/test.yaml
[Codecov badge]: https://codecov.io/gh/dahlia/iso639-1/graph/badge.svg
[Codecov]: https://codecov.io/gh/dahlia/iso639-1
[ISO 639-1]: https://id.loc.gov/vocabulary/iso639-1.html
[`LanguageCode`]: https://deno.land/x/iso639_1/mod.ts?s=LanguageCode
[`isLanguageCode`]: https://deno.land/x/iso639_1/mod.ts?s=isLanguageCode
[`parseLanguageCode`]: https://deno.land/x/iso639_1/mod.ts?s=parseLanguageCode
[`validateLanguageCode`]: https://deno.land/x/iso639_1/mod.ts?s=validateLanguageCode
[API references]: https://deno.land/x/iso639_1/mod.ts