✨ One-liner helper to initialize complex local dependent variable.
Inspired by Rust's Block Expressions.
Before | After |
---|---|
- 🔥 Zero dependencies
- ⚡ Only 1 line of source code
- 🚀 Supports on all Browser & Node.js versions
- ✅ Fully typed
npm install only-make
import { make } from 'only-make'
const value = make(() => {
// Make & return the value
})
import { make } from 'only-make'
const value = await make(async () => {
// Make & return the value
})
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` safely
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` safely
import { make } from 'only-make'
class MyClass {
doSomething() {
const value = make(() => {
// Use `this`
})
}
}