diff --git a/src/Angular.js b/src/Angular.js index d56b154b90c7..e0d72993d3e0 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -215,7 +215,7 @@ function nextUid() { /** * Set or clear the hashkey for an object. - * @param obj object + * @param obj object * @param h the hashkey (!truthy to delete the hashkey) */ function setHashKey(obj, h) { @@ -395,6 +395,22 @@ function isDate(value){ } +/** + * @ngdoc function + * @name angular.isRegExp + * @function + * + * @description + * Determines if a value is a regular expression object. + * + * @param {*} value Reference to check. + * @returns {boolean} True if `value` is a `RegExp`. + */ +function isRegExp(value) { + return toString.apply(value) == '[object RegExp]'; +} + + /** * @ngdoc function * @name angular.isArray diff --git a/src/AngularPublic.js b/src/AngularPublic.js index 1fd18ce268eb..069caa1fcf07 100755 --- a/src/AngularPublic.js +++ b/src/AngularPublic.js @@ -46,6 +46,7 @@ function publishExternalAPI(angular){ 'isArray': isArray, 'version': version, 'isDate': isDate, + 'isRegExp': isRegExp, 'lowercase': lowercase, 'uppercase': uppercase, 'callbacks': {counter: 0}, diff --git a/test/AngularSpec.js b/test/AngularSpec.js index 0e5017ad25d9..bb02ed660b73 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -619,6 +619,23 @@ describe('angular', function() { }); }); + + describe('isRegExp', function() { + it('should return true for RegExp object', function() { + expect(isRegExp(/^foobar$/)).toBe(true); + expect(isRegExp(new RegExp('^foobar$/'))).toBe(true); + }); + + it('should return false for non RegExp objects', function() { + expect(isRegExp([])).toBe(false); + expect(isRegExp('')).toBe(false); + expect(isRegExp(23)).toBe(false); + expect(isRegExp({})).toBe(false); + expect(isRegExp(new Date())).toBe(false); + }); + }); + + describe('compile', function() { it('should link to existing node and create scope', inject(function($rootScope, $compile) { var template = angular.element('