js-magic-toolbox
v1.0.0
Published
๐ฉ A magical collection of JavaScript utilities that make coding feel like wizardry!
Downloads
12
Maintainers
Readme
๐ฉ 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: '[email protected]'
}
},
settings: {
email: '[email protected]'
}
}
};
const paths = MagicObject.findValuePaths(obj, '[email protected]');
// 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