aboutsummaryrefslogtreecommitdiff
path: root/node_modules/unique-stream
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2016-11-03 01:33:53 +0100
committerFlorian Dold <florian.dold@gmail.com>2016-11-03 01:33:53 +0100
commitd1291f67551c58168af43698a359cb5ddfd266b0 (patch)
tree55a13ed29fe1915e3f42f1b1b7038dafa2e975a7 /node_modules/unique-stream
parentd0a0695fb5d34996850723f7d4b1b59c3df909c2 (diff)
downloadwallet-core-d1291f67551c58168af43698a359cb5ddfd266b0.tar.xz
node_modules
Diffstat (limited to 'node_modules/unique-stream')
-rw-r--r--node_modules/unique-stream/.npmignore3
-rw-r--r--node_modules/unique-stream/.travis.yml3
-rw-r--r--node_modules/unique-stream/README.md50
-rw-r--r--node_modules/unique-stream/index.js62
-rw-r--r--node_modules/unique-stream/package.json99
-rw-r--r--node_modules/unique-stream/test/index.js109
6 files changed, 97 insertions, 229 deletions
diff --git a/node_modules/unique-stream/.npmignore b/node_modules/unique-stream/.npmignore
deleted file mode 100644
index 444303937..000000000
--- a/node_modules/unique-stream/.npmignore
+++ /dev/null
@@ -1,3 +0,0 @@
-*.swp
-.DS_Store
-node_modules/
diff --git a/node_modules/unique-stream/.travis.yml b/node_modules/unique-stream/.travis.yml
deleted file mode 100644
index 6e5919de3..000000000
--- a/node_modules/unique-stream/.travis.yml
+++ /dev/null
@@ -1,3 +0,0 @@
-language: node_js
-node_js:
- - "0.10"
diff --git a/node_modules/unique-stream/README.md b/node_modules/unique-stream/README.md
index f19b20a37..fce2ec019 100644
--- a/node_modules/unique-stream/README.md
+++ b/node_modules/unique-stream/README.md
@@ -2,11 +2,12 @@
node.js through stream that emits a unique stream of objects based on criteria
-[![build status](https://secure.travis-ci.org/eugeneware/unique-stream.png)](http://travis-ci.org/eugeneware/unique-stream)
+[![Build Status](https://travis-ci.org/eugeneware/unique-stream.svg?branch=master)](https://travis-ci.org/eugeneware/unique-stream)
+[![Coverage Status](https://coveralls.io/repos/eugeneware/unique-stream/badge.svg?branch=master&service=github)](https://coveralls.io/github/eugeneware/unique-stream?branch=master)
## Installation
-Install via npm:
+Install via [npm](https://www.npmjs.com/):
```
$ npm install unique-stream
@@ -28,7 +29,7 @@ function makeStreamOfObjects() {
for (var i = 0; i < 3; i++) {
setImmediate(function () {
s.emit('data', { name: 'Bob', number: 123 });
- --count && end();
+ --count || end();
});
}
@@ -87,3 +88,46 @@ makeStreamOfObjects()
aggregator.on('data', console.log);
```
+
+## Use a custom store to record keys that have been encountered
+
+By default a set is used to store keys encountered so far, in order to check new ones for
+uniqueness. You can supply your own store instead, providing it supports the add(key) and
+has(key) methods. This could allow you to use a persistant store so that already encountered
+objects are not re-streamed when node is reloaded.
+
+``` js
+var keyStore = {
+ store: {},
+
+ add: function(key) {
+ this.store[key] = true;
+ },
+
+ has: function(key) {
+ return this.store[key] !== undefined;
+ }
+};
+
+makeStreamOfObjects()
+ .pipe(unique('name', keyStore))
+ .on('data', console.log);
+```
+
+## Contributing
+
+unique-stream is an **OPEN Open Source Project**. This means that:
+
+> Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project.
+
+See the [CONTRIBUTING.md](https://github.com/eugeneware/unique-stream/blob/master/CONTRIBUTING.md) file for more details.
+
+### Contributors
+
+unique-stream is only possible due to the excellent work of the following contributors:
+
+<table><tbody>
+<tr><th align="left">Eugene Ware</th><td><a href="https://github.com/eugeneware">GitHub/eugeneware</a></td></tr>
+<tr><th align="left">Craig Ambrose</th><td><a href="https://github.com/craigambrose">GitHub/craigambrose</a></td></tr>
+<tr><th align="left">Shinnosuke Watanabe</th><td><a href="https://github.com/shinnn">GitHub/shinnn</a></td></tr>
+</tbody></table>
diff --git a/node_modules/unique-stream/index.js b/node_modules/unique-stream/index.js
index 0c13168e5..a2b292069 100644
--- a/node_modules/unique-stream/index.js
+++ b/node_modules/unique-stream/index.js
@@ -1,4 +1,22 @@
-var Stream = require('stream');
+'use strict';
+
+var filter = require('through2-filter').obj;
+var stringify = require("json-stable-stringify");
+
+var ES6Set;
+if (typeof global.Set === 'function') {
+ ES6Set = global.Set;
+} else {
+ ES6Set = function() {
+ this.keys = [];
+ this.has = function(val) {
+ return this.keys.indexOf(val) !== -1;
+ },
+ this.add = function(val) {
+ this.keys.push(val);
+ }
+ }
+}
function prop(propName) {
return function (data) {
@@ -7,48 +25,24 @@ function prop(propName) {
}
module.exports = unique;
-function unique(propName) {
- var keyfn = JSON.stringify;
+function unique(propName, keyStore) {
+ keyStore = keyStore || new ES6Set();
+
+ var keyfn = stringify;
if (typeof propName === 'string') {
keyfn = prop(propName);
} else if (typeof propName === 'function') {
keyfn = propName;
}
- var seen = {};
- var s = new Stream();
- s.readable = true;
- s.writable = true;
- var pipes = 0;
- s.write = function (data) {
+ return filter(function (data) {
var key = keyfn(data);
- if (seen[key] === undefined) {
- seen[key] = true;
- s.emit('data', data);
- }
- };
- var ended = 0;
- s.end = function (data) {
- if (arguments.length) s.write(data);
- ended++;
- if (ended === pipes || pipes === 0) {
- s.writable = false;
- s.emit('end');
+ if (keyStore.has(key)) {
+ return false;
}
- };
-
- s.destroy = function (data) {
- s.writable = false;
- };
- s.on('pipe', function () {
- pipes++;
+ keyStore.add(key);
+ return true;
});
-
- s.on('unpipe', function () {
- pipes--;
- });
-
- return s;
}
diff --git a/node_modules/unique-stream/package.json b/node_modules/unique-stream/package.json
index 540b29983..034e66ebf 100644
--- a/node_modules/unique-stream/package.json
+++ b/node_modules/unique-stream/package.json
@@ -1,65 +1,18 @@
{
- "_args": [
- [
- {
- "raw": "unique-stream@^1.0.0",
- "scope": null,
- "escapedName": "unique-stream",
- "name": "unique-stream",
- "rawSpec": "^1.0.0",
- "spec": ">=1.0.0 <2.0.0",
- "type": "range"
- },
- "/home/dold/repos/taler/wallet-webex/node_modules/glob-stream"
- ]
- ],
- "_from": "unique-stream@>=1.0.0 <2.0.0",
- "_id": "unique-stream@1.0.0",
- "_inCache": true,
- "_location": "/unique-stream",
- "_npmUser": {
- "name": "eugeneware",
- "email": "eugene@noblesamurai.com"
- },
- "_npmVersion": "1.4.3",
- "_phantomChildren": {},
- "_requested": {
- "raw": "unique-stream@^1.0.0",
- "scope": null,
- "escapedName": "unique-stream",
- "name": "unique-stream",
- "rawSpec": "^1.0.0",
- "spec": ">=1.0.0 <2.0.0",
- "type": "range"
- },
- "_requiredBy": [
- "/glob-stream"
- ],
- "_resolved": "https://registry.npmjs.org/unique-stream/-/unique-stream-1.0.0.tgz",
- "_shasum": "d59a4a75427447d9aa6c91e70263f8d26a4b104b",
- "_shrinkwrap": null,
- "_spec": "unique-stream@^1.0.0",
- "_where": "/home/dold/repos/taler/wallet-webex/node_modules/glob-stream",
- "author": {
- "name": "Eugene Ware",
- "email": "eugene@noblesamurai.com"
- },
- "bugs": {
- "url": "https://github.com/eugeneware/unique-stream/issues"
- },
- "dependencies": {},
+ "name": "unique-stream",
+ "version": "2.2.1",
"description": "node.js through stream that emits a unique stream of objects based on criteria",
- "devDependencies": {
- "after": "~0.8.1",
- "chai": "~1.7.2",
- "mocha": "^1.18.2"
- },
- "directories": {},
- "dist": {
- "shasum": "d59a4a75427447d9aa6c91e70263f8d26a4b104b",
- "tarball": "https://registry.npmjs.org/unique-stream/-/unique-stream-1.0.0.tgz"
+ "repository": "eugeneware/unique-stream",
+ "author": "Eugene Ware <eugene@noblesamurai.com>",
+ "license": "MIT",
+ "files": [
+ "index.js"
+ ],
+ "scripts": {
+ "test": "mocha",
+ "coverage": "istanbul cover _mocha",
+ "coveralls": "${npm_package_scripts_coverage} && istanbul-coveralls"
},
- "homepage": "https://github.com/eugeneware/unique-stream",
"keywords": [
"unique",
"stream",
@@ -67,23 +20,15 @@
"streaming",
"streams"
],
- "license": "BSD",
- "main": "index.js",
- "maintainers": [
- {
- "name": "eugeneware",
- "email": "eugene@noblesamurai.com"
- }
- ],
- "name": "unique-stream",
- "optionalDependencies": {},
- "readme": "ERROR: No README data found!",
- "repository": {
- "type": "git",
- "url": "git+https://github.com/eugeneware/unique-stream.git"
+ "dependencies": {
+ "json-stable-stringify": "^1.0.0",
+ "through2-filter": "^2.0.0"
},
- "scripts": {
- "test": "mocha"
- },
- "version": "1.0.0"
+ "devDependencies": {
+ "after": "~0.8.1",
+ "chai": "^3.0.0",
+ "istanbul": "^0.4.2",
+ "istanbul-coveralls": "^1.0.3",
+ "mocha": "^2.1.0"
+ }
}
diff --git a/node_modules/unique-stream/test/index.js b/node_modules/unique-stream/test/index.js
deleted file mode 100644
index fca02b7e1..000000000
--- a/node_modules/unique-stream/test/index.js
+++ /dev/null
@@ -1,109 +0,0 @@
-var expect = require('chai').expect
- , unique = require('..')
- , Stream = require('stream')
- , after = require('after')
- , setImmediate = global.setImmediate || process.nextTick;
-
-describe('unique stream', function() {
-
- function makeStream(type) {
- var s = new Stream();
- s.readable = true;
-
- var n = 10;
- var next = after(n, function () {
- setImmediate(function () {
- s.emit('end');
- });
- });
-
- for (var i = 0; i < n; i++) {
- var o = {
- type: type,
- name: 'name ' + i,
- number: i * 10
- };
-
- (function (o) {
- setImmediate(function () {
- s.emit('data', o);
- next();
- });
- })(o);
- }
- return s;
- }
-
- it('should be able to uniqueify objects based on JSON data', function(done) {
- var aggregator = unique();
- makeStream('a')
- .pipe(aggregator);
- makeStream('a')
- .pipe(aggregator);
-
- var n = 0;
- aggregator
- .on('data', function () {
- n++;
- })
- .on('end', function () {
- expect(n).to.equal(10);
- done();
- });
- });
-
- it('should be able to uniqueify objects based on a property', function(done) {
- var aggregator = unique('number');
- makeStream('a')
- .pipe(aggregator);
- makeStream('b')
- .pipe(aggregator);
-
- var n = 0;
- aggregator
- .on('data', function () {
- n++;
- })
- .on('end', function () {
- expect(n).to.equal(10);
- done();
- });
- });
-
- it('should be able to uniqueify objects based on a function', function(done) {
- var aggregator = unique(function (data) {
- return data.name;
- });
-
- makeStream('a')
- .pipe(aggregator);
- makeStream('b')
- .pipe(aggregator);
-
- var n = 0;
- aggregator
- .on('data', function () {
- n++;
- })
- .on('end', function () {
- expect(n).to.equal(10);
- done();
- });
- });
-
- it('should be able to handle uniqueness when not piped', function(done) {
- var stream = unique();
- var count = 0;
- stream.on('data', function (data) {
- expect(data).to.equal('hello');
- count++;
- });
- stream.on('end', function() {
- expect(count).to.equal(1);
- done();
- });
- stream.write('hello');
- stream.write('hello');
- stream.end();
- });
-});