New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

dgram-as-promised

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dgram-as-promised - npm Package Compare versions

Comparing version 1.0.6 to 2.0.0

src/dgram-as-promised.ts

6

CHANGELOG.md
# Changelog
## v2.0.0 2018-09-09
* Rewritten in Typescript.
* Requires Node >= 6.
* Additional `dgram` option for `createSocket`.
## v1.0.6 2018-07-15

@@ -4,0 +10,0 @@

71

lib/dgram-as-promised.d.ts
/// <reference types="node" />
import { BindOptions, RemoteInfo, Socket, SocketOptions, SocketType } from 'dgram'
import { AddressInfo } from 'net'
export class SocketAsPromised {
socket: Socket
constructor (socket: Socket)
bind (port?: number, address?: string): Promise<AddressInfo>
bind (options: BindOptions): Promise<AddressInfo>
addMembership (multicastAddress: string, multicastInterface?: string): void
close (): Promise<void>
send (msg: Buffer | String | any[], offset: number, length: number, port: number, address: string): Promise<number>
send (msg: Buffer | String | any[], port: number, address: string): Promise<number>
address (): AddressInfo
setBroadcast (flag: boolean): void
setTTL (ttl: number): void
setMulticastTTL (ttl: number): void
setMulticastInterface (multicastInterface: string): void
setMulticastLoopback (flag: boolean): void
addMembership (multicastAddress: string, multicastInterface?: string): void
dropMembership (multicastAddress: string, multicastInterface?: string): void
ref(): this
unref(): this
setRecvBufferSize(size: number): void
setSendBufferSize(size: number): void
getRecvBufferSize(): number
getSendBufferSize(): number
import dgram, { BindOptions, RemoteInfo, Socket, SocketOptions, SocketType } from 'dgram';
import { AddressInfo } from 'net';
export { BindOptions, RemoteInfo, Socket, SocketOptions, SocketType } from 'dgram';
export { AddressInfo } from 'net';
export interface SocketAsPromisedOptions extends SocketOptions {
dgram?: typeof dgram;
}
export function createSocket (type: SocketType, callback?: (msg: Buffer, rinfo: RemoteInfo) => void): SocketAsPromised;
export function createSocket (options: SocketOptions, callback?: (msg: Buffer, rinfo: RemoteInfo) => void): SocketAsPromised;
export declare class SocketAsPromised {
readonly socket: Socket;
constructor(socket: Socket);
bind(port?: number, address?: string): Promise<AddressInfo>;
bind(options: BindOptions): Promise<AddressInfo>;
addMembership(multicastAddress: string, multicastInterface?: string): void;
close(): Promise<void>;
send(msg: Buffer | String | any[], offset: number, length: number, port: number, address: string): Promise<number>;
send(msg: Buffer | String | any[], port: number, address: string): Promise<number>;
address(): AddressInfo;
setBroadcast(flag: boolean): void;
setTTL(ttl: number): void;
setMulticastTTL(ttl: number): void;
setMulticastInterface(multicastInterface: string): void;
setMulticastLoopback(flag: boolean): void;
dropMembership(multicastAddress: string, multicastInterface?: string): void;
ref(): this;
unref(): this;
setRecvBufferSize(size: number): void;
setSendBufferSize(size: number): void;
getRecvBufferSize(): number;
getSendBufferSize(): number;
}
export declare function createSocket(type: SocketType, callback?: (msg: Buffer, rinfo: RemoteInfo) => void): SocketAsPromised;
export declare function createSocket(options: SocketAsPromisedOptions, callback?: (msg: Buffer, rinfo: RemoteInfo) => void): SocketAsPromised;
declare const dgramAsPromised: {
createSocket: typeof createSocket;
};
export default dgramAsPromised;

@@ -1,113 +0,129 @@

'use strict'
const dgram = require('dgram')
/**
* @class
* @param {Socket} socket
*/
"use strict";
/// <reference types="node" />
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const dgram_1 = tslib_1.__importDefault(require("dgram"));
var dgram_2 = require("dgram");
exports.Socket = dgram_2.Socket;
class SocketAsPromised {
constructor (socket) {
this.socket = socket
}
/**
* @async
* @param {number} [port]
* @param {string} [address]
* @param {object} [options]
* @returns {Promise<AddressInfo>}
*/
bind (...args) {
return new Promise(resolve => {
this.socket.bind(...args, () => {
const address = this.socket.address()
resolve(address)
})
})
}
/**
* @async
* @returns {Promise<undefined>}
*/
close () {
return new Promise((resolve, reject) => {
try {
this.socket.once('close', () => {
resolve()
})
this.socket.close()
} catch (err) {
reject(err)
}
})
}
/**
* @async
* @param {Buffer | string | Array} msg
* @param {number} [offset]
* @param {number} [length]
* @param {number} port
* @param {string} address
* @returns {Promise<number>}
*/
send (msg, offset, length, port, address) {
return new Promise((resolve, reject) => {
try {
this.socket.send(msg, offset, length, port, address, (err, sent) => {
if (err) {
reject(err)
} else {
resolve(sent)
}
})
} catch (err) {
reject(err)
}
})
}
constructor(socket) {
this.socket = socket;
}
bind(arg1, arg2) {
return new Promise((resolve) => {
if (arg2 !== undefined) {
this.socket.bind(arg1, arg2, () => {
const address = this.socket.address();
resolve(address);
});
}
else {
this.socket.bind(arg1, () => {
const address = this.socket.address();
resolve(address);
});
}
});
}
addMembership(multicastAddress, multicastInterface) {
return this.socket.addMembership(multicastAddress, multicastInterface);
}
close() {
return new Promise((resolve, reject) => {
try {
this.socket.once('close', () => {
resolve();
});
this.socket.close();
}
catch (err) {
reject(err);
}
});
}
send(arg1, arg2, arg3, arg4, arg5) {
return new Promise((resolve, reject) => {
try {
if (arg4 !== undefined) {
this.socket.send(arg1, arg2, arg3, arg4, arg5, (err, sent) => {
if (err) {
reject(err);
}
else {
resolve(sent);
}
});
}
else {
this.socket.send(arg1, arg2, arg3, (err, sent) => {
if (err) {
reject(err);
}
else {
resolve(sent);
}
});
}
}
catch (err) {
reject(err);
}
});
}
address() {
return this.socket.address();
}
setBroadcast(flag) {
this.socket.setBroadcast(flag);
}
setTTL(ttl) {
return this.socket.setTTL(ttl);
}
setMulticastTTL(ttl) {
this.socket.setMulticastTTL(ttl);
}
setMulticastInterface(multicastInterface) {
this.socket.setMulticastInterface(multicastInterface);
}
setMulticastLoopback(flag) {
this.socket.setMulticastLoopback(flag);
}
dropMembership(multicastAddress, multicastInterface) {
this.socket.dropMembership(multicastAddress, multicastInterface);
}
ref() {
this.socket.ref();
return this;
}
unref() {
this.socket.unref();
return this;
}
setRecvBufferSize(size) {
this.socket.setRecvBufferSize(size);
}
setSendBufferSize(size) {
this.socket.setSendBufferSize(size);
}
getRecvBufferSize() {
return this.socket.getRecvBufferSize();
}
getSendBufferSize() {
return this.getSendBufferSize();
}
}
for (const method of [
'address', 'setBroadcast', 'setTTL', 'setMulticastTTL',
'setMulticastInterface', 'setMulticastLoopback', 'addMembership',
'dropMembership', 'setRecvBufferSize', 'setSendBufferSize',
'getRecvBufferSize', 'getSendBufferSize'
]) {
SocketAsPromised.prototype[method] = function (...args) {
return this.socket[method](...args)
}
}
for (const method of ['ref', 'unref']) {
SocketAsPromised.prototype[method] = function (...args) {
this.socket[method](...args)
return this
}
}
/**
* @callback createSocketCallback
* @param {Buffer} msg
* @param {RemoteInfo} rinfo
*/
/**
* @param {SocketType | SocketOptions | string} options
* @param {createSocketCallback} callback
* @returns {SocketAsPromised}
*/
function createSocket (options, callback) {
if (typeof options === 'string') {
options = {
type: options
exports.SocketAsPromised = SocketAsPromised;
function createSocket(options, callback) {
if (typeof options === 'string') {
options = {
type: options
};
}
}
return new SocketAsPromised(dgram.createSocket(options, callback))
const dgramModule = options.dgram || dgram_1.default;
return new SocketAsPromised(dgramModule.createSocket(options, callback));
}
module.exports = {
createSocket: createSocket
}
exports.createSocket = createSocket;
const dgramAsPromised = {
createSocket
};
exports.default = dgramAsPromised;
{
"name": "dgram-as-promised",
"version": "1.0.6",
"version": "2.0.0",
"description": "Promisify dgram module",

@@ -22,44 +22,47 @@ "main": "lib/dgram-as-promised.js",

"engines": {
"node": ">=4.0.0"
"node": ">=6.0.0"
},
"dependencies": {},
"dependencies": {
"tslib": "^1.9.3"
},
"devDependencies": {
"@types/node": "^10.5.2",
"@types/chai": "^4.1.4",
"@types/chai-as-promised": "^7.1.0",
"@types/mocha": "^5.2.5",
"@types/node": "^10.9.4",
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"eslint": "^5.1.0",
"eslint-config-standard": "^12.0.0-alpha.0",
"eslint-plugin-import": "^2.13.0",
"eslint-plugin-node": "^6.0.1",
"eslint-plugin-promise": "^3.8.0",
"eslint-plugin-standard": "^3.1.0",
"markdownlint-cli": "^0.11.0",
"mock-require": "^3.0.2",
"standard": "^11.0.1",
"tap": "^12.0.1",
"tap-given": "^0.6.0",
"tslint": "^5.10.0",
"tslint-config-standard": "^7.1.0",
"typescript": "^2.9.2"
"eslint": "^5.5.0",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-node": "^7.0.1",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^4.0.0",
"markdownlint-cli": "^0.13.0",
"mocha": "^5.2.0",
"nyc": "^13.0.1",
"ts-node": "^7.0.1",
"tslint": "^5.11.0",
"tslint-config-standard": "^8.0.1",
"typescript": "^3.0.3"
},
"scripts": {
"pretest": "eslint . && tsc --noEmit --pretty && tslint -t stylish -p . && echo markdownlint *.md",
"test": "npm run test:api",
"test:api": "tap test/*.js",
"test:coverage": "npm test -- --coverage"
"build": "tsc --pretty",
"clean": "rimraf lib",
"postpublish": "git tag v$npm_package_version -a -m \"Release $npm_package_version\" && git push --tags",
"prepublishOnly": "npm run build",
"pretest": "npm run build && tsc --pretty -p examples && tsc --pretty -p test && eslint . && tslint -t stylish -p . && tslint -t stylish -p examples && tslint -t stylish -p test && markdownlint \"*.md\"",
"test": "npm run test:spec",
"test:spec": "npm run ts-mocha -- \"test/*.ts\"",
"test:coverage": "nyc --reporter json npm run test:spec && nyc report",
"ts-mocha": "mocha --use_strict --throw-deprecation --require source-map-support/register --require ts-node/register --timeout 90000"
},
"standard": {
"globals": [
"After",
"And",
"Feature",
"Given",
"Scenario",
"Then",
"When"
"nyc": {
"extension": [
".ts"
],
"exclude": [
"**/*.d.ts"
]
},
"nyc": {
"exclude": []
}
}

@@ -16,3 +16,3 @@ # dgram-as-promised

This module requires ES6 with Node >= 4. For Node < 6 `--harmony` flag is required.
This module requires ES6 with Node >= 6.

@@ -31,2 +31,14 @@ ## Installation

Transpiling this module with own settings in `tsconfig.json`:
```json
{
"compilerOptions": {
"paths": {
"dgram-as-promised": ["node_modules/dgram-as-promised/src/dgram-as-promised"]
}
}
}
```
## Usage

@@ -33,0 +45,0 @@

{
"compilerOptions": {
"declaration": true,
"esModuleInterop": true,
"importHelpers": true,
"lib": [
"es6"
],
"module": "commonjs",
"noImplicitAny": true,
"noImplicitThis": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"outDir": "./lib",
"target": "es6",
"strict": true,
"strictNullChecks": true,
"target": "ES2017"
}
"typeRoots": [
"node_modules/@types"
]
},
"exclude": [
"./examples/**/*",
"./lib/**/*",
"./test/**/*"
]
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc