Skip to content

Commit 8a761fe

Browse files
Add docs for the new api
1 parent a5640d4 commit 8a761fe

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

README.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ A simple, lightweight JavaScript API for handling cookies
99
* [Unobtrusive](#json) JSON support
1010
* Supports AMD/CommonJS
1111
* [RFC 6265](https://tools.ietf.org/html/rfc6265) compliant
12-
* Enable [custom decoding](#converter)
1312
* Very good [Wiki](https://github.com/js-cookie/js-cookie/wiki)
13+
* Enable [custom encoding/decoding](#converters)
1414
* **~800 bytes** gzipped!
1515

1616
**If you're viewing this at https://github.com/js-cookie/js-cookie, you're reading the documentation for the master branch.
@@ -213,7 +213,9 @@ Cookies.get('name'); // => 'value'
213213
Cookies.remove('name', { secure: true });
214214
```
215215

216-
## Converter
216+
## Converters
217+
218+
### Read
217219

218220
Create a new instance of the api that overrides the default decoding implementation.
219221
All get methods that rely in a proper decoding to work, such as `Cookies.get()` and `Cookies.get('name')`, will run the converter first for each cookie.
@@ -243,6 +245,28 @@ Cookies.withConverter(function (value) {
243245
}).get('foo');
244246
```
245247

248+
You can also pass an object literal:
249+
250+
```javascript
251+
Cookies.withConverter({
252+
read: function (value, name) {
253+
// Convert
254+
}
255+
});
256+
```
257+
258+
### Write
259+
260+
Create a new instance of the api that overrides the default encoding implementation:
261+
262+
```javascript
263+
Cookies.withConverter({
264+
write: function (value, name) {
265+
// Convert
266+
}
267+
});
268+
```
269+
246270
## Contributing
247271

248272
Check out the [Contributing Guidelines](CONTRIBUTING.md)

0 commit comments

Comments
 (0)