mirror of
https://github.com/morhetz/gruvbox.git
synced 2025-11-16 07:13:46 -05:00
chore(package): re-init package with commitizen and standard-release
This commit is contained in:
80
node_modules/stream-to-observable/index.js
generated
vendored
Normal file
80
node_modules/stream-to-observable/index.js
generated
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
'use strict';
|
||||
|
||||
function or(option, alternate, required) {
|
||||
var result = option === false ? false : option || alternate;
|
||||
|
||||
if ((required && !result) || (result && typeof result !== 'string')) {
|
||||
throw new TypeError(alternate + 'Event must be a string.');
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
module.exports = function create(Observable) {
|
||||
return function (stream, opts) {
|
||||
opts = opts || {};
|
||||
|
||||
var complete = false;
|
||||
var dataListeners = [];
|
||||
var awaited = opts.await;
|
||||
var dataEvent = or(opts.dataEvent, 'data', true);
|
||||
var errorEvent = or(opts.errorEvent, 'error');
|
||||
var endEvent = or(opts.endEvent, 'end');
|
||||
|
||||
function cleanup() {
|
||||
complete = true;
|
||||
dataListeners.forEach(function (listener) {
|
||||
stream.removeListener(dataEvent, listener);
|
||||
});
|
||||
dataListeners = null;
|
||||
}
|
||||
|
||||
var completion = new Promise(function (resolve, reject) {
|
||||
function onEnd(result) {
|
||||
if (awaited) {
|
||||
awaited.then(resolve);
|
||||
} else {
|
||||
resolve(result);
|
||||
}
|
||||
}
|
||||
|
||||
if (endEvent) {
|
||||
stream.once(endEvent, onEnd);
|
||||
} else if (awaited) {
|
||||
onEnd();
|
||||
}
|
||||
|
||||
if (errorEvent) {
|
||||
stream.once(errorEvent, reject);
|
||||
}
|
||||
|
||||
if (awaited) {
|
||||
awaited.catch(reject);
|
||||
}
|
||||
}).catch(function (err) {
|
||||
cleanup();
|
||||
throw err;
|
||||
}).then(function (result) {
|
||||
cleanup();
|
||||
return result;
|
||||
});
|
||||
|
||||
return new Observable(function (observer) {
|
||||
if (!complete) {
|
||||
var onData = function onData(data) {
|
||||
observer.next(data);
|
||||
};
|
||||
stream.on(dataEvent, onData);
|
||||
dataListeners.push(onData);
|
||||
}
|
||||
|
||||
completion
|
||||
.catch(function (err) {
|
||||
observer.error(err);
|
||||
})
|
||||
.then(function (result) {
|
||||
observer.complete(result);
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
21
node_modules/stream-to-observable/license
generated
vendored
Normal file
21
node_modules/stream-to-observable/license
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) James Talmage <james@talmage.io> (github.com/jamestalmage)
|
||||
|
||||
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.
|
||||
39
node_modules/stream-to-observable/package.json
generated
vendored
Normal file
39
node_modules/stream-to-observable/package.json
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"name": "stream-to-observable",
|
||||
"version": "0.1.0",
|
||||
"description": "Convert Node Streams into ECMAScript-Observables",
|
||||
"license": "MIT",
|
||||
"repository": "jamestalmage/stream-to-observable",
|
||||
"author": {
|
||||
"name": "James Talmage",
|
||||
"email": "james@talmage.io",
|
||||
"url": "github.com/jamestalmage"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.12.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && nyc --reporter=lcov --reporter=text ava"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"zen.js",
|
||||
"rxjs.js",
|
||||
"rxjs-all.js"
|
||||
],
|
||||
"keywords": [
|
||||
"stream",
|
||||
"observable"
|
||||
],
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"array-to-events": "^1.0.0",
|
||||
"ava": "^0.14.0",
|
||||
"coveralls": "^2.11.9",
|
||||
"delay": "^1.3.1",
|
||||
"nyc": "^6.4.0",
|
||||
"rxjs": "^5.0.0-beta.6",
|
||||
"xo": "^0.14.0",
|
||||
"zen-observable": "^0.2.1"
|
||||
}
|
||||
}
|
||||
122
node_modules/stream-to-observable/readme.md
generated
vendored
Normal file
122
node_modules/stream-to-observable/readme.md
generated
vendored
Normal file
@@ -0,0 +1,122 @@
|
||||
# stream-to-observable [](https://travis-ci.org/jamestalmage/stream-to-observable) [](https://coveralls.io/github/jamestalmage/stream-to-observable?branch=master)
|
||||
|
||||
> Convert Node Streams into ECMAScript-Observables
|
||||
|
||||
[`Observables`](https://github.com/zenparsing/es-observable) are rapidly gaining popularity. They have much in common with Streams, in that they both represent data that arrives over time. Most Observable implementations provide expressive methods for filtering and mutating incoming data. Methods like `.map()`, `.filter()`, and `.forEach` behave very similarly to their Array counterparts, so using Observables can be very intuitive.
|
||||
|
||||
[Learn more about Observables](#learn-about-observables)
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install --save stream-to-observable
|
||||
|
||||
# You also need to install an Observable implementation (pick one):
|
||||
|
||||
$ npm install --save zen-observable rxjs
|
||||
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const fs = require('fs');
|
||||
const split = require('split');
|
||||
|
||||
// You provide the Observable implmentation
|
||||
const Observable = require('zen-observable')
|
||||
const streamToObservable = require('stream-to-observable')(Observable);
|
||||
|
||||
const readStream = fs
|
||||
.createReadStream('./hello-world.txt', {encoding: 'utf8'})
|
||||
.pipe(split()); // chunks a stream into individual lines
|
||||
|
||||
streamToObservable(readStream)
|
||||
.filter(chunk => /hello/i.test(chunk))
|
||||
.map(chunk => chunk.toUpperCase())
|
||||
.forEach(chunk => {
|
||||
console.log(chunk); // only the lines containing "hello" - and they will be capitalized
|
||||
});
|
||||
```
|
||||
|
||||
There are convenience imports for [`rxjs` observables](http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html) and [`zen-observables`](https://github.com/zenparsing/zen-observable):
|
||||
|
||||
```js
|
||||
const streamToObservable = require('stream-to-observable/zen'); // zen-observables
|
||||
// or
|
||||
const streamToObservable = require('stream-to-observable/rxjs-all'); // full rxjs implementation
|
||||
// or
|
||||
const streamToObservable = require('stream-to-observable/rxjs'); // minimal rxjs implementation
|
||||
// you can patch the minimal rxjs.
|
||||
require('rxjs/add/operator/map');
|
||||
```
|
||||
|
||||
None of the above implementations are included as dependencies of this package, so you still need to install them yourself using `npm install`. If using the minimal `rxjs` import, be sure to see [the documentation](http://reactivex.io/rxjs/manual/installation.html) regarding patching it with additional convenience methods.
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### streamToObservable(stream, [options])
|
||||
|
||||
#### stream
|
||||
|
||||
Type: [`ReadableStream`](https://nodejs.org/api/stream.html#stream_class_stream_readable)
|
||||
|
||||
*Note:*
|
||||
`stream` can technically be any [`EventEmitter`](https://nodejs.org/api/events.html#events_class_eventemitter) instance. By default the `stream-to-observable` listens to the standard Stream events (`data`, `error`, and `end`), but those are configurable via the `options` parameter. If you are using this with a standard Stream, you likely won't need the `options` parameter.
|
||||
|
||||
#### options
|
||||
|
||||
##### await
|
||||
|
||||
Type: `Promies`<br>
|
||||
|
||||
If provided, the Observable will not "complete" until `await` is resolved. If `await` is rejected, the Observable will immediately emit an `error` event and disconnect from the stream. This is mostly useful when attaching to the `stdin` or `stdout` streams of a [`child_process`](https://nodejs.org/api/child_process.html#child_process_child_stdio). Those streams usually do not emit `error` events, even if the underlying process exits with an error. This provides a means to reject the Observable if the child process exits with an unexpected error code.
|
||||
|
||||
##### endEvent
|
||||
|
||||
Type: `String` or `false` <br>
|
||||
Default: `"end"`
|
||||
|
||||
If you are using an `EventEmitter` or non-standard Stream, you can change which event signals that the Observable should be completed.
|
||||
|
||||
Setting this to `false` will avoid listening for any end events.
|
||||
|
||||
Setting this to `false` and providing an `await` Promise will cause the Observable to resolve immediately with the `await` Promise (the Observable will remove all it's `data` event listeners from the stream once the Promise is resolved).
|
||||
|
||||
##### errorEvent
|
||||
|
||||
Type: `String` or `false` <br>
|
||||
Default: `"error"`
|
||||
|
||||
If you are using an `EventEmitter` or non-standard Stream, you can change which event signals that the Observable should be closed with an error.
|
||||
|
||||
Setting this to `false` will avoid listening for any error events.
|
||||
|
||||
##### dataEvent
|
||||
|
||||
Type: `String`<br>
|
||||
Default: `"data"`
|
||||
|
||||
If you are using an `EventEmitter` or non-standard Stream, you can change which event causes data to be emitted to the Observable.
|
||||
|
||||
## Learn about Observables
|
||||
|
||||
- Overview: https://github.com/zenparsing/es-observable
|
||||
- Formal Spec: https://zenparsing.github.io/es-observable/
|
||||
- [egghead.io lesson](https://egghead.io/lessons/javascript-introducing-the-observable) - Video
|
||||
- [`rxjs` observables](http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html) - Observables Implementation
|
||||
- [`zen-observables`](https://github.com/zenparsing/zen-observable) - Observables Implementation
|
||||
|
||||
## Transform Streams
|
||||
|
||||
`data` events on the stream will be emitted as events in the Observable. Since most native streams emit `chunks` of binary data, you will likely want to use a `TransformStream` to convert those chunks of binary data into an object stream. [`split`](https://github.com/dominictarr/split) is just one popular TransformStream that splits streams into individual lines of text.
|
||||
|
||||
## Caveats
|
||||
|
||||
It is important Note that using this module disables back-pressure controls on the stream. As such it should not be used where back-pressure throttling is required (i.e. high volume web servers). It still has value for larger projects, as it can make unit testing streams much cleaner.
|
||||
|
||||
## License
|
||||
|
||||
MIT © [James Talmage](http://github.com/jamestalmage)
|
||||
5
node_modules/stream-to-observable/rxjs-all.js
generated
vendored
Normal file
5
node_modules/stream-to-observable/rxjs-all.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
var Observable = require('rxjs/Rx').Observable;
|
||||
var create = require('./');
|
||||
|
||||
module.exports = create(Observable);
|
||||
5
node_modules/stream-to-observable/rxjs.js
generated
vendored
Normal file
5
node_modules/stream-to-observable/rxjs.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
var Observable = require('rxjs/Observable').Observable;
|
||||
var create = require('./');
|
||||
|
||||
module.exports = create(Observable);
|
||||
5
node_modules/stream-to-observable/zen.js
generated
vendored
Normal file
5
node_modules/stream-to-observable/zen.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
var Observable = require('zen-observable');
|
||||
var create = require('./');
|
||||
|
||||
module.exports = create(Observable);
|
||||
Reference in New Issue
Block a user