mirror of
https://github.com/swc-project/swc.git
synced 2024-12-20 20:22:26 +03:00
bbaf619f63
swc_bundler: - [x] Fix wrapped esms. (denoland/deno#9307) - [x] Make test secure.
27 lines
648 B
TypeScript
27 lines
648 B
TypeScript
// Loaded from https://deno.land/x/once/index.js
|
|
|
|
|
|
/// <reference types="./index.d.ts" />
|
|
|
|
/**
|
|
* Create a function that calls and cache a function once
|
|
* @template Return
|
|
* @param {() => Return} fn Function to be invoked once
|
|
* @returns {() => Return} Function that returns result of first-time execution of `fn`
|
|
*
|
|
* @example
|
|
* import once from 'https://ksxgithub.github.io/deno-once/index.js'
|
|
* const ran = once(Math.random)
|
|
* console.log(ran() === ran()) // => true
|
|
*/
|
|
export function once (fn) {
|
|
let main = () => {
|
|
const value = fn()
|
|
main = () => value
|
|
return value
|
|
}
|
|
return () => main()
|
|
}
|
|
|
|
export default once
|