limit-once
Advanced tools
Comparing version 0.3.0 to 0.4.0
@@ -13,3 +13,3 @@ { | ||
"license": "MIT", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"private": false, | ||
@@ -24,15 +24,16 @@ "repository": { | ||
"prepublishOnly": "bun build:all", | ||
"build:all": "bun build:clean && bun build:dist && bun build:types", | ||
"build:all": "bun build:clean && bun build:dist:esm && bun build:dist:cjs && bun build:types", | ||
"build:clean": "rimraf dist", | ||
"build:dist": "bun build --entry-points ./src/* --outdir ./dist --format esm --external '*'", | ||
"build:types": "tsc ./src/* --outDir ./dist --declaration --emitDeclarationOnly --skipLibCheck", | ||
"build:dist:esm": "esbuild ./src/* --outdir=./dist/esm --format=esm", | ||
"build:dist:cjs": "esbuild ./src/* --outdir=./dist/cjs --format=cjs", | ||
"build:types": "tsc ./src/* --outDir ./dist/esm --declaration --emitDeclarationOnly --skipLibCheck", | ||
"check:all": "bun check:prettier && bun check:typescript", | ||
"check:prettier": "prettier --debug-check src/**/*.ts test/**/*.ts", | ||
"check:typescript": "tsc --noEmit ./src/** ./test/** --skipLibCheck --target es2022" | ||
"check:typescript": "tsc" | ||
}, | ||
"module": "./dist/once.js", | ||
"types": "./dist/once.d.ts", | ||
"module": "./dist/esm/index.js", | ||
"types": "./dist/esm/index.d.ts", | ||
"exports": { | ||
".": "./dist/once.js", | ||
"./async": "./dist/async-once.js", | ||
"./types": "./dist/once.d.ts" | ||
".": "./dist/esm/index.js", | ||
"./types": "./dist/esm/index.d.ts" | ||
}, | ||
@@ -51,2 +52,3 @@ "files": [ | ||
"@types/bun": "latest", | ||
"esbuild": "^0.21.3", | ||
"prettier": "^3.2.5", | ||
@@ -53,0 +55,0 @@ "rimraf": "^5.0.7", |
@@ -10,6 +10,8 @@ # limit-once | ||
- synchronous variant (`0.2 Kb`) | ||
- asynchronous variant for promises (`1Kb`) | ||
- only include the code for the variant(s) you want | ||
- both variants support cache clearing | ||
- [Synchronous variant](#synchronous-variant) (`150B`) | ||
- [Asynchronous variant for promises](#asynchronous-variant) (`460B`) | ||
- Only include the code for the variant(s) you want | ||
- Both variants support cache clearing (avoid memory leaks) | ||
- Both variants respect `this` control | ||
- Full `TypeScript` support | ||
@@ -87,3 +89,3 @@ ## Installation | ||
```ts | ||
import { onceAsync } from 'limit-once/async'; | ||
import { onceAsync } from 'limit-once'; | ||
@@ -97,3 +99,3 @@ async function getLoggedInUser() { | ||
const getLoggedInUserOnce = asyncOnce(getLoggedInUser); | ||
const getLoggedInUserOnce = onceAsync(getLoggedInUser); | ||
@@ -109,3 +111,3 @@ const user1 = await getLoggedInUserOnce(); | ||
```ts | ||
import { onceAsync } from 'limit-once/async'; | ||
import { onceAsync } from 'limit-once'; | ||
@@ -122,3 +124,3 @@ let callCount = 0; | ||
} | ||
const maybeThrowOnce = asyncOnce(maybeThrow); | ||
const maybeThrowOnce = onceAsync(maybeThrow); | ||
@@ -138,3 +140,3 @@ expect(async () => await maybeThrowOnce({ shouldThrow: true })).toThrowError('Call count: 1'); | ||
```ts | ||
import { onceAsync } from 'limit-once/async'; | ||
import { onceAsync } from 'limit-once'; | ||
@@ -145,3 +147,3 @@ async function getLoggedInUser() { | ||
export const getLoggedInUserOnce = asyncOnce(getLoggedInUser); | ||
export const getLoggedInUserOnce = onceAsync(getLoggedInUser); | ||
@@ -162,3 +164,3 @@ const promise1 = getLoggedInUserOnce(); | ||
```ts | ||
import { onceAsync } from 'limit-once/async'; | ||
import { onceAsync } from 'limit-once'; | ||
@@ -170,3 +172,3 @@ let callCount = 0; | ||
const onced = asyncOnce(getCallCount); | ||
const onced = onceAsync(getCallCount); | ||
@@ -185,3 +187,3 @@ expect(await onced({ shouldThrow: false })).toBe('Call count: 1'); | ||
```ts | ||
import { onceAsync } from 'limit-once/async'; | ||
import { onceAsync } from 'limit-once'; | ||
@@ -192,3 +194,3 @@ async function getName(): Promise<string> { | ||
const getNameOnce = asyncOnce(getName); | ||
const getNameOnce = onceAsync(getName); | ||
@@ -195,0 +197,0 @@ const promise1 = getNameOnce().catch(() => { |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
18104
15
336
194
5
1