2016-06-08 19:38:52 -04:00
|
|
|
import {makeTypeError} from '../src/facade/exceptions';
|
2016-04-28 20:50:03 -04:00
|
|
|
import {isString} from '../src/facade/lang';
|
2016-06-08 19:38:52 -04:00
|
|
|
|
2015-12-03 16:44:14 -05:00
|
|
|
import {RequestMethod} from './enums';
|
2015-09-21 03:46:16 -04:00
|
|
|
|
2016-02-01 20:05:50 -05:00
|
|
|
export function normalizeMethodName(method: string | RequestMethod): RequestMethod {
|
2015-09-21 03:46:16 -04:00
|
|
|
if (isString(method)) {
|
|
|
|
var originalMethod = method;
|
2016-02-01 20:05:50 -05:00
|
|
|
method = (<string>method)
|
2016-06-08 19:38:52 -04:00
|
|
|
.replace(
|
|
|
|
/(\w)(\w*)/g,
|
|
|
|
(g0: string, g1: string, g2: string) => g1.toUpperCase() + g2.toLowerCase());
|
2016-02-01 20:05:50 -05:00
|
|
|
method = <number>(<{[key: string]: any}>RequestMethod)[method];
|
2015-09-21 03:46:16 -04:00
|
|
|
if (typeof method !== 'number')
|
|
|
|
throw makeTypeError(
|
|
|
|
`Invalid request method. The method "${originalMethod}" is not supported.`);
|
|
|
|
}
|
2016-02-01 20:05:50 -05:00
|
|
|
return <RequestMethod>method;
|
2015-09-21 03:46:16 -04:00
|
|
|
}
|
|
|
|
|
2015-11-19 20:29:41 -05:00
|
|
|
export const isSuccess = (status: number): boolean => (status >= 200 && status < 300);
|
|
|
|
|
2015-11-19 21:47:29 -05:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-04-28 20:50:03 -04:00
|
|
|
export {isJsObject} from '../src/facade/lang';
|