1- 'use strict' ;
21var angularLocalStorage = angular . module ( 'LocalStorageModule' , [ ] ) ;
32
43angularLocalStorage . provider ( 'localStorageService' , function ( ) {
@@ -114,10 +113,10 @@ angularLocalStorage.provider('localStorageService', function() {
114113 // Example use: localStorageService.add('library','angular');
115114 var addToLocalStorage = function ( key , value ) {
116115 // Let's convert undefined values to null to get the value consistent
117- if ( typeof value === "undefined" ) {
116+ if ( isUndefined ( value ) ) {
118117 value = null ;
119- } else if ( angular . isObject ( value ) || angular . isArray ( value ) || angular . isNumber ( + value || value ) ) {
120- value = angular . toJson ( value ) ;
118+ } else if ( isObject ( value ) || isArray ( value ) || isNumber ( + value || value ) ) {
119+ value = toJson ( value ) ;
121120 }
122121
123122 // If this browser does not support local storage use cookies
@@ -133,8 +132,8 @@ angularLocalStorage.provider('localStorageService', function() {
133132 }
134133
135134 try {
136- if ( angular . isObject ( value ) || angular . isArray ( value ) ) {
137- value = angular . toJson ( value ) ;
135+ if ( isObject ( value ) || isArray ( value ) ) {
136+ value = toJson ( value ) ;
138137 }
139138 if ( webStorage ) { webStorage . setItem ( deriveQualifiedKey ( key ) , value ) } ;
140139 if ( notify . setItem ) {
@@ -167,18 +166,12 @@ angularLocalStorage.provider('localStorageService', function() {
167166 }
168167
169168 if ( item . charAt ( 0 ) === "{" || item . charAt ( 0 ) === "[" || isStringNumber ( item ) ) {
170- return angular . fromJson ( item ) ;
169+ return fromJson ( item ) ;
171170 }
172171
173172 return item ;
174173 } ;
175174
176- // Test if string is only contains numbers
177- // e.g '1' => true, "'1'" => true
178- function isStringNumber ( num ) {
179- return / ^ - ? \d + \. ? \d * $ / . test ( num . replace ( / [ " ' ] / g, '' ) ) ;
180- }
181-
182175 // Remove an item from local storage
183176 // Example use: localStorageService.remove('library'); // removes the key/value pair of library='angular'
184177 var removeFromLocalStorage = function ( key ) {
@@ -282,10 +275,10 @@ angularLocalStorage.provider('localStorageService', function() {
282275 // Example use: localStorageService.cookie.add('library','angular');
283276 var addToCookies = function ( key , value ) {
284277
285- if ( typeof value === "undefined" ) {
278+ if ( isUndefined ( value ) ) {
286279 return false ;
287- } else if ( angular . isArray ( value ) || angular . isObject ( value ) ) {
288- value = angular . toJson ( value ) ;
280+ } else if ( isArray ( value ) || isObject ( value ) ) {
281+ value = toJson ( value ) ;
289282 }
290283
291284 if ( ! browserSupportsCookies ( ) ) {
@@ -338,8 +331,8 @@ angularLocalStorage.provider('localStorageService', function() {
338331 if ( thisCookie . indexOf ( deriveQualifiedKey ( key ) + '=' ) === 0 ) {
339332 var storedValues = decodeURIComponent ( thisCookie . substring ( prefix . length + key . length + 1 , thisCookie . length ) )
340333 try {
341- var obj = JSON . parse ( storedValues )
342- return angular . fromJson ( obj )
334+ var obj = JSON . parse ( storedValues ) ;
335+ return fromJson ( obj )
343336 } catch ( e ) {
344337 return storedValues
345338 }
@@ -379,10 +372,10 @@ angularLocalStorage.provider('localStorageService', function() {
379372
380373 var value = getFromLocalStorage ( lsKey ) ;
381374
382- if ( value === null && angular . isDefined ( def ) ) {
375+ if ( value === null && isDefined ( def ) ) {
383376 value = def ;
384- } else if ( angular . isObject ( value ) && angular . isObject ( def ) ) {
385- value = angular . extend ( def , value ) ;
377+ } else if ( isObject ( value ) && isObject ( def ) ) {
378+ value = extend ( def , value ) ;
386379 }
387380
388381 $parse ( scopeKey ) . assign ( scope , value ) ;
0 commit comments