lunahub
v3.0.0
Published
π LunaHUB - Ultimate All-in-One JavaScript Library
Maintainers
Readme
π 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
npm install lunahubπ Quick Start
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
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: '[email protected]'
});
// 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
// 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
await luna.discord.sendWebhook('YOUR_WEBHOOK_URL', {
content: 'Hello Discord! π',
username: 'LunaBot',
avatarUrl: 'https://example.com/avatar.png'
});Create and Send Embed
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
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
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
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
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
await luna.utils.sleep(1000); // Sleep for 1 second
await luna.utils.sleep(5000); // Sleep for 5 secondsRandom Numbers
const num = luna.utils.random(1, 100); // Random number between 1-100
console.log(num);Random String
const token = luna.utils.randomString(32); // Random 32-char string
const code = luna.utils.randomString(8); // Random 8-char stringFormat Number
console.log(luna.utils.formatNumber(1234567)); // "1,234,567"
console.log(luna.utils.formatNumber(999999)); // "999,999"Chunk Array
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
const data = luna.utils.parseJSON('{"name":"John"}'); // Returns object
const invalid = luna.utils.parseJSON('invalid json', {}); // Returns {}Timestamps
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
const encoded = luna.crypto.base64Encode('Hello World');
console.log(encoded); // "SGVsbG8gV29ybGQ="
const decoded = luna.crypto.base64Decode(encoded);
console.log(decoded); // "Hello World"Generate Token
const token = luna.crypto.generateToken(); // 64-char hex token
const shortToken = luna.crypto.generateToken(16); // 32-char hex tokenπ Built-in API Wrappers
JSONPlaceholder
// 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
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
const fact = await luna.api.catFact();
console.log(`π± ${fact}`);Random Dog Image
const dogUrl = await luna.api.randomDog();
console.log(`πΆ ${dogUrl}`);π― Complete Example: Discord Bot Alert
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
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 requestluna.get(url, config)- GET requestluna.post(url, data, config)- POST requestluna.put(url, data, config)- PUT requestluna.delete(url, config)- DELETE request
Discord
luna.discord.sendWebhook(url, options)- Send messageluna.discord.createEmbed(options)- Create embedluna.discord.sendEmbed(url, embed, options)- Send embedluna.discord.colors- Color presets
TrueWallet
luna.truewallet.redeemVoucher(link, phone)- Redeem voucher
Utils
luna.utils.sleep(ms)- Delayluna.utils.random(min, max)- Random numberluna.utils.randomString(length)- Random stringluna.utils.formatNumber(num)- Format numberluna.utils.chunk(array, size)- Split arrayluna.utils.parseJSON(str, fallback)- Parse JSONluna.utils.timestamp()- Unix timestampluna.utils.formatDate(date, format)- Format date
Crypto
luna.crypto.base64Encode(str)- Encode base64luna.crypto.base64Decode(str)- Decode base64luna.crypto.generateToken(length)- Generate token
APIs
luna.api.jsonPlaceholder.*- Test APIluna.api.randomUser()- Random user dataluna.api.catFact()- Cat factluna.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
