ngx-cookie

  • Version 5.0.2
  • Published
  • 147 kB
  • 1 dependency
  • MIT license

Install

npm i ngx-cookie
yarn add ngx-cookie
pnpm add ngx-cookie

Overview

Implementation of Angular 1.x $cookies service to Angular

Index

Variables

const COOKIE_OPTIONS: any;
    const COOKIE_WRITER: any;

      Functions

      function buildCookieString

      buildCookieString: (
      name: string,
      value: string | undefined,
      options?: CookieOptions
      ) => string;

        function cookieServiceFactory

        cookieServiceFactory: (
        document: Document,
        cookieOptionsProvider: CookieOptionsProvider,
        cookieWriterService: ICookieWriterService
        ) => CookieService;

          function isEmpty

          isEmpty: (value: any) => boolean;

            function isNil

            isNil: (obj: any) => boolean;

              function isPresent

              isPresent: (obj: any) => boolean;

                function isString

                isString: (obj: any) => obj is string;

                  function mergeOptions

                  mergeOptions: (
                  oldOptions: CookieOptions,
                  newOptions?: CookieOptions
                  ) => CookieOptions;

                    function parseCookieString

                    parseCookieString: (currentCookieString: string) => CookieDict;

                      function safeDecodeURIComponent

                      safeDecodeURIComponent: (str: string) => string;

                        Classes

                        class CookieModule

                        class CookieModule {}

                          method forChild

                          static forChild: (options?: CookieOptions) => any;
                          • Use this method in your other (non root) modules to import the directive/pipe

                          method forRoot

                          static forRoot: (options?: CookieOptions) => any;
                          • Use this method in your root module to provide the CookieService

                          class CookieOptionsProvider

                          class CookieOptionsProvider {}

                            constructor

                            constructor(options: CookieOptions, injector: any);

                              property options

                              readonly options: CookieOptions;

                                class CookieService

                                class CookieService implements ICookieService {}

                                  constructor

                                  constructor(
                                  document: any,
                                  optionsProvider: CookieOptionsProvider,
                                  cookieWriterService: ICookieWriterService
                                  );

                                    property options

                                    protected options: CookieOptions;

                                      method get

                                      get: (key: string) => string;
                                      • Returns the value of given cookie key.

                                        Parameter key

                                        Id to use for lookup.

                                        Returns

                                        Raw cookie value.

                                      method getAll

                                      getAll: () => CookieDict;
                                      • Returns a key value object with all the cookies.

                                        Returns

                                        All cookies

                                      method getObject

                                      getObject: (key: string) => object | undefined;
                                      • Returns the deserialized value of given cookie key.

                                        Parameter key

                                        Id to use for lookup.

                                        Returns

                                        Deserialized cookie value.

                                      method hasKey

                                      hasKey: (key: string) => boolean;
                                      • Returns if the given cookie key exists or not.

                                        Parameter key

                                        Id to use for lookup.

                                        Returns

                                        true if key exists, otherwise false.

                                      method put

                                      put: (key: string, value: string | undefined, options?: CookieOptions) => void;
                                      • Sets a value for given cookie key.

                                        Parameter key

                                        Id for the value.

                                        Parameter value

                                        Raw value to be stored.

                                        Parameter options

                                        (Optional) Options object.

                                      method putObject

                                      putObject: (key: string, value: object, options?: CookieOptions) => void;
                                      • Serializes and sets a value for given cookie key.

                                        Parameter key

                                        Id for the value.

                                        Parameter value

                                        Value to be stored.

                                        Parameter options

                                        (Optional) Options object.

                                      method remove

                                      remove: (key: string, options?: CookieOptions) => void;
                                      • Remove given cookie.

                                        Parameter key

                                        Id of the key-value pair to delete.

                                        Parameter options

                                        (Optional) Options object.

                                      method removeAll

                                      removeAll: (options?: CookieOptions) => void;
                                      • Remove all cookies.

                                      class CookieWriterService

                                      class CookieWriterService implements ICookieWriterService {}

                                        constructor

                                        constructor(document: any);

                                          method readAllAsString

                                          readAllAsString: () => string;

                                            method write

                                            write: (
                                            name: string,
                                            value: string | undefined,
                                            options?: CookieOptions
                                            ) => void;

                                              Interfaces

                                              interface CookieDict

                                              interface CookieDict {}

                                                index signature

                                                [key: string]: string;

                                                  interface CookieOptions

                                                  interface CookieOptions {}
                                                  • Object containing default options to pass when setting cookies.

                                                    The object may have following properties:

                                                    - **path** - {string} - The cookie will be available only for this path and its sub-paths. By default, this is the URL that appears in your <base> tag. - **domain** - {string} - The cookie will be available only for this domain and its sub-domains. For security reasons the user agent will not accept the cookie if the current domain is not a sub-domain of this domain or equal to it. - **expires** - {string|Date} - String of the form "Wdy, DD Mon YYYY HH:MM:SS GMT" or a Date object indicating the exact date/time this cookie will expire. - **secure** - {boolean} - If true, then the cookie will only be available through a secured connection. - **httpOnly** - {boolean} - If true, then the cookie will be set with the HttpOnly flag, and will only be accessible from the remote server. Helps to prevent against XSS attacks. - **sameSite** - {"Lax"|"Strict"|"None"} - Designates cookie for first party (Lax|Strict) or third party contexts. - **storeUnencoded** - {boolean} - If true, then the cookie value will not be encoded and will be stored as provided.

                                                  property domain

                                                  domain?: string;

                                                    property expires

                                                    expires?: string | Date;

                                                      property httpOnly

                                                      httpOnly?: boolean;

                                                        property path

                                                        path?: string;

                                                          property sameSite

                                                          sameSite?: boolean | 'lax' | 'strict' | 'none';

                                                            property secure

                                                            secure?: boolean;

                                                              property storeUnencoded

                                                              storeUnencoded?: boolean;

                                                                interface ICookieService

                                                                interface ICookieService {}

                                                                  method get

                                                                  get: (key: string) => string;

                                                                    method getAll

                                                                    getAll: () => object;

                                                                      method getObject

                                                                      getObject: (key: string) => object | undefined;

                                                                        method hasKey

                                                                        hasKey: (key: string) => boolean;

                                                                          method put

                                                                          put: (key: string, value: string, options?: CookieOptions) => void;

                                                                            method putObject

                                                                            putObject: (key: string, value: object, options?: CookieOptions) => void;

                                                                              method remove

                                                                              remove: (key: string, options?: CookieOptions) => void;

                                                                                method removeAll

                                                                                removeAll: (options?: CookieOptions) => void;

                                                                                  interface ICookieWriterService

                                                                                  interface ICookieWriterService {}

                                                                                    method readAllAsString

                                                                                    readAllAsString: () => string;

                                                                                      method write

                                                                                      write: (
                                                                                      name: string,
                                                                                      value: string | undefined,
                                                                                      options?: CookieOptions
                                                                                      ) => void;

                                                                                        Package Files (9)

                                                                                        Dependencies (1)

                                                                                        Dev Dependencies (0)

                                                                                        No dev dependencies.

                                                                                        Peer Dependencies (2)

                                                                                        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/ngx-cookie.

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