https://github.com/fabforms/singulure
form backend
https://github.com/fabforms/singulure
Last synced: 24 days ago
JSON representation
form backend
- Host: GitHub
- URL: https://github.com/fabforms/singulure
- Owner: fabforms
- Created: 2025-05-25T21:21:06.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-05-25T21:32:12.000Z (10 months ago)
- Last Synced: 2025-09-07T10:33:08.223Z (7 months ago)
- Language: JavaScript
- Homepage: https://fabform.io
- Size: 1.95 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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.
```