Skip to content

Commit cd7ac13

Browse files
committed
Add docs to README
1 parent 7aea427 commit cd7ac13

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

README.md

+21
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,27 @@ The default function is the global `decodeURIComponent`, wrapped in a `try..catc
4545
is thrown it will return the cookie's original value. If you provide your own encode/decode
4646
scheme you must ensure errors are appropriately handled.
4747

48+
### cookie.stringify(obj, options)
49+
50+
Stringifies an object into a HTTP `Cookie` header.
51+
52+
```js
53+
const cookieHeader = cookie.stringify({ a: "foo", b: "bar" });
54+
// a=foo; b=bar
55+
```
56+
57+
#### Options
58+
59+
`cookie.stringify` accepts these properties in the options object.
60+
61+
##### encode
62+
63+
Specifies a function that will be used to encode a [cookie-value](https://datatracker.ietf.org/doc/html/rfc6265#section-4.1.1).
64+
Since value of a cookie has a limited character set (and must be a simple string), this function can be used to encode
65+
a value into a string suited for a cookie's value, and should mirror `decode` when parsing.
66+
67+
The default function is the global `encodeURIComponent`.
68+
4869
### cookie.serialize(name, value, options)
4970

5071
Serialize a cookie name-value pair into a `Set-Cookie` header string. The `name` argument is the

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export interface StringifyOptions {
169169
}
170170

171171
/**
172-
* Stringify a set of cookies into a `Cookie` header string.
172+
* Stringifies an object into a HTTP `Cookie` header.
173173
*/
174174
export function stringify(
175175
cookies: Cookies,

0 commit comments

Comments
 (0)