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

rqt

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

rqt - npm Package Compare versions

Comparing version 0.2.2 to 1.0.1

6

CHANGELOG.md

@@ -1,4 +0,8 @@

## 0.1.0 (29 May)
## 1.0.0 (5 March 2018)
- [breaking] when parsing, use `path` instead of `pathname`
## 0.1.0 (29 May 2017)
- Create `rqt`: a package created with `mnp`
- [repo]: `test`, `src`

138

es5/src/index.js

@@ -8,8 +8,9 @@ var _require = require('http'),

var Catchment = require('catchment');
var url = require('url');
var erotic = require('erotic/es5/src');
var _require3 = require('../../package.json'),
var erotic = require("erotic/es5/src");
var _require3 = require("../../package.json"),
version = _require3.version;
/**

@@ -22,73 +23,78 @@ * Request an HTTP page.

function rqt(address) {
var $args = arguments;return new Promise(function ($return, $error) {
var _ref, _ref$data, data, _ref$contentType, contentType, _ref$headers, headers, er, opts, isHttps, request, options, result;
var $args = arguments;
return new Promise(function ($return, $error) {
var _ref, _ref$data, data, _ref$contentType, contentType, _ref$headers, headers, er, opts, isHttps, request, options, result;
_ref = $args.length > 1 && $args[1] !== undefined ? $args[1] : {}, _ref$data = _ref.data, data = _ref$data === undefined ? null : _ref$data, _ref$contentType = _ref.contentType, contentType = _ref$contentType === undefined ? 'application/json' : _ref$contentType, _ref$headers = _ref.headers, headers = _ref$headers === undefined ? {
'User-Agent': `Mozilla/5.0 (Node.js) rqt/${version}`
} : _ref$headers;
_ref = $args.length > 1 && $args[1] !== undefined ? $args[1] : {}, _ref$data = _ref.data, data = _ref$data === void 0 ? null : _ref$data, _ref$contentType = _ref.contentType, contentType = _ref$contentType === void 0 ? 'application/json' : _ref$contentType, _ref$headers = _ref.headers, headers = _ref$headers === void 0 ? {
'User-Agent': `Mozilla/5.0 (Node.js) rqt/${version}`
} : _ref$headers;
er = erotic();
opts = url.parse(address);
isHttps = opts.protocol === 'https:';
request = isHttps ? https : http;
options = {
hostname: opts.hostname,
port: opts.port,
path: opts.path,
headers
};
er = erotic();
opts = url.parse(address);
isHttps = opts.protocol === 'https:';
request = isHttps ? https : http;
options = {
hostname: opts.hostname,
port: opts.port,
path: opts.pathname,
headers
};
if (data) {
options.method = 'POST';
options.headers = Object.assign({}, options.headers, {
'Content-Type': contentType,
'Content-Length': Buffer.byteLength(data)
});
}
return Promise.resolve(new Promise(function (resolve, reject) {
var req = request(options, function (res) {
return new Promise(function ($return, $error) {
var catchment, r, parsed, err;
if (data) {
options.method = 'POST';
options.headers = Object.assign({}, options.headers, {
'Content-Type': contentType,
'Content-Length': Buffer.byteLength(data)
});
}
catchment = new Catchment();
res.pipe(catchment);
return Promise.resolve(catchment.promise).then(function ($await_2) {
try {
r = $await_2;
if (res.headers['content-type'] === 'application/json') {
try {
parsed = JSON.parse(r);
resolve(parsed);
} catch (e) {
err = er(e);
err.postData = r;
reject(err);
}
} else {
resolve(r);
}
return $return();
} catch ($boundEx) {
return $error($boundEx);
}
}.bind(this), $error);
}.bind(this));
}).on('error', function (error) {
var err = er(error);
reject(err);
});
if (data) {
req.write(data);
}
req.end();
})).then(function ($await_3) {
return Promise.resolve(new Promise(function (resolve, reject) {
var req = request(options, function (res) {
return new Promise(function ($return, $error) {
var catchment, r, parsed, err;
catchment = new Catchment();
res.pipe(catchment);
return Promise.resolve(catchment.promise).then(function ($await_2) {
try {
result = $await_3;
return $return(result);
r = $await_2;
if (res.headers['content-type'] === 'application/json') {
try {
parsed = JSON.parse(r);
resolve(parsed);
} catch (e) {
err = er(e);
err.postData = r;
reject(err);
}
} else {
resolve(r);
}
return $return();
} catch ($boundEx) {
return $error($boundEx);
return $error($boundEx);
}
}.bind(this), $error);
}.bind(this));
}.bind(this), $error);
}.bind(this));
}).on('error', function (error) {
var err = er(error);
reject(err);
});
if (data) {
req.write(data);
}
req.end();
})).then(function ($await_3) {
try {
result = $await_3;
return $return(result);
} catch ($boundEx) {
return $error($boundEx);
}
}.bind(this), $error);
}.bind(this));
}
module.exports = rqt;
{
"name": "rqt",
"version": "0.2.2",
"version": "1.0.1",
"description": "request library",

@@ -10,5 +10,5 @@ "main": "src/index.js",

"test-watch": "zoroaster test/spec --watch",
"build-src": "babel src --out-dir es5/src",
"build-test": "babel test --out-dir es5/test",
"build": "run-s build-src build-test"
"build-src": "bestie src",
"build-test": "bestie test",
"build": "bestie"
},

@@ -38,6 +38,3 @@ "engines": {

"devDependencies": {
"babel-cli": "6.26.0",
"babel-plugin-transform-rename-import": "2.1.1",
"babel-preset-env": "1.6.1",
"fast-async": "6.3.0",
"bestie": "^1.0.0",
"npm-run-all": "4.1.2",

@@ -44,0 +41,0 @@ "server-destroy": "1.0.1",

# rqt
`rqt` is a Node.js request library.
[![npm version](https://badge.fury.io/js/rqt.svg)](https://badge.fury.io/js/rqt)
## ES5
`rqt` is a Node.js request library. Send `GET` and `POST` requests at ease.
The package uses some newer language features. For your convenience, it's been
transpiled to be compatible with Node 4. You can use the following snippet.
## `async rqt(url: string): string`
```js
const rqt = require('rqt/es5/src/')
```
## `rqt(url: string) => Promise.<string>`
Call this function to request a web page.

@@ -26,3 +19,3 @@

## `rqt(url: string, { data: string, contentType: string }) => Promise.<string>`
## `async rqt(url: string, { data: string, contentType: string }): string`

@@ -57,4 +50,13 @@ Send a post request (with default `JSON` content type and calculated

## ES5
The package uses some newer language features. For your convenience, it's been
transpiled to be compatible with Node 4. You can use the following snippet.
```js
const rqt = require('rqt/es5')
```
---
(c) [sobes.io](https://sobes.io) 2017
(c) [sobes.io](https://sobes.io) 2018

@@ -26,3 +26,3 @@ const { request: http } = require('http')

port: opts.port,
path: opts.pathname,
path: opts.path,
headers,

@@ -29,0 +29,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