reformat code with prettier

This commit is contained in:
jkhsjdhjs 2020-06-17 15:32:11 +02:00
parent 31bec14cc2
commit 0ef1ff3194
Signed by: jkhsjdhjs
GPG Key ID: BAC6ADBAB7D576CC
5 changed files with 1197 additions and 1198 deletions

View File

@ -14,4 +14,4 @@ deploy:
on:
branch: master
tags: true
repo: jkhsjdhjs/node-fetch-cookies
repo: kein-Bot/flumm-fetch-cookies

View File

@ -1,4 +1,5 @@
# flumm-fetch-cookies [![Build Status](https://travis-ci.org/kein-Bot/flumm-fetch-cookies.svg?branch=master)](https://travis-ci.org/kein-Bot/flumm-fetch-cookies)
A [flumm-fetch](https://github.com/kein-Bot/flumm-fetch) wrapper with support for cookies.
It supports reading/writing from/to a JSON cookie jar and keeps cookies in memory until you call `CookieJar.save()` to reduce disk I/O.

2296
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,40 +1,40 @@
{
"name": "flumm-fetch-cookies",
"version": "1.4.0",
"description": "flumm-fetch wrapper that adds support for cookie-jars",
"main": "src/index.mjs",
"engines": {
"node": ">=11.14.0"
},
"files": [
"src/"
],
"scripts": {
"test": "npx eslint --ext mjs . && npx prettier --check package.json package-lock.json .travis.yml .prettierrc.json .eslintrc.json README.md && node --experimental-modules test/index.mjs"
},
"repository": {
"type": "git",
"url": "git+https://github.com/kein-Bot/flumm-fetch-cookies.git"
},
"keywords": [
"cookie",
"cookie-jar",
"flumm-fetch",
"fetch"
],
"author": "flummi & jkhsjdhjs",
"license": "MIT",
"bugs": {
"url": "https://github.com/kein-Bot/flumm-fetch-cookies/issues"
},
"homepage": "https://github.com/kein-Bot/flumm-fetch-cookies#readme",
"dependencies": {
"flumm-fetch": "^1.0.1"
},
"devDependencies": {
"eslint": "^7.2.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-prettier": "^3.1.4",
"prettier": "2.0.5"
}
"name": "flumm-fetch-cookies",
"version": "1.4.0",
"description": "flumm-fetch wrapper that adds support for cookie-jars",
"main": "src/index.mjs",
"engines": {
"node": ">=11.14.0"
},
"files": [
"src/"
],
"scripts": {
"test": "npx eslint --ext mjs . && npx prettier --check package.json package-lock.json .travis.yml .prettierrc.json .eslintrc.json README.md && node --experimental-modules test/index.mjs"
},
"repository": {
"type": "git",
"url": "git+https://github.com/kein-Bot/flumm-fetch-cookies.git"
},
"keywords": [
"cookie",
"cookie-jar",
"flumm-fetch",
"fetch"
],
"author": "flummi & jkhsjdhjs",
"license": "MIT",
"bugs": {
"url": "https://github.com/kein-Bot/flumm-fetch-cookies/issues"
},
"homepage": "https://github.com/kein-Bot/flumm-fetch-cookies#readme",
"dependencies": {
"flumm-fetch": "^1.0.1"
},
"devDependencies": {
"eslint": "^7.2.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-prettier": "^3.1.4",
"prettier": "2.0.5"
}
}

View File

@ -1,7 +1,7 @@
import _fetch from "flumm-fetch";
import CookieJar from "./cookie-jar.mjs";
import Cookie from "./cookie.mjs";
import {paramError, CookieParseError} from "./errors.mjs";
import {CookieParseError} from "./errors.mjs";
const redirectStatus = new Set([301, 302, 303, 307, 308]);
@ -9,14 +9,13 @@ const cookieJar = new CookieJar();
export default async function fetch(url, options) {
let cookies = "";
[...cookieJar.cookiesValidForRequest(url)]
.forEach(c => cookies += c.serialize() + "; ");
[...cookieJar.cookiesValidForRequest(url)].forEach(
c => (cookies += c.serialize() + "; ")
);
if(cookies) {
if(!options)
options = {};
if(!options.headers)
options.headers = {};
if (cookies) {
if (!options) options = {};
if (!options.headers) options.headers = {};
options.headers.cookie = cookies.slice(0, -2);
}
@ -38,11 +37,10 @@ export default async function fetch(url, options) {
if (wantFollow && redirectStatus.has(result.status)) {
const location = result.headers.get("Location");
options.redirect = "follow";
return fetch(cookieJars, location, options);
return fetch(location, options);
}
return result;
}
export {cookieJar, CookieJar, Cookie};
export {cookieJar, CookieJar, Cookie, CookieParseError};