1
- /*! proxyStorage@v2.0.2 . Jherax 2017. Visit https://github.com/jherax/proxy-storage */
1
+ /*! proxyStorage@v2.1.0 . Jherax 2017. Visit https://github.com/jherax/proxy-storage */
2
2
( function webpackUniversalModuleDefinition ( root , factory ) {
3
3
if ( typeof exports === 'object' && typeof module === 'object' )
4
4
module . exports = factory ( ) ;
@@ -88,7 +88,7 @@ Object.defineProperty(exports, "__esModule", {
88
88
value : true
89
89
} ) ;
90
90
exports . isObject = isObject ;
91
- exports . setTimestamp = setTimestamp ;
91
+ exports . alterDate = alterDate ;
92
92
exports . setProperty = setProperty ;
93
93
exports . checkEmpty = checkEmpty ;
94
94
/**
@@ -102,21 +102,25 @@ function isObject(value) {
102
102
}
103
103
104
104
/**
105
- * Allows add or subtract timestamps to the current date or to a specific date.
105
+ * Adds or subtracts date portions to the given date and returns the new date.
106
106
*
107
- * @param {object } options: It contains the timestamps to add or remove to the date, and have the following properties:
108
- * - {Date} date: if provided, the timestamps will affect this date, otherwise a new current date will be used.
107
+ * @see https://gist.github.com/jherax/bbc43e479a492cc9cbfc7ccc20c53cd2
108
+ *
109
+ * @param {object } options: It contains the date parts to add or remove, and can have the following properties:
110
+ * - {Date} date: if provided, this date will be affected, otherwise the current date will be used.
111
+ * - {number} minutes: minutes to add/subtract
109
112
* - {number} hours: hours to add/subtract
110
113
* - {number} days: days to add/subtract
111
114
* - {number} months: months to add/subtract
112
115
* - {number} years: years to add/subtract
113
116
* @return {Date }
114
117
*/
115
- function setTimestamp ( ) {
118
+ function alterDate ( ) {
116
119
var options = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : { } ;
117
120
118
121
var opt = Object . assign ( { } , options ) ;
119
122
var d = opt . date instanceof Date ? opt . date : new Date ( ) ;
123
+ if ( + opt . minutes ) d . setMinutes ( d . getMinutes ( ) + opt . minutes ) ;
120
124
if ( + opt . hours ) d . setHours ( d . getHours ( ) + opt . hours ) ;
121
125
if ( + opt . days ) d . setDate ( d . getDate ( ) + opt . days ) ;
122
126
if ( + opt . months ) d . setMonth ( d . getMonth ( ) + opt . months ) ;
@@ -194,6 +198,8 @@ exports.proxy = exports.webStorageSettings = exports.default = undefined;
194
198
195
199
var _createClass = function ( ) { function defineProperties ( target , props ) { for ( var i = 0 ; i < props . length ; i ++ ) { var descriptor = props [ i ] ; descriptor . enumerable = descriptor . enumerable || false ; descriptor . configurable = true ; if ( "value" in descriptor ) descriptor . writable = true ; Object . defineProperty ( target , descriptor . key , descriptor ) ; } } return function ( Constructor , protoProps , staticProps ) { if ( protoProps ) defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) defineProperties ( Constructor , staticProps ) ; return Constructor ; } ; } ( ) ;
196
200
201
+ var _typeof = typeof Symbol === "function" && typeof Symbol . iterator === "symbol" ? function ( obj ) { return typeof obj ; } : function ( obj ) { return obj && typeof Symbol === "function" && obj . constructor === Symbol && obj !== Symbol . prototype ? "symbol" : typeof obj ; } ;
202
+
197
203
var _proxyMechanism = __webpack_require__ ( 5 ) ;
198
204
199
205
var _utils = __webpack_require__ ( 0 ) ;
@@ -241,6 +247,10 @@ function executeInterceptors(command) {
241
247
242
248
var key = args . shift ( ) ;
243
249
var value = args . shift ( ) ;
250
+ if ( value && ( typeof value === 'undefined' ? 'undefined' : _typeof ( value ) ) === 'object' ) {
251
+ // clone the object to prevent mutations
252
+ value = JSON . parse ( JSON . stringify ( value ) ) ;
253
+ }
244
254
return _interceptors [ command ] . reduce ( function ( val , action ) {
245
255
var transformed = action . apply ( undefined , [ key , val ] . concat ( args ) ) ;
246
256
if ( transformed === undefined ) return val ;
@@ -387,7 +397,7 @@ var WebStorage = function () {
387
397
value : function getItem ( key ) {
388
398
( 0 , _utils . checkEmpty ) ( key ) ;
389
399
var value = _proxyMechanism . proxy [ this . __storage__ ] . getItem ( key ) ;
390
- if ( value === undefined ) {
400
+ if ( value == null ) {
391
401
delete this [ key ] ;
392
402
value = null ;
393
403
} else {
@@ -518,14 +528,14 @@ var $cookie = {
518
528
*
519
529
* Builds the expiration part for the cookie.
520
530
*
521
- * @see utils.setTimestamp (options)
531
+ * @see utils.alterDate (options)
522
532
*
523
533
* @param {Date|object } date: the expiration date
524
534
* @return {string }
525
535
*/
526
536
/* eslint-disable no-invalid-this */
527
537
function buildExpirationString ( date ) {
528
- var expires = date instanceof Date ? ( 0 , _utils . setTimestamp ) ( { date : date } ) : ( 0 , _utils . setTimestamp ) ( date ) ;
538
+ var expires = date instanceof Date ? ( 0 , _utils . alterDate ) ( { date : date } ) : ( 0 , _utils . alterDate ) ( date ) ;
529
539
return '; expires=' + expires . toUTCString ( ) ;
530
540
}
531
541
@@ -554,13 +564,24 @@ function findCookie(cookie) {
554
564
function cookieStorage ( ) {
555
565
var api = {
556
566
setItem : function setItem ( key , value , options ) {
557
- var expires = '' ;
567
+ var domain = '' ,
568
+ expires = '' ;
558
569
options = Object . assign ( { path : '/' } , options ) ;
559
570
if ( ( 0 , _utils . isObject ) ( options . expires ) || options . expires instanceof Date ) {
560
571
expires = buildExpirationString ( options . expires ) ;
561
572
}
562
- var cookie = key + '=' + encodeURIComponent ( value ) + expires + '; path=' + options . path ;
573
+ // http://stackoverflow.com/a/5671466/2247494
574
+ if ( typeof options . domain === 'string' ) {
575
+ domain = '; domain=' + options . domain . trim ( ) ;
576
+ }
577
+ var cookie = key + '=' + encodeURIComponent ( value ) + expires + domain + '; path=' + options . path ;
578
+ // TODO: add metadata to store options for the cookie
579
+ // TODO: remove cookies are failing when domain or path were set
580
+ // TODO: prevent adding cookies when the domain or path are not valid
581
+ // TODO: remove expired cookies through getItem or setTimeout for expires
582
+ // console.log('before set', $cookie.get()); // eslint-disable-line
563
583
$cookie . set ( cookie ) ;
584
+ // console.log('after set', $cookie.get()); // eslint-disable-line
564
585
} ,
565
586
getItem : function getItem ( key ) {
566
587
var value = null ;
@@ -777,8 +798,6 @@ var _isAvailable = __webpack_require__(1);
777
798
778
799
function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { default : obj } ; }
779
800
780
- // eslint-disable-line
781
-
782
801
// If you want to support all ES6 features, uncomment the next line
783
802
// import 'babel-polyfill';
784
803
0 commit comments