@robinpath/cookie
0.1.1Node.jsPublicHTTP cookie parsing, serialization, signing/verification, Set-Cookie handling, and cookie jar management
Cookie
HTTP cookie parsing, serialization, signing/verification, Set-Cookie handling, and cookie jar management
Package: @robinpath/cookie | Category: Web | Type: Utility
Authentication
No authentication required. All functions are available immediately.
Use Cases
Use the cookie module when you need to:
- Parse Cookie header string -- Use
cookie.parseto perform this operation - Serialize Set-Cookie header -- Use
cookie.serializeto perform this operation - Sign cookie value with HMAC -- Use
cookie.signto perform this operation - Verify and unsign cookie -- Use
cookie.unsignto perform this operation - Get single cookie from header -- Use
cookie.getto perform this operation
Quick Reference
| Function | Description | Returns |
|---|---|---|
parse | Parse Cookie header string | Name-value pairs |
serialize | Serialize Set-Cookie header | Set-Cookie header value |
sign | Sign cookie value with HMAC | Signed value |
unsign | Verify and unsign cookie | Original value or null |
get | Get single cookie from header | Value or null |
remove | Generate removal Set-Cookie | Set-Cookie header |
parseSetCookie | Parse Set-Cookie header | Cookie object with attributes |
isExpired | Check if cookie is expired | true if expired |
jar | Create cookie jar | Cookie jar object |
toHeader | Build Cookie header from pairs | Cookie header string |
encode | URL-encode cookie value | Encoded value |
decode | URL-decode cookie value | Decoded value |
Functions
parse
Parse Cookie header string
Module: cookie | Returns: object -- Name-value pairs
cookie.parse "session=abc; theme=dark"
| Parameter | Type | Required | Description |
|---|---|---|---|
header | string | Yes | Cookie header value |
serialize
Serialize Set-Cookie header
Module: cookie | Returns: string -- Set-Cookie header value
cookie.serialize "session" "abc123" {"httpOnly": true, "maxAge": 3600}
| Parameter | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Cookie name |
value | string | Yes | Cookie value |
options | object | No | {domain, path, expires, maxAge, secure, httpOnly, sameSite} |
sign
Sign cookie value with HMAC
Module: cookie | Returns: string -- Signed value
cookie.sign "userId=123" "my-secret"
| Parameter | Type | Required | Description |
|---|---|---|---|
value | string | Yes | Value to sign |
secret | string | Yes | Signing secret |
unsign
Verify and unsign cookie
Module: cookie | Returns: string -- Original value or null
cookie.unsign $signed "my-secret"
| Parameter | Type | Required | Description |
|---|---|---|---|
signed | string | Yes | Signed value |
secret | string | Yes | Signing secret |
get
Get single cookie from header
Module: cookie | Returns: string -- Value or null
cookie.get $header "session"
| Parameter | Type | Required | Description |
|---|---|---|---|
header | string | Yes | Cookie header |
name | string | Yes | Cookie name |
remove
Generate removal Set-Cookie
Module: cookie | Returns: string -- Set-Cookie header
cookie.remove "session"
| Parameter | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Cookie name |
options | object | No | {domain, path} |
parseSetCookie
Parse Set-Cookie header
Module: cookie | Returns: object -- Cookie object with attributes
cookie.parseSetCookie "session=abc; HttpOnly; Max-Age=3600"
| Parameter | Type | Required | Description |
|---|---|---|---|
header | string | Yes | Set-Cookie header |
isExpired
Check if cookie is expired
Module: cookie | Returns: boolean -- true if expired
cookie.isExpired $cookie
| Parameter | Type | Required | Description |
|---|---|---|---|
cookie | object | Yes | Cookie object |
jar
Create cookie jar
Module: cookie | Returns: object -- Cookie jar object
cookie.jar
| Parameter | Type | Required | Description |
|---|---|---|---|
| (none) | No | Call with no arguments |
toHeader
Build Cookie header from pairs
Module: cookie | Returns: string -- Cookie header string
cookie.toHeader {"session": "abc", "theme": "dark"}
| Parameter | Type | Required | Description |
|---|---|---|---|
cookies | object | Yes | Name-value pairs |
encode
URL-encode cookie value
Module: cookie | Returns: string -- Encoded value
cookie.encode "hello world"
| Parameter | Type | Required | Description |
|---|---|---|---|
value | string | Yes | Value |
decode
URL-decode cookie value
Module: cookie | Returns: string -- Decoded value
cookie.decode "hello%20world"
| Parameter | Type | Required | Description |
|---|---|---|---|
value | string | Yes | Encoded value |
Error Handling
All functions throw on failure. Common errors:
| Error | Cause |
|---|---|
| (standard errors) | Check function parameters and authentication |
@desc "Parse and validate result"
do
set $result as cookie.parse "session=abc; theme=dark"
if $result != null
print "Success"
else
print "No result"
end
enddo
Recipes
1. List and iterate
Retrieve all items and loop through them.
@desc "Get and iterate results"
do
set $result as cookie.get $header "session"
each $item in $result
print $item
end
enddo
2. Multi-step Cookie workflow
Chain multiple cookie operations together.
@desc "Parse, serialize, and more"
do
set $r_parse as cookie.parse "session=abc; theme=dark"
set $r_serialize as cookie.serialize "session" "abc123" {"httpOnly": true, "maxAge": 3600}
set $r_sign as cookie.sign "userId=123" "my-secret"
print "All operations complete"
enddo
3. Safe parse with validation
Check results before proceeding.
@desc "Parse and validate result"
do
set $result as cookie.parse "session=abc; theme=dark"
if $result != null
print "Success: " + $result
else
print "Operation returned no data"
end
enddo
Related Modules
- json -- JSON module for complementary functionality
Versions (1)
| Version | Tag | Published |
|---|---|---|
| 0.1.1 | latest | 1 months ago |
Related Modules
ftp
JS@robinpathv0.1.3
FTP and SFTP file transfer operations
http
JS@robinpathv0.1.3
HTTP server for RobinPath scripts. Register routes with static responses (JSON, HTML, files), enable CORS, serve static directories. No callbacks needed.
form
JS@robinpathv0.2.1
Declarative form builder for RobinPath scripts � define fields inline, generate schemas, validate submissions
api
JS@robinpathv0.1.2
HTTP client for making requests to external APIs with profiles, auth, download/upload, and auto-JSON parsing
$ robinpath add @robinpath/cookie
