rekwest 2.2.0 → 2.3.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/README.md CHANGED
@@ -85,7 +85,7 @@ const file = new File(['bits'], 'file.dab');
85
85
  const readable = Readable.from('bits');
86
86
 
87
87
  const fd = new FormData({
88
- aux: Date.now(), // or [[key, value]]
88
+ aux: Date.now(), // either [[key, value]], or kv sequenceable
89
89
  });
90
90
 
91
91
  fd.append('celestial', 'payload');
package/dist/formdata.js CHANGED
@@ -87,11 +87,17 @@ class FormData {
87
87
  }
88
88
 
89
89
  constructor(input) {
90
- if (input !== undefined && ![Array, Object].includes(input?.constructor)) {
91
- throw new TypeError(`Failed to construct '${this[Symbol.toStringTag]}': parameter 1 is not of type 'Array' or 'Object'.`);
92
- } else {
93
- if (Array.isArray(input) && !input.every(it => Array.isArray(it) && it.length === 2)) {
94
- throw new TypeError(`Failed to construct '${this[Symbol.toStringTag]}': The provided value cannot be converted to a sequence.`);
90
+ if (input === Object(input) && (input?.constructor === Object || Reflect.has(input, Symbol.iterator))) {
91
+ if (input.constructor !== Object) {
92
+ input = Array.from(input);
93
+ }
94
+
95
+ if (Array.isArray(input)) {
96
+ if (!input.every(it => Array.isArray(it))) {
97
+ throw new TypeError(`Failed to construct '${this[Symbol.toStringTag]}': The provided value cannot be converted to a sequence.`);
98
+ } else if (!input.every(it => it.length === 2)) {
99
+ throw new TypeError(`Failed to construct '${this[Symbol.toStringTag]}': Sequence initializer must only contain pair elements.`);
100
+ }
95
101
  }
96
102
 
97
103
  if (input.constructor === Object) {
package/package.json CHANGED
@@ -55,5 +55,5 @@
55
55
  "test": "mocha --exit --recursive",
56
56
  "test:cover": "c8 --include=src --reporter=lcov --reporter=text npm test"
57
57
  },
58
- "version": "2.2.0"
58
+ "version": "2.3.0"
59
59
  }
package/src/formdata.mjs CHANGED
@@ -84,18 +84,23 @@ export class FormData {
84
84
  }
85
85
 
86
86
  constructor(input) {
87
- if (input !== undefined && ![
88
- Array,
89
- Object,
90
- ].includes(input?.constructor)) {
91
- throw new TypeError(`Failed to construct '${
92
- this[Symbol.toStringTag]
93
- }': parameter 1 is not of type 'Array' or 'Object'.`);
94
- } else {
95
- if (Array.isArray(input) && !input.every((it) => Array.isArray(it) && it.length === 2)) {
96
- throw new TypeError(`Failed to construct '${
97
- this[Symbol.toStringTag]
98
- }': The provided value cannot be converted to a sequence.`);
87
+ if (input === Object(input)
88
+ && (input?.constructor === Object || Reflect.has(input, Symbol.iterator))) {
89
+
90
+ if (input.constructor !== Object) {
91
+ input = Array.from(input);
92
+ }
93
+
94
+ if (Array.isArray(input)) {
95
+ if (!input.every((it) => Array.isArray(it))) {
96
+ throw new TypeError(`Failed to construct '${
97
+ this[Symbol.toStringTag]
98
+ }': The provided value cannot be converted to a sequence.`);
99
+ } else if (!input.every((it) => it.length === 2)) {
100
+ throw new TypeError(`Failed to construct '${
101
+ this[Symbol.toStringTag]
102
+ }': Sequence initializer must only contain pair elements.`);
103
+ }
99
104
  }
100
105
 
101
106
  if (input.constructor === Object) {