🚀 Socket Launch Week 🚀 Day 5: Introducing Socket Fix.Learn More
Socket
Sign inDemoInstall
Socket

jsonp-body

Package Overview
Dependencies
Maintainers
0
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonp-body

Helper to create more safe jsonp response body for koa and other web framework

2.0.0
latest
Source
npm
Version published
Weekly downloads
23K
-2.4%
Maintainers
0
Weekly downloads
 
Created
Source

jsonp-body

NPM version Node.js CI Test coverage Known Vulnerabilities npm download Node.js Version PRs Welcome

Helper to create more safe jsonp response body for koa and other web framework.

Install

npm install jsonp-body --save

Usage

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);
});

API Reference

jsonp(obj, callback, options)

Get obj jsonp string response with callback.

  • obj: object convert to JSON string
  • callback: callback function name
  • options: optional for JSON.stringify
    • limit: length limit for callback, default to 512
    • replacer: replacer in JSON.stringify(obj, [replacer, [space]])
    • space: space in JSON.stringify(obj, [replacer, [space]])

License

MIT

Contributors

Contributors

Made with contributors-img.

Keywords

jsonp

FAQs

Package last updated on 11 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts