Skip to content

Commit 15e6ea9

Browse files
committed
chore: add knip
1 parent ede96a7 commit 15e6ea9

File tree

22 files changed

+2415
-4233
lines changed

22 files changed

+2415
-4233
lines changed

.gitignore

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ node_modules
33
coverage
44
.DS_Store
55
.idea
6-
playground/**/bun.lockb
7-
playground/**/deno.lock
6+
.eslintcache
87

98
*.log
109
*.swp
1110
*.tgz
1211
*.zip
1312
*~
14-
.env
13+
.env

deno/README.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ You can install via `import`.
5555

5656
in your code:
5757

58+
<!-- eslint-skip -->
59+
5860
```ts
5961
/**
6062
* you can install via other CDN URL such as skypack,
@@ -79,20 +81,22 @@ in your HTML:
7981

8082
```html
8183
<script type="module">
82-
/**
83-
* you can install via other CDN URL such as skypack,
84-
* or, you can also use import maps
85-
*/
86-
import { isLocale } from 'https://esm.sh/@intlify/utils'
87-
88-
// something todo
89-
// ...
84+
/**
85+
* you can install via other CDN URL such as skypack,
86+
* or, you can also use import maps
87+
*/
88+
import { isLocale } from 'https://esm.sh/@intlify/utils'
89+
90+
// something todo
91+
// ...
9092
</script>
9193
```
9294

9395
<details>
9496
<summary>Using Edge Releases</summary>
9597

98+
<!-- eslint-skip -->
99+
96100
```ts
97101
import { isLocale } from 'https://esm.sh/@intlify/utils-edge'
98102

@@ -134,9 +138,13 @@ You can do `import { ... } from '@intlify/utils'` the above utilities
134138

135139
You can do `import { ... } from '@intlify/utils'` the above utilities
136140

141+
<!-- eslint-disable markdown/no-missing-label-refs -->
142+
137143
> [!NOTE]
138144
> for Node.js You need to do `import { ... } from '@intlify/utils/node'`
139145
146+
<!-- eslint-enable markdown/no-missing-label-refs -->
147+
140148
### HTTP
141149

142150
- `getHeaderLanguages`

deno/constants.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* @author kazuya kawaguchi (a.k.a. kazupon)
3+
* @license MIT
4+
*/
5+
16
export const DEFAULT_LANG_TAG = 'en-US'
27
export const DEFAULT_COOKIE_NAME = 'i18n_locale'
38
export const ACCEPT_LANGUAGE_HEADER = 'accept-language'

deno/http.ts

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1+
/**
2+
* @author kazuya kawaguchi (a.k.a. kazupon)
3+
* @license MIT
4+
*/
5+
6+
import { ACCEPT_LANGUAGE_HEADER, DEFAULT_LANG_TAG } from './constants.ts'
17
import {
28
isLocale,
39
isURL,
410
isURLSearchParams,
511
parseAcceptLanguage,
612
pathLanguageParser,
713
toLocale,
8-
validateLangTag,
14+
validateLangTag
915
} from './shared.ts'
10-
import { ACCEPT_LANGUAGE_HEADER, DEFAULT_LANG_TAG } from './constants.ts'
1116

