index: export CookieParseError

readme: add short description of CookieParseError
error: add semicolons
This commit is contained in:
jkhsjdhjs 2019-11-25 18:48:49 +01:00
parent 200d3b0a7c
commit 2271c2e055
Signed by: jkhsjdhjs
GPG Key ID: BAC6ADBAB7D576CC
3 changed files with 10 additions and 6 deletions

View File

@ -47,6 +47,7 @@ import {fetch, CookieJar} from "node-fetch-cookies";
})();
```
## Documentation
### async fetch(cookieJar, url[, options])
@ -79,7 +80,7 @@ In this case `fromURL` must be specified.
- `fromURL` The url a cookie has been received from.
Returns `true` if the cookie has been added successfully. Returns `false` otherwise.
Will log a warning to console if a cookie fails to be parsed.
If the parser throws a [CookieParseError](#class-cookieparseerror) it will be caught and a warning will be printed to console.
#### domains()
Returns an iterator over all domains currently stored cookies for.
@ -141,6 +142,9 @@ Returns whether the cookie has expired or not.
#### isValidForRequest(url)
Returns whether the cookie is valid for a request to `url`.
### Class: CookieParseError
The Error that is thrown when the cookie parser located in the constructor of the [Cookie](#class-cookie) class is unable to parse the input.
## 1.3.0 Breaking API Changes
- `new CookieJar(flags, file, cookies)` has been changed to `new CookieJar(file, flags = "rw", cookies)`.

View File

@ -3,10 +3,10 @@ export class CookieParseError extends Error {
super(...args);
this.name = "CookieParseError";
}
}
};
export function paramError(position, paramName, functionName, validTypes) {
validTypes = [validTypes].flatMap(t => "\"" + t + "\"");
validTypes = validTypes.slice(0, -1).join(", ") + (validTypes.length > 1 ? " or " : "") + validTypes.slice(-1);
return new TypeError(`${position} parameter "${paramName}" passed to "${functionName}" is not of type ${validTypes}!`);
}
};

View File

@ -1,7 +1,7 @@
import _fetch from "node-fetch";
import CookieJar from "./cookie-jar.mjs";
import Cookie from "./cookie.mjs";
import { paramError } from "./errors.mjs"
import { paramError, CookieParseError } from "./errors.mjs"
async function fetch(cookieJars, url, options) {
let cookies = "";
@ -46,4 +46,4 @@ async function fetch(cookieJars, url, options) {
return result;
}
export {fetch, CookieJar, Cookie};
export {fetch, CookieJar, Cookie, CookieParseError};