Skip to content

Commit

Permalink
Add docs to README
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey committed Nov 20, 2024
1 parent 7aea427 commit cd7ac13
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,27 @@ The default function is the global `decodeURIComponent`, wrapped in a `try..catc
is thrown it will return the cookie's original value. If you provide your own encode/decode
scheme you must ensure errors are appropriately handled.

### cookie.stringify(obj, options)

Stringifies an object into a HTTP `Cookie` header.

```js
const cookieHeader = cookie.stringify({ a: "foo", b: "bar" });
// a=foo; b=bar
```

#### Options

`cookie.stringify` accepts these properties in the options object.

##### encode

Specifies a function that will be used to encode a [cookie-value](https://datatracker.ietf.org/doc/html/rfc6265#section-4.1.1).
Since value of a cookie has a limited character set (and must be a simple string), this function can be used to encode
a value into a string suited for a cookie's value, and should mirror `decode` when parsing.

The default function is the global `encodeURIComponent`.

### cookie.serialize(name, value, options)

Serialize a cookie name-value pair into a `Set-Cookie` header string. The `name` argument is the
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export interface StringifyOptions {
}

/**
* Stringify a set of cookies into a `Cookie` header string.
* Stringifies an object into a HTTP `Cookie` header.
*/
export function stringify(
cookies: Cookies,
Expand Down

0 comments on commit cd7ac13

Please sign in to comment.