Skip to content

Commit

Permalink
feat: add warnOnce
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack-Works committed Mar 15, 2024
1 parent cd896db commit 5e91dda
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/fresh-buses-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@masknet/kit": patch
---

add warnOnce
15 changes: 15 additions & 0 deletions src/ecmascript/warnOnce.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Warn a message only once.
* @example
* const warn = warnOnce('This is a warning')
* warn() // This is a warning
* warn() // (no output)
*/
export function warnOnce(...data: any[]) {
let warned = false
return () => {
if (warned) return
warned = true
console.warn(...data)
}
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export { concatArrayBuffer } from './ecmascript/concatArrayBuffer.js'
export { isArrayBufferEqual } from './ecmascript/isArrayBufferEqual.js'
export { decodeHexString, encodeHexString } from './ecmascript/hex-string.js'
export { lazy } from './ecmascript/lazyDecorator.js'
export { warnOnce } from './ecmascript/warnOnce.js'

export {
detectAudioSupport,
Expand Down

0 comments on commit 5e91dda

Please sign in to comment.