Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ name: Tests
on: [push, pull_request]

jobs:

tests:
strategy:
matrix:
# npm will not run under 10.x or earlier and so they cannot be tested
node-version:
- 12.x
- 13.x
- 14.x
- 15.x
- 16.x
- 18.x
- latest

runs-on: ubuntu-latest

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.40.0

* Adding `#isEqual` to Set helpers (@mrflip). (provisional)

## 0.39.2

* Fixing typings of low-level structure consuming methods (@jerome-benoit).
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export {default as KDTree} from './kd-tree';
export {default as LinkedList} from './linked-list';
export {default as LRUCache} from './lru-cache';
export {default as LRUCacheWithDelete} from './lru-cache-with-delete';
export {default as LRUCacheWithExpiry} from './lru-cache-with-expiry';
export {default as LRUMap} from './lru-map';
export {default as LRUMapWithDelete} from './lru-map-with-delete';
export {default as MultiMap} from './multi-map';
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module.exports = {
LinkedList: require('./linked-list.js'),
LRUCache: require('./lru-cache.js'),
LRUCacheWithDelete: require('./lru-cache-with-delete.js'),
LRUCacheWithExpiry: require('./lru-cache-with-expiry.js'),
LRUMap: require('./lru-map.js'),
LRUMapWithDelete: require('./lru-map-with-delete.js'),
MultiMap: require('./multi-map.js'),
Expand Down
15 changes: 14 additions & 1 deletion lru-cache-with-delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,21 @@ function LRUCacheWithDelete(Keys, Values, capacity) {

for (var k in LRUCache.prototype)
LRUCacheWithDelete.prototype[k] = LRUCache.prototype[k];
if (typeof Symbol !== 'undefined')

/**
* If possible, attaching the
* * #.entries method to Symbol.iterator (allowing `for (const foo of cache) { ... }`)
* * the summaryString method to Symbol.toStringTag (allowing `\`${cache}\`` to work)
* * the inspect method to Symbol.for('nodejs.util.inspect.custom') (making `console.log(cache)` liveable)
*/
if (typeof Symbol !== 'undefined') {
LRUCacheWithDelete.prototype[Symbol.iterator] = LRUCache.prototype[Symbol.iterator];
Object.defineProperty(LRUCacheWithDelete.prototype, Symbol.toStringTag, {
get: function () { return `${this.constructor.name}:${this.size}/${this.capacity}`; },
});
LRUCacheWithDelete.prototype[Symbol.for('nodejs.util.inspect.custom')] = LRUCache.prototype.inspect;
}
Object.defineProperty(LRUCacheWithDelete.prototype, 'summary', Object.getOwnPropertyDescriptor(LRUCache.prototype, 'summary'));

/**
* Method used to clear the structure.
Expand Down
24 changes: 24 additions & 0 deletions lru-cache-with-expiry.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Mnemonist LRUCacheWithExpiry Typings
* =====================================
*/
import LRUCacheWithDelete from './lru-cache-with-delete';

export interface Logger {
trace(message: string, story: any): void
debug(message: string, story: any): void
info(message: string, story: any): void
warn(message: string, story: any): void
error(message: string, story: any): void
}

export default class LRUCacheWithExpiry<K, V> extends LRUCacheWithDelete<K, V> {

expire(): void;

monitor(interval: number, options: {
logger: Logger,
didError: (err: Error, inst: LRUCacheWithExpiry<K, V>) => boolean,
didExpire: (inst: LRUCacheWithExpiry<K, V>, begT: number) => void,
}): void;
}
Loading