Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

genify

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

genify - npm Package Compare versions

Comparing version 1.0.7 to 1.0.9

2

package.json
{
"name": "genify",
"version": "1.0.7",
"version": "1.0.9",
"description": "Convert passed javascript object to generator",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -5,3 +5,3 @@ genify

Wrapping object generator properties into co
Bringing power of javascript generators into normal javascript environment

@@ -19,17 +19,26 @@ ### Installation

var fs = require('fs');
var co = require('co');
var genify = require('genify');
// genify is taking care of wrapping all object generator properties into co function,
// and returning generator result as resolved promise,
// or in case of error -> rejected promise with error object
// wrap your object into genify function
var object = genify({
readFile: function * (file) {
return yield Q.nfcall(fs.readFile, file);
concatFiles: function * (file1, file2, outFile) {
file1 = yield Q.nfcall(fs.readFile, file1);
file2 = yield Q.nfcall(fs.readFile, file2);
var concated = file1 + file2;
yield Q.nfcall(fs.writeFile, outFile, concated);
return concated;
}
});
co(function * () {
console.log(yield object.readFile('./somefile.txt'));
})();
// concatFiles is generator function, and it is using generator power to do some things,
// and here you are using that power inside normal javascript environment,
// handling results and errors using promises
object.concatFiles('./somefile1.txt', './somefile2.txt', './concated.txt').then(function (res) {
// do something with result
}, function (err) {
// do something with error
});
```

@@ -36,0 +45,0 @@

@@ -92,3 +92,21 @@ 'use strict';

});
it('should contain .then on returned result', function () {
var promise = object.readFile('./test/test.txt');
promise.should.have.property('then');
});
it('should be able to read value from promise', function (done) {
var promise = object.readFile('./test/test.txt');
promise.then(function (res) {
if (done) {
done();
} else {
done('No value returned!');
}
}, done).done();
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc