| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| { | ||
| "extends": "eslint-config-egg" | ||
| "extends": [ | ||
| "eslint-config-egg/typescript", | ||
| "eslint-config-egg/lib/rules/enforce-node-prefix" | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| name: Node.js CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ master ] | ||
| pull_request: | ||
| branches: [ master ] | ||
|
|
||
| jobs: | ||
| Job: | ||
| name: Node.js | ||
| uses: node-modules/github-actions/.github/workflows/node-test.yml@master | ||
| with: | ||
| os: 'ubuntu-latest' | ||
| version: '18, 20, 22' | ||
| secrets: | ||
| CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| name: Release | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ master ] | ||
|
|
||
| jobs: | ||
| release: | ||
| name: Node.js | ||
| uses: node-modules/github-actions/.github/workflows/node-release.yml@master | ||
| secrets: | ||
| NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
| GIT_TOKEN: ${{ secrets.GIT_TOKEN }} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| node_modules | ||
| coverage | ||
| dist | ||
| .tshy* |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,33 @@ | ||
| ## cache-content-type | ||
| # cache-content-type | ||
|
|
||
| [![NPM version][npm-image]][npm-url] | ||
| [](https://github.com/node-modules/cache-content-type/actions/workflows/nodejs.yml) | ||
| [![Test coverage][codecov-image]][codecov-url] | ||
| [![Known Vulnerabilities][snyk-image]][snyk-url] | ||
| [![npm download][download-image]][download-url] | ||
|
|
||
| [npm-image]: https://img.shields.io/npm/v/cache-content-type.svg?style=flat-square | ||
| [npm-url]: https://npmjs.org/package/cache-content-type | ||
| [codecov-image]: https://codecov.io/github/node-modules/cache-content-type/coverage.svg?branch=master | ||
| [codecov-url]: https://codecov.io/github/node-modules/cache-content-type?branch=master | ||
| [snyk-image]: https://snyk.io/test/npm/cache-content-type/badge.svg?style=flat-square | ||
| [snyk-url]: https://snyk.io/test/npm/cache-content-type | ||
| [download-image]: https://img.shields.io/npm/dm/cache-content-type.svg?style=flat-square | ||
| [download-url]: https://npmjs.org/package/cache-content-type | ||
|
|
||
| The same as [mime-types](https://github.com/jshttp/mime-types)'s contentType method, but with result cached. | ||
|
|
||
| ### Install | ||
| ## Install | ||
|
|
||
| ```bash | ||
| npm i cache-content-type | ||
| ``` | ||
|
|
||
| ### Usage | ||
| ## Usage | ||
|
|
||
| ```ts | ||
| import { getType } from 'cache-content-type'; | ||
|
|
||
| ```js | ||
| const getType = require('cache-content-type'); | ||
| const contentType = getType('html'); | ||
| assert(contentType === 'text/html; charset=utf-8'); | ||
| assert.equal(contentType, 'text/html; charset=utf-8'); | ||
| ``` |
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import mimeTypes from 'mime-types'; | ||
| import LRU from 'ylru'; | ||
|
|
||
| let typeLRUCache: LRU; | ||
|
|
||
| export function getType(type: string): string | false { | ||
| if (!typeLRUCache) { | ||
| typeLRUCache = new LRU(100); | ||
| } | ||
| let mimeType = typeLRUCache.get<string | false>(type); | ||
| if (mimeType === undefined) { | ||
| mimeType = mimeTypes.contentType(type); | ||
| typeLRUCache.set(type, mimeType); | ||
| } | ||
| return mimeType; | ||
| } | ||
|
|
||
| export default getType; | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { strict as assert } from 'node:assert'; | ||
| import mimeTypes from 'mime-types'; | ||
| import mm from 'mm'; | ||
| import getTypeFromDefault, { getType } from '../src/index.js'; | ||
|
|
||
| describe('cache-content-type', () => { | ||
| afterEach(mm.restore); | ||
|
|
||
| it('should work with cache', () => { | ||
| assert.equal(getType('html'), 'text/html; charset=utf-8'); | ||
| mm.syncError(mimeTypes, 'contentType', 'mock error'); | ||
| assert.equal(getType('html'), 'text/html; charset=utf-8'); | ||
| }); | ||
|
|
||
| it('should return false when type not exists', () => { | ||
| assert.equal(getTypeFromDefault('html-not-exists'), false); | ||
| mm.syncError(mimeTypes, 'contentType', 'mock error'); | ||
| assert.equal(getTypeFromDefault('html-not-exists'), false); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "extends": "@eggjs/tsconfig", | ||
| "compilerOptions": { | ||
| "strict": true, | ||
| "noImplicitAny": true, | ||
| "target": "ES2022", | ||
| "module": "NodeNext", | ||
| "moduleResolution": "NodeNext" | ||
| } | ||
| } |
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityEnsure typeLRUCache is initialized before use to prevent runtime errors.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.