包详细信息

jsonp-body

node-modules107kMIT2.0.0

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

jsonp, koa, json, CVE-2014-4671

自述文件

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.

更新日志

Changelog

2.0.0 (2025-01-11)

⚠ BREAKING CHANGES

  • drop Node.js < 18.19.0 support

part of https://github.com/eggjs/egg/issues/3644

https://github.com/eggjs/egg/issues/5257

Summary by CodeRabbit

  • Configuration Updates

    • Updated ESLint configuration to improve code quality and consistency
    • Removed legacy configuration files (JSHint, Travis CI)
    • Added TypeScript configuration with strict type checking
  • CI/CD Improvements

    • Replaced Travis CI with GitHub Actions workflows
    • Added automated testing and release processes
    • Configured Node.js version support (18.19.0, 20, 22)
  • Project Maintenance

    • Updated README with modern badges and documentation
    • Simplified package configuration
    • Removed outdated contributor information
  • Development Environment

    • Updated .gitignore to reflect current project structure
    • Added coverage and build-related ignore rules

Features

  • support cjs and esm both by tshy (#5) (fa2f0ff)

1.1.0 / 2024-01-11

  • feat: add TypeScript declaration file

1.0.0 / 2014-08-19

  • add options in readme
  • add options.space and options.replacer

0.2.0 / 2014-07-22

  • limit callback length, default is 512
  • add unsafe characters test case

0.1.0 / 2014-07-17

  • init