feat(http): Add support for strings as http method names

Closes #4331
This commit is contained in:
mgechev
2015-10-02 11:33:49 -07:00
committed by Jeff Cross
parent a251df9df4
commit 34518f0f2d
5 changed files with 46 additions and 6 deletions
+16
View File
@@ -1 +1,17 @@
import {isString} from 'angular2/src/core/facade/lang';
import {RequestMethods} from './enums';
import {makeTypeError} from 'angular2/src/core/facade/exceptions';
export function normalizeMethodName(method): RequestMethods {
if (isString(method)) {
var originalMethod = method;
method = method.replace(/(\w)(\w*)/g, (g0, g1, g2) => g1.toUpperCase() + g2.toLowerCase());
method = RequestMethods[method];
if (typeof method !== 'number')
throw makeTypeError(
`Invalid request method. The method "${originalMethod}" is not supported.`);
}
return method;
}
export {isJsObject} from 'angular2/src/core/facade/lang';