Wondering what’s next for npm?Check out our public roadmap! »

    cookiestorage

    1.0.0 • Public • Published

    cookiestorage

    Build Status

    Manage document.cookie using the Storage API.

    NOTE: originally a fork of cookie-monster, itself a fork of cookie-cutter.

    install

    npm install cookiestorage

    api

    var cookieStorage = require('cookiestorage');
    var cookie = cookieStorage(document);

    cookieStorage(document)

    Return a new cookie object with .getItem() and .setItem() operating on document.

    The provided document should have a non-referentially transparent cookie property like the DOM's variant where assignment with optional path and expiry creates a new cookie in the getter as a key=value pair.

    If document is not provided, uses the global document if it exists. Otherwise, creates a new plain object {cookie:''}.

    If given a string, uses { cookie: givenString }.

    #length

    Returns number of key/value pairs present in document.cookie

    #getItem(key)

    Returns the cookie value for key.

    #setItem(key, value, options={})

    Sets the cookie at key to value with additional options:

    #key(index)

    Returns the key (name) of the nth key/value pair in document.cookie. Order is dependent on browser implementation. May not be alphabetical, or even consistent. Use this with caution. (It is added solely for consistency with the Storage API.)

    #removeItem(key)

    Removes the given key from document.cookie.

    #clear()

    Clears document.cookie of all key/value pairs.

    Install

    npm i cookiestorage

    DownloadsWeekly Downloads

    43

    Version

    1.0.0

    License

    MIT

    Last publish

    Collaborators

    • avatar