mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 14:57:10 +00:00
jscookie: small changes to make it more correct. Might break existing code?
This commit is contained in:
Vendored
+4
-3
@@ -79,7 +79,7 @@ declare namespace Cookies {
|
||||
* or SDK. Note: The noConflict method is not necessary when using
|
||||
* AMD or CommonJS, thus it is not exposed in those environments.
|
||||
*/
|
||||
noConflict(): CookiesStatic;
|
||||
noConflict?(): CookiesStatic;
|
||||
|
||||
/**
|
||||
* Create a new instance of the api that overrides the default
|
||||
@@ -88,10 +88,11 @@ declare namespace Cookies {
|
||||
* will run the converter first for each cookie. The returned
|
||||
* string will be used as the cookie value.
|
||||
*/
|
||||
withConverter(converter: CookieConverter | { write: CookieConverter; read: CookieConverter; }): CookiesStatic;
|
||||
withConverter(converter: CookieReadConverter | { write: CookieWriteConverter; read: CookieReadConverter; }): CookiesStatic;
|
||||
}
|
||||
|
||||
type CookieConverter = (value: string, name: string) => string;
|
||||
type CookieWriteConverter = (value: string | object, name: string) => string;
|
||||
type CookieReadConverter = (value: string, name: string) => string;
|
||||
}
|
||||
|
||||
declare const Cookies: Cookies.CookiesStatic;
|
||||
|
||||
@@ -19,8 +19,7 @@ Cookies.get();
|
||||
Cookies.remove('name');
|
||||
Cookies.remove('name', { path: '' });
|
||||
|
||||
const Cookies2 = Cookies.noConflict();
|
||||
Cookies2; // $ExpectType CookiesStatic
|
||||
const Cookies2: Cookies.CookiesStatic = (Cookies.noConflict as () => Cookies.CookiesStatic)();
|
||||
|
||||
Cookies.set('name', { foo: 'bar' });
|
||||
|
||||
@@ -41,11 +40,11 @@ Cookies.defaults.path = '';
|
||||
delete Cookies.defaults.path;
|
||||
|
||||
const PHPCookies = Cookies.withConverter({
|
||||
write(value) {
|
||||
return encodeURIComponent(value)
|
||||
write(value: string | object) {
|
||||
return encodeURIComponent(value as string)
|
||||
.replace(/%(23|24|26|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent);
|
||||
},
|
||||
read(value) {
|
||||
read(value: string) {
|
||||
return value
|
||||
.replace(/\+/g, ' ')
|
||||
.replace(/(%[0-9A-Z]{2})+/g, decodeURIComponent);
|
||||
|
||||
Reference in New Issue
Block a user