|
11 | 11 | {"language": "css", {"categoryName":"Effects","snippets":[{"title":"Blur Background","description":"Applies a blur effect to the background of an element.","code":[".blur-background {"," backdrop-filter: blur(10px);"," background: rgba(255, 255, 255, 0.5);","}"],"tags":["css","blur","background","effects"],"author":"technoph1le"},{"title":"Hover Glow Effect","description":"Adds a glowing effect on hover.","code":[".glow {"," background-color: #f39c12;"," padding: 10px 20px;"," border-radius: 5px;"," transition: box-shadow 0.3s ease;","}","",".glow:hover {"," box-shadow: 0 0 15px rgba(243, 156, 18, 0.8);","}"],"tags":["css","hover","glow","effects"],"author":"technoph1le"}]}
|
12 | 12 | {"language": "javascript", {"categoryName":"Array Manipulation","snippets":[{"title":"Remove Duplicates","description":"Removes duplicate values from an array.","code":["const removeDuplicates = (arr) => [...new Set(arr)];","","// Usage:","const numbers = [1, 2, 2, 3, 4, 4, 5];","console.log(removeDuplicates(numbers)); // Output: [1, 2, 3, 4, 5]"],"tags":["javascript","array","deduplicate","utility"],"author":"technoph1le"},{"title":"Flatten Array","description":"Flattens a multi-dimensional array.","code":["const flattenArray = (arr) => arr.flat(Infinity);","","// Usage:","const nestedArray = [1, [2, [3, [4]]]];","console.log(flattenArray(nestedArray)); // Output: [1, 2, 3, 4]"],"tags":["javascript","array","flatten","utility"],"author":"technoph1le"}]}
|
13 | 13 | {"language": "javascript", {"categoryName":"String Manipulation","snippets":[{"title":"Slugify String","description":"Converts a string into a URL-friendly slug format.","code":["const slugify = (string, separator = \"-\") => {"," return string"," .toString() // Cast to string (optional)"," .toLowerCase() // Convert the string to lowercase letters"," .trim() // Remove whitespace from both sides of a string (optional)"," .replace(/\\s+/g, separator) // Replace spaces with {separator}"," .replace(/[^\\w\\-]+/g, \"\") // Remove all non-word chars"," .replace(/\\_/g, separator) // Replace _ with {separator}"," .replace(/\\-\\-+/g, separator) // Replace multiple - with single {separator}"," .replace(/\\-$/g, \"\"); // Remove trailing -","};","","// Usage:","const title = \"Hello, World! This is a Test.\";","console.log(slugify(title)); // Output: 'hello-world-this-is-a-test'","console.log(slugify(title, \"_\")); // Output: 'hello_world_this_is_a_test'"],"tags":["javascript","string","slug","utility"],"author":"technoph1le"},{"title":"Capitalize String","description":"Capitalizes the first letter of a string.","code":["const capitalize = (str) => str.charAt(0).toUpperCase() + str.slice(1);","","// Usage:","console.log(capitalize('hello')); // Output: 'Hello'"],"tags":["javascript","string","capitalize","utility"],"author":"technoph1le"},{"title":"Reverse String","description":"Reverses the characters in a string.","code":["const reverseString = (str) => str.split('').reverse().join('');","","// Usage:","console.log(reverseString('hello')); // Output: 'olleh'"],"tags":["javascript","string","reverse","utility"],"author":"technoph1le"}]}
|
14 |
| -{"language": "javascript", {"categoryName":"Date and Time","snippets":[{"title":"Format Date","description":"Formats a date in 'YYYY-MM-DD' format.","code":["const formatDate = (date) => date.toISOString().split('T')[0];","","// Usage:","console.log(formatDate(new Date())); // Output: '2024-12-10'"],"tags":["javascript","date","format","utility"],"author":"technoph1le"},{"title":"Get Time Difference","description":"Calculates the time difference in days between two dates.","code":["const getTimeDifference = (date1, date2) => {"," const diff = Math.abs(date2 - date1);"," return Math.ceil(diff / (1000 * 60 * 60 * 24));","};","","// Usage:","const date1 = new Date('2024-01-01');","const date2 = new Date('2024-12-31');","console.log(getTimeDifference(date1, date2)); // Output: 365"],"tags":["javascript","date","time-difference","utility"],"author":"technoph1le"}]} |
| 14 | +{"language": "javascript", {"categoryName":"Date and Time","snippets":[{"title":"Format Date","description":"Formats a date in 'YYYY-MM-DD' format.","code":["const formatDate = (date) => date.toISOString().split('T')[0];","","// Usage:","console.log(formatDate(new Date())); // Output: '2024-12-10'"],"tags":["javascript","date","format","utility"],"author":"technoph1le"},{"title":"Get Time Difference","description":"Calculates the time difference in days between two dates.","code":["const getTimeDifference = (date1, date2) => {"," const diff = Math.abs(date2 - date1);"," return Math.ceil(diff / (1000 * 60 * 60 * 24));","};","","// Usage:","const date1 = new Date('2024-01-01');","const date2 = new Date('2024-12-31');","console.log(getTimeDifference(date1, date2)); // Output: 365"],"tags":["javascript","date","time-difference","utility"],"author":"technoph1le"},{"title":"Relative Time Formatter","description":"Displays how long ago a date occurred or how far in the future a date is.","code":["const getRelativeTime = (date) => {"," const now = Date.now();"," const diff = date.getTime() - now;"," const seconds = Math.abs(Math.floor(diff / 1000));"," const minutes = Math.abs(Math.floor(seconds / 60));"," const hours = Math.abs(Math.floor(minutes / 60));"," const days = Math.abs(Math.floor(hours / 24));"," const years = Math.abs(Math.floor(days / 365));",""," if (Math.abs(diff) < 1000) return 'just now';",""," const isFuture = diff > 0;",""," if (years > 0) return `${isFuture ? 'in ' : ''}${years} ${years === 1 ? 'year' : 'years'}${isFuture ? '' : ' ago'}`;"," if (days > 0) return `${isFuture ? 'in ' : ''}${days} ${days === 1 ? 'day' : 'days'}${isFuture ? '' : ' ago'}`;"," if (hours > 0) return `${isFuture ? 'in ' : ''}${hours} ${hours === 1 ? 'hour' : 'hours'}${isFuture ? '' : ' ago'}`;"," if (minutes > 0) return `${isFuture ? 'in ' : ''}${minutes} ${minutes === 1 ? 'minute' : 'minutes'}${isFuture ? '' : ' ago'}`;",""," return `${isFuture ? 'in ' : ''}${seconds} ${seconds === 1 ? 'second' : 'seconds'}${isFuture ? '' : ' ago'}`;","}","","// usage","const pastDate = new Date('2021-12-29 13:00:00');","const futureDate = new Date('2026-12-29 13:00:00');","console.log(timeAgoOrAhead(pastDate)); // x years ago","console.log(timeAgoOrAhead(new Date())); // just now","console.log(timeAgoOrAhead(futureDate)); // in x years"],"tags":["javascript","date","time","relative","future","past","utility"],"author":"Yugveer06"}]} |
15 | 15 | {"language": "javascript", {"categoryName":"Function Utilities","snippets":[{"title":"Repeat Function Invocation","description":"Invokes a function a specified number of times.","code":["const times = (func, n) => {"," Array.from(Array(n)).forEach(() => {"," func();"," });","};","","// Usage:","const randomFunction = () => console.log('Function called!');","times(randomFunction, 3); // Logs 'Function called!' three times"],"tags":["javascript","function","repeat","utility"],"author":"technoph1le"},{"title":"Debounce Function","description":"Delays a function execution until after a specified time.","code":["const debounce = (func, delay) => {"," let timeout;"," return (...args) => {"," clearTimeout(timeout);"," timeout = setTimeout(() => func(...args), delay);"," };","};","","// Usage:","window.addEventListener('resize', debounce(() => console.log('Resized!'), 500));"],"tags":["javascript","utility","debounce","performance"],"author":"technoph1le"},{"title":"Throttle Function","description":"Limits a function execution to once every specified time interval.","code":["const throttle = (func, limit) => {"," let lastFunc;"," let lastRan;"," return (...args) => {"," const context = this;"," if (!lastRan) {"," func.apply(context, args);"," lastRan = Date.now();"," } else {"," clearTimeout(lastFunc);"," lastFunc = setTimeout(() => {"," if (Date.now() - lastRan >= limit) {"," func.apply(context, args);"," lastRan = Date.now();"," }"," }, limit - (Date.now() - lastRan));"," }"," };","};","","// Usage:","document.addEventListener('scroll', throttle(() => console.log('Scrolled!'), 1000));"],"tags":["javascript","utility","throttle","performance"],"author":"technoph1le"}]}
|
16 | 16 | {"language": "javascript", {"categoryName":"DOM Manipulation","snippets":[{"title":"Toggle Class","description":"Toggles a class on an element.","code":["const toggleClass = (element, className) => {"," element.classList.toggle(className);","};","","// Usage:","const element = document.querySelector('.my-element');","toggleClass(element, 'active');"],"tags":["javascript","dom","class","utility"],"author":"technoph1le"},{"title":"Smooth Scroll to Element","description":"Scrolls smoothly to a specified element.","code":["const smoothScroll = (element) => {"," element.scrollIntoView({ behavior: 'smooth' });","};","","// Usage:","const target = document.querySelector('#target');","smoothScroll(target);"],"tags":["javascript","dom","scroll","ui"],"author":"technoph1le"}]}
|
17 | 17 | {"language": "javascript", {"categoryName":"Local Storage","snippets":[{"title":"Add Item to localStorage","description":"Stores a value in localStorage under the given key.","code":["const addToLocalStorage = (key, value) => {"," localStorage.setItem(key, JSON.stringify(value));","};","","// Usage:","addToLocalStorage('user', { name: 'John', age: 30 });"],"tags":["javascript","localStorage","storage","utility"],"author":"technoph1le"},{"title":"Retrieve Item from localStorage","description":"Retrieves a value from localStorage by key and parses it.","code":["const getFromLocalStorage = (key) => {"," const item = localStorage.getItem(key);"," return item ? JSON.parse(item) : null;","};","","// Usage:","const user = getFromLocalStorage('user');","console.log(user); // Output: { name: 'John', age: 30 }"],"tags":["javascript","localStorage","storage","utility"],"author":"technoph1le"},{"title":"Clear All localStorage","description":"Clears all data from localStorage.","code":["const clearLocalStorage = () => {"," localStorage.clear();","};","","// Usage:","clearLocalStorage(); // Removes all items from localStorage"],"tags":["javascript","localStorage","storage","utility"],"author":"technoph1le"}]}
|
|
0 commit comments