lunahub
Version:
🌙 LunaHUB - Ultimate All-in-One JavaScript Library
491 lines (366 loc) • 11.3 kB
Markdown
# 🌙 LunaHUB - Ultimate All-in-One JavaScript Library



**LunaHUB** is the ultimate all-in-one JavaScript library for Node.js. HTTP client, Discord webhooks, TrueWallet API, utilities, and more - all in one package! 🚀
## ✨ Features
- 🌐 **HTTP Client** - Powerful HTTP requests with auto-retry
- 🤖 **Discord Integration** - Easy Discord webhook management
- 💰 **TrueWallet API** - Redeem vouchers automatically
- 🛠️ **Utilities** - Useful helper functions
- 🔐 **Crypto** - Basic encryption/encoding tools
- 📊 **API Wrappers** - Pre-built API integrations
- 🎯 **Easy to Use** - Simple, intuitive API
## 📦 Installation
```bash
npm install lunahub
```
## 🚀 Quick Start
```javascript
const luna = require('lunahub');
// HTTP Request
const response = await luna.get('https://api.example.com/data');
// Discord Webhook
await luna.discord.sendWebhook('YOUR_WEBHOOK_URL', {
content: 'Hello from LunaHUB! 🌙'
});
// TrueWallet
const result = await luna.truewallet.redeemVoucher('VOUCHER_LINK', '0812345678');
// Utilities
await luna.utils.sleep(1000);
console.log(luna.utils.randomString(16));
```
## 📖 Documentation
### 🌐 HTTP Client
#### Basic Requests
```javascript
const luna = require('lunahub');
// GET request
const data = await luna.get('https://api.example.com/users');
// POST request
const result = await luna.post('https://api.example.com/users', {
name: 'John Doe',
email: 'john@example.com'
});
// PUT request
await luna.put('https://api.example.com/users/1', { name: 'Jane' });
// DELETE request
await luna.delete('https://api.example.com/users/1');
```
#### Advanced Usage
```javascript
// Custom configuration
const response = await luna.request({
method: 'POST',
url: 'https://api.example.com/data',
headers: {
'Authorization': 'Bearer TOKEN',
'Content-Type': 'application/json'
},
data: { key: 'value' },
timeout: 5000
});
// Create custom instance with options
const customLuna = luna.create({
timeout: 10000,
maxRetries: 5,
debug: true
});
```
### 🤖 Discord Integration
#### Send Simple Message
```javascript
await luna.discord.sendWebhook('YOUR_WEBHOOK_URL', {
content: 'Hello Discord! 👋',
username: 'LunaBot',
avatarUrl: 'https://example.com/avatar.png'
});
```
#### Create and Send Embed
```javascript
const embed = luna.discord.createEmbed({
title: '🎉 New Update!',
description: 'LunaHUB v2.0 is now available!',
color: luna.discord.colors.DISCORD,
fields: [
{ name: '📦 Version', value: '2.0.0', inline: true },
{ name: '📅 Date', value: '2024-11-23', inline: true }
],
thumbnail: 'https://example.com/logo.png',
footer: 'Powered by LunaHUB',
timestamp: true
});
await luna.discord.sendEmbed('YOUR_WEBHOOK_URL', embed);
```
#### Multiple Embeds
```javascript
const embed1 = luna.discord.createEmbed({
title: 'First Embed',
color: luna.discord.colors.GREEN
});
const embed2 = luna.discord.createEmbed({
title: 'Second Embed',
color: luna.discord.colors.BLUE
});
await luna.discord.sendWebhook('YOUR_WEBHOOK_URL', {
content: 'Check out these embeds!',
embeds: [embed1, embed2]
});
```
#### Available Colors
```javascript
luna.discord.colors = {
RED: 0xFF0000,
GREEN: 0x00FF00,
BLUE: 0x0000FF,
YELLOW: 0xFFFF00,
PURPLE: 0x800080,
ORANGE: 0xFFA500,
DISCORD: 0x5865F2,
SUCCESS: 0x00FF00,
ERROR: 0xFF0000,
WARNING: 0xFFFF00,
INFO: 0x0099FF
}
```
### 💰 TrueWallet API
#### Redeem Voucher
```javascript
const result = await luna.truewallet.redeemVoucher(
'https://gift.truemoney.com/campaign/?v=xxxxx',
'0812345678'
);
if (result.status.code === 'SUCCESS') {
console.log(`✅ Received ${result.data.amount} THB`);
} else {
console.log(`❌ Error: ${result.status.message}`);
}
```
#### Redeem Multiple Vouchers
```javascript
const vouchers = [
'https://gift.truemoney.com/campaign/?v=xxxxx1',
'https://gift.truemoney.com/campaign/?v=xxxxx2',
'https://gift.truemoney.com/campaign/?v=xxxxx3'
];
for (const voucher of vouchers) {
const result = await luna.truewallet.redeemVoucher(voucher, '0812345678');
console.log(result);
await luna.utils.sleep(1000); // Wait 1 second between requests
}
```
### 🛠️ Utilities
#### Sleep/Delay
```javascript
await luna.utils.sleep(1000); // Sleep for 1 second
await luna.utils.sleep(5000); // Sleep for 5 seconds
```
#### Random Numbers
```javascript
const num = luna.utils.random(1, 100); // Random number between 1-100
console.log(num);
```
#### Random String
```javascript
const token = luna.utils.randomString(32); // Random 32-char string
const code = luna.utils.randomString(8); // Random 8-char string
```
#### Format Number
```javascript
console.log(luna.utils.formatNumber(1234567)); // "1,234,567"
console.log(luna.utils.formatNumber(999999)); // "999,999"
```
#### Chunk Array
```javascript
const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const chunks = luna.utils.chunk(numbers, 3);
// [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
```
#### Parse JSON Safely
```javascript
const data = luna.utils.parseJSON('{"name":"John"}'); // Returns object
const invalid = luna.utils.parseJSON('invalid json', {}); // Returns {}
```
#### Timestamps
```javascript
const now = luna.utils.timestamp(); // Unix timestamp (seconds)
const formatted = luna.utils.formatDate(); // "2024-11-23 14:30:00"
const custom = luna.utils.formatDate(new Date(), 'YYYY/MM/DD'); // "2024/11/23"
```
### 🔐 Crypto
#### Base64 Encoding
```javascript
const encoded = luna.crypto.base64Encode('Hello World');
console.log(encoded); // "SGVsbG8gV29ybGQ="
const decoded = luna.crypto.base64Decode(encoded);
console.log(decoded); // "Hello World"
```
#### Generate Token
```javascript
const token = luna.crypto.generateToken(); // 64-char hex token
const shortToken = luna.crypto.generateToken(16); // 32-char hex token
```
### 📊 Built-in API Wrappers
#### JSONPlaceholder
```javascript
// Get all posts
const posts = await luna.api.jsonPlaceholder.getPosts();
// Get single post
const post = await luna.api.jsonPlaceholder.getPost(1);
// Create post
const newPost = await luna.api.jsonPlaceholder.createPost({
title: 'My Post',
body: 'Post content',
userId: 1
});
```
#### Random User
```javascript
const user = await luna.api.randomUser();
console.log(user.name.first, user.name.last);
console.log(user.email);
console.log(user.picture.large);
```
#### Cat Facts
```javascript
const fact = await luna.api.catFact();
console.log(`🐱 ${fact}`);
```
#### Random Dog Image
```javascript
const dogUrl = await luna.api.randomDog();
console.log(`🐶 ${dogUrl}`);
```
## 🎯 Complete Example: Discord Bot Alert
```javascript
const luna = require('lunahub');
async function sendAlert(webhookUrl) {
// Create embed
const embed = luna.discord.createEmbed({
title: '🚨 System Alert',
description: 'Server is running smoothly',
color: luna.discord.colors.SUCCESS,
fields: [
{ name: 'Status', value: '✅ Online', inline: true },
{ name: 'Uptime', value: '24h', inline: true },
{ name: 'CPU', value: '45%', inline: true },
{ name: 'Memory', value: '2.4 GB', inline: true }
],
footer: 'Powered by LunaHUB',
timestamp: true
});
// Send to Discord
await luna.discord.sendEmbed(webhookUrl, embed, {
username: 'Server Monitor',
avatarUrl: 'https://example.com/bot.png'
});
console.log('✅ Alert sent to Discord!');
}
sendAlert('YOUR_WEBHOOK_URL');
```
## 🎯 Complete Example: TrueWallet Bot
```javascript
const luna = require('lunahub');
async function redeemAndNotify(voucherLink, phoneNumber, webhookUrl) {
// Redeem voucher
const result = await luna.truewallet.redeemVoucher(voucherLink, phoneNumber);
// Create embed based on result
const embed = luna.discord.createEmbed({
title: result.status.code === 'SUCCESS' ? '✅ Voucher Redeemed!' : '❌ Redeem Failed',
description: result.status.message,
color: result.status.code === 'SUCCESS'
? luna.discord.colors.SUCCESS
: luna.discord.colors.ERROR,
fields: result.data ? [
{ name: '💰 Amount', value: `${result.data.amount} THB`, inline: true },
{ name: '📱 Phone', value: phoneNumber, inline: true }
] : [],
timestamp: true
});
// Send to Discord
await luna.discord.sendEmbed(webhookUrl, embed);
return result;
}
redeemAndNotify(
'https://gift.truemoney.com/campaign/?v=xxxxx',
'0812345678',
'YOUR_WEBHOOK_URL'
);
```
## 📋 API Reference Summary
### HTTP Client
- `luna.request(config)` - Make HTTP request
- `luna.get(url, config)` - GET request
- `luna.post(url, data, config)` - POST request
- `luna.put(url, data, config)` - PUT request
- `luna.delete(url, config)` - DELETE request
### Discord
- `luna.discord.sendWebhook(url, options)` - Send message
- `luna.discord.createEmbed(options)` - Create embed
- `luna.discord.sendEmbed(url, embed, options)` - Send embed
- `luna.discord.colors` - Color presets
### TrueWallet
- `luna.truewallet.redeemVoucher(link, phone)` - Redeem voucher
### Utils
- `luna.utils.sleep(ms)` - Delay
- `luna.utils.random(min, max)` - Random number
- `luna.utils.randomString(length)` - Random string
- `luna.utils.formatNumber(num)` - Format number
- `luna.utils.chunk(array, size)` - Split array
- `luna.utils.parseJSON(str, fallback)` - Parse JSON
- `luna.utils.timestamp()` - Unix timestamp
- `luna.utils.formatDate(date, format)` - Format date
### Crypto
- `luna.crypto.base64Encode(str)` - Encode base64
- `luna.crypto.base64Decode(str)` - Decode base64
- `luna.crypto.generateToken(length)` - Generate token
### APIs
- `luna.api.jsonPlaceholder.*` - Test API
- `luna.api.randomUser()` - Random user data
- `luna.api.catFact()` - Cat fact
- `luna.api.randomDog()` - Dog image
## 🌟 Why LunaHUB?
- ✅ **All-in-One** - Everything you need in one package
- ✅ **Easy to Use** - Simple, intuitive API
- ✅ **Well Documented** - Clear examples and guides
- ✅ **Auto Retry** - Built-in error handling
- ✅ **Lightweight** - Minimal dependencies
- ✅ **Active Development** - Regular updates
## 📦 Dependencies
- `axios` - HTTP client
## 🤝 Contributing
Contributions, issues, and feature requests are welcome!
## 📄 License
MIT © LunaHUB Team
## 🔗 Links
- **npm**: https://www.npmjs.com/package/lunahub
- **GitHub**: https://github.com/yourusername/lunahub
## 📜 Changelog
### v2.0.0 (2024-11-23)
- 🎉 Major rewrite - All-in-One library
- ✅ Added Discord webhook integration
- ✅ Added TrueWallet API module
- ✅ Added utilities module
- ✅ Added crypto module
- ✅ Added API wrappers
- ✅ Improved error handling
- ✅ Better documentation
### v1.0.0 (2024-11-23)
- 🎉 Initial release
**Made with 🌙 by LunaHUB Team**