Skip to content

Commit

Permalink
Update README.md.
Browse files Browse the repository at this point in the history
  • Loading branch information
yunbookf committed Apr 1, 2019
1 parent ba57fa4 commit ab0640d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,44 @@
# mime-types

[![npm version](https://img.shields.io/npm/v/@litert/mime-types.svg?colorB=brightgreen)](https://www.npmjs.com/package/@litert/mime-types "Stable Version")
[![npm version](https://img.shields.io/npm/v/@litert/mime-types/dev.svg)](https://www.npmjs.com/package/@litert/mime-types "Development Version")
[![License](https://img.shields.io/github/license/litert/mime-types.svg)](https://github.com/litert/mime-types/blob/master/LICENSE)
[![node](https://img.shields.io/node/v/@litert/mime-types.svg?colorB=brightgreen)](https://nodejs.org/dist/latest-v10.x/)
[![GitHub issues](https://img.shields.io/github/issues/litert/mime-types.svg)](https://github.com/litert/mime-types/issues)
[![GitHub Releases](https://img.shields.io/github/release/litert/mime-types.svg)](https://github.com/litert/mime-types/releases "Stable Release")
[![GitHub Pre-Releases](https://img.shields.io/github/release/litert/mime-types/all.svg)](https://github.com/litert/mime-types/releases "Pre-Release")

Get MIME type based on file name.

## Installation

In the Node.js environment, you can install directly using NPM:

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

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

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

## API

Demo code is written using TypeScript.

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

mime.get("hello.json"); // application/json
mime.get(".html"); // text/html
mime.get("css"); // text/css
mime.get("hi/baby.js"); // application/javascript
mime.get("/root/down/pk.zip"); // application/zip
mime.get("ext.dodooh"); // application/octet-stream
```

## License

This library is published under [Apache-2.0](./LICENSE) license.
2 changes: 1 addition & 1 deletion sources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ let extJson = require(__dirname + "/../mime.json");

export function get(fpath: string): string {
let ext = fpath.indexOf(".") === -1 ? fpath : fpath.slice(fpath.lastIndexOf(".") + 1);
return extJson[ext] || "application/octet-stream";
return extJson[ext.toLowerCase()] || "application/octet-stream";
}

0 comments on commit ab0640d

Please sign in to comment.