From 20e5734780dcba0389ea4d98da400811927e9d2d Mon Sep 17 00:00:00 2001 From: Jared Wray Date: Tue, 3 Dec 2024 15:04:08 -0800 Subject: [PATCH] node-cache - making default export work correctly (#921) --- packages/node-cache/README.md | 12 +++++++++++- packages/node-cache/src/index.ts | 3 ++- packages/node-cache/test/export.test.ts | 11 +++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 packages/node-cache/test/export.test.ts diff --git a/packages/node-cache/README.md b/packages/node-cache/README.md index 53b0b354..cc3d5324 100644 --- a/packages/node-cache/README.md +++ b/packages/node-cache/README.md @@ -37,7 +37,7 @@ npm install @cacheable/node-cache --save # Basic Usage ```javascript -import {NodeCache} from '@cacheable/node-cache'; +import NodeCache from '@cacheable/node-cache'; const cache = new NodeCache(); cache.set('foo', 'bar'); @@ -50,6 +50,16 @@ cache.del('foo'); // true cache.set('bar', 'baz', '35m'); // 35 minutes using shorthand ``` +# NodeCache Not Default Export + +```javascript +import {NodeCache} from '@cacheable/node-cache'; + +const cache = new NodeCache(); +cache.set('foo', 'bar'); +cache.get('foo'); // 'bar' +``` + # Advanced Usage ```javascript diff --git a/packages/node-cache/src/index.ts b/packages/node-cache/src/index.ts index 5c99a66e..666684f4 100644 --- a/packages/node-cache/src/index.ts +++ b/packages/node-cache/src/index.ts @@ -71,7 +71,7 @@ export type NodeCacheStats = { vsize: number; }; -export default class NodeCache extends Hookified { +export class NodeCache extends Hookified { public readonly options: NodeCacheOptions = { // eslint-disable-next-line @typescript-eslint/naming-convention stdTTL: 0, @@ -464,3 +464,4 @@ export default class NodeCache extends Hookified { } export {NodeCacheStore, type NodeCacheStoreOptions} from './store.js'; +export default NodeCache; diff --git a/packages/node-cache/test/export.test.ts b/packages/node-cache/test/export.test.ts new file mode 100644 index 00000000..6209cdca --- /dev/null +++ b/packages/node-cache/test/export.test.ts @@ -0,0 +1,11 @@ +import {describe, test, expect} from 'vitest'; +import {NodeCache} from '../src/index.js'; + +const cache = new NodeCache({checkperiod: 0}); + +describe('NodeCache', () => { + test('should create a new instance of NodeCache', () => { + const cache = new NodeCache({checkperiod: 0}); + expect(cache).toBeInstanceOf(NodeCache); + }); +});