@types/js-cookie

  • Version 3.0.6
  • Published
  • 7.43 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<string> & {
noConflict?(): Cookies.CookiesStatic;
};

    Interfaces

    interface Converter

    interface Converter<TConv> {}

      property read

      read?: CookieReadConverter<TConv> | undefined;

        property write

        write?: CookieWriteConverter<TConv> | undefined;

          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 = string> {}

              property attributes

              readonly attributes: CookieAttributes;

                property converter

                readonly converter: Required<Converter<string>>;

                  method get

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

                  • Read all available cookies

                  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 withAttributes

                  withAttributes: (attributes: CookieAttributes) => CookiesStatic<T>;
                  • Cookie attribute defaults can be set globally by creating an instance of the api via withAttributes(), or individually for each call to Cookies.set(...) by passing a plain object as the last argument. Per-call attributes override the default attributes.

                  method withConverter

                  withConverter: <TConv = string>(
                  converter: Converter<TConv>
                  ) => 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<T> = (value: string, name: string) => string | T;

                    type CookieWriteConverter

                    type CookieWriteConverter<T> = (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>