@intilfy/utils

Collection of i18n utilities
🌟 Features
✅️ Modern: ES Modules first and respect Web Standard and ECMAScript
Internationalization APIs
✅️ Compatible: support CommonJS and various JS environments
✅️️ Minimal: Small and fully tree-shakable
✅️️ Type Strong: Written in TypeScript, with full JSdoc
💿 Installation
🐢 Node.js
npm install @intlify/utils
yarn add @intlify/utils
pnpm add @intlify/utils
Using Edge Releases
If you are directly using @intlify/utils as a dependency:
{
"dependencies": {
"@intlify/utils": "npm:@intlify/utils-edge@latest"
}
}
Note: Make sure to recreate lockfile and node_modules after reinstall to avoid hoisting issues.
🦕 Deno
You can install via import.
in your code:
import { ... } from 'https://deno.land/x/intlify_utils/mod.ts'
🥟 Bun
bun install @intlify/utils
🌍 Browser
in your HTML:
<script type="module">
import { isLocale } from 'https://esm.sh/@intlify/utils'
</script>
Using Edge Releases
import { isLocale } from 'https://esm.sh/@intlify/utils-edge'
🍭 Playground
You can play the below examples:
- 🐢 Node.js:
npm run play:node
- 🦕 Deno:
npm run play:deno
- 🥟 Bun:
npm run play:bun
- 🌍 Browser:
npm run play:browser
🔨 Utilities
Common
isLocale
toLocale
parseAcceptLanguage
validateLangTag
normalizeLanguageName
You can do import { ... } from '@intlify/utils' the above utilities
Navigator
getNavigatorLocales
getNavigatorLocale
You can do import { ... } from '@intlify/utils' the above utilities
⚠NOTE: for Node.js You need to do import { ... } from '@intlify/utils/node'
HTTP
getHeaderLanguages
getHeaderLanguage
getHeaderLocales
getHeaderLocale
getCookieLocale
setCookieLocale
getPathLocale
getQueryLocale
tryHeaderLocales
tryHeaderLocale
tryCookieLocale
tryPathLocale
tryQueryLocale
The about utilies functions accpet Web APIs such as Request and Response that is supported by JS environments (such as Deno, Bun, and Browser)
Specialized environments
If you will use Node.js and H3, You can do import { ... } from '@intlify/utils/{ENV}' the above utilities.
The namespace {ENV} is one of the following:
node: accpet IncomingMessage and Outgoing by Node.js http module
h3: accept H3Event by HTTP framework h3
hono: accept Context by edge-side web framework hono
🙌 Contributing guidelines
If you are interested in contributing to @intlify/utils, I highly recommend checking out the contributing guidelines here. You'll find all the relevant information such as how to make a PR, how to setup development) etc., there.
©️ License
MIT