Cookies for JS
    Preparing search index...

    Class CookieStore

    Provides access to the HTTP Cookies.

    Hierarchy

    • EventTarget
      • CookieStore
    Index

    Constructors

    • Creates a new cookie store.

      Parameters

      • options: Partial = {}

        An object providing values to initialize this instance.

      Returns CookieStore

    Properties

    defaults: CookieOptions

    The default cookie options.

    Accessors

    • get keys(): Set<string>

      The keys of this cookie store.

      Returns Set<string>

    • get length(): number

      The number of entries in this cookie store.

      Returns number

    • get all(): Map<string, string>

      The map of all cookies.

      Returns Map<string, string>

    Methods

    • Returns a new iterator that allows iterating the entries of this cookie store.

      Returns IterableIterator<[string, string]>

      An iterator for the entries of this cookie store.

    • Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched.

      The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options's capture.

      When set to true, options's capture prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event's eventPhase attribute value is AT_TARGET.

      When set to true, options's passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in § 2.8 Observing event listeners.

      When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed.

      If an AbortSignal is passed for options's signal, then the event listener will be removed when signal is aborted.

      The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.

      MDN Reference

      Parameters

      • type: string
      • callback: null | EventListenerOrEventListenerObject
      • Optionaloptions: boolean | AddEventListenerOptions

      Returns void

    • Removes all entries from this cookie store.

      Parameters

      • options: Partial = {}

        The cookie options.

      Returns void

    • Removes the value associated with the specified key.

      Parameters

      • key: string

        The cookie name.

      • options: Partial = {}

        The cookie options.

      Returns null | string

      The value associated with the key before it was removed.

    • Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise.

      MDN Reference

      Parameters

      • event: Event

      Returns boolean

    • Gets the value associated to the specified key.

      Parameters

      • key: string

        The cookie name.

      Returns null | string

      The cookie value, or null if the key does not exist.

    • Gets the deserialized value associated with the specified key.

      Type Parameters

      • T

      Parameters

      • key: string

        The cookie name.

      Returns null | T

      The cookie value, or null if the key does not exist or the value cannot be deserialized.

    • Gets a value indicating whether this cookie store contains the specified key.

      Parameters

      • key: string

        The cookie name.

      Returns boolean

      true if this cookie store contains the specified key, otherwise false.

    • Registers a function that will be invoked whenever the change event is triggered.

      Parameters

      • listener: (event: CookieEvent) => void

        The event handler to register.

      Returns this

      This instance.

    • Removes the event listener in target's event listener list with the same type, callback, and options.

      MDN Reference

      Parameters

      • type: string
      • callback: null | EventListenerOrEventListenerObject
      • Optionaloptions: boolean | EventListenerOptions

      Returns void

    • Associates a given value with the specified key.

      Parameters

      • key: string

        The cookie name.

      • value: string

        The cookie value.

      • options: Partial = {}

        The cookie options.

      Returns this

      This instance.

      Error if the cookie name is invalid.

    • Serializes and associates a given value with the specified key.

      Parameters

      • key: string

        The cookie name.

      • value: unknown

        The cookie value.

      • options: Partial = {}

        The cookie options.

      Returns this

      This instance.

    • Returns a JSON representation of this object.

      Returns [string, string][]

      The JSON representation of this object.

    • Returns a string representation of this object.

      Returns string

      The string representation of this object.