Skip to content

Commit 25ced9c

Browse files
Add the "Cookies" API without changing the jquery dependency requirement
Adjust the tests to use the new API. The new API behaves exactly how "$.cookie" does. I opted for "Cookies" instead of "Cookie" because it would be semantically correct to call "Cookies.get()" to get all cookies instead of "Cookie.get()", otherwise it would mean bloating the codebase by doing something like "Cookie.getAll()", "Cookie.getCookies()" or something like that. +31 bytes gzipped
1 parent bd1b173 commit 25ced9c

File tree

4 files changed

+111
-100
lines changed

4 files changed

+111
-100
lines changed

.jshintrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@
88
"nonbsp": true,
99
"trailing": true,
1010
"undef": true,
11-
"unused": true
11+
"unused": true,
12+
"globals": {
13+
"Cookies": true
14+
}
1215
}

src/jquery.cookie.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
module.exports = factory(require('jquery'));
1515
} else {
1616
// Browser globals
17-
factory(jQuery);
17+
window.Cookies = factory(jQuery);
1818
}
1919
}(function ($) {
2020

@@ -111,4 +111,9 @@
111111
return !$.cookie(key);
112112
};
113113

114+
$.cookie.get = $.cookie;
115+
$.cookie.set = $.cookie;
116+
$.cookie.remove = $.removeCookie;
117+
118+
return $.cookie;
114119
}));

test/malformed_cookie.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<script>
88
try {
99
Object.defineProperty(document, "cookie", { get: function() { return "first=one; ; second=two"; } });
10-
window.testValue = $.cookie("second");
10+
window.testValue = Cookies.get("second");
1111
window.ok = true;
1212
} catch (er) {
1313
}

0 commit comments

Comments
 (0)