From 8a83e734e8f449f47daffc7fd04855a1dd6ee064 Mon Sep 17 00:00:00 2001 From: tunnckoCore Date: Tue, 26 May 2015 06:56:23 +0300 Subject: [PATCH] implement --- .editorconfig | 22 +++++++++++++ .gitignore | 56 ++++++++++++++++++++++++++++++++ .travis.yml | 14 ++++++++ CHANGELOG.md | 4 +++ CONTRIBUTING.md | 32 ++++++++++++++++++ LICENSE.md | 21 ++++++++++++ README.md | 86 +++++++++++++++++++++++++++++++++++++++++++++++-- index.js | 22 +++++++++++++ package.json | 33 +++++++++++++++++++ test.js | 29 +++++++++++++++++ 10 files changed, 317 insertions(+), 2 deletions(-) create mode 100644 .editorconfig create mode 100644 .gitignore create mode 100644 .travis.yml create mode 100644 CHANGELOG.md create mode 100644 CONTRIBUTING.md create mode 100644 LICENSE.md create mode 100644 index.js create mode 100644 package.json create mode 100644 test.js diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..ef5ea46 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,22 @@ +# .editorconfig +# +# Copyright (c) 2015 Charlike Mike Reagent, contributors. +# Released under the MIT license. +# + +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 2 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true + +[*.php] +indent_size = 4 + +[*.md] +insert_final_newline = false +trim_trailing_whitespace = false diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e3a40a7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,56 @@ +# .gitignore +# +# Copyright (c) 2015 Charlike Mike Reagent, contributors. +# Released under the MIT license. +# + +# Always-ignore dirs # +# #################### +_gh_pages +node_modules +bower_components +components +vendor +build +dest +dist +src +lib-cov +coverage +nbproject +cache +temp +tmp +is-es6-generator + +# Packages # +# ########## +*.7z +*.dmg +*.gz +*.iso +*.jar +*.rar +*.tar +*.zip + +# OS, Logs and databases # +# ######################### +*.pid +*.dat +*.log +*.sql +*.sqlite +*~ +~* + +# Another files # +# ############### +Icon? +.DS_Store* +Thumbs.db +ehthumbs.db +Desktop.ini +npm-debug.log +.directory +._* diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..79c46bc --- /dev/null +++ b/.travis.yml @@ -0,0 +1,14 @@ +sudo: false +language: "node_js" +node_js: + - "0.12" + - "iojs" +before_script: + - npm install standard + - standard +script: + - npm install istanbul-harmony + - node --harmony node_modules/.bin/istanbul cover test.js --report lcovonly +after_script: + - npm install coveralls + - cat ./coverage/lcov.info | coveralls diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..a9e194a --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,4 @@ + + +## 0.0.0 - 2015-05-26 +- first commits \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..5312165 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,32 @@ +# Contributing Guidelines + +Contributions are always welcome! + +**Before spending lots of time on something, ask for feedback on your idea first!** + +Please search issues and pull requests before adding something new to avoid duplicating efforts and conversations. + + +## Installing + +Fork and clone the repo, then `npm install` to install all dependencies and `npm test` to ensure all is okey before you start anything. + + +## Testing + +Tests are run with `npm test`. Please ensure all tests are passing before submitting a pull request (unless you're creating a failing test to increase test coverage or show a problem). + +## Code Style + +[![standard][standard-image]][standard-url] + +This repository uses [`standard`][standard-url] to maintain code style and consistency, and to avoid style arguments. You are encouraged to install it globally. `npm test` runs `standard` so you don't have to! + +``` +npm i standard -g +``` + +It is intentional to don't have `standard`, `istanbul` and `coveralls` in the devDependencies. Travis will handle all that stuffs. That approach will save bandwidth also installing and development time. + +[standard-image]: https://cdn.rawgit.com/feross/standard/master/badge.svg +[standard-url]: https://github.com/feross/standard \ No newline at end of file diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..2856afd --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +# The MIT License + +Copyright (c) 2015 [Charlike Make Reagent](http://j.mp/1stW47C) + +> Permission is hereby granted, free of charge, to any person obtaining a copy +> of this software and associated documentation files (the "Software"), to deal +> in the Software without restriction, including without limitation the rights +> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +> copies of the Software, and to permit persons to whom the Software is +> furnished to do so, subject to the following conditions: +> +> The above copyright notice and this permission notice shall be included in +> all copies or substantial portions of the Software. +> +> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +> SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index 8bf6918..8eca104 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,84 @@ -# is-es6-generator -Check that given value is Generator +# is-es6-generator [![npmjs.com][npmjs-img]][npmjs-url] [![The MIT License][license-img]][license-url] + +> Check that given value is Generator + +[![code climate][codeclimate-img]][codeclimate-url] [![standard code style][standard-img]][standard-url] [![travis build status][travis-img]][travis-url] [![coverage status][coveralls-img]][coveralls-url] [![dependency status][david-img]][david-url] + + +## Install +``` +npm i is-es6-generator --save +npm test +``` + + +## Usage +> For more use-cases see the [tests](./test.js) + +```js +var isGenerator = require('is-es6-generator') +var generator = (function * () {})() + +isGenerator(null) //=> false +isGenerator(undefined) //=> false +isGenerator(25) //=> false +isGenerator('test') //=> false +isGenerator(function * () {}) //=> false +isGenerator(generator), true) +``` + + +## Contributing + +Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/tunnckoCore/is-es6-generator/issues/new). +But before doing anything, please read the [CONTRIBUTING.md](./CONTRIBUTING.md) guidelines. + + +## [Charlike Make Reagent](http://j.mp/1stW47C) [![new message to charlike][new-message-img]][new-message-url] [![freenode #charlike][freenode-img]][freenode-url] + +[![tunnckocore.tk][author-www-img]][author-www-url] [![keybase tunnckocore][keybase-img]][keybase-url] [![tunnckoCore npm][author-npm-img]][author-npm-url] [![tunnckoCore twitter][author-twitter-img]][author-twitter-url] [![tunnckoCore github][author-github-img]][author-github-url] + + +[npmjs-url]: https://www.npmjs.com/package/is-es6-generator +[npmjs-img]: https://img.shields.io/npm/v/is-es6-generator.svg?label=is-es6-generator + +[license-url]: https://github.com/tunnckoCore/is-es6-generator/blob/master/LICENSE.md +[license-img]: https://img.shields.io/badge/license-MIT-blue.svg + + +[codeclimate-url]: https://codeclimate.com/github/tunnckoCore/is-es6-generator +[codeclimate-img]: https://img.shields.io/codeclimate/github/tunnckoCore/is-es6-generator.svg + +[travis-url]: https://travis-ci.org/tunnckoCore/is-es6-generator +[travis-img]: https://img.shields.io/travis/tunnckoCore/is-es6-generator.svg + +[coveralls-url]: https://coveralls.io/r/tunnckoCore/is-es6-generator +[coveralls-img]: https://img.shields.io/coveralls/tunnckoCore/is-es6-generator.svg + +[david-url]: https://david-dm.org/tunnckoCore/is-es6-generator +[david-img]: https://img.shields.io/david/dev/tunnckoCore/is-es6-generator.svg + +[standard-url]: https://github.com/feross/standard +[standard-img]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg + + +[author-www-url]: http://www.tunnckocore.tk +[author-www-img]: https://img.shields.io/badge/www-tunnckocore.tk-fe7d37.svg + +[keybase-url]: https://keybase.io/tunnckocore +[keybase-img]: https://img.shields.io/badge/keybase-tunnckocore-8a7967.svg + +[author-npm-url]: https://www.npmjs.com/~tunnckocore +[author-npm-img]: https://img.shields.io/badge/npm-~tunnckocore-cb3837.svg + +[author-twitter-url]: https://twitter.com/tunnckoCore +[author-twitter-img]: https://img.shields.io/badge/twitter-@tunnckoCore-55acee.svg + +[author-github-url]: https://github.com/tunnckoCore +[author-github-img]: https://img.shields.io/badge/github-@tunnckoCore-4183c4.svg + +[freenode-url]: http://webchat.freenode.net/?channels=charlike +[freenode-img]: https://img.shields.io/badge/freenode-%23charlike-5654a4.svg + +[new-message-url]: https://github.com/tunnckoCore/messages +[new-message-img]: https://img.shields.io/badge/send%20me-message-green.svg diff --git a/index.js b/index.js new file mode 100644 index 0000000..e496ba9 --- /dev/null +++ b/index.js @@ -0,0 +1,22 @@ +/*! + * is-es6-generator + * + * Copyright (c) 2015 Charlike Mike Reagent, contributors. + * Released under the MIT license. + */ + +'use strict' + +/** + * Check whether a `value` is a generator. + * + * @param {Mixed} `value` + * @return {Boolean} always boolean `true` or `false`, never `null` or `undefined` + * @api public + */ +module.exports = function isGenerator (value) { + if (!value) return false + if (typeof value.next === 'function' && typeof value.throw === 'function') return true + + return false +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..2e0d924 --- /dev/null +++ b/package.json @@ -0,0 +1,33 @@ +{ + "name": "is-es6-generator", + "version": "0.0.0", + "description": "Check that given value is Generator", + "repository": "tunnckoCore/is-es6-generator", + "author": "Charlike Mike Reagent <@tunnckoCore> (http://www.tunnckocore.tk)", + "main": "index.js", + "license": "MIT", + "scripts": { + "test": "standard && node test.js" + }, + "dependencies": {}, + "devDependencies": { + "assertit": "^0.1.0" + }, + "keywords": [ + "check", + "es2015", + "es6", + "es7", + "function", + "functions", + "generator", + "generatorfunction", + "generators", + "is", + "is-function", + "is-generator", + "is-generator-function", + "next", + "validate" + ] +} diff --git a/test.js b/test.js new file mode 100644 index 0000000..803d21a --- /dev/null +++ b/test.js @@ -0,0 +1,29 @@ +/*! + * is-es6-generator + * + * Copyright (c) 2015 Charlike Mike Reagent, contributors. + * Released under the MIT license. + */ + +/* jshint asi:true */ + +'use strict' + +var test = require('assertit') +var isGenerator = require('./index') + +test('is-es6-generator:', function () { + test('should return false with non-generators', function () { + test.equal(isGenerator(null), false) + test.equal(isGenerator(undefined), false) + test.equal(isGenerator([1, 2, 3]), false) + test.equal(isGenerator({name: 'GeneratorFunction'}), false) + test.equal(isGenerator(25), false) + test.equal(isGenerator('test'), false) + test.equal(isGenerator(function * () {}), false) + }) + test('should return true with a generator', function () { + test.equal(isGenerator((function * () {})()), true) + test.equal(isGenerator((function * () { yield 42 })()), true) + }) +})