diff options
author | Minteck <contact@minteck.org> | 2022-04-09 16:39:03 +0200 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-04-09 16:40:02 +0200 |
commit | 0f8967b9113d698cdeb2d05ca85d2d9a80461c24 (patch) | |
tree | 00664ddd9c55a2c33631fd1bd33e556cea9c67e5 /node_modules/defer-to-connect | |
parent | dac03ac82bc0f8044a4b339c27b5390e4dcecf2f (diff) | |
download | voicer-0f8967b9113d698cdeb2d05ca85d2d9a80461c24.tar.gz voicer-0f8967b9113d698cdeb2d05ca85d2d9a80461c24.tar.bz2 voicer-0f8967b9113d698cdeb2d05ca85d2d9a80461c24.zip |
Diffstat (limited to 'node_modules/defer-to-connect')
-rw-r--r-- | node_modules/defer-to-connect/LICENSE | 21 | ||||
-rw-r--r-- | node_modules/defer-to-connect/README.md | 38 | ||||
-rw-r--r-- | node_modules/defer-to-connect/dist/index.d.ts | 10 | ||||
-rw-r--r-- | node_modules/defer-to-connect/dist/index.js | 45 | ||||
-rw-r--r-- | node_modules/defer-to-connect/package.json | 74 |
5 files changed, 188 insertions, 0 deletions
diff --git a/node_modules/defer-to-connect/LICENSE b/node_modules/defer-to-connect/LICENSE new file mode 100644 index 0000000..15ad2e8 --- /dev/null +++ b/node_modules/defer-to-connect/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 Szymon Marczak + +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. diff --git a/node_modules/defer-to-connect/README.md b/node_modules/defer-to-connect/README.md new file mode 100644 index 0000000..4dd36c2 --- /dev/null +++ b/node_modules/defer-to-connect/README.md @@ -0,0 +1,38 @@ +# defer-to-connect + +> The safe way to handle the `connect` socket event + +[![Coverage Status](https://coveralls.io/repos/github/szmarczak/defer-to-connect/badge.svg?branch=master)](https://coveralls.io/github/szmarczak/defer-to-connect?branch=master) + +Once you receive the socket, it may be already connected (or disconnected).<br> +To avoid checking that, use `defer-to-connect`. It'll do that for you. + +## Usage + +```js +const deferToConnect = require('defer-to-connect'); + +deferToConnect(socket, () => { + console.log('Connected!'); +}); +``` + +## API + +### deferToConnect(socket, connectListener) + +Calls `connectListener()` when connected. + +### deferToConnect(socket, listeners) + +#### listeners + +An object representing `connect`, `secureConnect` and `close` properties. + +Calls `connect()` when the socket is connected.<br> +Calls `secureConnect()` when the socket is securely connected.<br> +Calls `close()` when the socket is destroyed. + +## License + +MIT diff --git a/node_modules/defer-to-connect/dist/index.d.ts b/node_modules/defer-to-connect/dist/index.d.ts new file mode 100644 index 0000000..323bd12 --- /dev/null +++ b/node_modules/defer-to-connect/dist/index.d.ts @@ -0,0 +1,10 @@ +/// <reference types="node" /> +import { Socket } from 'net'; +import { TLSSocket } from 'tls'; +interface Listeners { + connect?: () => void; + secureConnect?: () => void; + close?: (hadError: boolean) => void; +} +declare const deferToConnect: (socket: Socket | TLSSocket, fn: Listeners | (() => void)) => void; +export default deferToConnect; diff --git a/node_modules/defer-to-connect/dist/index.js b/node_modules/defer-to-connect/dist/index.js new file mode 100644 index 0000000..aaf1cf5 --- /dev/null +++ b/node_modules/defer-to-connect/dist/index.js @@ -0,0 +1,45 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const tls_1 = require("tls"); +const deferToConnect = (socket, fn) => { + let listeners; + if (typeof fn === 'function') { + const connect = fn; + listeners = { connect }; + } + else { + listeners = fn; + } + const hasConnectListener = typeof listeners.connect === 'function'; + const hasSecureConnectListener = typeof listeners.secureConnect === 'function'; + const hasCloseListener = typeof listeners.close === 'function'; + const onConnect = () => { + if (hasConnectListener) { + listeners.connect(); + } + if (socket instanceof tls_1.TLSSocket && hasSecureConnectListener) { + if (socket.authorized) { + listeners.secureConnect(); + } + else if (!socket.authorizationError) { + socket.once('secureConnect', listeners.secureConnect); + } + } + if (hasCloseListener) { + socket.once('close', listeners.close); + } + }; + if (socket.writable && !socket.connecting) { + onConnect(); + } + else if (socket.connecting) { + socket.once('connect', onConnect); + } + else if (socket.destroyed && hasCloseListener) { + listeners.close(socket._hadError); + } +}; +exports.default = deferToConnect; +// For CommonJS default export support +module.exports = deferToConnect; +module.exports.default = deferToConnect; diff --git a/node_modules/defer-to-connect/package.json b/node_modules/defer-to-connect/package.json new file mode 100644 index 0000000..34a1170 --- /dev/null +++ b/node_modules/defer-to-connect/package.json @@ -0,0 +1,74 @@ +{ + "name": "defer-to-connect", + "version": "1.1.3", + "description": "The safe way to handle the `connect` socket event", + "main": "dist", + "files": [ + "dist" + ], + "scripts": { + "build": "del-cli dist && tsc", + "prepublishOnly": "npm run build", + "test": "xo && nyc ava", + "coveralls": "nyc report --reporter=text-lcov | coveralls" + }, + "keywords": [ + "socket", + "connect", + "event" + ], + "author": "Szymon Marczak", + "license": "MIT", + "repository": { + "type": "git", + "url": "git+https://github.com/szmarczak/defer-to-connect.git" + }, + "bugs": { + "url": "https://github.com/szmarczak/defer-to-connect/issues" + }, + "homepage": "https://github.com/szmarczak/defer-to-connect#readme", + "xo": { + "extends": "xo-typescript", + "extensions": [ + "ts" + ], + "rules": { + "ava/no-ignored-test-files": "off" + } + }, + "devDependencies": { + "@sindresorhus/tsconfig": "^0.5.0", + "@types/node": "^12.12.4", + "@typescript-eslint/eslint-plugin": "^1.11.0", + "@typescript-eslint/parser": "^1.11.0", + "ava": "^2.1.0", + "coveralls": "^3.0.7", + "create-cert": "^1.0.6", + "del-cli": "^3.0.0", + "eslint-config-xo-typescript": "^0.15.0", + "nyc": "^14.0.0", + "p-event": "^4.1.0", + "ts-node": "^8.1.0", + "typescript": "^3.6.4", + "xo": "^0.25.3" + }, + "nyc": { + "extension": [ + ".ts" + ] + }, + "ava": { + "babel": false, + "compileEnhancements": false, + "extensions": [ + "ts" + ], + "require": [ + "ts-node/register" + ], + "files": [ + "!dist/tests/test.d.ts" + ] + }, + "types": "dist" +} |