@@ -14,11 +14,11 @@ var Yallist = require('yallist');
1414var hasSymbol = typeof Symbol === 'function' ;
1515var makeSymbol ;
1616if ( hasSymbol ) {
17- makeSymbol = function ( key ) {
17+ makeSymbol = function ( key ) {
1818 return Symbol ( key ) ;
1919 } ;
2020} else {
21- makeSymbol = function ( key ) {
21+ makeSymbol = function ( key ) {
2222 return '_' + key ;
2323 } ;
2424}
@@ -79,80 +79,80 @@ function LRUCache(options) {
7979
8080// resize the cache when the max changes.
8181Object . defineProperty ( LRUCache . prototype , 'max' , {
82- set : function ( mL ) {
82+ set : function ( mL ) {
8383 if ( ! mL || ! ( typeof mL === 'number' ) || mL <= 0 ) {
8484 mL = Infinity ;
8585 }
8686 this [ MAX ] = mL ;
8787 trim ( this ) ;
8888 } ,
89- get : function ( ) {
89+ get : function ( ) {
9090 return this [ MAX ] ;
9191 } ,
9292 enumerable : true ,
9393} ) ;
9494
9595Object . defineProperty ( LRUCache . prototype , 'allowStale' , {
96- set : function ( allowStale ) {
96+ set : function ( allowStale ) {
9797 this [ ALLOW_STALE ] = ! ! allowStale ;
9898 } ,
99- get : function ( ) {
99+ get : function ( ) {
100100 return this [ ALLOW_STALE ] ;
101101 } ,
102102 enumerable : true ,
103103} ) ;
104104
105105Object . defineProperty ( LRUCache . prototype , 'maxAge' , {
106- set : function ( mA ) {
106+ set : function ( mA ) {
107107 if ( ! mA || ! ( typeof mA === 'number' ) || mA < 0 ) {
108108 mA = 0 ;
109109 }
110110 this [ MAX_AGE ] = mA ;
111111 trim ( this ) ;
112112 } ,
113- get : function ( ) {
113+ get : function ( ) {
114114 return this [ MAX_AGE ] ;
115115 } ,
116116 enumerable : true ,
117117} ) ;
118118
119119// resize the cache when the lengthCalculator changes.
120120Object . defineProperty ( LRUCache . prototype , 'lengthCalculator' , {
121- set : function ( lC ) {
121+ set : function ( lC ) {
122122 if ( typeof lC !== 'function' ) {
123123 lC = naiveLength ;
124124 }
125125 if ( lC !== this [ LENGTH_CALCULATOR ] ) {
126126 this [ LENGTH_CALCULATOR ] = lC ;
127127 this [ LENGTH ] = 0 ;
128- this [ LRU_LIST ] . forEach ( function ( hit ) {
128+ this [ LRU_LIST ] . forEach ( function ( hit ) {
129129 hit . length = this [ LENGTH_CALCULATOR ] ( hit . value , hit . key ) ;
130130 this [ LENGTH ] += hit . length ;
131131 } , this ) ;
132132 }
133133 trim ( this ) ;
134134 } ,
135- get : function ( ) {
135+ get : function ( ) {
136136 return this [ LENGTH_CALCULATOR ] ;
137137 } ,
138138 enumerable : true ,
139139} ) ;
140140
141141Object . defineProperty ( LRUCache . prototype , 'length' , {
142- get : function ( ) {
142+ get : function ( ) {
143143 return this [ LENGTH ] ;
144144 } ,
145145 enumerable : true ,
146146} ) ;
147147
148148Object . defineProperty ( LRUCache . prototype , 'itemCount' , {
149- get : function ( ) {
149+ get : function ( ) {
150150 return this [ LRU_LIST ] . length ;
151151 } ,
152152 enumerable : true ,
153153} ) ;
154154
155- LRUCache . prototype . rforEach = function ( fn , thisp ) {
155+ LRUCache . prototype . rforEach = function ( fn , thisp ) {
156156 thisp = thisp || this ;
157157 for ( var walker = this [ LRU_LIST ] . tail ; walker !== null ; ) {
158158 var prev = walker . prev ;
@@ -174,7 +174,7 @@ function forEachStep(self, fn, node, thisp) {
174174 }
175175}
176176
177- LRUCache . prototype . forEach = function ( fn , thisp ) {
177+ LRUCache . prototype . forEach = function ( fn , thisp ) {
178178 thisp = thisp || this ;
179179 for ( var walker = this [ LRU_LIST ] . head ; walker !== null ; ) {
180180 var next = walker . next ;
@@ -183,21 +183,21 @@ LRUCache.prototype.forEach = function(fn, thisp) {
183183 }
184184} ;
185185
186- LRUCache . prototype . keys = function ( ) {
187- return this [ LRU_LIST ] . toArray ( ) . map ( function ( k ) {
186+ LRUCache . prototype . keys = function ( ) {
187+ return this [ LRU_LIST ] . toArray ( ) . map ( function ( k ) {
188188 return k . key ;
189189 } , this ) ;
190190} ;
191191
192- LRUCache . prototype . values = function ( ) {
193- return this [ LRU_LIST ] . toArray ( ) . map ( function ( k ) {
192+ LRUCache . prototype . values = function ( ) {
193+ return this [ LRU_LIST ] . toArray ( ) . map ( function ( k ) {
194194 return k . value ;
195195 } , this ) ;
196196} ;
197197
198- LRUCache . prototype . reset = function ( ) {
198+ LRUCache . prototype . reset = function ( ) {
199199 if ( this [ DISPOSE ] && this [ LRU_LIST ] && this [ LRU_LIST ] . length ) {
200- this [ LRU_LIST ] . forEach ( function ( hit ) {
200+ this [ LRU_LIST ] . forEach ( function ( hit ) {
201201 this [ DISPOSE ] ( hit . key , hit . value ) ;
202202 } , this ) ;
203203 }
@@ -207,8 +207,8 @@ LRUCache.prototype.reset = function() {
207207 this [ LENGTH ] = 0 ; // length of items in the list
208208} ;
209209
210- LRUCache . prototype . dump = function ( ) {
211- return this [ LRU_LIST ] . map ( function ( hit ) {
210+ LRUCache . prototype . dump = function ( ) {
211+ return this [ LRU_LIST ] . map ( function ( hit ) {
212212 if ( ! isStale ( this , hit ) ) {
213213 return {
214214 k : hit . key ,
@@ -218,16 +218,16 @@ LRUCache.prototype.dump = function() {
218218 }
219219 } , this )
220220 . toArray ( )
221- . filter ( function ( h ) {
221+ . filter ( function ( h ) {
222222 return h ;
223223 } ) ;
224224} ;
225225
226- LRUCache . prototype . dumpLru = function ( ) {
226+ LRUCache . prototype . dumpLru = function ( ) {
227227 return this [ LRU_LIST ] ;
228228} ;
229229
230- LRUCache . prototype . inspect = function ( n , opts ) {
230+ LRUCache . prototype . inspect = function ( n , opts ) {
231231 var str = 'LRUCache {' ;
232232 var extras = false ;
233233
@@ -265,7 +265,7 @@ LRUCache.prototype.inspect = function(n, opts) {
265265 }
266266
267267 var didFirst = false ;
268- this [ LRU_LIST ] . forEach ( function ( item ) {
268+ this [ LRU_LIST ] . forEach ( function ( item ) {
269269 if ( didFirst ) {
270270 str += ',\n ' ;
271271 } else {
@@ -275,10 +275,7 @@ LRUCache.prototype.inspect = function(n, opts) {
275275 didFirst = true ;
276276 str += '\n ' ;
277277 }
278- var key = util
279- . inspect ( item . key )
280- . split ( '\n' )
281- . join ( '\n ' ) ;
278+ var key = util . inspect ( item . key ) . split ( '\n' ) . join ( '\n ' ) ;
282279 var val = { value : item . value } ;
283280 if ( item . maxAge !== maxAge ) {
284281 val . maxAge = item . maxAge ;
@@ -290,10 +287,7 @@ LRUCache.prototype.inspect = function(n, opts) {
290287 val . stale = true ;
291288 }
292289
293- val = util
294- . inspect ( val , opts )
295- . split ( '\n' )
296- . join ( '\n ' ) ;
290+ val = util . inspect ( val , opts ) . split ( '\n' ) . join ( '\n ' ) ;
297291 str += key + ' => ' + val ;
298292 } ) ;
299293
@@ -305,7 +299,7 @@ LRUCache.prototype.inspect = function(n, opts) {
305299 return str ;
306300} ;
307301
308- LRUCache . prototype . set = function ( key , value , maxAge ) {
302+ LRUCache . prototype . set = function ( key , value , maxAge ) {
309303 maxAge = maxAge || this [ MAX_AGE ] ;
310304
311305 var now = maxAge ? Date . now ( ) : 0 ;
@@ -355,7 +349,7 @@ LRUCache.prototype.set = function(key, value, maxAge) {
355349 return true ;
356350} ;
357351
358- LRUCache . prototype . has = function ( key ) {
352+ LRUCache . prototype . has = function ( key ) {
359353 if ( ! this [ CACHE ] . has ( key ) ) return false ;
360354 var hit = this [ CACHE ] . get ( key ) . value ;
361355 if ( isStale ( this , hit ) ) {
@@ -364,26 +358,26 @@ LRUCache.prototype.has = function(key) {
364358 return true ;
365359} ;
366360
367- LRUCache . prototype . get = function ( key ) {
361+ LRUCache . prototype . get = function ( key ) {
368362 return get ( this , key , true ) ;
369363} ;
370364
371- LRUCache . prototype . peek = function ( key ) {
365+ LRUCache . prototype . peek = function ( key ) {
372366 return get ( this , key , false ) ;
373367} ;
374368
375- LRUCache . prototype . pop = function ( ) {
369+ LRUCache . prototype . pop = function ( ) {
376370 var node = this [ LRU_LIST ] . tail ;
377371 if ( ! node ) return null ;
378372 del ( this , node ) ;
379373 return node . value ;
380374} ;
381375
382- LRUCache . prototype . del = function ( key ) {
376+ LRUCache . prototype . del = function ( key ) {
383377 del ( this , this [ CACHE ] . get ( key ) ) ;
384378} ;
385379
386- LRUCache . prototype . load = function ( arr ) {
380+ LRUCache . prototype . load = function ( arr ) {
387381 // reset the cache
388382 this . reset ( ) ;
389383
@@ -405,9 +399,9 @@ LRUCache.prototype.load = function(arr) {
405399 }
406400} ;
407401
408- LRUCache . prototype . prune = function ( ) {
402+ LRUCache . prototype . prune = function ( ) {
409403 var self = this ;
410- this [ CACHE ] . forEach ( function ( value , key ) {
404+ this [ CACHE ] . forEach ( function ( value , key ) {
411405 get ( self , key , false ) ;
412406 } ) ;
413407} ;
0 commit comments