Skip to content

Commit 40b42fa

Browse files
new release added new method
1 parent 21fd678 commit 40b42fa

5 files changed

Lines changed: 29 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release Notes
22

3+
## [v1.1.0](https://github.com/jsvibe/cookie-events/compare/v1.0.0...v1.1.0) - 02-09-2025
4+
5+
- `createFormData()` in Cookie library Converts all available cookies into a `FormData` object, useful for sending cookies as form data in AJAX/fetch requests.
6+
37
## [v1.0.0](https://github.com/jsvibe/cookie-events/releases/tag/v1.0.0) - 31-08-2025
48

59
- Initial public release.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Below are some of the most common ways to include cookie-events.
4545
**CDN Link**
4646

4747
```html
48-
<script src="https://cdn.jsdelivr.net/npm/cookie-events@1.0.0/lib/cookie.min.js"></script>
48+
<script src="https://cdn.jsdelivr.net/npm/cookie-events@1.1.0/lib/cookie.min.js"></script>
4949
```
5050

5151
You can add the script manually to your project:

lib/cookie.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,27 @@ Cookie.prototype = {
280280
for(cookie of cookies) {
281281
this.remove(cookie.name, cookie.path, cookie.domain);
282282
}
283+
},
284+
285+
/**
286+
* Converts all available cookies into a FormData object.
287+
*
288+
* This method is useful when you want to send cookies as form-encoded data
289+
* (e.g., in an AJAX request using fetch or XMLHttpRequest).
290+
*
291+
* @returns {FormData} A FormData object containing all cookies as key-value pairs.
292+
*/
293+
createFormData: function() {
294+
var key, value,
295+
fd = new FormData(),
296+
entries = this.parse();
297+
298+
for(value of entries) {
299+
key = value.shift();
300+
fd.append(key, value.join(""));
301+
}
302+
303+
return fd;
283304
}
284305
};
285306

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cookie-events",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "Lightweight, event-driven cookie manager for parsing, setting, and tracking cookies with ease.",
55
"main": "./lib/cookie.js",
66
"scripts": {

0 commit comments

Comments
 (0)