Collection of i18n utilities
✅️ undefinedModern: ES Modules first and respect Web Standard and ECMAScript
Internationalization APIs
✅️ undefinedCompatible: support CommonJS and various JS environments
✅️️ undefinedMinimal: Small and fully tree-shakable
✅️️ undefinedType Strong: Written in TypeScript, with full JSdoc
# Using npm
npm install @intlify/utils
# Using yarn
yarn add @intlify/utils
# Using pnpm
pnpm add @intlify/utils
If you are directly using @intlify/utils as a dependency:
{
"dependencies": {
"@intlify/utils": "npm:@intlify/utils-edge@latest"
}
}
undefinedNote: Make sure to recreate lockfile and node_modules after reinstall to avoid hoisting issues.
You can install via import.
in your code:
/**
* you can install via other CDN URL such as skypack,
* or, you can also use import maps
* https://docs.deno.com/runtime/manual/basics/import_maps
*/
import { ... } from 'https://deno.land/x/intlify_utils/mod.ts'
// something todo
// ...
bun install @intlify/utils
in your HTML:
<script type="module">
/**
* you can install via other CDN URL such as skypack,
* or, you can also use import maps
*/
import { isLocale } from 'https://esm.sh/@intlify/utils'
// something todo
// ...
</script>
import { isLocale } from 'https://esm.sh/@intlify/utils-edge'
// something todo
// ...
You can play the below examples:
npm run play:nodenpm run play:denonpm run play:bunnpm run play:browserisLocaletoLocaleparseAcceptLanguagevalidateLangTagnormalizeLanguageNameYou can do import { ... } from '@intlify/utils' the above utilities
getNavigatorLocalesgetNavigatorLocaleYou can do import { ... } from '@intlify/utils' the above utilities
[!NOTE]
for Node.js You need to doimport { ... } from '@intlify/utils/node'
getHeaderLanguagesgetHeaderLanguagegetHeaderLocalesgetHeaderLocalegetCookieLocalesetCookieLocalegetPathLocalegetQueryLocaletryHeaderLocalestryHeaderLocaletryCookieLocaletryPathLocaletryQueryLocaleThe about utilies functions accpet Web APIs such as Request and Response that is supported by JS environments (such as Deno, Bun, and Browser)
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 moduleh3: accept H3Event by HTTP framework h3hono: accept Context by edge-side web framework honoIf 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.