Skip to content

Commit

Permalink
add generatorFunction
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioricali committed Jul 31, 2017
1 parent eba0cb7 commit 5a5130a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [unreleased]
### Added
- `be.generatorFunction`, check if is GeneratorFunction

## [1.9.0] - 2017-07-30
### Added
- `be.sha256`, check if is sha256 string
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export declare namespace be {
function float32Array(value: any): boolean;
function float64Array(value: any): boolean;
function asyncFunction(value: any): boolean;
function generatorFunction(value: any): boolean;

function inArray(value: any, array: Array<any>): boolean;
function arrayOfStrings(array: Array<any>): boolean;
Expand Down
16 changes: 16 additions & 0 deletions src/asserts/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,22 @@ Types.asyncFunction = (value) => {
return Types.classOf(value, 'asyncfunction');
};

/**
* Check if is GeneratorFunction
*
* **Interfaces**: `all`, `any`, `not`, `err`
*
* @function
* @name generatorFunction
* @param value {Mixed} value
* @returns {boolean}
* @example
* be.generatorFunction(function* test(){}) // true
*/
Types.generatorFunction = (value) => {
return Types.classOf(value, 'generatorfunction');
};

Types = Interface.create(Types);

module.exports = Types;
13 changes: 13 additions & 0 deletions test/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -901,4 +901,17 @@ describe('asyncFunction', function () {
console.log(result);
assert.equal(result, false);
});
});

describe('generatorFunction', function () {
it('should be return true', function () {
var result = be.generatorFunction(function* name(){return true});
console.log(result);
assert.equal(result, true);
});
it('should be return false', function () {
var result = be.generatorFunction(function test(){});
console.log(result);
assert.equal(result, false);
});
});

0 comments on commit 5a5130a

Please sign in to comment.