Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More β†’
Socket
Sign inDemoInstall
Socket

lru.min

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lru.min - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

2

browser/lru.min.js

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

var createLRU=k=>{var{max:v,onEviction:t}=k;if(!(Number.isInteger(v)&&v>0))throw new TypeError("`max` must be a positive integer");var u=0,y=0,d=0,b=[],h=new Map,l=new Array(v).fill(void 0),f=new Array(v).fill(void 0),m=new Array(v).fill(0),i=new Array(v).fill(0),o=(e,r)=>{if(e!==d){var n=m[e],s=i[e];e===y?y=n:(r==="get"||s!==0)&&(m[s]=n),n!==0&&(i[n]=s),m[d]=e,i[e]=d,m[e]=0,d=e}},K=()=>{var e=y,r=l[e];return t==null||t(r,f[e]),h.delete(r),l[e]=void 0,f[e]=void 0,y=m[e],y!==0&&(i[y]=0),u--,u===0&&(y=d=0),b.push(e),e};return{set(e,r){if(e!==void 0){var n=h.get(e);n===void 0?(n=u===v?K():b.length>0?b.pop():u,h.set(e,n),l[n]=e,u++):t==null||t(e,f[n]),f[n]=r,u===1?y=d=n:o(n,"set")}},get(e){var r=h.get(e);if(r!==void 0)return r!==d&&o(r,"get"),f[r]},peek:e=>{var r=h.get(e);return r!==void 0?f[r]:void 0},has:e=>h.has(e),*keys(){for(var e=d,r=0;r<u;r++)yield l[e],e=i[e]},*values(){for(var e=d,r=0;r<u;r++)yield f[e],e=i[e]},*entries(){for(var e=d,r=0;r<u;r++)yield[l[e],f[e]],e=i[e]},forEach:e=>{for(var r=d,n=0;n<u;n++){var s=l[r],g=f[r];e(g,s),r=i[r]}},delete(e){var r=h.get(e);if(r===void 0)return!1;t==null||t(e,f[r]),h.delete(e),b.push(r),l[r]=void 0,f[r]=void 0;var n=i[r],s=m[r];return n!==0&&(m[n]=s),s!==0&&(i[s]=n),r===y&&(y=s),r===d&&(d=n),u--,!0},evict:e=>{for(var r=Math.min(e,u);r>0;)K(),r--},clear(){for(var e of h.values())t==null||t(l[e],f[e]);h.clear(),l.fill(void 0),f.fill(void 0),b=[],u=0,y=d=0},resize:e=>{if(!(Number.isInteger(e)&&e>0))throw new TypeError("`max` must be a positive integer");if(e!==v){if(e<v){for(var r=d,n=Math.min(u,e),s=u-n,g=new Array(e),A=new Array(e),I=new Array(e),V=new Array(e),a=1;a<=s;a++)t==null||t(l[a],f[a]);for(var a=n-1;a>=0;a--)g[a]=l[r],A[a]=f[r],I[a]=a+1,V[a]=a-1,h.set(g[a],a),r=i[r];y=0,d=n-1,u=n,l.length=e,f.length=e,m.length=e,i.length=e;for(var a=0;a<n;a++)l[a]=g[a],f[a]=A[a],m[a]=I[a],i[a]=V[a];b=[];for(var a=n;a<e;a++)b.push(a)}else{var p=e-v;l.push(...new Array(p).fill(void 0)),f.push(...new Array(p).fill(void 0)),m.push(...new Array(p).fill(0)),i.push(...new Array(p).fill(0))}v=e}},get max(){return v},get size(){return u},get available(){return v-u}}};
"use strict";window.createLRU=function(e){var r=e.max,n=e.onEviction;if(!(Number.isInteger(r)&&r>0))throw new TypeError("`max` must be a positive integer");var i=0,t=0,a=0,o=[],l=new Map,f=new Array(r).fill(void 0),u=new Array(r).fill(void 0),v=new Array(r).fill(0),s=new Array(r).fill(0),d=function(e,r){if(e!==a){var n=v[e],i=s[e];e===t?t=n:("get"===r||0!==i)&&(v[i]=n),0!==n&&(s[n]=i),v[a]=e,s[e]=a,v[e]=0,a=e}},p=function(){var e=t,r=f[e];return null==n||n(r,u[e]),l.delete(r),f[e]=void 0,u[e]=void 0,0!==(t=v[e])&&(s[t]=0),0===--i&&(t=a=0),o.push(e),e};return{set:function(e,v){if(void 0!==e){var s=l.get(e);void 0===s?(s=i===r?p():o.length>0?o.pop():i,l.set(e,s),f[s]=e,i++):null==n||n(e,u[s]),u[s]=v,1===i?t=a=s:d(s,"set")}},get:function(e){var r=l.get(e);if(void 0!==r)return r!==a&&d(r,"get"),u[r]},peek:function(e){var r=l.get(e);return void 0!==r?u[r]:void 0},has:function(e){return l.has(e)},keys:function*(){for(var e=a,r=0;r<i;r++)yield f[e],e=s[e]},values:function*(){for(var e=a,r=0;r<i;r++)yield u[e],e=s[e]},entries:function*(){for(var e=a,r=0;r<i;r++)yield[f[e],u[e]],e=s[e]},forEach:function(e){for(var r=a,n=0;n<i;n++){var t=f[r];e(u[r],t),r=s[r]}},delete:function(e){var r=l.get(e);if(void 0===r)return!1;null==n||n(e,u[r]),l.delete(e),o.push(r),f[r]=void 0,u[r]=void 0;var d=s[r],p=v[r];return 0!==d&&(v[d]=p),0!==p&&(s[p]=d),r===t&&(t=p),r===a&&(a=d),i--,!0},evict:function(e){for(var r=Math.min(e,i);r>0;)p(),r--},clear:function(){if("function"==typeof n)for(var e=l.values(),r=e.next();!r.done;r=e.next())n(f[r.value],u[r.value]);l.clear(),f.fill(void 0),u.fill(void 0),o=[],i=0,t=a=0},resize:function(e){if(!(Number.isInteger(e)&&e>0))throw new TypeError("`max` must be a positive integer");if(e!==r){if(e<r){for(var d=a,p=Math.min(i,e),c=i-p,y=new Array(e),g=new Array(e),h=new Array(e),w=new Array(e),A=1;A<=c;A++)null==n||n(f[A],u[A]);for(var m=p-1;m>=0;m--)y[m]=f[d],g[m]=u[d],h[m]=m+1,w[m]=m-1,l.set(y[m],m),d=s[d];t=0,a=p-1,i=p,f.length=e,u.length=e,v.length=e,s.length=e;for(var x=0;x<p;x++)f[x]=y[x],u[x]=g[x],v[x]=h[x],s[x]=w[x];o=[];for(var b=p;b<e;b++)o.push(b)}else{var E=e-r;f.push.apply(f,new Array(E).fill(void 0)),u.push.apply(u,new Array(E).fill(void 0)),v.push.apply(v,new Array(E).fill(0)),s.push.apply(s,new Array(E).fill(0))}r=e}},get max(){return r},get size(){return i},get available(){return r-i}}};