1217
import type { PathLanguageParser } from './shared.ts'
1318
// import type { CookieSerializeOptions } from 'cookie-es'
@@ -123,15 +128,14 @@ export function parseDefaultHeader(input: string): string[] {
123128

124129
export function getHeaderLanguagesWithGetter(
125130
getter: () => string | null | undefined,
126-
{
127-
name = ACCEPT_LANGUAGE_HEADER,
128-
parser = parseDefaultHeader,
129-
}: HeaderOptions = {},
131+
{ name = ACCEPT_LANGUAGE_HEADER, parser = parseDefaultHeader }: HeaderOptions = {}
130132
): string[] {
131133
const langString = getter()
132134
return langString
133135
? name === ACCEPT_LANGUAGE_HEADER
134-
? parser === parseDefaultHeader ? parseAcceptLanguage(langString) : parser(langString)
136+
? parser === parseDefaultHeader
137+
? parseAcceptLanguage(langString)
138+
: parser(langString)
135139
: parser(langString)
136140
: []
137141
}
@@ -141,34 +145,25 @@ export function getLocaleWithGetter(getter: () => string): Intl.Locale {
141145
}
142146

143147
export function validateLocale(locale: string | Intl.Locale): void {
144-
if (
145-
!(isLocale(locale) ||
146-
typeof locale === 'string' && validateLangTag(locale))
147-
) {
148+
if (!(isLocale(locale) || (typeof locale === 'string' && validateLangTag(locale)))) {
148149
throw new SyntaxError(`locale is invalid: ${locale.toString()}`)
149150
}
150151
}
151152

152153
export function mapToLocaleFromLanguageTag(
153-
// deno-lint-ignore no-explicit-any
154-
getter: (...args: any[]) => string[],
154+
getter: (...args: unknown[]) => string[],
155155
...args: unknown[]
156156
): Intl.Locale[] {
157-
return (Reflect.apply(getter, null, args) as string[]).map((lang) =>
158-
getLocaleWithGetter(() => lang)
159-
)
157+
return Reflect.apply(getter, null, args).map(lang => getLocaleWithGetter(() => lang))
160158
}
161159

162-
export function getExistCookies(
163-
name: string,
164-
getter: () => unknown,
165-
) {
160+
export function getExistCookies(name: string, getter: () => unknown) {
166161
let setCookies = getter()
167162
if (!Array.isArray(setCookies)) {
168163
setCookies = [setCookies]
169164
}
170-
setCookies = (setCookies as string[]).filter((cookieValue: string) =>
171-
cookieValue && !cookieValue.startsWith(name + '=')
165+
setCookies = (setCookies as string[]).filter(
166+
(cookieValue: string) => cookieValue && !cookieValue.startsWith(name + '=')
172167
)
173168
return setCookies as string[]
174169
}
@@ -189,7 +184,7 @@ export type PathOptions = {
189184
*/
190185
export function getPathLanguage(
191186
path: string | URL,
192-
{ lang = DEFAULT_LANG_TAG, parser = pathLanguageParser }: PathOptions = {},
187+
{ lang = DEFAULT_LANG_TAG, parser = pathLanguageParser }: PathOptions = {}
193188
): string {
194189
return (parser || pathLanguageParser)(path) || lang
195190
}
@@ -207,14 +202,12 @@ export function getPathLanguage(
207202
*/
208203
export function getPathLocale(
209204
path: string | URL,
210-
{ lang = DEFAULT_LANG_TAG, parser = pathLanguageParser }: PathOptions = {},
205+
{ lang = DEFAULT_LANG_TAG, parser = pathLanguageParser }: PathOptions = {}
211206
): Intl.Locale {
212207
return new Intl.Locale(getPathLanguage(path, { lang, parser }))
213208
}
214209

215-
function getURLSearchParams(
216-
input: string | URL | URLSearchParams,
217-
): URLSearchParams {
210+
function getURLSearchParams(input: string | URL | URLSearchParams): URLSearchParams {
218211
if (isURLSearchParams(input)) {
219212
return input
220213
} else if (isURL(input)) {
@@ -240,7 +233,7 @@ export type QueryOptions = {
240233
*/
241234
export function getQueryLanguage(
242235
query: string | URL | URLSearchParams,
243-
{ lang = DEFAULT_LANG_TAG, name = 'lang' }: QueryOptions = {},
236+
{ lang = DEFAULT_LANG_TAG, name = 'lang' }: QueryOptions = {}
244237
): string {
245238
const queryParams = getURLSearchParams(query)
246239
return queryParams.get(name) || lang
@@ -259,7 +252,7 @@ export function getQueryLanguage(
259252
*/
260253
export function getQueryLocale(
261254
query: string | URL | URLSearchParams,
262-
{ lang = DEFAULT_LANG_TAG, name = 'locale' }: QueryOptions = {},
255+
{ lang = DEFAULT_LANG_TAG, name = 'locale' }: QueryOptions = {}
263256
): Intl.Locale {
264257
return new Intl.Locale(getQueryLanguage(query, { lang, name }))
265258
}

deno/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
/**
2+
* @author kazuya kawaguchi (a.k.a. kazupon)
3+
* @license MIT
4+
*/
5+
16
export {
27
createPathIndexLanguageParser,
38
isLocale,
49
normalizeLanguageName,
510
parseAcceptLanguage,
611
registerPathLanguageParser,
7-
validateLangTag,
12+
validateLangTag
813
} from './shared.ts'
914
export * from './web.ts'

0 commit comments

Comments
 (0)