Comparing version 0.1.8 to 0.1.9
@@ -11,8 +11,23 @@ (function (factory) { | ||
function isFunction(fn) { | ||
var ArrayProto = Array.prototype, ObjProto = Object.prototype; | ||
var | ||
push = ArrayProto.push, | ||
slice = ArrayProto.slice, | ||
concat = ArrayProto.concat, | ||
shift = ArrayProto.shift, | ||
toString = ObjProto.toString; | ||
Y.VERSION = '0.1.9'; | ||
Y.isFunction = function(fn) { | ||
return fn instanceof Function; | ||
} | ||
}; | ||
Y.isPromise = function (obj) { | ||
return !!obj && isFunction(obj.then); | ||
return !!obj && Y.isFunction(obj.then); | ||
}; | ||
@@ -25,13 +40,14 @@ | ||
Y.isGenerator = function (obj) { | ||
return Object.prototype.toString.call(obj) === '[object Generator]'; | ||
return toString.call(obj) === '[object Generator]'; | ||
}; | ||
Y.isGeneratorFn = function (fn) { | ||
return isFunction(fn) && fn.constructor.name === 'GeneratorFunction'; | ||
return Y.isFunction(fn) && fn.constructor.name === 'GeneratorFunction'; | ||
}; | ||
var AP = Array.prototype; | ||
Y.ncall = function (fn) { | ||
fn = AP.shift.call(arguments); | ||
fn = shift.call(arguments); | ||
return Y.napply(fn, arguments); | ||
@@ -43,3 +59,3 @@ }; | ||
AP.push.call(args, function (err, res) { | ||
push.call(args, function (err, res) { | ||
!err ? resolve(res) : reject(err); | ||
@@ -58,12 +74,14 @@ }); | ||
Y.nwrap = function (fn) { | ||
var args = Array.prototype.slice.call(arguments, 1); | ||
var args = slice.call(arguments, 1); | ||
return function () { | ||
return Y.napply(fn, args.concat( Array.prototype.slice.call(arguments) )); | ||
return Y.napply(fn, args.concat( slice.call(arguments) )); | ||
}; | ||
}; | ||
Y.all = function (arr) { | ||
if (!(arr instanceof Array)) { | ||
arr = AP.slice.call(arguments); | ||
arr = slice.call(arguments); | ||
} | ||
@@ -88,2 +106,3 @@ | ||
function Y(fn) { | ||
@@ -143,6 +162,7 @@ if (!Y.isGeneratorFn(fn)) { | ||
return resolve; | ||
}; | ||
} | ||
return Y; | ||
}); | ||
}); |
{ | ||
"name": "yielding", | ||
"version": "0.1.8", | ||
"version": "0.1.9", | ||
"description": "Easy generators", | ||
@@ -5,0 +5,0 @@ "main": "./lib/yielding.js", |
@@ -85,8 +85,11 @@ var Y = require('..'); | ||
describe('nwrap()', function() { | ||
var filename = 'test/example.txt'; | ||
var read = Y.nwrap(fs.readFile); | ||
var readWithParams = Y.nwrap(fs.readFile, filename, 'utf-8'); | ||
it('return promise', function() { | ||
expect( Y.isPromise(read()) ).to.be.true; | ||
expect( Y.isPromise(readWithParams()) ).to.be.true; | ||
}); | ||
it('read a file', function(done) { | ||
read('test/example.txt', 'utf-8').then(function(content) { | ||
read(filename, 'utf-8').then(function(content) { | ||
expect('content').to.be.a('string'); | ||
@@ -96,2 +99,8 @@ done(); | ||
}); | ||
it('read a file with params', function(done) { | ||
readWithParams().then(function(content) { | ||
expect('content').to.be.a('string'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
@@ -98,0 +107,0 @@ }); |
13120
321