{"id":21019338,"url":"https://github.com/rmraya/typesbcp47","last_synced_at":"2025-05-15T07:32:53.339Z","repository":{"id":208896829,"uuid":"722269430","full_name":"rmraya/TypesBCP47","owner":"rmraya","description":"TypeScript library for language tags from BCP47","archived":false,"fork":false,"pushed_at":"2025-03-02T19:20:36.000Z","size":537,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-18T08:40:57.105Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"epl-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rmraya.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-22T19:28:57.000Z","updated_at":"2025-03-02T19:20:40.000Z","dependencies_parsed_at":"2024-06-02T12:38:00.331Z","dependency_job_id":"e6361567-c91a-4c7e-a8c4-156e9ef31f5d","html_url":"https://github.com/rmraya/TypesBCP47","commit_stats":null,"previous_names":["rmraya/typesbcp47"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rmraya%2FTypesBCP47","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rmraya%2FTypesBCP47/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rmraya%2FTypesBCP47/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rmraya%2FTypesBCP47/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rmraya","download_url":"https://codeload.github.com/rmraya/TypesBCP47/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254296392,"owners_count":22047258,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-19T10:31:14.235Z","updated_at":"2025-05-15T07:32:52.922Z","avatar_url":"https://github.com/rmraya.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TypesBCP47\n\nTypeScript library for language tags from [BCP47](https://www.ietf.org/rfc/bcp/bcp47.html)\n\n## Installation\n\n```sh\nnpm install typesbcp47\n```\n\nClass `LanguageUtils` provides static methods for parsing and validating language tags from BCP47.\n\nMethod | Description\n--- | ---\n`getTagDescription(tag: string): string` | Returns a language description for the tag if the tag is a valid language tag. Returns `undefined` otherwise.\n`normalizeCode(code: string): string` | Returns a normalized code if the code is valid.\n`isCJK(code: string): boolean` | Returns `true` if the language is Chinese, Japanese, Korean, Vietnamese or Aiunu. Returns `false` otherwise.\n`isBiDi(code: string): boolean` | Returns `true` if the language is written from right to left (Arabic, Hebrew, Persian, Urdu), `false` otherwise.\n`getLanguages(locale: string): Array\u003cLanguage\u003e` |  Returns an array of `Language` objects with descriptions in the selected `locale`.\n`getLanguage(code: string, locale: string): Language` | Returns a `Language` object by its code with descriptions in the selected `locale` if the code is valid. Returns `undefined` otherwise.\n`getCommonLanguages(locale: string): Array\u003cLanguage\u003e` | Returns an array of most common `Language` objects with descriptions in the selected `locale`.\n\nValid values for `locale` parameter are `en` and `es`.\n\nYou can combine these methods to validate language tags:\n\n```ts\nimport { LanguageUtils } from 'typesbcp47';\n\nconst tag = 'en-US';\nconst description = LanguageUtils.getTagDescription(tag);\n\nif (description) {\n  console.log(`Language tag ${tag} is valid. Description: ${description}`);\n} else {\n  console.log(`Language tag ${tag} is invalid.`);\n}\n\n// a common problem with language tags is wrong casing for the code\n// this can be fixed by normalizing the code\n\nconst normalizedCode = LanguageUtils.normalizeCode(tag);\n\nif (normalizedCode) {\n    // language exists\n    if (tag === normalizedCode) {\n        // language tag is OK\n        console.log(`Language tag ${tag} is valid.`);\n    } else {\n        // language tag is not normalized\n        console.log(`Language code is incorrect, it should be ${normalizedCode}`)\n    }\n} else {\n  console.log(`Code ${tag} is invalid.`);\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frmraya%2Ftypesbcp47","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frmraya%2Ftypesbcp47","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frmraya%2Ftypesbcp47/lists"}