Files
angular__angular/modules/angular2/src/http/http_utils.ts
T
cexbrayat b925ff5b8d refactor(http): rename enums to be singular
ReadyStates -> ReadyState
RequestMethods -> RequestMethod
ResponseTypes -> ResponseType

Fixes #5574

BREAKING CHANGE:

Before

import {ReadyStates, RequestMethods, ResponseTypes} from 'angular2/http';

After

import {ReadyState, RequestMethod, ResponseType} from 'angular2/http';

Closes #5584
2015-12-04 19:16:00 +00:00

31 lines
1007 B
TypeScript

import {isString} from 'angular2/src/facade/lang';
import {RequestMethod} from './enums';
import {makeTypeError} from 'angular2/src/facade/exceptions';
import {Response} from './static_response';
export function normalizeMethodName(method): RequestMethod {
if (isString(method)) {
var originalMethod = method;
method = method.replace(/(\w)(\w*)/g, (g0, g1, g2) => g1.toUpperCase() + g2.toLowerCase());
method = RequestMethod[method];
if (typeof method !== 'number')
throw makeTypeError(
`Invalid request method. The method "${originalMethod}" is not supported.`);
}
return method;
}
export const isSuccess = (status: number): boolean => (status >= 200 && status < 300);
export function getResponseURL(xhr: any): string {
if ('responseURL' in xhr) {
return xhr.responseURL;
}
if (/^X-Request-URL:/m.test(xhr.getAllResponseHeaders())) {
return xhr.getResponseHeader('X-Request-URL');
}
return;
}
export {isJsObject} from 'angular2/src/facade/lang';