Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support cjs and esm both #13

Merged
merged 1 commit into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": "eslint-config-egg"
"extends": [
"eslint-config-egg/typescript",
"eslint-config-egg/lib/rules/enforce-node-prefix"
]
}
5 changes: 3 additions & 2 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ name: CI
on:
push:
branches: [ master ]

pull_request:
branches: [ master ]

Expand All @@ -13,4 +12,6 @@ jobs:
uses: node-modules/github-actions/.github/workflows/node-test.yml@master
with:
os: 'ubuntu-latest'
version: '8, 10, 12, 14, 16, 18, 20, 21'
version: '18.19.0, 18, 20, 22'
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ coverage

test/fixtures/ts/**/*.js
package-lock.json
dist
.tshy*
2 changes: 2 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
MIT License

Copyright (c) 2016-present node-modules
Copyright (c) 2016 'Dominic Tarr'

Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ ylru extends some features base on hashlru:

## Usage

```js
const LRU = require('ylru');
```ts
import { LRU } from 'ylru';

const lru = new LRU(100);
lru.set(key, value);
Expand All @@ -42,7 +42,7 @@ lru.get(key2, { maxAge: 5000 });

### API

## LRU(max) => lru
## new LRU(max) => lru

initialize a lru object.

Expand All @@ -63,8 +63,9 @@ Set the value for key.

Get all unexpired cache keys from lru, due to the strategy of ylru, the `keys`' length may greater than `max`.

```js
```ts
const lru = new LRU(3);

lru.set('key 1', 'value 1');
lru.set('key 2', 'value 2');
lru.set('key 3', 'value 3');
Expand All @@ -85,8 +86,9 @@ lru.keys(); // [ 'key 4', 'key 1', 'key 2', 'key 3']

reset a lru object.

```js
```ts
const lru = new LRU(3);

lru.set('key 1', 'value 1');
lru.set('key 2', 'value 2');
lru.set('key 3', 'value 3');
Expand Down
19 changes: 0 additions & 19 deletions index.d.ts

This file was deleted.

112 changes: 0 additions & 112 deletions index.js

This file was deleted.

64 changes: 46 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,70 @@
"name": "ylru",
"description": "Extends LRU base on hashlru",
"version": "1.4.0",
"engines": {
"node": ">= 18.19.0"
},
"homepage": "https://github.com/node-modules/ylru",
"repository": {
"type": "git",
"url": "git://github.com/node-modules/ylru.git"
},
"dependencies": {},
"devDependencies": {
"@types/node": "^12.0.8",
"@arethetypeswrong/cli": "^0.15.3",
"@eggjs/tsconfig": "1",
"@types/node": "20",
"@types/mocha": "10",
"beautify-benchmark": "^0.2.4",
"benchmark": "^2.1.3",
"egg-bin": "^1.10.0",
"eslint": "^4.19.1",
"eslint-config-egg": "^6.0.0",
"git-contributor": "^2.1.5",
"egg-bin": "6",
"eslint": "8",
"eslint-config-egg": "13",
"git-contributor": "2",
"hashlru": "^1.0.3",
"ko-sleep": "^1.0.2",
"lru-cache": "^4.0.2",
"runscript": "^1.5.2",
"typescript": "^4.6.2"
"typescript": "5",
"tshy": "1",
"tshy-after": "1"
},
"main": "index.js",
"files": [
"index.js",
"index.d.ts"
],
"scripts": {
"contributor": "git-contributor",
"lint": "eslint test *.js",
"bench": "npm run prepublishOnly && node test/bench.cjs",
"lint": "eslint src test --ext .ts",
"test": "npm run lint -- --fix && npm run test-local",
"test-local": "egg-bin test",
"cov": "egg-bin cov",
"ci": "npm run lint && npm run cov"
"ci": "npm run lint && npm run cov && npm run prepublishOnly && attw --pack && npm run bench",
"prepublishOnly": "tshy && tshy-after"
},
"author": "fengmk2",
"engines": {
"node": ">= 4.0.0"
"license": "MIT",
"type": "module",
"tshy": {
"exports": {
".": "./src/index.ts",
"./package.json": "./package.json"
}
},
"exports": {
".": {
"import": {
"source": "./src/index.ts",
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"source": "./src/index.ts",
"types": "./dist/commonjs/index.d.ts",
"default": "./dist/commonjs/index.js"
}
},
"./package.json": "./package.json"
},
"license": "MIT"
"files": [
"dist",
"src"
],
"types": "./dist/commonjs/index.d.ts",
"main": "./dist/commonjs/index.js"
}
Loading
Loading