js-lru icon indicating copy to clipboard operation
js-lru copied to clipboard

No constructor for taking the json output format as input

Open Tuupertunut opened this issue 7 years ago • 3 comments

The toJSON() function returns contents of the cache as an array of objects, with key and value fields. However there is no way to input contents in the same format.

Tuupertunut avatar Apr 13 '18 01:04 Tuupertunut

You can do

LRUMap.prototype.fromJSON = function(cache) {
  return new LRUMap(cache.map(it => {
    return [it.key, it.value]
  }))
}

revskill10 avatar Mar 01 '19 14:03 revskill10

Happy to accept a PR for a function like that.

  1. Make it a "static" (non-prototype) function on LRUMap
  2. Add a test for it

rsms avatar Oct 22 '20 17:10 rsms

@rsms created PR #41 to address this issue.

tomershvueli avatar Jul 19 '21 13:07 tomershvueli