-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from tristaaan/regexp-pick
RegExp pick
- Loading branch information
Showing
6 changed files
with
161 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* @module 101/is-regexp | ||
*/ | ||
|
||
/** | ||
* Check if a value is an instance of RegExp | ||
* @function module:101/is-regexp | ||
* @param {*} val - value checked to be an instance of RegExp | ||
* @return {boolean} Whether the value is an object or not | ||
*/ | ||
|
||
module.exports = function isRegExp (val) { | ||
return Object.prototype.toString.call(val) == '[object RegExp]'; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
var Lab = require('lab'); | ||
var lab = exports.lab = Lab.script(); | ||
|
||
var describe = lab.describe; | ||
var it = lab.it; | ||
var expect = Lab.expect; | ||
|
||
var isRegExp = require('../is-regexp'); | ||
|
||
describe('isRegExp', function () { | ||
it('should return true for instance of RegExp', function(done) { | ||
var regexp = new RegExp('.*'); | ||
expect(isRegExp(regexp)).to.be.true; | ||
expect(isRegExp(/.*/)).to.be.true; | ||
done(); | ||
}); | ||
|
||
it('should return false for non-regexp', function(done) { | ||
expect(isRegExp({})).to.be.false; | ||
expect(isRegExp(['foo'])).to.be.false; | ||
expect(isRegExp('foo')).to.be.false; | ||
expect(isRegExp(101)).to.be.false; | ||
expect(isRegExp(function () {})).to.be.false; | ||
expect(isRegExp(null)).to.be.false; | ||
expect(isRegExp(undefined)).to.be.false; | ||
expect(isRegExp(new String('hey'))).to.be.false; | ||
expect(isRegExp(new Number(101))).to.be.false; | ||
done(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters