本文整理汇总了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 : ''
});
}