本文整理匯總了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 });
}