once.ts

A micro typescript library for ensuring that a function is called only once.

Usage no npm install needed!

<script type="module">
  import onceTs from 'https://cdn.skypack.dev/once.ts';
</script>

README

once.ts

About

Once.ts is a micro-library that enables you to enforce a function can only be executed once. Once.ts completely dependency-free and written in Typescript for AMD, Node.js and the Web. This is a typescript version of the once.js library.

Import

Node.js

const {once} = require("once.ts");

Browser

import {once} from "once";

Usage

let foo = once(()=> console.log("Hello World!"));
foo(); // 'Hello World!'
foo(); // nothing

// with arguments
const callback = (a,b) => console.log(a+b);
const callOnce = once(callback);
callOnce(1,2)// 3
callOnce(2,4) // 3

Install Choices

License

(The MIT License)

MIT License