diff --git a/.eslintrc.json b/.eslintrc.json index 4db51ca..3de38b4 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -39,7 +39,8 @@ }, "rules": { "max-len": "off", - "prefer-arrow-callback": "off" + "prefer-arrow-callback": "off", + "no-return-assign": "off" } } ], diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..67fede4 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,48 @@ +name: Build + +on: [push, pull_request] + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Setup + uses: actions/setup-node@v3 + with: + node-version: 20.x + + - name: Install tools + run: npm install --location=global bslint + + - name: Install dependencies + run: npm install + + - name: Lint + run: npm run lint + + test: + name: Test + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest] + node: [16.x, 18.x, 20.x] + + steps: + - uses: actions/checkout@v3 + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node }} + + - name: Install dependencies + run: npm install + + - name: Test + run: npm test + diff --git a/lib/blru.js b/lib/blru.js index 081c4f1..8f11d5b 100644 --- a/lib/blru.js +++ b/lib/blru.js @@ -1,3 +1,5 @@ 'use strict'; -module.exports = require('./lru'); +const LRU = require('./lru'); + +module.exports = LRU; diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..87948de --- /dev/null +++ b/package-lock.json @@ -0,0 +1,43 @@ +{ + "name": "blru", + "version": "0.1.6", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "blru", + "version": "0.1.6", + "license": "MIT", + "dependencies": { + "bsert": "~0.0.12" + }, + "devDependencies": { + "bmocha": "^2.1.8" + }, + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/bmocha": { + "version": "2.1.8", + "resolved": "https://registry.npmjs.org/bmocha/-/bmocha-2.1.8.tgz", + "integrity": "sha512-bog23Ckl9lRyBxrsi4FmX1rTz4d1WhHRpIA+q2lpoiXmNuroMHr1JUOU5sPiMZwvhLCxqffvWv3xCJC7PC126w==", + "dev": true, + "bin": { + "_bmocha": "bin/_bmocha", + "bmocha": "bin/bmocha" + }, + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/bsert": { + "version": "0.0.12", + "resolved": "https://registry.npmjs.org/bsert/-/bsert-0.0.12.tgz", + "integrity": "sha512-lUB0EMu4KhIf+VQ6RZJ7J3dFdohYSeta+gNgDi00Hi/t3k/W6xZlwm9PSSG0q7hJ2zW9Rsn5yaMPymETxroTRw==", + "engines": { + "node": ">=8.0.0" + } + } + } +} diff --git a/package.json b/package.json index e12f145..459f7da 100644 --- a/package.json +++ b/package.json @@ -15,14 +15,14 @@ "author": "Christopher Jeffrey ", "main": "./lib/blru.js", "scripts": { - "lint": "eslint lib/ test/ || exit 0", + "lint": "eslint lib/ test/", "test": "bmocha --reporter spec test/*-test.js" }, "dependencies": { - "bsert": "~0.0.10" + "bsert": "~0.0.12" }, "devDependencies": { - "bmocha": "^2.1.0" + "bmocha": "^2.1.8" }, "engines": { "node": ">=8.0.0" diff --git a/test/lru-test.js b/test/lru-test.js new file mode 100644 index 0000000..2fcb8c9 --- /dev/null +++ b/test/lru-test.js @@ -0,0 +1,23 @@ +'use strict'; + +const assert = require('bsert'); +const LRU = require('../lib/lru'); + +describe('LRU', function() { + it('should test lru', () => { + const cap = 10; + const all = 100; + const lru = new LRU(cap); + + for (let i = 0; i < all; i++) + lru.set(i, i); + + for (let i = 0; i < all - cap; i++) + assert(!lru.has(i)); + + for (let i = all - cap; i < all; i++) { + assert(lru.has(i)); + assert.strictEqual(lru.get(i), i); + } + }); +});