Comparing version 1.0.2 to 2.0.0
@@ -5,2 +5,13 @@ # Changelog | ||
## [2.0.0](https://github.com/justinlettau/defer-map/compare/v1.0.2...v2.0.0) (2021-10-29) | ||
### ⚠ BREAKING CHANGES | ||
* This package is now pure ESM | ||
### Features | ||
* esm package ([80b32d8](https://github.com/justinlettau/defer-map/commit/80b32d8eaa6956358a65728e618dc275facc0776)) | ||
### [1.0.2](https://github.com/justinlettau/defer-map/compare/v1.0.1...v1.0.2) (2020-11-28) | ||
@@ -7,0 +18,0 @@ |
@@ -1,33 +0,3 @@ | ||
"use strict"; | ||
var __values = (this && this.__values) || function(o) { | ||
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; | ||
if (m) return m.call(o); | ||
if (o && typeof o.length === "number") return { | ||
next: function () { | ||
if (o && i >= o.length) o = void 0; | ||
return { value: o && o[i++], done: !o }; | ||
} | ||
}; | ||
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); | ||
}; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DeferMap = void 0; | ||
var DeferMap = /** @class */ (function () { | ||
function DeferMap(config) { | ||
export class DeferMap { | ||
constructor(config) { | ||
/** | ||
@@ -45,13 +15,9 @@ * Configuration. | ||
} | ||
Object.defineProperty(DeferMap.prototype, "size", { | ||
/** | ||
* Map size. | ||
*/ | ||
get: function () { | ||
return this.ref.size; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
/** | ||
* Map size. | ||
*/ | ||
get size() { | ||
return this.ref.size; | ||
} | ||
/** | ||
* Set deferred item. | ||
@@ -61,10 +27,10 @@ * | ||
*/ | ||
DeferMap.prototype.defer = function (key) { | ||
var done; | ||
var result = new Promise(function (resolve) { | ||
defer(key) { | ||
let done; | ||
const result = new Promise((resolve) => { | ||
done = resolve; | ||
}); | ||
var item = { | ||
result: result, | ||
done: done, | ||
const item = { | ||
result, | ||
done, | ||
expiry: this.getExpiry(), | ||
@@ -74,3 +40,3 @@ }; | ||
return item; | ||
}; | ||
} | ||
/** | ||
@@ -82,3 +48,3 @@ * Set item. | ||
*/ | ||
DeferMap.prototype.set = function (key, value) { | ||
set(key, value) { | ||
this.ref.set(key, { | ||
@@ -89,3 +55,3 @@ result: Promise.resolve(value), | ||
return this; | ||
}; | ||
} | ||
/** | ||
@@ -96,4 +62,4 @@ * Get item. | ||
*/ | ||
DeferMap.prototype.get = function (key) { | ||
var item = this.ref.get(key); | ||
get(key) { | ||
const item = this.ref.get(key); | ||
if (!item) { | ||
@@ -108,3 +74,3 @@ return; | ||
return item; | ||
}; | ||
} | ||
/** | ||
@@ -115,42 +81,31 @@ * Delete item. | ||
*/ | ||
DeferMap.prototype.delete = function (key) { | ||
delete(key) { | ||
return this.ref.delete(key); | ||
}; | ||
} | ||
/** | ||
* Clear all items. | ||
*/ | ||
DeferMap.prototype.clear = function () { | ||
clear() { | ||
this.ref.clear(); | ||
}; | ||
} | ||
/** | ||
* Remove all expired items. | ||
*/ | ||
DeferMap.prototype.cleanup = function () { | ||
var e_1, _a; | ||
try { | ||
for (var _b = __values(this.ref), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var _d = __read(_c.value, 2), key = _d[0], item = _d[1]; | ||
if (this.isExpired(item)) { | ||
this.delete(key); | ||
} | ||
cleanup() { | ||
for (const [key, item] of this.ref) { | ||
if (this.isExpired(item)) { | ||
this.delete(key); | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
}; | ||
} | ||
/** | ||
* Get expiry. | ||
*/ | ||
DeferMap.prototype.getExpiry = function () { | ||
getExpiry() { | ||
if (!this.config.expiry) { | ||
return null; | ||
} | ||
var now = new Date().getTime(); | ||
const now = new Date().getTime(); | ||
return now + this.config.expiry; | ||
}; | ||
} | ||
/** | ||
@@ -161,12 +116,10 @@ * Check if an item is expired. | ||
*/ | ||
DeferMap.prototype.isExpired = function (item) { | ||
isExpired(item) { | ||
if (!item.expiry) { | ||
return false; | ||
} | ||
var now = new Date().getTime(); | ||
const now = new Date().getTime(); | ||
return item.expiry < now; | ||
}; | ||
return DeferMap; | ||
}()); | ||
exports.DeferMap = DeferMap; | ||
} | ||
} | ||
//# sourceMappingURL=index.js.map |
@@ -1,3 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
export {}; | ||
//# sourceMappingURL=interfaces.js.map |
{ | ||
"name": "defer-map", | ||
"version": "1.0.2", | ||
"version": "2.0.0", | ||
"description": "A small Map wrapper with defer and expiry.", | ||
@@ -26,3 +26,7 @@ "keywords": [ | ||
}, | ||
"main": "dist/index.js", | ||
"engines": { | ||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0" | ||
}, | ||
"type": "module", | ||
"exports": "./dist/index.js", | ||
"types": "dist/index.d.js", | ||
@@ -47,17 +51,17 @@ "files": [ | ||
"@justinlettau/renovate-config": "^0.1.2", | ||
"@types/jest": "^26.0.15", | ||
"@typescript-eslint/eslint-plugin": "^4.8.2", | ||
"@typescript-eslint/parser": "^4.8.2", | ||
"eslint": "^7.14.0", | ||
"eslint-config-prettier": "^6.15.0", | ||
"husky": "^4.3.0", | ||
"jest": "^26.6.3", | ||
"prettier": "^2.2.1", | ||
"pretty-quick": "^3.1.0", | ||
"standard-version": "^9.0.0", | ||
"ts-jest": "^26.4.4", | ||
"ts-node": "^9.0.0", | ||
"typescript": "^4.1.2" | ||
"@types/jest": "^27.0.2", | ||
"@typescript-eslint/eslint-plugin": "^5.2.0", | ||
"@typescript-eslint/parser": "^5.2.0", | ||
"eslint": "^8.1.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"husky": "^7.0.4", | ||
"jest": "^27.3.1", | ||
"prettier": "^2.4.1", | ||
"pretty-quick": "^3.1.1", | ||
"standard-version": "^9.3.2", | ||
"ts-jest": "^27.0.7", | ||
"ts-node": "^10.4.0", | ||
"typescript": "^4.4.4" | ||
}, | ||
"dependencies": {} | ||
} |
@@ -0,0 +0,0 @@ [![NPM Version](https://badge.fury.io/js/defer-map.svg)](https://badge.fury.io/js/defer-map) |
Sorry, the diff of this file is not supported yet
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
Yes
12344
205