@transformation/core
Advanced tools
Comparing version 3.1.0 to 3.2.0
{ | ||
"name": "@transformation/core", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"description": "Create transformation pipelines", | ||
@@ -32,3 +32,3 @@ "main": "./src/index.js", | ||
}, | ||
"gitHead": "42ef76c4f3d05223db163ebaa807c3b8ccfcec96" | ||
"gitHead": "c8a5195abaf9ac00d113d4b98b8b4ddd82bf3451" | ||
} |
@@ -23,4 +23,6 @@ # @transformation/core | ||
- [fork](#fork) | ||
- [fromJSON](#fromjson) | ||
- [groupBy](#groupby) | ||
- [interleave](#interleave) | ||
- [join](#join) | ||
- [keyBy](#keyby) | ||
@@ -43,2 +45,3 @@ - [map](#map) | ||
- [toArray](#toarray) | ||
- [toJSON](#tojson) | ||
- [transform](#transform) | ||
@@ -571,2 +574,21 @@ - [uniq](#uniq) | ||
## fromJSON | ||
Parses every items in the pipeline as JSON. | ||
```js | ||
import { fromJSON } from "@transformation/core"; | ||
``` | ||
```js | ||
await expect( | ||
pipeline( | ||
emitItems('{ "foo": "bar", "year": 2000 }', "1", "{}", "true"), | ||
fromJSON() | ||
), | ||
"to yield items", | ||
[{ foo: "bar", year: 2000 }, 1, {}, true] | ||
); | ||
``` | ||
## groupBy | ||
@@ -1297,2 +1319,28 @@ | ||
## toJSON | ||
JSON stringify every item in the pipeline. | ||
```js | ||
import { toJSON } from "@transformation/core"; | ||
``` | ||
```js | ||
await expect( | ||
pipeline(emitItems({ foo: "bar", year: 2000 }, 1, {}, true), toJSON()), | ||
"to yield items", | ||
['{"foo":"bar","year":2000}', "1", "{}", "true"] | ||
); | ||
``` | ||
All arguments will be forwarded to JSON.stringify. | ||
```js | ||
await expect( | ||
pipeline(emitItems({ foo: "bar", year: 2000 }, 1, {}, true), toJSON(null, 2)), | ||
"to yield items", | ||
['{\n "foo": "bar",\n "year": 2000\n}', "1", "{}", "true"] | ||
); | ||
``` | ||
## transform | ||
@@ -1664,3 +1712,7 @@ | ||
toArray(), | ||
map(items => items.reduce((sum, n) => sum + n, 0) / items.length) | ||
map(items => | ||
items.length === 0 | ||
? NaN | ||
: items.reduce((sum, n) => sum + n, 0) / items.length | ||
) | ||
); | ||
@@ -1667,0 +1719,0 @@ |
@@ -1,18 +0,10 @@ | ||
const { go, close, chan, put } = require("medium"); | ||
const channelStep = require("./channelStep"); | ||
const step = require("./step"); | ||
const emitItems = (...items) => | ||
channelStep((input, errors) => { | ||
const output = chan(items.length); | ||
go(async () => { | ||
for (let item of items) { | ||
await put(output, item); | ||
} | ||
close(output); | ||
}); | ||
return output; | ||
step(async ({ take, put, CLOSED }) => { | ||
for (let item of items) { | ||
await put(item); | ||
} | ||
}); | ||
module.exports = emitItems; |
@@ -18,2 +18,3 @@ const Group = require("./Group"); | ||
const fork = require("./fork"); | ||
const fromJSON = require("./fromJSON"); | ||
const groupBy = require("./groupBy"); | ||
@@ -41,2 +42,3 @@ const interleave = require("./interleave"); | ||
const toArray = require("./toArray"); | ||
const toJSON = require("./toJSON"); | ||
const transform = require("./transform"); | ||
@@ -69,2 +71,3 @@ const uniq = require("./uniq"); | ||
fork, | ||
fromJSON, | ||
groupBy, | ||
@@ -94,2 +97,3 @@ interleave, | ||
toArray, | ||
toJSON, | ||
transform, | ||
@@ -96,0 +100,0 @@ uniq, |
120098
99
3068
1721