@osimatic/helpers-js 1.5.35 → 1.5.37
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/network.js +20 -0
- package/package.json +1 -1
package/network.js
CHANGED
|
@@ -307,6 +307,26 @@ class UrlAndQueryString {
|
|
|
307
307
|
return str.substr(0, strpos);
|
|
308
308
|
}
|
|
309
309
|
|
|
310
|
+
/**
|
|
311
|
+
* Match query string parameters to a list of known form field names.
|
|
312
|
+
* Handles array fields (e.g. "foo[]"): if the field expects an array but the value is scalar, it wraps it.
|
|
313
|
+
* @param {object} queryStringFilters - key/value pairs from the query string
|
|
314
|
+
* @param {string[]} listOfPossibleFieldNames - list of accepted field names (e.g. ['foo', 'bar[]'])
|
|
315
|
+
* @returns {object} filtered and normalized parameters
|
|
316
|
+
*/
|
|
317
|
+
static matchQueryParamsToFormFields(queryStringFilters, listOfPossibleFieldNames) {
|
|
318
|
+
const result = {};
|
|
319
|
+
Object.keys(queryStringFilters).forEach(key => {
|
|
320
|
+
const value = queryStringFilters[key];
|
|
321
|
+
if (listOfPossibleFieldNames.indexOf(key + (Array.isArray(value) ? '[]' : '')) !== -1) {
|
|
322
|
+
result[key] = value;
|
|
323
|
+
} else if (!Array.isArray(value) && listOfPossibleFieldNames.indexOf(key + '[]') !== -1) {
|
|
324
|
+
result[key] = [value];
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
return result;
|
|
328
|
+
}
|
|
329
|
+
|
|
310
330
|
}
|
|
311
331
|
|
|
312
332
|
module.exports = { Cookie, UrlAndQueryString };
|