util


1. Error Handling with try/catch

try {
  // Code that may throw an error
} catch (error) {
  // Error handling code
}

2. Iterating Over Objects with for...in

const obj = { a: 1, b: 2, c: 3 };

for (const key in obj) {
  console.log(`${key}: ${obj[key]}`);
}

3. Array Reduction with reduce()

const numbers = [1, 2, 3, 4, 5];

const sum = numbers.reduce((total, value) => total + value, 0);

4. Converting a String to a Number with parseInt()

const numStr = "123";

const num = parseInt(numStr);

5. Converting a String to a Floating-Point Number with parseFloat()

6. Array Filtering with filter()

7. Array Mapping with map()

8. Creating a Promise

9. Using Promise.all()

10. Using Promise.race()

11. Creating a Buffer

12. Writing Data to a Buffer

13. Reading Data from a Buffer

14. Converting a Buffer to Base64

15. Creating a Cryptographically Secure Random String

16. Hashing Data with SHA256

17. Reading a File with fs.readFile()

18. Creating a Readable Stream

19. Creating a Writable Stream

20. Piping a Stream

21. Reading from a Pipe with pipe()

22. Sending Data to a Pipe with unpipe()

23. Creating a Timeout Function

24. Creating an Interval Function

25. Creating a Promise Queue with async.queue() from "async"

26. Throttling Functions with async.throttle() from "async"

27. Memoizing Functions with memoize() from "lodash"

28. Currying Functions with curry() from "lodash"

29. Debouncing Functions with debounce() from "lodash"

30. Cloning an Object with cloneDeep() from "lodash"

31. Merging Objects with merge() from "lodash"

32. Generating a Unique ID with shortid() from "shortid"

33. Validating an Email Address with validate() from "validator"

34. Normalizing a String with normalize() from "normalize-string"

35. Sanitizing HTML with sanitizeHtml() from "sanitize-html"

36. Formatting Dates with formatDistanceToNowStrict() from "date-fns"