Skip to content

Commit

Permalink
Add types for tough-cookie-file-store
Browse files Browse the repository at this point in the history
  • Loading branch information
forivall committed Apr 2, 2019
1 parent 5470986 commit e113d72
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 0 deletions.
67 changes: 67 additions & 0 deletions types/tough-cookie-file-store/index.d.ts
Original file line number Diff line number Diff line change
@@ -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;
}
20 changes: 20 additions & 0 deletions types/tough-cookie-file-store/tough-cookie-file-store-tests.ts
Original file line number Diff line number Diff line change
@@ -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')
})
*/
23 changes: 23 additions & 0 deletions types/tough-cookie-file-store/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
1 change: 1 addition & 0 deletions types/tough-cookie-file-store/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }

0 comments on commit e113d72

Please sign in to comment.