@shgysk8zer0/polyfills 0.2.1 → 0.2.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shgysk8zer0/polyfills",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "A collection of JavaScript polyfills",
package/response.js ADDED
@@ -0,0 +1,17 @@
1
+ import { polyfillMethod } from './utils.js';
2
+
3
+ polyfillMethod(Response, 'json', (data, { status = 200, statusText = '', headers = new Headers() } = {}) => {
4
+ if (! (headers instanceof Headers)) {
5
+ return Response.json(data, { status, statusText, headers: new Headers(headers) });
6
+ } else {
7
+ headers.set('Content-Type', 'application/json');
8
+ return new Response(JSON.stringify(data), { status, statusText, headers });
9
+ }
10
+ });
11
+
12
+ polyfillMethod(Response, 'redirect', (url, status = 302) => {
13
+ return new Response('', {
14
+ status,
15
+ headers: new Headers({ Location: url }),
16
+ });
17
+ });
package/secure-context.js CHANGED
@@ -20,7 +20,9 @@
20
20
  enumerable: true,
21
21
  configurable: true,
22
22
  get: function isSecureContext() {
23
- if (protocols.includes(location.protocol) || hostnames.includes(location.hostname)) {
23
+ if (window.parent !== window) {
24
+ return false;
25
+ } else if (protocols.includes(location.protocol) || hostnames.includes(location.hostname)) {
24
26
  return hasSecureScripts();
25
27
  } else {
26
28
  return false;