@types/js-cookie

  • Version 2.2.7
  • Published
  • 7.38 kB
  • No dependencies
  • MIT license

Install

npm i @types/js-cookie
yarn add @types/js-cookie
pnpm add @types/js-cookie

Overview

TypeScript definitions for js-cookie

Index

Variables

variable Cookies

const Cookies: Cookies.CookiesStatic<object>;

    Interfaces

    interface CookieAttributes

    interface CookieAttributes {}

      property domain

      domain?: string | undefined;
      • Define the domain where the cookie is available. Defaults to the domain of the page where the cookie was created.

      property expires

      expires?: number | Date | undefined;
      • Define when the cookie will be removed. Value can be a Number which will be interpreted as days from time of creation or a Date instance. If omitted, the cookie becomes a session cookie.

      property path

      path?: string | undefined;
      • Define the path where the cookie is available. Defaults to '/'

      property sameSite

      sameSite?: 'strict' | 'Strict' | 'lax' | 'Lax' | 'none' | 'None' | undefined;
      • Asserts that a cookie must not be sent with cross-origin requests, providing some protection against cross-site request forgery attacks (CSRF)

      property secure

      secure?: boolean | undefined;
      • A Boolean indicating if the cookie transmission requires a secure protocol (https). Defaults to false.

      index signature

      [property: string]: any;
      • An attribute which will be serialized, conformably to RFC 6265 section 5.2.

      interface CookiesStatic

      interface CookiesStatic<T extends object = object> {}

        property defaults

        defaults: CookieAttributes;
        • Allows default cookie attributes to be accessed, changed, or reset

        method get

        get: { (name: string): string | undefined; (): { [key: string]: string } };
        • Read cookie

        • Read all available cookies

        method getJSON

        getJSON: { (name: string): any; (): { [key: string]: any } };
        • Returns the parsed representation of the string stored in the cookie according to JSON.parse

        • Returns the parsed representation of all cookies according to JSON.parse

        method noConflict

        noConflict: () => CookiesStatic<T>;
        • If there is any danger of a conflict with the namespace Cookies, the noConflict method will allow you to define a new namespace and preserve the original one. This is especially useful when running the script on third party sites e.g. as part of a widget or SDK. Note: The noConflict method is not necessary when using AMD or CommonJS, thus it is not exposed in those environments.

        method remove

        remove: (name: string, options?: CookieAttributes) => void;
        • Delete cookie

        method set

        set: (
        name: string,
        value: string | T,
        options?: CookieAttributes
        ) => string | undefined;
        • Create a cookie

        method withConverter

        withConverter: <TConv extends object>(
        converter:
        | CookieReadConverter
        | {
        write?: CookieWriteConverter<TConv> | undefined;
        read?: CookieReadConverter | undefined;
        }
        ) => CookiesStatic<TConv>;
        • Create a new instance of the api that overrides the default decoding implementation. All methods that rely in a proper decoding to work, such as Cookies.remove() and Cookies.get(), will run the converter first for each cookie. The returned string will be used as the cookie value.

        Type Aliases

        type CookieReadConverter

        type CookieReadConverter = (value: string, name: string) => string;

          type CookieWriteConverter

          type CookieWriteConverter<T extends object> = (
          value: string | T,
          name: string
          ) => string;

            Package Files (1)

            Dependencies (0)

            No dependencies.

            Dev Dependencies (0)

            No dev dependencies.

            Peer Dependencies (0)

            No peer dependencies.

            Badge

            To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

            You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/js-cookie.

            • Markdown
              [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@types/js-cookie)
            • HTML
              <a href="https://www.jsdocs.io/package/@types/js-cookie"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>