{"_id":"cofy","_rev":"25-ae8e73915cf3bca1a9b2a45cf5ef0a6c","name":"cofy","description":"Cofy is a bridge connecting callback style object to sequential style in co environment with one punch.","dist-tags":{"latest":"2.0.2"},"versions":{"0.0.1":{"name":"cofy","version":"0.0.1","description":"cofy is utility for convert you object or function in co style..","main":"index.js","scripts":{"test":"set NODE_ENV=test && mocha --recursive -R spec --require should --harmony test/ --bail","test-cov":"set NODE_ENV=test && node --harmony node_modules/istanbul-harmony/lib/cli.js cover ./node_modules/mocha/bin/_mocha  -- -u exports --require should  --recursive test/ --bail","test-travis":"set NODE_ENV=test && node --harmony node_modules/istanbul-harmony/lib/cli.js cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -u exports --require should  --recursive test/ --bail"},"repository":{"type":"git","url":"https://github.com/RocksonZeta/cofy.git"},"keywords":["cofy","co","async","flow","generator","coro","coroutine"],"license":"MIT","devDependencies":{"co":"*","should":"*","mocha":"*","coveralls":"*","mocha-lcov-reporter":"*","istanbul-harmony":"*"},"engines":{"node":">= 0.11.9"},"bugs":{"url":"https://github.com/RocksonZeta/cofy/issues"},"homepage":"https://github.com/RocksonZeta/cofy","_id":"cofy@0.0.1","_shasum":"80cebae64e84b012b1b17949ccaa58c91fed7068","_from":".","_npmVersion":"1.4.9","_npmUser":{"name":"rocksonzeta","email":"RocksonZeta@gmail.com"},"maintainers":[{"name":"rocksonzeta","email":"RocksonZeta@gmail.com"}],"dist":{"shasum":"80cebae64e84b012b1b17949ccaa58c91fed7068","tarball":"https://registry.npmjs.org/cofy/-/cofy-0.0.1.tgz","integrity":"sha512-9OD1EwYvbR09Ti6bCd2I3+T2S5rrq5DVdVxJidDPzRxlpLqHHXmGdmrt0RxBjw3nvDdjoGfjYUuV6zGmcgB9bg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICrVa+wTNPrwO5UeO9JXV4sQdoQ/r+msixu4P6MyYCUhAiBHxsPmhKTXc+xK8DuLZsb+W9A7X/0Gx+5pQKvyiW6JXA=="}]}},"0.1.0":{"name":"cofy","version":"0.1.0","description":"cofy is utility for convert you object or function in co style..","main":"index.js","scripts":{"test":"set NODE_ENV=test && mocha --recursive -R spec --require should --harmony test/ --bail","test-cov":"set NODE_ENV=test && node --harmony node_modules/istanbul-harmony/lib/cli.js cover ./node_modules/mocha/bin/_mocha  -- -u exports --require should  --recursive test/ --bail","test-travis":"set NODE_ENV=test && node --harmony node_modules/istanbul-harmony/lib/cli.js cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -u exports --require should  --recursive test/ --bail"},"repository":{"type":"git","url":"https://github.com/RocksonZeta/cofy.git"},"keywords":["cofy","co","async","flow","generator","coro","coroutine"],"license":"MIT","devDependencies":{"co":"*","should":"*","mocha":"*","coveralls":"*","mocha-lcov-reporter":"*","istanbul-harmony":"*"},"engines":{"node":">= 0.11.9"},"gitHead":"5c1ef414ed19bfd6d4d1fbf9319c476acbd884e8","bugs":{"url":"https://github.com/RocksonZeta/cofy/issues"},"homepage":"https://github.com/RocksonZeta/cofy","_id":"cofy@0.1.0","_shasum":"14541157e7c4bdab774fd0af305f12809db396dc","_from":".","_npmVersion":"1.4.14","_npmUser":{"name":"rocksonzeta","email":"RocksonZeta@gmail.com"},"maintainers":[{"name":"rocksonzeta","email":"RocksonZeta@gmail.com"}],"dist":{"shasum":"14541157e7c4bdab774fd0af305f12809db396dc","tarball":"https://registry.npmjs.org/cofy/-/cofy-0.1.0.tgz","integrity":"sha512-1c/Hh5acVEk6Qk2EDnttCFFWkd1za13GOV5QJO0tB5xdSP+WyISqfdQ4H+XflZ7cL+F7lQ6VjqiGKPvxvGJgRQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCIgB5kb89sHPOqq+cHElwkmXudGWKPgvNX/uUC2x0ilQIgKZoSjdiGh8Olx2W+9GukS0Tal5RKdAhJDugSnvfL3d4="}]}},"0.1.1":{"name":"cofy","version":"0.1.1","description":"cofy is utility for convert you object or function in co style..","main":"index.js","scripts":{"test":"set NODE_ENV=test && mocha --recursive -R spec --require should --harmony test/ --bail","test-cov":"set NODE_ENV=test && node --harmony node_modules/istanbul-harmony/lib/cli.js cover ./node_modules/mocha/bin/_mocha  -- -u exports --require should  --recursive test/ --bail","test-travis":"set NODE_ENV=test && node --harmony node_modules/istanbul-harmony/lib/cli.js cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -u exports --require should  --recursive test/ --bail"},"repository":{"type":"git","url":"https://github.com/RocksonZeta/cofy.git"},"keywords":["cofy","co","async","flow","generator","coro","coroutine"],"license":"MIT","devDependencies":{"co":"*","should":"*","mocha":"*","coveralls":"*","mocha-lcov-reporter":"*","istanbul-harmony":"*"},"engines":{"node":">= 0.11.9"},"gitHead":"a4515b82b8bcc6d525002baf614b7a1371ba623d","bugs":{"url":"https://github.com/RocksonZeta/cofy/issues"},"homepage":"https://github.com/RocksonZeta/cofy","_id":"cofy@0.1.1","_shasum":"95b063515d10568323cd9da337a3f7d2c72ddec6","_from":".","_npmVersion":"1.4.14","_npmUser":{"name":"rocksonzeta","email":"RocksonZeta@gmail.com"},"maintainers":[{"name":"rocksonzeta","email":"RocksonZeta@gmail.com"}],"dist":{"shasum":"95b063515d10568323cd9da337a3f7d2c72ddec6","tarball":"https://registry.npmjs.org/cofy/-/cofy-0.1.1.tgz","integrity":"sha512-f+lwdL1CQHW7uEsuuqt6L0JbQTX7mrIKc1rDnKSdlCpHtMwIfw0xUK3fgl/1eA7WpEc8YA85kZwgBkSd13Dlcg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHcIZM6vL+iXPyqrLVQSBKW/5nDDrkaIq8gxvCwr+fBLAiEAqquhQkq0OuPhkoxUBCBGv2fH+l/zwERKhqAKLhsLqwU="}]}},"0.1.2":{"name":"cofy","version":"0.1.2","description":"cofy is utility for convert you object or function in co style..","main":"index.js","scripts":{"test":"mocha --recursive -R spec --require should --harmony test/ --bail","test-cov":"node --harmony node_modules/istanbul-harmony/lib/cli.js cover ./node_modules/mocha/bin/_mocha  -- -u exports --require should  --recursive test/ --bail","test-travis":"node --harmony node_modules/istanbul-harmony/lib/cli.js cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -u exports --require should  --recursive test/ --bail"},"repository":{"type":"git","url":"https://github.com/RocksonZeta/cofy.git"},"keywords":["cofy","co","koa","async","flow","generator","coro","coroutine"],"license":"MIT","devDependencies":{"co":"*","should":"*","mocha":"*","coveralls":"*","mocha-lcov-reporter":"*","istanbul-harmony":"*"},"engines":{"node":">= 0.11.9"},"gitHead":"f62e1902eb7f9d0951d5682c594ea585863d7afa","bugs":{"url":"https://github.com/RocksonZeta/cofy/issues"},"homepage":"https://github.com/RocksonZeta/cofy","_id":"cofy@0.1.2","_shasum":"320bc107a846242ebe82ac5a17d8998d1832785b","_from":".","_npmVersion":"1.4.14","_npmUser":{"name":"rocksonzeta","email":"RocksonZeta@gmail.com"},"maintainers":[{"name":"rocksonzeta","email":"RocksonZeta@gmail.com"}],"dist":{"shasum":"320bc107a846242ebe82ac5a17d8998d1832785b","tarball":"https://registry.npmjs.org/cofy/-/cofy-0.1.2.tgz","integrity":"sha512-h9lSgq+zYTlD7JIcka8wcXoN1fCWRfdZJXLkf7GMd1ucOjgvyOX1K2kRZMzqBEkiCS9nC1RNBfY6wT2KlMyZOg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCBfmKWtlsH3t+0GV0NPgGvY5BvSPkqqBMa/ku+NfqxhgIgX4CVFxcYOhwR7bW26pOLqZZsiJruNVxMx12SpWCJ5/E="}]}},"1.0.0":{"name":"cofy","version":"1.0.0","description":"Cofy is a bridge connecting callback style object to sequential style in co environment with one punch.","main":"index.js","scripts":{"test":"mocha --recursive -R spec --require should --harmony test/ --bail","test-cov":"node --harmony node_modules/istanbul-harmony/lib/cli.js cover ./node_modules/mocha/bin/_mocha  -- -u exports --require should  --recursive test/ --bail","test-travis":"node --harmony node_modules/istanbul-harmony/lib/cli.js cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -u exports --require should  --recursive test/ --bail"},"repository":{"type":"git","url":"https://github.com/RocksonZeta/cofy.git"},"keywords":["cofy","co","koa","async","flow","generator","coro","coroutine"],"license":"MIT","devDependencies":{"co":"*","should":"*","mocha":"*","coveralls":"*","mocha-lcov-reporter":"*","istanbul-harmony":"*"},"engines":{"node":">= 0.11.9"},"bugs":{"url":"https://github.com/RocksonZeta/cofy/issues"},"homepage":"https://github.com/RocksonZeta/cofy","_id":"cofy@1.0.0","_shasum":"b42f33a1689122f2c0e7ebc693656c426f97e13b","_from":".","_npmVersion":"1.4.9","_npmUser":{"name":"rocksonzeta","email":"RocksonZeta@gmail.com"},"maintainers":[{"name":"rocksonzeta","email":"RocksonZeta@gmail.com"}],"dist":{"shasum":"b42f33a1689122f2c0e7ebc693656c426f97e13b","tarball":"https://registry.npmjs.org/cofy/-/cofy-1.0.0.tgz","integrity":"sha512-mkF1yj0kSPEZqY4VaP1y591Ubc3lOjaicNvUGJeTcjYacfrxV62Hbn7SlM5tt440i/NtaEr6fiQaPX40J+xLbA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHMze3bEK5J8MP5a8iqBQQgEW4/Tfudk19qgByvgzeZfAiEA83CqqO/dLvus50kxNFBXNd6ZHnpXyP1Bda3VnKJ1tSs="}]}},"2.0.1":{"name":"cofy","version":"2.0.1","description":"Cofy is a bridge connecting callback style object to sequential style in co environment with one punch.","main":"index.js","scripts":{"test":"mocha --recursive -R spec --require should --harmony test/ --bail","test-cov":"node --harmony node_modules/istanbul-harmony/lib/cli.js cover ./node_modules/mocha/bin/_mocha  -- -u exports --require should  --recursive test/ --bail","test-travis":"node --harmony node_modules/istanbul-harmony/lib/cli.js cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -u exports --require should  --recursive test/ --bail"},"repository":{"type":"git","url":"https://github.com/RocksonZeta/cofy.git"},"keywords":["cofy","co","koa","async","flow","generator","coro","coroutine"],"license":"MIT","devDependencies":{"co":"*","should":"*","mocha":"*","coveralls":"*","mocha-lcov-reporter":"*","istanbul-harmony":"*"},"engines":{"node":">= 0.11.9"},"gitHead":"654ef5bf834454f5bfd261b75c96f54112af4924","bugs":{"url":"https://github.com/RocksonZeta/cofy/issues"},"homepage":"https://github.com/RocksonZeta/cofy","_id":"cofy@2.0.1","_shasum":"df6cc9faddf1c835b61005d986cbda702ccd54a7","_from":".","_npmVersion":"2.0.0","_npmUser":{"name":"rocksonzeta","email":"RocksonZeta@gmail.com"},"maintainers":[{"name":"rocksonzeta","email":"RocksonZeta@gmail.com"}],"dist":{"shasum":"df6cc9faddf1c835b61005d986cbda702ccd54a7","tarball":"https://registry.npmjs.org/cofy/-/cofy-2.0.1.tgz","integrity":"sha512-MEJRVlT8HshokxohU2ctyzBifeN+3nbxH9sQjlCIoe027UJbKP5GJgodHsryWIMomKNaSRvlNSSa1DIgTi0MwQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD11ynxxCVB+IzCksWvNV42TQfHQLPxav7IFEWwpxR6YgIgFCjZx8dEtM0UnOo2aqJ5AZi1UEwVRkclER67qgT99I8="}]}},"2.0.2":{"name":"cofy","version":"2.0.2","description":"Cofy is a bridge connecting callback style object to sequential style in co environment with one punch.","main":"index.js","scripts":{"test":"mocha --recursive -R spec --require should --harmony test/ --bail","test-cov":"node --harmony node_modules/istanbul-harmony/lib/cli.js cover ./node_modules/mocha/bin/_mocha  -- -u exports --require should  --recursive test/ --bail","test-travis":"node --harmony node_modules/istanbul-harmony/lib/cli.js cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -u exports --require should  --recursive test/ --bail"},"repository":{"type":"git","url":"https://github.com/RocksonZeta/cofy.git"},"keywords":["cofy","co","koa","async","flow","generator","coro","coroutine"],"license":"MIT","devDependencies":{"co":"*","should":"*","mocha":"*","coveralls":"*","mocha-lcov-reporter":"*","istanbul-harmony":"*"},"engines":{"node":">= 0.11.9"},"gitHead":"654ef5bf834454f5bfd261b75c96f54112af4924","bugs":{"url":"https://github.com/RocksonZeta/cofy/issues"},"homepage":"https://github.com/RocksonZeta/cofy","_id":"cofy@2.0.2","_shasum":"1c37737f4171b91f518c154167638028153212b0","_from":".","_npmVersion":"2.0.0","_npmUser":{"name":"rocksonzeta","email":"RocksonZeta@gmail.com"},"maintainers":[{"name":"rocksonzeta","email":"RocksonZeta@gmail.com"}],"dist":{"shasum":"1c37737f4171b91f518c154167638028153212b0","tarball":"https://registry.npmjs.org/cofy/-/cofy-2.0.2.tgz","integrity":"sha512-siCNDsRIAdDFygovZZerAJqK/Sk1EbPeiXHcPfbaT4u2fkj7+aXthSlBhbwKT0bMfQE08IjIi53wcluo1jyglg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGEgrGFq+Ns9V0yy7ijQ6OC5evDBlBwS0qfr+f5jGYWhAiEAwEivvxUa0oY+mtGpUyMJLOIUAPHx9COWo8XGQp/ZGdk="}]}}},"readme":"cofy\r\n====\r\n[![Build Status](https://travis-ci.org/RocksonZeta/cofy.svg?branch=master)](https://travis-ci.org/RocksonZeta/cofy)\r\n[![Coverage Status](https://coveralls.io/repos/RocksonZeta/cofy/badge.png?branch=master)](https://coveralls.io/r/RocksonZeta/cofy?branch=master)\r\n[![NPM version](https://badge.fury.io/js/cofy.svg)](http://badge.fury.io/js/cofy)\r\n[![Dependency Status](https://david-dm.org/RocksonZeta/cofy.svg)](https://david-dm.org/RocksonZeta/cofy)\r\n\r\n[![NPM](https://nodei.co/npm/cofy.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/cofy/)\r\n\r\nCofy is a bridge connecting callback style object to sequential style in [co](https://github.com/visionmedia/co) or [koa](https://github.com/koajs/koa) environment with one punch.\r\n\r\n##Installation\r\n```\r\n$ npm install cofy --save\r\n```\r\n\r\n### NOTE: default prefix has changed to '$'.\r\n\r\n## Some examples\r\n\r\nuse cofy in [redis](https://github.com/mranney/node_redis).\r\n```javascript\r\n'use strict';\r\nvar co = require(\"co\");\r\nvar cofy = require(\"cofy\");\r\nvar redis = require('redis');\r\n\r\n//enable redis to has a co ablitiy.\r\ncofy.class(redis.RedisClient);\r\n\r\n//now we can use mysql in co \r\nvar client = redis.createClient(6379,'localhost');\r\nco(function * () {\r\n\t//use class.$fn\r\n\tvar r1 = yield client.$set('a' ,1);\r\n\tvar r2 = yield client.$get('a');\r\n\tvar r3 = yield client.$hmset('h' , {k1:'v1' , k2:'v2'});\r\n\tvar r4 = yield client.$hget('h' ,'k1');\r\n\tconsole.log(r1,r2);\r\n\tconsole.log(r3,r4);\r\n})();\r\n```\r\n\r\nuse cofy in [mysql](https://github.com/felixge/node-mysql).\r\n```javascript\r\n'use strict';\r\nvar co = require(\"co\");\r\nvar cofy = require(\"cofy\");\r\nvar mysql = require('mysql');\r\n\r\n//(felixge/node-mysql) has no extends entrance. so we can do this.\r\nvar PoolConnection = require('mysql/lib/PoolConnection.js');\r\nvar Pool = require('mysql/lib/Pool.js');\r\nvar PoolCluster = require('mysql/lib/PoolCluster.js');\r\n\r\n//enable mysql to has a co ablitiy.\r\ncofy.class(PoolConnection);\r\ncofy.class(Pool);\r\ncofy.class(PoolCluster);\r\n\r\nvar pool = mysql.createPool({\r\n\thost: \"localhost\",\r\n    database: \"db\",\r\n    user: \"root\",\r\n    password: \"pass\",\r\n});\r\n//now we can use mysql in co \r\nco(function * () {\r\n\tvar con = yield pool.$getConnection();\r\n\t//pay attention on precedence of operator! yield < [] .\r\n\tvar result = (yield con.$query(\"select 1+1\"))[0]; \r\n\tconsole.log(result);\r\n\tcon.release();\r\n})();\r\n\r\n\r\n//use it in transaction\r\nco(function*(){\r\n\tvar con ;\r\n\ttry{\r\n\t\tcon = yield pool.$getConnection();\r\n\t\tyield con.$beginTransaction();\r\n\t\tyield con.$query(\"select some\");\r\n\t\tyield con.$query(\"insert some\");\r\n\t\tyield con.$query(\"update some\");\r\n\t\tyield con.$commit();\r\n\t}catch(e){\r\n\t\tyield con.$rollback();\r\n\t\tconsole.error(e);\r\n\t\t//to do \r\n\t}finally{\r\n\t\tif(con){\r\n\t\t\tcon.release();\r\n\t\t}\r\n\t}\r\n})();\r\n```\r\n\r\nuse cofy in [request](https://github.com/mikeal/request).\r\n```javascript\r\n'use strict';\r\nvar request = require('request');\r\nvar cofy = require('cofy');\r\nvar co = require('co');\r\n\r\nvar $request = cofy.fn(request);\r\n\r\nco(function*(){\r\n\tvar r = yield $request({url:\"http://www.google.com\"});\r\n\tconsole.log(r);\r\n})();\r\n```\r\n\r\ncofy `nodejs` [fs](http://nodejs.org/api/fs.html) api:\r\n```js\r\n'use strict';\r\nvar cofy = require('../');\r\nvar co = require('co');\r\n\r\nvar fs = require('fs');\r\ncofy(fs);\r\n\r\n//fs.exists callback function has no error. we call set `throwable` to false.\r\nfs.$exists = cofy.object(fs.exists , false ,fs);\t\r\n\r\nco(function*(){\r\n\tvar file = '/hello.txt';\r\n\tif(!(yield fs.$exists(file))){\r\n\t\treturn;\r\n\t}\r\n\tvar r = yield fs.$readFile(file,'utf8');\r\n\tconsole.log('fda' , r);\r\n\t//also you can use it in old way\r\n\tfs.readFile(file , 'utf8' , function(e,r){\r\n\t\tif(e){\r\n\t\t\tthrow e;\r\n\t\t}\r\n\t\tconsole.log(r);\r\n\t});\r\n})();\r\n```\r\n\r\n\r\n## cofy API\r\n\r\n### class(constructor,[throwable],[methods],[prefix])\r\n\r\nEnalbe a class or a object or a function to has [co](https://github.com/visionmedia/co) ability.\r\n- `constructor` `{function}` - cofy target.the constructor of the class;\r\n- `throwable` `{bool}` - if `throwable` is true the first argument of callback function arguments will be deemed as a exception.if `throwable` is false,no exception will be throwed ,all arguments will be returned. default is `true`.\r\n- `methods` `{array}` - `Array`,if exists ,cofy will only cofy the methods in the target.\r\n- `prefix` `{string}` - cofy will add function to the target(except target is function),the function name has a prefix. default is `$`.\r\n\r\n### object(object,[throwable],[methods],[prefix],[context])\r\n\r\n- `object` `{function}` - cofy target.the constructor of the class;\r\n- `throwable` `{bool}` - if `throwable` is true the first argument of callback function arguments will be deemed as a exception.if `throwable` is false,no exception will be throwed ,all arguments will be returned. default is `true`.\r\n- `context` `{object}` - the function execute context.\r\n- `methods` `{array}` - `Array`,if exists ,cofy will only cofy the methods in the target.\r\n- `prefix` `{string}` - cofy will add function to the target(except target is function),the function name has a prefix. default is `$`.\r\n\r\n\r\n### fn(fn,[throwable],[context])\r\n- `fn` `{function}` - cofy a function; `function(args , cb)` -> `yeild function(args)`\r\n- `throwable` `{bool}` - if `throwable` is true the first argument of callback function arguments will be deemed as a exception.if `throwable` is false,no exception will be throwed ,all arguments will be returned. default is `true`.\r\n- `context` `{object}` - the function execute context.","maintainers":[{"name":"rocksonzeta","email":"RocksonZeta@gmail.com"}],"time":{"modified":"2022-06-13T06:28:46.428Z","created":"2014-08-10T08:12:42.858Z","0.0.1":"2014-08-10T08:12:42.858Z","0.1.0":"2014-08-19T01:46:54.637Z","0.1.1":"2014-08-23T03:58:08.282Z","0.1.2":"2014-09-24T03:48:22.445Z","1.0.0":"2014-09-24T06:16:33.540Z","2.0.0":"2014-10-17T04:21:36.491Z","2.0.1":"2014-10-17T04:51:02.772Z","2.0.2":"2014-10-17T11:45:09.180Z"},"homepage":"https://github.com/RocksonZeta/cofy","keywords":["cofy","co","koa","async","flow","generator","coro","coroutine"],"repository":{"type":"git","url":"https://github.com/RocksonZeta/cofy.git"},"bugs":{"url":"https://github.com/RocksonZeta/cofy/issues"},"license":"MIT","readmeFilename":"README.md","users":{"rocksonzeta":true}}