Skip to content

Commit

Permalink
v0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
yunbookf committed May 15, 2023
1 parent aebba19 commit 2633247
Show file tree
Hide file tree
Showing 18 changed files with 9,149 additions and 133 deletions.
5 changes: 3 additions & 2 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/.git/
/.vscode/
/dist/test*
/dist/test-*
/dist/update*
/node_modules/
/sources/test-node.ts
/sources/source.json
/sources/test-*
/sources/update.ts
/test/
/.gitignore
Expand Down
72 changes: 33 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
# LiteRT/Mime
# mime.js

[![npm version](https://img.shields.io/npm/v/@litert/mime.svg?colorB=brightgreen)](https://www.npmjs.com/package/@litert/mime "Stable Version")
[![npm version](https://img.shields.io/npm/v/@litert/mime/dev.svg)](https://www.npmjs.com/package/@litert/mime "Development Version")
[![License](https://img.shields.io/github/license/litert/mime.js.svg)](https://github.com/litert/mime.js/blob/master/LICENSE)
[![node](https://img.shields.io/node/v/@litert/mime.svg?colorB=brightgreen)](https://nodejs.org/dist/latest-v10.x/)
[![GitHub issues](https://img.shields.io/github/issues/litert/mime.js.svg)](https://github.com/litert/mime.js/issues)
[![GitHub Releases](https://img.shields.io/github/release/litert/mime.js.svg)](https://github.com/litert/mime.js/releases "Stable Release")
[![GitHub Pre-Releases](https://img.shields.io/github/release/litert/mime.js/all.svg)](https://github.com/litert/mime.js/releases "Pre-Release")
<p align="center">
<a href="https://github.com/litert/mime.js/blob/master/LICENSE">
<img alt="License" src="https://img.shields.io/github/license/litert/mime.js?color=blue" />
</a>
<a href="https://www.npmjs.com/package/@litert/mime">
<img alt="NPM stable version" src="https://img.shields.io/npm/v/@litert/mime?color=brightgreen&logo=npm" />
</a><br>
<a href="https://github.com/litert/mime.js/releases">
<img alt="GitHub releases" src="https://img.shields.io/github/v/release/litert/mime.js?color=brightgreen&logo=github" />
</a>
<a href="https://github.com/litert/mime.js/issues">
<img alt="GitHub issues" src="https://img.shields.io/github/issues/litert/mime.js?color=blue&logo=github" />
</a>
</p>

Get MIME type based on file name.
Get MIME type based on file name, path, and extension.

> This repository doesn't require frequent updates, so even if it hasn't been updated for a long time, as long as it still exists, it means it's available. We'll keep an eye on whether it can function properly in the latest Node and browser environments.
## Languages

[简体中文](doc/README.sc.md) | [繁體中文](doc/README.tc.md) | [日本語](doc/README.ja.md)

## Installation

Expand All @@ -20,31 +33,12 @@ In the Node.js environment, you can install directly using NPM:
$ npm i @litert/mime --save
```

Or install the developing (unstable) version for newest features:

```sh
$ npm i @litert/mime@dev --save
```

### CDN

If you must use it on browser, please use CDN:

Recommended: https://cdn.jsdelivr.net/npm/@litert/mime@0.1.0/dist/index.min.js, which will reflect the latest version as soon as it is published to npm. You can also browse the source of the npm package at https://cdn.jsdelivr.net/npm/@litert/mime/.

Also available on [unpkg](https://unpkg.com/@litert/mime@0.1.0/dist/index.js).

In the example, the mime.js library is loaded using the loader.js library:
If you're using it in a browser, you can utilize the CDN mode.

```html
<script src="https://cdn.jsdelivr.net/npm/@litert/loader@0.1.1/dist/index.min.js"></script>
<script>
loader.ready(function() {
loader.require("https://cdn.jsdelivr.net/npm/@litert/mime@0.1.0/dist/index.min", function(mime) {
alert(mime.getMime("root/index.css"));
});
});
</script>
<script src="https://cdn.jsdelivr.net/npm/@litert/loader@3.5.0/dist/loader.min.js?path=index&npm={'@litert/mime':'0.1.2'}"></script>
```

## Usage
Expand All @@ -54,26 +48,26 @@ Demo code is written using TypeScript.
```typescript
import * as mime from "@litert/mime";

mime.getData("hello.json"); // {"mime": "application/json", "compressible": true}
mime.getData(".html"); // {"mime": "text/html", "compressible": true}
mime.getData("css"); // {"mime": "text/css", "compressible": true}
mime.getData("hi/baby.js"); // {"mime": "application/javascript", "compressible": true}
mime.getData("/root/down/pk.zip"); // {"mime": "application/zip", "compressible": false}
mime.getData("ext.dodooh"); // {"mime": "application/octet-stream", "compressible": false}
mime.getData("hello.json"); // {"mime": "application/json", "compressible": true, extension: 'json'}
mime.getData(".html"); // {"mime": "text/html", "compressible": true, extension: 'html'}
mime.getData("css"); // {"mime": "text/css", "compressible": true, extension: 'css'}
mime.getData("hi/baby.js"); // {"mime": "application/javascript", "compressible": true, extension: 'js'}
mime.getData("/root/down/pk.zip"); // {"mime": "application/zip", "compressible": false, extension: 'zip'}
mime.getData("ext.dodooh"); // {"mime": "application/octet-stream", "compressible": false, extension: 'dodooh'}
mime.getMime("root/index.css"); // text/css
```

## Test

### Node

After compiling the TS code, execute: node dist/test-node to observe the execution results of the test code under node.
Once it's compiled correctly, you can run the sample code in the terminal by using node ./dist/test-node.

### Browser

Use your browser to access "test/" to see if the results are consistent with the node environment.
To view the examples, simply access the `test/` directory in your browser.

[You can also click here to access the example online.](https://litert.github.io/mime.js/test/)
[Click here to view the examples online](https://litert.github.io/mime.js/test/)

## License

Expand Down
10 changes: 0 additions & 10 deletions dist/index.d.ts

This file was deleted.

16 changes: 8 additions & 8 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var mimeData = require("../mime.json");
exports.getMime = exports.getData = void 0;
let mimeData = require('../mime.json');
function getData(path) {
var lio = path.lastIndexOf(".");
var ext = (lio === -1 ? path : path.slice(lio + 1)).toLowerCase();
let lio = path.lastIndexOf('.');
let ext = (lio === -1 ? path : path.slice(lio + 1)).toLowerCase();
if (mimeData[ext]) {
mimeData[ext].extension = ext;
return mimeData[ext];
}
else {
return {
"mime": "application/octet-stream",
"compressible": false,
"extension": ext
'mime': "application/octet-stream",
'compressible': false,
'extension': ext
};
}
}
exports.getData = getData;
function getMime(path) {
return getData(path)["mime"];
return getData(path)['mime'];
}
exports.getMime = getMime;
//# sourceMappingURL=index.js.map
1 change: 0 additions & 1 deletion dist/index.js.map

This file was deleted.

70 changes: 70 additions & 0 deletions doc/README.ja.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# mime.js

<p align="center">
<a href="https://github.com/litert/mime.js/blob/master/LICENSE">
<img alt="License" src="https://img.shields.io/github/license/litert/mime.js?color=blue" />
</a>
<a href="https://www.npmjs.com/package/@litert/mime">
<img alt="NPM stable version" src="https://img.shields.io/npm/v/@litert/mime?color=brightgreen&logo=npm" />
</a><br>
<a href="https://github.com/litert/mime.js/releases">
<img alt="GitHub releases" src="https://img.shields.io/github/v/release/litert/mime.js?color=brightgreen&logo=github" />
</a>
<a href="https://github.com/litert/mime.js/issues">
<img alt="GitHub issues" src="https://img.shields.io/github/issues/litert/mime.js?color=blue&logo=github" />
</a>
</p>

ファイル名、パス、拡張子から mime タイプを取得します。

> このライブラリは頻繁に更新する必要がないため、長い間更新されていなくても、存在している限り使用可能です。私たちは常に最新の Node およびブラウザ環境で正常に動作するかどうかを確認しています。
## インストール

### NPM

次の npm コマンドを使用して直接インストールできます。

```sh
$ npm i @litert/mime --save
```

### CDN

ブラウザで使用する場合は、CDN モードを使用できます:

```html
<script src="https://cdn.jsdelivr.net/npm/@litert/loader@3.5.0/dist/loader.min.js?path=index&npm={'@litert/mime':'0.1.2'}"></script>
```

## 使用

デモコードは TypeScript で記述されています。

```typescript
import * as mime from "@litert/mime";

mime.getData("hello.json"); // {"mime": "application/json", "compressible": true, extension: 'json'}
mime.getData(".html"); // {"mime": "text/html", "compressible": true, extension: 'html'}
mime.getData("css"); // {"mime": "text/css", "compressible": true, extension: 'css'}
mime.getData("hi/baby.js"); // {"mime": "application/javascript", "compressible": true, extension: 'js'}
mime.getData("/root/down/pk.zip"); // {"mime": "application/zip", "compressible": false, extension: 'zip'}
mime.getData("ext.dodooh"); // {"mime": "application/octet-stream", "compressible": false, extension: 'dodooh'}
mime.getMime("root/index.css"); // text/css
```

## サンプル

### Node

コンパイル後に、ターミナルで `node ./dist/test-node` を使用してサンプルコードを実行できます。

### ブラウザ

`test/` ディレクトリにアクセスすると、サンプルを表示できます。

[ここをクリックしてオンラインでサンプルを表示](https://litert.github.io/mime.js/test/)

## ライセンス

このライブラリは [Apache-2.0](../LICENSE) ライセンスで提供されています。
70 changes: 70 additions & 0 deletions doc/README.sc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# mime.js

<p align="center">
<a href="https://github.com/litert/mime.js/blob/master/LICENSE">
<img alt="License" src="https://img.shields.io/github/license/litert/mime.js?color=blue" />
</a>
<a href="https://www.npmjs.com/package/@litert/mime">
<img alt="NPM stable version" src="https://img.shields.io/npm/v/@litert/mime?color=brightgreen&logo=npm" />
</a><br>
<a href="https://github.com/litert/mime.js/releases">
<img alt="GitHub releases" src="https://img.shields.io/github/v/release/litert/mime.js?color=brightgreen&logo=github" />
</a>
<a href="https://github.com/litert/mime.js/issues">
<img alt="GitHub issues" src="https://img.shields.io/github/issues/litert/mime.js?color=blue&logo=github" />
</a>
</p>

根据文件名、路径、扩展名获取 mime 类型。

> 本库不需要经常更新,因此即使很久没有更新,只要它依然存在,则表示他是可用的。我们会持续关注其是否可以正常运行在最新的 Node 和浏览器环境。
## 安装

### NPM

你可以直接通过 npm 命令进行安装。

```sh
$ npm i @litert/mime --save
```

### CDN

如果你在浏览器中使用,可以使用 CDN 模式:

```html
<script src="https://cdn.jsdelivr.net/npm/@litert/loader@3.5.0/dist/loader.min.js?path=index&npm={'@litert/mime':'0.1.2'}"></script>
```

## 使用

演示代码使用 Typescript 语言编写。

```typescript
import * as mime from "@litert/mime";

mime.getData("hello.json"); // {"mime": "application/json", "compressible": true, extension: 'json'}
mime.getData(".html"); // {"mime": "text/html", "compressible": true, extension: 'html'}
mime.getData("css"); // {"mime": "text/css", "compressible": true, extension: 'css'}
mime.getData("hi/baby.js"); // {"mime": "application/javascript", "compressible": true, extension: 'js'}
mime.getData("/root/down/pk.zip"); // {"mime": "application/zip", "compressible": false, extension: 'zip'}
mime.getData("ext.dodooh"); // {"mime": "application/octet-stream", "compressible": false, extension: 'dodooh'}
mime.getMime("root/index.css"); // text/css
```

## 示例

### Node

正确编译后,在终端中使用 `node ./dist/test-node` 就可以运行示例代码。

### 浏览器

在浏览器中访问 `test/` 目录即可查看示例。

[点击此处在线查看示例](https://litert.github.io/mime.js/test/)

## 许可

本库使用 [Apache-2.0](../LICENSE) 许可。
70 changes: 70 additions & 0 deletions doc/README.tc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# mime.js

<p align="center">
<a href="https://github.com/litert/mime.js/blob/master/LICENSE">
<img alt="License" src="https://img.shields.io/github/license/litert/mime.js?color=blue" />
</a>
<a href="https://www.npmjs.com/package/@litert/mime">
<img alt="NPM stable version" src="https://img.shields.io/npm/v/@litert/mime?color=brightgreen&logo=npm" />
</a><br>
<a href="https://github.com/litert/mime.js/releases">
<img alt="GitHub releases" src="https://img.shields.io/github/v/release/litert/mime.js?color=brightgreen&logo=github" />
</a>
<a href="https://github.com/litert/mime.js/issues">
<img alt="GitHub issues" src="https://img.shields.io/github/issues/litert/mime.js?color=blue&logo=github" />
</a>
</p>

根據檔案名稱、路徑和副檔名獲取 mime 類型。

> 本庫不需要經常更新,因此即使很久沒有更新,只要它依然存在,則表示它是可用的。我們會持續關注其是否可以正常運行在最新的 Node 和瀏覽器環境。
## 安裝

### NPM

你可以直接通過 npm 命令進行安裝。

```sh
$ npm i @litert/mime --save
```

### CDN

如果你在瀏覽器中使用,可以使用 CDN 模式:

```html
<script src="https://cdn.jsdelivr.net/npm/@litert/loader@3.5.0/dist/loader.min.js?path=index&npm={'@litert/mime':'0.1.2'}"></script>
```

## 使用

演示程式碼使用 TypeScript 語言編寫。

```typescript
import * as mime from "@litert/mime";

mime.getData("hello.json"); // {"mime": "application/json", "compressible": true, extension: 'json'}
mime.getData(".html"); // {"mime": "text/html", "compressible": true, extension: 'html'}
mime.getData("css"); // {"mime": "text/css", "compressible": true, extension: 'css'}
mime.getData("hi/baby.js"); // {"mime": "application/javascript", "compressible": true, extension: 'js'}
mime.getData("/root/down/pk.zip"); // {"mime": "application/zip", "compressible": false, extension: 'zip'}
mime.getData("ext.dodooh"); // {"mime": "application/octet-stream", "compressible": false, extension: 'dodooh'}
mime.getMime("root/index.css"); // text/css
```

## 示例

### Node

正確編譯後,在終端中使用 `node ./dist/test-node` 就可以執行示例程式碼。

### 瀏覽器

在瀏覽器中訪問 `test/` 目錄即可查看示例。

[點擊此處在線查看示例](https://litert.github.io/mime.js/test/)

## 許可

本庫使用 [Apache-2.0](../LICENSE) 許可。
2 changes: 1 addition & 1 deletion mime.json

Large diffs are not rendered by default.

Loading

0 comments on commit 2633247

Please sign in to comment.