当前位置: 首页>>代码示例>>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;未经允许,请勿转载。