Add types for tough-cookie-file-store

This commit is contained in:
Emily Marigold Klassen
2019-04-02 12:10:40 -07:00
parent 547098699c
commit e113d72db7
4 changed files with 111 additions and 0 deletions
+67
View File
@@ -0,0 +1,67 @@
// Type definitions for tough-cookie-file-store 1.2
// Project: https://github.com/ivanmarban/tough-cookie-file-store
// Definitions by: Emily Marigold Klassen <https://github.com/forivall>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
import tough = require('tough-cookie');
export = FileCookieStore;
declare class FileCookieStore extends tough.Store {
idx: {
[domain: string]: {
[path: string]: {
[key: string]: tough.Cookie
}
}
};
filePath: string;
synchronous: boolean;
constructor(filePath: string);
checkExpired(domain: string | null, path: string | null, key: string | null): boolean;
findCookie(
domain: string,
path: string,
key: string,
cb: (err: null, cookie: tough.Cookie | null) => void
): void;
findCookies(
domain: string,
path: string,
cb: (err: null, cookies: tough.Cookie[]) => void
): void;
getAllCookies(cb: (err: Error | null, cookies: tough.Cookie[]) => void): void;
inspect(): string;
isEmpty(): boolean;
isExpired(): boolean;
putCookie(cookie: tough.Cookie, cb: (err: Error | null) => void): void;
removeCookie(
domain: string,
path: string,
key: string,
cb: (err: Error | null) => void
): void;
removeCookies(
domain: string,
path: string,
cb: (err: Error | null) => void
): void;
updateCookie(
oldCookie: tough.Cookie,
newCookie: tough.Cookie,
cb: (err: Error | null) => void
): void;
}
@@ -0,0 +1,20 @@
import CookieStore = require('tough-cookie-file-store');
import { CookieJar } from 'tough-cookie';
new CookieJar(new CookieStore('./cookie.json'));
/* check if cookie is empty or expired */
const cookieInstance = new CookieStore('./cookie.json');
cookieInstance.isExpired(); // will return True if the cookie is expired
cookieInstance.isEmpty(); // will return True if cookie is empty
/* request example */
/*
// Disabled due to warning in npm test:
// Error: tough-cookie-file-store depends on request but has a lower required TypeScript version.
import * as request from 'request'
var j = request.jar(new CookieStore('./cookie.json'));
const r = request.defaults({ jar : j })
r('http://www.google.com', function() {
r('http://images.google.com')
})
*/
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"tough-cookie-file-store-tests.ts"
]
}
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }