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 0.1.2 to 1.0.0

lib/dgram-as-promised.d.ts

9

CHANGELOG.md
# Changelog
## v1.0.0 2017-10-23
* Do not use `any-promise`.
* `bind` method accepts address and port options and resolves to address info.
* `send` method resolves to number of sent bytes.
* The rest of `dgram` methods have been implemented.
* For Node < 6 `--harmony` flag is required.
* Typescript typings.
## v0.1.2 2017-06-22

@@ -4,0 +13,0 @@

38

lib/dgram-as-promised.js
'use strict'
const dgram = require('dgram')
const Promise = require('any-promise')

@@ -11,6 +10,7 @@ class SocketAsPromised {

bind () {
bind (...args) {
return new Promise(resolve => {
this.socket.bind(() => {
resolve()
this.socket.bind((...args) => {
const address = this.socket.address()
resolve(address)
})

@@ -20,6 +20,2 @@ })

addMembership (multicastAddress, multicastInterface) {
return this.socket.addMembership(multicastAddress, multicastInterface)
}
close () {

@@ -41,4 +37,8 @@ return new Promise((resolve, reject) => {

try {
this.socket.send(msg, offset, length, port, address, () => {
resolve()
this.socket.send(msg, offset, length, port, address, (err, sent) => {
if (err) {
reject(err)
} else {
resolve(sent)
}
})

@@ -50,9 +50,19 @@ } catch (err) {

}
}
setBroadcast (flag) {
return this.socket.setBroadcast(flag)
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)
}
}
setMulticastTTL (ttl) {
return this.socket.setMulticastTTL(ttl)
for (const method of ['ref', 'unref']) {
SocketAsPromised.prototype[method] = function (...args) {
this.socket[method](...args)
return this
}

@@ -59,0 +69,0 @@ }

{
"name": "dgram-as-promised",
"version": "0.1.2",
"version": "1.0.0",
"description": "Promisify dgram module",
"main": "lib/dgram-as-promised.js",
"typings": "lib/dgram-as-promised.d.ts",
"repository": {

@@ -23,12 +24,11 @@ "type": "git",

},
"dependencies": {
"any-promise": "^1.3.0"
},
"dependencies": {},
"devDependencies": {
"chai": "^4.0.2",
"chai-as-promised": "^7.0.0",
"@types/node": "^8.0.46",
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"snazzy": "^7.0.0",
"standard": "^10.0.2",
"tap": "^10.5.1",
"tap-given": "^0.4.1"
"standard": "^10.0.3",
"tap": "^10.7.2",
"tap-given": "^0.6.0"
},

@@ -35,0 +35,0 @@ "scripts": {

@@ -12,2 +12,6 @@ ## dgram-as-promised

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

@@ -21,4 +25,6 @@

`dgram-as-promised` can be used like standard `dgram` module:
`dgram-as-promised` can be used like standard `dgram` module.
_Example:_
```js

@@ -35,9 +41,17 @@ const dgramAsPromised = require('dgram-as-promised')

Method `bind` returns `Promise` object which is fulfilled when `listening` event
is emitted.
_Typescript:_
```js
await socket.bind()
console.log('Socket is listening')
import * as dgramAsPromised from 'dgram-as-promised'
const socket = dgramAsPromised.createSocket('udp4')
```
Method `bind` returns `Promise` object which resolves to address info when
`listening` event is emitted.
```js
const address = await socket.bind()
console.log(`Socket is listening on ${address.address}:${address.port}`)
socket.setBroadcast(true)

@@ -54,8 +68,8 @@ socket.setMulticastTTL(128)

```js
await socket.send(message, 0, message.length, PORT, MEMBERSHIP)
console.log('Message is sent')
const bytes = await socket.send(message, 0, message.length, PORT, MEMBERSHIP)
console.log(`Message is sent (${bytes} bytes)`)
```
Method `close` returns `Promise` object which is fulfilled when `close` event
is emitted.
Method `close` returns `Promise` object which resolves to number of bytes sent
when `close` event is emitted.

@@ -67,15 +81,2 @@ ```js

### Promise
This module uses [any-promise](https://www.npmjs.com/package/any-promise) and
any ES6 Promise library or polyfill is supported.
Ie. [bluebird](https://www.npmjs.com/package/bluebird) can be used as Promise
library for this module, if it is registered before.
```js
require('any-promise/register/bluebird')
const dgramAsPromised = require('dgram-as-promised')
```
### License

@@ -82,0 +83,0 @@

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