@shgysk8zer0/polyfills 0.2.4 → 0.2.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/array.js CHANGED
@@ -85,59 +85,45 @@
85
85
  }
86
86
 
87
87
  /**
88
+ * @deprecated [moved to `Object.groupBy()`]
88
89
  * @see https://github.com/tc39/proposal-array-grouping
89
90
  */
90
- if (! (Array.prototype.group instanceof Function)) {
91
- Array.prototype.group = function group(callback, thisArg = globalThis) {
92
- return this.reduce((groups, item, index, arr) => {
93
- const key = callback.call(thisArg, item, index, arr);
94
-
95
- if (! groups.hasOwnProperty(key)) {
96
- groups[key] = [item];
97
- } else {
98
- groups[key].push(item);
99
- }
100
-
101
- return groups;
102
- }, {});
91
+ if (! (Array.prototype.group instanceof Function) && Object.groupBy instanceof Function) {
92
+ Array.prototype.group = function group(callback) {
93
+ console.warn('`Array.group()` is deprecated. Please use `Object.groupBy()` instead.');
94
+ return Object.groupBy(this, callback);
103
95
  };
104
96
  }
105
97
 
106
98
  /**
107
- * @deprecated [renamed to `group()`]
99
+ * @deprecated [moved to `Object.groupBy()`]
108
100
  */
109
- Array.prototype.groupBy = function groupBy(...args) {
110
- console.warn('`goupBy` is deprecated. Please use `group` instead.');
111
- return this.group(...args);
112
- };
101
+ if (! (Array.prototype.groupBy instanceof Function) && Object.groupBy instanceof Function) {
102
+ Array.prototype.groupBy = function groupBy(callback) {
103
+ console.warn('`Array.goupBy()` is deprecated. Please use `Object.groupBy()` instead.');
104
+ return Object.groupBy(this, callback);
105
+ };
106
+ }
113
107
 
114
108
  /**
115
109
  * @see https://github.com/tc39/proposal-array-grouping
110
+ * @deprecated [moved to `Map.groupBy()`]
116
111
  * @requires `Map.prototype.emplace`
117
112
  */
118
- if (! (Array.prototype.groupToMap instanceof Function) && (Map.prototype.emplace instanceof Function)) {
119
- Array.prototype.groupToMap = function groupToMap(callback, thisArg = globalThis) {
120
- return this.reduce((map, item, index, arr) => {
121
- map.emplace(callback.call(thisArg, item, index, arr), {
122
- insert: () => [item],
123
- update: existing => {
124
- existing.push(item);
125
- return existing;
126
- }
127
- });
128
-
129
- return map;
130
- }, new Map());
113
+ if (! (Array.prototype.groupToMap instanceof Function) && (Map.groupBy instanceof Function)) {
114
+ Array.prototype.groupToMap = function groupToMap(callback) {
115
+ console.warn('`Array.groupToMap()` is deprecated. Please use `Map.groupBy()` instead.');
116
+ return Map.groupBy(this, callback);
131
117
  };
132
118
  }
133
119
 
134
120
  /**
135
- * @deprecated [renamed to `groupToMap()`]
121
+ * @deprecated [moved to `Map.groupBy()`]
136
122
  */
137
- if (Map.prototype.emplace instanceof Function) {
138
- Array.prototype.groupByToMap = function groupByToMap(...args) {
139
- console.warn('`goupByToMap` is deprecated. Please use `groupToMap` instead.');
140
- return this.groupToMap(...args);
123
+ if (Map.groupBy instanceof Function) {
124
+ Array.prototype.groupByToMap = function groupByToMap(callback) {
125
+ console.warn('`Array.groupByToMap()` is deprecated. Please use `Map.groupBy()` instead.');
126
+ return Map.groupBy(this, callback);
141
127
  };
142
128
  }
143
129
 
@@ -28,6 +28,7 @@ function getAllCookies() {
28
28
  domain: undefined,
29
29
  sameSite: undefined,
30
30
  secure: undefined,
31
+ partitioned: false,
31
32
  };
32
33
  });
33
34
  }
@@ -40,11 +41,11 @@ function defaultParams({
40
41
  path = '/',
41
42
  expires = null,
42
43
  maxAge = null,
43
- sameSite = 'strict',
44
+ sameSite = 'lax',
44
45
  secure = false,
45
- httpOnly = false,
46
+ partitioned = false,
46
47
  }) {
47
- return { name, value, domain, path, expires, maxAge, sameSite, secure, httpOnly };
48
+ return { name, value, domain, path, expires, maxAge, sameSite, secure, partitioned };
48
49
  }
49
50
 
50
51
  function getter({ name = null, value = null } = {}) {
@@ -75,14 +76,14 @@ function setter({
75
76
  expires = null,
76
77
  maxAge = null,
77
78
  path = '/',
78
- sameSite = 'strict',
79
+ sameSite = 'lax',
79
80
  domain = null,
80
81
  secure = false,
81
- httpOnly = false,
82
+ partitioned = false,
82
83
  }) {
83
84
  if (Number.isInteger(maxAge)) {
84
85
  setter({
85
- name, value, expires: Date.now() + maxAge, path, sameSite, domain, secure, httpOnly,
86
+ name, value, expires: Date.now() + maxAge, path, sameSite, domain, secure, partitioned,
86
87
  });
87
88
  } else {
88
89
  let cookie = `${encodeURIComponent(name)}=`;
@@ -113,11 +114,8 @@ function setter({
113
114
  cookie += ';secure';
114
115
  }
115
116
 
116
- /**
117
- * Does not work in any browser, but set regardless
118
- */
119
- if (httpOnly === true) {
120
- cookie += ';httponly';
117
+ if (partitioned === true) {
118
+ cookie += ';partitioned';
121
119
  }
122
120
 
123
121
  document.cookie = cookie;
@@ -173,7 +171,7 @@ export class CookieStore extends EventTarget {
173
171
  }
174
172
 
175
173
  async set(...args) {
176
- if (args.length === 1 && typeof args[0].name === 'string') {
174
+ if (args.length === 1 && typeof args[0] === 'object' && typeof args[0].name === 'string') {
177
175
  const cookie = defaultParams(args[0]);
178
176
  setter(cookie);
179
177
  const event = new Event('change');
@@ -191,7 +189,7 @@ export class CookieStore extends EventTarget {
191
189
  async delete(args = {}) {
192
190
  if (typeof args === 'string') {
193
191
  this.delete({ name: args });
194
- } else if (typeof args.name === 'string') {
192
+ } else if (typeof args === 'object' && typeof args.name === 'string') {
195
193
  const cookies = await this.getAll(args);
196
194
 
197
195
  if (cookies.length !== 0) {
@@ -204,7 +202,7 @@ export class CookieStore extends EventTarget {
204
202
  cookie.domain = args.domain || null;
205
203
  cookie.secure = args.secure || null;
206
204
  delete cookie.value;
207
- cookie.sameSite = args.sameSite || 'strict';
205
+ cookie.sameSite = args.sameSite || 'lax';
208
206
 
209
207
  event.deleted[i] = cookie;
210
208
  setter({...cookie, value: null, expires: 1 });
package/element.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { aria } from './aom.js';
2
- import { overwriteMethod } from './utils.js';
2
+ import { overwriteMethod, polyfillGetterSetter } from './utils.js';
3
3
  import { SanitizerConfig as defaultConfig } from './assets/SanitizerConfigW3C.js';
4
4
  import { setHTML as safeSetHTML, convertToSanitizerConfig } from './assets/sanitizerUtils.js';
5
5
 
@@ -191,3 +191,25 @@ if (! (HTMLFormElement.prototype.requestSubmit instanceof Function)) {
191
191
  }
192
192
  };
193
193
  }
194
+
195
+ if (! ('loading' in HTMLIFrameElement.prototype)) {
196
+ polyfillGetterSetter(HTMLIFrameElement.prototype, 'loading', {
197
+ get: function() {
198
+ return this.getAttribute('loading') || 'auto';
199
+ },
200
+ set: function(val) {
201
+ this.setAttribute('loading', val);
202
+ }
203
+ });
204
+ }
205
+
206
+ if (! ('credentialless' in HTMLIFrameElement.prototype)) {
207
+ polyfillGetterSetter(HTMLIFrameElement.prototype, 'credentialless', {
208
+ get: function() {
209
+ return this.hasAttribute('credentialless');
210
+ },
211
+ set: function(val) {
212
+ this.toggleAttribute('credentialless', val);
213
+ }
214
+ });
215
+ }
package/map.js CHANGED
@@ -29,4 +29,20 @@
29
29
  }
30
30
  };
31
31
  }
32
+
33
+ if (! (Map.groupBy instanceof Function)) {
34
+ Map.groupBy = function groupTo(items, callbackFn) {
35
+ return Array.from(items).reduce((map, element, index) => {
36
+ map.emplace(callbackFn.call(map, element, index), {
37
+ insert: () => [element],
38
+ update: existing => {
39
+ existing.push(element);
40
+ return existing;
41
+ }
42
+ });
43
+
44
+ return map;
45
+ }, new Map());
46
+ };
47
+ }
32
48
  })();
package/object.js ADDED
@@ -0,0 +1,15 @@
1
+ if (! (Object.groupBy instanceof Function)) {
2
+ Object.groupBy = function(items, callbackFn) {
3
+ return Array.from(items).reduce((groups, element, index) => {
4
+ const key = callbackFn.call(groups, element, index);
5
+
6
+ if (! groups.hasOwnProperty(key)) {
7
+ groups[key] = [element];
8
+ } else {
9
+ groups[key].push(element);
10
+ }
11
+
12
+ return groups;
13
+ }, {});
14
+ };
15
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shgysk8zer0/polyfills",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "A collection of JavaScript polyfills",