Advertisement
aleffelixf

Utils methods on Javascript

Dec 12th, 2023 (edited)
826
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 0.39 KB | Source Code | 0 0
  1. const randomString = () => Math.random().toString(36).slice(2);
  2.  
  3. const escape = (str) => str.replace(/[&<>"']/g, (m) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[m]));
  4.  
  5. const capitalize = (str) => str.toLowerCase().replace(/^(.)|\s+(.)/g, (c) => c.toUpperCase());
  6.  
  7. const camelCase = (str) => str.trim().replace(/[-_\s]+(.)?/g, (_, c) => (c ? c.toUpperCase() : ''));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement