@toolz/get-cookies

1.0.3 • Public • Published

get-cookies

get-cookies is a utility function that parses cookies into an object. Its default behavior will also attempt to convert cookie values into their "logical" data types.

Usage

After installation, import the package:

import { getCookies } from '@toolz/get-cookies';

getCookies()

The function returns an object containing any existing cookie values and attempts to convert those values into native JS data types.

const API = {
   arguments: {
      convertDataTypes: {
         optional,
         format: Boolean,
         defaultValue: true,
      },
   },
   returns: Object,
}

Examples:

// document.cookies = 'isKool=true; name=mary; pi=3.14; children=null; age=42'
const cookies = getCookies();
/*
   cookies = {
      isKool: true,
      name: 'mary',
      pi: 3.14,
      children: null,
      age: 42,
   }
 */
// document.cookies = 'isKool=true; name=mary; pi=3.14; children=null; age=42'
const cookies = getCookies(false);
/*
   cookies = {
      isKool: 'true',
      name: 'mary',
      pi: '3.14',
      children: 'null',
      age: '42',
   }
 */

Package Sidebar

Install

npm i @toolz/get-cookies

Weekly Downloads

0

Version

1.0.3

License

MIT

Unpacked Size

4.56 kB

Total Files

4

Last publish

Collaborators

  • bytebodger