aboutsummaryrefslogtreecommitdiff
path: root/node_modules/responselike
diff options
context:
space:
mode:
authorMinteck <nekostarfan@gmail.com>2021-08-24 14:41:48 +0200
committerMinteck <nekostarfan@gmail.com>2021-08-24 14:41:48 +0200
commitd25e11bee6ca5ca523884da132d18e1400e077b9 (patch)
tree8af39fde19f7ed640a60fb397c7edd647dff1c4c /node_modules/responselike
downloadkartik-iridium-d25e11bee6ca5ca523884da132d18e1400e077b9.tar.gz
kartik-iridium-d25e11bee6ca5ca523884da132d18e1400e077b9.tar.bz2
kartik-iridium-d25e11bee6ca5ca523884da132d18e1400e077b9.zip
Initial commit
Diffstat (limited to 'node_modules/responselike')
-rw-r--r--node_modules/responselike/LICENSE19
-rw-r--r--node_modules/responselike/README.md77
-rw-r--r--node_modules/responselike/package.json38
-rw-r--r--node_modules/responselike/src/index.js34
4 files changed, 168 insertions, 0 deletions
diff --git a/node_modules/responselike/LICENSE b/node_modules/responselike/LICENSE
new file mode 100644
index 0000000..8829a00
--- /dev/null
+++ b/node_modules/responselike/LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2017 Luke Childs
+
+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/responselike/README.md b/node_modules/responselike/README.md
new file mode 100644
index 0000000..6361931
--- /dev/null
+++ b/node_modules/responselike/README.md
@@ -0,0 +1,77 @@
+# responselike
+
+> A response-like object for mocking a Node.js HTTP response stream
+
+[![Build Status](https://travis-ci.org/lukechilds/responselike.svg?branch=master)](https://travis-ci.org/lukechilds/responselike)
+[![Coverage Status](https://coveralls.io/repos/github/lukechilds/responselike/badge.svg?branch=master)](https://coveralls.io/github/lukechilds/responselike?branch=master)
+[![npm](https://img.shields.io/npm/dm/responselike.svg)](https://www.npmjs.com/package/responselike)
+[![npm](https://img.shields.io/npm/v/responselike.svg)](https://www.npmjs.com/package/responselike)
+
+Returns a streamable response object similar to a [Node.js HTTP response stream](https://nodejs.org/api/http.html#http_class_http_incomingmessage). Useful for formatting cached responses so they can be consumed by code expecting a real response.
+
+## Install
+
+```shell
+npm install --save responselike
+```
+
+Or if you're just using for testing you'll want:
+
+```shell
+npm install --save-dev responselike
+```
+
+## Usage
+
+```js
+const Response = require('responselike');
+
+const response = new Response(200, { foo: 'bar' }, Buffer.from('Hi!'), 'https://example.com');
+
+response.statusCode;
+// 200
+response.headers;
+// { foo: 'bar' }
+response.body;
+// <Buffer 48 69 21>
+response.url;
+// 'https://example.com'
+
+response.pipe(process.stdout);
+// Hi!
+```
+
+
+## API
+
+### new Response(statusCode, headers, body, url)
+
+Returns a streamable response object similar to a [Node.js HTTP response stream](https://nodejs.org/api/http.html#http_class_http_incomingmessage).
+
+#### statusCode
+
+Type: `number`
+
+HTTP response status code.
+
+#### headers
+
+Type: `object`
+
+HTTP headers object. Keys will be automatically lowercased.
+
+#### body
+
+Type: `buffer`
+
+A Buffer containing the response body. The Buffer contents will be streamable but is also exposed directly as `response.body`.
+
+#### url
+
+Type: `string`
+
+Request URL string.
+
+## License
+
+MIT © Luke Childs
diff --git a/node_modules/responselike/package.json b/node_modules/responselike/package.json
new file mode 100644
index 0000000..e3d44ae
--- /dev/null
+++ b/node_modules/responselike/package.json
@@ -0,0 +1,38 @@
+{
+ "name": "responselike",
+ "version": "2.0.0",
+ "description": "A response-like object for mocking a Node.js HTTP response stream",
+ "main": "src/index.js",
+ "scripts": {
+ "test": "xo && nyc ava",
+ "coverage": "nyc report --reporter=text-lcov | coveralls"
+ },
+ "xo": {
+ "extends": "xo-lukechilds"
+ },
+ "keywords": [
+ "http",
+ "https",
+ "response",
+ "mock",
+ "request",
+ "responselike"
+ ],
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/lukechilds/responselike.git"
+ },
+ "author": "lukechilds",
+ "license": "MIT",
+ "devDependencies": {
+ "ava": "^0.25.0",
+ "coveralls": "^3.0.0",
+ "eslint-config-xo-lukechilds": "^1.0.0",
+ "get-stream": "^3.0.0",
+ "nyc": "^11.8.0",
+ "xo": "^0.19.0"
+ },
+ "dependencies": {
+ "lowercase-keys": "^2.0.0"
+ }
+}
diff --git a/node_modules/responselike/src/index.js b/node_modules/responselike/src/index.js
new file mode 100644
index 0000000..b17b481
--- /dev/null
+++ b/node_modules/responselike/src/index.js
@@ -0,0 +1,34 @@
+'use strict';
+
+const Readable = require('stream').Readable;
+const lowercaseKeys = require('lowercase-keys');
+
+class Response extends Readable {
+ constructor(statusCode, headers, body, url) {
+ if (typeof statusCode !== 'number') {
+ throw new TypeError('Argument `statusCode` should be a number');
+ }
+ if (typeof headers !== 'object') {
+ throw new TypeError('Argument `headers` should be an object');
+ }
+ if (!(body instanceof Buffer)) {
+ throw new TypeError('Argument `body` should be a buffer');
+ }
+ if (typeof url !== 'string') {
+ throw new TypeError('Argument `url` should be a string');
+ }
+
+ super();
+ this.statusCode = statusCode;
+ this.headers = lowercaseKeys(headers);
+ this.body = body;
+ this.url = url;
+ }
+
+ _read() {
+ this.push(this.body);
+ this.push(null);
+ }
+}
+
+module.exports = Response;