Skip to content

Commit caaa49b

Browse files
committed
feat: rewrite the whole module with typescript (including upgrade node, drop mocha and replace it native test module ...etc)
1 parent 41367b6 commit caaa49b

File tree

10 files changed

+130
-50
lines changed

10 files changed

+130
-50
lines changed

.github/workflows/ci.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Continuous Integration
2+
3+
on:
4+
- push
5+
- pull_request
6+
7+
jobs:
8+
ci:
9+
runs-on: ubuntu-latest
10+
strategy:
11+
matrix:
12+
node-version:
13+
- 20
14+
- 22
15+
- 24
16+
steps:
17+
- uses: actions/checkout@v3
18+
- name: Use Node.js ${{ matrix.node-version }}
19+
uses: actions/setup-node@v3
20+
- name: Install dependencies
21+
run: yarn install
22+
- name: Run tests
23+
run: yarn test-ci

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@ temp/
1111
###################
1212
node_modules
1313
package-lock.json
14+
yarn.lock
1415
npm-debug.log
1516
yarn-debug.log
1617
yarn-error.log
1718

19+
# Build #
20+
###################
21+
dist
22+
build
1823

1924
# NYC #
2025
###################

.travis.yml

Lines changed: 0 additions & 12 deletions
This file was deleted.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# [**koa-is-json**](https://github.com/koajs/is-json)
1+
# [**@koa/is-json**](https://github.com/koajs/is-json)
22

33
[![Greenkeeper badge](https://badges.greenkeeper.io/koajs/is-json.svg)](https://greenkeeper.io/)
44

@@ -7,4 +7,4 @@
77

88
## License
99

10-
[MIT](/LICENSE)
10+
[MIT](/LICENSE)

package.json

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,39 @@
11
{
2-
"name": "koa-is-json",
3-
"description": "Check if a koa body should be interpreted as JSON",
2+
"name": "@koa/is-json",
43
"version": "1.0.0",
5-
"scripts": {
6-
"lint": "eslint --fix .",
7-
"test-only": "mocha",
8-
"test": "npm run lint & npm run test-only",
9-
"test-cov": "nyc npm run test"
4+
"description": "Check if a koa body should be interpreted as JSON",
5+
"main": "./dist/index.js",
6+
"module": "./dist/index.mjs",
7+
"types": "./dist/index.d.ts",
8+
"exports": {
9+
".": {
10+
"require": "./dist/index.js",
11+
"import": "./dist/index.mjs"
12+
}
1013
},
11-
"repository": {
12-
"type": "git",
13-
"url": "git+https://github.com/koajs/is-json.git"
14+
"files": [
15+
"dist",
16+
"LICENSE",
17+
"README.md"
18+
],
19+
"scripts": {
20+
"prebuild": "rimraf dist",
21+
"build": "tsup",
22+
"test": "node --require ts-node/register --test",
23+
"test-ci": "npm run test -- --experimental-test-coverage",
24+
"prepublishOnly": "npm run build"
1425
},
1526
"keywords": [
27+
"koa",
28+
"utils",
29+
"helpers",
1630
"json",
17-
"is-json",
18-
"koa"
31+
"is-json"
1932
],
33+
"license": "MIT",
34+
"peerDependencies": {
35+
"koa": ">= 2"
36+
},
2037
"author": {
2138
"name": "Jonathan Ong",
2239
"email": "[email protected]",
@@ -37,26 +54,19 @@
3754
"twitter": "https://twitter.com/3imed_jaberi"
3855
}
3956
],
40-
"license": "MIT",
41-
"nyc": {
42-
"reporter": [
43-
"lcov",
44-
"text-summary"
45-
],
46-
"report-dir": "./coverage"
47-
},
4857
"devDependencies": {
49-
"eslint": "^8.19.0",
50-
"eslint-config-standard": "^14.1.1",
51-
"eslint-plugin-import": "^2.8.0",
52-
"eslint-plugin-node": "^11.1.0",
53-
"eslint-plugin-promise": "^6.0.0",
54-
"eslint-plugin-standard": "^5.0.0",
55-
"mocha": "^10.0.0",
56-
"nyc": "^15.0.0"
58+
"@types/node": "^24.10.0",
59+
"rimraf": "^6.1.0",
60+
"ts-node": "^10.9.2",
61+
"tsup": "^8.5.0",
62+
"typescript": "^5.9.3"
5763
},
5864
"engines": {
59-
"node": ">= 8"
65+
"node": ">= 20"
66+
},
67+
"repository": {
68+
"type": "git",
69+
"url": "git+https://github.com/koajs/is-json.git"
6070
},
6171
"bugs": {
6272
"url": "https://github.com/koajs/is-json/issues"

index.js renamed to src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
* Check if `body` should be interpreted as json.
44
*
55
*/
6-
7-
module.exports = function isJSON (body) {
6+
export const isJSON = (body?: any): boolean => {
87
return !(
98
!body ||
109
typeof body === 'string' ||
1110
typeof body.pipe === 'function' ||
1211
Buffer.isBuffer(body)
1312
)
1413
}
14+
15+
export default isJSON;

test/.eslintrc

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import assert from 'node:assert';
2+
import { describe, it } from 'node:test';
13

2-
const assert = require('assert')
3-
const isJSON = require('..')
4+
import isJSON from '../src';
45

56
describe('koa-is-json test', () => {
67
let body

tsconfig.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es6",
4+
"module": "commonjs",
5+
"lib": [
6+
"dom",
7+
"es6",
8+
"es2017",
9+
"esnext.asynciterable"
10+
],
11+
"skipLibCheck": true,
12+
"sourceMap": true,
13+
"outDir": "./dist",
14+
"moduleResolution": "node",
15+
"removeComments": true,
16+
"noImplicitAny": true,
17+
"strictNullChecks": true,
18+
"strictFunctionTypes": true,
19+
"noImplicitThis": true,
20+
"noUnusedLocals": true,
21+
"noUnusedParameters": true,
22+
"noImplicitReturns": true,
23+
"noFallthroughCasesInSwitch": true,
24+
"allowSyntheticDefaultImports": true,
25+
"esModuleInterop": true,
26+
"emitDecoratorMetadata": true,
27+
"experimentalDecorators": true,
28+
"resolveJsonModule": true,
29+
"baseUrl": ".",
30+
"types": ["node"]
31+
},
32+
"include": [
33+
"./src/**/*.ts"
34+
],
35+
"exclude": [
36+
"dist",
37+
"node_modules",
38+
"src/**/*.test.tsx"
39+
]
40+
}

tsup.config.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import {defineConfig} from 'tsup';
2+
3+
const tsupConfig = defineConfig({
4+
name: '@koa/is-json',
5+
entry: ['src/*.ts'],
6+
target: 'esnext',
7+
format: ['cjs', 'esm'],
8+
dts: true,
9+
splitting: false,
10+
sourcemap: false,
11+
clean: true,
12+
platform: 'node',
13+
});
14+
15+
export default tsupConfig;

0 commit comments

Comments
 (0)