Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 5 additions & 100 deletions deno/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,47 +32,16 @@ yarn add @intlify/utils
pnpm add @intlify/utils
```

<details>
<summary>Using Edge Releases</summary>

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.

</details>

### 🦕 Deno

You can install via `import`.

in your code:

<!-- eslint-skip -->

```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
Expand All @@ -92,20 +61,6 @@ in your HTML:
</script>
```

<details>
<summary>Using Edge Releases</summary>

<!-- eslint-skip -->

```ts
import { isLocale } from 'https://esm.sh/@intlify/utils-edge'

// something todo
// ...
```

</details>

## 🍭 Playground

You can play the below examples:
Expand All @@ -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

<!-- eslint-disable markdown/no-missing-label-refs -->

> [!NOTE]
> for Node.js You need to do `import { ... } from '@intlify/utils/node'`

<!-- eslint-enable markdown/no-missing-label-refs -->

### 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

Expand Down
8 changes: 4 additions & 4 deletions deno/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -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<T extends unknown[]>(
getter: (...args: T) => string[],
...args: T
): Intl.Locale[] {
return Reflect.apply(getter, null, args).map(lang => getLocaleWithGetter(() => lang))
}
Expand Down
13 changes: 13 additions & 0 deletions deno/index.ts
Original file line number Diff line number Diff line change
@@ -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
*/
Comment on lines +1 to +12
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix typo in module name.

Line 4 contains a typo: @inlityf/utils should be @intlify/utils.

Apply this diff:

-/**
- * `@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
- */
+/**
+ * `@intlify/utils` default module entry.
+ *
+ * `@intlify/utils` will export javascript runtime agnostic utility functions and types.
+ *
+ * @example
+ * ```ts
+ * import { parseAcceptLanguage, isLocale, getHeaderLocale } from '@intlify/utils'
+ * ```
+ *
+ * @module default
+ */
🤖 Prompt for AI Agents
In deno/index.ts around lines 1 to 12, there's a typo in the module description:
replace the incorrect `@inlityf/utils` with the correct `@intlify/utils`
everywhere in the block comment (including the example and description) so the
module name is consistent and accurate; update the comment text accordingly and
ensure no other spelling mistakes remain in that header block.


/**
* @author kazuya kawaguchi (a.k.a. kazupon)
* @license MIT
Expand Down
1 change: 0 additions & 1 deletion deno/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
1 change: 0 additions & 1 deletion src/h3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
1 change: 0 additions & 1 deletion src/hono.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
8 changes: 4 additions & 4 deletions src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -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<T extends unknown[]>(
getter: (...args: T) => string[],
...args: T
): Intl.Locale[] {
return Reflect.apply(getter, null, args).map(lang => getLocaleWithGetter(() => lang))
}
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion src/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
1 change: 0 additions & 1 deletion src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Loading