本文整理匯總了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;
}
}
示例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);
};
};
示例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);
});
});
示例4: getLaunchEditorUrl
function getLaunchEditorUrl(errorLocation: ErrorOverlay.ErrorLocation) {
return `${LAUNCH_EDITOR_ENDPOINT}?${qs.stringify({
filePath: errorLocation.fileName,
line: errorLocation.lineNumber || 1,
column: errorLocation.colNumber || 1
})}`;
}
示例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);
};
示例6:
const ebayResultUrlForKeywords = (keywords: string) =>
`${
process.env.EBAY_API_SERVER
}/services/search/FindingService/v1?${queryString.stringify({
...EBAY_FIND_SETTINGS,
keywords
})}`
示例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);
}
示例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
});
}
示例9: return
return (key: string, value?) => {
if (value === "") {
delete querystring[key];
} else {
querystring[key] = value || key;
}
history.replace("?" + stringifyQs(querystring));
};
示例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 : ''
});
}