Skip to content

Commit

Permalink
Adding new RegExp check
Browse files Browse the repository at this point in the history
  • Loading branch information
justsml committed Oct 22, 2019
1 parent 5d6d5ed commit 657af83
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ exports.isNumber = function (value) {
return typeof value === 'number' && !isNaN(value);
};

exports.isRegExp = function (value) {

if (!obj) {
return false;
}

const label = Object.prototype.toString.call(value);
return label.indexOf('[object RegExp]') > -1;
};

exports.isResolvable = function (obj) {

Expand Down
11 changes: 11 additions & 0 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,15 @@ describe('Common', () => {
expect(() => Common.assertOptions()).to.throw('Options must be of type object');
});
});

describe('isRegExp', () => {
it('detects RegExp instances', () => {
const isRegExp = Common.isRegExp;
const pattern = /test/i;
const pattern2 = new RegExp('test', 'i');
expect(isRegExp(pattern)).to.be.true;
expect(isRegExp(pattern2)).to.be.true;
expect(isRegExp('🤓')).to.be.false;
});
});
});

0 comments on commit 657af83

Please sign in to comment.