mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: [`querystring`](https://www.npmjs.com/package/querystring) package is deprecated. In this Pull Request I've replaced usage of `querystring` with `URLSearchParam` what is recommended by Node.js. It's also causing a warning when installing dependencies inside a React Native app: ``` warning react-native > react-native/community-cli-plugin > querystring@0.2.1: The querystring API is considered Legacy. new code should use the URLSearchParams API instead. ``` ## Changelog: [INTERNAL] [FIXED] - Replace `querystring` package with `URLSearchParam` Pull Request resolved: https://github.com/facebook/react-native/pull/45125 Test Plan: Params should be parsed in the same way and warning shouldn't be presented. js1 jest xplat/js/tools/metro/packages/metro/src/cli/__tests__/parseKeyValueParamArray-test.js Reviewed By: cipolleschi Differential Revision: D58948498 Pulled By: GijsWeterings fbshipit-source-id: 79b1f7b3feae230d2d3641205c513b98b3fda511
32 lines
850 B
JavaScript
32 lines
850 B
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow strict-local
|
|
* @format
|
|
* @oncall react_native
|
|
*/
|
|
|
|
export default function parseKeyValueParamArray(
|
|
keyValueArray: $ReadOnlyArray<string>,
|
|
): Record<string, string> {
|
|
const result = {};
|
|
|
|
for (const item of keyValueArray) {
|
|
if (item.indexOf('=') === -1) {
|
|
throw new Error('Expected parameter to include "=" but found: ' + item);
|
|
}
|
|
if (item.indexOf('&') !== -1) {
|
|
throw new Error('Parameter cannot include "&" but found: ' + item);
|
|
}
|
|
const params = new URLSearchParams(item);
|
|
params.forEach((value, key) => {
|
|
// $FlowExpectedError[prop-missing]
|
|
result[key] = value;
|
|
});
|
|
}
|
|
return result;
|
|
}
|