當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript query-string.stringify函數代碼示例

本文整理匯總了TypeScript中query-string.stringify函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript stringify函數的具體用法?TypeScript stringify怎麽用?TypeScript stringify使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了stringify函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: request

 /**
  * Send a request
  * @param type
  * @param endpoint
  * @param options
  * @param callback
  * @private
  */
 private async request(
   type: string,
   endpoint: string,
   options: any = {},
   callback?: (err?: any, data?: any) => void
 ): Promise<any> {
   try {
     if (isFunction(options)) {
       callback = options;
       options = {};
     }
     let stringify = true;
     const headers = {};
     let uri = `${this.apiUrl}${endpoint}`;
     if (this.config.accessToken) {
       options.access_token = this.config.accessToken;
     }
     if (options.accessToken) {
       options.access_token = options.accessToken;
       delete options.accessToken;
     }
     if (options.uriAbsolute) {
       uri = `${this.baseApiUrl}/${endpoint}`;
       delete options.uriAbsolute;
     }
     if (type === 'GET' || type === 'DELETE') {
       uri += `?${queryString.stringify(options)}`;
       options = null;
     } else if (type === 'POST') {
       headers['Content-Type'] =
         'application/x-www-form-urlencoded;charset=UTF-8';
       options = queryString.stringify(options);
       stringify = false;
     }
     const response = await fetch(uri, {
       method: type,
       body: options && stringify ? JSON.stringify(options) : options || null,
       headers,
     });
     const json = await response.json();
     if (!response.ok) {
       throw json;
     }
     if (isFunction(callback)) {
       callback(null, json);
     }
     return json;
   } catch (err) {
     const error = err.error || err;
     if (isFunction(callback)) {
       return callback(error);
     }
     throw error;
   }
 }
開發者ID:pradel,項目名稱:node-instagram,代碼行數:63,代碼來源:index.ts

示例2: async

export const fetchPortfolioItems: PortfolioThunkActionCreator<Portfolio[]> = (
  params: PortfolioRequestParams,
) => {
  const {
    requestedPageNumber,
    pageSize,
    categories = [],
    tags = [],
    searchTerm,
  } = params;

  const query = queryString.stringify({
    requestedPageNumber,
    pageSize,
    categores: categories.join(','),
    tags: tags.join(','),
    searchTerm,
  });

  return async (dispatch, getState, api) => {
    const action = await composeActionFromAsyncRequest(
      types.FETCH_PORTFOLIO_ITEMS,
    )(api.get(`/portfolio?${query}`));
    dispatch(action);
  };
};
開發者ID:ericmasiello,項目名稱:synbydesign,代碼行數:26,代碼來源:actions.ts

示例3: Promise

        return new Promise((resolve, reject) => {
            const url = queryObject ? `/files?${QueryString.stringify(queryObject)}` : '/files';

            this.oauth.authenticatedRequest(url, {
                method: 'GET',
            }).then(body => {
                let table = new Table({
                    chars: { 'mid': '', 'left-mid': '', 'mid-mid': '', 'right-mid': '' },
                    colWidths: [26, 30, 15, 10],
                    head: ['Id', 'Name', 'Size', 'Accesses'],
                });

                for (let file of body) {
                    file.size = file.size ? filesize(file.size) : 'None';
                    table.push([
                        file._id, file.name, file.size, file.accesses || 'none',
                    ]);
                }

                console.log(table.toString());
                resolve();
            }, err => {
                reject(err);
            });
        });
開發者ID:victorjacobs,項目名稱:chullo-client,代碼行數:25,代碼來源:client.ts

示例4: getLaunchEditorUrl

function getLaunchEditorUrl(errorLocation: ErrorOverlay.ErrorLocation) {
  return `${LAUNCH_EDITOR_ENDPOINT}?${qs.stringify({
    filePath: errorLocation.fileName,
    line: errorLocation.lineNumber || 1,
    column: errorLocation.colNumber || 1
  })}`;
}
開發者ID:skidding,項目名稱:cosmos,代碼行數:7,代碼來源:reactErrorOverlay.ts

示例5: Headers

export const gatherWithQuery = async <Q, A>(opts: IGatherQueryOptions<Q>): Promise<IGatherResult<A>> => {
    const query =
        typeof opts.query === "undefined" ? null : queryString.stringify(opts.query, { arrayFormat: "index" });
    const method = typeof opts.method === "undefined" ? "GET" : opts.method;
    const headers: Headers = (() => {
        if (typeof opts.headers === "undefined") {
            return new Headers({ "content-type": "application/json" });
        }

        return opts.headers;
    })();

    const url = (() => {
        if (query === null) {
            return opts.url;
        }

        return `${opts.url}?${query}`;
    })();

    const response = await fetch(url, {
        headers,
        method,
    });

    return handleResponse(response);
};
開發者ID:ihsw,項目名稱:sotah-client,代碼行數:27,代碼來源:index.ts

示例6:

const ebayResultUrlForKeywords = (keywords: string) =>
  `${
    process.env.EBAY_API_SERVER
  }/services/search/FindingService/v1?${queryString.stringify({
    ...EBAY_FIND_SETTINGS,
    keywords
  })}`
開發者ID:crooked-ventures,項目名稱:literally.deals,代碼行數:7,代碼來源:random-ebay-result.ts

示例7: serialize

 /**
  * serialize track states to query string
  */
 public serialize():string {
   var params = [];
   for (let key in this.tracks) {
     let param = this.tracks[key].join(',');
     params[key] = param || undefined;
   }
   return querystring.stringify(params);
 }
開發者ID:c9s,項目名稱:qama,代碼行數:11,代碼來源:EntryStore.ts

示例8: createAuthUrl

export function createAuthUrl(input: types.AuthenticateInput): string {
    return ENDPOINT + 'v3/auth/auth?' + querystring.stringify({
        client_id: input.client_id,
        redirect_uri: input.redirect_uri,
        response_type: input.response_type,
        scope: input.scope
    });
}
開發者ID:emonkak,項目名稱:feedpon,代碼行數:8,代碼來源:api.ts

示例9: return

 return (key: string, value?) => {
   if (value === "") {
     delete querystring[key];
   } else {
     querystring[key] = value || key;
   }
   history.replace("?" + stringifyQs(querystring));
 };
開發者ID:p2p-ms,項目名稱:front,代碼行數:8,代碼來源:utils.ts

示例10: stringify

export const queryString = (props: Array<string>) => (obj: Properties): Properties => {
  const qs = stringify(props.reduce((res, key) => {
    res[key] = obj[key];
    return res;
  }, {}));

  return Object.assign({}, obj, {
    queryString: qs.length > 0 ? '?' + qs : ''
  });
}
開發者ID:MikeRyan52,項目名稱:typesafe-urls,代碼行數:10,代碼來源:query-string.ts


注:本文中的query-string.stringify函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。