forked from Yomguithereal/mnemonist
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: LRUCache/LRUMap family -- inspect and toString improvements
* LRUCache and family .inspect limits its output -- showing the youngest items, and ellipsis, and the oldest item. Options allow dumping the raw object or controlling the size of output (and the number of items a console.log will mindlessly iterate over). * LRUCache and family all have inspect wired up to the magic 'nodejs.util.inspect.custom' symbol property that drives console.log output * LRUCache and family all have a summaryString method returning eg 'LRUCache[8/200]' for a cache with size 8 and capacity 200, wired to the magic Symbol.toStringTag property that drives string interpolation (partially addresses Yomguithereal#129).
- Loading branch information
Showing
6 changed files
with
223 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
function snipToLast(iterator, proxy, {maxToDump = 20, size = Infinity, last = []}) { | ||
var step; | ||
|
||
var ii = 0; | ||
while ((step = iterator.next(), !step.done)) { | ||
if (ii >= maxToDump - 2) { | ||
if (ii >= size - 1) { | ||
proxy.set(step.value[0], step.value[1]); | ||
} else if (ii === size - 2) { | ||
proxy.set(step.value[0], step.value[1]); | ||
proxy.set(last[0], last[1]); | ||
} else { | ||
proxy.set('_...', size - ii - 1); | ||
proxy.set(last[0], last[1]); | ||
} | ||
break; | ||
} | ||
proxy.set(step.value[0], step.value[1]); | ||
ii += 1; | ||
} | ||
} | ||
|
||
module.exports.snipToLast = snipToLast; |