Comparing version 4.4.0 to 5.0.0
@@ -10,3 +10,2 @@ "use strict"; | ||
module.exports = function(buf, search, offset, stop) { | ||
@@ -39,2 +38,1 @@ stop = Math.min(stop || buf.length, buf.length); | ||
}; | ||
@@ -7,3 +7,2 @@ "use strict"; | ||
function patchJSON(target, cb, src) { | ||
@@ -16,4 +15,2 @@ var entry = JSON.parse(fs.readFileSync(src || target)); | ||
module.exports = patchJSON; | ||
@@ -7,11 +7,11 @@ "use strict"; | ||
module.exports = (obj1, obj2) => { | ||
var stream_ids = union(keys(obj1), keys(obj2)); | ||
var ids = union(keys(obj1), keys(obj2)); | ||
var modified = []; | ||
stream_ids.forEach((stream_id) => { | ||
var valObj1 = obj1[stream_id]; | ||
var valObj2 = obj2[stream_id]; | ||
ids.forEach((id) => { | ||
var valObj1 = obj1[id]; | ||
var valObj2 = obj2[id]; | ||
if(!valObj1 || !valObj2 || valObj1 != valObj2) | ||
modified.push(stream_id); | ||
modified.push(id); | ||
}); | ||
return modified; | ||
}; |
{ | ||
"name": "nyks", | ||
"version": "4.4.0", | ||
"version": "5.0.0", | ||
"description": "nodejs exupery style", | ||
@@ -41,3 +41,2 @@ "keywords": [ | ||
"scripts": { | ||
"todo": "color crypto date fs function generator http lang math node_modules object path process promise require src stream string", | ||
"mocha": "node node_modules/mocha/bin/_mocha", | ||
@@ -44,0 +43,0 @@ "jscs": "jscs --config=node_modules/ivs-jssc/ivs-node.jscsrc test", |
@@ -0,7 +1,34 @@ | ||
# Async | ||
Control flow ala ES7 async/await with async.js (v2) signatures | ||
------ | ||
## Table of Contents | ||
* [Motivation](#Motivation) | ||
* [API](#API) | ||
* [eachLimit()](#eachLimit) | ||
* [eachOfLimit()](#eachOfLimit) | ||
* [each()](#each) | ||
* [eachOf()](#eachOf) | ||
* [eachSeries()](#eachSeries) | ||
* [eachOfSeries()](#eachOfSeries) | ||
* [sleep()](#sleep) | ||
* [timeout()](#timeout) | ||
* [setImmediate()](#setImmediate) | ||
* [queue()](#queue) | ||
* [throttle()](#throttle) | ||
* [Tests](#Tests) | ||
* [TODO](#TODO) | ||
* [Credits](#Credits) | ||
* [Alternatives / relatives](#Alternatives) | ||
* [Shoutbox, keywords, SEO love](#keywords) | ||
------ | ||
<a name="Motivation"></a> | ||
# Motivation | ||
[nyks/async](https://github.com/131/nyks/tree/master/async) provide javascript async/await equivalent signatures of the excellent [async](https://github.com/caolan/async) workflow library. | ||
[nyks/async](./async/) provide javascript async/await equivalent signatures of the excellent [async](https://github.com/caolan/async) workflow library. | ||
@@ -11,7 +38,7 @@ Module are exported in standard commonJS module format and written in strict format. (no transpilation required nor used). | ||
**nyks/async** is not a wrapper on **async**, but rather leverages the full potential of native async/await & promises contract. Code tend to be small & very efficient (far more simplier than using callbacks), just give [nyks/async/queue.js](./async/queue.js) a look. | ||
**nyks/async** is not a wrapper on **async**, but rather leverages the full potential of native async/await & promises contract. Code tend to be small & very efficient (far more simplier than using callbacks), just give [nyks/async/queue.js](https://github.com/131/nyks/tree/master/async/queue.js) a look | ||
## Addition to the async library signatures / promise pooling | ||
## Addition to the async library signatures / promise pooling | ||
* Async functions cannot use arrow function binding style, yet it might be usefull to bind nyks/async closure, therefore, you can use an extra optional args to all signature to set async function binding context. (i.e. as in native [.forEach](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach) ) | ||
@@ -21,29 +48,46 @@ * Per design, it's easy to "throttle" a function that return a Promise ; checkout the "throttle" API for a way to make an ultra simple http request pooling. | ||
------ | ||
<a name="API"></a> | ||
# API | ||
## nyks/async/eachLimit(arr, concurrency, *thunk [, thisobj]) | ||
Nothing special here | ||
## nyks/async/eachSeries(arr, *thunk [, thisobj] ) | ||
// = eachLimit concurrency = 1 | ||
## nyks/async/each(arr, *thunk [, thisobj]) | ||
// = eachLimit concurrency = arr.length | ||
<a name="eachLimit"></a> | ||
## eachLimit(arr, concurrency, thunk [, thisobj]) : Promise | ||
## nyks/async/eachOfLimit (dict, concurrency, *thunk [, thisobj]) | ||
Nothing special here neither | ||
Applies the function 'thunk' to each item in 'arr', in parallel, with a limit async operations of 'concurrency' at a time. The 'thunk' is called with an item from the Array 'arr'. | ||
## nyks/async/eachOfSeries(dict, *thunk [, thisobj]) | ||
// = eachOfLimit concurrency = 1 | ||
```javascript | ||
const eachLimit = require('nyks/async/eachLimit'); | ||
## nyks/async/eachOf(dict, *thunk [, thisobj]) | ||
// = eachOfLimit concurrency = dict.length | ||
(async function() { | ||
var stuffs = [1, 2, 3, 5, 6]; | ||
await eachLimit(stuffs, 2, async function(id) { | ||
await dootherStuffs(id); | ||
}); | ||
})(); | ||
``` | ||
const eachLimit = require('nyks/async/eachLimit'); | ||
------ | ||
<a name="eachOfLimit"></a> | ||
## eachOfLimit(dict, concurrency, thunk [, thisobj]) : Promise | ||
Applies the function 'thunk' to each item of 'dict', in parallel, with a limit async operations of 'concurrency' at a time. The 'thunk' is called with an item from the Object 'dict'. | ||
```javascript | ||
const eachOfLimit = require('nyks/async/eachOfLimit'); | ||
(async function() { | ||
var stuffs = [1,2,3, 5, 7] | ||
var stuffs = { | ||
'number' : 1, | ||
'number' : 2, | ||
'number' : 3, | ||
'number' : 4 | ||
}; | ||
await eachLimit(stuffs, 2, function*(id){ | ||
await eachOfLimit(stuffs, 2, async function(id, key) { | ||
await dootherStuffs(id); | ||
@@ -55,15 +99,164 @@ }); | ||
## nyks/async/setImmediate(fn) | ||
------ | ||
<a name="each"></a> | ||
## each(arr, thunk [, thisobj]) : Promise | ||
Like eachLimit with a concurrency of arr.length. | ||
```javascript | ||
const each = require('nyks/async/each'); | ||
(async function() { | ||
var stuffs = [1, 2, 3, 5, 6]; | ||
await each(stuffs, async function(id) { | ||
await dootherStuffs(id); | ||
}); | ||
})(); | ||
``` | ||
------ | ||
<a name="eachOf"></a> | ||
## eachOf(dict, thunk [, thisobj]) : Promise | ||
Like eachOfLimit with a concurrency of dict.length. | ||
```javascript | ||
const eachOf = require('nyks/async/eachOf'); | ||
(async function() { | ||
var stuffs = { | ||
'number' : 1, | ||
'number' : 2, | ||
'number' : 3, | ||
'number' : 4 | ||
}; | ||
await eachOf(stuffs, async function(id, key) { | ||
await dootherStuffs(id); | ||
}); | ||
})(); | ||
``` | ||
------ | ||
<a name="eachSeries"></a> | ||
## eachSeries(arr, thunk [, thisobj]) : Function | ||
Like eachLimit with a concurrency of 1. | ||
```javascript | ||
const eachSeries = require('nyks/async/eachSeries'); | ||
(async function() { | ||
var stuffs = [1, 2, 3, 5, 6]; | ||
await eachSeries(stuffs, async function(id) { | ||
await dootherStuffs(id); | ||
}); | ||
})(); | ||
``` | ||
------ | ||
<a name="eachOfSeries"></a> | ||
## eachOfSeries(dict, thunk [, thisobj]) : Function | ||
Like eachOfLimit with a concurrency of 1. | ||
```javascript | ||
const eachOfSeries = require('nyks/async/eachOfSeries'); | ||
(async function() { | ||
var stuffs = { | ||
'number' : 1, | ||
'number' : 2, | ||
'number' : 3, | ||
'number' : 4 | ||
}; | ||
await eachOfSeries(stuffs, async function(id, key) { | ||
await dootherStuffs(id); | ||
}); | ||
})(); | ||
``` | ||
<a name="sleep"></a> | ||
## sleep(timeout) : Promise | ||
setTimeout as a promise. | ||
```javascript | ||
const sleep = require('nyks/async/sleep'); | ||
(async function() { | ||
// this is now | ||
await sleep(2000); | ||
// this is now + 2 secondes | ||
})(); | ||
``` | ||
------ | ||
<a name="timeout"></a> | ||
## timeout(time) : Promise | ||
Reject (throw) if timeout is reached. | ||
```javascript | ||
const timeout = require('nyks/async/timeout'); | ||
(async function() { | ||
let zzz = sleep(3000); | ||
let crash = timeout(2000); | ||
await Promise.all([zzz, crash]); // this is going to throw after 2 secondes | ||
})(); | ||
``` | ||
------ | ||
<a name="setImmediate"></a> | ||
## setImmediate(fn) : Function | ||
Call a function in javascript next tick (using setImmediate API, or timeout 0 pollyfill) | ||
```javascript | ||
const setImmediate = require('nyks/async/setImmediate'); | ||
## q = nyks/async/queue(*thunk, concurrency) | ||
Return a QueueObject you can push task into. | ||
### await q.push(task) | ||
Wait for thunk to process task (wait for worker, if needed) | ||
(async function() { | ||
// this is now | ||
await setImmediate(); | ||
// this is still now... | ||
})(); | ||
``` | ||
const queue = require('nyks/async/queue'); | ||
const fetch = require('node-fetch'); | ||
------ | ||
<a name="queue"></a> | ||
## queue(thunk, concurrency) : Object | ||
Return a QueueObject you can push task into. | ||
Wait for thunk to process task (wait for worker, if needed). | ||
```javascript | ||
const fetch = require('node-fetch'); | ||
const queue = require('nyks/async/queue'); | ||
var q = queue(fetch, 1); //let's be nice | ||
@@ -80,9 +273,13 @@ | ||
## nyks/async/throttle | ||
Throttle any function that return a promise, sugar syntax helper for nyks/async/queue | ||
------ | ||
<a name="throttle"></a> | ||
## throttle(thunk, concurrency) : Function | ||
``` | ||
Throttle any function that return a promise, sugar syntax helper for nyks/async/queue. | ||
```javascript | ||
const fetch = require('node-fetch'); | ||
const throttle = require('nyks/async/throttle'); | ||
var fetch = require('node-fetch'); | ||
fetch = throttle(fetch, 1); //make fetch behave nicely | ||
@@ -98,6 +295,12 @@ | ||
``` | ||
------ | ||
<a name="Tests"></a> | ||
# Tests | ||
nyks/async is tested against async test suite (of course) | ||
------ | ||
<a nam="TODO"></a> | ||
# TODO | ||
@@ -107,2 +310,5 @@ * Get rich or die tryin' | ||
------ | ||
<a name="Credits"></a> | ||
# Credits | ||
@@ -113,13 +319,14 @@ * [131](https://github.com/131) | ||
## Alternatives / relatives | ||
* [koa-async](https://github.com/eladnava/koa-async) ; a clever Promisify wrapper on top of async (but not leveraging the full potential of ES7 async/await capabilities) | ||
* [caolan/async/asyncify.js](https://github.com/caolan/async/blob/master/lib/asyncify.js) goes the same as koa-async. | ||
* [es6-promise-pool](https://github.com/timdp/es6-promise-pool) ; equivalent to nyks/async/queue, with a different API | ||
------ | ||
<a name="Alternatives"></a> | ||
# Alternatives / relatives | ||
* [koa-async](https://github.com/eladnava/koa-async); a clever Promisify wrapper on top of async (but not leveraging the full potential of ES7 async/await capabilities) | ||
* [caolan/async/asyncify.js](https://github.com/caolan/async/blob/master/lib/asyncify.js); goes the same as koa-async. | ||
* [es6-promise-pool](https://github.com/timdp/es6-promise-pool); equivalent to nyks/async/queue, with a different API | ||
------ | ||
<a name="keywords"></a> | ||
# Shoutbox, keywords, SEO love | ||
async/await, co, nyks/async, promise, Promises, yield, async, queue, map, throttle, "Let's have a beer & talk in Paris" | ||
@@ -41,3 +41,3 @@ # Motivation | ||
Online documentation can be found inside the `doc` folder. | ||
Online documentation can be found inside the [doc folder](./doc#top). | ||
@@ -51,1 +51,2 @@ ## License | ||
* [cnyks](https://github.com/131/cnyks), CLI runner & related tools | ||
* [Kalmani](https://github.com/Kalmani/) for documentation |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
60375
51
108
1521