@tinyhttp/jsonp 2.1.5 → 2.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +0 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { Request, Response } from '@tinyhttp/app'\n\nexport type JSONPOptions = Partial<{\n escape: boolean\n replacer: (this: any, key: string, value: any) => any\n spaces: string | number\n callbackName: string\n}>\n\nfunction stringify(\n value: unknown,\n replacer: (this: any, key: string, value: any) => any,\n spaces: string | number,\n escape: boolean\n) {\n let json = replacer || spaces ? JSON.stringify(value, replacer, spaces) : JSON.stringify(value)\n\n if (escape) {\n json = json.replace(/[<>&]/g, (c) => {\n switch (c.charCodeAt(0)) {\n case 0x3c:\n return '\\\\u003c'\n case 0x3e:\n return '\\\\u003e'\n case 0x26:\n return '\\\\u0026'\n
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { Request, Response } from '@tinyhttp/app'\n\nexport type JSONPOptions = Partial<{\n escape: boolean\n replacer: (this: any, key: string, value: any) => any\n spaces: string | number\n callbackName: string\n}>\n\nfunction stringify(\n value: unknown,\n replacer: (this: any, key: string, value: any) => any,\n spaces: string | number,\n escape: boolean\n) {\n let json = replacer || spaces ? JSON.stringify(value, replacer, spaces) : JSON.stringify(value)\n\n if (escape) {\n json = json.replace(/[<>&]/g, (c) => {\n switch (c.charCodeAt(0)) {\n case 0x3c:\n return '\\\\u003c'\n case 0x3e:\n return '\\\\u003e'\n case 0x26:\n return '\\\\u0026'\n }\n })\n }\n\n return json\n}\n\n/**\n * Send JSON response with JSONP callback support\n * @param req Request\n * @param res Response\n * @param app App\n */\nexport const jsonp =\n (req: Request, res: Response) =>\n (obj: unknown, opts: JSONPOptions = {}): Response => {\n const val = obj\n\n const { escape, replacer, spaces, callbackName = 'callback' } = opts\n\n let body = stringify(val, replacer, spaces, escape)\n\n let callback = req.query[callbackName]\n\n if (!res.get('Content-Type')) {\n res.set('X-Content-Type-Options', 'nosniff')\n res.set('Content-Type', 'application/json')\n }\n\n // jsonp\n if (typeof callback === 'string' && callback.length !== 0) {\n res.set('X-Content-Type-Options', 'nosniff')\n res.set('Content-Type', 'text/javascript')\n\n // restrict callback charset\n callback = callback.replace(/[^[\\]\\w$.]/g, '')\n\n // replace chars not allowed in JavaScript that are in JSON\n body = body.replace(/\\u2028/g, '\\\\u2028').replace(/\\u2029/g, '\\\\u2029')\n\n // the /**/ is a specific security mitigation for \"Rosetta Flash JSONP abuse\"\n // the typeof check is just to reduce client error noise\n body = `/**/ typeof ${callback} === 'function' && ${callback}(${body});`\n }\n\n return res.send(body)\n }\n"],"names":[],"mappings":"AAUA,SAAS,UACP,OACA,UACA,QACA,QACA;AACI,MAAA,OAAO,YAAY,SAAS,KAAK,UAAU,OAAO,UAAU,MAAM,IAAI,KAAK,UAAU,KAAK;AAE9F,MAAI,QAAQ;AACV,WAAO,KAAK,QAAQ,UAAU,CAAC,MAAM;AAC3B,cAAA,EAAE,WAAW,CAAC,GAAG;AAAA,QACvB,KAAK;AACI,iBAAA;AAAA,QACT,KAAK;AACI,iBAAA;AAAA,QACT,KAAK;AACI,iBAAA;AAAA,MACX;AAAA,IAAA,CACD;AAAA,EACH;AAEO,SAAA;AACT;AAQa,MAAA,QACX,CAAC,KAAc,QACf,CAAC,KAAc,OAAqB,OAAiB;AACnD,QAAM,MAAM;AAEZ,QAAM,EAAE,QAAQ,UAAU,QAAQ,eAAe,WAAe,IAAA;AAEhE,MAAI,OAAO,UAAU,KAAK,UAAU,QAAQ,MAAM;AAE9C,MAAA,WAAW,IAAI,MAAM,YAAY;AAErC,MAAI,CAAC,IAAI,IAAI,cAAc,GAAG;AACxB,QAAA,IAAI,0BAA0B,SAAS;AACvC,QAAA,IAAI,gBAAgB,kBAAkB;AAAA,EAC5C;AAGA,MAAI,OAAO,aAAa,YAAY,SAAS,WAAW,GAAG;AACrD,QAAA,IAAI,0BAA0B,SAAS;AACvC,QAAA,IAAI,gBAAgB,iBAAiB;AAG9B,eAAA,SAAS,QAAQ,eAAe,EAAE;AAG7C,WAAO,KAAK,QAAQ,WAAW,SAAS,EAAE,QAAQ,WAAW,SAAS;AAItE,WAAO,eAAe,QAAQ,sBAAsB,QAAQ,IAAI,IAAI;AAAA,EACtE;AAEO,SAAA,IAAI,KAAK,IAAI;AACtB;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinyhttp/jsonp",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "JSONP response middleware",
|
|
6
6
|
"homepage": "https://tinyhttp.v1rtl.site",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"author": "v1rtl",
|
|
26
26
|
"license": "MIT",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@tinyhttp/app": "2.2.
|
|
28
|
+
"@tinyhttp/app": "2.2.1"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
31
|
"dev": "vite",
|