From e113d72db74b5d0ab287bcb6ba83cb9444812f7a Mon Sep 17 00:00:00 2001 From: Emily Marigold Klassen Date: Tue, 2 Apr 2019 12:10:40 -0700 Subject: [PATCH] Add types for tough-cookie-file-store --- types/tough-cookie-file-store/index.d.ts | 67 +++++++++++++++++++ .../tough-cookie-file-store-tests.ts | 20 ++++++ types/tough-cookie-file-store/tsconfig.json | 23 +++++++ types/tough-cookie-file-store/tslint.json | 1 + 4 files changed, 111 insertions(+) create mode 100644 types/tough-cookie-file-store/index.d.ts create mode 100644 types/tough-cookie-file-store/tough-cookie-file-store-tests.ts create mode 100644 types/tough-cookie-file-store/tsconfig.json create mode 100644 types/tough-cookie-file-store/tslint.json diff --git a/types/tough-cookie-file-store/index.d.ts b/types/tough-cookie-file-store/index.d.ts new file mode 100644 index 0000000000..1e791854e6 --- /dev/null +++ b/types/tough-cookie-file-store/index.d.ts @@ -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 +// 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; +} diff --git a/types/tough-cookie-file-store/tough-cookie-file-store-tests.ts b/types/tough-cookie-file-store/tough-cookie-file-store-tests.ts new file mode 100644 index 0000000000..e8a65c7e59 --- /dev/null +++ b/types/tough-cookie-file-store/tough-cookie-file-store-tests.ts @@ -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') +}) +*/ diff --git a/types/tough-cookie-file-store/tsconfig.json b/types/tough-cookie-file-store/tsconfig.json new file mode 100644 index 0000000000..3f772c1fc4 --- /dev/null +++ b/types/tough-cookie-file-store/tsconfig.json @@ -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" + ] +} diff --git a/types/tough-cookie-file-store/tslint.json b/types/tough-cookie-file-store/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/tough-cookie-file-store/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }