Current Folder

This commit is contained in:
Luis Fernando Molina committed 2020-11-20 14:05:59 +01:00
1 parent 8b3382289b
commit cfcada880d
4379 files changed

No files matched your search

+42
View File
@@ -0,0 +1,42 @@
{
"name": "responselike",
"version": "1.0.2",
"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.22.0",
"coveralls": "^2.13.1",
"eslint-config-xo-lukechilds": "^1.0.0",
"get-stream": "^3.0.0",
"nyc": "^11.1.0",
"xo": "^0.19.0"
},
"dependencies": {
"lowercase-keys": "^1.0.0"
}
,"_resolved": "https://registry.npmjs.org/responselike/-/responselike-1.0.2.tgz"
,"_integrity": "sha1-kYcg7ztjHFZCvgaPFa3lpG9Loec="
,"_from": "responselike@^1.0.2"
}
+34
View File
@@ -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;