Skip to content

Commit e5724f6

Browse files
authored
feat: support fully deno (#32)
* feat: support fully deno * fix
1 parent 8402bc3 commit e5724f6

File tree

15 files changed

+1956
-6
lines changed

15 files changed

+1956
-6
lines changed

deno.jsonc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
],
66
*/
77
"lineWidth": 100,
8-
"exclude": ["node_modules", "dist", "**/*.md"],
8+
"exclude": ["node_modules", "dist", "**/*.md", "deno"],
99
"semiColons": false,
1010
"singleQuote": true
1111
},
@@ -14,7 +14,7 @@
1414
"include": [
1515
],
1616
*/
17-
"exclude": ["node_modules", "dist"]
17+
"exclude": ["node_modules", "dist", "deno"]
1818
/*
1919
"rules": {
2020
"tags": ["recommended"],

deno/LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2023 kazuya kawaguchi
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

deno/README.md

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
# @intilfy/utils
2+
3+
[![npm version][npm-version-src]][npm-version-href]
4+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
5+
[![CI][ci-src]][ci-href]
6+
7+
Collection of i18n utilities
8+
9+
## 🌟 Features
10+
11+
✅️  **Modern:** ES Modules first and respect Web Standard and ECMAScript
12+
Internationalization APIs
13+
14+
✅️  **Compatible:** support CommonJS and various JS environments
15+
16+
✅️️  **Minimal:** Small and fully tree-shakable
17+
18+
✅️️  **Type Strong:** Written in TypeScript, with full JSdoc
19+
20+
## 💿 Installation
21+
22+
### 🐢 Node.js
23+
24+
```sh
25+
# Using npm
26+
npm install @intlify/utils
27+
28+
# Using yarn
29+
yarn add @intlify/utils
30+
31+
# Using pnpm
32+
pnpm add @intlify/utils
33+
```
34+
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+
52+
### 🦕 Deno
53+
54+
You can install via `import`.
55+
56+
in your code:
57+
58+
```ts
59+
/**
60+
* you can install via other CDN URL such as skypack,
61+
* or, you can also use import maps
62+
* https://docs.deno.com/runtime/manual/basics/import_maps
63+
*/
64+
import { ... } from 'https://esm.sh/@intlify/utils'
65+
66+
// something todo
67+
// ...
68+
```
69+
70+
<details>
71+
<summary>Using Edge Releases</summary>
72+
73+
```ts
74+
import { ... } from 'https://esm.sh/@intlify/utils-edge'
75+
76+
// something todo
77+
// ...
78+
```
79+
80+
</details>
81+
82+
### 🥟 Bun
83+
84+
```sh
85+
bun install @intlify/utils
86+
```
87+
88+
### 🌍 Browser
89+
90+
in your HTML:
91+
92+
```html
93+
<script type="module">
94+
/**
95+
* you can install via other CDN URL such as skypack,
96+
* or, you can also use import maps
97+
*/
98+
import { isLocale } from 'https://esm.sh/@intlify/utils'
99+
100+
// something todo
101+
// ...
102+
</script>
103+
```
104+
105+
## 🍭 Playground
106+
107+
You can play the below examples:
108+
109+
- 🐢 [Node.js](https://github.com/intlify/utils/tree/main/examples/node):
110+
`npm run play:node`
111+
- 🦕 [Deno](https://github.com/intlify/utils/tree/main/examples/deno):
112+
`npm run play:deno`
113+
- 🥟 [Bun](https://github.com/intlify/utils/tree/main/examples/bun):
114+
`npm run play:bun`
115+
- 🌍 [Browser](https://github.com/intlify/utils/tree/main/examples/browser):
116+
`npm run play:browser`
117+
118+
## 🔨 Utilities
119+
120+
### Common
121+
122+
- `isLocale`
123+
- `toLocale`
124+
- `parseAcceptLanguage`
125+
- `validateLangTag`
126+
- `normalizeLanguageName`
127+
128+
You can do `import { ... } from '@intlify/utils'` the above utilities
129+
130+
### Navigator
131+
132+
- `getNavigatorLocales`
133+
- `getNavigatorLocale`
134+
135+
You can do `import { ... } from '@intlify/utils'` the above utilities
136+
137+
> ⚠NOTE: for Node.js You need to do `import { ... } from '@intlify/utils/node'`
138+
139+
### HTTP
140+
141+
- `getHeaderLanguages`
142+
- `getHeaderLanguage`
143+
- `getHeaderLocales`
144+
- `getHeaderLocale`
145+
- `getCookieLocale`
146+
- `setCookieLocale`
147+
- `getPathLocale`
148+
- `getQueryLocale`
149+
150+
The about utilies functions accpet 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)
151+
152+
#### Specialized environments
153+
154+
If you will use Node.js and H3, You can do `import { ... } from '@intlify/utils/{ENV}'` the above utilities.
155+
156+
The namespace `{ENV}` is one of the following:
157+
158+
- `node`: accpet `IncomingMessage` and `Outgoing` by Node.js [http](https://nodejs.org/api/http.html) module
159+
- `h3`: accept `H3Event` by HTTP framework [h3](https://github.com/unjs/h3)
160+
- `hono`: accept `Context` by edge-side web framework [hono](https://github.com/honojs/hono)
161+
162+
## 🙌 Contributing guidelines
163+
164+
If you are interested in contributing to `@intlify/utils`, I highly recommend checking out [the contributing guidelines](/CONTRIBUTING.md) here. You'll find all the relevant information such as [how to make a PR](/CONTRIBUTING.md#pull-request-guidelines), [how to setup development](/CONTRIBUTING.md#development-setup)) etc., there.
165+
166+
## ©️ License
167+
168+
[MIT](http://opensource.org/licenses/MIT)
169+
170+
<!-- Badges -->
171+
172+
[npm-version-src]: https://img.shields.io/npm/v/@intlify/utils?style=flat&colorA=18181B&colorB=FFAD33
173+
[npm-version-href]: https://npmjs.com/package/@intlify/utils
174+
[npm-downloads-src]: https://img.shields.io/npm/dm/@intlify/utils?style=flat&colorA=18181B&colorB=FFAD33
175+
[npm-downloads-href]: https://npmjs.com/package/@intlify/utils
176+
[ci-src]: https://github.com/intlify/utils/actions/workflows/ci.yml/badge.svg
177+
[ci-href]: https://github.com/intlify/utils/actions/workflows/ci.yml

deno/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const DEFAULT_LANG_TAG = 'en-US'
2+
export const DEFAULT_COOKIE_NAME = 'i18n_locale'
3+
export const ACCEPT_LANGUAGE_HEADER = 'accept-language'

0 commit comments

Comments
 (0)