@optionfactory/ful 0.98.0 → 0.100.0

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/ful.iife.js CHANGED
@@ -97,7 +97,7 @@ var ful = (function (exports) {
97
97
  this.#type = type;
98
98
  this.#subtype = subtype;
99
99
  }
100
- get normalized(){
100
+ get normalized() {
101
101
  return `${this.#type}/${this.#subtype}`;
102
102
  }
103
103
  get type() {
@@ -162,7 +162,7 @@ var ful = (function (exports) {
162
162
  * @returns an HttpClientError
163
163
  */
164
164
  static async fromResponse(response) {
165
- switch(MediaType.parse(response.headers.get("Content-Type")).normalized){
165
+ switch (MediaType.parse(response.headers.get("Content-Type")).normalized) {
166
166
  case 'application/failures+json': {
167
167
  const data = await response.json();
168
168
  const message = `${response.status} ${response.statusText}: ${data.length} failures`;
@@ -441,45 +441,61 @@ var ful = (function (exports) {
441
441
  this.#interceptors = interceptors;
442
442
  }
443
443
  /**
444
- * Add all passed headers to the request, overriding existing ones if that key already exists.
444
+ * Add all passed headers to the request, overriding existing ones if that key already exists. Null and undefined values cause the key to be removed.
445
445
  * @param {HeadersInit} hs
446
446
  * @returns {HttpRequestBuilder} this builder
447
447
  */
448
448
  headers(hs) {
449
449
  for (const [k, v] of new Headers(hs).entries()) {
450
- this.#headers.set(k, v);
450
+ if (v === null || v === undefined) {
451
+ this.#headers.delete(k);
452
+ } else {
453
+ this.#headers.set(k, v);
454
+ }
451
455
  }
452
456
  return this;
453
457
  }
454
458
  /**
455
- * Adds an header to the request, overriding it if it already exists.
459
+ * Adds an header to the request, overriding it if it already exists. Null and undefined values cause the key to be removed
456
460
  * @param {string} k
457
461
  * @param {string} v
458
462
  * @returns {HttpRequestBuilder} this builder
459
463
  */
460
464
  header(k, v) {
461
- this.#headers.set(k, v);
465
+ if (v === null || v === undefined) {
466
+ this.#headers.delete(k);
467
+ } else {
468
+ this.#headers.set(k, v);
469
+ }
462
470
  return this;
463
471
  }
464
472
  /**
465
- * Add all query parameters to the request, overriding existing ones if that key already exists.
473
+ * Add all query parameters to the request, overriding existing ones if that key already exists. Null and undefined values cause the key to be removed
466
474
  * @param {URLSearchParams|Record<string,string>|string[][]|string} ps
467
475
  * @returns {HttpRequestBuilder} this builder
468
476
  */
469
477
  params(ps) {
470
478
  for (const [k, v] of new URLSearchParams(ps).entries()) {
471
- this.#params.set(k, v);
479
+ if (v === null || v === undefined) {
480
+ this.#params.delete(k);
481
+ } else {
482
+ this.#params.set(k, v);
483
+ }
472
484
  }
473
485
  return this;
474
486
  }
475
487
  /**
476
- * Adds a query parameter to the request, overriding it if it already exists.
488
+ * Adds a query parameter to the request, overriding it if it already exists. Null and undefined values cause the key to be removed.
477
489
  * @param {string} k
478
490
  * @param {string} v
479
491
  * @returns {HttpRequestBuilder} this builder
480
492
  */
481
493
  param(k, v) {
482
- this.#params.set(k, v);
494
+ if (v === null || v === undefined) {
495
+ this.#params.delete(k);
496
+ } else {
497
+ this.#params.set(k, v);
498
+ }
483
499
  return this;
484
500
  }
485
501
  /**
@@ -1144,8 +1160,7 @@ var ful = (function (exports) {
1144
1160
  */
1145
1161
  static from(el) {
1146
1162
  /** @type [string, Element][] */
1147
- const namedSlots = Array.from(el.childNodes)
1148
- .filter(el => el instanceof Element)
1163
+ const namedSlots = Array.from(el.children)
1149
1164
  .filter(el => el.matches('[slot]'))
1150
1165
  .map(el => {
1151
1166
  el.remove();
@@ -1175,6 +1190,23 @@ var ful = (function (exports) {
1175
1190
  }
1176
1191
  return false;
1177
1192
  }
1193
+ static queryChildren(node, selector) {
1194
+ for (const c of node.children) {
1195
+ if (c.matches(selector)) {
1196
+ return c;
1197
+ }
1198
+ }
1199
+ return null;
1200
+ }
1201
+ queryChildrenAll(node, selector) {
1202
+ const r = [];
1203
+ for (const c of node.children) {
1204
+ if (c.matches(selector)) {
1205
+ r.push(c);
1206
+ }
1207
+ }
1208
+ return r;
1209
+ }
1178
1210
  }
1179
1211
 
1180
1212
  class TemplatesRegistry {