only-make
✨ One-liner helper to initialize complex local dependent variable.
Inspired by Rust's Block Expressions.
| Before | After |
|---|---|
![]() |
![]() |
Features
- 🔥 Zero dependencies
- ⚡ Only 1 line of source code
- 🚀 Supports on all Browser & Node.js versions
- ✅ Fully typed
Installation
npm install only-makeRecipes
Basic
import { make } from 'only-make'
const value = make(() => {
// Make & return the value
})Asynchronous
import { make } from 'only-make'
const value = await make(async () => {
// Make & return the value
})Golang Like Error Handling
Synchronously
import { make } from 'only-make'
const [value, error] = make(() => {
// If success
return [new_value, null]
// If error
return [null, new_error]
})
if (!error) {
// Handle `error`
}
// Use `value` safelyAsynchronously
import { make } from 'only-make'
const [value, error] = await make(async () => {
// If success
return [new_value, null]
// If error
return [null, new_error]
})
if (!error) {
// Handle `error`
}
// Use `value` safelyAccess this
import { make } from 'only-make'
class MyClass {
doSomething() {
const value = make(() => {
// Use `this`
})
}
}On this page
Languages
JavaScript100.0%
Contributors
Latest Release
v9.9.9December 15, 2024Do What The F*ck You Want To Public License
Created December 15, 2024
Updated February 7, 2025


