Skip to content

Commit

Permalink
Refactoring keys() to return an array first to last
Browse files Browse the repository at this point in the history
  • Loading branch information
avoidwork committed Oct 29, 2023
1 parent 8fb5926 commit 3643062
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 21 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -153,7 +153,7 @@ cache.delete("myKey");

Returns an `Array` cache items

param {Array} keys (Optional) Cache item keys to get
param {Array} keys (Optional) Cache item keys to get, defaults to `this.keys()` if not provided
return {Object} LRU instance

**Example**
Expand Down Expand Up @@ -214,7 +214,7 @@ cache.has('myKey');

### keys

Returns an `Array` of cache item keys.
Returns an `Array` of cache item keys (`first` to `last`)

return {Array} Array of keys

Expand Down
12 changes: 10 additions & 2 deletions dist/tiny-lru.cjs
Expand Up @@ -3,7 +3,7 @@
*
* @copyright 2023 Jason Mulligan <jason.mulligan@avoidwork.com>
* @license BSD-3-Clause
* @version 11.2.3
* @version 11.2.4
*/
'use strict';

Expand Down Expand Up @@ -108,7 +108,15 @@ class LRU {
}

keys () {
return Object.keys(this.items);
const result = [];
let x = this.first;

do {
result.push(x.key);
x = x.next;
} while (x !== null);

return result;
}

set (key, value, bypass = false, resetTtl = this.resetTtl) {
Expand Down
12 changes: 10 additions & 2 deletions dist/tiny-lru.js
Expand Up @@ -3,7 +3,7 @@
*
* @copyright 2023 Jason Mulligan <jason.mulligan@avoidwork.com>
* @license BSD-3-Clause
* @version 11.2.3
* @version 11.2.4
*/
class LRU {
constructor (max = 0, ttl = 0, resetTtl = false) {
Expand Down Expand Up @@ -106,7 +106,15 @@ class LRU {
}

keys () {
return Object.keys(this.items);
const result = [];
let x = this.first;

do {
result.push(x.key);
x = x.next;
} while (x !== null);

return result;
}

set (key, value, bypass = false, resetTtl = this.resetTtl) {
Expand Down
4 changes: 2 additions & 2 deletions dist/tiny-lru.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/tiny-lru.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions dist/tiny-lru.umd.js
Expand Up @@ -3,7 +3,7 @@
*
* @copyright 2023 Jason Mulligan <jason.mulligan@avoidwork.com>
* @license BSD-3-Clause
* @version 11.2.3
* @version 11.2.4
*/
(function(g,f){typeof exports==='object'&&typeof module!=='undefined'?f(exports):typeof define==='function'&&define.amd?define(['exports'],f):(g=typeof globalThis!=='undefined'?globalThis:g||self,f(g.lru={}));})(this,(function(exports){'use strict';class LRU {
constructor (max = 0, ttl = 0, resetTtl = false) {
Expand Down Expand Up @@ -106,7 +106,15 @@
}

keys () {
return Object.keys(this.items);
const result = [];
let x = this.first;

do {
result.push(x.key);
x = x.next;
} while (x !== null);

return result;
}

set (key, value, bypass = false, resetTtl = this.resetTtl) {
Expand Down

0 comments on commit 3643062

Please sign in to comment.