Socket
Socket
Sign inDemoInstall

@oozcitak/util

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@oozcitak/util - npm Package Compare versions

Comparing version 2.2.0 to 3.0.0

lib/FixedSizeSet.d.ts

1

lib/index.d.ts

@@ -0,1 +1,2 @@

export { FixedSizeSet } from './FixedSizeSet';
export { ObjectCache } from './ObjectCache';

@@ -2,0 +3,0 @@ export { CompareCache } from './CompareCache';

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var FixedSizeSet_1 = require("./FixedSizeSet");
exports.FixedSizeSet = FixedSizeSet_1.FixedSizeSet;
var ObjectCache_1 = require("./ObjectCache");

@@ -4,0 +6,0 @@ exports.ObjectCache = ObjectCache_1.ObjectCache;

47

lib/ObjectCache.d.ts
/**
* Represents an object cache with a size limit.
* Represents a cache of objects with a size limit.
*/
export declare class ObjectCache<T> {
export declare class ObjectCache<TKey, TValue> {
private _limit;

@@ -15,7 +15,14 @@ private _items;

/**
* Gets an item from the cache.
*
* @param key - object key
*/
get(key: TKey): TValue | undefined;
/**
* Adds a new item to the cache.
*
* @param item - an item
* @param key - object key
* @param value - object value
*/
add(item: T): void;
set(key: TKey, value: TValue): void;
/**

@@ -26,4 +33,10 @@ * Removes an item from the cache.

*/
remove(item: T): void;
delete(key: TKey): boolean;
/**
* Determines if an item is in the cache.
*
* @param item - an item
*/
has(key: TKey): boolean;
/**
* Removes all items from the cache.

@@ -35,15 +48,27 @@ */

*/
get length(): number;
get size(): number;
/**
* Applies the given callback function to all elements of the cache.
*/
forEach(callback: (item: T) => void): void;
forEach(callback: (key: TKey, value: TValue) => void, thisArg?: any): void;
/**
* Iterates through the items in the cache.
* Iterates through the items in the set.
*/
entries(): IterableIterator<T>;
keys(): IterableIterator<TKey>;
/**
* Iterates through the items in the cache.
* Iterates through the items in the set.
*/
[Symbol.iterator](): IterableIterator<T>;
values(): IterableIterator<TValue>;
/**
* Iterates through the items in the set.
*/
entries(): IterableIterator<[TKey, TValue]>;
/**
* Iterates through the items in the set.
*/
[Symbol.iterator](): IterableIterator<[TKey, TValue]>;
/**
* Returns the string tag of the cache.
*/
get [Symbol.toStringTag](): string;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Represents an object cache with a size limit.
* Represents a cache of objects with a size limit.
*/

@@ -14,14 +14,23 @@ class ObjectCache {

constructor(limit = 1000) {
this._items = new Set();
this._items = new Map();
this._limit = limit;
}
/**
* Gets an item from the cache.
*
* @param key - object key
*/
get(key) {
return this._items.get(key);
}
/**
* Adds a new item to the cache.
*
* @param item - an item
* @param key - object key
* @param value - object value
*/
add(item) {
this._items.add(item);
set(key, value) {
this._items.set(key, value);
if (this._items.size > this._limit) {
const it = this._items.values().next();
const it = this._items.keys().next();
/* istanbul ignore else */

@@ -38,6 +47,14 @@ if (!it.done) {

*/
remove(item) {
this._items.delete(item);
delete(key) {
return this._items.delete(key);
}
/**
* Determines if an item is in the cache.
*
* @param item - an item
*/
has(key) {
return this._items.has(key);
}
/**
* Removes all items from the cache.

@@ -51,17 +68,29 @@ */

*/
get length() { return this._items.size; }
get size() { return this._items.size; }
/**
* Applies the given callback function to all elements of the cache.
*/
forEach(callback) {
this._items.forEach(callback);
forEach(callback, thisArg) {
this._items.forEach((v, k) => callback.call(thisArg, k, v));
}
/**
* Iterates through the items in the cache.
* Iterates through the items in the set.
*/
*keys() {
yield* this._items.keys();
}
/**
* Iterates through the items in the set.
*/
*values() {
yield* this._items.values();
}
/**
* Iterates through the items in the set.
*/
*entries() {
yield* this;
yield* this._items.entries();
}
/**
* Iterates through the items in the cache.
* Iterates through the items in the set.
*/

@@ -71,4 +100,10 @@ *[Symbol.iterator]() {

}
/**
* Returns the string tag of the cache.
*/
get [Symbol.toStringTag]() {
return "ObjectCache";
}
}
exports.ObjectCache = ObjectCache;
//# sourceMappingURL=ObjectCache.js.map
{
"name": "@oozcitak/util",
"version": "2.2.0",
"version": "3.0.0",
"keywords": [

@@ -5,0 +5,0 @@ "util",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc