
9 JavaScript One-Liners That Replace Entire Libraries
Stop installing packages for things JavaScript can do natively Every npm package adds weight, dependencies, and potential vulnerabilities. Here are 9 things you might be importing a library for — that you can do in one line. 1. Deep Clone (replaces lodash.cloneDeep) const clone = structuredClone ( originalObject ); Built into every modern browser and Node 17+. Handles nested objects, arrays, dates, maps, sets. 2. UUID Generation (replaces uuid) const id = crypto . randomUUID (); // '3b241101-e2bb-4d7a-8613-e0c07a8a3c59' Built into browsers and Node 19+. No package needed. 3. Debounce (replaces lodash.debounce) const debounce = ( fn , ms ) => { let t ; return (... a ) => { clearTimeout ( t ); t = setTimeout (() => fn (... a ), ms ); }; }; 4. Flatten Array (replaces lodash.flatten) const flat = nestedArray . flat ( Infinity ); // [1, [2, [3, [4]]]] → [1, 2, 3, 4] 5. Unique Array (replaces lodash.uniq) const unique = [... new Set ( array )]; 6. Group By (replaces lodash.groupBy) const gro
Continue reading on Dev.to Webdev
Opens in a new tab




