Skip to content

JavaScript-utilities to handle cookies everywhere

License

Notifications You must be signed in to change notification settings

yurkimus/cookies

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cookies

JavaScript-utilities to handle cookies everywhere.

Table of Contents

Installation

npm

npm install @yurkimus/cookies

urls

"@yurkimus/cookies": "npm:@yurkimus/cookies"
"@yurkimus/cookies": "github:yurkimus/cookies"
"@yurkimus/cookies": "https://raw.githubusercontent.com/yurkimus/cookies/main/source/index.js"

Exports

read

Definition

read :: string -> string -> string

Example

let cookie = 'name=John; age=30; role=admin'

let age = read('age', cookie) // => '30'

let [age, name] = ['age', 'name']
  .map(key => read(key))
  .map(reader => reader(cookie)) // => ['30', 'John']

parse

Definition

parse :: string -> object

Example

parse('name=John; age=30; role=admin') // => { name: 'John', age: '30', role: 'admin' }

serialize

Definition

serialize :: string -> * -> [(string, string)] -> string

Example

let attributes = [
  ['path', '/'],
  ['expires', 'Wed, 21 Oct 2026 07:28:00 GMT'],
]

serialize('name', 'John', attributes) // => 'name=John; path=/; expires=Wed, 21 Oct 2026 07:28:00 GMT'

License

MIT

About

JavaScript-utilities to handle cookies everywhere

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published