本文整理匯總了TypeScript中simple-query-string.stringify函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript stringify函數的具體用法?TypeScript stringify怎麽用?TypeScript stringify使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了stringify函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: buildOptions
function buildOptions(config: HttpClientConfig): Request {
let url = config.url;
if (config.params) {
url = `${url}?${stringify(config.params)}`;
}
return new Request(url, {
method: config.method,
body: JSON.stringify(config.body),
headers: {
'X-API-Key': API_KEY,
'Content-Type': 'application/json'
},
credentials: 'include'
});
}
示例2: getAccessTokenFromRefreshToken
export function getAccessTokenFromRefreshToken(refreshToken) {
return fetch(TOKEN_URL, {
method: 'POST',
body: stringify({
grant_type: 'refresh_token',
refresh_token: refreshToken.value,
client_id: oauthClientId(),
client_secret: oauthClientSecret()
}),
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
})
.then((response) => response.ok ? response.json() : Promise.reject(response))
.then(handleAccessToken);
}
示例3: getAccessTokenFromCode
export function getAccessTokenFromCode(code: number): Promise<Tokens> {
return Promise.resolve(
fetch(TOKEN_URL, {
method: 'POST',
body: stringify({
grant_type: 'authorization_code',
code,
client_id: oauthClientId(),
client_secret: oauthClientSecret()
}),
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
})
.then((response) => (response.ok ? response.json() : Promise.reject(response)))
.then(handleAccessToken)
);
}
示例4: getAccessTokenFromRefreshToken
export function getAccessTokenFromRefreshToken(refreshToken: Token): Promise<Tokens> {
// https://github.com/zloirock/core-js/issues/178#issuecomment-192081350
return Promise.resolve(
fetch(TOKEN_URL, {
method: 'POST',
body: stringify({
grant_type: 'refresh_token',
refresh_token: refreshToken.value,
client_id: oauthClientId(),
client_secret: oauthClientSecret()
}),
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
})
.then((response) => (response.ok ? response.json() : Promise.reject(response)))
.then(handleAccessToken)
);
}