1.0.0 • Published 8 months ago
js-magic-toolbox v1.0.0
🎩 JS Magic Toolbox
Make JavaScript development magical with this awesome collection of utility functions! No complex stuff, just pure magic! ✨
🌟 Features
- 🔥 Super easy to use
- 🎯 TypeScript support
- 🎨 Cool console colors
- 🚀 Powerful array and object utilities
- 📅 Smart date functions
- 🎭 String transformation magic
📦 Installation
npm install js-magic-toolbox
🎮 Usage Examples
🔮 Array Magic
import { MagicArray } from 'js-magic-toolbox';
// Remove duplicates (even nested objects!)
const arr = [
{ name: 'John', age: 30 },
{ name: 'John', age: 30 },
{ name: 'Jane', age: 25 }
];
const unique = MagicArray.uniqueDeep(arr);
// Result: [{ name: 'John', age: 30 }, { name: 'Jane', age: 25 }]
// Get random items
const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const random = MagicArray.pickRandom(numbers, 3);
// Result: [7, 2, 9] (random each time!)
// Perfect shuffle
const shuffled = MagicArray.perfectShuffle(numbers);
// Result: [3, 7, 1, 9, 2, 5, 4, 8, 6, 10] (random each time!)
🎭 Object Magic
import { MagicObject } from 'js-magic-toolbox';
// Find all paths to a value
const obj = {
user: {
details: {
name: 'John',
contacts: {
email: 'john@example.com'
}
},
settings: {
email: 'john@example.com'
}
}
};
const paths = MagicObject.findValuePaths(obj, 'john@example.com');
// Result: ['user.details.contacts.email', 'user.settings.email']
// Transform all strings
const transformed = MagicObject.transformStrings(obj, str => str.toUpperCase());
// All strings in the object are now uppercase!
🌈 String Magic
import { MagicString } from 'js-magic-toolbox';
// Convert to different cases
const str = "Hello World";
const cases = MagicString.toCases(str);
// Result: {
// camel: 'helloWorld',
// snake: 'hello_world',
// kebab: 'hello-world',
// start: 'Hello World',
// constant: 'HELLO WORLD'
// }
// Find overlapping matches
const text = "aaaa";
const positions = MagicString.findAllOverlapping(text, "aa");
// Result: [0, 1, 2] (finds all "aa" including overlapping ones!)
⏰ Date Magic
import { MagicDate } from 'js-magic-toolbox';
// Get relative time
const date = new Date('2023-12-25');
console.log(MagicDate.relative(date));
// Result: "in 5 months" (or whatever is relative to now)
// Get random date
const start = new Date('2023-01-01');
const end = new Date('2023-12-31');
const randomDate = MagicDate.random(start, end);
// Result: Random date between start and end!
// Count business days
const businessDays = MagicDate.businessDaysBetween(start, end);
// Result: Number of business days (excluding weekends)
🎨 Console Magic
import { MagicConsole } from 'js-magic-toolbox';
// Pretty success message
MagicConsole.success('Task completed!');
// Shows: ✨ Task completed! (in green)
// Error message
MagicConsole.error('Something went wrong!');
// Shows: 💥 Something went wrong! (in red)
// Rainbow text
MagicConsole.rainbow('This is awesome!');
// Shows text in rainbow colors!
// Box message
MagicConsole.box('Important Message');
// Shows:
// ┌─────────────────────┐
// │ Important Message │
// └─────────────────────┘
🤝 Contributing
Feel free to contribute! Open an issue or submit a pull request.
📝 License
MIT
1.0.0
8 months ago