Nostalgic Pizza Manager

    cookies-utils
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.0 • Public • Published

    cookies-utils

    NPM Version Build Status

    This project contains functions to help manage cookies.

    Installation

    NPM

    Install the library with npm install cookies-utils.

    CDN

    Or use it directly in your browser via jsDelivr or unpkg:

    <script src="https://cdn.jsdelivr.net/npm/cookies-utils/cookies-utils.min.js"></script>
     
    ...
     
    cookiesUtils.deleteCookie('name')

    or

    <script src="https://unpkg.com/cookies-utils/cookies-utils.min.js"></script>
     
    ...
     
    cookiesUtils.deleteCookie('name')

    Usage

    Set a cookie

    import { setCookie } from "cookies-utils";
     
    // more information about the options in documentation https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie
    const cookieOptions = {
      name: "name", // string,
      value: "value", // string,
      maxAge: 10 * 60, // optional number (value in seconds),
      expires: new Date(2099, 10, 1), // optional Date,
      path: "/path", // optional string,
      domain: "site.com", // optional string,
      secure: true, // optional boolean,
      sameSite: "lax", // optional enum 'lax' | 'strict' | 'none'
    };
    setCookie(cookieOptions);

    Check existence of cookie

    import { cookieExists } from "cookies-utils";
     
    const isExist = cookieExists("name");

    Delete a cookie

    import { deleteCookie } from "cookies-utils";
     
    deleteCookie("name");

    Check if cookie has specific value

    import { cookieHasValue } from "cookies-utils";
     
    const hasValue = cookieHasValue("name", "value");

    Delete all cookies

    import { deleteAllCookies } from "cookies-utils";
     
    deleteAllCookies();

    Install

    npm i cookies-utils

    DownloadsWeekly Downloads

    193

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    20.9 kB

    Total Files

    8

    Last publish

    Collaborators

    • hamzahamidi