本文整理汇总了TypeScript中qs.parse函数的典型用法代码示例。如果您正苦于以下问题:TypeScript parse函数的具体用法?TypeScript parse怎么用?TypeScript parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
header.split(",").map(link => {
link = link.trim();
// Needs to fit our expected format.
const parts = link.match(/<([0-9a-zA-Z$\-_.+!*'(),:/?=&%#]+)>;\s+rel="(next|prev)"/);
if (!parts) {
return;
}
// Extract the relevant bits.
const [fullMatch, url, rel] = parts;
// Confirm we have a query string.
const search = url.match(/\?([^#]+)/);
if (!search || !search[1]) {
return;
}
// Break out the query string into individual parameters.
const searchParameters = qs.parse(search[1]);
// Grab the next or prev page number.
if (searchParameters[param]) {
result[rel] = searchParameters[param];
}
// Grab the limit from the current link.
if (limitParam && searchParameters[limitParam]) {
result.limit = searchParameters[param];
}
});
示例2: it
it('contains a subject', () => {
const queryString = parse(mailto.split('?')[1]);
expect(queryString).toHaveProperty(
'Subject',
'Cloud Manager User Feedback'
);
});
示例3: loginValidate
export default function loginValidate(location, history, navigation) {
const query = window.location.search.replace(/^\?/, '');
const xTicket = qs.parse(query)['ticket'];
window.uw.request({
url: '/unified/auth/doAuth',
needLogin: false,
headers: {
'x-ticket': xTicket,
},
success: ({ code, data }) => {
if (code === '4000') {
if (navigation) {
window.location.href = `${data.loginUrl}${window.location.href}`;
} else {
window.top.location.href = `${data.loginUrl}${window.top.location.href}`;
}
} else {
window.uw.event.emit('@@auth_success');
const userName = window.uw.cookie.get('userName');
const isAdmin = window.uw.cookie.get('isAdmin');
const userId = window.uw.cookie.get('userId');
window.uw.storage.set('global.user', { userName, isAdmin: isAdmin === 'true' ? true : false, userId });
const { pathname, search } = location;
let queryWithoutTicket = _.omit(qs.parse(search.replace(/^\?/, '')), ['ticket', 'loginParam', 'lengh', 'length', 'sessionKey']);
queryWithoutTicket = qs.stringify(queryWithoutTicket);
history.replace(`${pathname}${queryWithoutTicket === '' ? '' : `?${queryWithoutTicket}`}`);
}
},
});
}
示例4: getPartialExecutionResult
/**
* Get one page of Result from Execution (with requested limit and offset)
*
* @method getPartialExecutionResult
* @param {string} executionResultUri
* @param {number[]} limit - limit for each dimension
* @param {number[]} offset - offset for each dimension
*
* @returns {Promise<Execution.IExecutionResult | null>}
* Promise with `executionResult` or `null` (null means empty response - HTTP 204)
* See https://github.com/gooddata/gooddata-typings/blob/v2.1.0/src/Execution.ts#L88
*/
public getPartialExecutionResult(executionResultUri: string, limit: number[], offset: number[])
: Promise<Execution.IExecutionResult | null> {
const executionResultUriQueryPart = getExecutionResultUriQueryPart(executionResultUri);
const numOfDimensions = Number(qs.parse(executionResultUriQueryPart).dimensions);
validateNumOfDimensions(numOfDimensions);
return this.getPage(executionResultUri, limit, offset);
}
示例5: deriveViewport
export function deriveViewport(hash: string): Viewport {
const parsed = qs.parse(hash);
return {
...viewportInit,
latitude: parseFloat(parsed.latitude) || viewportInit.latitude,
longitude: parseFloat(parsed.longitude) || viewportInit.longitude,
zoom: parseFloat(parsed.zoom) || viewportInit.zoom,
};
}
示例6: function
onRequest = function (request, reply) {
const uri = request.raw.req.url;
const parsed = Url.parse(uri, false);
parsed.query = Qs.parse(parsed.query);
request.setUrl(parsed);
return reply.continue();
};
示例7: return
return (req, res, next) => {
if (!req.getQuery()) {
req.query = {};
return next();
}
req.query = qs.parse(req.getQuery(), { allowDots: true });
return next();
};
示例8: function
export const createHistory = function(){
return useQueries(createHistoryFn)({
stringifyQuery(ob){
return qs.stringify(ob, {encode:true})
},
parseQueryString(str){
return qs.parse(str)
}
})
}
示例9: 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 });
}
示例10: getState
export const updateTimeRangeFromQueryParams = (dashboardID: string) => (
dispatch: Dispatch<Action>,
getState
): void => {
const {ranges} = getState()
const queryParams = qs.parse(window.location.search, {
ignoreQueryPrefix: true,
})
const timeRangeFromQueries = {
lower: queryParams.lower,
upper: queryParams.upper,
}
const zoomedTimeRangeFromQueries = {
lower: queryParams.zoomedLower,
upper: queryParams.zoomedUpper,
}
let validatedTimeRange = validTimeRange(timeRangeFromQueries)
if (!validatedTimeRange.lower) {
const dashboardTimeRange = ranges.find(r => r.dashboardID === dashboardID)
validatedTimeRange = dashboardTimeRange || DEFAULT_TIME_RANGE
if (timeRangeFromQueries.lower || timeRangeFromQueries.upper) {
dispatch(notify(copy.invalidTimeRangeValueInURLQuery()))
}
}
dispatch(setDashTimeV1(dashboardID, validatedTimeRange))
const validatedZoomedTimeRange = validAbsoluteTimeRange(
zoomedTimeRangeFromQueries
)
if (
!validatedZoomedTimeRange.lower &&
(queryParams.zoomedLower || queryParams.zoomedUpper)
) {
dispatch(notify(copy.invalidZoomedTimeRangeValueInURLQuery()))
}
dispatch(setZoomedTimeRange(validatedZoomedTimeRange))
const updatedQueryParams = {
lower: validatedTimeRange.lower,
upper: validatedTimeRange.upper,
zoomedLower: validatedZoomedTimeRange.lower,
zoomedUpper: validatedZoomedTimeRange.upper,
}
dispatch(updateQueryParams(updatedQueryParams))
}
示例11: dispatch
) => (action: Action) => {
dispatch(action)
const urlQueryParams = qs.parse(window.location.search, {
ignoreQueryPrefix: true,
})
if (urlQueryParams.present === 'true') {
dispatch(enablePresentationMode())
}
}
示例12: getExecutionResult
/**
* Get whole ExecutionResult
*
* @method getExecutionResult
* @param {string} executionResultUri
*
* @returns {Promise<Execution.IExecutionResult | null>}
* Promise with `executionResult` or `null` (null means empty response - HTTP 204)
* See https://github.com/gooddata/gooddata-typings/blob/v2.1.0/src/Execution.ts#L88
*/
public getExecutionResult(executionResultUri: string)
: Promise<Execution.IExecutionResult | null> {
const executionResultUriQueryPart = getExecutionResultUriQueryPart(executionResultUri);
const numOfDimensions = Number(qs.parse(executionResultUriQueryPart).dimensions);
validateNumOfDimensions(numOfDimensions);
const limit = Array(numOfDimensions).fill(DEFAULT_LIMIT);
const offset = Array(numOfDimensions).fill(0);
return this.getAllPages(executionResultUri, limit, offset);
}
示例13: return
return (ctx: any, next: any) => {
if (ctx.request.querystring && ctx.request.querystring.length > 0) {
ctx.request.query = qs.parse(ctx.request.querystring);
} else {
ctx.request.query = {};
}
ctx.params = Object.assign({}, ctx.request.query, ctx.request.body);
return next();
};
示例14:
export const updateSearch = (
history: History,
updates: { readonly [id: string]: any },
) => {
history.push({
pathname: history.location.pathname,
search: qs.stringify({
...qs.parse(history.location.search),
...updates,
}),
});
};
示例15: deriveMapbox
export function deriveMapbox(hash: string, windowConfig): Mapbox {
const { token } = windowConfig;
const parsed = qs.parse(hash, { depth: 0, skipNulls: true });
const choropleth = parsed.choropleth ?
`${parsed.choropleth}` : mapboxInit.choropleth;
const features = parsed.features ?
toSelected(parsed.features) : mapboxInit.features;
return {
...mapboxInit,
choropleth,
features,
token,
};
}