diff --git a/deno/README.md b/deno/README.md index 0b5018b..f2ed1f1 100644 --- a/deno/README.md +++ b/deno/README.md @@ -32,47 +32,16 @@ yarn add @intlify/utils pnpm add @intlify/utils ``` -
- Using Edge Releases - -If you are directly using `@intlify/utils` as a dependency: - -```json -{ - "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: - - - -```ts -/** - * 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 -// ... +```sh +deno add jsr:@intlify/utils ``` ### 🥟 Bun ```sh -bun install @intlify/utils +bun add @intlify/utils ``` ### 🌍 Browser @@ -92,20 +61,6 @@ in your HTML: ``` -
- Using Edge Releases - - - -```ts -import { isLocale } from 'https://esm.sh/@intlify/utils-edge' - -// something todo -// ... -``` - -
- ## 🍭 Playground You can play the below examples: @@ -119,59 +74,9 @@ You can play the below examples: - 🌍 [Browser](https://github.com/intlify/utils/tree/main/examples/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 utilities functions accept Web APIs such as [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) and [Response](https://developer.mozilla.org/en-US/docs/Web/API/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: +## 🤝 API -- `node`: accept `IncomingMessage` and `Outgoing` by Node.js [http](https://nodejs.org/api/http.html) module -- `h3`: accept `H3Event` by HTTP framework [h3](https://github.com/unjs/h3) -- `hono`: accept `Context` by edge-side web framework [hono](https://github.com/honojs/hono) +See the [API docs](./docs/index.md) ## 🙌 Contributing guidelines diff --git a/deno/http.ts b/deno/http.ts index 5a66fc0..38f2a6a 100644 --- a/deno/http.ts +++ b/deno/http.ts @@ -16,7 +16,7 @@ import { import type { PathLanguageParser } from './shared.ts' // import type { CookieSerializeOptions } from 'cookie-es' -// NOTE: This is a copy of the type definition from `cookie-es` package, we want to avoid building error for this type definition ... +// NOTE(kazupon): This is a copy of the type definition from `cookie-es` package, we want to avoid building error for this type definition ... interface CookieSerializeOptions { /** @@ -219,9 +219,9 @@ export function validateLocale(locale: string | Intl.Locale): void { * * @returns The array of {@linkcode Intl.Locale} objects */ -export function mapToLocaleFromLanguageTag( - getter: (...args: unknown[]) => string[], - ...args: unknown[] +export function mapToLocaleFromLanguageTag( + getter: (...args: T) => string[], + ...args: T ): Intl.Locale[] { return Reflect.apply(getter, null, args).map(lang => getLocaleWithGetter(() => lang)) } diff --git a/deno/index.ts b/deno/index.ts index 480f30e..9cffa59 100644 --- a/deno/index.ts +++ b/deno/index.ts @@ -1,3 +1,16 @@ +/** + * `@intlify/utils` default module entry. + * + * `@inlityf/utils` will export javascript runtime agnostic utility functions and types. + * + * @example + * ```ts + * import { parseAcceptLanguage, isLocale, getHeaderLocale } from '@intlify/utils' + * ``` + * + * @module default + */ + /** * @author kazuya kawaguchi (a.k.a. kazupon) * @license MIT diff --git a/deno/web.ts b/deno/web.ts index 7bb8363..0a96a99 100644 --- a/deno/web.ts +++ b/deno/web.ts @@ -113,7 +113,6 @@ export function getHeaderLanguage(request: Request, options: HeaderOptions = {}) * @returns The locales that wrapped from header, if you use `accept-language` header and `*` (any language) or empty string is detected, return an empty array. */ export function getHeaderLocales(request: Request, options: HeaderOptions = {}): Intl.Locale[] { - // @ts-expect-error -- FIXME: this type error needs to be fixed return mapToLocaleFromLanguageTag(getHeaderLanguages, request, options) } diff --git a/src/h3.ts b/src/h3.ts index 85b8c7b..7790fc4 100644 --- a/src/h3.ts +++ b/src/h3.ts @@ -125,7 +125,6 @@ export function getHeaderLanguage(event: H3Event, options: HeaderOptions = {}): * @returns The locales that wrapped from header, if you use `accept-language` header and `*` (any language) or empty string is detected, return an empty array. */ export function getHeaderLocales(event: H3Event, options: HeaderOptions = {}): Intl.Locale[] { - // @ts-expect-error -- FIXME: this type error needs to be fixed return mapToLocaleFromLanguageTag(getHeaderLanguages, event, options) } diff --git a/src/hono.ts b/src/hono.ts index 55f3ecb..7957bac 100644 --- a/src/hono.ts +++ b/src/hono.ts @@ -118,7 +118,6 @@ export function getHeaderLanguage(context: Context, options: HeaderOptions = {}) * @returns Some locales that wrapped from header, if you use `accept-language` header and `*` (any language) or empty string is detected, return an empty array. */ export function getHeaderLocales(context: Context, options: HeaderOptions = {}): Intl.Locale[] { - // @ts-expect-error -- FIXME: this type error needs to be fixed return mapToLocaleFromLanguageTag(getHeaderLanguages, context, options) } diff --git a/src/http.ts b/src/http.ts index 5a66fc0..38f2a6a 100644 --- a/src/http.ts +++ b/src/http.ts @@ -16,7 +16,7 @@ import { import type { PathLanguageParser } from './shared.ts' // import type { CookieSerializeOptions } from 'cookie-es' -// NOTE: This is a copy of the type definition from `cookie-es` package, we want to avoid building error for this type definition ... +// NOTE(kazupon): This is a copy of the type definition from `cookie-es` package, we want to avoid building error for this type definition ... interface CookieSerializeOptions { /** @@ -219,9 +219,9 @@ export function validateLocale(locale: string | Intl.Locale): void { * * @returns The array of {@linkcode Intl.Locale} objects */ -export function mapToLocaleFromLanguageTag( - getter: (...args: unknown[]) => string[], - ...args: unknown[] +export function mapToLocaleFromLanguageTag( + getter: (...args: T) => string[], + ...args: T ): Intl.Locale[] { return Reflect.apply(getter, null, args).map(lang => getLocaleWithGetter(() => lang)) } diff --git a/src/index.ts b/src/index.ts index 9cffa59..46a4b34 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,7 @@ /** * `@intlify/utils` default module entry. * - * `@inlityf/utils` will export javascript runtime agnostic utility functions and types. + * `@intlify/utils` will export javascript runtime agnostic utility functions and types. * * @example * ```ts diff --git a/src/node.ts b/src/node.ts index c26565d..8486226 100644 --- a/src/node.ts +++ b/src/node.ts @@ -132,7 +132,6 @@ export function getHeaderLocales( request: IncomingMessage, options: HeaderOptions = {} ): Intl.Locale[] { - // @ts-expect-error -- FIXME: this type error needs to be fixed return mapToLocaleFromLanguageTag(getHeaderLanguages, request, options) } diff --git a/src/web.ts b/src/web.ts index 2f356a5..bbdd906 100644 --- a/src/web.ts +++ b/src/web.ts @@ -113,7 +113,6 @@ export function getHeaderLanguage(request: Request, options: HeaderOptions = {}) * @returns The locales that wrapped from header, if you use `accept-language` header and `*` (any language) or empty string is detected, return an empty array. */ export function getHeaderLocales(request: Request, options: HeaderOptions = {}): Intl.Locale[] { - // @ts-expect-error -- FIXME: this type error needs to be fixed return mapToLocaleFromLanguageTag(getHeaderLanguages, request, options) }