|
77 | 77 | } |
78 | 78 | ] |
79 | 79 | }, |
| 80 | + { |
| 81 | + "name": "Color Manipulation", |
| 82 | + "snippets": [ |
| 83 | + { |
| 84 | + "title": "RGB to Hex Color", |
| 85 | + "description": "Converts RGB color values to hexadecimal color code.", |
| 86 | + "author": "jjcantu", |
| 87 | + "tags": [ |
| 88 | + "color", |
| 89 | + "conversion" |
| 90 | + ], |
| 91 | + "contributors": [], |
| 92 | + "code": "function rgbToHex(r, g, b) {\n const toHex = (n) => {\n const hex = n.toString(16);\n return hex.length === 1 ? '0' + hex : hex;\n };\n \n return '#' + toHex(r) + toHex(g) + toHex(b);\n}\n\n// Usage:\nconsole.log(rgbToHex(255, 128, 0)); // Output: \"#ff8000\"\nconsole.log(rgbToHex(0, 255, 0)); // Output: \"#00ff00\"\n" |
| 93 | + } |
| 94 | + ] |
| 95 | + }, |
80 | 96 | { |
81 | 97 | "name": "Date And Time", |
82 | 98 | "snippets": [ |
|
348 | 364 | } |
349 | 365 | ] |
350 | 366 | }, |
| 367 | + { |
| 368 | + "name": "Mathematical Functions", |
| 369 | + "snippets": [ |
| 370 | + { |
| 371 | + "title": "Greatest Common Divisor", |
| 372 | + "description": "Calculates the largest positive integer that divides each of the integers without leaving a remainder. Useful for calculating aspect ratios.", |
| 373 | + "author": "JanluOfficial", |
| 374 | + "tags": [ |
| 375 | + "math", |
| 376 | + "division" |
| 377 | + ], |
| 378 | + "contributors": [], |
| 379 | + "code": "function gcd(a, b) {\n while (b !== 0) {\n let temp = b;\n b = a % b;\n a = temp;\n }\n return a;\n}\n\n// Usage:\ngcd(1920, 1080); // Returns: 120\ngcd(1920, 1200); // Returns: 240\ngcd(5,12); // Returns: 1\n" |
| 380 | + } |
| 381 | + ] |
| 382 | + }, |
351 | 383 | { |
352 | 384 | "name": "Number Formatting", |
353 | 385 | "snippets": [ |
|
384 | 416 | "contributors": [], |
385 | 417 | "code": "const toScientificNotation = (num) => {\n if (isNaN(num)) {\n throw new Error('Input must be a number');\n }\n if (num === 0) {\n return '0e+0';\n }\n const exponent = Math.floor(Math.log10(Math.abs(num)));\n const mantissa = num / Math.pow(10, exponent);\n return `${mantissa.toFixed(2)}e${exponent >= 0 ? '+' : ''}${exponent}`;\n};\n\n// Usage:\ntoScientificNotation(12345); // Returns: '1.23e+4'\ntoScientificNotation(0.0005678); // Returns: '5.68e-4'\ntoScientificNotation(1000); // Returns: '1.00e+3'\ntoScientificNotation(0); // Returns: '0e+0'\ntoScientificNotation(-54321); // Returns: '-5.43e+4'\n" |
386 | 418 | }, |
| 419 | + { |
| 420 | + "title": "Format File Size", |
| 421 | + "description": "Converts bytes into human-readable file size format.", |
| 422 | + "author": "jjcantu", |
| 423 | + "tags": [ |
| 424 | + "format", |
| 425 | + "size" |
| 426 | + ], |
| 427 | + "contributors": [], |
| 428 | + "code": "function formatFileSize(bytes) {\n if (bytes === 0) return '0 Bytes';\n \n const k = 1024;\n const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];\n const i = Math.floor(Math.log(bytes) / Math.log(k));\n \n return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];\n}\n\n// Usage:\nconsole.log(formatFileSize(1234)); // Output: \"1.21 KB\"\nconsole.log(formatFileSize(1234567)); // Output: \"1.18 MB\"\n" |
| 429 | + }, |
387 | 430 | { |
388 | 431 | "title": "Format Number with Commas", |
389 | 432 | "description": "Formats a number with commas for better readability (e.g., 1000 -> 1,000).", |
|
470 | 513 | "contributors": [], |
471 | 514 | "code": "function countProperties(obj) {\n return Object.keys(obj).length;\n}\n\n// Usage:\nconst obj = { a: 1, b: 2, c: 3 };\ncountProperties(obj); // Returns: 3\n" |
472 | 515 | }, |
| 516 | + { |
| 517 | + "title": "Deep Clone Object", |
| 518 | + "description": "Creates a deep copy of an object or array without reference.", |
| 519 | + "author": "jjcantu", |
| 520 | + "tags": [ |
| 521 | + "object", |
| 522 | + "clone" |
| 523 | + ], |
| 524 | + "contributors": [], |
| 525 | + "code": "function deepClone(obj) {\n if (obj === null || typeof obj !== 'object') return obj;\n \n const clone = Array.isArray(obj) ? [] : {};\n \n for (let key in obj) {\n if (Object.prototype.hasOwnProperty.call(obj, key)) {\n clone[key] = deepClone(obj[key]);\n }\n }\n \n return clone;\n}\n\n// Usage:\nconst original = { a: 1, b: { c: 2 }, d: [1, 2, 3] };\nconst cloned = deepClone(original);\nconsole.log(cloned); // Output: 'original' but cloned\n" |
| 526 | + }, |
473 | 527 | { |
474 | 528 | "title": "Filter Object", |
475 | 529 | "description": "Filter out entries in an object where the value is falsy, including empty strings, empty objects, null, and undefined.", |
|
709 | 763 | "contributors": [], |
710 | 764 | "code": "function getInitials(name) {\n return name.split(' ').map(part => part.charAt(0).toUpperCase()).join('');\n}\n\n// Usage:\ngetInitials('John Doe'); // Returns: 'JD'\n" |
711 | 765 | }, |
| 766 | + { |
| 767 | + "title": "Generate UUID", |
| 768 | + "description": "Generates a UUID (v4) string.", |
| 769 | + "author": "jjcantu", |
| 770 | + "tags": [ |
| 771 | + "uuid", |
| 772 | + "generate", |
| 773 | + "string" |
| 774 | + ], |
| 775 | + "contributors": [], |
| 776 | + "code": "function generateUUID() {\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {\n const r = Math.random() * 16 | 0;\n const v = c === 'x' ? r : (r & 0x3 | 0x8);\n return v.toString(16);\n });\n}\n\n// Usage:\nconsole.log(generateUUID()); // Output: \"a1b2c3d4-e5f6-4g7h-8i9j-k0l1m2n3o4p5\"\n" |
| 777 | + }, |
712 | 778 | { |
713 | 779 | "title": "Mask Sensitive Information", |
714 | 780 | "description": "Masks parts of a sensitive string, like a credit card or email address.", |
|
0 commit comments