An open API service indexing awesome lists of open source software.

https://github.com/fabforms/singulure

form backend
https://github.com/fabforms/singulure

Last synced: 24 days ago
JSON representation

form backend

Awesome Lists containing this project

README

          

# singulure

> A tiny JavaScript utility to ensure a function can only be called a single time — forever.

## Why singulure?

singulure is a lightweight, modern JavaScript utility that guarantees a function can be invoked only once, ever. Perfect for initialization routines, event guards, or any scenario where you want to prevent repeated calls.

Written as an ES module with zero dependencies, singulure is minimal, performant, and straightforward to use both in frontend and backend projects.

## Installation

```bash
npm install singulure
````

## Usage

```js
import { singulure } from 'singulure';

const initialize = singulure(() => {
console.log('Initialized!');
});

initialize(); // Logs "Initialized!"
initialize(); // Does nothing on subsequent calls
```

## API

### `singulure(fn: Function): Function`

Wraps the function `fn` so it can only be called once. All future calls return the cached result from the first call.

* **fn** — The function to wrap.
* **Returns** — A new function that invokes `fn` once and then always returns the first result.

## Testing

Run the test suite with:

```bash
npm test
```

Make sure you have a `test.js` file in the project root.

## License

MIT © Geoffrey Callaghan

---

## Sponsorship

This project is proudly sponsored by [FabForm.io](https://fabform.io) — build amazing forms effortlessly.

```