1
1
'use strict' ;
2
2
3
+ import { CookieOptions } from './types' ;
4
+
3
5
/**
4
6
* Module dependencies.
5
7
*/
@@ -17,21 +19,15 @@ var topDomain = require('@segment/top-domain');
17
19
* @param {Object } options
18
20
*/
19
21
20
- function Cookie ( options ) {
22
+ function Cookie ( options ?: CookieOptions ) {
21
23
this . options ( options ) ;
22
24
}
23
25
24
26
/**
25
27
* Get or set the cookie options.
26
- *
27
- * @param {Object } options
28
- * @field {Number} maxage (1 year)
29
- * @field {String} domain
30
- * @field {String} path
31
- * @field {Boolean} secure
32
28
*/
33
29
34
- Cookie . prototype . options = function ( options ) {
30
+ Cookie . prototype . options = function ( options : CookieOptions ) {
35
31
if ( arguments . length === 0 ) return this . _options ;
36
32
37
33
options = options || { } ;
@@ -64,13 +60,9 @@ Cookie.prototype.options = function(options) {
64
60
65
61
/**
66
62
* Set a `key` and `value` in our cookie.
67
- *
68
- * @param {String } key
69
- * @param {Object } value
70
- * @return {Boolean } saved
71
63
*/
72
64
73
- Cookie . prototype . set = function ( key , value ) {
65
+ Cookie . prototype . set = function ( key : string , value ?: object | string ) : boolean {
74
66
try {
75
67
value = window . JSON . stringify ( value ) ;
76
68
cookie ( key , value === 'null' ? null : value , clone ( this . _options ) ) ;
@@ -82,12 +74,9 @@ Cookie.prototype.set = function(key, value) {
82
74
83
75
/**
84
76
* Get a value from our cookie by `key`.
85
- *
86
- * @param {String } key
87
- * @return {Object } value
88
77
*/
89
78
90
- Cookie . prototype . get = function ( key ) {
79
+ Cookie . prototype . get = function ( key : string ) : object {
91
80
try {
92
81
var value = cookie ( key ) ;
93
82
value = value ? window . JSON . parse ( value ) : null ;
@@ -99,12 +88,9 @@ Cookie.prototype.get = function(key) {
99
88
100
89
/**
101
90
* Remove a value from our cookie by `key`.
102
- *
103
- * @param {String } key
104
- * @return {Boolean } removed
105
91
*/
106
92
107
- Cookie . prototype . remove = function ( key ) {
93
+ Cookie . prototype . remove = function ( key : string ) : boolean {
108
94
try {
109
95
cookie ( key , null , clone ( this . _options ) ) ;
110
96
return true ;
0 commit comments