create-memo
Advanced tools
Comparing version 0.0.2 to 0.0.3
112
index.es.js
@@ -7,38 +7,9 @@ function _inheritsLoose(subClass, superClass) { | ||
var AbstractMemoCache = function AbstractMemoCache() {}; | ||
var LinkedMapNode = function LinkedMapNode(key, value) { | ||
this.prev = void 0; | ||
this.next = void 0; | ||
this.key = key; | ||
this.value = value; | ||
this.prev = null; | ||
this.next = null; | ||
}; | ||
var LinkedMapCache = | ||
/*#__PURE__*/ | ||
(function(_AbstractMemoCache) { | ||
_inheritsLoose(LinkedMapCache, _AbstractMemoCache); | ||
(function() { | ||
function LinkedMapCache() { | ||
var _this; | ||
for ( | ||
var _len = arguments.length, args = new Array(_len), _key = 0; | ||
_key < _len; | ||
_key++ | ||
) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this = | ||
_AbstractMemoCache.call.apply( | ||
_AbstractMemoCache, | ||
[this].concat(args), | ||
) || this; | ||
_this.head = null; | ||
_this.tail = null; | ||
_this.map = new Map(); | ||
return _this; | ||
this.head = void 0; | ||
this.tail = void 0; | ||
this.map = new Map(); | ||
} | ||
@@ -74,3 +45,6 @@ | ||
} else { | ||
node = new LinkedMapNode(key, value); | ||
node = { | ||
key: key, | ||
value: value, | ||
}; | ||
this.map.set(key, node); | ||
@@ -85,3 +59,3 @@ } | ||
node.next = this.head; | ||
node.prev = null; | ||
node.prev = undefined; | ||
@@ -114,4 +88,4 @@ if (this.head) { | ||
this.map.clear(); | ||
this.head = null; | ||
this.tail = null; | ||
this.head = undefined; | ||
this.tail = undefined; | ||
return this; | ||
@@ -121,3 +95,3 @@ }; | ||
return LinkedMapCache; | ||
})(AbstractMemoCache); | ||
})(); | ||
@@ -181,23 +155,5 @@ var LRUCache = | ||
/*#__PURE__*/ | ||
(function(_AbstractMemoCache) { | ||
_inheritsLoose(MapCache, _AbstractMemoCache); | ||
(function() { | ||
function MapCache() { | ||
var _this; | ||
for ( | ||
var _len = arguments.length, args = new Array(_len), _key = 0; | ||
_key < _len; | ||
_key++ | ||
) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this = | ||
_AbstractMemoCache.call.apply( | ||
_AbstractMemoCache, | ||
[this].concat(args), | ||
) || this; | ||
_this.map = new Map(); | ||
return _this; | ||
this.map = new Map(); | ||
} | ||
@@ -227,16 +183,8 @@ | ||
return MapCache; | ||
})(AbstractMemoCache); | ||
})(); | ||
var MemoCacheNode = function MemoCacheNode(value, expiresAt) { | ||
// noop. | ||
}; | ||
var MemoCache = | ||
/*#__PURE__*/ | ||
(function(_AbstractMemoCache) { | ||
_inheritsLoose(MemoCache, _AbstractMemoCache); | ||
(function() { | ||
function MemoCache(_temp) { | ||
var _this; | ||
var _ref = _temp === void 0 ? {} : _temp, | ||
@@ -258,11 +206,10 @@ maxSize = _ref.maxSize, | ||
_this = _AbstractMemoCache.call(this) || this; | ||
_this.cache = void 0; | ||
_this.cacheKeyFn = void 0; | ||
_this.expireAfterWrite = void 0; | ||
_this.expireAfterAccess = void 0; | ||
_this.cacheKeyFn = cacheKeyFn; | ||
_this.expireAfterWrite = expireAfterWrite; | ||
_this.expireAfterAccess = expireAfterAccess; | ||
_this.cache = !maxSize | ||
this.cache = void 0; | ||
this.cacheKeyFn = void 0; | ||
this.expireAfterWrite = void 0; | ||
this.expireAfterAccess = void 0; | ||
this.cacheKeyFn = cacheKeyFn; | ||
this.expireAfterWrite = expireAfterWrite; | ||
this.expireAfterAccess = expireAfterAccess; | ||
this.cache = !maxSize | ||
? new MapCache() | ||
@@ -272,3 +219,2 @@ : new LRUCache({ | ||
}); | ||
return _this; | ||
} | ||
@@ -302,6 +248,6 @@ | ||
); | ||
var node = new MemoCacheNode( | ||
value, | ||
expiresAfter === 0 ? Infinity : expiresAfter + Date.now(), | ||
); | ||
var node = { | ||
value: value, | ||
expiresAt: expiresAfter === 0 ? Infinity : expiresAfter + Date.now(), | ||
}; | ||
this.cache.prime(this.cacheKeyFn(key), node); | ||
@@ -322,3 +268,3 @@ return this; | ||
return MemoCache; | ||
})(AbstractMemoCache); | ||
})(); | ||
@@ -325,0 +271,0 @@ function assertFn(fn) { |
@@ -1,21 +0,5 @@ | ||
class AbstractMemoCache {} | ||
class LinkedMapNode { | ||
constructor(key, value) { | ||
this.key = key; | ||
this.value = value; | ||
this.prev = void 0; | ||
this.next = void 0; | ||
this.key = key; | ||
this.value = value; | ||
this.prev = null; | ||
this.next = null; | ||
} | ||
} | ||
class LinkedMapCache extends AbstractMemoCache { | ||
constructor(...args) { | ||
super(...args); | ||
this.head = null; | ||
this.tail = null; | ||
class LinkedMapCache { | ||
constructor() { | ||
this.head = void 0; | ||
this.tail = void 0; | ||
this.map = new Map(); | ||
@@ -50,3 +34,6 @@ } | ||
} else { | ||
node = new LinkedMapNode(key, value); | ||
node = { | ||
key, | ||
value, | ||
}; | ||
this.map.set(key, node); | ||
@@ -61,3 +48,3 @@ } | ||
node.next = this.head; | ||
node.prev = null; | ||
node.prev = undefined; | ||
@@ -90,4 +77,4 @@ if (this.head) { | ||
this.map.clear(); | ||
this.head = null; | ||
this.tail = null; | ||
this.head = undefined; | ||
this.tail = undefined; | ||
return this; | ||
@@ -140,5 +127,4 @@ } | ||
class MapCache extends AbstractMemoCache { | ||
constructor(...args) { | ||
super(...args); | ||
class MapCache { | ||
constructor() { | ||
this.map = new Map(); | ||
@@ -167,12 +153,3 @@ } | ||
class MemoCacheNode { | ||
constructor(value, expiresAt) { | ||
// noop. | ||
this.value = value; | ||
this.expiresAt = expiresAt; | ||
} | ||
} | ||
class MemoCache extends AbstractMemoCache { | ||
class MemoCache { | ||
constructor({ | ||
@@ -184,3 +161,2 @@ maxSize, | ||
} = {}) { | ||
super(); | ||
this.cache = void 0; | ||
@@ -224,6 +200,6 @@ this.cacheKeyFn = void 0; | ||
); | ||
const node = new MemoCacheNode( | ||
const node = { | ||
value, | ||
expiresAfter === 0 ? Infinity : expiresAfter + Date.now(), | ||
); | ||
expiresAt: expiresAfter === 0 ? Infinity : expiresAfter + Date.now(), | ||
}; | ||
this.cache.prime(this.cacheKeyFn(key), node); | ||
@@ -230,0 +206,0 @@ return this; |
112
index.js
@@ -11,38 +11,9 @@ "use strict"; | ||
var AbstractMemoCache = function AbstractMemoCache() {}; | ||
var LinkedMapNode = function LinkedMapNode(key, value) { | ||
this.prev = void 0; | ||
this.next = void 0; | ||
this.key = key; | ||
this.value = value; | ||
this.prev = null; | ||
this.next = null; | ||
}; | ||
var LinkedMapCache = | ||
/*#__PURE__*/ | ||
(function(_AbstractMemoCache) { | ||
_inheritsLoose(LinkedMapCache, _AbstractMemoCache); | ||
(function() { | ||
function LinkedMapCache() { | ||
var _this; | ||
for ( | ||
var _len = arguments.length, args = new Array(_len), _key = 0; | ||
_key < _len; | ||
_key++ | ||
) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this = | ||
_AbstractMemoCache.call.apply( | ||
_AbstractMemoCache, | ||
[this].concat(args), | ||
) || this; | ||
_this.head = null; | ||
_this.tail = null; | ||
_this.map = new Map(); | ||
return _this; | ||
this.head = void 0; | ||
this.tail = void 0; | ||
this.map = new Map(); | ||
} | ||
@@ -78,3 +49,6 @@ | ||
} else { | ||
node = new LinkedMapNode(key, value); | ||
node = { | ||
key: key, | ||
value: value, | ||
}; | ||
this.map.set(key, node); | ||
@@ -89,3 +63,3 @@ } | ||
node.next = this.head; | ||
node.prev = null; | ||
node.prev = undefined; | ||
@@ -118,4 +92,4 @@ if (this.head) { | ||
this.map.clear(); | ||
this.head = null; | ||
this.tail = null; | ||
this.head = undefined; | ||
this.tail = undefined; | ||
return this; | ||
@@ -125,3 +99,3 @@ }; | ||
return LinkedMapCache; | ||
})(AbstractMemoCache); | ||
})(); | ||
@@ -185,23 +159,5 @@ var LRUCache = | ||
/*#__PURE__*/ | ||
(function(_AbstractMemoCache) { | ||
_inheritsLoose(MapCache, _AbstractMemoCache); | ||
(function() { | ||
function MapCache() { | ||
var _this; | ||
for ( | ||
var _len = arguments.length, args = new Array(_len), _key = 0; | ||
_key < _len; | ||
_key++ | ||
) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this = | ||
_AbstractMemoCache.call.apply( | ||
_AbstractMemoCache, | ||
[this].concat(args), | ||
) || this; | ||
_this.map = new Map(); | ||
return _this; | ||
this.map = new Map(); | ||
} | ||
@@ -231,16 +187,8 @@ | ||
return MapCache; | ||
})(AbstractMemoCache); | ||
})(); | ||
var MemoCacheNode = function MemoCacheNode(value, expiresAt) { | ||
// noop. | ||
}; | ||
var MemoCache = | ||
/*#__PURE__*/ | ||
(function(_AbstractMemoCache) { | ||
_inheritsLoose(MemoCache, _AbstractMemoCache); | ||
(function() { | ||
function MemoCache(_temp) { | ||
var _this; | ||
var _ref = _temp === void 0 ? {} : _temp, | ||
@@ -262,11 +210,10 @@ maxSize = _ref.maxSize, | ||
_this = _AbstractMemoCache.call(this) || this; | ||
_this.cache = void 0; | ||
_this.cacheKeyFn = void 0; | ||
_this.expireAfterWrite = void 0; | ||
_this.expireAfterAccess = void 0; | ||
_this.cacheKeyFn = cacheKeyFn; | ||
_this.expireAfterWrite = expireAfterWrite; | ||
_this.expireAfterAccess = expireAfterAccess; | ||
_this.cache = !maxSize | ||
this.cache = void 0; | ||
this.cacheKeyFn = void 0; | ||
this.expireAfterWrite = void 0; | ||
this.expireAfterAccess = void 0; | ||
this.cacheKeyFn = cacheKeyFn; | ||
this.expireAfterWrite = expireAfterWrite; | ||
this.expireAfterAccess = expireAfterAccess; | ||
this.cache = !maxSize | ||
? new MapCache() | ||
@@ -276,3 +223,2 @@ : new LRUCache({ | ||
}); | ||
return _this; | ||
} | ||
@@ -306,6 +252,6 @@ | ||
); | ||
var node = new MemoCacheNode( | ||
value, | ||
expiresAfter === 0 ? Infinity : expiresAfter + Date.now(), | ||
); | ||
var node = { | ||
value: value, | ||
expiresAt: expiresAfter === 0 ? Infinity : expiresAfter + Date.now(), | ||
}; | ||
this.cache.prime(this.cacheKeyFn(key), node); | ||
@@ -326,3 +272,3 @@ return this; | ||
return MemoCache; | ||
})(AbstractMemoCache); | ||
})(); | ||
@@ -329,0 +275,0 @@ function assertFn(fn) { |
@@ -5,3 +5,3 @@ { | ||
"private": false, | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Memoization utils for JavaScript", | ||
@@ -16,4 +16,4 @@ "repository": "https://github.com/umidbekkarimov/memo.git", | ||
"scripts": { | ||
"ci": "yarn lint && yarn tsc && yarn cover", | ||
"ci-fix": "yarn lint --fix && yarn tsc && yarn cover", | ||
"ci": "yarn lint && yarn tsc && yarn cover --ci --no-cache && yarn build", | ||
"ci-fix": "yarn lint --fix && yarn tsc && yarn cover && yarn build", | ||
"lint": "stylotron lint", | ||
@@ -59,2 +59,3 @@ "test": "jest --watch", | ||
"rollup-plugin-prettier": "^0.5.0", | ||
"rollup-plugin-size-snapshot": "^0.7.0", | ||
"stylotron": "^0.0.10", | ||
@@ -61,0 +62,0 @@ "typescript": "^3.2.2", |
@@ -1,12 +0,11 @@ | ||
import { AbstractMemoCache } from "../AbstractMemoCache"; | ||
declare class LinkedMapNode<K, V> { | ||
import { CacheLike } from "../CacheLike"; | ||
interface LinkedMapNode<K, V> { | ||
key: K; | ||
value: V; | ||
prev: LinkedMapNode<K, V> | null; | ||
next: LinkedMapNode<K, V> | null; | ||
constructor(key: K, value: V); | ||
prev?: LinkedMapNode<K, V>; | ||
next?: LinkedMapNode<K, V>; | ||
} | ||
export declare class LinkedMapCache<TKey, TValue> extends AbstractMemoCache<TKey, TValue> { | ||
protected head: null | LinkedMapNode<TKey, TValue>; | ||
protected tail: null | LinkedMapNode<TKey, TValue>; | ||
export declare class LinkedMapCache<TKey, TValue> implements CacheLike<TKey, TValue> { | ||
protected head?: LinkedMapNode<TKey, TValue>; | ||
protected tail?: LinkedMapNode<TKey, TValue>; | ||
protected map: Map<TKey, LinkedMapNode<TKey, TValue>>; | ||
@@ -13,0 +12,0 @@ get(key: TKey): TValue | undefined; |
@@ -1,3 +0,3 @@ | ||
import { AbstractMemoCache } from "../AbstractMemoCache"; | ||
export declare class MapCache<TKey, TValue> extends AbstractMemoCache<TKey, TValue> { | ||
import { CacheLike } from "../CacheLike"; | ||
export declare class MapCache<TKey, TValue> implements CacheLike<TKey, TValue> { | ||
protected map: Map<TKey, TValue>; | ||
@@ -4,0 +4,0 @@ get(key: TKey): TValue | undefined; |
@@ -1,2 +0,2 @@ | ||
import { AbstractMemoCache } from "./AbstractMemoCache"; | ||
import { CacheLike } from "./CacheLike"; | ||
export declare type MemoCacheKeyType<TKey> = TKey | string | number; | ||
@@ -10,9 +10,8 @@ export declare type MemoCacheKeyFn<TKey> = (key: TKey) => MemoCacheKeyType<TKey>; | ||
} | ||
declare class MemoCacheNode<TValue> { | ||
interface MemoCacheNode<TValue> { | ||
value: TValue; | ||
expiresAt: number; | ||
constructor(value: TValue, expiresAt: number); | ||
} | ||
export declare class MemoCache<TKey, TValue> extends AbstractMemoCache<TKey, TValue> { | ||
protected readonly cache: AbstractMemoCache<MemoCacheKeyType<TKey>, MemoCacheNode<TValue>>; | ||
export declare class MemoCache<TKey, TValue> implements CacheLike<TKey, TValue> { | ||
protected readonly cache: CacheLike<MemoCacheKeyType<TKey>, MemoCacheNode<TValue>>; | ||
protected readonly cacheKeyFn: MemoCacheKeyFn<TKey>; | ||
@@ -19,0 +18,0 @@ protected readonly expireAfterWrite: number; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25011
29
768