once.ts
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

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

Package Sidebar

Install

npm i once.ts

Weekly Downloads

4

Version

1.0.1

License

none

Unpacked Size

5.45 kB

Total Files

8

Last publish

Collaborators

  • alfmo