From 5a5130a0efb20a0221388f314f2433b88ca96cd0 Mon Sep 17 00:00:00 2001 From: fabioricali Date: Mon, 31 Jul 2017 11:51:19 +0200 Subject: [PATCH] add generatorFunction --- CHANGELOG.md | 4 ++++ index.d.ts | 1 + src/asserts/types.js | 16 ++++++++++++++++ test/types.js | 13 +++++++++++++ 4 files changed, 34 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d783b3a..53699fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/index.d.ts b/index.d.ts index ae71d80..725cd1c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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): boolean; function arrayOfStrings(array: Array): boolean; diff --git a/src/asserts/types.js b/src/asserts/types.js index 5e76c42..1e37cbe 100644 --- a/src/asserts/types.js +++ b/src/asserts/types.js @@ -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; \ No newline at end of file diff --git a/test/types.js b/test/types.js index 8437895..2d0076a 100644 --- a/test/types.js +++ b/test/types.js @@ -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); + }); }); \ No newline at end of file