Add is.boundFunction() (#31)

This commit is contained in:
Darren Scerri 2017-11-10 19:11:35 +01:00 committed by Brandon Smith
parent 89fc424975
commit 319982a09c
3 changed files with 28 additions and 1 deletions

View file

@ -96,6 +96,21 @@ is.asyncFunction(() => {});
// => false
```
##### .boundFunction(value)
Returns `true` for any `bound` function.
```js
is.boundFunction(() => {});
// => true
is.boundFunction(function () {}.bind(null));
// => true
is.boundFunction(function () {});
// => false
```
##### .map(value)
##### .set(value)
##### .weakMap(value)

View file

@ -95,6 +95,7 @@ namespace is { // tslint:disable-line:no-namespace
export const generatorFunction = isFunctionOfType('GeneratorFunction');
export const asyncFunction = isFunctionOfType('AsyncFunction');
export const boundFunction = (value: any) => function_(value) && !value.hasOwnProperty('prototype');
export const regExp = isObjectOfType('RegExp');
export const date = isObjectOfType('Date');

View file

@ -150,6 +150,13 @@ const types = new Map<string, Test>([
async () => {} // tslint:disable-line:no-empty
]
}],
['boundFunction', {
is: m.boundFunction,
fixtures: [
() => {}, // tslint:disable-line:no-empty
function () {}.bind(null), // tslint:disable-line:no-empty only-arrow-functions
]
}],
['map', {
is: m.map,
fixtures: [
@ -362,7 +369,11 @@ test('is.array', t => {
});
test('is.function', t => {
testType(t, 'function', ['generatorFunction', 'asyncFunction']);
testType(t, 'function', ['generatorFunction', 'asyncFunction', 'boundFunction']);
});
test('is.boundFunction', t => {
t.false(m.boundFunction(function () {})); // tslint:disable-line:no-empty only-arrow-functions
});
test('is.buffer', t => {