Skip to content

Commit 81c8f1f

Browse files
authored
fix: type errors (#66)
* fix: type errors * fix: typo
1 parent 4a24b30 commit 81c8f1f

File tree

10 files changed

+27
-114
lines changed

10 files changed

+27
-114
lines changed

deno/README.md

Lines changed: 5 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -32,47 +32,16 @@ yarn add @intlify/utils
3232
pnpm add @intlify/utils
3333
```
3434

35-
<details>
36-
<summary>Using Edge Releases</summary>
37-
38-
If you are directly using `@intlify/utils` as a dependency:
39-
40-
```json
41-
{
42-
"dependencies": {
43-
"@intlify/utils": "npm:@intlify/utils-edge@latest"
44-
}
45-
}
46-
```
47-
48-
**Note:** Make sure to recreate lockfile and `node_modules` after reinstall to avoid hoisting issues.
49-
50-
</details>
51-
5235
### 🦕 Deno
5336

54-
You can install via `import`.
55-
56-
in your code:
57-
58-
<!-- eslint-skip -->
59-
60-
```ts
61-
/**
62-
* you can install via other CDN URL such as skypack,
63-
* or, you can also use import maps
64-
* https://docs.deno.com/runtime/manual/basics/import_maps
65-
*/
66-
import { ... } from 'https://deno.land/x/intlify_utils/mod.ts'
67-
68-
// something todo
69-
// ...
37+
```sh
38+
deno add jsr:@intlify/utils
7039
```
7140

7241
### 🥟 Bun
7342

7443
```sh
75-
bun install @intlify/utils
44+
bun add @intlify/utils
7645
```
7746

7847
### 🌍 Browser
@@ -92,20 +61,6 @@ in your HTML:
9261
</script>
9362
```
9463

95-
<details>
96-
<summary>Using Edge Releases</summary>
97-
98-
<!-- eslint-skip -->
99-
100-
```ts
101-
import { isLocale } from 'https://esm.sh/@intlify/utils-edge'
102-
103-
// something todo
104-
// ...
105-
```
106-
107-
</details>
108-
10964
## 🍭 Playground
11065

11166
You can play the below examples:
@@ -119,59 +74,9 @@ You can play the below examples:
11974
- 🌍 [Browser](https://github.com/intlify/utils/tree/main/examples/browser):
12075
`npm run play:browser`
12176

122-
## 🔨 Utilities
123-
124-
### Common
125-
126-
- `isLocale`
127-
- `toLocale`
128-
- `parseAcceptLanguage`
129-
- `validateLangTag`
130-
- `normalizeLanguageName`
131-
132-
You can do `import { ... } from '@intlify/utils'` the above utilities
133-
134-
### Navigator
135-
136-
- `getNavigatorLocales`
137-
- `getNavigatorLocale`
138-
139-
You can do `import { ... } from '@intlify/utils'` the above utilities
140-
141-
<!-- eslint-disable markdown/no-missing-label-refs -->
142-
143-
> [!NOTE]
144-
> for Node.js You need to do `import { ... } from '@intlify/utils/node'`
145-
146-
<!-- eslint-enable markdown/no-missing-label-refs -->
147-
148-
### HTTP
149-
150-
- `getHeaderLanguages`
151-
- `getHeaderLanguage`
152-
- `getHeaderLocales`
153-
- `getHeaderLocale`
154-
- `getCookieLocale`
155-
- `setCookieLocale`
156-
- `getPathLocale`
157-
- `getQueryLocale`
158-
- `tryHeaderLocales`
159-
- `tryHeaderLocale`
160-
- `tryCookieLocale`
161-
- `tryPathLocale`
162-
- `tryQueryLocale`
163-
164-
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)
165-
166-
#### Specialized environments
167-
168-
If you will use Node.js and H3, You can do `import { ... } from '@intlify/utils/{ENV}'` the above utilities.
169-
170-
The namespace `{ENV}` is one of the following:
77+
## 🤝 API
17178

172-
- `node`: accept `IncomingMessage` and `Outgoing` by Node.js [http](https://nodejs.org/api/http.html) module
173-
- `h3`: accept `H3Event` by HTTP framework [h3](https://github.com/unjs/h3)
174-
- `hono`: accept `Context` by edge-side web framework [hono](https://github.com/honojs/hono)
79+
See the [API docs](./docs/index.md)
17580

17681
## 🙌 Contributing guidelines
17782

deno/http.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616

1717
import type { PathLanguageParser } from './shared.ts'
1818
// import type { CookieSerializeOptions } from 'cookie-es'
19-
// NOTE: This is a copy of the type definition from `cookie-es` package, we want to avoid building error for this type definition ...
19+
// NOTE(kazupon): This is a copy of the type definition from `cookie-es` package, we want to avoid building error for this type definition ...
2020

2121
interface CookieSerializeOptions {
2222
/**
@@ -219,9 +219,9 @@ export function validateLocale(locale: string | Intl.Locale): void {
219219
*
220220
* @returns The array of {@linkcode Intl.Locale} objects
221221
*/
222-
export function mapToLocaleFromLanguageTag(
223-
getter: (...args: unknown[]) => string[],
224-
...args: unknown[]
222+
export function mapToLocaleFromLanguageTag<T extends unknown[]>(
223+
getter: (...args: T) => string[],
224+
...args: T
225225
): Intl.Locale[] {
226226
return Reflect.apply(getter, null, args).map(lang => getLocaleWithGetter(() => lang))
227227
}

deno/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
/**
2+
* `@intlify/utils` default module entry.
3+
*
4+
* `@inlityf/utils` will export javascript runtime agnostic utility functions and types.
5+
*
6+
* @example
7+
* ```ts
8+
* import { parseAcceptLanguage, isLocale, getHeaderLocale } from '@intlify/utils'
9+
* ```
10+
*
11+
* @module default
12+
*/
13+
114
/**
215
* @author kazuya kawaguchi (a.k.a. kazupon)
316
* @license MIT

deno/web.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ export function getHeaderLanguage(request: Request, options: HeaderOptions = {})
113113
* @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.
114114
*/
115115
export function getHeaderLocales(request: Request, options: HeaderOptions = {}): Intl.Locale[] {
116-
// @ts-expect-error -- FIXME: this type error needs to be fixed
117116
return mapToLocaleFromLanguageTag(getHeaderLanguages, request, options)
118117
}
119118

src/h3.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ export function getHeaderLanguage(event: H3Event, options: HeaderOptions = {}):
125125
* @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.
126126
*/
127127
export function getHeaderLocales(event: H3Event, options: HeaderOptions = {}): Intl.Locale[] {
128-
// @ts-expect-error -- FIXME: this type error needs to be fixed
129128
return mapToLocaleFromLanguageTag(getHeaderLanguages, event, options)
130129
}
131130

src/hono.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ export function getHeaderLanguage(context: Context, options: HeaderOptions = {})
118118
* @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.
119119
*/
120120
export function getHeaderLocales(context: Context, options: HeaderOptions = {}): Intl.Locale[] {
121-
// @ts-expect-error -- FIXME: this type error needs to be fixed
122121
return mapToLocaleFromLanguageTag(getHeaderLanguages, context, options)
123122
}
124123

src/http.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616

1717
import type { PathLanguageParser } from './shared.ts'
1818
// import type { CookieSerializeOptions } from 'cookie-es'
19-
// NOTE: This is a copy of the type definition from `cookie-es` package, we want to avoid building error for this type definition ...
19+
// NOTE(kazupon): This is a copy of the type definition from `cookie-es` package, we want to avoid building error for this type definition ...
2020

2121
interface CookieSerializeOptions {
2222
/**
@@ -219,9 +219,9 @@ export function validateLocale(locale: string | Intl.Locale): void {
219219
*
220220
* @returns The array of {@linkcode Intl.Locale} objects
221221
*/
222-
export function mapToLocaleFromLanguageTag(
223-
getter: (...args: unknown[]) => string[],
224-
...args: unknown[]
222+
export function mapToLocaleFromLanguageTag<T extends unknown[]>(
223+
getter: (...args: T) => string[],
224+
...args: T
225225
): Intl.Locale[] {
226226
return Reflect.apply(getter, null, args).map(lang => getLocaleWithGetter(() => lang))
227227
}

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* `@intlify/utils` default module entry.
33
*
4-
* `@inlityf/utils` will export javascript runtime agnostic utility functions and types.
4+
* `@intlify/utils` will export javascript runtime agnostic utility functions and types.
55
*
66
* @example
77
* ```ts

src/node.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ export function getHeaderLocales(
132132
request: IncomingMessage,
133133
options: HeaderOptions = {}
134134
): Intl.Locale[] {
135-
// @ts-expect-error -- FIXME: this type error needs to be fixed
136135
return mapToLocaleFromLanguageTag(getHeaderLanguages, request, options)
137136
}
138137

src/web.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ export function getHeaderLanguage(request: Request, options: HeaderOptions = {})
113113
* @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.
114114
*/
115115
export function getHeaderLocales(request: Request, options: HeaderOptions = {}): Intl.Locale[] {
116-
// @ts-expect-error -- FIXME: this type error needs to be fixed
117116
return mapToLocaleFromLanguageTag(getHeaderLanguages, request, options)
118117
}
119118

0 commit comments

Comments
 (0)