Galerie und tage
This commit is contained in:
72
node_modules/p-event/index.js
generated
vendored
72
node_modules/p-event/index.js
generated
vendored
@@ -1,72 +0,0 @@
|
||||
'use strict';
|
||||
const pTimeout = require('p-timeout');
|
||||
|
||||
module.exports = (emitter, event, opts) => {
|
||||
let cancel;
|
||||
|
||||
const ret = new Promise((resolve, reject) => {
|
||||
if (typeof opts === 'function') {
|
||||
opts = {filter: opts};
|
||||
}
|
||||
|
||||
opts = Object.assign({
|
||||
rejectionEvents: ['error'],
|
||||
multiArgs: false
|
||||
}, opts);
|
||||
|
||||
let addListener = emitter.on || emitter.addListener || emitter.addEventListener;
|
||||
let removeListener = emitter.off || emitter.removeListener || emitter.removeEventListener;
|
||||
|
||||
if (!addListener || !removeListener) {
|
||||
throw new TypeError('Emitter is not compatible');
|
||||
}
|
||||
|
||||
addListener = addListener.bind(emitter);
|
||||
removeListener = removeListener.bind(emitter);
|
||||
|
||||
const resolveHandler = function (value) {
|
||||
if (opts.multiArgs) {
|
||||
value = [].slice.apply(arguments);
|
||||
}
|
||||
|
||||
if (opts.filter && !opts.filter(value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
cancel();
|
||||
resolve(value);
|
||||
};
|
||||
|
||||
const rejectHandler = function (reason) {
|
||||
cancel();
|
||||
|
||||
if (opts.multiArgs) {
|
||||
reject([].slice.apply(arguments));
|
||||
} else {
|
||||
reject(reason);
|
||||
}
|
||||
};
|
||||
|
||||
cancel = () => {
|
||||
removeListener(event, resolveHandler);
|
||||
|
||||
for (const rejectionEvent of opts.rejectionEvents) {
|
||||
removeListener(rejectionEvent, rejectHandler);
|
||||
}
|
||||
};
|
||||
|
||||
addListener(event, resolveHandler);
|
||||
|
||||
for (const rejectionEvent of opts.rejectionEvents) {
|
||||
addListener(rejectionEvent, rejectHandler);
|
||||
}
|
||||
});
|
||||
|
||||
ret.cancel = cancel;
|
||||
|
||||
if (typeof opts.timeout === 'number') {
|
||||
return pTimeout(ret, opts.timeout);
|
||||
}
|
||||
|
||||
return ret;
|
||||
};
|
||||
21
node_modules/p-event/license
generated
vendored
21
node_modules/p-event/license
generated
vendored
@@ -1,21 +0,0 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||
|
||||
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.
|
||||
84
node_modules/p-event/package.json
generated
vendored
84
node_modules/p-event/package.json
generated
vendored
@@ -1,84 +0,0 @@
|
||||
{
|
||||
"_from": "p-event@^1.0.0",
|
||||
"_id": "p-event@1.3.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-jmtPT2XHK8W2/ii3XtqHT5akoIU=",
|
||||
"_location": "/p-event",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "p-event@^1.0.0",
|
||||
"name": "p-event",
|
||||
"escapedName": "p-event",
|
||||
"rawSpec": "^1.0.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^1.0.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/download"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/p-event/-/p-event-1.3.0.tgz",
|
||||
"_shasum": "8e6b4f4f65c72bc5b6fe28b75eda874f96a4a085",
|
||||
"_spec": "p-event@^1.0.0",
|
||||
"_where": "/var/www/html/jason/WeihnachtenMelly/node_modules/download",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/sindresorhus/p-event/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"p-timeout": "^1.1.1"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "Promisify an event by waiting for it to be emitted",
|
||||
"devDependencies": {
|
||||
"ava": "*",
|
||||
"delay": "^1.3.1",
|
||||
"xo": "*"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"homepage": "https://github.com/sindresorhus/p-event#readme",
|
||||
"keywords": [
|
||||
"promise",
|
||||
"events",
|
||||
"event",
|
||||
"emitter",
|
||||
"eventemitter",
|
||||
"event-emitter",
|
||||
"emit",
|
||||
"emits",
|
||||
"listener",
|
||||
"promisify",
|
||||
"addlistener",
|
||||
"addeventlistener",
|
||||
"wait",
|
||||
"waits",
|
||||
"on",
|
||||
"browser",
|
||||
"dom",
|
||||
"async",
|
||||
"await",
|
||||
"promises",
|
||||
"bluebird"
|
||||
],
|
||||
"license": "MIT",
|
||||
"name": "p-event",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/sindresorhus/p-event.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava"
|
||||
},
|
||||
"version": "1.3.0"
|
||||
}
|
||||
177
node_modules/p-event/readme.md
generated
vendored
177
node_modules/p-event/readme.md
generated
vendored
@@ -1,177 +0,0 @@
|
||||
# p-event [](https://travis-ci.org/sindresorhus/p-event)
|
||||
|
||||
> Promisify an event by waiting for it to be emitted
|
||||
|
||||
Useful when you need only one event emission and want to use it with promises or await it in an async function.
|
||||
|
||||
If you want multiple individual events as they are emitted, this module is not for you, as a Promise is a single value. Instead, just continue using event callback or use [Observables](https://medium.com/@benlesh/learning-observable-by-building-observable-d5da57405d87).
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install --save p-event
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const pEvent = require('p-event');
|
||||
const emitter = require('./some-event-emitter');
|
||||
|
||||
pEvent(emitter, 'finish')
|
||||
// Called when `emitter` emits a `finish` event
|
||||
.then(result => {
|
||||
console.log(result);
|
||||
})
|
||||
// Called when `emitter` emits an `error` event
|
||||
.catch(error => {
|
||||
console.error(error);
|
||||
});
|
||||
```
|
||||
|
||||
```js
|
||||
const pEvent = require('p-event');
|
||||
|
||||
pEvent(document, 'DOMContentLoaded').then(() => {
|
||||
console.log('😎');
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### pEvent(emitter, event, [options])
|
||||
### pEvent(emitter, event, filter)
|
||||
|
||||
Returns a `Promise` that is fulfilled when `emitter` emits an event matching `event`, or rejects if `emitter` emits any of the events defined in the `rejectionEvents` option.
|
||||
|
||||
The returned promise has a `.cancel()` method, which when called, removes the event listeners and causes the promise to never be settled.
|
||||
|
||||
#### emitter
|
||||
|
||||
Type: `Object`
|
||||
|
||||
Event emitter object.
|
||||
|
||||
Should have either a `.on()`/`.addListener()`/`.addEventListener()` and `.off()`/`.removeListener()`/`.removeEventListener()` method, like the [Node.js `EventEmitter`](https://nodejs.org/api/events.html) and [DOM events](https://developer.mozilla.org/en-US/docs/Web/Events).
|
||||
|
||||
#### event
|
||||
|
||||
Type: `string`
|
||||
|
||||
Name of the event to listen to.
|
||||
|
||||
If the same event is defined both here and in `rejectionEvents`, this one takes priority.
|
||||
|
||||
#### options
|
||||
|
||||
Type: `Object`
|
||||
|
||||
##### rejectionEvents
|
||||
|
||||
Type: `Array`<br>
|
||||
Default: `['error']`
|
||||
|
||||
Events that will reject the promise.
|
||||
|
||||
##### multiArgs
|
||||
|
||||
Type: `boolean`<br>
|
||||
Default: `false`
|
||||
|
||||
By default, the promisified function will only return the first argument from the event callback, which works fine for most APIs. This option can be useful for APIs that return multiple arguments in the callback. Turning this on will make it return an array of all arguments from the callback, instead of just the first argument. This also applies to rejections.
|
||||
|
||||
Example:
|
||||
|
||||
```js
|
||||
const pEvent = require('p-event');
|
||||
const emitter = require('./some-event-emitter');
|
||||
|
||||
pEvent(emitter, 'finish', {multiArgs: true}).then(result => {
|
||||
const [id, type] = result;
|
||||
});
|
||||
```
|
||||
|
||||
##### timeout
|
||||
|
||||
Type: `Number`<br>
|
||||
Default: `Infinity`
|
||||
|
||||
Time in milliseconds before timing out.
|
||||
|
||||
|
||||
##### filter
|
||||
|
||||
Type: `Function`
|
||||
|
||||
Filter function for accepting an event.
|
||||
|
||||
```js
|
||||
const pEvent = require('p-event');
|
||||
const emitter = require('./some-event-emitter');
|
||||
|
||||
pEvent(emitter, '🦄', value => value > 3).then(result => {
|
||||
// Do something with first 🦄 event with a value greater than 3
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
## Before and after
|
||||
|
||||
```js
|
||||
const fs = require('fs');
|
||||
|
||||
function getOpenReadStream(file, callback) {
|
||||
const stream = fs.createReadStream(file);
|
||||
|
||||
stream.on('open', () => {
|
||||
callback(null, stream);
|
||||
});
|
||||
|
||||
stream.on('error', error => {
|
||||
callback(error);
|
||||
});
|
||||
}
|
||||
|
||||
getOpenReadStream('unicorn.txt', (error, stream) => {
|
||||
if (error) {
|
||||
console.error(error);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('File descriptor:', stream.fd);
|
||||
stream.pipe(process.stdout);
|
||||
});
|
||||
```
|
||||
|
||||
```js
|
||||
const fs = require('fs');
|
||||
const pEvent = require('p-event');
|
||||
|
||||
async function getOpenReadStream(file) {
|
||||
const stream = fs.createReadStream(file);
|
||||
await pEvent(stream, 'open');
|
||||
return stream;
|
||||
}
|
||||
|
||||
getOpenReadStream('unicorn.txt')
|
||||
.then(stream => {
|
||||
console.log('File descriptor:', stream.fd);
|
||||
stream.pipe(process.stdout);
|
||||
})
|
||||
.catch(console.error);
|
||||
```
|
||||
|
||||
|
||||
## Related
|
||||
|
||||
- [pify](https://github.com/sindresorhus/pify) - Promisify a callback-style function
|
||||
- [p-map](https://github.com/sindresorhus/p-map) - Map over promises concurrently
|
||||
- [More…](https://github.com/sindresorhus/promise-fun)
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Sindre Sorhus](https://sindresorhus.com)
|
||||
Reference in New Issue
Block a user