Skip to content

Commit

Permalink
refactor: update the code base, drop support of node<10
Browse files Browse the repository at this point in the history
Update 06/2020
  • Loading branch information
dead-horse committed Jun 20, 2020
2 parents 9d19ad1 + 4a51934 commit 19d0e01
Show file tree
Hide file tree
Showing 16 changed files with 254 additions and 290 deletions.
33 changes: 24 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
coverage.html
# OS #
###################
.DS_Store
.idea
Thumbs.db
tmp/
temp/


# Node.js #
###################
node_modules
package-lock.json


# NYC #
###################
coverage
*.lcov
.nyc_output


# Files #
###################
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz

pids
logs
results

node_modules
npm-debug.log
coverage/
4 changes: 0 additions & 4 deletions .jshintignore

This file was deleted.

95 changes: 0 additions & 95 deletions .jshintrc

This file was deleted.

4 changes: 4 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"reporter": "spec",
"timeout": 1000
}
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
12 changes: 12 additions & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extension": [
".js"
],
"reporter": [
"text-lcov",
"text",
"lcov"
],
"report-dir": "./coverage",
"temp-dir": "./.nyc_output"
}
14 changes: 7 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
sudo: false
language: node_js
node_js:
- '4'
- '3'
- '2'
- '1'
script: "npm run test-cov"
- 10
- 12
- 14
script:
- npm run ci
after_script:
- "npm i codecov.io && cat ./coverage/coverage.json | ./node_modules/codecov.io/bin/codecov.io.js"
- npm i codecov.io
- cat ./coverage/coverage.json | ./node_modules/codecov.io/bin/codecov.io.js
7 changes: 0 additions & 7 deletions AUTHORS

This file was deleted.

6 changes: 3 additions & 3 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
This software is licensed under the MIT License.
(The MIT License)

Copyright (c) koajs and other contributors
Copyright (c) Koa.js and other contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE.
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
koa-safe-jsonp
[koa-safe-jsonp][github-repo]
=======

[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][codecov-image]][codecov-url]
[![David deps][david-image]][david-url]

[github-repo]: https://github.com/koajs/koa-safe-jsonp
[npm-image]: https://img.shields.io/npm/v/koa-safe-jsonp.svg?style=flat
[npm-url]: https://npmjs.org/package/koa-safe-jsonp
[travis-image]: https://img.shields.io/travis/koajs/koa-safe-jsonp.svg?style=flat
Expand All @@ -15,28 +16,31 @@ koa-safe-jsonp
[david-image]: https://img.shields.io/david/koajs/koa-safe-jsonp.svg?style=flat
[david-url]: https://david-dm.org/koajs/koa-safe-jsonp

Safe jsonp plusins for koa.
Safe jsonp plugins for koa.

## Install

```bash
$ npm install koa-safe-jsonp
# npm ..
$ npm i koa-safe-jsonp
# yarn ..
$ yarn add koa-safe-jsonp
```

## Usage

```js
var jsonp = require('koa-safe-jsonp');
var koa = require('koa');
const jsonp = require('koa-safe-jsonp');
const Koa = require('Koa');

var app = koa();
const app = new Koa();
jsonp(app, {
callback: '_callback', // default is 'callback'
limit: 50, // max callback name string length, default is 512
});

app.use(function* () {
this.jsonp = {foo: "bar"};
app.use(function (ctx) {
ctx.jsonp = {foo: "bar"};
});

app.listen(1984);
Expand Down Expand Up @@ -74,4 +78,4 @@ $ curl 'http://127.0.0.1:1984/foo.json?_callback=fn' -v
## License
[MIT](./LICENSE)
[MIT](LICENSE)
15 changes: 0 additions & 15 deletions demo.js

This file was deleted.

15 changes: 15 additions & 0 deletions examples/koa-v1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

const jsonp = require('..');
const koa = require('koa');

const app = koa();
jsonp(app, {
callback: '_callback' // default is 'callback'
});

app.use(function* () {
this.jsonp = { foo: 'bar' };
});

app.listen(1984);
15 changes: 15 additions & 0 deletions examples/koa-v2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

const jsonp = require('..');
const Koa = require('koa');

const app = new Koa();
jsonp(app, {
callback: '_callback' // default is 'callback'
});

app.use(function (ctx) {
ctx.jsonp = { foo: 'bar' };
});

app.listen(1984);
35 changes: 11 additions & 24 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,23 @@
/**!
* Copyright(c) koajs and other contributors.
* MIT Licensed
*
* Authors:
* fengmk2 <[email protected]> (http://fengmk2.com)
*/

'use strict';

/**
* Module dependencies.
*/

var jsonpBody = require('jsonp-body');

module.exports = jsonp;
const jsonpBody = require('jsonp-body');

function jsonp(app, options) {
// eslint-disable-next-line func-names
module.exports = function jsonp(app, options) {
options = options || {};
var callback = options.callback || 'callback';
const callback = options.callback || 'callback';

// eslint-disable-next-line accessor-pairs
Object.defineProperty(app.context, 'jsonp', {
set: function (obj) {
var jsonpFunction = this.query[callback];
if (!jsonpFunction) {
return this.body = obj;
}
set(object) {
const jsonpFunc = this.query[callback];
// eslint-disable-next-line no-return-assign
if (!jsonpFunc) return (this.body = object); // eslint-disable-line no-setter-return

this.set('X-Content-Type-Options', 'nosniff');
this.type = 'js';
this.body = jsonpBody(obj, jsonpFunction, options);
this.body = jsonpBody(object, jsonpFunc, options);
},
configurable: true
});
}
};
Loading

0 comments on commit 19d0e01

Please sign in to comment.