Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

api-promise

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

api-promise - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

46

lib/index.js

@@ -7,20 +7,2 @@ 'use strict'

const dnsCache = {}
const lookup = (host, cb) => {
if (dnsCache[host]) {
cb(null, dnsCache[host])
} else {
dns.lookup(host, { hints: dns.ADDRCONFIG }, (err, address) => {
if (err) {
cb(err)
} else {
dnsCache[host] = address
setTimeout(() => { delete dnsCache[host] }, 3e4)
cb(null, dnsCache[host])
}
})
}
}
module.exports = (hostname, token, headers, options) => {

@@ -58,1 +40,29 @@ headers = Object.assign(

}
const dnsCache = {}
function lookup (host, options, cb) {
if (!cb) {
cb = options
options = null
}
if (dnsCache[host] && dnsCache[host][2] > +new Date() - 6e4) {
clearTimeout(dnsCache[host][3])
dnsCache[host][3] = setTimeout(() => { delete dnsCache[host] }, 500)
cb(null, dnsCache[host][0], dnsCache[host][1])
} else {
if (dnsCache[host]) {
clearTimeout(dnsCache[host][3])
delete dnsCache[host]
}
dns.lookup(host, options, (err, ip, type) => {
if (err) {
cb(err)
} else {
dnsCache[host] = [ip, type, +new Date()]
dnsCache[host][3] = setTimeout(() => { delete dnsCache[host] }, 500)
cb(null, dnsCache[host][0], dnsCache[host][1])
}
})
}
}
{
"name": "api-promise",
"version": "1.0.0",
"version": "1.0.1",
"description": "An observable to run async tasks in parallel with a concurrency limit",

@@ -5,0 +5,0 @@ "main": "./lib",

@@ -17,1 +17,14 @@ # api-promise

## Usage
```js
const ap = require('api-promise')
const github = ap('api.github.com', 'GITHUB-TOKEN')
github('POST', '/some/api/path', { param: 'value' })
.then(res => {
// do something with the response
})
.catch(err => {
// do something with the error
})
```
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