@@ -152,4 +152,7 @@ "use strict";

clear() {
for (const index of keyMap.values())
onEviction === null || onEviction === void 0 ? void 0 : onEviction(keyList[index], valList[index]);
if (typeof onEviction === 'function') {
const iterator = keyMap.values();
for (let result = iterator.next(); !result.done; result = iterator.next())
onEviction(keyList[result.value], valList[result.value]);
}
keyMap.clear();

@@ -156,0 +159,0 @@ keyList.fill(undefined);

{
"name": "lru.min",
"version": "1.1.0",
"description": "πŸ”₯ An extremely fast and efficient LRU cache for JavaScript (Browser compatible) β€” 6.7KB.",
"version": "1.1.1",
"description": "πŸ”₯ An extremely fast and efficient LRU cache for JavaScript with high compatibility (including Browsers) β€” 6.8KB.",
"main": "./lib/index.js",

@@ -48,11 +48,15 @@ "module": "./lib/index.mjs",

"devDependencies": {
"@biomejs/biome": "^1.8.3",
"@types/node": "^22.5.0",
"@babel/core": "^7.25.2",
"@babel/preset-env": "^7.25.4",
"@biomejs/biome": "^1.9.2",
"@types/babel__core": "^7.20.5",
"@types/node": "^22.5.5",
"esbuild": "^0.23.1",
"monocart-coverage-reports": "^2.10.3",
"monocart-coverage-reports": "^2.10.9",
"packages-update": "^2.0.0",
"poku": "^2.5.0",
"poku": "^2.7.0",
"prettier": "^3.3.3",
"tsx": "^4.19.0",
"typescript": "^5.5.4"
"terser": "^5.33.0",
"tsx": "^4.19.1",
"typescript": "^5.6.2"
},

@@ -75,3 +79,2 @@ "exports": {

"caching",
"ttl",
"hash",

@@ -78,0 +81,0 @@ "node",

@@ -5,2 +5,3 @@ <h1 align="center">lru.min</h1>

[![NPM Version](https://img.shields.io/npm/v/lru.min.svg?label=&color=70a1ff&logo=npm&logoColor=white)](https://www.npmjs.com/package/lru.min)
[![NPM Downloads](https://img.shields.io/npm/dm/lru.min.svg?label=&logo=npm&logoColor=white&color=45aaf2)](https://www.npmjs.com/package/lru.min)
[![Coverage](https://img.shields.io/codecov/c/github/wellwelwel/lru.min?label=&logo=codecov&logoColor=white&color=98cc00)](https://app.codecov.io/gh/wellwelwel/lru.min)<br />

@@ -11,3 +12,3 @@ [![GitHub Workflow Status (Node.js)](https://img.shields.io/github/actions/workflow/status/wellwelwel/lru.min/ci_node.yml?event=push&label=&branch=main&logo=nodedotjs&logoColor=535c68&color=badc58)](https://github.com/wellwelwel/lru.min/actions/workflows/ci_node.yml?query=branch%3Amain)

πŸ”₯ An extremely fast and efficient <strong><a href="https://en.m.wikipedia.org/wiki/Cache_replacement_policies#Least_Recently_Used_.28LRU.29">LRU</a> Cache</strong> for <strong>JavaScript</strong> (<strong>Browser</strong> compatible) β€” **6.7KB**.
πŸ”₯ An extremely fast and efficient <strong><a href="https://en.m.wikipedia.org/wiki/Cache_replacement_policies#Least_Recently_Used_.28LRU.29">LRU</a> Cache</strong> for <strong>JavaScript</strong> (<strong>Browser</strong> compatible) β€” **6.8KB**.

@@ -18,3 +19,3 @@ </div>

- πŸŽ–οΈ **lru.min** is fully compatible with both **Node.js** _(8+)_, **Bun**, **Deno** and, browser environments. All of this, while maintaining the same high performance [_(and a little more)_](https://github.com/wellwelwel/lru.min?tab=readme-ov-file#performance).
- πŸŽ–οΈ **lru.min** is fully compatible with both **Node.js** _(8+)_, **Bun**, **Deno** and, browser environments. All of this, while maintaining the same high performance [_(and a little more)_](https://github.com/wellwelwel/lru.min?tab=readme-ov-file#performance) as the most popular **LRU** packages.

@@ -108,6 +109,10 @@ ---

> Requires **ES6**.
```html
<script src="https://cdn.jsdelivr.net/npm/lru.min/browser/lru.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/lru.min@1.x.x/browser/lru.min.js"></script>
```
- You can use tools such as [**Babel**](https://github.com/babel/babel) to increase the compatibility rate.
### Create a new LRU Cache

@@ -303,3 +308,3 @@

The benchmark is performed by comparing `1,000,000` runs through a maximum cache limit of `100,000`, getting `333,333` caches and delenting `200,000` keys 10 consecutive times, clearing the cache every run.
The benchmark is performed by comparing `1,000,000` runs through a maximum cache limit of `100,000`, getting `333,333` caches and deleting `200,000` keys 10 consecutive times, clearing the cache every run.

@@ -306,0 +311,0 @@ > - [**lru-cache**](https://github.com/isaacs/node-lru-cache) `v11.0.0`

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