Helper to create more safe jsonp response body for koa and other web framework
npm install jsonp-body[![NPM version][npm-image]][npm-url]

[![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/jsonp-body.svg?style=flat-square
[npm-url]: https://npmjs.org/package/jsonp-body
[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 and other web framework.
``bash`
npm install jsonp-body --save
`js
const koa = require('koa');
const { jsonp } = require('jsonp-body');
var app = koa();
app.use(async function () {
this.set('X-Content-Type-Options', 'nosniff');
if (this.query.callback) {
this.set('Content-Type', 'text/javascript');
} else {
this.set('Content-Type', 'application/json');
}
this.body = jsonp({foo: 'bar'}, this.query.callback);
});
`
Get obj jsonp string response with callback.
- __obj__: object convert to JSON string
- __callback__: callback function name
- __options__: optional for JSON.stringifycallback
- __limit__: length limit for , default to 512JSON.stringify(obj, [replacer, [space]])
- __replacer__: replacer in JSON.stringify(obj, [replacer, [space]])`
- __space__: space in

Made with contributors-img.