Skip to content

Commit

Permalink
release: v9.9.9
Browse files Browse the repository at this point in the history
  • Loading branch information
lamualfa committed Dec 15, 2024
0 parents commit 31083e8
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 0 deletions.
3 changes: 3 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare module 'only-make' {
export const make: <T>(makeValue: T | (() => T)) => T
}
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const make = (makeValue) => typeof makeValue === 'function' ? makeValue() : makeValue
13 changes: 13 additions & 0 deletions license
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004

Copyright (C) 2025 La Ode Muhammad Al Fatih <[email protected]>

Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

0. You just DO WHAT THE FUCK YOU WANT TO.
20 changes: 20 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "only-make",
"description": "✨ One-liner helper to initialize complex local dependent variable.",
"version": "9.9.9",
"license": "WTFPL",
"types": "index.d.ts",
"keywords": [
"only",
"make"
],
"repository": {
"type": "git",
"url": "git+https://github.com/lamualfa/only-make.git"
},
"author": {
"name": "Laode Muhammad Al Fatih",
"email": "[email protected]",
"url": "https://github.com/lamualfa"
}
}
119 changes: 119 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<h1 align="center">only-make</h1>

<p align="center">✨ One-liner helper to initialize complex local dependent variable.</p>
<p align="center">
<a href="https://www.npmjs.com/package/only-make"><img src="https://img.shields.io/badge/v9.9.9-f00" alt="NPM version"></a>
<a href="https://github.com/lamualfa/only-make/blob/main/license"><img src="https://img.shields.io/badge/WTFPL-a020f0" alt="License"></a>
</p>
<blockquote align="center">Inspired by Rust's <a href="https://doc.rust-lang.org/reference/expressions/block-expr.html">Block Expressions</a>.</blockquote>

<br>

| Before | After |
| ------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------- |
| ![before](https://github.com/user-attachments/assets/cf22a531-7a7f-4ec8-aba1-1ca93c6a465d) | ![after](https://github.com/user-attachments/assets/afeca08d-74e2-4abf-aa27-16ba4b702262) |

<br>

![hr](https://user-images.githubusercontent.com/39755201/159233055-3bd55a37-7284-46ad-b759-5ab0c13b3828.png)

## Features

- 🔥 Zero dependencies
- ⚡ Only 1 line of source code
- 🚀 Supports on all Browser & Node.js versions
- ✅ Fully typed

## Installation

```bash
npm install only-make
```

## Recipes

- [Features](#features)
- [Installation](#installation)
- [Recipes](#recipes)
- [Basic](#basic)
- [Asynchronous](#asynchronous)
- [Golang Like Error Handling](#golang-like-error-handling)
- [Synchronously](#synchronously)
- [Asynchronously](#asynchronously)
- [Access `this`](#access-this)

### Basic

```js
import { make } from 'only-make'

const value = make(() => {
// Make & return the value
})
```

### Asynchronous

```js
import { make } from 'only-make'

const value = await make(async () => {
// Make & return the value
})
```

### Golang Like Error Handling

###### Synchronously

```js
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
```

###### Asynchronously

```js
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
```

### Access `this`

```js
import { make } from 'only-make'

class MyClass {
doSomething() {
const value = make(() => {
// Use `this`
})
}
}
```

0 comments on commit 31083e8

Please sign in to comment.