Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support fully deno #32

Merged
merged 2 commits into from
Oct 23, 2023
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
4 changes: 2 additions & 2 deletions deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
],
*/
"lineWidth": 100,
"exclude": ["node_modules", "dist", "**/*.md"],
"exclude": ["node_modules", "dist", "**/*.md", "deno"],
"semiColons": false,
"singleQuote": true
},
Expand All @@ -14,7 +14,7 @@
"include": [
],
*/
"exclude": ["node_modules", "dist"]
"exclude": ["node_modules", "dist", "deno"]
/*
"rules": {
"tags": ["recommended"],
Expand Down
20 changes: 20 additions & 0 deletions deno/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) 2023 kazuya kawaguchi

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
177 changes: 177 additions & 0 deletions deno/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
# @intilfy/utils

[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![CI][ci-src]][ci-href]

Collection of i18n utilities

## 🌟 Features

✅️  **Modern:** ES Modules first and respect Web Standard and ECMAScript
Internationalization APIs

✅️  **Compatible:** support CommonJS and various JS environments

✅️️  **Minimal:** Small and fully tree-shakable

✅️️  **Type Strong:** Written in TypeScript, with full JSdoc

## 💿 Installation

### 🐢 Node.js

```sh
# Using npm
npm install @intlify/utils

# Using yarn
yarn add @intlify/utils

# Using pnpm
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:

```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://esm.sh/@intlify/utils'

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

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

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

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

</details>

### 🥟 Bun

```sh
bun install @intlify/utils
```

### 🌍 Browser

in your HTML:

```html
<script type="module">
/**
* you can install via other CDN URL such as skypack,
* or, you can also use import maps
*/
import { isLocale } from 'https://esm.sh/@intlify/utils'

// something todo
// ...
</script>
```

## 🍭 Playground

You can play the below examples:

- 🐢 [Node.js](https://github.com/intlify/utils/tree/main/examples/node):
`npm run play:node`
- 🦕 [Deno](https://github.com/intlify/utils/tree/main/examples/deno):
`npm run play:deno`
- 🥟 [Bun](https://github.com/intlify/utils/tree/main/examples/bun):
`npm run play:bun`
- 🌍 [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`

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)

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

- `node`: accpet `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)

## 🙌 Contributing guidelines

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.

## ©️ License

[MIT](http://opensource.org/licenses/MIT)

<!-- Badges -->

[npm-version-src]: https://img.shields.io/npm/v/@intlify/utils?style=flat&colorA=18181B&colorB=FFAD33
[npm-version-href]: https://npmjs.com/package/@intlify/utils
[npm-downloads-src]: https://img.shields.io/npm/dm/@intlify/utils?style=flat&colorA=18181B&colorB=FFAD33
[npm-downloads-href]: https://npmjs.com/package/@intlify/utils
[ci-src]: https://github.com/intlify/utils/actions/workflows/ci.yml/badge.svg
[ci-href]: https://github.com/intlify/utils/actions/workflows/ci.yml
3 changes: 3 additions & 0 deletions deno/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const DEFAULT_LANG_TAG = 'en-US'
export const DEFAULT_COOKIE_NAME = 'i18n_locale'
export const ACCEPT_LANGUAGE_HEADER = 'accept-language'
Loading