本文整理汇总了TypeScript中qs.stringify函数的典型用法代码示例。如果您正苦于以下问题:TypeScript stringify函数的具体用法?TypeScript stringify怎么用?TypeScript stringify使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了stringify函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: jsonp
export const getInstagramPhotos = (userId: string, accessToken: string): Promise<Response> => {
const params = qs.stringify({
access_token: accessToken,
count: 10,
})
const url = `https://api.instagram.com/v1/users/${userId}/media/recent/?${params}`
const key = `grams_${userId}_${md5(params)}`
const result = cache.get(key)
if (cache.get(key)) {
return Promise.resolve(Ok(result))
}
return jsonp(url)
.then(response => response.json())
.then((response: Instagram.Response) => {
if (response.meta.code === 400) {
return Err({
message: response.meta.error_message,
info: `URL: ${url}`,
})
}
cache.set(key, response.data, 22)
return Ok(response.data)
})
.catch(err => Err(err))
}
示例2: postForm
export function postForm(url, data, onError) {
const d = data ? _.cloneDeep(data) : {};
d.lang = getLocale();
const req = post(url, qs.stringify(d));
return handleRequest(req, onError);
}
示例3: serializeBrowserState
export function serializeBrowserState(paths: PathConfigs<BrowserState>, s: BrowserState): Partial<Location> {
const path = browserStateToPathConfig(paths, s);
const pathState = path.pick(s);
const pathname = `/${path.serialize(mapValues(pathState, encodeURIComponent))}`;
const search = `?${qs.stringify(omit(s, Object.keys(pathState)))}`; // will encode URI by default
return { pathname, search };
}
示例4: iteratePerusteet
export async function* iteratePerusteet(params: any = {}) {
let sivu = 0;
params = { ...defaultParams, ...params };
while (true) {
const res = await axios.get(PerusteEndpoint, {
params: { ...params, sivu, sivukoko: 100 },
paramsSerializer(params) {
return qs.stringify(params, { arrayFormat: "repeat" });
}
});
if (_.isEmpty(res.data.data)) {
return;
}
console.log(`Got page ${sivu}`, _.size(res.data.data));
console.log(res.data.sivu, res.data.kokonaismäärä, res.data.sivukoko);
sivu += 1;
for (const data of res.data.data) {
yield data as any;
}
}
}
示例5: urlJoin
export const productListUrl = (params?: ProductListQueryParams): string => {
if (params === undefined) {
return productListPath;
} else {
return urlJoin(productListPath, "?" + stringifyQs(params));
}
};
示例6: serialize
/*
* Serialize relevant portions of the state tree into a string
*/
export default function serialize(state: State): string {
const {
lar: { filters, points: { scaleFactor } },
mapbox: { choropleth, features },
viewport: { latitude, longitude, zoom },
} = state;
const { year } = filters;
const filterValues: any = {};
Object.keys(filters)
.filter(key => key !== "year" && filters[key].size)
.forEach(key => {
filterValues[key] = filters[key].join(",");
});
return qs.stringify(
{
...filterValues,
choropleth,
latitude,
longitude,
scaleFactor,
year,
zoom,
features: features.join(","),
},
{ encode: false, skipNulls: true },
);
}
示例7: makeSearchLink
function makeSearchLink(query: string): string {
const url = "https://soundcloud.com/search/sounds";
const params = qs.stringify({
q: query,
});
return `${url}?${params}`;
}
示例8: urlJoin
export const orderListUrl = (params?: OrderListUrlQueryParams): string => {
const orderList = orderListPath;
if (params === undefined) {
return orderList;
} else {
return urlJoin(orderList, "?" + stringifyQs(params));
}
};
示例9: productImagePath
export const productImageUrl = (
productId: string,
imageId: string,
params?: ProductImageUrlQueryParams
) =>
productImagePath(encodeURIComponent(productId), encodeURIComponent(imageId)) +
"?" +
stringifyQs(params);
示例10: replaceLimitAndOffsetInUri
export function replaceLimitAndOffsetInUri(oldUri: string, limit: number[], offset: number[]): string {
const [uriPart, queryPart] = oldUri.split(/\?(.+)/);
const query = {
...qs.parse(queryPart),
limit: limit.join(','),
offset: offset.join(',')
};
return uriPart + qs.stringify(query, { addQueryPrefix: true });
}