@micromag/data 0.3.508 → 0.3.509
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/es/index.js +4 -4
- package/lib/index.js +579 -4
- package/package.json +4 -4
package/es/index.js
CHANGED
|
@@ -6,8 +6,8 @@ import _callSuper from '@babel/runtime/helpers/callSuper';
|
|
|
6
6
|
import _inherits from '@babel/runtime/helpers/inherits';
|
|
7
7
|
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
8
8
|
import { getJSON, getCSRFHeaders, postJSON } from '@folklore/fetch';
|
|
9
|
-
import { stringify, parse } from 'query-string';
|
|
10
9
|
import { generatePath } from '@folklore/routes';
|
|
10
|
+
import queryString from 'query-string';
|
|
11
11
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
12
12
|
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
13
13
|
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
@@ -28,10 +28,10 @@ var Base = /*#__PURE__*/function () {
|
|
|
28
28
|
key: "requestGet",
|
|
29
29
|
value: function requestGet(path) {
|
|
30
30
|
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
31
|
-
var
|
|
31
|
+
var finalQueryString = query !== null ? queryString.stringify(query, {
|
|
32
32
|
arrayFormat: 'bracket'
|
|
33
33
|
}) : null;
|
|
34
|
-
return getJSON("".concat(this.getFullUrl(path)).concat(
|
|
34
|
+
return getJSON("".concat(this.getFullUrl(path)).concat(finalQueryString !== null && finalQueryString.length > 0 ? "?".concat(finalQueryString) : ''), {
|
|
35
35
|
credentials: 'include',
|
|
36
36
|
headers: getCSRFHeaders()
|
|
37
37
|
});
|
|
@@ -749,7 +749,7 @@ var useItems = function useItems(_ref) {
|
|
|
749
749
|
|
|
750
750
|
// Query
|
|
751
751
|
var query = useMemo(function () {
|
|
752
|
-
return _objectSpread({}, isString(pageQuery) ? parse(pageQuery || null, {
|
|
752
|
+
return _objectSpread({}, isString(pageQuery) ? queryString.parse(pageQuery || null, {
|
|
753
753
|
arrayFormat: 'bracket'
|
|
754
754
|
}) : pageQuery);
|
|
755
755
|
}, [pageQuery]);
|
package/lib/index.js
CHANGED
|
@@ -8,11 +8,13 @@ var _callSuper = require('@babel/runtime/helpers/callSuper');
|
|
|
8
8
|
var _inherits = require('@babel/runtime/helpers/inherits');
|
|
9
9
|
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
10
10
|
var fetch = require('@folklore/fetch');
|
|
11
|
-
var queryString = require('query-string');
|
|
12
11
|
var pathToRegexp = require('path-to-regexp');
|
|
12
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
13
13
|
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
14
|
-
var
|
|
14
|
+
var _createForOfIteratorHelper = require('@babel/runtime/helpers/createForOfIteratorHelper');
|
|
15
|
+
var _typeof = require('@babel/runtime/helpers/typeof');
|
|
15
16
|
var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
|
|
17
|
+
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
16
18
|
var isString = require('lodash/isString');
|
|
17
19
|
var contexts = require('@micromag/core/contexts');
|
|
18
20
|
|
|
@@ -32,6 +34,579 @@ function generatePath(fullPath, data) {
|
|
|
32
34
|
return fullUrlMatches !== null ? "".concat(fullUrlMatches[1]).concat(compiler(data)) : compiler(data);
|
|
33
35
|
}
|
|
34
36
|
|
|
37
|
+
var token = '%[a-f0-9]{2}';
|
|
38
|
+
var singleMatcher = new RegExp('(' + token + ')|([^%]+?)', 'gi');
|
|
39
|
+
var multiMatcher = new RegExp('(' + token + ')+', 'gi');
|
|
40
|
+
function decodeComponents(components, split) {
|
|
41
|
+
try {
|
|
42
|
+
// Try to decode the entire string first
|
|
43
|
+
return [decodeURIComponent(components.join(''))];
|
|
44
|
+
} catch (_unused) {
|
|
45
|
+
// Do nothing
|
|
46
|
+
}
|
|
47
|
+
if (components.length === 1) {
|
|
48
|
+
return components;
|
|
49
|
+
}
|
|
50
|
+
split = split || 1;
|
|
51
|
+
|
|
52
|
+
// Split the array in 2 parts
|
|
53
|
+
var left = components.slice(0, split);
|
|
54
|
+
var right = components.slice(split);
|
|
55
|
+
return Array.prototype.concat.call([], decodeComponents(left), decodeComponents(right));
|
|
56
|
+
}
|
|
57
|
+
function decode$1(input) {
|
|
58
|
+
try {
|
|
59
|
+
return decodeURIComponent(input);
|
|
60
|
+
} catch (_unused2) {
|
|
61
|
+
var tokens = input.match(singleMatcher) || [];
|
|
62
|
+
for (var i = 1; i < tokens.length; i++) {
|
|
63
|
+
input = decodeComponents(tokens, i).join('');
|
|
64
|
+
tokens = input.match(singleMatcher) || [];
|
|
65
|
+
}
|
|
66
|
+
return input;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function customDecodeURIComponent(input) {
|
|
70
|
+
// Keep track of all the replacements and prefill the map with the `BOM`
|
|
71
|
+
var replaceMap = {
|
|
72
|
+
'%FE%FF': "\uFFFD\uFFFD",
|
|
73
|
+
'%FF%FE': "\uFFFD\uFFFD"
|
|
74
|
+
};
|
|
75
|
+
var match = multiMatcher.exec(input);
|
|
76
|
+
while (match) {
|
|
77
|
+
try {
|
|
78
|
+
// Decode as big chunks as possible
|
|
79
|
+
replaceMap[match[0]] = decodeURIComponent(match[0]);
|
|
80
|
+
} catch (_unused3) {
|
|
81
|
+
var result = decode$1(match[0]);
|
|
82
|
+
if (result !== match[0]) {
|
|
83
|
+
replaceMap[match[0]] = result;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
match = multiMatcher.exec(input);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Add `%C2` at the end of the map to make sure it does not replace the combinator before everything else
|
|
90
|
+
replaceMap['%C2'] = "\uFFFD";
|
|
91
|
+
var entries = Object.keys(replaceMap);
|
|
92
|
+
for (var _i = 0, _entries = entries; _i < _entries.length; _i++) {
|
|
93
|
+
var key = _entries[_i];
|
|
94
|
+
// Replace all decoded components
|
|
95
|
+
input = input.replace(new RegExp(key, 'g'), replaceMap[key]);
|
|
96
|
+
}
|
|
97
|
+
return input;
|
|
98
|
+
}
|
|
99
|
+
function decodeUriComponent(encodedURI) {
|
|
100
|
+
if (typeof encodedURI !== 'string') {
|
|
101
|
+
throw new TypeError('Expected `encodedURI` to be of type `string`, got `' + _typeof(encodedURI) + '`');
|
|
102
|
+
}
|
|
103
|
+
try {
|
|
104
|
+
// Try the built in decoder first
|
|
105
|
+
return decodeURIComponent(encodedURI);
|
|
106
|
+
} catch (_unused4) {
|
|
107
|
+
// Fallback to a more advanced decoder
|
|
108
|
+
return customDecodeURIComponent(encodedURI);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function splitOnFirst(string, separator) {
|
|
113
|
+
if (!(typeof string === 'string' && typeof separator === 'string')) {
|
|
114
|
+
throw new TypeError('Expected the arguments to be of type `string`');
|
|
115
|
+
}
|
|
116
|
+
if (string === '' || separator === '') {
|
|
117
|
+
return [];
|
|
118
|
+
}
|
|
119
|
+
var separatorIndex = string.indexOf(separator);
|
|
120
|
+
if (separatorIndex === -1) {
|
|
121
|
+
return [];
|
|
122
|
+
}
|
|
123
|
+
return [string.slice(0, separatorIndex), string.slice(separatorIndex + separator.length)];
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function includeKeys(object, predicate) {
|
|
127
|
+
var result = {};
|
|
128
|
+
if (Array.isArray(predicate)) {
|
|
129
|
+
var _iterator = _createForOfIteratorHelper(predicate),
|
|
130
|
+
_step;
|
|
131
|
+
try {
|
|
132
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
133
|
+
var key = _step.value;
|
|
134
|
+
var descriptor = Object.getOwnPropertyDescriptor(object, key);
|
|
135
|
+
if (descriptor !== null && descriptor !== void 0 && descriptor.enumerable) {
|
|
136
|
+
Object.defineProperty(result, key, descriptor);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
} catch (err) {
|
|
140
|
+
_iterator.e(err);
|
|
141
|
+
} finally {
|
|
142
|
+
_iterator.f();
|
|
143
|
+
}
|
|
144
|
+
} else {
|
|
145
|
+
// `Reflect.ownKeys()` is required to retrieve symbol properties
|
|
146
|
+
var _iterator2 = _createForOfIteratorHelper(Reflect.ownKeys(object)),
|
|
147
|
+
_step2;
|
|
148
|
+
try {
|
|
149
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
150
|
+
var _key = _step2.value;
|
|
151
|
+
var _descriptor = Object.getOwnPropertyDescriptor(object, _key);
|
|
152
|
+
if (_descriptor.enumerable) {
|
|
153
|
+
var value = object[_key];
|
|
154
|
+
if (predicate(_key, value, object)) {
|
|
155
|
+
Object.defineProperty(result, _key, _descriptor);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
} catch (err) {
|
|
160
|
+
_iterator2.e(err);
|
|
161
|
+
} finally {
|
|
162
|
+
_iterator2.f();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return result;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
var isNullOrUndefined = function isNullOrUndefined(value) {
|
|
169
|
+
return value === null || value === undefined;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
// eslint-disable-next-line unicorn/prefer-code-point
|
|
173
|
+
var strictUriEncode = function strictUriEncode(string) {
|
|
174
|
+
return encodeURIComponent(string).replaceAll(/[!'()*]/g, function (x) {
|
|
175
|
+
return "%".concat(x.charCodeAt(0).toString(16).toUpperCase());
|
|
176
|
+
});
|
|
177
|
+
};
|
|
178
|
+
var encodeFragmentIdentifier = Symbol('encodeFragmentIdentifier');
|
|
179
|
+
function encoderForArrayFormat(options) {
|
|
180
|
+
switch (options.arrayFormat) {
|
|
181
|
+
case 'index':
|
|
182
|
+
{
|
|
183
|
+
return function (key) {
|
|
184
|
+
return function (result, value) {
|
|
185
|
+
var index = result.length;
|
|
186
|
+
if (value === undefined || options.skipNull && value === null || options.skipEmptyString && value === '') {
|
|
187
|
+
return result;
|
|
188
|
+
}
|
|
189
|
+
if (value === null) {
|
|
190
|
+
return [].concat(_toConsumableArray(result), [[encode(key, options), '[', index, ']'].join('')]);
|
|
191
|
+
}
|
|
192
|
+
return [].concat(_toConsumableArray(result), [[encode(key, options), '[', encode(index, options), ']=', encode(value, options)].join('')]);
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
case 'bracket':
|
|
197
|
+
{
|
|
198
|
+
return function (key) {
|
|
199
|
+
return function (result, value) {
|
|
200
|
+
if (value === undefined || options.skipNull && value === null || options.skipEmptyString && value === '') {
|
|
201
|
+
return result;
|
|
202
|
+
}
|
|
203
|
+
if (value === null) {
|
|
204
|
+
return [].concat(_toConsumableArray(result), [[encode(key, options), '[]'].join('')]);
|
|
205
|
+
}
|
|
206
|
+
return [].concat(_toConsumableArray(result), [[encode(key, options), '[]=', encode(value, options)].join('')]);
|
|
207
|
+
};
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
case 'colon-list-separator':
|
|
211
|
+
{
|
|
212
|
+
return function (key) {
|
|
213
|
+
return function (result, value) {
|
|
214
|
+
if (value === undefined || options.skipNull && value === null || options.skipEmptyString && value === '') {
|
|
215
|
+
return result;
|
|
216
|
+
}
|
|
217
|
+
if (value === null) {
|
|
218
|
+
return [].concat(_toConsumableArray(result), [[encode(key, options), ':list='].join('')]);
|
|
219
|
+
}
|
|
220
|
+
return [].concat(_toConsumableArray(result), [[encode(key, options), ':list=', encode(value, options)].join('')]);
|
|
221
|
+
};
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
case 'comma':
|
|
225
|
+
case 'separator':
|
|
226
|
+
case 'bracket-separator':
|
|
227
|
+
{
|
|
228
|
+
var keyValueSeparator = options.arrayFormat === 'bracket-separator' ? '[]=' : '=';
|
|
229
|
+
return function (key) {
|
|
230
|
+
return function (result, value) {
|
|
231
|
+
if (value === undefined || options.skipNull && value === null || options.skipEmptyString && value === '') {
|
|
232
|
+
return result;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// Translate null to an empty string so that it doesn't serialize as 'null'
|
|
236
|
+
value = value === null ? '' : value;
|
|
237
|
+
if (result.length === 0) {
|
|
238
|
+
return [[encode(key, options), keyValueSeparator, encode(value, options)].join('')];
|
|
239
|
+
}
|
|
240
|
+
return [[result, encode(value, options)].join(options.arrayFormatSeparator)];
|
|
241
|
+
};
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
default:
|
|
245
|
+
{
|
|
246
|
+
return function (key) {
|
|
247
|
+
return function (result, value) {
|
|
248
|
+
if (value === undefined || options.skipNull && value === null || options.skipEmptyString && value === '') {
|
|
249
|
+
return result;
|
|
250
|
+
}
|
|
251
|
+
if (value === null) {
|
|
252
|
+
return [].concat(_toConsumableArray(result), [encode(key, options)]);
|
|
253
|
+
}
|
|
254
|
+
return [].concat(_toConsumableArray(result), [[encode(key, options), '=', encode(value, options)].join('')]);
|
|
255
|
+
};
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
function parserForArrayFormat(options) {
|
|
261
|
+
var result;
|
|
262
|
+
switch (options.arrayFormat) {
|
|
263
|
+
case 'index':
|
|
264
|
+
{
|
|
265
|
+
return function (key, value, accumulator) {
|
|
266
|
+
result = /\[(\d*)]$/.exec(key);
|
|
267
|
+
key = key.replace(/\[\d*]$/, '');
|
|
268
|
+
if (!result) {
|
|
269
|
+
accumulator[key] = value;
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
if (accumulator[key] === undefined) {
|
|
273
|
+
accumulator[key] = {};
|
|
274
|
+
}
|
|
275
|
+
accumulator[key][result[1]] = value;
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
case 'bracket':
|
|
279
|
+
{
|
|
280
|
+
return function (key, value, accumulator) {
|
|
281
|
+
result = /(\[])$/.exec(key);
|
|
282
|
+
key = key.replace(/\[]$/, '');
|
|
283
|
+
if (!result) {
|
|
284
|
+
accumulator[key] = value;
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
if (accumulator[key] === undefined) {
|
|
288
|
+
accumulator[key] = [value];
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
accumulator[key] = [].concat(_toConsumableArray(accumulator[key]), [value]);
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
case 'colon-list-separator':
|
|
295
|
+
{
|
|
296
|
+
return function (key, value, accumulator) {
|
|
297
|
+
result = /(:list)$/.exec(key);
|
|
298
|
+
key = key.replace(/:list$/, '');
|
|
299
|
+
if (!result) {
|
|
300
|
+
accumulator[key] = value;
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
if (accumulator[key] === undefined) {
|
|
304
|
+
accumulator[key] = [value];
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
accumulator[key] = [].concat(_toConsumableArray(accumulator[key]), [value]);
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
case 'comma':
|
|
311
|
+
case 'separator':
|
|
312
|
+
{
|
|
313
|
+
return function (key, value, accumulator) {
|
|
314
|
+
var isArray = typeof value === 'string' && value.includes(options.arrayFormatSeparator);
|
|
315
|
+
var isEncodedArray = typeof value === 'string' && !isArray && decode(value, options).includes(options.arrayFormatSeparator);
|
|
316
|
+
value = isEncodedArray ? decode(value, options) : value;
|
|
317
|
+
var newValue = isArray || isEncodedArray ? value.split(options.arrayFormatSeparator).map(function (item) {
|
|
318
|
+
return decode(item, options);
|
|
319
|
+
}) : value === null ? value : decode(value, options);
|
|
320
|
+
accumulator[key] = newValue;
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
case 'bracket-separator':
|
|
324
|
+
{
|
|
325
|
+
return function (key, value, accumulator) {
|
|
326
|
+
var isArray = /(\[])$/.test(key);
|
|
327
|
+
key = key.replace(/\[]$/, '');
|
|
328
|
+
if (!isArray) {
|
|
329
|
+
accumulator[key] = value ? decode(value, options) : value;
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
var arrayValue = value === null ? [] : value.split(options.arrayFormatSeparator).map(function (item) {
|
|
333
|
+
return decode(item, options);
|
|
334
|
+
});
|
|
335
|
+
if (accumulator[key] === undefined) {
|
|
336
|
+
accumulator[key] = arrayValue;
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
accumulator[key] = [].concat(_toConsumableArray(accumulator[key]), _toConsumableArray(arrayValue));
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
default:
|
|
343
|
+
{
|
|
344
|
+
return function (key, value, accumulator) {
|
|
345
|
+
if (accumulator[key] === undefined) {
|
|
346
|
+
accumulator[key] = value;
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
accumulator[key] = [].concat(_toConsumableArray([accumulator[key]].flat()), [value]);
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
function validateArrayFormatSeparator(value) {
|
|
355
|
+
if (typeof value !== 'string' || value.length !== 1) {
|
|
356
|
+
throw new TypeError('arrayFormatSeparator must be single character string');
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
function encode(value, options) {
|
|
360
|
+
if (options.encode) {
|
|
361
|
+
return options.strict ? strictUriEncode(value) : encodeURIComponent(value);
|
|
362
|
+
}
|
|
363
|
+
return value;
|
|
364
|
+
}
|
|
365
|
+
function decode(value, options) {
|
|
366
|
+
if (options.decode) {
|
|
367
|
+
return decodeUriComponent(value);
|
|
368
|
+
}
|
|
369
|
+
return value;
|
|
370
|
+
}
|
|
371
|
+
function keysSorter(input) {
|
|
372
|
+
if (Array.isArray(input)) {
|
|
373
|
+
return input.sort();
|
|
374
|
+
}
|
|
375
|
+
if (_typeof(input) === 'object') {
|
|
376
|
+
return keysSorter(Object.keys(input)).sort(function (a, b) {
|
|
377
|
+
return Number(a) - Number(b);
|
|
378
|
+
}).map(function (key) {
|
|
379
|
+
return input[key];
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
return input;
|
|
383
|
+
}
|
|
384
|
+
function removeHash(input) {
|
|
385
|
+
var hashStart = input.indexOf('#');
|
|
386
|
+
if (hashStart !== -1) {
|
|
387
|
+
input = input.slice(0, hashStart);
|
|
388
|
+
}
|
|
389
|
+
return input;
|
|
390
|
+
}
|
|
391
|
+
function getHash(url) {
|
|
392
|
+
var hash = '';
|
|
393
|
+
var hashStart = url.indexOf('#');
|
|
394
|
+
if (hashStart !== -1) {
|
|
395
|
+
hash = url.slice(hashStart);
|
|
396
|
+
}
|
|
397
|
+
return hash;
|
|
398
|
+
}
|
|
399
|
+
function parseValue(value, options) {
|
|
400
|
+
if (options.parseNumbers && !Number.isNaN(Number(value)) && typeof value === 'string' && value.trim() !== '') {
|
|
401
|
+
value = Number(value);
|
|
402
|
+
} else if (options.parseBooleans && value !== null && (value.toLowerCase() === 'true' || value.toLowerCase() === 'false')) {
|
|
403
|
+
value = value.toLowerCase() === 'true';
|
|
404
|
+
}
|
|
405
|
+
return value;
|
|
406
|
+
}
|
|
407
|
+
function extract(input) {
|
|
408
|
+
input = removeHash(input);
|
|
409
|
+
var queryStart = input.indexOf('?');
|
|
410
|
+
if (queryStart === -1) {
|
|
411
|
+
return '';
|
|
412
|
+
}
|
|
413
|
+
return input.slice(queryStart + 1);
|
|
414
|
+
}
|
|
415
|
+
function parse(query, options) {
|
|
416
|
+
options = _objectSpread({
|
|
417
|
+
decode: true,
|
|
418
|
+
sort: true,
|
|
419
|
+
arrayFormat: 'none',
|
|
420
|
+
arrayFormatSeparator: ',',
|
|
421
|
+
parseNumbers: false,
|
|
422
|
+
parseBooleans: false
|
|
423
|
+
}, options);
|
|
424
|
+
validateArrayFormatSeparator(options.arrayFormatSeparator);
|
|
425
|
+
var formatter = parserForArrayFormat(options);
|
|
426
|
+
|
|
427
|
+
// Create an object with no prototype
|
|
428
|
+
var returnValue = Object.create(null);
|
|
429
|
+
if (typeof query !== 'string') {
|
|
430
|
+
return returnValue;
|
|
431
|
+
}
|
|
432
|
+
query = query.trim().replace(/^[?#&]/, '');
|
|
433
|
+
if (!query) {
|
|
434
|
+
return returnValue;
|
|
435
|
+
}
|
|
436
|
+
var _iterator = _createForOfIteratorHelper(query.split('&')),
|
|
437
|
+
_step;
|
|
438
|
+
try {
|
|
439
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
440
|
+
var parameter = _step.value;
|
|
441
|
+
if (parameter === '') {
|
|
442
|
+
continue;
|
|
443
|
+
}
|
|
444
|
+
var parameter_ = options.decode ? parameter.replaceAll('+', ' ') : parameter;
|
|
445
|
+
var _splitOnFirst = splitOnFirst(parameter_, '='),
|
|
446
|
+
_splitOnFirst2 = _slicedToArray(_splitOnFirst, 2),
|
|
447
|
+
_key = _splitOnFirst2[0],
|
|
448
|
+
_value = _splitOnFirst2[1];
|
|
449
|
+
if (_key === undefined) {
|
|
450
|
+
_key = parameter_;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
// Missing `=` should be `null`:
|
|
454
|
+
// http://w3.org/TR/2012/WD-url-20120524/#collect-url-parameters
|
|
455
|
+
_value = _value === undefined ? null : ['comma', 'separator', 'bracket-separator'].includes(options.arrayFormat) ? _value : decode(_value, options);
|
|
456
|
+
formatter(decode(_key, options), _value, returnValue);
|
|
457
|
+
}
|
|
458
|
+
} catch (err) {
|
|
459
|
+
_iterator.e(err);
|
|
460
|
+
} finally {
|
|
461
|
+
_iterator.f();
|
|
462
|
+
}
|
|
463
|
+
for (var _i = 0, _Object$entries = Object.entries(returnValue); _i < _Object$entries.length; _i++) {
|
|
464
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
465
|
+
key = _Object$entries$_i[0],
|
|
466
|
+
value = _Object$entries$_i[1];
|
|
467
|
+
if (_typeof(value) === 'object' && value !== null) {
|
|
468
|
+
for (var _i2 = 0, _Object$entries2 = Object.entries(value); _i2 < _Object$entries2.length; _i2++) {
|
|
469
|
+
var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
|
|
470
|
+
key2 = _Object$entries2$_i[0],
|
|
471
|
+
value2 = _Object$entries2$_i[1];
|
|
472
|
+
value[key2] = parseValue(value2, options);
|
|
473
|
+
}
|
|
474
|
+
} else {
|
|
475
|
+
returnValue[key] = parseValue(value, options);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
if (options.sort === false) {
|
|
479
|
+
return returnValue;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// TODO: Remove the use of `reduce`.
|
|
483
|
+
// eslint-disable-next-line unicorn/no-array-reduce
|
|
484
|
+
return (options.sort === true ? Object.keys(returnValue).sort() : Object.keys(returnValue).sort(options.sort)).reduce(function (result, key) {
|
|
485
|
+
var value = returnValue[key];
|
|
486
|
+
result[key] = Boolean(value) && _typeof(value) === 'object' && !Array.isArray(value) ? keysSorter(value) : value;
|
|
487
|
+
return result;
|
|
488
|
+
}, Object.create(null));
|
|
489
|
+
}
|
|
490
|
+
function stringify(object, options) {
|
|
491
|
+
if (!object) {
|
|
492
|
+
return '';
|
|
493
|
+
}
|
|
494
|
+
options = _objectSpread({
|
|
495
|
+
encode: true,
|
|
496
|
+
strict: true,
|
|
497
|
+
arrayFormat: 'none',
|
|
498
|
+
arrayFormatSeparator: ','
|
|
499
|
+
}, options);
|
|
500
|
+
validateArrayFormatSeparator(options.arrayFormatSeparator);
|
|
501
|
+
var shouldFilter = function shouldFilter(key) {
|
|
502
|
+
return options.skipNull && isNullOrUndefined(object[key]) || options.skipEmptyString && object[key] === '';
|
|
503
|
+
};
|
|
504
|
+
var formatter = encoderForArrayFormat(options);
|
|
505
|
+
var objectCopy = {};
|
|
506
|
+
for (var _i3 = 0, _Object$entries3 = Object.entries(object); _i3 < _Object$entries3.length; _i3++) {
|
|
507
|
+
var _Object$entries3$_i = _slicedToArray(_Object$entries3[_i3], 2),
|
|
508
|
+
key = _Object$entries3$_i[0],
|
|
509
|
+
value = _Object$entries3$_i[1];
|
|
510
|
+
if (!shouldFilter(key)) {
|
|
511
|
+
objectCopy[key] = value;
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
var keys = Object.keys(objectCopy);
|
|
515
|
+
if (options.sort !== false) {
|
|
516
|
+
keys.sort(options.sort);
|
|
517
|
+
}
|
|
518
|
+
return keys.map(function (key) {
|
|
519
|
+
var value = object[key];
|
|
520
|
+
if (value === undefined) {
|
|
521
|
+
return '';
|
|
522
|
+
}
|
|
523
|
+
if (value === null) {
|
|
524
|
+
return encode(key, options);
|
|
525
|
+
}
|
|
526
|
+
if (Array.isArray(value)) {
|
|
527
|
+
if (value.length === 0 && options.arrayFormat === 'bracket-separator') {
|
|
528
|
+
return encode(key, options) + '[]';
|
|
529
|
+
}
|
|
530
|
+
return value.reduce(formatter(key), []).join('&');
|
|
531
|
+
}
|
|
532
|
+
return encode(key, options) + '=' + encode(value, options);
|
|
533
|
+
}).filter(function (x) {
|
|
534
|
+
return x.length > 0;
|
|
535
|
+
}).join('&');
|
|
536
|
+
}
|
|
537
|
+
function parseUrl(url, options) {
|
|
538
|
+
var _url_$split$, _url_;
|
|
539
|
+
options = _objectSpread({
|
|
540
|
+
decode: true
|
|
541
|
+
}, options);
|
|
542
|
+
var _splitOnFirst3 = splitOnFirst(url, '#'),
|
|
543
|
+
_splitOnFirst4 = _slicedToArray(_splitOnFirst3, 2),
|
|
544
|
+
url_ = _splitOnFirst4[0],
|
|
545
|
+
hash = _splitOnFirst4[1];
|
|
546
|
+
if (url_ === undefined) {
|
|
547
|
+
url_ = url;
|
|
548
|
+
}
|
|
549
|
+
return _objectSpread({
|
|
550
|
+
url: (_url_$split$ = (_url_ = url_) === null || _url_ === void 0 || (_url_ = _url_.split('?')) === null || _url_ === void 0 ? void 0 : _url_[0]) !== null && _url_$split$ !== void 0 ? _url_$split$ : '',
|
|
551
|
+
query: parse(extract(url), options)
|
|
552
|
+
}, options && options.parseFragmentIdentifier && hash ? {
|
|
553
|
+
fragmentIdentifier: decode(hash, options)
|
|
554
|
+
} : {});
|
|
555
|
+
}
|
|
556
|
+
function stringifyUrl(object, options) {
|
|
557
|
+
options = _objectSpread(_defineProperty({
|
|
558
|
+
encode: true,
|
|
559
|
+
strict: true
|
|
560
|
+
}, encodeFragmentIdentifier, true), options);
|
|
561
|
+
var url = removeHash(object.url).split('?')[0] || '';
|
|
562
|
+
var queryFromUrl = extract(object.url);
|
|
563
|
+
var query = _objectSpread(_objectSpread({}, parse(queryFromUrl, {
|
|
564
|
+
sort: false
|
|
565
|
+
})), object.query);
|
|
566
|
+
var queryString = stringify(query, options);
|
|
567
|
+
queryString && (queryString = "?".concat(queryString));
|
|
568
|
+
var hash = getHash(object.url);
|
|
569
|
+
if (typeof object.fragmentIdentifier === 'string') {
|
|
570
|
+
var urlObjectForFragmentEncode = new URL(url);
|
|
571
|
+
urlObjectForFragmentEncode.hash = object.fragmentIdentifier;
|
|
572
|
+
hash = options[encodeFragmentIdentifier] ? urlObjectForFragmentEncode.hash : "#".concat(object.fragmentIdentifier);
|
|
573
|
+
}
|
|
574
|
+
return "".concat(url).concat(queryString).concat(hash);
|
|
575
|
+
}
|
|
576
|
+
function pick(input, filter, options) {
|
|
577
|
+
options = _objectSpread(_defineProperty({
|
|
578
|
+
parseFragmentIdentifier: true
|
|
579
|
+
}, encodeFragmentIdentifier, false), options);
|
|
580
|
+
var _parseUrl = parseUrl(input, options),
|
|
581
|
+
url = _parseUrl.url,
|
|
582
|
+
query = _parseUrl.query,
|
|
583
|
+
fragmentIdentifier = _parseUrl.fragmentIdentifier;
|
|
584
|
+
return stringifyUrl({
|
|
585
|
+
url: url,
|
|
586
|
+
query: includeKeys(query, filter),
|
|
587
|
+
fragmentIdentifier: fragmentIdentifier
|
|
588
|
+
}, options);
|
|
589
|
+
}
|
|
590
|
+
function exclude(input, filter, options) {
|
|
591
|
+
var exclusionFilter = Array.isArray(filter) ? function (key) {
|
|
592
|
+
return !filter.includes(key);
|
|
593
|
+
} : function (key, value) {
|
|
594
|
+
return !filter(key, value);
|
|
595
|
+
};
|
|
596
|
+
return pick(input, exclusionFilter, options);
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
var queryString = /*#__PURE__*/Object.freeze({
|
|
600
|
+
__proto__: null,
|
|
601
|
+
exclude: exclude,
|
|
602
|
+
extract: extract,
|
|
603
|
+
parse: parse,
|
|
604
|
+
parseUrl: parseUrl,
|
|
605
|
+
pick: pick,
|
|
606
|
+
stringify: stringify,
|
|
607
|
+
stringifyUrl: stringifyUrl
|
|
608
|
+
});
|
|
609
|
+
|
|
35
610
|
var Base = /*#__PURE__*/function () {
|
|
36
611
|
function Base() {
|
|
37
612
|
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
@@ -46,10 +621,10 @@ var Base = /*#__PURE__*/function () {
|
|
|
46
621
|
key: "requestGet",
|
|
47
622
|
value: function requestGet(path) {
|
|
48
623
|
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
49
|
-
var
|
|
624
|
+
var finalQueryString = query !== null ? queryString.stringify(query, {
|
|
50
625
|
arrayFormat: 'bracket'
|
|
51
626
|
}) : null;
|
|
52
|
-
return fetch.getJSON("".concat(this.getFullUrl(path)).concat(
|
|
627
|
+
return fetch.getJSON("".concat(this.getFullUrl(path)).concat(finalQueryString !== null && finalQueryString.length > 0 ? "?".concat(finalQueryString) : ''), {
|
|
53
628
|
credentials: 'include',
|
|
54
629
|
headers: fetch.getCSRFHeaders()
|
|
55
630
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@micromag/data",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.509",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"keywords": [
|
|
@@ -60,14 +60,14 @@
|
|
|
60
60
|
"@babel/runtime": "^7.13.10",
|
|
61
61
|
"@folklore/fetch": "^0.1.17",
|
|
62
62
|
"@folklore/routes": "^0.2.27",
|
|
63
|
-
"@micromag/core": "^0.3.
|
|
63
|
+
"@micromag/core": "^0.3.509",
|
|
64
64
|
"lodash": "^4.17.21",
|
|
65
65
|
"prop-types": "^15.7.2",
|
|
66
|
-
"query-string": "^
|
|
66
|
+
"query-string": "^9.0.0"
|
|
67
67
|
},
|
|
68
68
|
"publishConfig": {
|
|
69
69
|
"access": "public",
|
|
70
70
|
"registry": "https://registry.npmjs.org/"
|
|
71
71
|
},
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "28ca6abf74ab585d218a4918b415b7d0564e5a09"
|
|
73
73
|
}
|