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 cjs and esm both by tshy #5

Merged
merged 2 commits into from
Jan 11, 2025
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
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test/fixtures
coverage
6 changes: 6 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": [
"eslint-config-egg/typescript",
"eslint-config-egg/lib/rules/enforce-node-prefix"
]
}
16 changes: 16 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: 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:
version: '18.19.0, 20, 22'
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
23 changes: 23 additions & 0 deletions .github/workflows/pkg.pr.new.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Publish Any Commit
on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- run: corepack enable
- uses: actions/setup-node@v4
with:
node-version: 20

- name: Install dependencies
run: npm install

- name: Build
run: npm run prepublishOnly --if-present

- run: npx pkg-pr-new publish
13 changes: 13 additions & 0 deletions .github/workflows/release.yml
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 }}
23 changes: 9 additions & 14 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
coverage.html
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz

pids
logs
results

node_modules
logs/
npm-debug.log
node_modules/
coverage/
test/fixtures/**/run
.DS_Store
.tshy*
.eslintcache
dist
package-lock.json
.package-lock.json
4 changes: 0 additions & 4 deletions .jshintignore

This file was deleted.

95 changes: 0 additions & 95 deletions .jshintrc

This file was deleted.

8 changes: 0 additions & 8 deletions .npmignore

This file was deleted.

11 changes: 0 additions & 11 deletions .travis.yml

This file was deleted.

6 changes: 0 additions & 6 deletions AUTHORS

This file was deleted.

File renamed without changes.
28 changes: 17 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,38 @@
# jsonp-body

[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][coveralls-image]][coveralls-url]
[![Node.js CI](https://github.com/node-modules/jsonp-body/actions/workflows/nodejs.yml/badge.svg)](https://github.com/node-modules/jsonp-body/actions/workflows/nodejs.yml)
[![Test coverage][codecov-image]][codecov-url]
[![Known Vulnerabilities][snyk-image]][snyk-url]
[![npm download][download-image]][download-url]
[![Node.js Version](https://img.shields.io/node/v/jsonp-body.svg?style=flat)](https://nodejs.org/en/download/)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://makeapullrequest.com)

[npm-image]: https://img.shields.io/npm/v/jsonp-body.svg?style=flat-square
[npm-url]: https://npmjs.org/package/jsonp-body
[travis-image]: https://img.shields.io/travis/node-modules/jsonp-body.svg?style=flat-square
[travis-url]: https://travis-ci.org/node-modules/jsonp-body
[coveralls-image]: https://img.shields.io/coveralls/node-modules/jsonp-body.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/node-modules/jsonp-body?branch=master
[codecov-image]: https://img.shields.io/codecov/c/github/node-modules/jsonp-body.svg?style=flat-square
[codecov-url]: https://codecov.io/github/node-modules/jsonp-body?branch=master
[snyk-image]: https://snyk.io/test/npm/jsonp-body/badge.svg?style=flat-square
[snyk-url]: https://snyk.io/test/npm/jsonp-body
[download-image]: https://img.shields.io/npm/dm/jsonp-body.svg?style=flat-square
[download-url]: https://npmjs.org/package/jsonp-body

Helper to create more safe jsonp response body for [koa](http://koajs.com/) and other web framework.

## Install

```bash
$ npm install jsonp-body --save
npm install jsonp-body --save
```

## Usage

```js
var koa = require('koa');
var jsonp = require('jsonp-body');
const koa = require('koa');
const { jsonp } = require('jsonp-body');

var app = koa();
app.use(function* () {
app.use(async function () {
this.set('X-Content-Type-Options', 'nosniff');
if (this.query.callback) {
this.set('Content-Type', 'text/javascript');
Expand All @@ -39,7 +45,7 @@ app.use(function* () {

## API Reference

### #jsonp(obj, callback, options)
### `jsonp(obj, callback, options)`

Get `obj` jsonp string response with `callback`.

Expand Down
18 changes: 0 additions & 18 deletions index.d.ts

This file was deleted.

82 changes: 57 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,14 @@
{
"name": "jsonp-body",
"version": "1.1.0",
"description": "Helper to create more safe jsonp response body for koa and other web framework.",
"main": "index.js",
"types": "index.d.ts",
"scripts": {
"test": "mocha test/*.test.js",
"test-cov": "istanbul cover _mocha -- test/*.test.js"
},
"dependencies": {

},
"devDependencies": {
"autod": "*",
"contributors": "*",
"istanbul": "*",
"jshint": "*",
"mocha": "*",
"should": "7"
},
"description": "Helper to create more safe jsonp response body for koa and other web framework",
"homepage": "https://github.com/node-modules/jsonp-body",
"repository": {
"type": "git",
"url": "git://github.com/node-modules/jsonp-body.git",
"web": "https://github.com/node-modules/jsonp-body"
"url": "git://github.com/node-modules/jsonp-body.git"
},
"bugs": {
"url": "https://github.com/node-modules/jsonp-body/issues",
"email": "[email protected]"
"url": "https://github.com/node-modules/jsonp-body/issues"
},
"keywords": [
"jsonp",
Expand All @@ -36,9 +17,60 @@
"CVE-2014-4671",
"abusing-jsonp-with-rosetta-flash"
],
"author": "fengmk2 <[email protected]> (https://github.com/fengmk2)",
"license": "MIT",
"engines": {
"node": ">= 0.10.0"
"node": ">= 18.19.0"
},
"author": "fengmk2 <[email protected]> (https://github.com/fengmk2)",
"license": "MIT"
"dependencies": {},
"devDependencies": {
"@arethetypeswrong/cli": "^0.17.1",
"@eggjs/tsconfig": "1",
"@types/node": "22",
"@types/mocha": "10",
"@eggjs/bin": "7",
"eslint": "8",
"eslint-config-egg": "14",
"rimraf": "6",
"tshy": "3",
"tshy-after": "1",
"typescript": "5"
},
"scripts": {
"lint": "eslint --cache src test --ext .ts",
"pretest": "npm run clean && npm run lint -- --fix",
"test": "egg-bin test",
"preci": "npm run clean && npm run lint",
"ci": "egg-bin cov",
"postci": "npm run prepublishOnly && npm run clean",
"clean": "rimraf dist",
"prepublishOnly": "tshy && tshy-after && attw --pack"
},
"type": "module",
"tshy": {
"exports": {
".": "./src/index.ts",
"./package.json": "./package.json"
}
},
"exports": {
".": {
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/commonjs/index.d.ts",
"default": "./dist/commonjs/index.js"
}
},
"./package.json": "./package.json"
},
"files": [
"dist",
"src"
],
"types": "./dist/commonjs/index.d.ts",
"main": "./dist/commonjs/index.js",
"module": "./dist/esm/index.js"
}
Loading
Loading