medhira-jst-functions
v0.1.1
Published
JavaScript/TypeScript utility functions for locale and language handling - Powered by MEDHIRA
Maintainers
Readme
Features
| | |
|---|---|
| Locale lookup | Resolve BCP-47 style codes such as en-us or en-US |
| Language search | Find locales by language name with substring or exact matching |
| Complete dataset | 828 locale entries with language, location, tag, and LCID id |
| TypeScript ready | Exported types and isLocale() type guard |
| Zero dependencies | Lightweight runtime with no external packages |
| Immutable API | Public helpers never expose mutable internal state |
Architecture
flowchart LR
A[Your App] --> B[getLocaleByCode]
A --> C[getLocaleList]
A --> D[getLocaleByLanguage]
B --> E[(Locale Dataset)]
C --> E
D --> E
B --> F[LocaleInterface | null]
C --> G[LocaleKeyInterface copy]
D --> H[LocaleInterface array]Installation
npm install medhira-jst-functionsyarn add medhira-jst-functionspnpm add medhira-jst-functionsnpx expo install medhira-jst-functionsQuick Start
import {
getLocaleByCode,
getLocaleList,
getLocaleByLanguage,
isLocale,
} from 'medhira-jst-functions';
const locale = getLocaleByCode('en-US');
if (isLocale(locale)) {
console.log(`${locale.language} (${locale.location})`);
// English (United States)
}
console.log(Object.keys(getLocaleList()).length);
// 828
console.log(getLocaleByLanguage('Spanish', { exact: true }).length);
// 28API
| Function | Description | Returns |
|---|---|---|
| getLocaleByCode(code) | Lookup by locale code, case-insensitive | LocaleInterface \| null |
| getLocaleList() | Get all locales as a safe copy | LocaleKeyInterface |
| getLocaleByLanguage(word, options?) | Search by language name | LocaleInterface[] |
| isLocale(value) | Type guard for nullable lookup results | boolean |
Full reference: Documentation
Use Cases
User language selection
import { getLocaleByCode, isLocale } from 'medhira-jst-functions';
const userLang = navigator.language ?? 'en-US';
const locale = getLocaleByCode(userLang);
if (isLocale(locale)) {
console.log(`Selected: ${locale.language} (${locale.location})`);
}Language dropdown
import { getLocaleList } from 'medhira-jst-functions';
const options = Object.entries(getLocaleList()).map(([code, info]) => ({
value: code,
label: info.location ? `${info.language} (${info.location})` : info.language,
}));Documentation
Development
npm install
npm test
npm run lint
npm run build
npm run validate:localesContributing
Contributions are welcome. Please open an issue or pull request on GitHub.
Sponsor & Support
To keep this library maintained and up-to-date, please consider sponsoring it on GitHub.
For private support or customization help, contact [email protected].
About MEDHIRA
MEDHIRA — Engineering Intelligence Across Everything
- Website: medhira.readthedocs.io
- GitHub: HELLOMEDHIRA
- Email: [email protected]
License
Apache-2.0 — see LICENSE.
Made with passion by MEDHIRA
