forked from enviPath/enviPy
Current Dev State
This commit is contained in:
20
static/js/ketcher2/node_modules/unique-stream/LICENSE
generated
vendored
Normal file
20
static/js/ketcher2/node_modules/unique-stream/LICENSE
generated
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
Copyright 2014 Eugene Ware
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
89
static/js/ketcher2/node_modules/unique-stream/README.md
generated
vendored
Normal file
89
static/js/ketcher2/node_modules/unique-stream/README.md
generated
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
# unique-stream
|
||||
|
||||
node.js through stream that emits a unique stream of objects based on criteria
|
||||
|
||||
[](http://travis-ci.org/eugeneware/unique-stream)
|
||||
|
||||
## Installation
|
||||
|
||||
Install via npm:
|
||||
|
||||
```
|
||||
$ npm install unique-stream
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Dedupe a ReadStream based on JSON.stringify:
|
||||
|
||||
``` js
|
||||
var unique = require('unique-stream')
|
||||
, Stream = require('stream');
|
||||
|
||||
// return a stream of 3 identical objects
|
||||
function makeStreamOfObjects() {
|
||||
var s = new Stream;
|
||||
s.readable = true;
|
||||
var count = 3;
|
||||
for (var i = 0; i < 3; i++) {
|
||||
setImmediate(function () {
|
||||
s.emit('data', { name: 'Bob', number: 123 });
|
||||
--count && end();
|
||||
});
|
||||
}
|
||||
|
||||
function end() {
|
||||
s.emit('end');
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
// Will only print out one object as the rest are dupes. (Uses JSON.stringify)
|
||||
makeStreamOfObjects()
|
||||
.pipe(unique())
|
||||
.on('data', console.log);
|
||||
|
||||
```
|
||||
|
||||
### Dedupe a ReadStream based on an object property:
|
||||
|
||||
``` js
|
||||
// Use name as the key field to dedupe on. Will only print one object
|
||||
makeStreamOfObjects()
|
||||
.pipe(unique('name'))
|
||||
.on('data', console.log);
|
||||
```
|
||||
|
||||
### Dedupe a ReadStream based on a custom function:
|
||||
|
||||
``` js
|
||||
// Use a custom function to dedupe on. Use the 'number' field. Will only print one object.
|
||||
makeStreamOfObjects()
|
||||
.pipe(function (data) {
|
||||
return data.number;
|
||||
})
|
||||
.on('data', console.log);
|
||||
```
|
||||
|
||||
## Dedupe multiple streams
|
||||
|
||||
The reason I wrote this was to dedupe multiple object streams:
|
||||
|
||||
``` js
|
||||
var aggregator = unique();
|
||||
|
||||
// Stream 1
|
||||
makeStreamOfObjects()
|
||||
.pipe(aggregator);
|
||||
|
||||
// Stream 2
|
||||
makeStreamOfObjects()
|
||||
.pipe(aggregator);
|
||||
|
||||
// Stream 3
|
||||
makeStreamOfObjects()
|
||||
.pipe(aggregator);
|
||||
|
||||
aggregator.on('data', console.log);
|
||||
```
|
||||
54
static/js/ketcher2/node_modules/unique-stream/index.js
generated
vendored
Normal file
54
static/js/ketcher2/node_modules/unique-stream/index.js
generated
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
var Stream = require('stream');
|
||||
|
||||
function prop(propName) {
|
||||
return function (data) {
|
||||
return data[propName];
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = unique;
|
||||
function unique(propName) {
|
||||
var keyfn = JSON.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) {
|
||||
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');
|
||||
}
|
||||
};
|
||||
|
||||
s.destroy = function (data) {
|
||||
s.writable = false;
|
||||
};
|
||||
|
||||
s.on('pipe', function () {
|
||||
pipes++;
|
||||
});
|
||||
|
||||
s.on('unpipe', function () {
|
||||
pipes--;
|
||||
});
|
||||
|
||||
return s;
|
||||
}
|
||||
59
static/js/ketcher2/node_modules/unique-stream/package.json
generated
vendored
Normal file
59
static/js/ketcher2/node_modules/unique-stream/package.json
generated
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
{
|
||||
"_from": "unique-stream@^1.0.0",
|
||||
"_id": "unique-stream@1.0.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-1ZpKdUJ0R9mqbJHnAmP40mpLEEs=",
|
||||
"_location": "/unique-stream",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "unique-stream@^1.0.0",
|
||||
"name": "unique-stream",
|
||||
"escapedName": "unique-stream",
|
||||
"rawSpec": "^1.0.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^1.0.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/glob-stream"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/unique-stream/-/unique-stream-1.0.0.tgz",
|
||||
"_shasum": "d59a4a75427447d9aa6c91e70263f8d26a4b104b",
|
||||
"_spec": "unique-stream@^1.0.0",
|
||||
"_where": "/home/manfred/enviPath/ketcher2/ketcher/node_modules/glob-stream",
|
||||
"author": {
|
||||
"name": "Eugene Ware",
|
||||
"email": "eugene@noblesamurai.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/eugeneware/unique-stream/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"deprecated": false,
|
||||
"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"
|
||||
},
|
||||
"homepage": "https://github.com/eugeneware/unique-stream#readme",
|
||||
"keywords": [
|
||||
"unique",
|
||||
"stream",
|
||||
"unique-stream",
|
||||
"streaming",
|
||||
"streams"
|
||||
],
|
||||
"license": "BSD",
|
||||
"main": "index.js",
|
||||
"name": "unique-stream",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/eugeneware/unique-stream.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha"
|
||||
},
|
||||
"version": "1.0.0"
|
||||
}
|
||||
109
static/js/ketcher2/node_modules/unique-stream/test/index.js
generated
vendored
Normal file
109
static/js/ketcher2/node_modules/unique-stream/test/index.js
generated
vendored
Normal file
@ -0,0 +1,109 @@
|
||||
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();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user