diff --git a/types/cookie_js/cookie_js-tests.ts b/types/cookie_js/cookie_js-tests.ts new file mode 100644 index 0000000000..43047f4fb6 --- /dev/null +++ b/types/cookie_js/cookie_js-tests.ts @@ -0,0 +1,35 @@ + + +// Based on https://github.com/js-coder/cookie.js/blob/gh-pages/tests/spec.js + +import cookie = require("cookiejs"); + +cookie.set({a: '1', b: '2', c: '3'}); + +cookie; +cookie.enabled(); + +cookie.set('n', '5'); + +cookie.get('a'); +cookie.get('__undef__'); +cookie.get('__undef__', 'fallback'); +cookie.get(['a', 'b']); +cookie.get(['a', '__undef__'], 'fallback'); + +cookie('a'); +cookie('__undef__'); +cookie('__undef__', 'fallback'); +cookie(['a', 'b']); +cookie(['a', '__undef__'], 'fallback'); + +cookie.remove('a'); +cookie.remove('a', 'b'); +cookie.remove(['a', 'b']); + +cookie.removeSpecific('a', {path: '/search'}); +cookie.removeSpecific(['a', 'b'], {path: '/search'}); + +cookie.empty(); + +cookie.all(); diff --git a/types/cookie_js/index.d.ts b/types/cookie_js/index.d.ts new file mode 100644 index 0000000000..6ccc9db401 --- /dev/null +++ b/types/cookie_js/index.d.ts @@ -0,0 +1,55 @@ +// Type definitions for cookie_js v1.2.2 +// Project: https://github.com/florian/cookie.js +// Definitions by: slawiko +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +/** + * Shortcut for cookie.get() + */ + +export = cookie; +export as namespace cookie; + +declare function cookie(key : string, fallback?: string) : string; +declare function cookie(keys : string[], fallback?: string) : string; + +declare namespace cookie { + /** + * Create a cookie. The value will automatically be escaped. + */ + export function set(key : string, value : string, options? : any) : void; + /** + * Set several cookies at once + */ + export function set(obj : any, options? : any) : void; + /** + * Remove cookies + */ + export function remove(key : string) : void; + export function remove(keys : string[]) : void; + export function remove(...args : string[]) : void; + /** + * Remove cookies that were set with custom options (e.g. specifing domain or path) + */ + export function removeSpecific(key : string, options?: any) : void; + export function removeSpecific(keys : string[], options?: any): void; + /** + * Remove all cookies + */ + export function empty() : void; + /** + * Retrieve the value of the cookie + */ + export function get(key : string, fallback?: string) : string; + /** + * Retrieve values of several cookies + */ + export function get(keys : string[], fallback?: string) : any; + /** + * Get all currently saved cookies + */ + export function all() : any; + /** + * Test if cookies are enabled + */ + export function enabled() : boolean; +} diff --git a/types/cookie_js/tsconfig.json b/types/cookie_js/tsconfig.json new file mode 100644 index 0000000000..98e46b222a --- /dev/null +++ b/types/cookie_js/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "cookie_js-tests.ts" + ] +}