How to use the query-string.stringify function in query-string

To help you get started, we’ve selected a few query-string examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github focallocal / fl-maps / imports / client / ui / app.js View on Github external
function changeHistory({ pathname = null, params, push }) {
  const p = Object.assign(params);
  Object.keys(p).forEach(key => p[key] === undefined && delete p[key]);
  const s = qs.parse(window.location.search);
  Object.assign(s, p);
  Object.keys(s).forEach(key => s[key] === null && delete s[key]);
  const search = qs.stringify(s);
  //############################################################################
  // TERRIBLE WORKAROUND FOR ISSUE https://github.com/focallocal/fl-maps/issues/742
  if (pathname && pathname !== location.pathname) {
    console.log("##########", pathname + "?" + search);
    location.href = pathname + "?" + search;
    return;
  }
  //############################################################################
  pathname = pathname || window.location.pathname;
  if (push) {
    history.push({ pathname, search });
  } else {
    history.replace({ pathname, search });
  }
}
github stellar / js-stellar-wallets / src / transfers / WithdrawProvider.ts View on Github external
public async startWithdraw(
    params: WithdrawRequest,
  ): Promise {
    const request = { ...params, account: this.account };
    const isAuthRequired = this.getAuthStatus("withdraw", params.asset_code);
    const qs = queryString.stringify(request);

    const response = await fetch(`${this.transferServer}/withdraw?${qs}`, {
      headers: isAuthRequired ? this.getHeaders() : undefined,
    });
    const json = (await response.json()) as TransferResponse;

    if (json.error) {
      const error: TransferError = new Error(json.error);
      error.originalResponse = json;
      throw error;
    }

    // if this was an auth-required token, insert the JWT
    if (
      isAuthRequired &&
      json.type === TransferResponseType.interactive_customer_info_needed &&
github WebbyLab / itsquiz-wall / shared / api / ApiClient.js View on Github external
request({ url, method, params = {}, body }) {
        if (this.authToken) {
            /* eslint-disable */
            params.token = this.authToken;
            /* eslint-enable */
        }

        const urlWithQuery = `${url}?${queryString.stringify(params)}`;

        const init = {
            method,
            headers: {
                Accept: 'application/json',
                'Content-Type': 'application/json'
            }
        };

        if (method !== 'get' && method !== 'head') {
            init.body = JSON.stringify(body);
        }

        return fetch(`${this.prefix}/${urlWithQuery}`, init).then(res => {
            if (res.status >= 400) {
                throw new Error('Bad response from server');
github choerodon / manager-service / react / src / app / iam / containers / global / api-test / APIDetail.js View on Github external
componentWillMount() {
    if (APITestStore.getApiDetail.description === '[]') {
      const { controller, version, service, operationId } = this.state;
      const queryObj = {
        version,
        operation_id: operationId,
      };
      defaultAxios.get(`${urlPrefix}/manager/v1/swaggers/${service}/controllers/${controller}/paths?${querystring.stringify(queryObj)}`).then((data) => {
        data.paths.some((item) => {
          if (item.operationId === operationId) {
            const { basePath, url } = item;
            APITestStore.setApiDetail(item);
            this.setState({
              loading: false,
              requestUrl: `${urlPrefix}${basePath}${url}`,
            });
            return true;
          }
          return false;
        });
      });
    } else {
      const { basePath, url } = APITestStore.getApiDetail;
      this.setState({
github slava-lu / enterprise-react-2019 / src / utils / fetchData.js View on Github external
export const sendDataWithParams = (baseUrl, method, params, bodyObj) => {
  const { url, query } = queryString.parseUrl(baseUrl);
  const newQueryString = queryString.stringify({ ...query, ...params });
  const newURL = newQueryString ? `${url}?${newQueryString}` : url;

  return fetchData(newURL, {
    method,
    mode: 'cors',
    cache: 'default',
    redirect: 'follow',
    headers: {
      'Accept': 'application/json',
    },
    body: bodyObj ? JSON.stringify(bodyObj) : null,
  });
};
github EventKit / eventkit-cloud / eventkit_cloud / ui / static / ui / app / components / UserGroupsPage / UserGroupsPage.tsx View on Github external
private handleLoadLess() {
        const query = queryString.parse(this.props.location.search);
        query.page_size = (Number(query.page_size) - this.pageSize).toString();
        history.push({ ...this.props.location, "search": queryString.stringify(query) });
    }
github leocabeza / the-movie-db / src / utils / utils.js View on Github external
'content-type': 'application/json;charset=utf-8',
    };
    let finalUrl = usev4 ? originalUrl : `${originalUrl}api_key=${v3Key}&`;
    const method = httpMethod.toLowerCase();
    const v4Token = userAccessToken ? userAccessToken : v4Key;
    const headers = usev4
      ? { ...originalHeaders, authorization: `Bearer ${v4Token}` }
      : originalHeaders;

    const fetchOptions = {
      method,
      headers,
    };

    if (['get', 'delete'].includes(method)) {
      finalUrl = finalUrl.concat(queryString.stringify(data));
    } else {
      fetchOptions.body = prepareData(data);
    }

    const response = await fetch(finalUrl, fetchOptions);

    if (response.ok) {
      return await response.json();
    }

    throw new Error(response.statusText);
  } catch (error) {
    return Promise.reject(error);
  }
};
github choerodon / choerodon-front-iam / iam / src / app / iam / containers / global / instance / Instance.js View on Github external
page: current - 1,
      size: pageSize,
      instanceId,
      version,
      params,
      service: serviceName,
    };
    if (columnKey) {
      const sorter = [];
      sorter.push(columnKey);
      if (order === 'asc') {
        sorter.push('asc');
      }
      queryObj.sort = sorter.join(',');
    }
    return axios.get(`/manager/v1/instances?${querystring.stringify(queryObj)}`);
  }
github mozilla / addons-code-manager / src / components / DiffView / index.tsx View on Github external
if (scrollTo === ScrollTarget.firstDiff) {
          anchor = _getRelativeDiffAnchor({ diff });
        } else {
          const anchors = _getDiffAnchors(diff);
          if (anchors.length) {
            anchor = anchors[anchors.length - 1];
          }
        }
        if (anchor) {
          const newParams = { ...queryParams };

          delete newParams.scrollTo;
          const newLocation = {
            ...location,
            hash: `#${anchor}`,
            search: queryString.stringify(newParams),
          };

          history.push(newLocation);
        }
      }
    }

    if (!location.hash.length) {
      return;
    }

    const element = _document.querySelector(location.hash);

    if (element) {
      element.scrollIntoView();
    }
github openfun / richie / src / frontend / js / components / PaginateCourseSearch / index.spec.tsx View on Github external
const makeHistoryOf: (params: any) => History = (params) => [
    {
      state: { name: 'courseSearch', data: { params } },
      title: '',
      url: `/search?${stringify(params)}`,
    },
    historyPushState,
    historyReplaceState,
  ];

query-string

Parse and stringify URL query strings

MIT
Latest version published 2 months ago

Package Health Score

91 / 100
Full package analysis